1 //===- ARMInstrThumb.td - Thumb support for ARM ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the Thumb instruction set.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Thumb specific DAG Nodes.
18 def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
19 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
21 def imm_neg_XFORM : SDNodeXForm<imm, [{
22 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
24 def imm_comp_XFORM : SDNodeXForm<imm, [{
25 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
29 /// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
30 def imm0_7 : PatLeaf<(i32 imm), [{
31 return (uint32_t)N->getZExtValue() < 8;
33 def imm0_7_neg : PatLeaf<(i32 imm), [{
34 return (uint32_t)-N->getZExtValue() < 8;
37 def imm0_255 : PatLeaf<(i32 imm), [{
38 return (uint32_t)N->getZExtValue() < 256;
40 def imm0_255_comp : PatLeaf<(i32 imm), [{
41 return ~((uint32_t)N->getZExtValue()) < 256;
44 def imm8_255 : PatLeaf<(i32 imm), [{
45 return (uint32_t)N->getZExtValue() >= 8 && (uint32_t)N->getZExtValue() < 256;
47 def imm8_255_neg : PatLeaf<(i32 imm), [{
48 unsigned Val = -N->getZExtValue();
49 return Val >= 8 && Val < 256;
52 // Break imm's up into two pieces: an immediate + a left shift.
53 // This uses thumb_immshifted to match and thumb_immshifted_val and
54 // thumb_immshifted_shamt to get the val/shift pieces.
55 def thumb_immshifted : PatLeaf<(imm), [{
56 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
59 def thumb_immshifted_val : SDNodeXForm<imm, [{
60 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
61 return CurDAG->getTargetConstant(V, MVT::i32);
64 def thumb_immshifted_shamt : SDNodeXForm<imm, [{
65 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
66 return CurDAG->getTargetConstant(V, MVT::i32);
69 // Scaled 4 immediate.
70 def t_imm_s4 : Operand<i32> {
71 let PrintMethod = "printThumbS4ImmOperand";
74 // Define Thumb specific addressing modes.
76 // t_addrmode_rr := reg + reg
78 def t_addrmode_rr : Operand<i32>,
79 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
80 let PrintMethod = "printThumbAddrModeRROperand";
81 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
84 // t_addrmode_s4 := reg + reg
87 def t_addrmode_s4 : Operand<i32>,
88 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
89 let PrintMethod = "printThumbAddrModeS4Operand";
90 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
93 // t_addrmode_s2 := reg + reg
96 def t_addrmode_s2 : Operand<i32>,
97 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
98 let PrintMethod = "printThumbAddrModeS2Operand";
99 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
102 // t_addrmode_s1 := reg + reg
105 def t_addrmode_s1 : Operand<i32>,
106 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
107 let PrintMethod = "printThumbAddrModeS1Operand";
108 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
111 // t_addrmode_sp := sp + imm8 * 4
113 def t_addrmode_sp : Operand<i32>,
114 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
115 let PrintMethod = "printThumbAddrModeSPOperand";
116 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
119 //===----------------------------------------------------------------------===//
120 // Miscellaneous Instructions.
123 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
124 // from removing one half of the matched pairs. That breaks PEI, which assumes
125 // these will always be in pairs, and asserts if it finds otherwise. Better way?
126 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
127 def tADJCALLSTACKUP :
128 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
129 "@ tADJCALLSTACKUP $amt1",
130 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>, Requires<[IsThumb1Only]>;
132 def tADJCALLSTACKDOWN :
133 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
134 "@ tADJCALLSTACKDOWN $amt",
135 [(ARMcallseq_start imm:$amt)]>, Requires<[IsThumb1Only]>;
138 def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
139 [/* For disassembly only; pattern left blank */]>,
140 T1Encoding<0b101111> {
141 let Inst{9-8} = 0b11;
142 let Inst{7-0} = 0b00000000;
145 def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
146 [/* For disassembly only; pattern left blank */]>,
147 T1Encoding<0b101111> {
148 let Inst{9-8} = 0b11;
149 let Inst{7-0} = 0b00010000;
152 def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
153 [/* For disassembly only; pattern left blank */]>,
154 T1Encoding<0b101111> {
155 let Inst{9-8} = 0b11;
156 let Inst{7-0} = 0b00100000;
159 def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
160 [/* For disassembly only; pattern left blank */]>,
161 T1Encoding<0b101111> {
162 let Inst{9-8} = 0b11;
163 let Inst{7-0} = 0b00110000;
166 def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
167 [/* For disassembly only; pattern left blank */]>,
168 T1Encoding<0b101111> {
169 let Inst{9-8} = 0b11;
170 let Inst{7-0} = 0b01000000;
173 def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
174 [/* For disassembly only; pattern left blank */]>,
175 T1Encoding<0b101101> {
176 let Inst{9-5} = 0b10010;
180 def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
181 [/* For disassembly only; pattern left blank */]>,
182 T1Encoding<0b101101> {
183 let Inst{9-5} = 0b10010;
187 // The i32imm operand $val can be used by a debugger to store more information
188 // about the breakpoint.
189 def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
190 [/* For disassembly only; pattern left blank */]>,
191 T1Encoding<0b101111> {
192 let Inst{9-8} = 0b10;
195 // For both thumb1 and thumb2.
196 let isNotDuplicable = 1 in
197 def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr,
198 "\n$cp:\n\tadd\t$dst, pc",
199 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
200 T1Special<{0,0,?,?}> {
201 let Inst{6-3} = 0b1111; // A8.6.6 Rm = pc
205 def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
206 "add\t$dst, pc, $rhs", []>,
207 T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10
210 def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
211 "add\t$dst, $sp, $rhs", []>,
212 T1Encoding<{1,0,1,0,1,?}>; // A6.2 & A8.6.8
215 def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
216 "add\t$dst, $rhs", []>,
217 T1Misc<{0,0,0,0,0,?,?}>; // A6.2.5 & A8.6.8
220 def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
221 "sub\t$dst, $rhs", []>,
222 T1Misc<{0,0,0,0,1,?,?}>; // A6.2.5 & A8.6.215
225 def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
226 "add\t$dst, $rhs", []>,
227 T1Special<{0,0,?,?}> {
228 let Inst{6-3} = 0b1101; // A8.6.9 Encoding T1
232 def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
233 "add\t$dst, $rhs", []>,
234 T1Special<{0,0,?,?}> {
235 // A8.6.9 Encoding T2
237 let Inst{2-0} = 0b101;
240 // Pseudo instruction that will expand into a tSUBspi + a copy.
241 let usesCustomInserter = 1 in { // Expanded after instruction selection.
242 def tSUBspi_ : PseudoInst<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs),
243 NoItinerary, "@ sub\t$dst, $rhs", []>;
245 def tADDspr_ : PseudoInst<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
246 NoItinerary, "@ add\t$dst, $rhs", []>;
249 def tANDsp : PseudoInst<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
250 NoItinerary, "@ and\t$dst, $rhs", []>;
251 } // usesCustomInserter
253 //===----------------------------------------------------------------------===//
254 // Control Flow Instructions.
257 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
258 def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr", [(ARMretflag)]>,
259 T1Special<{1,1,0,?}> { // A6.2.3 & A8.6.25
260 let Inst{6-3} = 0b1110; // Rm = lr
262 // Alternative return instruction used by vararg functions.
263 def tBX_RET_vararg : TI<(outs), (ins tGPR:$target), IIC_Br, "bx\t$target",[]>,
264 T1Special<{1,1,0,?}>; // A6.2.3 & A8.6.25
268 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
269 def tBRIND : TI<(outs), (ins GPR:$dst), IIC_Br, "mov\tpc, $dst",
271 T1Special<{1,0,1,?}> {
272 // <Rd> = Inst{7:2-0} = pc
273 let Inst{2-0} = 0b111;
277 // FIXME: remove when we have a way to marking a MI with these properties.
278 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
279 hasExtraDefRegAllocReq = 1 in
280 def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
282 T1Misc<{1,1,0,?,?,?,?}>;
285 Defs = [R0, R1, R2, R3, R12, LR,
286 D0, D1, D2, D3, D4, D5, D6, D7,
287 D16, D17, D18, D19, D20, D21, D22, D23,
288 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
289 // Also used for Thumb2
290 def tBL : TIx2<0b11110, 0b11, 1,
291 (outs), (ins i32imm:$func, variable_ops), IIC_Br,
293 [(ARMtcall tglobaladdr:$func)]>,
294 Requires<[IsThumb, IsNotDarwin]>;
296 // ARMv5T and above, also used for Thumb2
297 def tBLXi : TIx2<0b11110, 0b11, 0,
298 (outs), (ins i32imm:$func, variable_ops), IIC_Br,
300 [(ARMcall tglobaladdr:$func)]>,
301 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
303 // Also used for Thumb2
304 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
306 [(ARMtcall GPR:$func)]>,
307 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
308 T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24;
311 def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?,
312 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
313 "mov\tlr, pc\n\tbx\t$func",
314 [(ARMcall_nolink tGPR:$func)]>,
315 Requires<[IsThumb1Only, IsNotDarwin]>;
318 // On Darwin R9 is call-clobbered.
320 Defs = [R0, R1, R2, R3, R9, R12, LR,
321 D0, D1, D2, D3, D4, D5, D6, D7,
322 D16, D17, D18, D19, D20, D21, D22, D23,
323 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
324 // Also used for Thumb2
325 def tBLr9 : TIx2<0b11110, 0b11, 1,
326 (outs), (ins i32imm:$func, variable_ops), IIC_Br,
328 [(ARMtcall tglobaladdr:$func)]>,
329 Requires<[IsThumb, IsDarwin]>;
331 // ARMv5T and above, also used for Thumb2
332 def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
333 (outs), (ins i32imm:$func, variable_ops), IIC_Br,
335 [(ARMcall tglobaladdr:$func)]>,
336 Requires<[IsThumb, HasV5T, IsDarwin]>;
338 // Also used for Thumb2
339 def tBLXr_r9 : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
341 [(ARMtcall GPR:$func)]>,
342 Requires<[IsThumb, HasV5T, IsDarwin]>,
343 T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24
346 def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?,
347 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
348 "mov\tlr, pc\n\tbx\t$func",
349 [(ARMcall_nolink tGPR:$func)]>,
350 Requires<[IsThumb1Only, IsDarwin]>;
353 let isBranch = 1, isTerminator = 1 in {
354 let isBarrier = 1 in {
355 let isPredicable = 1 in
356 def tB : T1I<(outs), (ins brtarget:$target), IIC_Br,
357 "b\t$target", [(br bb:$target)]>,
358 T1Encoding<{1,1,1,0,0,?}>;
362 def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
363 "bl\t$target\t@ far jump",[]>;
365 def tBR_JTr : T1JTI<(outs),
366 (ins tGPR:$target, jtblock_operand:$jt, i32imm:$id),
367 IIC_Br, "mov\tpc, $target\n\t.align\t2\n$jt",
368 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>,
370 let Inst{15-7} = 0b010001101;
371 let Inst{2-0} = 0b111;
376 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
377 // a two-value operand where a dag node expects two operands. :(
378 let isBranch = 1, isTerminator = 1 in
379 def tBcc : T1I<(outs), (ins brtarget:$target, pred:$cc), IIC_Br,
381 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
382 T1Encoding<{1,1,0,1,?,?}>;
384 // Compare and branch on zero / non-zero
385 let isBranch = 1, isTerminator = 1 in {
386 def tCBZ : T1I<(outs), (ins tGPR:$cmp, brtarget:$target), IIC_Br,
387 "cbz\t$cmp, $target", []>,
388 T1Misc<{0,0,?,1,?,?,?}>;
390 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, brtarget:$target), IIC_Br,
391 "cbnz\t$cmp, $target", []>,
392 T1Misc<{1,0,?,1,?,?,?}>;
395 // A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
396 // A8.6.16 B: Encoding T1
397 // If Inst{11-8} == 0b1111 then SEE SVC
399 def tSVC : T1pI<(outs), (ins i32imm:$svc), IIC_Br, "svc", "\t$svc", []>,
401 let Inst{15-12} = 0b1101;
402 let Inst{11-8} = 0b1111;
406 // A8.6.16 B: Encoding T1 -- for disassembly only
407 // If Inst{11-8} == 0b1110 then UNDEFINED
408 def tTRAP : T1I<(outs), (ins), IIC_Br, "trap", []>, Encoding16 {
409 let Inst{15-12} = 0b1101;
410 let Inst{11-8} = 0b1110;
413 //===----------------------------------------------------------------------===//
414 // Load Store Instructions.
417 let canFoldAsLoad = 1, isReMaterializable = 1 in
418 def tLDR : T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoadr,
419 "ldr", "\t$dst, $addr",
420 [(set tGPR:$dst, (load t_addrmode_s4:$addr))]>,
422 def tLDRi: T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoadr,
423 "ldr", "\t$dst, $addr",
427 def tLDRB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoadr,
428 "ldrb", "\t$dst, $addr",
429 [(set tGPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>,
431 def tLDRBi: T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoadr,
432 "ldrb", "\t$dst, $addr",
436 def tLDRH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoadr,
437 "ldrh", "\t$dst, $addr",
438 [(set tGPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>,
440 def tLDRHi: T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoadr,
441 "ldrh", "\t$dst, $addr",
445 let AddedComplexity = 10 in
446 def tLDRSB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoadr,
447 "ldrsb", "\t$dst, $addr",
448 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>,
451 let AddedComplexity = 10 in
452 def tLDRSH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoadr,
453 "ldrsh", "\t$dst, $addr",
454 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>,
457 let canFoldAsLoad = 1 in
458 def tLDRspi : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoadi,
459 "ldr", "\t$dst, $addr",
460 [(set tGPR:$dst, (load t_addrmode_sp:$addr))]>,
463 // Special instruction for restore. It cannot clobber condition register
464 // when it's expanded by eliminateCallFramePseudoInstr().
465 let canFoldAsLoad = 1, mayLoad = 1 in
466 def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoadi,
467 "ldr", "\t$dst, $addr", []>,
471 // FIXME: Use ldr.n to work around a Darwin assembler bug.
472 let canFoldAsLoad = 1, isReMaterializable = 1 in
473 def tLDRpci : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoadi,
474 "ldr", ".n\t$dst, $addr",
475 [(set tGPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>,
476 T1Encoding<{0,1,0,0,1,?}>; // A6.2 & A8.6.59
478 // Special LDR for loads from non-pc-relative constpools.
479 let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1 in
480 def tLDRcp : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoadi,
481 "ldr", "\t$dst, $addr", []>,
484 def tSTR : T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStorer,
485 "str", "\t$src, $addr",
486 [(store tGPR:$src, t_addrmode_s4:$addr)]>,
488 def tSTRi: T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStorer,
489 "str", "\t$src, $addr",
493 def tSTRB : T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStorer,
494 "strb", "\t$src, $addr",
495 [(truncstorei8 tGPR:$src, t_addrmode_s1:$addr)]>,
497 def tSTRBi: T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStorer,
498 "strb", "\t$src, $addr",
502 def tSTRH : T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStorer,
503 "strh", "\t$src, $addr",
504 [(truncstorei16 tGPR:$src, t_addrmode_s2:$addr)]>,
506 def tSTRHi: T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStorer,
507 "strh", "\t$src, $addr",
511 def tSTRspi : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei,
512 "str", "\t$src, $addr",
513 [(store tGPR:$src, t_addrmode_sp:$addr)]>,
516 let mayStore = 1 in {
517 // Special instruction for spill. It cannot clobber condition register
518 // when it's expanded by eliminateCallFramePseudoInstr().
519 def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei,
520 "str", "\t$src, $addr", []>,
524 //===----------------------------------------------------------------------===//
525 // Load / store multiple Instructions.
528 // These requires base address to be written back or one of the loaded regs.
529 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
530 def tLDM : T1I<(outs),
531 (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
533 "ldm${addr:submode}${p}\t$addr, $wb", []>,
534 T1Encoding<{1,1,0,0,1,?}>; // A6.2 & A8.6.53
536 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
537 def tSTM : T1I<(outs),
538 (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
540 "stm${addr:submode}${p}\t$addr, $wb", []>,
541 T1Encoding<{1,1,0,0,0,?}>; // A6.2 & A8.6.189
543 let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
544 def tPOP : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
546 T1Misc<{1,1,0,?,?,?,?}>;
548 let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
549 def tPUSH : T1I<(outs), (ins pred:$p, reglist:$wb, variable_ops), IIC_Br,
550 "push${p}\t$wb", []>,
551 T1Misc<{0,1,0,?,?,?,?}>;
553 //===----------------------------------------------------------------------===//
554 // Arithmetic Instructions.
557 // Add with carry register
558 let isCommutable = 1, Uses = [CPSR] in
559 def tADC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
560 "adc", "\t$dst, $rhs",
561 [(set tGPR:$dst, (adde tGPR:$lhs, tGPR:$rhs))]>,
562 T1DataProcessing<0b0101>;
565 def tADDi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
566 "add", "\t$dst, $lhs, $rhs",
567 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7:$rhs))]>,
570 def tADDi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
571 "add", "\t$dst, $rhs",
572 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255:$rhs))]>,
573 T1General<{1,1,0,?,?}>;
576 let isCommutable = 1 in
577 def tADDrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
578 "add", "\t$dst, $lhs, $rhs",
579 [(set tGPR:$dst, (add tGPR:$lhs, tGPR:$rhs))]>,
582 let neverHasSideEffects = 1 in
583 def tADDhirr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
584 "add", "\t$dst, $rhs", []>,
585 T1Special<{0,0,?,?}>;
588 let isCommutable = 1 in
589 def tAND : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
590 "and", "\t$dst, $rhs",
591 [(set tGPR:$dst, (and tGPR:$lhs, tGPR:$rhs))]>,
592 T1DataProcessing<0b0000>;
595 def tASRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
596 "asr", "\t$dst, $lhs, $rhs",
597 [(set tGPR:$dst, (sra tGPR:$lhs, (i32 imm:$rhs)))]>,
598 T1General<{0,1,0,?,?}>;
601 def tASRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
602 "asr", "\t$dst, $rhs",
603 [(set tGPR:$dst, (sra tGPR:$lhs, tGPR:$rhs))]>,
604 T1DataProcessing<0b0100>;
607 def tBIC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
608 "bic", "\t$dst, $rhs",
609 [(set tGPR:$dst, (and tGPR:$lhs, (not tGPR:$rhs)))]>,
610 T1DataProcessing<0b1110>;
613 let Defs = [CPSR] in {
614 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
615 // Compare-to-zero still works out, just not the relationals
616 //def tCMN : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
617 // "cmn", "\t$lhs, $rhs",
618 // [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>,
619 // T1DataProcessing<0b1011>;
620 def tCMNz : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
621 "cmn", "\t$lhs, $rhs",
622 [(ARMcmpZ tGPR:$lhs, (ineg tGPR:$rhs))]>,
623 T1DataProcessing<0b1011>;
627 let Defs = [CPSR] in {
628 def tCMPi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMPi,
629 "cmp", "\t$lhs, $rhs",
630 [(ARMcmp tGPR:$lhs, imm0_255:$rhs)]>,
631 T1General<{1,0,1,?,?}>;
632 def tCMPzi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMPi,
633 "cmp", "\t$lhs, $rhs",
634 [(ARMcmpZ tGPR:$lhs, imm0_255:$rhs)]>,
635 T1General<{1,0,1,?,?}>;
639 let Defs = [CPSR] in {
640 def tCMPr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
641 "cmp", "\t$lhs, $rhs",
642 [(ARMcmp tGPR:$lhs, tGPR:$rhs)]>,
643 T1DataProcessing<0b1010>;
644 def tCMPzr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
645 "cmp", "\t$lhs, $rhs",
646 [(ARMcmpZ tGPR:$lhs, tGPR:$rhs)]>,
647 T1DataProcessing<0b1010>;
649 def tCMPhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iCMPr,
650 "cmp", "\t$lhs, $rhs", []>,
651 T1Special<{0,1,?,?}>;
652 def tCMPzhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iCMPr,
653 "cmp", "\t$lhs, $rhs", []>,
654 T1Special<{0,1,?,?}>;
659 let isCommutable = 1 in
660 def tEOR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
661 "eor", "\t$dst, $rhs",
662 [(set tGPR:$dst, (xor tGPR:$lhs, tGPR:$rhs))]>,
663 T1DataProcessing<0b0001>;
666 def tLSLri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
667 "lsl", "\t$dst, $lhs, $rhs",
668 [(set tGPR:$dst, (shl tGPR:$lhs, (i32 imm:$rhs)))]>,
669 T1General<{0,0,0,?,?}>;
672 def tLSLrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
673 "lsl", "\t$dst, $rhs",
674 [(set tGPR:$dst, (shl tGPR:$lhs, tGPR:$rhs))]>,
675 T1DataProcessing<0b0010>;
678 def tLSRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
679 "lsr", "\t$dst, $lhs, $rhs",
680 [(set tGPR:$dst, (srl tGPR:$lhs, (i32 imm:$rhs)))]>,
681 T1General<{0,0,1,?,?}>;
684 def tLSRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
685 "lsr", "\t$dst, $rhs",
686 [(set tGPR:$dst, (srl tGPR:$lhs, tGPR:$rhs))]>,
687 T1DataProcessing<0b0011>;
690 def tMOVi8 : T1sI<(outs tGPR:$dst), (ins i32imm:$src), IIC_iMOVi,
691 "mov", "\t$dst, $src",
692 [(set tGPR:$dst, imm0_255:$src)]>,
693 T1General<{1,0,0,?,?}>;
695 // TODO: A7-73: MOV(2) - mov setting flag.
698 let neverHasSideEffects = 1 in {
699 // FIXME: Make this predicable.
700 def tMOVr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
701 "mov\t$dst, $src", []>,
704 def tMOVSr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
705 "movs\t$dst, $src", []>, Encoding16 {
706 let Inst{15-6} = 0b0000000000;
709 // FIXME: Make these predicable.
710 def tMOVgpr2tgpr : T1I<(outs tGPR:$dst), (ins GPR:$src), IIC_iMOVr,
711 "mov\t$dst, $src", []>,
712 T1Special<{1,0,0,?}>;
713 def tMOVtgpr2gpr : T1I<(outs GPR:$dst), (ins tGPR:$src), IIC_iMOVr,
714 "mov\t$dst, $src", []>,
715 T1Special<{1,0,?,0}>;
716 def tMOVgpr2gpr : T1I<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVr,
717 "mov\t$dst, $src", []>,
718 T1Special<{1,0,?,?}>;
719 } // neverHasSideEffects
722 let isCommutable = 1 in
723 def tMUL : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMUL32,
724 "mul", "\t$dst, $rhs",
725 [(set tGPR:$dst, (mul tGPR:$lhs, tGPR:$rhs))]>,
726 T1DataProcessing<0b1101>;
728 // move inverse register
729 def tMVN : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
730 "mvn", "\t$dst, $src",
731 [(set tGPR:$dst, (not tGPR:$src))]>,
732 T1DataProcessing<0b1111>;
734 // bitwise or register
735 let isCommutable = 1 in
736 def tORR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
737 "orr", "\t$dst, $rhs",
738 [(set tGPR:$dst, (or tGPR:$lhs, tGPR:$rhs))]>,
739 T1DataProcessing<0b1100>;
742 def tREV : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
743 "rev", "\t$dst, $src",
744 [(set tGPR:$dst, (bswap tGPR:$src))]>,
745 Requires<[IsThumb1Only, HasV6]>,
746 T1Misc<{1,0,1,0,0,0,?}>;
748 def tREV16 : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
749 "rev16", "\t$dst, $src",
751 (or (and (srl tGPR:$src, (i32 8)), 0xFF),
752 (or (and (shl tGPR:$src, (i32 8)), 0xFF00),
753 (or (and (srl tGPR:$src, (i32 8)), 0xFF0000),
754 (and (shl tGPR:$src, (i32 8)), 0xFF000000)))))]>,
755 Requires<[IsThumb1Only, HasV6]>,
756 T1Misc<{1,0,1,0,0,1,?}>;
758 def tREVSH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
759 "revsh", "\t$dst, $src",
762 (or (srl (and tGPR:$src, 0xFF00), (i32 8)),
763 (shl tGPR:$src, (i32 8))), i16))]>,
764 Requires<[IsThumb1Only, HasV6]>,
765 T1Misc<{1,0,1,0,1,1,?}>;
767 // rotate right register
768 def tROR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
769 "ror", "\t$dst, $rhs",
770 [(set tGPR:$dst, (rotr tGPR:$lhs, tGPR:$rhs))]>,
771 T1DataProcessing<0b0111>;
774 def tRSB : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALUi,
775 "rsb", "\t$dst, $src, #0",
776 [(set tGPR:$dst, (ineg tGPR:$src))]>,
777 T1DataProcessing<0b1001>;
779 // Subtract with carry register
781 def tSBC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
782 "sbc", "\t$dst, $rhs",
783 [(set tGPR:$dst, (sube tGPR:$lhs, tGPR:$rhs))]>,
784 T1DataProcessing<0b0110>;
786 // Subtract immediate
787 def tSUBi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
788 "sub", "\t$dst, $lhs, $rhs",
789 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7_neg:$rhs))]>,
792 def tSUBi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
793 "sub", "\t$dst, $rhs",
794 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255_neg:$rhs))]>,
795 T1General<{1,1,1,?,?}>;
798 def tSUBrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
799 "sub", "\t$dst, $lhs, $rhs",
800 [(set tGPR:$dst, (sub tGPR:$lhs, tGPR:$rhs))]>,
803 // TODO: A7-96: STMIA - store multiple.
806 def tSXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
807 "sxtb", "\t$dst, $src",
808 [(set tGPR:$dst, (sext_inreg tGPR:$src, i8))]>,
809 Requires<[IsThumb1Only, HasV6]>,
810 T1Misc<{0,0,1,0,0,1,?}>;
813 def tSXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
814 "sxth", "\t$dst, $src",
815 [(set tGPR:$dst, (sext_inreg tGPR:$src, i16))]>,
816 Requires<[IsThumb1Only, HasV6]>,
817 T1Misc<{0,0,1,0,0,0,?}>;
820 let isCommutable = 1, Defs = [CPSR] in
821 def tTST : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
822 "tst", "\t$lhs, $rhs",
823 [(ARMcmpZ (and tGPR:$lhs, tGPR:$rhs), 0)]>,
824 T1DataProcessing<0b1000>;
827 def tUXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
828 "uxtb", "\t$dst, $src",
829 [(set tGPR:$dst, (and tGPR:$src, 0xFF))]>,
830 Requires<[IsThumb1Only, HasV6]>,
831 T1Misc<{0,0,1,0,1,1,?}>;
834 def tUXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
835 "uxth", "\t$dst, $src",
836 [(set tGPR:$dst, (and tGPR:$src, 0xFFFF))]>,
837 Requires<[IsThumb1Only, HasV6]>,
838 T1Misc<{0,0,1,0,1,0,?}>;
841 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
842 // Expanded after instruction selection into a branch sequence.
843 let usesCustomInserter = 1 in // Expanded after instruction selection.
845 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
846 NoItinerary, "@ tMOVCCr $cc",
847 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
850 // 16-bit movcc in IT blocks for Thumb2.
851 def tMOVCCr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iCMOVr,
852 "mov", "\t$dst, $rhs", []>,
853 T1Special<{1,0,?,?}>;
855 def tMOVCCi : T1pIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMOVi,
856 "mov", "\t$dst, $rhs", []>,
857 T1General<{1,0,0,?,?}>;
859 // tLEApcrel - Load a pc-relative address into a register without offending the
861 def tLEApcrel : T1I<(outs tGPR:$dst), (ins i32imm:$label, pred:$p), IIC_iALUi,
862 "adr$p\t$dst, #$label", []>,
863 T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10
865 def tLEApcrelJT : T1I<(outs tGPR:$dst),
866 (ins i32imm:$label, nohash_imm:$id, pred:$p),
867 IIC_iALUi, "adr$p\t$dst, #${label}_${id}", []>,
868 T1Encoding<{1,0,1,0,0,?}>; // A6.2 & A8.6.10
870 //===----------------------------------------------------------------------===//
874 // __aeabi_read_tp preserves the registers r1-r3.
877 def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
878 "bl\t__aeabi_read_tp",
879 [(set R0, ARMthread_pointer)]>;
882 // SJLJ Exception handling intrinsics
883 // eh_sjlj_setjmp() is an instruction sequence to store the return
884 // address and save #0 in R0 for the non-longjmp case.
885 // Since by its nature we may be coming from some other function to get
886 // here, and we're using the stack frame for the containing function to
887 // save/restore registers, we can't keep anything live in regs across
888 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
889 // when we get here from a longjmp(). We force everthing out of registers
890 // except for our own input by listing the relevant registers in Defs. By
891 // doing so, we also cause the prologue/epilogue code to actively preserve
892 // all of the callee-saved resgisters, which is exactly what we want.
893 // The current SP is passed in $val, and we reuse the reg as a scratch.
895 [ R0, R1, R2, R3, R4, R5, R6, R7, R12 ] in {
896 def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
897 AddrModeNone, SizeSpecial, NoItinerary,
898 "str\t$val, [$src, #8]\t@ begin eh.setjmp\n"
901 "\tstr\t$val, [$src, #4]\n"
904 "\tmovs\tr0, #1\t@ end eh.setjmp\n"
906 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
908 //===----------------------------------------------------------------------===//
909 // Non-Instruction Patterns
913 def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
914 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
915 def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
916 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
917 def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
918 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
920 // Subtract with carry
921 def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
922 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
923 def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
924 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
925 def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
926 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
928 // ConstantPool, GlobalAddress
929 def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
930 def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
933 def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
934 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
937 def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
938 Requires<[IsThumb, IsNotDarwin]>;
939 def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
940 Requires<[IsThumb, IsDarwin]>;
942 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
943 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
944 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
945 Requires<[IsThumb, HasV5T, IsDarwin]>;
947 // Indirect calls to ARM routines
948 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
949 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
950 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
951 Requires<[IsThumb, HasV5T, IsDarwin]>;
953 // zextload i1 -> zextload i8
954 def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
955 (tLDRB t_addrmode_s1:$addr)>;
957 // extload -> zextload
958 def : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
959 def : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
960 def : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
962 // If it's impossible to use [r,r] address mode for sextload, select to
963 // ldr{b|h} + sxt{b|h} instead.
964 def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
965 (tSXTB (tLDRB t_addrmode_s1:$addr))>,
966 Requires<[IsThumb1Only, HasV6]>;
967 def : T1Pat<(sextloadi16 t_addrmode_s2:$addr),
968 (tSXTH (tLDRH t_addrmode_s2:$addr))>,
969 Requires<[IsThumb1Only, HasV6]>;
971 def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
972 (tASRri (tLSLri (tLDRB t_addrmode_s1:$addr), 24), 24)>;
973 def : T1Pat<(sextloadi16 t_addrmode_s1:$addr),
974 (tASRri (tLSLri (tLDRH t_addrmode_s1:$addr), 16), 16)>;
976 // Large immediate handling.
979 def : T1Pat<(i32 thumb_immshifted:$src),
980 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
981 (thumb_immshifted_shamt imm:$src))>;
983 def : T1Pat<(i32 imm0_255_comp:$src),
984 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
986 // Pseudo instruction that combines ldr from constpool and add pc. This should
987 // be expanded into two instructions late to allow if-conversion and
989 let isReMaterializable = 1 in
990 def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
991 NoItinerary, "@ ldr.n\t$dst, $addr\n$cp:\n\tadd\t$dst, pc",
992 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
994 Requires<[IsThumb1Only]>;