blob: cb242cec2c068237e5b1474814bdda228560797f [file] [log] [blame]
Bill Wendling9c258942010-12-01 02:36:55 +00001//===- ARMInstrThumb.td - Thumb support for ARM ------------*- tablegen -*-===//
Evan Cheng10043e22007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Cheng10043e22007-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 Lattner2a0a3b42010-12-23 18:28:41 +000019 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
Chris Lattner04336992010-03-19 05:33:51 +000020 SDNPVariadic]>;
Evan Cheng10043e22007-01-19 07:51:42 +000021
Evan Cheng10043e22007-01-19 07:51:42 +000022def imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson9f944592009-08-11 20:47:22 +000023 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000024}]>;
25def imm_comp_XFORM : SDNodeXForm<imm, [{
Owen Anderson9f944592009-08-11 20:47:22 +000026 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000027}]>;
28
Evan Cheng10043e22007-01-19 07:51:42 +000029def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000030 return (uint32_t)-N->getZExtValue() < 8;
Evan Cheng10043e22007-01-19 07:51:42 +000031}], imm_neg_XFORM>;
32
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +000033def imm0_255_asmoperand : AsmOperandClass { let Name = "Imm0_255"; }
34def imm0_255 : Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 256; }]> {
35 let ParserMatchClass = imm0_255_asmoperand;
36}
Evan Cheng10043e22007-01-19 07:51:42 +000037def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000038 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000039}]>;
40
Eric Christophera98cd222011-04-28 05:49:04 +000041def imm8_255 : ImmLeaf<i32, [{
42 return Imm >= 8 && Imm < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000043}]>;
44def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000045 unsigned Val = -N->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +000046 return Val >= 8 && Val < 256;
47}], imm_neg_XFORM>;
48
Bill Wendling9c258942010-12-01 02:36:55 +000049// Break imm's up into two pieces: an immediate + a left shift. This uses
50// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
51// to get the val/shift pieces.
Evan Cheng10043e22007-01-19 07:51:42 +000052def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000053 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Cheng10043e22007-01-19 07:51:42 +000054}]>;
55
56def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000057 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Owen Anderson9f944592009-08-11 20:47:22 +000058 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000059}]>;
60
61def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000062 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson9f944592009-08-11 20:47:22 +000063 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000064}]>;
65
Jim Grosbach509dc2a2010-12-14 22:28:03 +000066// ADR instruction labels.
67def t_adrlabel : Operand<i32> {
68 let EncoderMethod = "getThumbAdrLabelOpValue";
69}
70
Evan Chengb1852592009-11-19 06:57:41 +000071// Scaled 4 immediate.
72def t_imm_s4 : Operand<i32> {
73 let PrintMethod = "printThumbS4ImmOperand";
Benjamin Kramer3ceac212011-07-14 21:47:24 +000074 let OperandType = "OPERAND_IMMEDIATE";
Evan Chengb1852592009-11-19 06:57:41 +000075}
76
Evan Cheng10043e22007-01-19 07:51:42 +000077// Define Thumb specific addressing modes.
78
Benjamin Kramer3ceac212011-07-14 21:47:24 +000079let OperandType = "OPERAND_PCREL" in {
Jim Grosbache119da12010-12-10 18:21:33 +000080def t_brtarget : Operand<OtherVT> {
81 let EncoderMethod = "getThumbBRTargetOpValue";
82}
83
Jim Grosbach78485ad2010-12-10 17:13:40 +000084def t_bcctarget : Operand<i32> {
85 let EncoderMethod = "getThumbBCCTargetOpValue";
86}
87
Jim Grosbach529c7e82010-12-09 19:01:46 +000088def t_cbtarget : Operand<i32> {
Jim Grosbach62b68112010-12-09 19:04:53 +000089 let EncoderMethod = "getThumbCBTargetOpValue";
Bill Wendlinga7d6aa92010-12-08 23:01:43 +000090}
91
Jim Grosbach9e199462010-12-06 23:57:07 +000092def t_bltarget : Operand<i32> {
93 let EncoderMethod = "getThumbBLTargetOpValue";
94}
95
Bill Wendling3392bfc2010-12-09 00:39:08 +000096def t_blxtarget : Operand<i32> {
97 let EncoderMethod = "getThumbBLXTargetOpValue";
98}
Benjamin Kramer3ceac212011-07-14 21:47:24 +000099}
Bill Wendling3392bfc2010-12-09 00:39:08 +0000100
Bill Wendling092a7bd2010-12-14 03:36:38 +0000101def MemModeRegThumbAsmOperand : AsmOperandClass {
102 let Name = "MemModeRegThumb";
103 let SuperClasses = [];
104}
105
106def MemModeImmThumbAsmOperand : AsmOperandClass {
107 let Name = "MemModeImmThumb";
Bill Wendling811c9362010-11-30 07:44:32 +0000108 let SuperClasses = [];
109}
110
Evan Cheng10043e22007-01-19 07:51:42 +0000111// t_addrmode_rr := reg + reg
112//
113def t_addrmode_rr : Operand<i32>,
114 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000115 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Cheng10043e22007-01-19 07:51:42 +0000116 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachfde21102009-04-07 20:34:09 +0000117 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000118}
119
Bill Wendling092a7bd2010-12-14 03:36:38 +0000120// t_addrmode_rrs := reg + reg
Evan Cheng10043e22007-01-19 07:51:42 +0000121//
Bill Wendling092a7bd2010-12-14 03:36:38 +0000122def t_addrmode_rrs1 : Operand<i32>,
123 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
124 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
125 let PrintMethod = "printThumbAddrModeRROperand";
126 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
127 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Cheng10043e22007-01-19 07:51:42 +0000128}
Bill Wendling092a7bd2010-12-14 03:36:38 +0000129def t_addrmode_rrs2 : Operand<i32>,
130 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
131 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
132 let PrintMethod = "printThumbAddrModeRROperand";
133 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
134 let ParserMatchClass = MemModeRegThumbAsmOperand;
135}
136def t_addrmode_rrs4 : Operand<i32>,
137 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
138 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
139 let PrintMethod = "printThumbAddrModeRROperand";
140 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
141 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Cheng10043e22007-01-19 07:51:42 +0000142}
Evan Chengc0b73662007-01-23 22:59:13 +0000143
Bill Wendling092a7bd2010-12-14 03:36:38 +0000144// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc0b73662007-01-23 22:59:13 +0000145//
Bill Wendling092a7bd2010-12-14 03:36:38 +0000146def t_addrmode_is4 : Operand<i32>,
147 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
148 let EncoderMethod = "getAddrModeISOpValue";
149 let PrintMethod = "printThumbAddrModeImm5S4Operand";
150 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
151 let ParserMatchClass = MemModeImmThumbAsmOperand;
152}
153
154// t_addrmode_is2 := reg + imm5 * 2
155//
156def t_addrmode_is2 : Operand<i32>,
157 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
158 let EncoderMethod = "getAddrModeISOpValue";
159 let PrintMethod = "printThumbAddrModeImm5S2Operand";
160 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
161 let ParserMatchClass = MemModeImmThumbAsmOperand;
162}
163
164// t_addrmode_is1 := reg + imm5
165//
166def t_addrmode_is1 : Operand<i32>,
167 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
168 let EncoderMethod = "getAddrModeISOpValue";
169 let PrintMethod = "printThumbAddrModeImm5S1Operand";
170 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
171 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Cheng10043e22007-01-19 07:51:42 +0000172}
173
174// t_addrmode_sp := sp + imm8 * 4
175//
176def t_addrmode_sp : Operand<i32>,
177 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000178 let EncoderMethod = "getAddrModeThumbSPOpValue";
Evan Cheng10043e22007-01-19 07:51:42 +0000179 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesena94837d2010-01-13 00:43:06 +0000180 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000181 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Cheng10043e22007-01-19 07:51:42 +0000182}
183
Bill Wendling8a6449c2010-12-08 01:57:09 +0000184// t_addrmode_pc := <label> => pc + imm8 * 4
185//
186def t_addrmode_pc : Operand<i32> {
187 let EncoderMethod = "getAddrModePCOpValue";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000188 let ParserMatchClass = MemModeImmThumbAsmOperand;
Bill Wendling8a6449c2010-12-08 01:57:09 +0000189}
190
Evan Cheng10043e22007-01-19 07:51:42 +0000191//===----------------------------------------------------------------------===//
192// Miscellaneous Instructions.
193//
194
Jim Grosbach45fceea2010-02-22 23:10:38 +0000195// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
196// from removing one half of the matched pairs. That breaks PEI, which assumes
197// these will always be in pairs, and asserts if it finds otherwise. Better way?
198let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000199def tADJCALLSTACKUP :
Bill Wendling49a2e232010-11-19 22:02:18 +0000200 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
201 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
202 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000203
Jim Grosbach669f1d02009-03-27 23:06:27 +0000204def tADJCALLSTACKDOWN :
Bill Wendling49a2e232010-11-19 22:02:18 +0000205 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
206 [(ARMcallseq_start imm:$amt)]>,
207 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000208}
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000209
Bill Wendlingddce9f32010-11-30 00:50:22 +0000210// T1Disassembly - A simple class to make encoding some disassembly patterns
211// easier and less verbose.
Bill Wendling5da8cae2010-11-29 22:15:03 +0000212class T1Disassembly<bits<2> op1, bits<8> op2>
213 : T1Encoding<0b101111> {
214 let Inst{9-8} = op1;
215 let Inst{7-0} = op2;
216}
217
Johnny Chen90adefc2010-02-25 03:28:51 +0000218def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
219 [/* For disassembly only; pattern left blank */]>,
Bill Wendling5da8cae2010-11-29 22:15:03 +0000220 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chen90adefc2010-02-25 03:28:51 +0000221
Johnny Chen74cca5a2010-02-25 17:51:03 +0000222def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
223 [/* For disassembly only; pattern left blank */]>,
Bill Wendling5da8cae2010-11-29 22:15:03 +0000224 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chen74cca5a2010-02-25 17:51:03 +0000225
226def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
227 [/* For disassembly only; pattern left blank */]>,
Bill Wendling5da8cae2010-11-29 22:15:03 +0000228 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chen74cca5a2010-02-25 17:51:03 +0000229
230def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
231 [/* For disassembly only; pattern left blank */]>,
Bill Wendling5da8cae2010-11-29 22:15:03 +0000232 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chen74cca5a2010-02-25 17:51:03 +0000233
234def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
235 [/* For disassembly only; pattern left blank */]>,
Bill Wendling5da8cae2010-11-29 22:15:03 +0000236 T1Disassembly<0b11, 0x40>; // A8.6.157
237
238// The i32imm operand $val can be used by a debugger to store more information
239// about the breakpoint.
240def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
241 [/* For disassembly only; pattern left blank */]>,
242 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
243 // A8.6.22
244 bits<8> val;
245 let Inst{7-0} = val;
246}
Johnny Chen74cca5a2010-02-25 17:51:03 +0000247
Jim Grosbach39f93882011-07-22 17:52:23 +0000248def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
249 []>, T1Encoding<0b101101> {
250 bits<1> end;
Bill Wendling3acd0272010-11-21 10:55:23 +0000251 // A8.6.156
Johnny Chen74cca5a2010-02-25 17:51:03 +0000252 let Inst{9-5} = 0b10010;
Bill Wendling49a2e232010-11-19 22:02:18 +0000253 let Inst{4} = 1;
Jim Grosbach39f93882011-07-22 17:52:23 +0000254 let Inst{3} = end;
Bill Wendling49a2e232010-11-19 22:02:18 +0000255 let Inst{2-0} = 0b000;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000256}
257
Johnny Chen44908a52010-03-02 18:14:57 +0000258// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000259def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
260 NoItinerary, "cps$imod $iflags",
261 [/* For disassembly only; pattern left blank */]>,
Bill Wendling775899e2010-11-29 00:18:15 +0000262 T1Misc<0b0110011> {
263 // A8.6.38 & B6.1.1
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000264 bit imod;
265 bits<3> iflags;
266
267 let Inst{4} = imod;
268 let Inst{3} = 0;
269 let Inst{2-0} = iflags;
Bill Wendling775899e2010-11-29 00:18:15 +0000270}
Johnny Chen44908a52010-03-02 18:14:57 +0000271
Evan Cheng7cc6aca2009-08-04 23:47:55 +0000272// For both thumb1 and thumb2.
Chris Lattner9492c172010-10-31 19:15:18 +0000273let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +0000274def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendlinga82fb712010-11-19 22:37:33 +0000275 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chenc28e6292009-12-15 17:24:14 +0000276 T1Special<{0,0,?,?}> {
Bill Wendlingddce9f32010-11-30 00:50:22 +0000277 // A8.6.6
Bill Wendlinga82fb712010-11-19 22:37:33 +0000278 bits<3> dst;
Bill Wendlingddce9f32010-11-30 00:50:22 +0000279 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendlinga82fb712010-11-19 22:37:33 +0000280 let Inst{2-0} = dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000281}
Evan Cheng10043e22007-01-19 07:51:42 +0000282
Bill Wendlingddce9f32010-11-30 00:50:22 +0000283// PC relative add (ADR).
Evan Chengb1852592009-11-19 06:57:41 +0000284def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendlinga82fb712010-11-19 22:37:33 +0000285 "add\t$dst, pc, $rhs", []>,
286 T1Encoding<{1,0,1,0,0,?}> {
287 // A6.2 & A8.6.10
288 bits<3> dst;
289 bits<8> rhs;
290 let Inst{10-8} = dst;
291 let Inst{7-0} = rhs;
Jim Grosbachfef37282010-08-30 19:49:58 +0000292}
Evan Chengb566ab72009-06-25 01:05:06 +0000293
Bill Wendlinga82fb712010-11-19 22:37:33 +0000294// ADD <Rd>, sp, #<imm8>
295// This is rematerializable, which is particularly useful for taking the
296// address of locals.
297let isReMaterializable = 1 in
298def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
299 "add\t$dst, $sp, $rhs", []>,
300 T1Encoding<{1,0,1,0,1,?}> {
301 // A6.2 & A8.6.8
302 bits<3> dst;
303 bits<8> rhs;
304 let Inst{10-8} = dst;
305 let Inst{7-0} = rhs;
306}
307
308// ADD sp, sp, #<imm7>
Evan Chengb1852592009-11-19 06:57:41 +0000309def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chenc28e6292009-12-15 17:24:14 +0000310 "add\t$dst, $rhs", []>,
Bill Wendlinga82fb712010-11-19 22:37:33 +0000311 T1Misc<{0,0,0,0,0,?,?}> {
312 // A6.2.5 & A8.6.8
313 bits<7> rhs;
314 let Inst{6-0} = rhs;
315}
Evan Chengb566ab72009-06-25 01:05:06 +0000316
Bill Wendlinga82fb712010-11-19 22:37:33 +0000317// SUB sp, sp, #<imm7>
318// FIXME: The encoding and the ASM string don't match up.
Evan Chengb1852592009-11-19 06:57:41 +0000319def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chenc28e6292009-12-15 17:24:14 +0000320 "sub\t$dst, $rhs", []>,
Bill Wendlinga82fb712010-11-19 22:37:33 +0000321 T1Misc<{0,0,0,0,1,?,?}> {
322 // A6.2.5 & A8.6.214
323 bits<7> rhs;
324 let Inst{6-0} = rhs;
325}
Evan Chengb972e562009-08-07 00:34:42 +0000326
Bill Wendlinga82fb712010-11-19 22:37:33 +0000327// ADD <Rm>, sp
David Goodwina7c2dfb2009-08-19 18:00:44 +0000328def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chenc28e6292009-12-15 17:24:14 +0000329 "add\t$dst, $rhs", []>,
330 T1Special<{0,0,?,?}> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000331 // A8.6.9 Encoding T1
332 bits<4> dst;
333 let Inst{7} = dst{3};
334 let Inst{6-3} = 0b1101;
335 let Inst{2-0} = dst{2-0};
Johnny Chenc28e6292009-12-15 17:24:14 +0000336}
Evan Chengb972e562009-08-07 00:34:42 +0000337
Bill Wendlinga82fb712010-11-19 22:37:33 +0000338// ADD sp, <Rm>
David Goodwina7c2dfb2009-08-19 18:00:44 +0000339def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chenc28e6292009-12-15 17:24:14 +0000340 "add\t$dst, $rhs", []>,
341 T1Special<{0,0,?,?}> {
342 // A8.6.9 Encoding T2
Bill Wendlinga82fb712010-11-19 22:37:33 +0000343 bits<4> dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000344 let Inst{7} = 1;
Bill Wendlinga82fb712010-11-19 22:37:33 +0000345 let Inst{6-3} = dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000346 let Inst{2-0} = 0b101;
347}
Evan Chengb972e562009-08-07 00:34:42 +0000348
Evan Cheng10043e22007-01-19 07:51:42 +0000349//===----------------------------------------------------------------------===//
350// Control Flow Instructions.
351//
352
Bob Wilson73789b82009-10-28 18:26:41 +0000353// Indirect branches
354let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000355 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
356 T1Special<{1,1,0,?}> {
357 // A6.2.3 & A8.6.25
358 bits<4> Rm;
359 let Inst{6-3} = Rm;
360 let Inst{2-0} = 0b000;
361 }
Bob Wilson73789b82009-10-28 18:26:41 +0000362}
363
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000364let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson651b2302011-07-13 23:22:26 +0000365 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Jim Grosbach74719372011-07-08 21:50:04 +0000366 [(ARMretflag)], (tBX LR, pred:$p)>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000367
368 // Alternative return instruction used by vararg functions.
Jim Grosbach74719372011-07-08 21:50:04 +0000369 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000370 2, IIC_Br, [],
Jim Grosbach74719372011-07-08 21:50:04 +0000371 (tBX GPR:$Rm, pred:$p)>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000372}
373
Bill Wendling9c258942010-12-01 02:36:55 +0000374// All calls clobber the non-callee saved registers. SP is marked as a use to
375// prevent stack-pointer assignments that appear immediately before calls from
376// potentially appearing dead.
Jim Grosbach669f1d02009-03-27 23:06:27 +0000377let isCall = 1,
Evan Cheng9a133f62010-11-29 22:43:27 +0000378 // On non-Darwin platforms R9 is callee-saved.
Jakob Stoklund Olesenf8be3852011-05-03 22:31:24 +0000379 Defs = [R0, R1, R2, R3, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng9a133f62010-11-29 22:43:27 +0000380 Uses = [SP] in {
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000381 // Also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000382 def tBL : TIx2<0b11110, 0b11, 1,
Owen Anderson64d53622011-07-18 18:50:52 +0000383 (outs), (ins pred:$p, t_bltarget:$func, variable_ops), IIC_Br,
384 "bl${p}\t$func",
Johnny Chenc28e6292009-12-15 17:24:14 +0000385 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling4d8ff862010-12-03 01:55:47 +0000386 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach9e199462010-12-06 23:57:07 +0000387 bits<21> func;
388 let Inst{25-16} = func{20-11};
Jim Grosbache4fee202010-12-03 22:33:42 +0000389 let Inst{13} = 1;
390 let Inst{11} = 1;
Jim Grosbach9e199462010-12-06 23:57:07 +0000391 let Inst{10-0} = func{10-0};
Bill Wendling4d8ff862010-12-03 01:55:47 +0000392 }
Evan Cheng175bd142009-07-29 21:26:42 +0000393
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000394 // ARMv5T and above, also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000395 def tBLXi : TIx2<0b11110, 0b11, 0,
Owen Anderson64d53622011-07-18 18:50:52 +0000396 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops), IIC_Br,
397 "blx${p}\t$func",
Johnny Chenc28e6292009-12-15 17:24:14 +0000398 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbache4fee202010-12-03 22:33:42 +0000399 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach9e199462010-12-06 23:57:07 +0000400 bits<21> func;
401 let Inst{25-16} = func{20-11};
Jim Grosbache4fee202010-12-03 22:33:42 +0000402 let Inst{13} = 1;
403 let Inst{11} = 1;
Jim Grosbach9e199462010-12-06 23:57:07 +0000404 let Inst{10-1} = func{10-1};
405 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbache4fee202010-12-03 22:33:42 +0000406 }
Evan Cheng175bd142009-07-29 21:26:42 +0000407
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000408 // Also used for Thumb2
Owen Anderson64d53622011-07-18 18:50:52 +0000409 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
410 "blx${p}\t$func",
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000411 [(ARMtcall GPR:$func)]>,
Johnny Chenc28e6292009-12-15 17:24:14 +0000412 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
Owen Andersonb7456232011-05-11 17:00:48 +0000413 T1Special<{1,1,1,?}> { // A6.2.3 & A8.6.24;
414 bits<4> func;
415 let Inst{6-3} = func;
416 let Inst{2-0} = 0b000;
417 }
Evan Cheng175bd142009-07-29 21:26:42 +0000418
Lauro Ramos Venancio143b0df2007-03-27 16:19:21 +0000419 // ARMv4T
Cameron Zwaricha946f472011-05-25 21:53:50 +0000420 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +0000421 4, IIC_Br,
Evan Cheng175bd142009-07-29 21:26:42 +0000422 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +0000423 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng175bd142009-07-29 21:26:42 +0000424}
425
Evan Cheng175bd142009-07-29 21:26:42 +0000426let isCall = 1,
Evan Cheng9a133f62010-11-29 22:43:27 +0000427 // On Darwin R9 is call-clobbered.
428 // R7 is marked as a use to prevent frame-pointer assignments from being
429 // moved above / below calls.
Jakob Stoklund Olesenf8be3852011-05-03 22:31:24 +0000430 Defs = [R0, R1, R2, R3, R9, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng9a133f62010-11-29 22:43:27 +0000431 Uses = [R7, SP] in {
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000432 // Also used for Thumb2
Owen Anderson64d53622011-07-18 18:50:52 +0000433 def tBLr9 : tPseudoExpand<(outs), (ins pred:$p, t_bltarget:$func, variable_ops),
434 4, IIC_Br, [(ARMtcall tglobaladdr:$func)],
435 (tBL pred:$p, t_bltarget:$func)>,
436 Requires<[IsThumb, IsDarwin]>;
Evan Cheng175bd142009-07-29 21:26:42 +0000437
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000438 // ARMv5T and above, also used for Thumb2
Owen Anderson64d53622011-07-18 18:50:52 +0000439 def tBLXi_r9 : tPseudoExpand<(outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
440 4, IIC_Br, [(ARMcall tglobaladdr:$func)],
441 (tBLXi pred:$p, t_blxtarget:$func)>,
442 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng175bd142009-07-29 21:26:42 +0000443
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000444 // Also used for Thumb2
Owen Anderson64d53622011-07-18 18:50:52 +0000445 def tBLXr_r9 : tPseudoExpand<(outs), (ins pred:$p, GPR:$func, variable_ops),
446 2, IIC_Br, [(ARMtcall GPR:$func)],
447 (tBLXr pred:$p, GPR:$func)>,
448 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng175bd142009-07-29 21:26:42 +0000449
450 // ARMv4T
Cameron Zwaricha946f472011-05-25 21:53:50 +0000451 def tBXr9_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +0000452 4, IIC_Br,
Johnny Chenc28e6292009-12-15 17:24:14 +0000453 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +0000454 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000455}
456
Bill Wendling9c258942010-12-01 02:36:55 +0000457let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
458 let isPredicable = 1 in
Jim Grosbache119da12010-12-10 18:21:33 +0000459 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
Bill Wendling9c258942010-12-01 02:36:55 +0000460 "b\t$target", [(br bb:$target)]>,
Jim Grosbache119da12010-12-10 18:21:33 +0000461 T1Encoding<{1,1,1,0,0,?}> {
462 bits<11> target;
463 let Inst{10-0} = target;
464 }
Evan Cheng10043e22007-01-19 07:51:42 +0000465
Evan Cheng863736b2007-01-30 01:13:37 +0000466 // Far jump
Jim Grosbachb5743b92010-12-16 19:11:16 +0000467 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
468 // the clobber of LR.
Evan Cheng317bd7a2009-08-07 05:45:07 +0000469 let Defs = [LR] in
Owen Anderson64d53622011-07-18 18:50:52 +0000470 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
471 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>;
Evan Cheng863736b2007-01-30 01:13:37 +0000472
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000473 def tBR_JTr : tPseudoInst<(outs),
474 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
Owen Anderson651b2302011-07-13 23:22:26 +0000475 0, IIC_Br,
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000476 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
477 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chen466231a2009-12-16 02:32:54 +0000478 }
Evan Cheng0701c5a2007-01-27 02:29:45 +0000479}
480
Evan Chengaa3b8012007-07-05 07:13:32 +0000481// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach669f1d02009-03-27 23:06:27 +0000482// a two-value operand where a dag node expects two operands. :(
Evan Chengac1591b2007-07-21 00:34:19 +0000483let isBranch = 1, isTerminator = 1 in
Jim Grosbach78485ad2010-12-10 17:13:40 +0000484 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000485 "b${p}\t$target",
Johnny Chenc28e6292009-12-15 17:24:14 +0000486 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Eric Christopher9b67db82011-05-27 03:50:53 +0000487 T1BranchCond<{1,1,0,1}> {
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000488 bits<4> p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000489 bits<8> target;
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000490 let Inst{11-8} = p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000491 let Inst{7-0} = target;
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000492}
Evan Cheng10043e22007-01-19 07:51:42 +0000493
Evan Cheng6f29ad92009-10-31 23:46:45 +0000494// Compare and branch on zero / non-zero
495let isBranch = 1, isTerminator = 1 in {
Jim Grosbach529c7e82010-12-09 19:01:46 +0000496 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling1825cc72010-11-19 23:14:32 +0000497 "cbz\t$Rn, $target", []>,
498 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling775899e2010-11-29 00:18:15 +0000499 // A8.6.27
Bill Wendling1825cc72010-11-19 23:14:32 +0000500 bits<6> target;
501 bits<3> Rn;
502 let Inst{9} = target{5};
503 let Inst{7-3} = target{4-0};
504 let Inst{2-0} = Rn;
505 }
Evan Cheng6f29ad92009-10-31 23:46:45 +0000506
Jim Grosbach529c7e82010-12-09 19:01:46 +0000507 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
Johnny Chenc28e6292009-12-15 17:24:14 +0000508 "cbnz\t$cmp, $target", []>,
Bill Wendling1825cc72010-11-19 23:14:32 +0000509 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling775899e2010-11-29 00:18:15 +0000510 // A8.6.27
Bill Wendling1825cc72010-11-19 23:14:32 +0000511 bits<6> target;
512 bits<3> Rn;
513 let Inst{9} = target{5};
514 let Inst{7-3} = target{4-0};
515 let Inst{2-0} = Rn;
516 }
Evan Cheng6f29ad92009-10-31 23:46:45 +0000517}
518
Jim Grosbach166cd882011-07-08 20:13:35 +0000519// Tail calls
520let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
521 // Darwin versions.
522 let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
523 Uses = [SP] in {
Jim Grosbach4af86472011-07-08 20:32:21 +0000524 // tTAILJMPd: Darwin version uses a Thumb2 branch (no Thumb1 tail calls
525 // on Darwin), so it's in ARMInstrThumb2.td.
Jim Grosbach204c1282011-07-08 20:39:19 +0000526 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +0000527 4, IIC_Br, [],
Jim Grosbach204c1282011-07-08 20:39:19 +0000528 (tBX GPR:$dst, (ops 14, zero_reg))>,
529 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000530 }
531 // Non-Darwin versions (the difference is R9).
532 let Defs = [R0, R1, R2, R3, R12, QQQQ0, QQQQ2, QQQQ3, PC],
533 Uses = [SP] in {
Jim Grosbach4af86472011-07-08 20:32:21 +0000534 def tTAILJMPdND : tPseudoExpand<(outs), (ins t_brtarget:$dst, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +0000535 4, IIC_Br, [],
Jim Grosbach4af86472011-07-08 20:32:21 +0000536 (tB t_brtarget:$dst)>,
537 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbach204c1282011-07-08 20:39:19 +0000538 def tTAILJMPrND : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +0000539 4, IIC_Br, [],
Jim Grosbach204c1282011-07-08 20:39:19 +0000540 (tBX GPR:$dst, (ops 14, zero_reg))>,
541 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000542 }
543}
544
545
Johnny Chen57656da2010-02-25 02:21:11 +0000546// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
547// A8.6.16 B: Encoding T1
548// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng9a133f62010-11-29 22:43:27 +0000549let isCall = 1, Uses = [SP] in
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000550def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
551 "svc", "\t$imm", []>, Encoding16 {
552 bits<8> imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000553 let Inst{15-12} = 0b1101;
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000554 let Inst{11-8} = 0b1111;
555 let Inst{7-0} = imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000556}
557
Bill Wendling811c9362010-11-30 07:44:32 +0000558// The assembler uses 0xDEFE for a trap instruction.
Evan Cheng2fa5a7e2010-05-11 07:26:32 +0000559let isBarrier = 1, isTerminator = 1 in
Owen Andersonb7456232011-05-11 17:00:48 +0000560def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach85030542010-09-23 18:05:37 +0000561 "trap", [(trap)]>, Encoding16 {
Bill Wendling3acd0272010-11-21 10:55:23 +0000562 let Inst = 0xdefe;
Johnny Chen57656da2010-02-25 02:21:11 +0000563}
564
Evan Cheng10043e22007-01-19 07:51:42 +0000565//===----------------------------------------------------------------------===//
566// Load Store Instructions.
567//
568
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000569// Loads: reg/reg and reg/imm5
Dan Gohman8c5d6832010-02-27 23:47:46 +0000570let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000571multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
572 Operand AddrMode_r, Operand AddrMode_i,
573 AddrMode am, InstrItinClass itin_r,
574 InstrItinClass itin_i, string asm,
575 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000576 def r : // reg/reg
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000577 T1pILdStEncode<reg_opc,
578 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
579 am, itin_r, asm, "\t$Rt, $addr",
580 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling5ab38b52010-12-14 23:42:48 +0000581 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000582 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
583 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
584 am, itin_i, asm, "\t$Rt, $addr",
585 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
586}
587// Stores: reg/reg and reg/imm5
588multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
589 Operand AddrMode_r, Operand AddrMode_i,
590 AddrMode am, InstrItinClass itin_r,
591 InstrItinClass itin_i, string asm,
592 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000593 def r : // reg/reg
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000594 T1pILdStEncode<reg_opc,
595 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
596 am, itin_r, asm, "\t$Rt, $addr",
597 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling5ab38b52010-12-14 23:42:48 +0000598 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000599 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
600 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
601 am, itin_i, asm, "\t$Rt, $addr",
602 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
603}
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000604
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000605// A8.6.57 & A8.6.60
606defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
607 t_addrmode_is4, AddrModeT1_4,
608 IIC_iLoad_r, IIC_iLoad_i, "ldr",
609 UnOpFrag<(load node:$Src)>>;
Evan Cheng10043e22007-01-19 07:51:42 +0000610
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000611// A8.6.64 & A8.6.61
612defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
613 t_addrmode_is1, AddrModeT1_1,
614 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
615 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000616
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000617// A8.6.76 & A8.6.73
618defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
619 t_addrmode_is2, AddrModeT1_2,
620 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
621 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc0b73662007-01-23 22:59:13 +0000622
Evan Cheng0794c6a2009-07-11 07:08:13 +0000623let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000624def tLDRSB : // A8.6.80
Bill Wendlingc25545a2010-12-01 01:38:08 +0000625 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
626 AddrModeT1_1, IIC_iLoad_bh_r,
627 "ldrsb", "\t$dst, $addr",
628 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000629
Evan Cheng0794c6a2009-07-11 07:08:13 +0000630let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000631def tLDRSH : // A8.6.84
Bill Wendlingc25545a2010-12-01 01:38:08 +0000632 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
633 AddrModeT1_2, IIC_iLoad_bh_r,
634 "ldrsh", "\t$dst, $addr",
635 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000636
Dan Gohman69cc2cb2008-12-03 18:15:48 +0000637let canFoldAsLoad = 1 in
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000638def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendling6217ecd2010-12-15 23:31:24 +0000639 "ldr", "\t$Rt, $addr",
640 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000641 T1LdStSP<{1,?,?}> {
642 bits<3> Rt;
643 bits<8> addr;
644 let Inst{10-8} = Rt;
645 let Inst{7-0} = addr;
646}
Evan Cheng1526ba52007-01-24 08:53:17 +0000647
648// Load tconstpool
Evan Cheng3f1a9242009-11-04 00:00:39 +0000649// FIXME: Use ldr.n to work around a Darwin assembler bug.
Owen Andersoneab46252011-07-18 22:14:02 +0000650let canFoldAsLoad = 1, isReMaterializable = 1, isCodeGenOnly = 1 in
Bill Wendling8a6449c2010-12-08 01:57:09 +0000651def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling05632cb2010-11-30 23:54:45 +0000652 "ldr", ".n\t$Rt, $addr",
653 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
654 T1Encoding<{0,1,0,0,1,?}> {
655 // A6.2 & A8.6.59
656 bits<3> Rt;
Bill Wendling8a6449c2010-12-08 01:57:09 +0000657 bits<8> addr;
Bill Wendling05632cb2010-11-30 23:54:45 +0000658 let Inst{10-8} = Rt;
Bill Wendling8a6449c2010-12-08 01:57:09 +0000659 let Inst{7-0} = addr;
Bill Wendling05632cb2010-11-30 23:54:45 +0000660}
Evan Chengee2763f2007-03-19 07:20:03 +0000661
Johnny Chen57c89282011-04-22 19:12:43 +0000662// FIXME: Remove this entry when the above ldr.n workaround is fixed.
663// For disassembly use only.
664def tLDRpciDIS : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
665 "ldr", "\t$Rt, $addr",
666 [/* disassembly only */]>,
667 T1Encoding<{0,1,0,0,1,?}> {
668 // A6.2 & A8.6.59
669 bits<3> Rt;
670 bits<8> addr;
671 let Inst{10-8} = Rt;
672 let Inst{7-0} = addr;
673}
674
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000675// A8.6.194 & A8.6.192
676defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
677 t_addrmode_is4, AddrModeT1_4,
678 IIC_iStore_r, IIC_iStore_i, "str",
679 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Cheng10043e22007-01-19 07:51:42 +0000680
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000681// A8.6.197 & A8.6.195
682defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
683 t_addrmode_is1, AddrModeT1_1,
684 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
685 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc0b73662007-01-23 22:59:13 +0000686
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000687// A8.6.207 & A8.6.205
688defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000689 t_addrmode_is2, AddrModeT1_2,
690 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
691 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000692
Evan Cheng10043e22007-01-19 07:51:42 +0000693
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000694def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000695 "str", "\t$Rt, $addr",
696 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000697 T1LdStSP<{0,?,?}> {
698 bits<3> Rt;
699 bits<8> addr;
700 let Inst{10-8} = Rt;
701 let Inst{7-0} = addr;
702}
Evan Chengec13f8262007-02-07 00:06:56 +0000703
Evan Cheng10043e22007-01-19 07:51:42 +0000704//===----------------------------------------------------------------------===//
705// Load / store multiple Instructions.
706//
707
Bill Wendlinge69afc62010-11-13 09:09:38 +0000708multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
709 InstrItinClass itin_upd, bits<6> T1Enc,
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000710 bit L_bit, string baseOpc> {
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000711 def IA :
Bill Wendlinge69afc62010-11-13 09:09:38 +0000712 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000713 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000714 T1Encoding<T1Enc> {
715 bits<3> Rn;
716 bits<8> regs;
717 let Inst{10-8} = Rn;
718 let Inst{7-0} = regs;
719 }
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000720
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000721 def IA_UPD :
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000722 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
723 "$Rn = $wb", itin_upd>,
724 PseudoInstExpansion<(!cast<Instruction>(!strconcat(baseOpc, "IA"))
725 GPR:$Rn, pred:$p, reglist:$regs)> {
726 let Size = 2;
727 let OutOperandList = (outs GPR:$wb);
728 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
729 let Pattern = [];
730 let isCodeGenOnly = 1;
731 let isPseudo = 1;
732 list<Predicate> Predicates = [IsThumb];
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000733 }
Bill Wendlinge69afc62010-11-13 09:09:38 +0000734}
735
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000736// These require base address to be written back or one of the loaded regs.
Bill Wendling705ec772010-11-13 10:57:02 +0000737let neverHasSideEffects = 1 in {
738
739let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
740defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000741 {1,1,0,0,1,?}, 1, "tLDM">;
Bill Wendling705ec772010-11-13 10:57:02 +0000742
743let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
744defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
Owen Anderson83c6c4f2011-07-18 23:25:34 +0000745 {1,1,0,0,0,?}, 0, "tSTM">;
Owen Andersonb7456232011-05-11 17:00:48 +0000746
Bill Wendling705ec772010-11-13 10:57:02 +0000747} // neverHasSideEffects
Evan Chengcc9ca352009-08-11 21:11:32 +0000748
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000749let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling945b7762010-11-19 01:33:10 +0000750def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000751 IIC_iPop,
Bill Wendling945b7762010-11-19 01:33:10 +0000752 "pop${p}\t$regs", []>,
753 T1Misc<{1,1,0,?,?,?,?}> {
754 bits<16> regs;
Bill Wendling945b7762010-11-19 01:33:10 +0000755 let Inst{8} = regs{15};
756 let Inst{7-0} = regs{7-0};
757}
Evan Chengcc9ca352009-08-11 21:11:32 +0000758
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000759let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000760def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000761 IIC_iStore_m,
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000762 "push${p}\t$regs", []>,
763 T1Misc<{0,1,0,?,?,?,?}> {
764 bits<16> regs;
765 let Inst{8} = regs{14};
766 let Inst{7-0} = regs{7-0};
767}
Evan Cheng10043e22007-01-19 07:51:42 +0000768
769//===----------------------------------------------------------------------===//
770// Arithmetic Instructions.
771//
772
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000773// Helper classes for encoding T1pI patterns:
774class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
775 string opc, string asm, list<dag> pattern>
776 : T1pI<oops, iops, itin, opc, asm, pattern>,
777 T1DataProcessing<opA> {
778 bits<3> Rm;
779 bits<3> Rn;
780 let Inst{5-3} = Rm;
781 let Inst{2-0} = Rn;
782}
783class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
784 string opc, string asm, list<dag> pattern>
785 : T1pI<oops, iops, itin, opc, asm, pattern>,
786 T1Misc<opA> {
787 bits<3> Rm;
788 bits<3> Rd;
789 let Inst{5-3} = Rm;
790 let Inst{2-0} = Rd;
791}
792
Bill Wendling490240a2010-12-01 01:20:15 +0000793// Helper classes for encoding T1sI patterns:
794class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
795 string opc, string asm, list<dag> pattern>
796 : T1sI<oops, iops, itin, opc, asm, pattern>,
797 T1DataProcessing<opA> {
798 bits<3> Rd;
799 bits<3> Rn;
800 let Inst{5-3} = Rn;
801 let Inst{2-0} = Rd;
802}
803class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
804 string opc, string asm, list<dag> pattern>
805 : T1sI<oops, iops, itin, opc, asm, pattern>,
806 T1General<opA> {
807 bits<3> Rm;
808 bits<3> Rn;
809 bits<3> Rd;
810 let Inst{8-6} = Rm;
811 let Inst{5-3} = Rn;
812 let Inst{2-0} = Rd;
813}
814class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
815 string opc, string asm, list<dag> pattern>
816 : T1sI<oops, iops, itin, opc, asm, pattern>,
817 T1General<opA> {
818 bits<3> Rd;
819 bits<3> Rm;
820 let Inst{5-3} = Rm;
821 let Inst{2-0} = Rd;
822}
823
824// Helper classes for encoding T1sIt patterns:
Bill Wendling4915f562010-12-01 00:48:44 +0000825class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
826 string opc, string asm, list<dag> pattern>
827 : T1sIt<oops, iops, itin, opc, asm, pattern>,
828 T1DataProcessing<opA> {
Bill Wendling05632cb2010-11-30 23:54:45 +0000829 bits<3> Rdn;
830 bits<3> Rm;
Bill Wendling4915f562010-12-01 00:48:44 +0000831 let Inst{5-3} = Rm;
832 let Inst{2-0} = Rdn;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000833}
Bill Wendling4915f562010-12-01 00:48:44 +0000834class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
835 string opc, string asm, list<dag> pattern>
836 : T1sIt<oops, iops, itin, opc, asm, pattern>,
837 T1General<opA> {
838 bits<3> Rdn;
839 bits<8> imm8;
840 let Inst{10-8} = Rdn;
841 let Inst{7-0} = imm8;
842}
843
844// Add with carry register
845let isCommutable = 1, Uses = [CPSR] in
846def tADC : // A8.6.2
847 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
848 "adc", "\t$Rdn, $Rm",
849 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Chengf40b9002007-01-27 00:07:15 +0000850
David Goodwine85169c2009-06-25 22:49:55 +0000851// Add immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000852def tADDi3 : // A8.6.4 T1
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000853 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
854 IIC_iALUi,
Bill Wendling490240a2010-12-01 01:20:15 +0000855 "add", "\t$Rd, $Rm, $imm3",
856 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendlingfe1de032010-11-20 01:00:29 +0000857 bits<3> imm3;
858 let Inst{8-6} = imm3;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000859}
Evan Cheng10043e22007-01-19 07:51:42 +0000860
Bill Wendling4915f562010-12-01 00:48:44 +0000861def tADDi8 : // A8.6.4 T2
862 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
863 IIC_iALUi,
864 "add", "\t$Rdn, $imm8",
865 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000866
David Goodwine85169c2009-06-25 22:49:55 +0000867// Add register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000868let isCommutable = 1 in
Bill Wendling490240a2010-12-01 01:20:15 +0000869def tADDrr : // A8.6.6 T1
870 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
871 IIC_iALUr,
872 "add", "\t$Rd, $Rn, $Rm",
873 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000874
Evan Chengd93b5b62009-06-12 20:46:18 +0000875let neverHasSideEffects = 1 in
Bill Wendling7c646b92010-12-01 01:32:02 +0000876def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
877 "add", "\t$Rdn, $Rm", []>,
Bill Wendling284326b2010-11-20 01:18:47 +0000878 T1Special<{0,0,?,?}> {
879 // A8.6.6 T2
Bill Wendling7c646b92010-12-01 01:32:02 +0000880 bits<4> Rdn;
881 bits<4> Rm;
882 let Inst{7} = Rdn{3};
883 let Inst{6-3} = Rm;
884 let Inst{2-0} = Rdn{2-0};
Bill Wendling284326b2010-11-20 01:18:47 +0000885}
Evan Cheng10043e22007-01-19 07:51:42 +0000886
Bill Wendling284326b2010-11-20 01:18:47 +0000887// AND register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000888let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000889def tAND : // A8.6.12
890 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
891 IIC_iBITr,
892 "and", "\t$Rdn, $Rm",
893 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000894
David Goodwine85169c2009-06-25 22:49:55 +0000895// ASR immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000896def tASRri : // A8.6.14
897 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
898 IIC_iMOVsi,
899 "asr", "\t$Rd, $Rm, $imm5",
900 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000901 bits<5> imm5;
902 let Inst{10-6} = imm5;
Bill Wendling284326b2010-11-20 01:18:47 +0000903}
Evan Cheng10043e22007-01-19 07:51:42 +0000904
David Goodwine85169c2009-06-25 22:49:55 +0000905// ASR register
Bill Wendling4915f562010-12-01 00:48:44 +0000906def tASRrr : // A8.6.15
907 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
908 IIC_iMOVsr,
909 "asr", "\t$Rdn, $Rm",
910 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000911
David Goodwine85169c2009-06-25 22:49:55 +0000912// BIC register
Bill Wendling4915f562010-12-01 00:48:44 +0000913def tBIC : // A8.6.20
914 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
915 IIC_iBITr,
916 "bic", "\t$Rdn, $Rm",
917 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000918
David Goodwine85169c2009-06-25 22:49:55 +0000919// CMN register
Gabor Greif22f69222010-09-14 22:00:50 +0000920let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach267430f2010-01-22 00:08:13 +0000921//FIXME: Disable CMN, as CCodes are backwards from compare expectations
922// Compare-to-zero still works out, just not the relationals
Bill Wendling9c258942010-12-01 02:36:55 +0000923//def tCMN : // A8.6.33
924// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
925// IIC_iCMPr,
926// "cmn", "\t$lhs, $rhs",
927// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000928
929def tCMNz : // A8.6.33
930 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
931 IIC_iCMPr,
932 "cmn", "\t$Rn, $Rm",
933 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
934
935} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +0000936
David Goodwine85169c2009-06-25 22:49:55 +0000937// CMP immediate
Gabor Greif22f69222010-09-14 22:00:50 +0000938let isCompare = 1, Defs = [CPSR] in {
Bill Wendlingc31de252010-11-20 22:52:33 +0000939def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
940 "cmp", "\t$Rn, $imm8",
941 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
942 T1General<{1,0,1,?,?}> {
943 // A8.6.35
944 bits<3> Rn;
945 bits<8> imm8;
946 let Inst{10-8} = Rn;
947 let Inst{7-0} = imm8;
948}
949
David Goodwine85169c2009-06-25 22:49:55 +0000950// CMP register
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000951def tCMPr : // A8.6.36 T1
952 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
953 IIC_iCMPr,
954 "cmp", "\t$Rn, $Rm",
955 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
956
Bill Wendling775899e2010-11-29 00:18:15 +0000957def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
958 "cmp", "\t$Rn, $Rm", []>,
959 T1Special<{0,1,?,?}> {
960 // A8.6.36 T2
961 bits<4> Rm;
962 bits<4> Rn;
963 let Inst{7} = Rn{3};
964 let Inst{6-3} = Rm;
965 let Inst{2-0} = Rn{2-0};
966}
Bill Wendlingc31de252010-11-20 22:52:33 +0000967} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +0000968
Evan Cheng10043e22007-01-19 07:51:42 +0000969
David Goodwine85169c2009-06-25 22:49:55 +0000970// XOR register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000971let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000972def tEOR : // A8.6.45
973 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
974 IIC_iBITr,
975 "eor", "\t$Rdn, $Rm",
976 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000977
David Goodwine85169c2009-06-25 22:49:55 +0000978// LSL immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000979def tLSLri : // A8.6.88
980 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
981 IIC_iMOVsi,
982 "lsl", "\t$Rd, $Rm, $imm5",
983 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendling22db3132010-11-21 11:49:36 +0000984 bits<5> imm5;
985 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +0000986}
Evan Cheng10043e22007-01-19 07:51:42 +0000987
David Goodwine85169c2009-06-25 22:49:55 +0000988// LSL register
Bill Wendling4915f562010-12-01 00:48:44 +0000989def tLSLrr : // A8.6.89
990 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
991 IIC_iMOVsr,
992 "lsl", "\t$Rdn, $Rm",
993 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000994
David Goodwine85169c2009-06-25 22:49:55 +0000995// LSR immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000996def tLSRri : // A8.6.90
997 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
998 IIC_iMOVsi,
999 "lsr", "\t$Rd, $Rm, $imm5",
1000 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001001 bits<5> imm5;
1002 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001003}
Evan Cheng10043e22007-01-19 07:51:42 +00001004
David Goodwine85169c2009-06-25 22:49:55 +00001005// LSR register
Bill Wendling4915f562010-12-01 00:48:44 +00001006def tLSRrr : // A8.6.91
1007 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1008 IIC_iMOVsr,
1009 "lsr", "\t$Rdn, $Rm",
1010 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001011
Bill Wendling22db3132010-11-21 11:49:36 +00001012// Move register
Evan Cheng7f8ab6e2010-11-17 20:13:28 +00001013let isMoveImm = 1 in
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001014def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendling22db3132010-11-21 11:49:36 +00001015 "mov", "\t$Rd, $imm8",
1016 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1017 T1General<{1,0,0,?,?}> {
1018 // A8.6.96
1019 bits<3> Rd;
1020 bits<8> imm8;
1021 let Inst{10-8} = Rd;
1022 let Inst{7-0} = imm8;
1023}
Evan Cheng10043e22007-01-19 07:51:42 +00001024
Jim Grosbach4def7042011-07-01 17:14:11 +00001025// A7-73: MOV(2) - mov setting flag.
Evan Cheng10043e22007-01-19 07:51:42 +00001026
Evan Chengd93b5b62009-06-12 20:46:18 +00001027let neverHasSideEffects = 1 in {
Jim Grosbache9cc9012011-06-30 23:38:17 +00001028def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson651b2302011-07-13 23:22:26 +00001029 2, IIC_iMOVr,
Jim Grosbachb98ab912011-06-30 22:10:46 +00001030 "mov", "\t$Rd, $Rm", "", []>,
Jim Grosbache9cc9012011-06-30 23:38:17 +00001031 T1Special<{1,0,?,?}> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001032 // A8.6.97
1033 bits<4> Rd;
1034 bits<4> Rm;
Jim Grosbache9cc9012011-06-30 23:38:17 +00001035 let Inst{7} = Rd{3};
1036 let Inst{6-3} = Rm;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001037 let Inst{2-0} = Rd{2-0};
1038}
Evan Chengcd4cdd12009-07-11 06:43:01 +00001039let Defs = [CPSR] in
Bill Wendling4d8ff862010-12-03 01:55:47 +00001040def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1041 "movs\t$Rd, $Rm", []>, Encoding16 {
1042 // A8.6.97
1043 bits<3> Rd;
1044 bits<3> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +00001045 let Inst{15-6} = 0b0000000000;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001046 let Inst{5-3} = Rm;
1047 let Inst{2-0} = Rd;
Johnny Chenc28e6292009-12-15 17:24:14 +00001048}
Evan Chengd93b5b62009-06-12 20:46:18 +00001049} // neverHasSideEffects
Evan Cheng10043e22007-01-19 07:51:42 +00001050
Bill Wendling9c258942010-12-01 02:36:55 +00001051// Multiply register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001052let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001053def tMUL : // A8.6.105 T1
1054 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1055 IIC_iMUL32,
1056 "mul", "\t$Rdn, $Rm, $Rdn",
1057 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001058
Bill Wendling490240a2010-12-01 01:20:15 +00001059// Move inverse register
1060def tMVN : // A8.6.107
1061 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1062 "mvn", "\t$Rd, $Rn",
1063 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001064
Bill Wendling22db3132010-11-21 11:49:36 +00001065// Bitwise or register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001066let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001067def tORR : // A8.6.114
1068 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1069 IIC_iBITr,
1070 "orr", "\t$Rdn, $Rm",
1071 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001072
Bill Wendling22db3132010-11-21 11:49:36 +00001073// Swaps
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001074def tREV : // A8.6.134
1075 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1076 IIC_iUNAr,
1077 "rev", "\t$Rd, $Rm",
1078 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1079 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001080
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001081def tREV16 : // A8.6.135
1082 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1083 IIC_iUNAr,
1084 "rev16", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001085 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001086 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001087
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001088def tREVSH : // A8.6.136
1089 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1090 IIC_iUNAr,
1091 "revsh", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001092 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001093 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001094
Bill Wendling4915f562010-12-01 00:48:44 +00001095// Rotate right register
1096def tROR : // A8.6.139
1097 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1098 IIC_iMOVsr,
1099 "ror", "\t$Rdn, $Rm",
1100 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001101
Bill Wendling4915f562010-12-01 00:48:44 +00001102// Negate register
Bill Wendling490240a2010-12-01 01:20:15 +00001103def tRSB : // A8.6.141
1104 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1105 IIC_iALUi,
1106 "rsb", "\t$Rd, $Rn, #0",
1107 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001108
David Goodwine85169c2009-06-25 22:49:55 +00001109// Subtract with carry register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001110let Uses = [CPSR] in
Bill Wendling4915f562010-12-01 00:48:44 +00001111def tSBC : // A8.6.151
1112 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1113 IIC_iALUr,
1114 "sbc", "\t$Rdn, $Rm",
1115 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001116
David Goodwine85169c2009-06-25 22:49:55 +00001117// Subtract immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001118def tSUBi3 : // A8.6.210 T1
1119 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1120 IIC_iALUi,
1121 "sub", "\t$Rd, $Rm, $imm3",
1122 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendlingccba1a82010-11-29 01:00:43 +00001123 bits<3> imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001124 let Inst{8-6} = imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001125}
Jim Grosbach669f1d02009-03-27 23:06:27 +00001126
Bill Wendling4915f562010-12-01 00:48:44 +00001127def tSUBi8 : // A8.6.210 T2
1128 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1129 IIC_iALUi,
1130 "sub", "\t$Rdn, $imm8",
1131 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001132
Bill Wendling490240a2010-12-01 01:20:15 +00001133// Subtract register
1134def tSUBrr : // A8.6.212
1135 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1136 IIC_iALUr,
1137 "sub", "\t$Rd, $Rn, $Rm",
1138 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwine85169c2009-06-25 22:49:55 +00001139
1140// TODO: A7-96: STMIA - store multiple.
Evan Cheng10043e22007-01-19 07:51:42 +00001141
Bill Wendling490240a2010-12-01 01:20:15 +00001142// Sign-extend byte
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001143def tSXTB : // A8.6.222
1144 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1145 IIC_iUNAr,
1146 "sxtb", "\t$Rd, $Rm",
1147 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1148 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwine85169c2009-06-25 22:49:55 +00001149
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001150// Sign-extend short
1151def tSXTH : // A8.6.224
1152 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1153 IIC_iUNAr,
1154 "sxth", "\t$Rd, $Rm",
1155 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1156 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001157
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001158// Test
Gabor Greif2afac8e2010-09-14 20:47:43 +00001159let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001160def tTST : // A8.6.230
1161 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1162 "tst", "\t$Rn, $Rm",
1163 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001164
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001165// Zero-extend byte
1166def tUXTB : // A8.6.262
1167 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1168 IIC_iUNAr,
1169 "uxtb", "\t$Rd, $Rm",
1170 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1171 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwine85169c2009-06-25 22:49:55 +00001172
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001173// Zero-extend short
1174def tUXTH : // A8.6.264
1175 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1176 IIC_iUNAr,
1177 "uxth", "\t$Rd, $Rm",
1178 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1179 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001180
Jim Grosbach3e2cad32010-02-16 21:23:02 +00001181// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman453d64c2009-10-29 18:10:34 +00001182// Expanded after instruction selection into a branch sequence.
1183let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Chengbb2af352009-08-12 05:17:19 +00001184 def tMOVCCr_pseudo :
Evan Chengfd108692009-08-12 02:03:03 +00001185 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbacha74c7ccd2010-11-18 01:38:26 +00001186 NoItinerary,
Evan Chengfd108692009-08-12 02:03:03 +00001187 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001188
1189// tLEApcrel - Load a pc-relative address into a register without offending the
1190// assembler.
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001191
1192def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1193 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1194 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling85a8a722010-11-30 00:18:30 +00001195 bits<3> Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001196 bits<8> addr;
Bill Wendling85a8a722010-11-30 00:18:30 +00001197 let Inst{10-8} = Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001198 let Inst{7-0} = addr;
Bill Wendling85a8a722010-11-30 00:18:30 +00001199}
Evan Cheng10043e22007-01-19 07:51:42 +00001200
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001201let neverHasSideEffects = 1, isReMaterializable = 1 in
1202def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001203 2, IIC_iALUi, []>;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001204
1205def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1206 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001207 2, IIC_iALUi, []>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001208
Evan Cheng10043e22007-01-19 07:51:42 +00001209//===----------------------------------------------------------------------===//
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001210// TLS Instructions
1211//
1212
1213// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbache4750ef2011-06-30 19:38:01 +00001214// This is a pseudo inst so that we can get the encoding right,
1215// complete with fixup for the aeabi_read_tp function.
1216let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson651b2302011-07-13 23:22:26 +00001217def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Jim Grosbache4750ef2011-06-30 19:38:01 +00001218 [(set R0, ARMthread_pointer)]>;
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001219
Bill Wendling9c258942010-12-01 02:36:55 +00001220//===----------------------------------------------------------------------===//
Jim Grosbach36d4dec2009-12-01 18:10:36 +00001221// SJLJ Exception handling intrinsics
Owen Andersonb7456232011-05-11 17:00:48 +00001222//
Bill Wendling9c258942010-12-01 02:36:55 +00001223
1224// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1225// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1226// from some other function to get here, and we're using the stack frame for the
1227// containing function to save/restore registers, we can't keep anything live in
1228// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner0ab5e2c2011-04-15 05:18:47 +00001229// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling9c258942010-12-01 02:36:55 +00001230// registers except for our own input by listing the relevant registers in
1231// Defs. By doing so, we also cause the prologue/epilogue code to actively
1232// preserve all of the callee-saved resgisters, which is exactly what we want.
1233// $val is a scratch register for our use.
Andrew Trick410172b2011-06-07 00:08:49 +00001234let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendlingddce9f32010-11-30 00:50:22 +00001235 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1236def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson651b2302011-07-13 23:22:26 +00001237 AddrModeNone, 0, NoItinerary, "","",
Bill Wendlingddce9f32010-11-30 00:50:22 +00001238 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001239
1240// FIXME: Non-Darwin version(s)
Chris Lattner9492c172010-10-31 19:15:18 +00001241let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001242 Defs = [ R7, LR, SP ] in
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001243def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson651b2302011-07-13 23:22:26 +00001244 AddrModeNone, 0, IndexModeNone,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001245 Pseudo, NoItinerary, "", "",
1246 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1247 Requires<[IsThumb, IsDarwin]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001248
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001249//===----------------------------------------------------------------------===//
Evan Cheng10043e22007-01-19 07:51:42 +00001250// Non-Instruction Patterns
1251//
1252
Jim Grosbach327cf8e2010-12-07 20:41:06 +00001253// Comparisons
1254def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1255 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1256def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1257 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1258
Evan Cheng61671c82009-07-10 02:09:04 +00001259// Add with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001260def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1261 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1262def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng01de9852009-08-20 17:01:04 +00001263 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwine5b969f2009-07-27 19:59:26 +00001264def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1265 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001266
1267// Subtract with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001268def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1269 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1270def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1271 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1272def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1273 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001274
Evan Cheng10043e22007-01-19 07:51:42 +00001275// ConstantPool, GlobalAddress
David Goodwine5b969f2009-07-27 19:59:26 +00001276def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1277def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001278
Evan Cheng0701c5a2007-01-27 02:29:45 +00001279// JumpTable
David Goodwine5b969f2009-07-27 19:59:26 +00001280def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1281 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001282
Evan Cheng10043e22007-01-19 07:51:42 +00001283// Direct calls
Evan Cheng175bd142009-07-29 21:26:42 +00001284def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Cheng6ab54fd2009-08-01 00:16:10 +00001285 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001286def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Cheng6ab54fd2009-08-01 00:16:10 +00001287 Requires<[IsThumb, IsDarwin]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001288
1289def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Cheng6ab54fd2009-08-01 00:16:10 +00001290 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001291def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Cheng6ab54fd2009-08-01 00:16:10 +00001292 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001293
1294// Indirect calls to ARM routines
Evan Cheng6ab54fd2009-08-01 00:16:10 +00001295def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1296 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1297def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1298 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001299
1300// zextload i1 -> zextload i8
Bill Wendling092a7bd2010-12-14 03:36:38 +00001301def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1302 (tLDRBr t_addrmode_rrs1:$addr)>;
1303def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1304 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001305
Evan Chengd02d75c2007-01-26 19:13:16 +00001306// extload -> zextload
Bill Wendling092a7bd2010-12-14 03:36:38 +00001307def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1308def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1309def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1310def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1311def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1312def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengd02d75c2007-01-26 19:13:16 +00001313
Evan Cheng6da267d2009-08-28 00:31:43 +00001314// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng0794c6a2009-07-11 07:08:13 +00001315// ldr{b|h} + sxt{b|h} instead.
Bill Wendling1171e9e2010-12-15 00:58:57 +00001316def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1317 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1318 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001319def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1320 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001321 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001322def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1323 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1324 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001325def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1326 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001327 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001328
Bill Wendling092a7bd2010-12-14 03:36:38 +00001329def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1330 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001331def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1332 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1333def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1334 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1335def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1336 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001337
Evan Cheng10043e22007-01-19 07:51:42 +00001338// Large immediate handling.
1339
1340// Two piece imms.
Evan Chengeab9ca72009-06-27 02:26:13 +00001341def : T1Pat<(i32 thumb_immshifted:$src),
1342 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1343 (thumb_immshifted_shamt imm:$src))>;
Evan Cheng10043e22007-01-19 07:51:42 +00001344
Evan Chengeab9ca72009-06-27 02:26:13 +00001345def : T1Pat<(i32 imm0_255_comp:$src),
1346 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Cheng207b2462009-11-06 23:52:48 +00001347
1348// Pseudo instruction that combines ldr from constpool and add pc. This should
1349// be expanded into two instructions late to allow if-conversion and
1350// scheduling.
1351let isReMaterializable = 1 in
1352def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling9c258942010-12-01 02:36:55 +00001353 NoItinerary,
Evan Cheng207b2462009-11-06 23:52:48 +00001354 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1355 imm:$cp))]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001356 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001357
1358// Pseudo-instruction for merged POP and return.
1359// FIXME: remove when we have a way to marking a MI with these properties.
1360let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1361 hasExtraDefRegAllocReq = 1 in
1362def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +00001363 2, IIC_iPop_Br, [],
Jim Grosbach95dee402011-07-08 17:40:42 +00001364 (tPOP pred:$p, reglist:$regs)>;
1365
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001366// Indirect branch using "mov pc, $Rm"
1367let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach39c67b52011-07-08 22:33:49 +00001368 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001369 2, IIC_Br, [(brind GPR:$Rm)],
Jim Grosbach39c67b52011-07-08 22:33:49 +00001370 (tMOVr PC, GPR:$Rm, pred:$p)>;
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001371}