1 //===-- ARMInstrThumb.td - Thumb support for ARM -----------*- tablegen -*-===//
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, SDNPOptInGlue, SDNPOutGlue,
22 def imm_sr_XFORM: SDNodeXForm<imm, [{
23 unsigned Imm = N->getZExtValue();
24 return CurDAG->getTargetConstant((Imm == 32 ? 0 : Imm), SDLoc(N), MVT::i32);
26 def ThumbSRImmAsmOperand: AsmOperandClass { let Name = "ImmThumbSR"; }
27 def imm_sr : Operand<i32>, PatLeaf<(imm), [{
28 uint64_t Imm = N->getZExtValue();
29 return Imm > 0 && Imm <= 32;
31 let PrintMethod = "printThumbSRImm";
32 let ParserMatchClass = ThumbSRImmAsmOperand;
35 def imm_comp_XFORM : SDNodeXForm<imm, [{
36 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), SDLoc(N),
40 def imm0_7_neg : PatLeaf<(i32 imm), [{
41 return (uint32_t)-N->getZExtValue() < 8;
44 def imm0_255_comp : PatLeaf<(i32 imm), [{
45 return ~((uint32_t)N->getZExtValue()) < 256;
48 def imm8_255 : ImmLeaf<i32, [{
49 return Imm >= 8 && Imm < 256;
51 def imm8_255_neg : PatLeaf<(i32 imm), [{
52 unsigned Val = -N->getZExtValue();
53 return Val >= 8 && Val < 256;
56 // Break imm's up into two pieces: an immediate + a left shift. This uses
57 // thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
58 // to get the val/shift pieces.
59 def thumb_immshifted : PatLeaf<(imm), [{
60 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
63 def thumb_immshifted_val : SDNodeXForm<imm, [{
64 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
65 return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
68 def thumb_immshifted_shamt : SDNodeXForm<imm, [{
69 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
70 return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
73 // Scaled 4 immediate.
74 def t_imm0_1020s4_asmoperand: AsmOperandClass { let Name = "Imm0_1020s4"; }
75 def t_imm0_1020s4 : Operand<i32> {
76 let PrintMethod = "printThumbS4ImmOperand";
77 let ParserMatchClass = t_imm0_1020s4_asmoperand;
78 let OperandType = "OPERAND_IMMEDIATE";
81 def t_imm0_508s4_asmoperand: AsmOperandClass { let Name = "Imm0_508s4"; }
82 def t_imm0_508s4 : Operand<i32> {
83 let PrintMethod = "printThumbS4ImmOperand";
84 let ParserMatchClass = t_imm0_508s4_asmoperand;
85 let OperandType = "OPERAND_IMMEDIATE";
87 // Alias use only, so no printer is necessary.
88 def t_imm0_508s4_neg_asmoperand: AsmOperandClass { let Name = "Imm0_508s4Neg"; }
89 def t_imm0_508s4_neg : Operand<i32> {
90 let ParserMatchClass = t_imm0_508s4_neg_asmoperand;
91 let OperandType = "OPERAND_IMMEDIATE";
94 // Define Thumb specific addressing modes.
96 // unsigned 8-bit, 2-scaled memory offset
97 class OperandUnsignedOffset_b8s2 : AsmOperandClass {
98 let Name = "UnsignedOffset_b8s2";
99 let PredicateMethod = "isUnsignedOffset<8, 2>";
102 def UnsignedOffset_b8s2 : OperandUnsignedOffset_b8s2;
104 // thumb style PC relative operand. signed, 8 bits magnitude,
105 // two bits shift. can be represented as either [pc, #imm], #imm,
106 // or relocatable expression...
107 def ThumbMemPC : AsmOperandClass {
108 let Name = "ThumbMemPC";
111 let OperandType = "OPERAND_PCREL" in {
112 def t_brtarget : Operand<OtherVT> {
113 let EncoderMethod = "getThumbBRTargetOpValue";
114 let DecoderMethod = "DecodeThumbBROperand";
117 // ADR instruction labels.
118 def t_adrlabel : Operand<i32> {
119 let EncoderMethod = "getThumbAdrLabelOpValue";
120 let PrintMethod = "printAdrLabelOperand<2>";
121 let ParserMatchClass = UnsignedOffset_b8s2;
124 def t_bcctarget : Operand<i32> {
125 let EncoderMethod = "getThumbBCCTargetOpValue";
126 let DecoderMethod = "DecodeThumbBCCTargetOperand";
129 def t_cbtarget : Operand<i32> {
130 let EncoderMethod = "getThumbCBTargetOpValue";
131 let DecoderMethod = "DecodeThumbCmpBROperand";
134 def t_bltarget : Operand<i32> {
135 let EncoderMethod = "getThumbBLTargetOpValue";
136 let DecoderMethod = "DecodeThumbBLTargetOperand";
139 def t_blxtarget : Operand<i32> {
140 let EncoderMethod = "getThumbBLXTargetOpValue";
141 let DecoderMethod = "DecodeThumbBLXOffset";
144 // t_addrmode_pc := <label> => pc + imm8 * 4
146 def t_addrmode_pc : MemOperand {
147 let EncoderMethod = "getAddrModePCOpValue";
148 let DecoderMethod = "DecodeThumbAddrModePC";
149 let PrintMethod = "printThumbLdrLabelOperand";
150 let ParserMatchClass = ThumbMemPC;
154 // t_addrmode_rr := reg + reg
156 def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
157 def t_addrmode_rr : MemOperand,
158 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
159 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
160 let PrintMethod = "printThumbAddrModeRROperand";
161 let DecoderMethod = "DecodeThumbAddrModeRR";
162 let ParserMatchClass = t_addrmode_rr_asm_operand;
163 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
166 // t_addrmode_rrs := reg + reg
168 // We use separate scaled versions because the Select* functions need
169 // to explicitly check for a matching constant and return false here so that
170 // the reg+imm forms will match instead. This is a horrible way to do that,
171 // as it forces tight coupling between the methods, but it's how selectiondag
173 def t_addrmode_rrs1 : MemOperand,
174 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
175 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
176 let PrintMethod = "printThumbAddrModeRROperand";
177 let DecoderMethod = "DecodeThumbAddrModeRR";
178 let ParserMatchClass = t_addrmode_rr_asm_operand;
179 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
181 def t_addrmode_rrs2 : MemOperand,
182 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
183 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
184 let DecoderMethod = "DecodeThumbAddrModeRR";
185 let PrintMethod = "printThumbAddrModeRROperand";
186 let ParserMatchClass = t_addrmode_rr_asm_operand;
187 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
189 def t_addrmode_rrs4 : MemOperand,
190 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
191 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
192 let DecoderMethod = "DecodeThumbAddrModeRR";
193 let PrintMethod = "printThumbAddrModeRROperand";
194 let ParserMatchClass = t_addrmode_rr_asm_operand;
195 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
198 // t_addrmode_is4 := reg + imm5 * 4
200 def t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
201 def t_addrmode_is4 : MemOperand,
202 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
203 let EncoderMethod = "getAddrModeISOpValue";
204 let DecoderMethod = "DecodeThumbAddrModeIS";
205 let PrintMethod = "printThumbAddrModeImm5S4Operand";
206 let ParserMatchClass = t_addrmode_is4_asm_operand;
207 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
210 // t_addrmode_is2 := reg + imm5 * 2
212 def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
213 def t_addrmode_is2 : MemOperand,
214 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
215 let EncoderMethod = "getAddrModeISOpValue";
216 let DecoderMethod = "DecodeThumbAddrModeIS";
217 let PrintMethod = "printThumbAddrModeImm5S2Operand";
218 let ParserMatchClass = t_addrmode_is2_asm_operand;
219 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
222 // t_addrmode_is1 := reg + imm5
224 def t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
225 def t_addrmode_is1 : MemOperand,
226 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
227 let EncoderMethod = "getAddrModeISOpValue";
228 let DecoderMethod = "DecodeThumbAddrModeIS";
229 let PrintMethod = "printThumbAddrModeImm5S1Operand";
230 let ParserMatchClass = t_addrmode_is1_asm_operand;
231 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
234 // t_addrmode_sp := sp + imm8 * 4
236 // FIXME: This really shouldn't have an explicit SP operand at all. It should
237 // be implicit, just like in the instruction encoding itself.
238 def t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
239 def t_addrmode_sp : MemOperand,
240 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
241 let EncoderMethod = "getAddrModeThumbSPOpValue";
242 let DecoderMethod = "DecodeThumbAddrModeSP";
243 let PrintMethod = "printThumbAddrModeSPOperand";
244 let ParserMatchClass = t_addrmode_sp_asm_operand;
245 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
248 //===----------------------------------------------------------------------===//
249 // Miscellaneous Instructions.
252 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
253 // from removing one half of the matched pairs. That breaks PEI, which assumes
254 // these will always be in pairs, and asserts if it finds otherwise. Better way?
255 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
256 def tADJCALLSTACKUP :
257 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
258 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
259 Requires<[IsThumb, IsThumb1Only]>;
261 def tADJCALLSTACKDOWN :
262 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
263 [(ARMcallseq_start imm:$amt)]>,
264 Requires<[IsThumb, IsThumb1Only]>;
267 class T1SystemEncoding<bits<8> opc>
268 : T1Encoding<0b101111> {
269 let Inst{9-8} = 0b11;
273 def tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
274 [(int_arm_hint imm0_15:$imm)]>,
275 T1SystemEncoding<0x00>,
276 Requires<[IsThumb, HasV6M]> {
281 class tHintAlias<string Asm, dag Result> : tInstAlias<Asm, Result> {
282 let Predicates = [IsThumb, HasV6M];
285 def : tHintAlias<"nop$p", (tHINT 0, pred:$p)>; // A8.6.110
286 def : tHintAlias<"yield$p", (tHINT 1, pred:$p)>; // A8.6.410
287 def : tHintAlias<"wfe$p", (tHINT 2, pred:$p)>; // A8.6.408
288 def : tHintAlias<"wfi$p", (tHINT 3, pred:$p)>; // A8.6.409
289 def : tHintAlias<"sev$p", (tHINT 4, pred:$p)>; // A8.6.157
290 def : tInstAlias<"sevl$p", (tHINT 5, pred:$p)> {
291 let Predicates = [IsThumb2, HasV8];
294 // The imm operand $val can be used by a debugger to store more information
295 // about the breakpoint.
296 def tBKPT : T1I<(outs), (ins imm0_255:$val), NoItinerary, "bkpt\t$val",
298 T1Encoding<0b101111> {
299 let Inst{9-8} = 0b10;
304 // default immediate for breakpoint mnemonic
305 def : InstAlias<"bkpt", (tBKPT 0)>, Requires<[IsThumb]>;
307 def tHLT : T1I<(outs), (ins imm0_63:$val), NoItinerary, "hlt\t$val",
308 []>, T1Encoding<0b101110>, Requires<[IsThumb, HasV8]> {
309 let Inst{9-6} = 0b1010;
314 def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
315 []>, T1Encoding<0b101101>, Requires<[IsNotMClass]>, Deprecated<HasV8Ops> {
318 let Inst{9-5} = 0b10010;
321 let Inst{2-0} = 0b000;
324 // Change Processor State is a system instruction -- for disassembly only.
325 def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
326 NoItinerary, "cps$imod $iflags", []>,
334 let Inst{2-0} = iflags;
335 let DecoderMethod = "DecodeThumbCPS";
338 // For both thumb1 and thumb2.
339 let isNotDuplicable = 1, isCodeGenOnly = 1 in
340 def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
341 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
342 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
345 let Inst{6-3} = 0b1111; // Rm = pc
349 // ADD <Rd>, sp, #<imm8>
350 // FIXME: This should not be marked as having side effects, and it should be
351 // rematerializable. Clearing the side effect bit causes miscompilations,
352 // probably because the instruction can be moved around.
353 def tADDrSPi : T1pI<(outs tGPR:$dst), (ins GPRsp:$sp, t_imm0_1020s4:$imm),
354 IIC_iALUi, "add", "\t$dst, $sp, $imm", []>,
355 T1Encoding<{1,0,1,0,1,?}>, Sched<[WriteALU]> {
359 let Inst{10-8} = dst;
361 let DecoderMethod = "DecodeThumbAddSpecialReg";
364 // Thumb1 frame lowering is rather fragile, we hope to be able to use
365 // tADDrSPi, but we may need to insert a sequence that clobbers CPSR.
366 def tADDframe : PseudoInst<(outs tGPR:$dst), (ins i32imm:$base, i32imm:$offset),
368 Requires<[IsThumb, IsThumb1Only]> {
372 // ADD sp, sp, #<imm7>
373 def tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
374 IIC_iALUi, "add", "\t$Rdn, $imm", []>,
375 T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
379 let DecoderMethod = "DecodeThumbAddSPImm";
382 // SUB sp, sp, #<imm7>
383 // FIXME: The encoding and the ASM string don't match up.
384 def tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
385 IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
386 T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
390 let DecoderMethod = "DecodeThumbAddSPImm";
393 def : tInstAlias<"add${p} sp, $imm",
394 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
395 def : tInstAlias<"add${p} sp, sp, $imm",
396 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
398 // Can optionally specify SP as a three operand instruction.
399 def : tInstAlias<"add${p} sp, sp, $imm",
400 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
401 def : tInstAlias<"sub${p} sp, sp, $imm",
402 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
405 def tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
406 "add", "\t$Rdn, $sp, $Rn", []>,
407 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
408 // A8.6.9 Encoding T1
410 let Inst{7} = Rdn{3};
411 let Inst{6-3} = 0b1101;
412 let Inst{2-0} = Rdn{2-0};
413 let DecoderMethod = "DecodeThumbAddSPReg";
417 def tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
418 "add", "\t$Rdn, $Rm", []>,
419 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
420 // A8.6.9 Encoding T2
424 let Inst{2-0} = 0b101;
425 let DecoderMethod = "DecodeThumbAddSPReg";
428 //===----------------------------------------------------------------------===//
429 // Control Flow Instructions.
433 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
434 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
435 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
439 let Inst{2-0} = 0b000;
440 let Unpredictable{2-0} = 0b111;
444 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
445 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
446 [(ARMretflag)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
448 // Alternative return instruction used by vararg functions.
449 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
451 (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
454 // All calls clobber the non-callee saved registers. SP is marked as a use to
455 // prevent stack-pointer assignments that appear immediately before calls from
456 // potentially appearing dead.
458 Defs = [LR], Uses = [SP] in {
459 // Also used for Thumb2
460 def tBL : TIx2<0b11110, 0b11, 1,
461 (outs), (ins pred:$p, t_bltarget:$func), IIC_Br,
463 [(ARMtcall tglobaladdr:$func)]>,
464 Requires<[IsThumb]>, Sched<[WriteBrL]> {
466 let Inst{26} = func{23};
467 let Inst{25-16} = func{20-11};
468 let Inst{13} = func{22};
469 let Inst{11} = func{21};
470 let Inst{10-0} = func{10-0};
473 // ARMv5T and above, also used for Thumb2
474 def tBLXi : TIx2<0b11110, 0b11, 0,
475 (outs), (ins pred:$p, t_blxtarget:$func), IIC_Br,
477 [(ARMcall tglobaladdr:$func)]>,
478 Requires<[IsThumb, HasV5T, IsNotMClass]>, Sched<[WriteBrL]> {
480 let Inst{26} = func{23};
481 let Inst{25-16} = func{20-11};
482 let Inst{13} = func{22};
483 let Inst{11} = func{21};
484 let Inst{10-1} = func{10-1};
485 let Inst{0} = 0; // func{0} is assumed zero
488 // Also used for Thumb2
489 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
491 [(ARMtcall GPR:$func)]>,
492 Requires<[IsThumb, HasV5T]>,
493 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
495 let Inst{6-3} = func;
496 let Inst{2-0} = 0b000;
500 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
502 [(ARMcall_nolink tGPR:$func)]>,
503 Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
506 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
507 let isPredicable = 1 in
508 def tB : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
509 "b", "\t$target", [(br bb:$target)]>,
510 T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
512 let Inst{10-0} = target;
513 let AsmMatchConverter = "cvtThumbBranches";
517 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
518 // the clobber of LR.
520 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
521 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>,
524 def tBR_JTr : tPseudoInst<(outs),
525 (ins tGPR:$target, i32imm:$jt),
527 [(ARMbrjt tGPR:$target, tjumptable:$jt)]>,
528 Sched<[WriteBrTbl]> {
529 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
533 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
534 // a two-value operand where a dag node expects two operands. :(
535 let isBranch = 1, isTerminator = 1 in
536 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
538 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
539 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
543 let Inst{7-0} = target;
544 let AsmMatchConverter = "cvtThumbBranches";
549 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
552 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
554 (tBX GPR:$dst, (ops 14, zero_reg))>,
555 Requires<[IsThumb]>, Sched<[WriteBr]>;
557 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
558 // on MachO), so it's in ARMInstrThumb2.td.
559 // Non-MachO version:
561 def tTAILJMPdND : tPseudoExpand<(outs),
562 (ins t_brtarget:$dst, pred:$p),
564 (tB t_brtarget:$dst, pred:$p)>,
565 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
570 // A8.6.218 Supervisor Call (Software Interrupt)
571 // A8.6.16 B: Encoding T1
572 // If Inst{11-8} == 0b1111 then SEE SVC
573 let isCall = 1, Uses = [SP] in
574 def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
575 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
577 let Inst{15-12} = 0b1101;
578 let Inst{11-8} = 0b1111;
582 // The assembler uses 0xDEFE for a trap instruction.
583 let isBarrier = 1, isTerminator = 1 in
584 def tTRAP : TI<(outs), (ins), IIC_Br,
585 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
589 //===----------------------------------------------------------------------===//
590 // Load Store Instructions.
593 // Loads: reg/reg and reg/imm5
594 let canFoldAsLoad = 1, isReMaterializable = 1 in
595 multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
596 Operand AddrMode_r, Operand AddrMode_i,
597 AddrMode am, InstrItinClass itin_r,
598 InstrItinClass itin_i, string asm,
601 T1pILdStEncode<reg_opc,
602 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
603 am, itin_r, asm, "\t$Rt, $addr",
604 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
606 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
607 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
608 am, itin_i, asm, "\t$Rt, $addr",
609 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
611 // Stores: reg/reg and reg/imm5
612 multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
613 Operand AddrMode_r, Operand AddrMode_i,
614 AddrMode am, InstrItinClass itin_r,
615 InstrItinClass itin_i, string asm,
618 T1pILdStEncode<reg_opc,
619 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
620 am, itin_r, asm, "\t$Rt, $addr",
621 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
623 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
624 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
625 am, itin_i, asm, "\t$Rt, $addr",
626 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
630 defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
631 t_addrmode_is4, AddrModeT1_4,
632 IIC_iLoad_r, IIC_iLoad_i, "ldr",
633 UnOpFrag<(load node:$Src)>>;
636 defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
637 t_addrmode_is1, AddrModeT1_1,
638 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
639 UnOpFrag<(zextloadi8 node:$Src)>>;
642 defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
643 t_addrmode_is2, AddrModeT1_2,
644 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
645 UnOpFrag<(zextloadi16 node:$Src)>>;
647 let AddedComplexity = 10 in
648 def tLDRSB : // A8.6.80
649 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
650 AddrModeT1_1, IIC_iLoad_bh_r,
651 "ldrsb", "\t$Rt, $addr",
652 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
654 let AddedComplexity = 10 in
655 def tLDRSH : // A8.6.84
656 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
657 AddrModeT1_2, IIC_iLoad_bh_r,
658 "ldrsh", "\t$Rt, $addr",
659 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
661 let canFoldAsLoad = 1 in
662 def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
663 "ldr", "\t$Rt, $addr",
664 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
669 let Inst{7-0} = addr;
672 let canFoldAsLoad = 1, isReMaterializable = 1 in
673 def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
674 "ldr", "\t$Rt, $addr",
675 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
676 T1Encoding<{0,1,0,0,1,?}> {
681 let Inst{7-0} = addr;
684 // A8.6.194 & A8.6.192
685 defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
686 t_addrmode_is4, AddrModeT1_4,
687 IIC_iStore_r, IIC_iStore_i, "str",
688 BinOpFrag<(store node:$LHS, node:$RHS)>>;
690 // A8.6.197 & A8.6.195
691 defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
692 t_addrmode_is1, AddrModeT1_1,
693 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
694 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
696 // A8.6.207 & A8.6.205
697 defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
698 t_addrmode_is2, AddrModeT1_2,
699 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
700 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
703 def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
704 "str", "\t$Rt, $addr",
705 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
710 let Inst{7-0} = addr;
713 //===----------------------------------------------------------------------===//
714 // Load / store multiple Instructions.
717 // These require base address to be written back or one of the loaded regs.
718 let hasSideEffects = 0 in {
720 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
721 def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
722 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
726 let Inst{7-0} = regs;
729 // Writeback version is just a pseudo, as there's no encoding difference.
730 // Writeback happens iff the base register is not in the destination register
733 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
734 "$Rn = $wb", IIC_iLoad_mu>,
735 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
737 let OutOperandList = (outs GPR:$wb);
738 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
740 let isCodeGenOnly = 1;
742 list<Predicate> Predicates = [IsThumb];
745 // There is no non-writeback version of STM for Thumb.
746 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
747 def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
748 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
749 AddrModeNone, 2, IIC_iStore_mu,
750 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
751 T1Encoding<{1,1,0,0,0,?}> {
755 let Inst{7-0} = regs;
760 def : InstAlias<"ldm${p} $Rn!, $regs",
761 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)>,
762 Requires<[IsThumb, IsThumb1Only]>;
764 let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
765 def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
767 "pop${p}\t$regs", []>,
768 T1Misc<{1,1,0,?,?,?,?}> {
770 let Inst{8} = regs{15};
771 let Inst{7-0} = regs{7-0};
774 let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
775 def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
777 "push${p}\t$regs", []>,
778 T1Misc<{0,1,0,?,?,?,?}> {
780 let Inst{8} = regs{14};
781 let Inst{7-0} = regs{7-0};
784 //===----------------------------------------------------------------------===//
785 // Arithmetic Instructions.
788 // Helper classes for encoding T1pI patterns:
789 class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
790 string opc, string asm, list<dag> pattern>
791 : T1pI<oops, iops, itin, opc, asm, pattern>,
792 T1DataProcessing<opA> {
798 class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
799 string opc, string asm, list<dag> pattern>
800 : T1pI<oops, iops, itin, opc, asm, pattern>,
808 // Helper classes for encoding T1sI patterns:
809 class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
810 string opc, string asm, list<dag> pattern>
811 : T1sI<oops, iops, itin, opc, asm, pattern>,
812 T1DataProcessing<opA> {
818 class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
819 string opc, string asm, list<dag> pattern>
820 : T1sI<oops, iops, itin, opc, asm, pattern>,
829 class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
830 string opc, string asm, list<dag> pattern>
831 : T1sI<oops, iops, itin, opc, asm, pattern>,
839 // Helper classes for encoding T1sIt patterns:
840 class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
841 string opc, string asm, list<dag> pattern>
842 : T1sIt<oops, iops, itin, opc, asm, pattern>,
843 T1DataProcessing<opA> {
849 class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
850 string opc, string asm, list<dag> pattern>
851 : T1sIt<oops, iops, itin, opc, asm, pattern>,
855 let Inst{10-8} = Rdn;
856 let Inst{7-0} = imm8;
859 // Add with carry register
860 let isCommutable = 1, Uses = [CPSR] in
862 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
863 "adc", "\t$Rdn, $Rm",
864 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
867 def tADDi3 : // A8.6.4 T1
868 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
870 "add", "\t$Rd, $Rm, $imm3",
871 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
874 let Inst{8-6} = imm3;
877 def tADDi8 : // A8.6.4 T2
878 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
879 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
880 "add", "\t$Rdn, $imm8",
881 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
885 let isCommutable = 1 in
886 def tADDrr : // A8.6.6 T1
887 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
889 "add", "\t$Rd, $Rn, $Rm",
890 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
892 let hasSideEffects = 0 in
893 def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
894 "add", "\t$Rdn, $Rm", []>,
895 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
899 let Inst{7} = Rdn{3};
901 let Inst{2-0} = Rdn{2-0};
905 let isCommutable = 1 in
906 def tAND : // A8.6.12
907 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
909 "and", "\t$Rdn, $Rm",
910 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
913 def tASRri : // A8.6.14
914 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
916 "asr", "\t$Rd, $Rm, $imm5",
917 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
920 let Inst{10-6} = imm5;
924 def tASRrr : // A8.6.15
925 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
927 "asr", "\t$Rdn, $Rm",
928 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
931 def tBIC : // A8.6.20
932 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
934 "bic", "\t$Rdn, $Rm",
935 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
939 let isCompare = 1, Defs = [CPSR] in {
940 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
941 // Compare-to-zero still works out, just not the relationals
942 //def tCMN : // A8.6.33
943 // T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
945 // "cmn", "\t$lhs, $rhs",
946 // [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
948 def tCMNz : // A8.6.33
949 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
952 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
954 } // isCompare = 1, Defs = [CPSR]
957 let isCompare = 1, Defs = [CPSR] in {
958 def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
959 "cmp", "\t$Rn, $imm8",
960 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
961 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
966 let Inst{7-0} = imm8;
970 def tCMPr : // A8.6.36 T1
971 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
974 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
976 def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
977 "cmp", "\t$Rn, $Rm", []>,
978 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
984 let Inst{2-0} = Rn{2-0};
986 } // isCompare = 1, Defs = [CPSR]
990 let isCommutable = 1 in
991 def tEOR : // A8.6.45
992 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
994 "eor", "\t$Rdn, $Rm",
995 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
998 def tLSLri : // A8.6.88
999 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
1001 "lsl", "\t$Rd, $Rm, $imm5",
1002 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
1005 let Inst{10-6} = imm5;
1009 def tLSLrr : // A8.6.89
1010 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1012 "lsl", "\t$Rdn, $Rm",
1013 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1016 def tLSRri : // A8.6.90
1017 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
1019 "lsr", "\t$Rd, $Rm, $imm5",
1020 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1023 let Inst{10-6} = imm5;
1027 def tLSRrr : // A8.6.91
1028 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1030 "lsr", "\t$Rdn, $Rm",
1031 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1034 let isMoveImm = 1 in
1035 def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
1036 "mov", "\t$Rd, $imm8",
1037 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1038 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
1042 let Inst{10-8} = Rd;
1043 let Inst{7-0} = imm8;
1045 // Because we have an explicit tMOVSr below, we need an alias to handle
1046 // the immediate "movs" form here. Blech.
1047 def : tInstAlias <"movs $Rdn, $imm",
1048 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
1050 // A7-73: MOV(2) - mov setting flag.
1052 let hasSideEffects = 0 in {
1053 def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
1055 "mov", "\t$Rd, $Rm", "", []>,
1056 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
1060 let Inst{7} = Rd{3};
1062 let Inst{2-0} = Rd{2-0};
1064 let Defs = [CPSR] in
1065 def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1066 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
1070 let Inst{15-6} = 0b0000000000;
1076 // Multiply register
1077 let isCommutable = 1 in
1078 def tMUL : // A8.6.105 T1
1079 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1080 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1081 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1082 T1DataProcessing<0b1101> {
1087 let AsmMatchConverter = "cvtThumbMultiply";
1090 def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1093 // Move inverse register
1094 def tMVN : // A8.6.107
1095 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1096 "mvn", "\t$Rd, $Rn",
1097 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
1099 // Bitwise or register
1100 let isCommutable = 1 in
1101 def tORR : // A8.6.114
1102 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1104 "orr", "\t$Rdn, $Rm",
1105 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1108 def tREV : // A8.6.134
1109 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1111 "rev", "\t$Rd, $Rm",
1112 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1113 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1115 def tREV16 : // A8.6.135
1116 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1118 "rev16", "\t$Rd, $Rm",
1119 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
1120 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1122 def tREVSH : // A8.6.136
1123 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1125 "revsh", "\t$Rd, $Rm",
1126 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
1127 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1129 // Rotate right register
1130 def tROR : // A8.6.139
1131 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1133 "ror", "\t$Rdn, $Rm",
1134 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1138 def tRSB : // A8.6.141
1139 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1141 "rsb", "\t$Rd, $Rn, #0",
1142 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
1144 // Subtract with carry register
1145 let Uses = [CPSR] in
1146 def tSBC : // A8.6.151
1147 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1149 "sbc", "\t$Rdn, $Rm",
1150 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>,
1153 // Subtract immediate
1154 def tSUBi3 : // A8.6.210 T1
1155 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
1157 "sub", "\t$Rd, $Rm, $imm3",
1158 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1161 let Inst{8-6} = imm3;
1164 def tSUBi8 : // A8.6.210 T2
1165 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1166 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
1167 "sub", "\t$Rdn, $imm8",
1168 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1171 // Subtract register
1172 def tSUBrr : // A8.6.212
1173 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1175 "sub", "\t$Rd, $Rn, $Rm",
1176 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1180 def tSXTB : // A8.6.222
1181 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1183 "sxtb", "\t$Rd, $Rm",
1184 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1185 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1188 // Sign-extend short
1189 def tSXTH : // A8.6.224
1190 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1192 "sxth", "\t$Rd, $Rm",
1193 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1194 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1198 let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
1199 def tTST : // A8.6.230
1200 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1201 "tst", "\t$Rn, $Rm",
1202 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1205 // A8.8.247 UDF - Undefined (Encoding T1)
1206 def tUDF : TI<(outs), (ins imm0_255:$imm8), IIC_Br, "udf\t$imm8",
1207 [(int_arm_undefined imm0_255:$imm8)]>, Encoding16 {
1209 let Inst{15-12} = 0b1101;
1210 let Inst{11-8} = 0b1110;
1211 let Inst{7-0} = imm8;
1215 def tUXTB : // A8.6.262
1216 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1218 "uxtb", "\t$Rd, $Rm",
1219 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1220 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1223 // Zero-extend short
1224 def tUXTH : // A8.6.264
1225 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1227 "uxth", "\t$Rd, $Rm",
1228 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1229 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1231 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
1232 // Expanded after instruction selection into a branch sequence.
1233 let usesCustomInserter = 1 in // Expanded after instruction selection.
1234 def tMOVCCr_pseudo :
1235 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1237 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
1239 // tLEApcrel - Load a pc-relative address into a register without offending the
1242 def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1243 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
1244 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
1247 let Inst{10-8} = Rd;
1248 let Inst{7-0} = addr;
1249 let DecoderMethod = "DecodeThumbAddSpecialReg";
1252 let hasSideEffects = 0, isReMaterializable = 1 in
1253 def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1254 2, IIC_iALUi, []>, Sched<[WriteALU]>;
1256 let hasSideEffects = 1 in
1257 def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1258 (ins i32imm:$label, pred:$p),
1259 2, IIC_iALUi, []>, Sched<[WriteALU]>;
1261 //===----------------------------------------------------------------------===//
1265 // __aeabi_read_tp preserves the registers r1-r3.
1266 // This is a pseudo inst so that we can get the encoding right,
1267 // complete with fixup for the aeabi_read_tp function.
1268 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
1269 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
1270 [(set R0, ARMthread_pointer)]>,
1273 //===----------------------------------------------------------------------===//
1274 // SJLJ Exception handling intrinsics
1277 // eh_sjlj_setjmp() is an instruction sequence to store the return address and
1278 // save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1279 // from some other function to get here, and we're using the stack frame for the
1280 // containing function to save/restore registers, we can't keep anything live in
1281 // regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1282 // tromped upon when we get here from a longjmp(). We force everything out of
1283 // registers except for our own input by listing the relevant registers in
1284 // Defs. By doing so, we also cause the prologue/epilogue code to actively
1285 // preserve all of the callee-saved resgisters, which is exactly what we want.
1286 // $val is a scratch register for our use.
1287 let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
1288 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1289 usesCustomInserter = 1 in
1290 def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1291 AddrModeNone, 0, NoItinerary, "","",
1292 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
1294 // FIXME: Non-IOS version(s)
1295 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1296 Defs = [ R7, LR, SP ] in
1297 def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
1298 AddrModeNone, 0, IndexModeNone,
1299 Pseudo, NoItinerary, "", "",
1300 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1301 Requires<[IsThumb]>;
1303 //===----------------------------------------------------------------------===//
1304 // Non-Instruction Patterns
1308 def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1309 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1310 def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1311 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1314 def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1315 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1316 def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
1317 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
1318 def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1319 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
1321 // Subtract with carry
1322 def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1323 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1324 def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1325 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1326 def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1327 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
1329 // Bswap 16 with load/store
1330 def : T1Pat<(srl (bswap (extloadi16 t_addrmode_rrs2:$addr)), (i32 16)),
1331 (tREV16 (tLDRHr t_addrmode_rrs2:$addr))>;
1332 def : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
1333 (tREV16 (tLDRHi t_addrmode_is2:$addr))>;
1334 def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1335 t_addrmode_rrs2:$addr),
1336 (tSTRHr (tREV16 tGPR:$Rn), t_addrmode_rrs2:$addr)>;
1337 def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1338 t_addrmode_is2:$addr),
1339 (tSTRHi(tREV16 tGPR:$Rn), t_addrmode_is2:$addr)>;
1342 def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
1345 def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
1348 (ARMWrapperPIC tglobaladdr:$addr))]>,
1349 Requires<[IsThumb, DontUseMovt]>;
1351 def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1354 (ARMWrapper tglobaladdr:$src))]>,
1355 Requires<[IsThumb, DontUseMovt]>;
1359 def : T1Pat<(ARMWrapperJT tjumptable:$dst),
1360 (tLEApcrelJT tjumptable:$dst)>;
1363 def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
1364 Requires<[IsThumb]>;
1366 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
1367 Requires<[IsThumb, HasV5T, IsNotMClass]>;
1369 // Indirect calls to ARM routines
1370 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1371 Requires<[IsThumb, HasV5T]>;
1373 // zextload i1 -> zextload i8
1374 def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1375 (tLDRBr t_addrmode_rrs1:$addr)>;
1376 def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1377 (tLDRBi t_addrmode_is1:$addr)>;
1379 // extload from the stack -> word load from the stack, as it avoids having to
1380 // materialize the base in a separate register. This only works when a word
1381 // load puts the byte/halfword value in the same place in the register that the
1382 // byte/halfword load would, i.e. when little-endian.
1383 def : T1Pat<(extloadi1 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1384 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1385 def : T1Pat<(extloadi8 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1386 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1387 def : T1Pat<(extloadi16 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1388 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1390 // extload -> zextload
1391 def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1392 def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1393 def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1394 def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1395 def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1396 def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1398 // If it's impossible to use [r,r] address mode for sextload, select to
1399 // ldr{b|h} + sxt{b|h} instead.
1400 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1401 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1402 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1403 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1404 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
1405 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1406 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1407 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1408 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1409 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1410 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
1411 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1413 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1414 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
1415 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1416 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1417 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1418 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1419 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1420 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
1422 def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
1423 (tLDRBi t_addrmode_is1:$src)>;
1424 def : T1Pat<(atomic_load_8 t_addrmode_rrs1:$src),
1425 (tLDRBr t_addrmode_rrs1:$src)>;
1426 def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
1427 (tLDRHi t_addrmode_is2:$src)>;
1428 def : T1Pat<(atomic_load_16 t_addrmode_rrs2:$src),
1429 (tLDRHr t_addrmode_rrs2:$src)>;
1430 def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
1431 (tLDRi t_addrmode_is4:$src)>;
1432 def : T1Pat<(atomic_load_32 t_addrmode_rrs4:$src),
1433 (tLDRr t_addrmode_rrs4:$src)>;
1434 def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1435 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
1436 def : T1Pat<(atomic_store_8 t_addrmode_rrs1:$ptr, tGPR:$val),
1437 (tSTRBr tGPR:$val, t_addrmode_rrs1:$ptr)>;
1438 def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1439 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
1440 def : T1Pat<(atomic_store_16 t_addrmode_rrs2:$ptr, tGPR:$val),
1441 (tSTRHr tGPR:$val, t_addrmode_rrs2:$ptr)>;
1442 def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1443 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
1444 def : T1Pat<(atomic_store_32 t_addrmode_rrs4:$ptr, tGPR:$val),
1445 (tSTRr tGPR:$val, t_addrmode_rrs4:$ptr)>;
1447 // Large immediate handling.
1450 def : T1Pat<(i32 thumb_immshifted:$src),
1451 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1452 (thumb_immshifted_shamt imm:$src))>;
1454 def : T1Pat<(i32 imm0_255_comp:$src),
1455 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
1457 // Pseudo instruction that combines ldr from constpool and add pc. This should
1458 // be expanded into two instructions late to allow if-conversion and
1460 let isReMaterializable = 1 in
1461 def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
1463 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1465 Requires<[IsThumb, IsThumb1Only]>;
1467 // Pseudo-instruction for merged POP and return.
1468 // FIXME: remove when we have a way to marking a MI with these properties.
1469 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1470 hasExtraDefRegAllocReq = 1 in
1471 def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
1473 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
1475 // Indirect branch using "mov pc, $Rm"
1476 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1477 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
1478 2, IIC_Br, [(brind GPR:$Rm)],
1479 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
1483 // In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1484 // encoding is available on ARMv6K, but we don't differentiate that finely.
1485 def : InstAlias<"nop", (tMOVr R8, R8, 14, 0)>,Requires<[IsThumb, IsThumb1Only]>;
1488 // For round-trip assembly/disassembly, we have to handle a CPS instruction
1489 // without any iflags. That's not, strictly speaking, valid syntax, but it's
1490 // a useful extension and assembles to defined behaviour (the insn does
1492 def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1493 def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1495 // "neg" is and alias for "rsb rd, rn, #0"
1496 def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1497 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1500 // Implied destination operand forms for shifts.
1501 def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1502 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1503 def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1504 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1505 def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1506 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;