blob: 8442e06503bd6ad68f5d228d8087688491a9df46 [file] [log] [blame]
Bill Wendling0480e282010-12-01 02:36:55 +00001//===- ARMInstrThumb.td - Thumb support for ARM ------------*- tablegen -*-===//
Evan Chenga8e29892007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Thumb specific DAG Nodes.
16//
17
18def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
Chris Lattner036609b2010-12-23 18:28:41 +000019 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000020 SDNPVariadic]>;
Evan Chenga8e29892007-01-19 07:51:42 +000021
Owen Anderson6d746312011-08-08 20:42:17 +000022def imm_sr : Operand<i32>, ImmLeaf<i32, [{
23 return Imm > 0 && Imm <= 32;
24}]> {
25 let EncoderMethod = "getThumbSRImmOpValue";
26 let DecoderMethod = "DecodeThumbSRImm";
27}
28
Evan Chenga8e29892007-01-19 07:51:42 +000029def imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000030 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000031}]>;
32def imm_comp_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000033 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000034}]>;
35
Evan Chenga8e29892007-01-19 07:51:42 +000036def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000037 return (uint32_t)-N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000038}], imm_neg_XFORM>;
39
Evan Chenga8e29892007-01-19 07:51:42 +000040def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000041 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000042}]>;
43
Eric Christopher8f232d32011-04-28 05:49:04 +000044def imm8_255 : ImmLeaf<i32, [{
45 return Imm >= 8 && Imm < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000046}]>;
47def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000048 unsigned Val = -N->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +000049 return Val >= 8 && Val < 256;
50}], imm_neg_XFORM>;
51
Bill Wendling0480e282010-12-01 02:36:55 +000052// Break imm's up into two pieces: an immediate + a left shift. This uses
53// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
54// to get the val/shift pieces.
Evan Chenga8e29892007-01-19 07:51:42 +000055def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000056 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000057}]>;
58
59def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000060 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000061 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000062}]>;
63
64def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000065 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000066 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000067}]>;
68
Jim Grosbachd40963c2010-12-14 22:28:03 +000069// ADR instruction labels.
70def t_adrlabel : Operand<i32> {
71 let EncoderMethod = "getThumbAdrLabelOpValue";
72}
73
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000074// Scaled 4 immediate.
75def t_imm_s4 : Operand<i32> {
76 let PrintMethod = "printThumbS4ImmOperand";
Benjamin Kramer151bd172011-07-14 21:47:24 +000077 let OperandType = "OPERAND_IMMEDIATE";
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000078}
79
Evan Chenga8e29892007-01-19 07:51:42 +000080// Define Thumb specific addressing modes.
81
Benjamin Kramer151bd172011-07-14 21:47:24 +000082let OperandType = "OPERAND_PCREL" in {
Jim Grosbache2467172010-12-10 18:21:33 +000083def t_brtarget : Operand<OtherVT> {
84 let EncoderMethod = "getThumbBRTargetOpValue";
85}
86
Jim Grosbach01086452010-12-10 17:13:40 +000087def t_bcctarget : Operand<i32> {
88 let EncoderMethod = "getThumbBCCTargetOpValue";
89}
90
Jim Grosbachcf6220a2010-12-09 19:01:46 +000091def t_cbtarget : Operand<i32> {
Jim Grosbach027d6e82010-12-09 19:04:53 +000092 let EncoderMethod = "getThumbCBTargetOpValue";
Bill Wendlingdff2f712010-12-08 23:01:43 +000093}
94
Jim Grosbach662a8162010-12-06 23:57:07 +000095def t_bltarget : Operand<i32> {
96 let EncoderMethod = "getThumbBLTargetOpValue";
Owen Anderson648f9a72011-08-08 23:25:22 +000097 let DecoderMethod = "DecodeThumbBLTargetOperand";
Jim Grosbach662a8162010-12-06 23:57:07 +000098}
99
Bill Wendling09aa3f02010-12-09 00:39:08 +0000100def t_blxtarget : Operand<i32> {
101 let EncoderMethod = "getThumbBLXTargetOpValue";
Owen Anderson6d746312011-08-08 20:42:17 +0000102 let DecoderMethod = "DecodeThumbBLXOffset";
Bill Wendling09aa3f02010-12-09 00:39:08 +0000103}
Benjamin Kramer151bd172011-07-14 21:47:24 +0000104}
Bill Wendling09aa3f02010-12-09 00:39:08 +0000105
Evan Chenga8e29892007-01-19 07:51:42 +0000106// t_addrmode_rr := reg + reg
107//
Jim Grosbach7ce05792011-08-03 23:50:40 +0000108def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
Evan Chenga8e29892007-01-19 07:51:42 +0000109def t_addrmode_rr : Operand<i32>,
110 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000111 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000112 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000113 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000114}
115
Bill Wendlingf4caf692010-12-14 03:36:38 +0000116// t_addrmode_rrs := reg + reg
Evan Chenga8e29892007-01-19 07:51:42 +0000117//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000118def t_addrmode_rrs1 : Operand<i32>,
119 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
120 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
121 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach7ce05792011-08-03 23:50:40 +0000122 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000123 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000124}
Bill Wendlingf4caf692010-12-14 03:36:38 +0000125def t_addrmode_rrs2 : Operand<i32>,
126 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
127 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
128 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach7ce05792011-08-03 23:50:40 +0000129 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000130 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000131}
132def t_addrmode_rrs4 : Operand<i32>,
133 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
134 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
135 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach7ce05792011-08-03 23:50:40 +0000136 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000137 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000138}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000139
Bill Wendlingf4caf692010-12-14 03:36:38 +0000140// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc38f2bc2007-01-23 22:59:13 +0000141//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000142def t_addrmode_is4 : Operand<i32>,
143 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
144 let EncoderMethod = "getAddrModeISOpValue";
145 let PrintMethod = "printThumbAddrModeImm5S4Operand";
146 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000147}
148
149// t_addrmode_is2 := reg + imm5 * 2
150//
151def t_addrmode_is2 : Operand<i32>,
152 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
153 let EncoderMethod = "getAddrModeISOpValue";
154 let PrintMethod = "printThumbAddrModeImm5S2Operand";
155 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000156}
157
158// t_addrmode_is1 := reg + imm5
159//
160def t_addrmode_is1 : Operand<i32>,
161 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
162 let EncoderMethod = "getAddrModeISOpValue";
163 let PrintMethod = "printThumbAddrModeImm5S1Operand";
164 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Evan Chenga8e29892007-01-19 07:51:42 +0000165}
166
167// t_addrmode_sp := sp + imm8 * 4
168//
169def t_addrmode_sp : Operand<i32>,
170 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbachd967cd02010-12-07 21:50:47 +0000171 let EncoderMethod = "getAddrModeThumbSPOpValue";
Owen Anderson648f9a72011-08-08 23:25:22 +0000172 let DecoderMethod = "DecodeThumbAddrModeSP";
Evan Chenga8e29892007-01-19 07:51:42 +0000173 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000174 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Evan Chenga8e29892007-01-19 07:51:42 +0000175}
176
Bill Wendlingb8958b02010-12-08 01:57:09 +0000177// t_addrmode_pc := <label> => pc + imm8 * 4
178//
179def t_addrmode_pc : Operand<i32> {
180 let EncoderMethod = "getAddrModePCOpValue";
Bill Wendlingb8958b02010-12-08 01:57:09 +0000181}
182
Evan Chenga8e29892007-01-19 07:51:42 +0000183//===----------------------------------------------------------------------===//
184// Miscellaneous Instructions.
185//
186
Jim Grosbach4642ad32010-02-22 23:10:38 +0000187// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
188// from removing one half of the matched pairs. That breaks PEI, which assumes
189// these will always be in pairs, and asserts if it finds otherwise. Better way?
190let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000191def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000192 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
193 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
194 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000195
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000196def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000197 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
198 [(ARMcallseq_start imm:$amt)]>,
199 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000200}
Evan Cheng44bec522007-05-15 01:29:07 +0000201
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000202// T1Disassembly - A simple class to make encoding some disassembly patterns
203// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000204class T1Disassembly<bits<2> op1, bits<8> op2>
205 : T1Encoding<0b101111> {
206 let Inst{9-8} = op1;
207 let Inst{7-0} = op2;
208}
209
Johnny Chenbd2c6232010-02-25 03:28:51 +0000210def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
211 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000212 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000213
Johnny Chend86d2692010-02-25 17:51:03 +0000214def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
215 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000216 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000217
218def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
219 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000220 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000221
222def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
223 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000224 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000225
226def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
227 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000228 T1Disassembly<0b11, 0x40>; // A8.6.157
229
230// The i32imm operand $val can be used by a debugger to store more information
231// about the breakpoint.
232def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
233 [/* For disassembly only; pattern left blank */]>,
234 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
235 // A8.6.22
236 bits<8> val;
237 let Inst{7-0} = val;
238}
Johnny Chend86d2692010-02-25 17:51:03 +0000239
Jim Grosbach06322472011-07-22 17:52:23 +0000240def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
241 []>, T1Encoding<0b101101> {
242 bits<1> end;
Bill Wendling7d0affd2010-11-21 10:55:23 +0000243 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000244 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000245 let Inst{4} = 1;
Jim Grosbach06322472011-07-22 17:52:23 +0000246 let Inst{3} = end;
Bill Wendlinga8981662010-11-19 22:02:18 +0000247 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000248}
249
Johnny Chen93042d12010-03-02 18:14:57 +0000250// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000251def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
252 NoItinerary, "cps$imod $iflags",
253 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000254 T1Misc<0b0110011> {
255 // A8.6.38 & B6.1.1
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000256 bit imod;
257 bits<3> iflags;
258
259 let Inst{4} = imod;
260 let Inst{3} = 0;
261 let Inst{2-0} = iflags;
Bill Wendling849f2e32010-11-29 00:18:15 +0000262}
Johnny Chen93042d12010-03-02 18:14:57 +0000263
Evan Cheng35d6c412009-08-04 23:47:55 +0000264// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000265let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000266def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000267 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000268 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000269 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000270 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000271 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000272 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000273}
Evan Chenga8e29892007-01-19 07:51:42 +0000274
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000275// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000276def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000277 "add\t$dst, pc, $rhs", []>,
278 T1Encoding<{1,0,1,0,0,?}> {
279 // A6.2 & A8.6.10
280 bits<3> dst;
281 bits<8> rhs;
282 let Inst{10-8} = dst;
283 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000284}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000285
Bill Wendling0ae28e42010-11-19 22:37:33 +0000286// ADD <Rd>, sp, #<imm8>
287// This is rematerializable, which is particularly useful for taking the
288// address of locals.
289let isReMaterializable = 1 in
290def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
291 "add\t$dst, $sp, $rhs", []>,
292 T1Encoding<{1,0,1,0,1,?}> {
293 // A6.2 & A8.6.8
294 bits<3> dst;
295 bits<8> rhs;
296 let Inst{10-8} = dst;
297 let Inst{7-0} = rhs;
298}
299
300// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000301def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000302 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000303 T1Misc<{0,0,0,0,0,?,?}> {
304 // A6.2.5 & A8.6.8
305 bits<7> rhs;
306 let Inst{6-0} = rhs;
307}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000308
Bill Wendling0ae28e42010-11-19 22:37:33 +0000309// SUB sp, sp, #<imm7>
310// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000311def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000312 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000313 T1Misc<{0,0,0,0,1,?,?}> {
314 // A6.2.5 & A8.6.214
315 bits<7> rhs;
316 let Inst{6-0} = rhs;
317}
Evan Cheng86198642009-08-07 00:34:42 +0000318
Bill Wendling0ae28e42010-11-19 22:37:33 +0000319// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000320def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000321 "add\t$dst, $rhs", []>,
322 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000323 // A8.6.9 Encoding T1
324 bits<4> dst;
325 let Inst{7} = dst{3};
326 let Inst{6-3} = 0b1101;
327 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000328}
Evan Cheng86198642009-08-07 00:34:42 +0000329
Bill Wendling0ae28e42010-11-19 22:37:33 +0000330// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000331def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000332 "add\t$dst, $rhs", []>,
333 T1Special<{0,0,?,?}> {
334 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000335 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000336 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000337 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000338 let Inst{2-0} = 0b101;
339}
Evan Cheng86198642009-08-07 00:34:42 +0000340
Evan Chenga8e29892007-01-19 07:51:42 +0000341//===----------------------------------------------------------------------===//
342// Control Flow Instructions.
343//
344
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000345// Indirect branches
346let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich421b1062011-05-26 03:41:12 +0000347 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
348 T1Special<{1,1,0,?}> {
349 // A6.2.3 & A8.6.25
350 bits<4> Rm;
351 let Inst{6-3} = Rm;
352 let Inst{2-0} = 0b000;
353 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000354}
355
Jim Grosbachead77cd2011-07-08 21:04:05 +0000356let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson16884412011-07-13 23:22:26 +0000357 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Jim Grosbach25e6d482011-07-08 21:50:04 +0000358 [(ARMretflag)], (tBX LR, pred:$p)>;
Jim Grosbachead77cd2011-07-08 21:04:05 +0000359
360 // Alternative return instruction used by vararg functions.
Jim Grosbach25e6d482011-07-08 21:50:04 +0000361 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +0000362 2, IIC_Br, [],
Jim Grosbach25e6d482011-07-08 21:50:04 +0000363 (tBX GPR:$Rm, pred:$p)>;
Jim Grosbachead77cd2011-07-08 21:04:05 +0000364}
365
Bill Wendling0480e282010-12-01 02:36:55 +0000366// All calls clobber the non-callee saved registers. SP is marked as a use to
367// prevent stack-pointer assignments that appear immediately before calls from
368// potentially appearing dead.
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000369let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000370 // On non-Darwin platforms R9 is callee-saved.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000371 Defs = [R0, R1, R2, R3, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000372 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000373 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000374 def tBL : TIx2<0b11110, 0b11, 1,
Owen Anderson0af0dc82011-07-18 18:50:52 +0000375 (outs), (ins pred:$p, t_bltarget:$func, variable_ops), IIC_Br,
376 "bl${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000377 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000378 Requires<[IsThumb, IsNotDarwin]> {
Owen Anderson648f9a72011-08-08 23:25:22 +0000379 bits<22> func;
380 let Inst{26} = func{21};
Jim Grosbach662a8162010-12-06 23:57:07 +0000381 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000382 let Inst{13} = 1;
383 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000384 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000385 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000386
Evan Chengb6207242009-08-01 00:16:10 +0000387 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000388 def tBLXi : TIx2<0b11110, 0b11, 0,
Owen Anderson0af0dc82011-07-18 18:50:52 +0000389 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops), IIC_Br,
390 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000391 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000392 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000393 bits<21> func;
394 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000395 let Inst{13} = 1;
396 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000397 let Inst{10-1} = func{10-1};
398 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000399 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000400
Evan Chengb6207242009-08-01 00:16:10 +0000401 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000402 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
403 "blx${p}\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000404 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000405 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
Owen Anderson18901d62011-05-11 17:00:48 +0000406 T1Special<{1,1,1,?}> { // A6.2.3 & A8.6.24;
407 bits<4> func;
408 let Inst{6-3} = func;
409 let Inst{2-0} = 0b000;
410 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000411
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000412 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000413 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000414 4, IIC_Br,
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000415 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000416 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000417}
418
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000419let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000420 // On Darwin R9 is call-clobbered.
421 // R7 is marked as a use to prevent frame-pointer assignments from being
422 // moved above / below calls.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000423 Defs = [R0, R1, R2, R3, R9, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000424 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000425 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000426 def tBLr9 : tPseudoExpand<(outs), (ins pred:$p, t_bltarget:$func, variable_ops),
427 4, IIC_Br, [(ARMtcall tglobaladdr:$func)],
428 (tBL pred:$p, t_bltarget:$func)>,
429 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000430
Evan Chengb6207242009-08-01 00:16:10 +0000431 // ARMv5T and above, also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000432 def tBLXi_r9 : tPseudoExpand<(outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
433 4, IIC_Br, [(ARMcall tglobaladdr:$func)],
434 (tBLXi pred:$p, t_blxtarget:$func)>,
435 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000436
Evan Chengb6207242009-08-01 00:16:10 +0000437 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000438 def tBLXr_r9 : tPseudoExpand<(outs), (ins pred:$p, GPR:$func, variable_ops),
439 2, IIC_Br, [(ARMtcall GPR:$func)],
440 (tBLXr pred:$p, GPR:$func)>,
441 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000442
443 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000444 def tBXr9_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000445 4, IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000446 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000447 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000448}
449
Bill Wendling0480e282010-12-01 02:36:55 +0000450let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
451 let isPredicable = 1 in
Jim Grosbache2467172010-12-10 18:21:33 +0000452 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
Bill Wendling0480e282010-12-01 02:36:55 +0000453 "b\t$target", [(br bb:$target)]>,
Jim Grosbache2467172010-12-10 18:21:33 +0000454 T1Encoding<{1,1,1,0,0,?}> {
455 bits<11> target;
456 let Inst{10-0} = target;
457 }
Evan Chenga8e29892007-01-19 07:51:42 +0000458
Evan Cheng225dfe92007-01-30 01:13:37 +0000459 // Far jump
Jim Grosbach3efad8f2010-12-16 19:11:16 +0000460 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
461 // the clobber of LR.
Evan Cheng53c67c02009-08-07 05:45:07 +0000462 let Defs = [LR] in
Owen Anderson0af0dc82011-07-18 18:50:52 +0000463 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
464 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000465
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000466 def tBR_JTr : tPseudoInst<(outs),
467 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
Owen Anderson16884412011-07-13 23:22:26 +0000468 0, IIC_Br,
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000469 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
470 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000471 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000472}
473
Evan Chengc85e8322007-07-05 07:13:32 +0000474// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000475// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000476let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000477 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000478 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000479 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Eric Christopher33281b22011-05-27 03:50:53 +0000480 T1BranchCond<{1,1,0,1}> {
Jim Grosbachceab5012010-12-04 00:20:40 +0000481 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000482 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000483 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000484 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000485}
Evan Chenga8e29892007-01-19 07:51:42 +0000486
Evan Chengde17fb62009-10-31 23:46:45 +0000487// Compare and branch on zero / non-zero
488let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000489 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000490 "cbz\t$Rn, $target", []>,
491 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000492 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000493 bits<6> target;
494 bits<3> Rn;
495 let Inst{9} = target{5};
496 let Inst{7-3} = target{4-0};
497 let Inst{2-0} = Rn;
498 }
Evan Chengde17fb62009-10-31 23:46:45 +0000499
Owen Anderson0bc8bbb2011-08-03 23:21:48 +0000500 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
501 "cbnz\t$Rn, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000502 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000503 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000504 bits<6> target;
505 bits<3> Rn;
506 let Inst{9} = target{5};
507 let Inst{7-3} = target{4-0};
508 let Inst{2-0} = Rn;
509 }
Evan Chengde17fb62009-10-31 23:46:45 +0000510}
511
Jim Grosbache36e21e2011-07-08 20:13:35 +0000512// Tail calls
513let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
514 // Darwin versions.
515 let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
516 Uses = [SP] in {
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000517 // tTAILJMPd: Darwin version uses a Thumb2 branch (no Thumb1 tail calls
518 // on Darwin), so it's in ARMInstrThumb2.td.
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000519 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000520 4, IIC_Br, [],
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000521 (tBX GPR:$dst, (ops 14, zero_reg))>,
522 Requires<[IsThumb, IsDarwin]>;
Jim Grosbache36e21e2011-07-08 20:13:35 +0000523 }
524 // Non-Darwin versions (the difference is R9).
525 let Defs = [R0, R1, R2, R3, R12, QQQQ0, QQQQ2, QQQQ3, PC],
526 Uses = [SP] in {
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000527 def tTAILJMPdND : tPseudoExpand<(outs), (ins t_brtarget:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000528 4, IIC_Br, [],
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000529 (tB t_brtarget:$dst)>,
530 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000531 def tTAILJMPrND : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000532 4, IIC_Br, [],
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000533 (tBX GPR:$dst, (ops 14, zero_reg))>,
534 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbache36e21e2011-07-08 20:13:35 +0000535 }
536}
537
538
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000539// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
540// A8.6.16 B: Encoding T1
541// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000542let isCall = 1, Uses = [SP] in
Jim Grosbached838482011-07-26 16:24:27 +0000543def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Bill Wendling6179c312010-11-20 00:53:35 +0000544 "svc", "\t$imm", []>, Encoding16 {
545 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000546 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000547 let Inst{11-8} = 0b1111;
548 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000549}
550
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000551// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000552let isBarrier = 1, isTerminator = 1 in
Owen Anderson18901d62011-05-11 17:00:48 +0000553def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000554 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000555 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000556}
557
Evan Chenga8e29892007-01-19 07:51:42 +0000558//===----------------------------------------------------------------------===//
559// Load Store Instructions.
560//
561
Bill Wendlingb6faf652010-12-14 22:10:49 +0000562// Loads: reg/reg and reg/imm5
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000563let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb6faf652010-12-14 22:10:49 +0000564multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
565 Operand AddrMode_r, Operand AddrMode_i,
566 AddrMode am, InstrItinClass itin_r,
567 InstrItinClass itin_i, string asm,
568 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000569 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000570 T1pILdStEncode<reg_opc,
571 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
572 am, itin_r, asm, "\t$Rt, $addr",
573 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000574 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000575 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
576 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
577 am, itin_i, asm, "\t$Rt, $addr",
578 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
579}
580// Stores: reg/reg and reg/imm5
581multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
582 Operand AddrMode_r, Operand AddrMode_i,
583 AddrMode am, InstrItinClass itin_r,
584 InstrItinClass itin_i, string asm,
585 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000586 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000587 T1pILdStEncode<reg_opc,
588 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
589 am, itin_r, asm, "\t$Rt, $addr",
590 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000591 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000592 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
593 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
594 am, itin_i, asm, "\t$Rt, $addr",
595 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
596}
Bill Wendling6179c312010-11-20 00:53:35 +0000597
Bill Wendlingb6faf652010-12-14 22:10:49 +0000598// A8.6.57 & A8.6.60
599defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
600 t_addrmode_is4, AddrModeT1_4,
601 IIC_iLoad_r, IIC_iLoad_i, "ldr",
602 UnOpFrag<(load node:$Src)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000603
Bill Wendlingb6faf652010-12-14 22:10:49 +0000604// A8.6.64 & A8.6.61
605defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
606 t_addrmode_is1, AddrModeT1_1,
607 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
608 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000609
Bill Wendlingb6faf652010-12-14 22:10:49 +0000610// A8.6.76 & A8.6.73
611defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
612 t_addrmode_is2, AddrModeT1_2,
613 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
614 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000615
Evan Cheng2f297df2009-07-11 07:08:13 +0000616let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000617def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000618 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
619 AddrModeT1_1, IIC_iLoad_bh_r,
620 "ldrsb", "\t$dst, $addr",
621 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000622
Evan Cheng2f297df2009-07-11 07:08:13 +0000623let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000624def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000625 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
626 AddrModeT1_2, IIC_iLoad_bh_r,
627 "ldrsh", "\t$dst, $addr",
628 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000629
Dan Gohman15511cf2008-12-03 18:15:48 +0000630let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000631def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000632 "ldr", "\t$Rt, $addr",
633 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000634 T1LdStSP<{1,?,?}> {
635 bits<3> Rt;
636 bits<8> addr;
637 let Inst{10-8} = Rt;
638 let Inst{7-0} = addr;
639}
Evan Cheng012f2d92007-01-24 08:53:17 +0000640
641// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000642// FIXME: Use ldr.n to work around a Darwin assembler bug.
Owen Anderson91614ae2011-07-18 22:14:02 +0000643let canFoldAsLoad = 1, isReMaterializable = 1, isCodeGenOnly = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000644def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000645 "ldr", ".n\t$Rt, $addr",
646 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
647 T1Encoding<{0,1,0,0,1,?}> {
648 // A6.2 & A8.6.59
649 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000650 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000651 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000652 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000653}
Evan Chengfa775d02007-03-19 07:20:03 +0000654
Johnny Chen597fa652011-04-22 19:12:43 +0000655// FIXME: Remove this entry when the above ldr.n workaround is fixed.
656// For disassembly use only.
657def tLDRpciDIS : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
658 "ldr", "\t$Rt, $addr",
659 [/* disassembly only */]>,
660 T1Encoding<{0,1,0,0,1,?}> {
661 // A6.2 & A8.6.59
662 bits<3> Rt;
663 bits<8> addr;
664 let Inst{10-8} = Rt;
665 let Inst{7-0} = addr;
666}
667
Bill Wendlingb6faf652010-12-14 22:10:49 +0000668// A8.6.194 & A8.6.192
669defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
670 t_addrmode_is4, AddrModeT1_4,
671 IIC_iStore_r, IIC_iStore_i, "str",
672 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000673
Bill Wendlingb6faf652010-12-14 22:10:49 +0000674// A8.6.197 & A8.6.195
675defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
676 t_addrmode_is1, AddrModeT1_1,
677 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
678 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000679
Bill Wendlingb6faf652010-12-14 22:10:49 +0000680// A8.6.207 & A8.6.205
681defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000682 t_addrmode_is2, AddrModeT1_2,
683 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
684 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000685
Evan Chenga8e29892007-01-19 07:51:42 +0000686
Jim Grosbachd967cd02010-12-07 21:50:47 +0000687def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendlingf4caf692010-12-14 03:36:38 +0000688 "str", "\t$Rt, $addr",
689 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000690 T1LdStSP<{0,?,?}> {
691 bits<3> Rt;
692 bits<8> addr;
693 let Inst{10-8} = Rt;
694 let Inst{7-0} = addr;
695}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000696
Evan Chenga8e29892007-01-19 07:51:42 +0000697//===----------------------------------------------------------------------===//
698// Load / store multiple Instructions.
699//
700
Bill Wendling6c470b82010-11-13 09:09:38 +0000701multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
702 InstrItinClass itin_upd, bits<6> T1Enc,
Owen Anderson565a0362011-07-18 23:25:34 +0000703 bit L_bit, string baseOpc> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000704 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000705 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000706 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000707 T1Encoding<T1Enc> {
708 bits<3> Rn;
709 bits<8> regs;
710 let Inst{10-8} = Rn;
711 let Inst{7-0} = regs;
712 }
Owen Anderson565a0362011-07-18 23:25:34 +0000713
Bill Wendling73fe34a2010-11-16 01:16:36 +0000714 def IA_UPD :
Owen Anderson565a0362011-07-18 23:25:34 +0000715 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
716 "$Rn = $wb", itin_upd>,
717 PseudoInstExpansion<(!cast<Instruction>(!strconcat(baseOpc, "IA"))
718 GPR:$Rn, pred:$p, reglist:$regs)> {
719 let Size = 2;
720 let OutOperandList = (outs GPR:$wb);
721 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
722 let Pattern = [];
723 let isCodeGenOnly = 1;
724 let isPseudo = 1;
725 list<Predicate> Predicates = [IsThumb];
Bill Wendling6179c312010-11-20 00:53:35 +0000726 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000727}
728
Bill Wendling73fe34a2010-11-16 01:16:36 +0000729// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000730let neverHasSideEffects = 1 in {
731
732let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
733defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
Owen Anderson565a0362011-07-18 23:25:34 +0000734 {1,1,0,0,1,?}, 1, "tLDM">;
Bill Wendlingddc918b2010-11-13 10:57:02 +0000735
736let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
737defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
Owen Anderson565a0362011-07-18 23:25:34 +0000738 {1,1,0,0,0,?}, 0, "tSTM">;
Owen Anderson18901d62011-05-11 17:00:48 +0000739
Bill Wendlingddc918b2010-11-13 10:57:02 +0000740} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000741
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000742let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000743def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000744 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000745 "pop${p}\t$regs", []>,
746 T1Misc<{1,1,0,?,?,?,?}> {
747 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000748 let Inst{8} = regs{15};
749 let Inst{7-0} = regs{7-0};
750}
Evan Cheng4b322e52009-08-11 21:11:32 +0000751
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000752let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000753def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000754 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000755 "push${p}\t$regs", []>,
756 T1Misc<{0,1,0,?,?,?,?}> {
757 bits<16> regs;
758 let Inst{8} = regs{14};
759 let Inst{7-0} = regs{7-0};
760}
Evan Chenga8e29892007-01-19 07:51:42 +0000761
762//===----------------------------------------------------------------------===//
763// Arithmetic Instructions.
764//
765
Bill Wendling1d045ee2010-12-01 02:28:08 +0000766// Helper classes for encoding T1pI patterns:
767class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
768 string opc, string asm, list<dag> pattern>
769 : T1pI<oops, iops, itin, opc, asm, pattern>,
770 T1DataProcessing<opA> {
771 bits<3> Rm;
772 bits<3> Rn;
773 let Inst{5-3} = Rm;
774 let Inst{2-0} = Rn;
775}
776class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
777 string opc, string asm, list<dag> pattern>
778 : T1pI<oops, iops, itin, opc, asm, pattern>,
779 T1Misc<opA> {
780 bits<3> Rm;
781 bits<3> Rd;
782 let Inst{5-3} = Rm;
783 let Inst{2-0} = Rd;
784}
785
Bill Wendling76f4e102010-12-01 01:20:15 +0000786// Helper classes for encoding T1sI patterns:
787class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
788 string opc, string asm, list<dag> pattern>
789 : T1sI<oops, iops, itin, opc, asm, pattern>,
790 T1DataProcessing<opA> {
791 bits<3> Rd;
792 bits<3> Rn;
793 let Inst{5-3} = Rn;
794 let Inst{2-0} = Rd;
795}
796class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
797 string opc, string asm, list<dag> pattern>
798 : T1sI<oops, iops, itin, opc, asm, pattern>,
799 T1General<opA> {
800 bits<3> Rm;
801 bits<3> Rn;
802 bits<3> Rd;
803 let Inst{8-6} = Rm;
804 let Inst{5-3} = Rn;
805 let Inst{2-0} = Rd;
806}
807class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
808 string opc, string asm, list<dag> pattern>
809 : T1sI<oops, iops, itin, opc, asm, pattern>,
810 T1General<opA> {
811 bits<3> Rd;
812 bits<3> Rm;
813 let Inst{5-3} = Rm;
814 let Inst{2-0} = Rd;
815}
816
817// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000818class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
819 string opc, string asm, list<dag> pattern>
820 : T1sIt<oops, iops, itin, opc, asm, pattern>,
821 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000822 bits<3> Rdn;
823 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000824 let Inst{5-3} = Rm;
825 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000826}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000827class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
828 string opc, string asm, list<dag> pattern>
829 : T1sIt<oops, iops, itin, opc, asm, pattern>,
830 T1General<opA> {
831 bits<3> Rdn;
832 bits<8> imm8;
833 let Inst{10-8} = Rdn;
834 let Inst{7-0} = imm8;
835}
836
837// Add with carry register
838let isCommutable = 1, Uses = [CPSR] in
839def tADC : // A8.6.2
840 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
841 "adc", "\t$Rdn, $Rm",
842 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000843
David Goodwinc9ee1182009-06-25 22:49:55 +0000844// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000845def tADDi3 : // A8.6.4 T1
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000846 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
847 IIC_iALUi,
Bill Wendling76f4e102010-12-01 01:20:15 +0000848 "add", "\t$Rd, $Rm, $imm3",
849 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000850 bits<3> imm3;
851 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000852}
Evan Chenga8e29892007-01-19 07:51:42 +0000853
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000854def tADDi8 : // A8.6.4 T2
855 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
856 IIC_iALUi,
857 "add", "\t$Rdn, $imm8",
858 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000859
David Goodwinc9ee1182009-06-25 22:49:55 +0000860// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000861let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000862def tADDrr : // A8.6.6 T1
863 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
864 IIC_iALUr,
865 "add", "\t$Rd, $Rn, $Rm",
866 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000867
Evan Chengcd799b92009-06-12 20:46:18 +0000868let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000869def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
870 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000871 T1Special<{0,0,?,?}> {
872 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000873 bits<4> Rdn;
874 bits<4> Rm;
875 let Inst{7} = Rdn{3};
876 let Inst{6-3} = Rm;
877 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000878}
Evan Chenga8e29892007-01-19 07:51:42 +0000879
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000880// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000881let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000882def tAND : // A8.6.12
883 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
884 IIC_iBITr,
885 "and", "\t$Rdn, $Rm",
886 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000887
David Goodwinc9ee1182009-06-25 22:49:55 +0000888// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000889def tASRri : // A8.6.14
Owen Anderson6d746312011-08-08 20:42:17 +0000890 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling76f4e102010-12-01 01:20:15 +0000891 IIC_iMOVsi,
892 "asr", "\t$Rd, $Rm, $imm5",
Owen Anderson6d746312011-08-08 20:42:17 +0000893 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000894 bits<5> imm5;
895 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000896}
Evan Chenga8e29892007-01-19 07:51:42 +0000897
David Goodwinc9ee1182009-06-25 22:49:55 +0000898// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000899def tASRrr : // A8.6.15
900 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
901 IIC_iMOVsr,
902 "asr", "\t$Rdn, $Rm",
903 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000904
David Goodwinc9ee1182009-06-25 22:49:55 +0000905// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000906def tBIC : // A8.6.20
907 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
908 IIC_iBITr,
909 "bic", "\t$Rdn, $Rm",
910 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000911
David Goodwinc9ee1182009-06-25 22:49:55 +0000912// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000913let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000914//FIXME: Disable CMN, as CCodes are backwards from compare expectations
915// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000916//def tCMN : // A8.6.33
917// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
918// IIC_iCMPr,
919// "cmn", "\t$lhs, $rhs",
920// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000921
922def tCMNz : // A8.6.33
923 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
924 IIC_iCMPr,
925 "cmn", "\t$Rn, $Rm",
926 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
927
928} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000929
David Goodwinc9ee1182009-06-25 22:49:55 +0000930// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000931let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000932def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
933 "cmp", "\t$Rn, $imm8",
934 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
935 T1General<{1,0,1,?,?}> {
936 // A8.6.35
937 bits<3> Rn;
938 bits<8> imm8;
939 let Inst{10-8} = Rn;
940 let Inst{7-0} = imm8;
941}
942
David Goodwinc9ee1182009-06-25 22:49:55 +0000943// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +0000944def tCMPr : // A8.6.36 T1
945 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
946 IIC_iCMPr,
947 "cmp", "\t$Rn, $Rm",
948 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
949
Bill Wendling849f2e32010-11-29 00:18:15 +0000950def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
951 "cmp", "\t$Rn, $Rm", []>,
952 T1Special<{0,1,?,?}> {
953 // A8.6.36 T2
954 bits<4> Rm;
955 bits<4> Rn;
956 let Inst{7} = Rn{3};
957 let Inst{6-3} = Rm;
958 let Inst{2-0} = Rn{2-0};
959}
Bill Wendling5cc88a22010-11-20 22:52:33 +0000960} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000961
Evan Chenga8e29892007-01-19 07:51:42 +0000962
David Goodwinc9ee1182009-06-25 22:49:55 +0000963// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +0000964let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000965def tEOR : // A8.6.45
966 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
967 IIC_iBITr,
968 "eor", "\t$Rdn, $Rm",
969 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000970
David Goodwinc9ee1182009-06-25 22:49:55 +0000971// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000972def tLSLri : // A8.6.88
973 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
974 IIC_iMOVsi,
975 "lsl", "\t$Rd, $Rm, $imm5",
976 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000977 bits<5> imm5;
978 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000979}
Evan Chenga8e29892007-01-19 07:51:42 +0000980
David Goodwinc9ee1182009-06-25 22:49:55 +0000981// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000982def tLSLrr : // A8.6.89
983 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
984 IIC_iMOVsr,
985 "lsl", "\t$Rdn, $Rm",
986 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000987
David Goodwinc9ee1182009-06-25 22:49:55 +0000988// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000989def tLSRri : // A8.6.90
Owen Anderson6d746312011-08-08 20:42:17 +0000990 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling76f4e102010-12-01 01:20:15 +0000991 IIC_iMOVsi,
992 "lsr", "\t$Rd, $Rm, $imm5",
Owen Anderson6d746312011-08-08 20:42:17 +0000993 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000994 bits<5> imm5;
995 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000996}
Evan Chenga8e29892007-01-19 07:51:42 +0000997
David Goodwinc9ee1182009-06-25 22:49:55 +0000998// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000999def tLSRrr : // A8.6.91
1000 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1001 IIC_iMOVsr,
1002 "lsr", "\t$Rdn, $Rm",
1003 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001004
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001005// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001006let isMoveImm = 1 in
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00001007def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001008 "mov", "\t$Rd, $imm8",
1009 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1010 T1General<{1,0,0,?,?}> {
1011 // A8.6.96
1012 bits<3> Rd;
1013 bits<8> imm8;
1014 let Inst{10-8} = Rd;
1015 let Inst{7-0} = imm8;
1016}
Evan Chenga8e29892007-01-19 07:51:42 +00001017
Jim Grosbachefeedce2011-07-01 17:14:11 +00001018// A7-73: MOV(2) - mov setting flag.
Evan Chenga8e29892007-01-19 07:51:42 +00001019
Evan Chengcd799b92009-06-12 20:46:18 +00001020let neverHasSideEffects = 1 in {
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001021def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson16884412011-07-13 23:22:26 +00001022 2, IIC_iMOVr,
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001023 "mov", "\t$Rd, $Rm", "", []>,
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001024 T1Special<{1,0,?,?}> {
Bill Wendling534a5e42010-12-03 01:55:47 +00001025 // A8.6.97
1026 bits<4> Rd;
1027 bits<4> Rm;
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001028 let Inst{7} = Rd{3};
1029 let Inst{6-3} = Rm;
Bill Wendling534a5e42010-12-03 01:55:47 +00001030 let Inst{2-0} = Rd{2-0};
1031}
Evan Cheng446c4282009-07-11 06:43:01 +00001032let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001033def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1034 "movs\t$Rd, $Rm", []>, Encoding16 {
1035 // A8.6.97
1036 bits<3> Rd;
1037 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001038 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001039 let Inst{5-3} = Rm;
1040 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001041}
Evan Chengcd799b92009-06-12 20:46:18 +00001042} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001043
Bill Wendling0480e282010-12-01 02:36:55 +00001044// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001045let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001046def tMUL : // A8.6.105 T1
1047 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1048 IIC_iMUL32,
1049 "mul", "\t$Rdn, $Rm, $Rdn",
1050 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001051
Bill Wendling76f4e102010-12-01 01:20:15 +00001052// Move inverse register
1053def tMVN : // A8.6.107
1054 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1055 "mvn", "\t$Rd, $Rn",
1056 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001057
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001058// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001059let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001060def tORR : // A8.6.114
1061 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1062 IIC_iBITr,
1063 "orr", "\t$Rdn, $Rm",
1064 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001065
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001066// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001067def tREV : // A8.6.134
1068 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1069 IIC_iUNAr,
1070 "rev", "\t$Rd, $Rm",
1071 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1072 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001073
Bill Wendling1d045ee2010-12-01 02:28:08 +00001074def tREV16 : // A8.6.135
1075 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1076 IIC_iUNAr,
1077 "rev16", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001078 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001079 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001080
Bill Wendling1d045ee2010-12-01 02:28:08 +00001081def tREVSH : // A8.6.136
1082 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1083 IIC_iUNAr,
1084 "revsh", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001085 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001086 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001087
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001088// Rotate right register
1089def tROR : // A8.6.139
1090 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1091 IIC_iMOVsr,
1092 "ror", "\t$Rdn, $Rm",
1093 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001094
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001095// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001096def tRSB : // A8.6.141
1097 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1098 IIC_iALUi,
1099 "rsb", "\t$Rd, $Rn, #0",
1100 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001101
David Goodwinc9ee1182009-06-25 22:49:55 +00001102// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001103let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001104def tSBC : // A8.6.151
1105 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1106 IIC_iALUr,
1107 "sbc", "\t$Rdn, $Rm",
1108 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001109
David Goodwinc9ee1182009-06-25 22:49:55 +00001110// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001111def tSUBi3 : // A8.6.210 T1
1112 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1113 IIC_iALUi,
1114 "sub", "\t$Rd, $Rm, $imm3",
1115 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001116 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001117 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001118}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001119
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001120def tSUBi8 : // A8.6.210 T2
1121 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1122 IIC_iALUi,
1123 "sub", "\t$Rdn, $imm8",
1124 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001125
Bill Wendling76f4e102010-12-01 01:20:15 +00001126// Subtract register
1127def tSUBrr : // A8.6.212
1128 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1129 IIC_iALUr,
1130 "sub", "\t$Rd, $Rn, $Rm",
1131 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001132
1133// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001134
Bill Wendling76f4e102010-12-01 01:20:15 +00001135// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001136def tSXTB : // A8.6.222
1137 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1138 IIC_iUNAr,
1139 "sxtb", "\t$Rd, $Rm",
1140 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1141 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001142
Bill Wendling1d045ee2010-12-01 02:28:08 +00001143// Sign-extend short
1144def tSXTH : // A8.6.224
1145 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1146 IIC_iUNAr,
1147 "sxth", "\t$Rd, $Rm",
1148 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1149 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001150
Bill Wendling1d045ee2010-12-01 02:28:08 +00001151// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001152let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001153def tTST : // A8.6.230
1154 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1155 "tst", "\t$Rn, $Rm",
1156 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001157
Bill Wendling1d045ee2010-12-01 02:28:08 +00001158// Zero-extend byte
1159def tUXTB : // A8.6.262
1160 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1161 IIC_iUNAr,
1162 "uxtb", "\t$Rd, $Rm",
1163 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1164 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001165
Bill Wendling1d045ee2010-12-01 02:28:08 +00001166// Zero-extend short
1167def tUXTH : // A8.6.264
1168 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1169 IIC_iUNAr,
1170 "uxth", "\t$Rd, $Rm",
1171 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1172 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001173
Jim Grosbach80dc1162010-02-16 21:23:02 +00001174// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001175// Expanded after instruction selection into a branch sequence.
1176let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001177 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001178 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001179 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001180 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001181
1182// tLEApcrel - Load a pc-relative address into a register without offending the
1183// assembler.
Jim Grosbachd40963c2010-12-14 22:28:03 +00001184
1185def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1186 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1187 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling67077412010-11-30 00:18:30 +00001188 bits<3> Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001189 bits<8> addr;
Bill Wendling67077412010-11-30 00:18:30 +00001190 let Inst{10-8} = Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001191 let Inst{7-0} = addr;
Bill Wendling67077412010-11-30 00:18:30 +00001192}
Evan Chenga8e29892007-01-19 07:51:42 +00001193
Jim Grosbachd40963c2010-12-14 22:28:03 +00001194let neverHasSideEffects = 1, isReMaterializable = 1 in
1195def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001196 2, IIC_iALUi, []>;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001197
1198def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1199 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001200 2, IIC_iALUi, []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001201
Evan Chenga8e29892007-01-19 07:51:42 +00001202//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001203// TLS Instructions
1204//
1205
1206// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbachff97eb02011-06-30 19:38:01 +00001207// This is a pseudo inst so that we can get the encoding right,
1208// complete with fixup for the aeabi_read_tp function.
1209let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson16884412011-07-13 23:22:26 +00001210def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Jim Grosbachff97eb02011-06-30 19:38:01 +00001211 [(set R0, ARMthread_pointer)]>;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001212
Bill Wendling0480e282010-12-01 02:36:55 +00001213//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001214// SJLJ Exception handling intrinsics
Owen Anderson18901d62011-05-11 17:00:48 +00001215//
Bill Wendling0480e282010-12-01 02:36:55 +00001216
1217// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1218// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1219// from some other function to get here, and we're using the stack frame for the
1220// containing function to save/restore registers, we can't keep anything live in
1221// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner7a2bdde2011-04-15 05:18:47 +00001222// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling0480e282010-12-01 02:36:55 +00001223// registers except for our own input by listing the relevant registers in
1224// Defs. By doing so, we also cause the prologue/epilogue code to actively
1225// preserve all of the callee-saved resgisters, which is exactly what we want.
1226// $val is a scratch register for our use.
Andrew Tricka1099f12011-06-07 00:08:49 +00001227let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001228 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1229def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson16884412011-07-13 23:22:26 +00001230 AddrModeNone, 0, NoItinerary, "","",
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001231 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001232
1233// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001234let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001235 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001236def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson16884412011-07-13 23:22:26 +00001237 AddrModeNone, 0, IndexModeNone,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001238 Pseudo, NoItinerary, "", "",
1239 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1240 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001241
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001242//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001243// Non-Instruction Patterns
1244//
1245
Jim Grosbach97a884d2010-12-07 20:41:06 +00001246// Comparisons
1247def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1248 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1249def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1250 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1251
Evan Cheng892837a2009-07-10 02:09:04 +00001252// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001253def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1254 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1255def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001256 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001257def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1258 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001259
1260// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001261def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1262 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1263def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1264 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1265def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1266 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001267
Evan Chenga8e29892007-01-19 07:51:42 +00001268// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001269def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1270def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001271
Evan Chengd85ac4d2007-01-27 02:29:45 +00001272// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001273def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1274 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001275
Evan Chenga8e29892007-01-19 07:51:42 +00001276// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001277def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001278 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001279def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001280 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001281
1282def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001283 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001284def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001285 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001286
1287// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001288def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1289 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1290def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1291 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001292
1293// zextload i1 -> zextload i8
Bill Wendlingf4caf692010-12-14 03:36:38 +00001294def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1295 (tLDRBr t_addrmode_rrs1:$addr)>;
1296def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1297 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001298
Evan Chengb60c02e2007-01-26 19:13:16 +00001299// extload -> zextload
Bill Wendlingf4caf692010-12-14 03:36:38 +00001300def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1301def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1302def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1303def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1304def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1305def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001306
Evan Cheng0e87e232009-08-28 00:31:43 +00001307// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001308// ldr{b|h} + sxt{b|h} instead.
Bill Wendling415af342010-12-15 00:58:57 +00001309def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1310 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1311 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001312def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1313 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001314 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling415af342010-12-15 00:58:57 +00001315def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1316 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1317 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001318def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1319 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001320 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001321
Bill Wendlingf4caf692010-12-14 03:36:38 +00001322def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1323 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling415af342010-12-15 00:58:57 +00001324def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1325 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1326def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1327 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1328def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1329 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001330
Evan Chenga8e29892007-01-19 07:51:42 +00001331// Large immediate handling.
1332
1333// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001334def : T1Pat<(i32 thumb_immshifted:$src),
1335 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1336 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001337
Evan Cheng9cb9e672009-06-27 02:26:13 +00001338def : T1Pat<(i32 imm0_255_comp:$src),
1339 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001340
1341// Pseudo instruction that combines ldr from constpool and add pc. This should
1342// be expanded into two instructions late to allow if-conversion and
1343// scheduling.
1344let isReMaterializable = 1 in
1345def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001346 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001347 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1348 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001349 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach53e3fc42011-07-08 17:40:42 +00001350
1351// Pseudo-instruction for merged POP and return.
1352// FIXME: remove when we have a way to marking a MI with these properties.
1353let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1354 hasExtraDefRegAllocReq = 1 in
1355def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +00001356 2, IIC_iPop_Br, [],
Jim Grosbach53e3fc42011-07-08 17:40:42 +00001357 (tPOP pred:$p, reglist:$regs)>;
1358
Jim Grosbachaa8d1b82011-07-08 22:25:23 +00001359// Indirect branch using "mov pc, $Rm"
1360let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach7e61a312011-07-08 22:33:49 +00001361 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001362 2, IIC_Br, [(brind GPR:$Rm)],
Jim Grosbach7e61a312011-07-08 22:33:49 +00001363 (tMOVr PC, GPR:$Rm, pred:$p)>;
Jim Grosbachaa8d1b82011-07-08 22:25:23 +00001364}