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]> {
530 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
534 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
535 // a two-value operand where a dag node expects two operands. :(
536 let isBranch = 1, isTerminator = 1 in
537 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
539 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
540 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
544 let Inst{7-0} = target;
545 let AsmMatchConverter = "cvtThumbBranches";
550 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
553 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
555 (tBX GPR:$dst, (ops 14, zero_reg))>,
556 Requires<[IsThumb]>, Sched<[WriteBr]>;
558 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
559 // on MachO), so it's in ARMInstrThumb2.td.
560 // Non-MachO version:
562 def tTAILJMPdND : tPseudoExpand<(outs),
563 (ins t_brtarget:$dst, pred:$p),
565 (tB t_brtarget:$dst, pred:$p)>,
566 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
571 // A8.6.218 Supervisor Call (Software Interrupt)
572 // A8.6.16 B: Encoding T1
573 // If Inst{11-8} == 0b1111 then SEE SVC
574 let isCall = 1, Uses = [SP] in
575 def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
576 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
578 let Inst{15-12} = 0b1101;
579 let Inst{11-8} = 0b1111;
583 // The assembler uses 0xDEFE for a trap instruction.
584 let isBarrier = 1, isTerminator = 1 in
585 def tTRAP : TI<(outs), (ins), IIC_Br,
586 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
590 //===----------------------------------------------------------------------===//
591 // Load Store Instructions.
594 // Loads: reg/reg and reg/imm5
595 let canFoldAsLoad = 1, isReMaterializable = 1 in
596 multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
597 Operand AddrMode_r, Operand AddrMode_i,
598 AddrMode am, InstrItinClass itin_r,
599 InstrItinClass itin_i, string asm,
602 T1pILdStEncode<reg_opc,
603 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
604 am, itin_r, asm, "\t$Rt, $addr",
605 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
607 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
608 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
609 am, itin_i, asm, "\t$Rt, $addr",
610 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
612 // Stores: reg/reg and reg/imm5
613 multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
614 Operand AddrMode_r, Operand AddrMode_i,
615 AddrMode am, InstrItinClass itin_r,
616 InstrItinClass itin_i, string asm,
619 T1pILdStEncode<reg_opc,
620 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
621 am, itin_r, asm, "\t$Rt, $addr",
622 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
624 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
625 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
626 am, itin_i, asm, "\t$Rt, $addr",
627 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
631 defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
632 t_addrmode_is4, AddrModeT1_4,
633 IIC_iLoad_r, IIC_iLoad_i, "ldr",
634 UnOpFrag<(load node:$Src)>>;
637 defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
638 t_addrmode_is1, AddrModeT1_1,
639 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
640 UnOpFrag<(zextloadi8 node:$Src)>>;
643 defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
644 t_addrmode_is2, AddrModeT1_2,
645 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
646 UnOpFrag<(zextloadi16 node:$Src)>>;
648 let AddedComplexity = 10 in
649 def tLDRSB : // A8.6.80
650 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
651 AddrModeT1_1, IIC_iLoad_bh_r,
652 "ldrsb", "\t$Rt, $addr",
653 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
655 let AddedComplexity = 10 in
656 def tLDRSH : // A8.6.84
657 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
658 AddrModeT1_2, IIC_iLoad_bh_r,
659 "ldrsh", "\t$Rt, $addr",
660 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
662 let canFoldAsLoad = 1 in
663 def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
664 "ldr", "\t$Rt, $addr",
665 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
670 let Inst{7-0} = addr;
673 let canFoldAsLoad = 1, isReMaterializable = 1 in
674 def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
675 "ldr", "\t$Rt, $addr",
676 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
677 T1Encoding<{0,1,0,0,1,?}> {
682 let Inst{7-0} = addr;
685 // A8.6.194 & A8.6.192
686 defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
687 t_addrmode_is4, AddrModeT1_4,
688 IIC_iStore_r, IIC_iStore_i, "str",
689 BinOpFrag<(store node:$LHS, node:$RHS)>>;
691 // A8.6.197 & A8.6.195
692 defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
693 t_addrmode_is1, AddrModeT1_1,
694 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
695 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
697 // A8.6.207 & A8.6.205
698 defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
699 t_addrmode_is2, AddrModeT1_2,
700 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
701 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
704 def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
705 "str", "\t$Rt, $addr",
706 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
711 let Inst{7-0} = addr;
714 //===----------------------------------------------------------------------===//
715 // Load / store multiple Instructions.
718 // These require base address to be written back or one of the loaded regs.
719 let hasSideEffects = 0 in {
721 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
722 def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
723 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
727 let Inst{7-0} = regs;
730 // Writeback version is just a pseudo, as there's no encoding difference.
731 // Writeback happens iff the base register is not in the destination register
734 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
735 "$Rn = $wb", IIC_iLoad_mu>,
736 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
738 let OutOperandList = (outs GPR:$wb);
739 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
741 let isCodeGenOnly = 1;
743 list<Predicate> Predicates = [IsThumb];
746 // There is no non-writeback version of STM for Thumb.
747 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
748 def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
749 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
750 AddrModeNone, 2, IIC_iStore_mu,
751 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
752 T1Encoding<{1,1,0,0,0,?}> {
756 let Inst{7-0} = regs;
761 def : InstAlias<"ldm${p} $Rn!, $regs",
762 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)>,
763 Requires<[IsThumb, IsThumb1Only]>;
765 let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
766 def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
768 "pop${p}\t$regs", []>,
769 T1Misc<{1,1,0,?,?,?,?}> {
771 let Inst{8} = regs{15};
772 let Inst{7-0} = regs{7-0};
775 let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
776 def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
778 "push${p}\t$regs", []>,
779 T1Misc<{0,1,0,?,?,?,?}> {
781 let Inst{8} = regs{14};
782 let Inst{7-0} = regs{7-0};
785 //===----------------------------------------------------------------------===//
786 // Arithmetic Instructions.
789 // Helper classes for encoding T1pI patterns:
790 class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
791 string opc, string asm, list<dag> pattern>
792 : T1pI<oops, iops, itin, opc, asm, pattern>,
793 T1DataProcessing<opA> {
799 class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
800 string opc, string asm, list<dag> pattern>
801 : T1pI<oops, iops, itin, opc, asm, pattern>,
809 // Helper classes for encoding T1sI patterns:
810 class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
811 string opc, string asm, list<dag> pattern>
812 : T1sI<oops, iops, itin, opc, asm, pattern>,
813 T1DataProcessing<opA> {
819 class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
820 string opc, string asm, list<dag> pattern>
821 : T1sI<oops, iops, itin, opc, asm, pattern>,
830 class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
831 string opc, string asm, list<dag> pattern>
832 : T1sI<oops, iops, itin, opc, asm, pattern>,
840 // Helper classes for encoding T1sIt patterns:
841 class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
842 string opc, string asm, list<dag> pattern>
843 : T1sIt<oops, iops, itin, opc, asm, pattern>,
844 T1DataProcessing<opA> {
850 class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
851 string opc, string asm, list<dag> pattern>
852 : T1sIt<oops, iops, itin, opc, asm, pattern>,
856 let Inst{10-8} = Rdn;
857 let Inst{7-0} = imm8;
860 // Add with carry register
861 let isCommutable = 1, Uses = [CPSR] in
863 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
864 "adc", "\t$Rdn, $Rm",
865 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
868 def tADDi3 : // A8.6.4 T1
869 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
871 "add", "\t$Rd, $Rm, $imm3",
872 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
875 let Inst{8-6} = imm3;
878 def tADDi8 : // A8.6.4 T2
879 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
880 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
881 "add", "\t$Rdn, $imm8",
882 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
886 let isCommutable = 1 in
887 def tADDrr : // A8.6.6 T1
888 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
890 "add", "\t$Rd, $Rn, $Rm",
891 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
893 let hasSideEffects = 0 in
894 def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
895 "add", "\t$Rdn, $Rm", []>,
896 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
900 let Inst{7} = Rdn{3};
902 let Inst{2-0} = Rdn{2-0};
906 let isCommutable = 1 in
907 def tAND : // A8.6.12
908 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
910 "and", "\t$Rdn, $Rm",
911 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
914 def tASRri : // A8.6.14
915 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
917 "asr", "\t$Rd, $Rm, $imm5",
918 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
921 let Inst{10-6} = imm5;
925 def tASRrr : // A8.6.15
926 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
928 "asr", "\t$Rdn, $Rm",
929 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
932 def tBIC : // A8.6.20
933 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
935 "bic", "\t$Rdn, $Rm",
936 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
940 let isCompare = 1, Defs = [CPSR] in {
941 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
942 // Compare-to-zero still works out, just not the relationals
943 //def tCMN : // A8.6.33
944 // T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
946 // "cmn", "\t$lhs, $rhs",
947 // [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
949 def tCMNz : // A8.6.33
950 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
953 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
955 } // isCompare = 1, Defs = [CPSR]
958 let isCompare = 1, Defs = [CPSR] in {
959 def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
960 "cmp", "\t$Rn, $imm8",
961 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
962 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
967 let Inst{7-0} = imm8;
971 def tCMPr : // A8.6.36 T1
972 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
975 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
977 def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
978 "cmp", "\t$Rn, $Rm", []>,
979 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
985 let Inst{2-0} = Rn{2-0};
987 } // isCompare = 1, Defs = [CPSR]
991 let isCommutable = 1 in
992 def tEOR : // A8.6.45
993 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
995 "eor", "\t$Rdn, $Rm",
996 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
999 def tLSLri : // A8.6.88
1000 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
1002 "lsl", "\t$Rd, $Rm, $imm5",
1003 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
1006 let Inst{10-6} = imm5;
1010 def tLSLrr : // A8.6.89
1011 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1013 "lsl", "\t$Rdn, $Rm",
1014 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1017 def tLSRri : // A8.6.90
1018 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
1020 "lsr", "\t$Rd, $Rm, $imm5",
1021 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1024 let Inst{10-6} = imm5;
1028 def tLSRrr : // A8.6.91
1029 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1031 "lsr", "\t$Rdn, $Rm",
1032 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1035 let isMoveImm = 1 in
1036 def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
1037 "mov", "\t$Rd, $imm8",
1038 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1039 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
1043 let Inst{10-8} = Rd;
1044 let Inst{7-0} = imm8;
1046 // Because we have an explicit tMOVSr below, we need an alias to handle
1047 // the immediate "movs" form here. Blech.
1048 def : tInstAlias <"movs $Rdn, $imm",
1049 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
1051 // A7-73: MOV(2) - mov setting flag.
1053 let hasSideEffects = 0 in {
1054 def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
1056 "mov", "\t$Rd, $Rm", "", []>,
1057 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
1061 let Inst{7} = Rd{3};
1063 let Inst{2-0} = Rd{2-0};
1065 let Defs = [CPSR] in
1066 def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1067 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
1071 let Inst{15-6} = 0b0000000000;
1077 // Multiply register
1078 let isCommutable = 1 in
1079 def tMUL : // A8.6.105 T1
1080 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1081 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1082 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1083 T1DataProcessing<0b1101> {
1088 let AsmMatchConverter = "cvtThumbMultiply";
1091 def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1094 // Move inverse register
1095 def tMVN : // A8.6.107
1096 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1097 "mvn", "\t$Rd, $Rn",
1098 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
1100 // Bitwise or register
1101 let isCommutable = 1 in
1102 def tORR : // A8.6.114
1103 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1105 "orr", "\t$Rdn, $Rm",
1106 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1109 def tREV : // A8.6.134
1110 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1112 "rev", "\t$Rd, $Rm",
1113 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1114 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1116 def tREV16 : // A8.6.135
1117 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1119 "rev16", "\t$Rd, $Rm",
1120 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
1121 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1123 def tREVSH : // A8.6.136
1124 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1126 "revsh", "\t$Rd, $Rm",
1127 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
1128 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1130 // Rotate right register
1131 def tROR : // A8.6.139
1132 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1134 "ror", "\t$Rdn, $Rm",
1135 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1139 def tRSB : // A8.6.141
1140 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1142 "rsb", "\t$Rd, $Rn, #0",
1143 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
1145 // Subtract with carry register
1146 let Uses = [CPSR] in
1147 def tSBC : // A8.6.151
1148 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1150 "sbc", "\t$Rdn, $Rm",
1151 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>,
1154 // Subtract immediate
1155 def tSUBi3 : // A8.6.210 T1
1156 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
1158 "sub", "\t$Rd, $Rm, $imm3",
1159 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1162 let Inst{8-6} = imm3;
1165 def tSUBi8 : // A8.6.210 T2
1166 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1167 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
1168 "sub", "\t$Rdn, $imm8",
1169 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1172 // Subtract register
1173 def tSUBrr : // A8.6.212
1174 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1176 "sub", "\t$Rd, $Rn, $Rm",
1177 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1181 def tSXTB : // A8.6.222
1182 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1184 "sxtb", "\t$Rd, $Rm",
1185 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1186 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1189 // Sign-extend short
1190 def tSXTH : // A8.6.224
1191 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1193 "sxth", "\t$Rd, $Rm",
1194 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1195 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1199 let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
1200 def tTST : // A8.6.230
1201 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1202 "tst", "\t$Rn, $Rm",
1203 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1206 // A8.8.247 UDF - Undefined (Encoding T1)
1207 def tUDF : TI<(outs), (ins imm0_255:$imm8), IIC_Br, "udf\t$imm8",
1208 [(int_arm_undefined imm0_255:$imm8)]>, Encoding16 {
1210 let Inst{15-12} = 0b1101;
1211 let Inst{11-8} = 0b1110;
1212 let Inst{7-0} = imm8;
1216 def tUXTB : // A8.6.262
1217 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1219 "uxtb", "\t$Rd, $Rm",
1220 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1221 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1224 // Zero-extend short
1225 def tUXTH : // A8.6.264
1226 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1228 "uxth", "\t$Rd, $Rm",
1229 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1230 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1232 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
1233 // Expanded after instruction selection into a branch sequence.
1234 let usesCustomInserter = 1 in // Expanded after instruction selection.
1235 def tMOVCCr_pseudo :
1236 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1238 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
1240 // tLEApcrel - Load a pc-relative address into a register without offending the
1243 def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1244 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
1245 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
1248 let Inst{10-8} = Rd;
1249 let Inst{7-0} = addr;
1250 let DecoderMethod = "DecodeThumbAddSpecialReg";
1253 let hasSideEffects = 0, isReMaterializable = 1 in
1254 def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1255 2, IIC_iALUi, []>, Sched<[WriteALU]>;
1257 let hasSideEffects = 1 in
1258 def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1259 (ins i32imm:$label, pred:$p),
1260 2, IIC_iALUi, []>, Sched<[WriteALU]>;
1262 //===----------------------------------------------------------------------===//
1266 // __aeabi_read_tp preserves the registers r1-r3.
1267 // This is a pseudo inst so that we can get the encoding right,
1268 // complete with fixup for the aeabi_read_tp function.
1269 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
1270 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
1271 [(set R0, ARMthread_pointer)]>,
1274 //===----------------------------------------------------------------------===//
1275 // SJLJ Exception handling intrinsics
1278 // eh_sjlj_setjmp() is an instruction sequence to store the return address and
1279 // save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1280 // from some other function to get here, and we're using the stack frame for the
1281 // containing function to save/restore registers, we can't keep anything live in
1282 // regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1283 // tromped upon when we get here from a longjmp(). We force everything out of
1284 // registers except for our own input by listing the relevant registers in
1285 // Defs. By doing so, we also cause the prologue/epilogue code to actively
1286 // preserve all of the callee-saved resgisters, which is exactly what we want.
1287 // $val is a scratch register for our use.
1288 let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
1289 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1290 usesCustomInserter = 1 in
1291 def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1292 AddrModeNone, 0, NoItinerary, "","",
1293 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
1295 // FIXME: Non-IOS version(s)
1296 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1297 Defs = [ R7, LR, SP ] in
1298 def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
1299 AddrModeNone, 0, IndexModeNone,
1300 Pseudo, NoItinerary, "", "",
1301 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1302 Requires<[IsThumb]>;
1304 //===----------------------------------------------------------------------===//
1305 // Non-Instruction Patterns
1309 def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1310 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1311 def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1312 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1315 def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1316 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1317 def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
1318 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
1319 def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1320 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
1322 // Subtract with carry
1323 def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1324 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1325 def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1326 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1327 def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1328 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
1330 // Bswap 16 with load/store
1331 def : T1Pat<(srl (bswap (extloadi16 t_addrmode_rrs2:$addr)), (i32 16)),
1332 (tREV16 (tLDRHr t_addrmode_rrs2:$addr))>;
1333 def : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
1334 (tREV16 (tLDRHi t_addrmode_is2:$addr))>;
1335 def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1336 t_addrmode_rrs2:$addr),
1337 (tSTRHr (tREV16 tGPR:$Rn), t_addrmode_rrs2:$addr)>;
1338 def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1339 t_addrmode_is2:$addr),
1340 (tSTRHi(tREV16 tGPR:$Rn), t_addrmode_is2:$addr)>;
1343 def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
1346 def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
1349 (ARMWrapperPIC tglobaladdr:$addr))]>,
1350 Requires<[IsThumb, DontUseMovt]>;
1352 def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1355 (ARMWrapper tglobaladdr:$src))]>,
1356 Requires<[IsThumb, DontUseMovt]>;
1360 def : T1Pat<(ARMWrapperJT tjumptable:$dst),
1361 (tLEApcrelJT tjumptable:$dst)>;
1364 def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
1365 Requires<[IsThumb]>;
1367 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
1368 Requires<[IsThumb, HasV5T, IsNotMClass]>;
1370 // Indirect calls to ARM routines
1371 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1372 Requires<[IsThumb, HasV5T]>;
1374 // zextload i1 -> zextload i8
1375 def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1376 (tLDRBr t_addrmode_rrs1:$addr)>;
1377 def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1378 (tLDRBi t_addrmode_is1:$addr)>;
1380 // extload from the stack -> word load from the stack, as it avoids having to
1381 // materialize the base in a separate register. This only works when a word
1382 // load puts the byte/halfword value in the same place in the register that the
1383 // byte/halfword load would, i.e. when little-endian.
1384 def : T1Pat<(extloadi1 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1385 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1386 def : T1Pat<(extloadi8 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1387 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1388 def : T1Pat<(extloadi16 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1389 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1391 // extload -> zextload
1392 def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1393 def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1394 def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1395 def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1396 def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1397 def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1399 // If it's impossible to use [r,r] address mode for sextload, select to
1400 // ldr{b|h} + sxt{b|h} instead.
1401 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1402 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1403 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1404 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1405 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
1406 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1407 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1408 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1409 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1410 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1411 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
1412 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1414 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1415 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
1416 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1417 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1418 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1419 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1420 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1421 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
1423 def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
1424 (tLDRBi t_addrmode_is1:$src)>;
1425 def : T1Pat<(atomic_load_8 t_addrmode_rrs1:$src),
1426 (tLDRBr t_addrmode_rrs1:$src)>;
1427 def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
1428 (tLDRHi t_addrmode_is2:$src)>;
1429 def : T1Pat<(atomic_load_16 t_addrmode_rrs2:$src),
1430 (tLDRHr t_addrmode_rrs2:$src)>;
1431 def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
1432 (tLDRi t_addrmode_is4:$src)>;
1433 def : T1Pat<(atomic_load_32 t_addrmode_rrs4:$src),
1434 (tLDRr t_addrmode_rrs4:$src)>;
1435 def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1436 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
1437 def : T1Pat<(atomic_store_8 t_addrmode_rrs1:$ptr, tGPR:$val),
1438 (tSTRBr tGPR:$val, t_addrmode_rrs1:$ptr)>;
1439 def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1440 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
1441 def : T1Pat<(atomic_store_16 t_addrmode_rrs2:$ptr, tGPR:$val),
1442 (tSTRHr tGPR:$val, t_addrmode_rrs2:$ptr)>;
1443 def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1444 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
1445 def : T1Pat<(atomic_store_32 t_addrmode_rrs4:$ptr, tGPR:$val),
1446 (tSTRr tGPR:$val, t_addrmode_rrs4:$ptr)>;
1448 // Large immediate handling.
1451 def : T1Pat<(i32 thumb_immshifted:$src),
1452 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1453 (thumb_immshifted_shamt imm:$src))>;
1455 def : T1Pat<(i32 imm0_255_comp:$src),
1456 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
1458 // Pseudo instruction that combines ldr from constpool and add pc. This should
1459 // be expanded into two instructions late to allow if-conversion and
1461 let isReMaterializable = 1 in
1462 def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
1464 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1466 Requires<[IsThumb, IsThumb1Only]>;
1468 // Pseudo-instruction for merged POP and return.
1469 // FIXME: remove when we have a way to marking a MI with these properties.
1470 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1471 hasExtraDefRegAllocReq = 1 in
1472 def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
1474 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
1476 // Indirect branch using "mov pc, $Rm"
1477 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1478 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
1479 2, IIC_Br, [(brind GPR:$Rm)],
1480 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
1484 // In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1485 // encoding is available on ARMv6K, but we don't differentiate that finely.
1486 def : InstAlias<"nop", (tMOVr R8, R8, 14, 0)>,Requires<[IsThumb, IsThumb1Only]>;
1489 // For round-trip assembly/disassembly, we have to handle a CPS instruction
1490 // without any iflags. That's not, strictly speaking, valid syntax, but it's
1491 // a useful extension and assembles to defined behaviour (the insn does
1493 def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1494 def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1496 // "neg" is and alias for "rsb rd, rn, #0"
1497 def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1498 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1501 // Implied destination operand forms for shifts.
1502 def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1503 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1504 def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1505 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1506 def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1507 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;