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), 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()), MVT::i32);
39 def imm0_7_neg : PatLeaf<(i32 imm), [{
40 return (uint32_t)-N->getZExtValue() < 8;
43 def imm0_255_comp : PatLeaf<(i32 imm), [{
44 return ~((uint32_t)N->getZExtValue()) < 256;
47 def imm8_255 : ImmLeaf<i32, [{
48 return Imm >= 8 && Imm < 256;
50 def imm8_255_neg : PatLeaf<(i32 imm), [{
51 unsigned Val = -N->getZExtValue();
52 return Val >= 8 && Val < 256;
55 // Break imm's up into two pieces: an immediate + a left shift. This uses
56 // thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
57 // to get the val/shift pieces.
58 def thumb_immshifted : PatLeaf<(imm), [{
59 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
62 def thumb_immshifted_val : SDNodeXForm<imm, [{
63 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
64 return CurDAG->getTargetConstant(V, MVT::i32);
67 def thumb_immshifted_shamt : SDNodeXForm<imm, [{
68 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
69 return CurDAG->getTargetConstant(V, MVT::i32);
72 // Scaled 4 immediate.
73 def t_imm0_1020s4_asmoperand: AsmOperandClass { let Name = "Imm0_1020s4"; }
74 def t_imm0_1020s4 : Operand<i32> {
75 let PrintMethod = "printThumbS4ImmOperand";
76 let ParserMatchClass = t_imm0_1020s4_asmoperand;
77 let OperandType = "OPERAND_IMMEDIATE";
80 def t_imm0_508s4_asmoperand: AsmOperandClass { let Name = "Imm0_508s4"; }
81 def t_imm0_508s4 : Operand<i32> {
82 let PrintMethod = "printThumbS4ImmOperand";
83 let ParserMatchClass = t_imm0_508s4_asmoperand;
84 let OperandType = "OPERAND_IMMEDIATE";
86 // Alias use only, so no printer is necessary.
87 def t_imm0_508s4_neg_asmoperand: AsmOperandClass { let Name = "Imm0_508s4Neg"; }
88 def t_imm0_508s4_neg : Operand<i32> {
89 let ParserMatchClass = t_imm0_508s4_neg_asmoperand;
90 let OperandType = "OPERAND_IMMEDIATE";
93 // Define Thumb specific addressing modes.
95 // unsigned 8-bit, 2-scaled memory offset
96 class OperandUnsignedOffset_b8s2 : AsmOperandClass {
97 let Name = "UnsignedOffset_b8s2";
98 let PredicateMethod = "isUnsignedOffset<8, 2>";
101 def UnsignedOffset_b8s2 : OperandUnsignedOffset_b8s2;
103 // thumb style PC relative operand. signed, 8 bits magnitude,
104 // two bits shift. can be represented as either [pc, #imm], #imm,
105 // or relocatable expression...
106 def ThumbMemPC : AsmOperandClass {
107 let Name = "ThumbMemPC";
110 let OperandType = "OPERAND_PCREL" in {
111 def t_brtarget : Operand<OtherVT> {
112 let EncoderMethod = "getThumbBRTargetOpValue";
113 let DecoderMethod = "DecodeThumbBROperand";
116 // ADR instruction labels.
117 def t_adrlabel : Operand<i32> {
118 let EncoderMethod = "getThumbAdrLabelOpValue";
119 let PrintMethod = "printAdrLabelOperand<2>";
120 let ParserMatchClass = UnsignedOffset_b8s2;
123 def t_bcctarget : Operand<i32> {
124 let EncoderMethod = "getThumbBCCTargetOpValue";
125 let DecoderMethod = "DecodeThumbBCCTargetOperand";
128 def t_cbtarget : Operand<i32> {
129 let EncoderMethod = "getThumbCBTargetOpValue";
130 let DecoderMethod = "DecodeThumbCmpBROperand";
133 def t_bltarget : Operand<i32> {
134 let EncoderMethod = "getThumbBLTargetOpValue";
135 let DecoderMethod = "DecodeThumbBLTargetOperand";
138 def t_blxtarget : Operand<i32> {
139 let EncoderMethod = "getThumbBLXTargetOpValue";
140 let DecoderMethod = "DecodeThumbBLXOffset";
143 // t_addrmode_pc := <label> => pc + imm8 * 4
145 def t_addrmode_pc : Operand<i32> {
146 let EncoderMethod = "getAddrModePCOpValue";
147 let DecoderMethod = "DecodeThumbAddrModePC";
148 let PrintMethod = "printThumbLdrLabelOperand";
149 let ParserMatchClass = ThumbMemPC;
153 // t_addrmode_rr := reg + reg
155 def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
156 def t_addrmode_rr : Operand<i32>,
157 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
158 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
159 let PrintMethod = "printThumbAddrModeRROperand";
160 let DecoderMethod = "DecodeThumbAddrModeRR";
161 let ParserMatchClass = t_addrmode_rr_asm_operand;
162 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
165 // t_addrmode_rrs := reg + reg
167 // We use separate scaled versions because the Select* functions need
168 // to explicitly check for a matching constant and return false here so that
169 // the reg+imm forms will match instead. This is a horrible way to do that,
170 // as it forces tight coupling between the methods, but it's how selectiondag
172 def t_addrmode_rrs1 : Operand<i32>,
173 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
174 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
175 let PrintMethod = "printThumbAddrModeRROperand";
176 let DecoderMethod = "DecodeThumbAddrModeRR";
177 let ParserMatchClass = t_addrmode_rr_asm_operand;
178 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
180 def t_addrmode_rrs2 : Operand<i32>,
181 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
182 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
183 let DecoderMethod = "DecodeThumbAddrModeRR";
184 let PrintMethod = "printThumbAddrModeRROperand";
185 let ParserMatchClass = t_addrmode_rr_asm_operand;
186 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
188 def t_addrmode_rrs4 : Operand<i32>,
189 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
190 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
191 let DecoderMethod = "DecodeThumbAddrModeRR";
192 let PrintMethod = "printThumbAddrModeRROperand";
193 let ParserMatchClass = t_addrmode_rr_asm_operand;
194 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
197 // t_addrmode_is4 := reg + imm5 * 4
199 def t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
200 def t_addrmode_is4 : Operand<i32>,
201 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
202 let EncoderMethod = "getAddrModeISOpValue";
203 let DecoderMethod = "DecodeThumbAddrModeIS";
204 let PrintMethod = "printThumbAddrModeImm5S4Operand";
205 let ParserMatchClass = t_addrmode_is4_asm_operand;
206 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
209 // t_addrmode_is2 := reg + imm5 * 2
211 def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
212 def t_addrmode_is2 : Operand<i32>,
213 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
214 let EncoderMethod = "getAddrModeISOpValue";
215 let DecoderMethod = "DecodeThumbAddrModeIS";
216 let PrintMethod = "printThumbAddrModeImm5S2Operand";
217 let ParserMatchClass = t_addrmode_is2_asm_operand;
218 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
221 // t_addrmode_is1 := reg + imm5
223 def t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
224 def t_addrmode_is1 : Operand<i32>,
225 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
226 let EncoderMethod = "getAddrModeISOpValue";
227 let DecoderMethod = "DecodeThumbAddrModeIS";
228 let PrintMethod = "printThumbAddrModeImm5S1Operand";
229 let ParserMatchClass = t_addrmode_is1_asm_operand;
230 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
233 // t_addrmode_sp := sp + imm8 * 4
235 // FIXME: This really shouldn't have an explicit SP operand at all. It should
236 // be implicit, just like in the instruction encoding itself.
237 def t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
238 def t_addrmode_sp : Operand<i32>,
239 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
240 let EncoderMethod = "getAddrModeThumbSPOpValue";
241 let DecoderMethod = "DecodeThumbAddrModeSP";
242 let PrintMethod = "printThumbAddrModeSPOperand";
243 let ParserMatchClass = t_addrmode_sp_asm_operand;
244 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
247 //===----------------------------------------------------------------------===//
248 // Miscellaneous Instructions.
251 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
252 // from removing one half of the matched pairs. That breaks PEI, which assumes
253 // these will always be in pairs, and asserts if it finds otherwise. Better way?
254 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
255 def tADJCALLSTACKUP :
256 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
257 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
258 Requires<[IsThumb, IsThumb1Only]>;
260 def tADJCALLSTACKDOWN :
261 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
262 [(ARMcallseq_start imm:$amt)]>,
263 Requires<[IsThumb, IsThumb1Only]>;
266 class T1SystemEncoding<bits<8> opc>
267 : T1Encoding<0b101111> {
268 let Inst{9-8} = 0b11;
272 def tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
273 [(int_arm_hint imm0_15:$imm)]>,
274 T1SystemEncoding<0x00>,
275 Requires<[IsThumb, HasV6M]> {
280 class tHintAlias<string Asm, dag Result> : tInstAlias<Asm, Result> {
281 let Predicates = [IsThumb, HasV6M];
284 def : tHintAlias<"nop$p", (tHINT 0, pred:$p)>; // A8.6.110
285 def : tHintAlias<"yield$p", (tHINT 1, pred:$p)>; // A8.6.410
286 def : tHintAlias<"wfe$p", (tHINT 2, pred:$p)>; // A8.6.408
287 def : tHintAlias<"wfi$p", (tHINT 3, pred:$p)>; // A8.6.409
288 def : tHintAlias<"sev$p", (tHINT 4, pred:$p)>; // A8.6.157
289 def : tInstAlias<"sevl$p", (tHINT 5, pred:$p)> {
290 let Predicates = [IsThumb2, HasV8];
292 def : T2Pat<(int_arm_sevl), (tHINT 5)>;
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>, 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 // ADD sp, sp, #<imm7>
365 def tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
366 IIC_iALUi, "add", "\t$Rdn, $imm", []>,
367 T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
371 let DecoderMethod = "DecodeThumbAddSPImm";
374 // SUB sp, sp, #<imm7>
375 // FIXME: The encoding and the ASM string don't match up.
376 def tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
377 IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
378 T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
382 let DecoderMethod = "DecodeThumbAddSPImm";
385 def : tInstAlias<"add${p} sp, $imm",
386 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
387 def : tInstAlias<"add${p} sp, sp, $imm",
388 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
390 // Can optionally specify SP as a three operand instruction.
391 def : tInstAlias<"add${p} sp, sp, $imm",
392 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
393 def : tInstAlias<"sub${p} sp, sp, $imm",
394 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
397 def tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
398 "add", "\t$Rdn, $sp, $Rn", []>,
399 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
400 // A8.6.9 Encoding T1
402 let Inst{7} = Rdn{3};
403 let Inst{6-3} = 0b1101;
404 let Inst{2-0} = Rdn{2-0};
405 let DecoderMethod = "DecodeThumbAddSPReg";
409 def tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
410 "add", "\t$Rdn, $Rm", []>,
411 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
412 // A8.6.9 Encoding T2
416 let Inst{2-0} = 0b101;
417 let DecoderMethod = "DecodeThumbAddSPReg";
420 //===----------------------------------------------------------------------===//
421 // Control Flow Instructions.
425 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
426 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
427 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
431 let Inst{2-0} = 0b000;
432 let Unpredictable{2-0} = 0b111;
436 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
437 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
438 [(ARMretflag)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
440 // Alternative return instruction used by vararg functions.
441 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
443 (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
446 // All calls clobber the non-callee saved registers. SP is marked as a use to
447 // prevent stack-pointer assignments that appear immediately before calls from
448 // potentially appearing dead.
450 Defs = [LR], Uses = [SP] in {
451 // Also used for Thumb2
452 def tBL : TIx2<0b11110, 0b11, 1,
453 (outs), (ins pred:$p, t_bltarget:$func), IIC_Br,
455 [(ARMtcall tglobaladdr:$func)]>,
456 Requires<[IsThumb]>, Sched<[WriteBrL]> {
458 let Inst{26} = func{23};
459 let Inst{25-16} = func{20-11};
460 let Inst{13} = func{22};
461 let Inst{11} = func{21};
462 let Inst{10-0} = func{10-0};
465 // ARMv5T and above, also used for Thumb2
466 def tBLXi : TIx2<0b11110, 0b11, 0,
467 (outs), (ins pred:$p, t_blxtarget:$func), IIC_Br,
469 [(ARMcall tglobaladdr:$func)]>,
470 Requires<[IsThumb, HasV5T]>, Sched<[WriteBrL]> {
472 let Inst{26} = func{23};
473 let Inst{25-16} = func{20-11};
474 let Inst{13} = func{22};
475 let Inst{11} = func{21};
476 let Inst{10-1} = func{10-1};
477 let Inst{0} = 0; // func{0} is assumed zero
480 // Also used for Thumb2
481 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
483 [(ARMtcall GPR:$func)]>,
484 Requires<[IsThumb, HasV5T]>,
485 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
487 let Inst{6-3} = func;
488 let Inst{2-0} = 0b000;
492 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
494 [(ARMcall_nolink tGPR:$func)]>,
495 Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
498 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
499 let isPredicable = 1 in
500 def tB : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
501 "b", "\t$target", [(br bb:$target)]>,
502 T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
504 let Inst{10-0} = target;
505 let AsmMatchConverter = "cvtThumbBranches";
509 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
510 // the clobber of LR.
512 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
513 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>,
516 def tBR_JTr : tPseudoInst<(outs),
517 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
519 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>,
520 Sched<[WriteBrTbl]> {
521 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
525 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
526 // a two-value operand where a dag node expects two operands. :(
527 let isBranch = 1, isTerminator = 1 in
528 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
530 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
531 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
535 let Inst{7-0} = target;
536 let AsmMatchConverter = "cvtThumbBranches";
541 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
544 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
546 (tBX GPR:$dst, (ops 14, zero_reg))>,
547 Requires<[IsThumb]>, Sched<[WriteBr]>;
549 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
550 // on MachO), so it's in ARMInstrThumb2.td.
551 // Non-MachO version:
553 def tTAILJMPdND : tPseudoExpand<(outs),
554 (ins t_brtarget:$dst, pred:$p),
556 (tB t_brtarget:$dst, pred:$p)>,
557 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
562 // A8.6.218 Supervisor Call (Software Interrupt)
563 // A8.6.16 B: Encoding T1
564 // If Inst{11-8} == 0b1111 then SEE SVC
565 let isCall = 1, Uses = [SP] in
566 def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
567 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
569 let Inst{15-12} = 0b1101;
570 let Inst{11-8} = 0b1111;
574 // The assembler uses 0xDEFE for a trap instruction.
575 let isBarrier = 1, isTerminator = 1 in
576 def tTRAP : TI<(outs), (ins), IIC_Br,
577 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
581 //===----------------------------------------------------------------------===//
582 // Load Store Instructions.
585 // Loads: reg/reg and reg/imm5
586 let canFoldAsLoad = 1, isReMaterializable = 1 in
587 multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
588 Operand AddrMode_r, Operand AddrMode_i,
589 AddrMode am, InstrItinClass itin_r,
590 InstrItinClass itin_i, string asm,
593 T1pILdStEncode<reg_opc,
594 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
595 am, itin_r, asm, "\t$Rt, $addr",
596 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
598 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
599 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
600 am, itin_i, asm, "\t$Rt, $addr",
601 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
603 // Stores: reg/reg and reg/imm5
604 multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
605 Operand AddrMode_r, Operand AddrMode_i,
606 AddrMode am, InstrItinClass itin_r,
607 InstrItinClass itin_i, string asm,
610 T1pILdStEncode<reg_opc,
611 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
612 am, itin_r, asm, "\t$Rt, $addr",
613 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
615 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
616 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
617 am, itin_i, asm, "\t$Rt, $addr",
618 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
622 defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
623 t_addrmode_is4, AddrModeT1_4,
624 IIC_iLoad_r, IIC_iLoad_i, "ldr",
625 UnOpFrag<(load node:$Src)>>;
628 defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
629 t_addrmode_is1, AddrModeT1_1,
630 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
631 UnOpFrag<(zextloadi8 node:$Src)>>;
634 defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
635 t_addrmode_is2, AddrModeT1_2,
636 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
637 UnOpFrag<(zextloadi16 node:$Src)>>;
639 let AddedComplexity = 10 in
640 def tLDRSB : // A8.6.80
641 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
642 AddrModeT1_1, IIC_iLoad_bh_r,
643 "ldrsb", "\t$Rt, $addr",
644 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
646 let AddedComplexity = 10 in
647 def tLDRSH : // A8.6.84
648 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
649 AddrModeT1_2, IIC_iLoad_bh_r,
650 "ldrsh", "\t$Rt, $addr",
651 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
653 let canFoldAsLoad = 1 in
654 def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
655 "ldr", "\t$Rt, $addr",
656 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
661 let Inst{7-0} = addr;
664 let canFoldAsLoad = 1, isReMaterializable = 1 in
665 def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
666 "ldr", "\t$Rt, $addr",
667 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
668 T1Encoding<{0,1,0,0,1,?}> {
673 let Inst{7-0} = addr;
676 // A8.6.194 & A8.6.192
677 defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
678 t_addrmode_is4, AddrModeT1_4,
679 IIC_iStore_r, IIC_iStore_i, "str",
680 BinOpFrag<(store node:$LHS, node:$RHS)>>;
682 // A8.6.197 & A8.6.195
683 defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
684 t_addrmode_is1, AddrModeT1_1,
685 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
686 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
688 // A8.6.207 & A8.6.205
689 defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
690 t_addrmode_is2, AddrModeT1_2,
691 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
692 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
695 def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
696 "str", "\t$Rt, $addr",
697 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
702 let Inst{7-0} = addr;
705 //===----------------------------------------------------------------------===//
706 // Load / store multiple Instructions.
709 // These require base address to be written back or one of the loaded regs.
710 let neverHasSideEffects = 1 in {
712 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
713 def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
714 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
718 let Inst{7-0} = regs;
721 // Writeback version is just a pseudo, as there's no encoding difference.
722 // Writeback happens iff the base register is not in the destination register
725 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
726 "$Rn = $wb", IIC_iLoad_mu>,
727 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
729 let OutOperandList = (outs GPR:$wb);
730 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
732 let isCodeGenOnly = 1;
734 list<Predicate> Predicates = [IsThumb];
737 // There is no non-writeback version of STM for Thumb.
738 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
739 def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
740 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
741 AddrModeNone, 2, IIC_iStore_mu,
742 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
743 T1Encoding<{1,1,0,0,0,?}> {
747 let Inst{7-0} = regs;
750 } // neverHasSideEffects
752 def : InstAlias<"ldm${p} $Rn!, $regs",
753 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)>,
754 Requires<[IsThumb, IsThumb1Only]>;
756 let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
757 def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
759 "pop${p}\t$regs", []>,
760 T1Misc<{1,1,0,?,?,?,?}> {
762 let Inst{8} = regs{15};
763 let Inst{7-0} = regs{7-0};
766 let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
767 def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
769 "push${p}\t$regs", []>,
770 T1Misc<{0,1,0,?,?,?,?}> {
772 let Inst{8} = regs{14};
773 let Inst{7-0} = regs{7-0};
776 //===----------------------------------------------------------------------===//
777 // Arithmetic Instructions.
780 // Helper classes for encoding T1pI patterns:
781 class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
782 string opc, string asm, list<dag> pattern>
783 : T1pI<oops, iops, itin, opc, asm, pattern>,
784 T1DataProcessing<opA> {
790 class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
791 string opc, string asm, list<dag> pattern>
792 : T1pI<oops, iops, itin, opc, asm, pattern>,
800 // Helper classes for encoding T1sI patterns:
801 class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
802 string opc, string asm, list<dag> pattern>
803 : T1sI<oops, iops, itin, opc, asm, pattern>,
804 T1DataProcessing<opA> {
810 class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
811 string opc, string asm, list<dag> pattern>
812 : T1sI<oops, iops, itin, opc, asm, pattern>,
821 class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
822 string opc, string asm, list<dag> pattern>
823 : T1sI<oops, iops, itin, opc, asm, pattern>,
831 // Helper classes for encoding T1sIt patterns:
832 class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
833 string opc, string asm, list<dag> pattern>
834 : T1sIt<oops, iops, itin, opc, asm, pattern>,
835 T1DataProcessing<opA> {
841 class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
842 string opc, string asm, list<dag> pattern>
843 : T1sIt<oops, iops, itin, opc, asm, pattern>,
847 let Inst{10-8} = Rdn;
848 let Inst{7-0} = imm8;
851 // Add with carry register
852 let isCommutable = 1, Uses = [CPSR] in
854 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
855 "adc", "\t$Rdn, $Rm",
856 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
859 def tADDi3 : // A8.6.4 T1
860 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
862 "add", "\t$Rd, $Rm, $imm3",
863 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
866 let Inst{8-6} = imm3;
869 def tADDi8 : // A8.6.4 T2
870 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
871 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
872 "add", "\t$Rdn, $imm8",
873 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
877 let isCommutable = 1 in
878 def tADDrr : // A8.6.6 T1
879 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
881 "add", "\t$Rd, $Rn, $Rm",
882 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
884 let neverHasSideEffects = 1 in
885 def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
886 "add", "\t$Rdn, $Rm", []>,
887 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
891 let Inst{7} = Rdn{3};
893 let Inst{2-0} = Rdn{2-0};
897 let isCommutable = 1 in
898 def tAND : // A8.6.12
899 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
901 "and", "\t$Rdn, $Rm",
902 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
905 def tASRri : // A8.6.14
906 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
908 "asr", "\t$Rd, $Rm, $imm5",
909 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
912 let Inst{10-6} = imm5;
916 def tASRrr : // A8.6.15
917 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
919 "asr", "\t$Rdn, $Rm",
920 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
923 def tBIC : // A8.6.20
924 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
926 "bic", "\t$Rdn, $Rm",
927 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
931 let isCompare = 1, Defs = [CPSR] in {
932 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
933 // Compare-to-zero still works out, just not the relationals
934 //def tCMN : // A8.6.33
935 // T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
937 // "cmn", "\t$lhs, $rhs",
938 // [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
940 def tCMNz : // A8.6.33
941 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
944 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
946 } // isCompare = 1, Defs = [CPSR]
949 let isCompare = 1, Defs = [CPSR] in {
950 def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
951 "cmp", "\t$Rn, $imm8",
952 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
953 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
958 let Inst{7-0} = imm8;
962 def tCMPr : // A8.6.36 T1
963 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
966 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
968 def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
969 "cmp", "\t$Rn, $Rm", []>,
970 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
976 let Inst{2-0} = Rn{2-0};
978 } // isCompare = 1, Defs = [CPSR]
982 let isCommutable = 1 in
983 def tEOR : // A8.6.45
984 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
986 "eor", "\t$Rdn, $Rm",
987 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
990 def tLSLri : // A8.6.88
991 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
993 "lsl", "\t$Rd, $Rm, $imm5",
994 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
997 let Inst{10-6} = imm5;
1001 def tLSLrr : // A8.6.89
1002 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1004 "lsl", "\t$Rdn, $Rm",
1005 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1008 def tLSRri : // A8.6.90
1009 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
1011 "lsr", "\t$Rd, $Rm, $imm5",
1012 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1015 let Inst{10-6} = imm5;
1019 def tLSRrr : // A8.6.91
1020 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1022 "lsr", "\t$Rdn, $Rm",
1023 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1026 let isMoveImm = 1 in
1027 def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
1028 "mov", "\t$Rd, $imm8",
1029 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1030 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
1034 let Inst{10-8} = Rd;
1035 let Inst{7-0} = imm8;
1037 // Because we have an explicit tMOVSr below, we need an alias to handle
1038 // the immediate "movs" form here. Blech.
1039 def : tInstAlias <"movs $Rdn, $imm",
1040 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
1042 // A7-73: MOV(2) - mov setting flag.
1044 let neverHasSideEffects = 1 in {
1045 def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
1047 "mov", "\t$Rd, $Rm", "", []>,
1048 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
1052 let Inst{7} = Rd{3};
1054 let Inst{2-0} = Rd{2-0};
1056 let Defs = [CPSR] in
1057 def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1058 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
1062 let Inst{15-6} = 0b0000000000;
1066 } // neverHasSideEffects
1068 // Multiply register
1069 let isCommutable = 1 in
1070 def tMUL : // A8.6.105 T1
1071 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1072 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1073 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1074 T1DataProcessing<0b1101> {
1079 let AsmMatchConverter = "cvtThumbMultiply";
1082 def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1085 // Move inverse register
1086 def tMVN : // A8.6.107
1087 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1088 "mvn", "\t$Rd, $Rn",
1089 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
1091 // Bitwise or register
1092 let isCommutable = 1 in
1093 def tORR : // A8.6.114
1094 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1096 "orr", "\t$Rdn, $Rm",
1097 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
1100 def tREV : // A8.6.134
1101 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1103 "rev", "\t$Rd, $Rm",
1104 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1105 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1107 def tREV16 : // A8.6.135
1108 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1110 "rev16", "\t$Rd, $Rm",
1111 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
1112 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1114 def tREVSH : // A8.6.136
1115 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1117 "revsh", "\t$Rd, $Rm",
1118 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
1119 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1121 // Rotate right register
1122 def tROR : // A8.6.139
1123 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1125 "ror", "\t$Rdn, $Rm",
1126 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1130 def tRSB : // A8.6.141
1131 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1133 "rsb", "\t$Rd, $Rn, #0",
1134 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
1136 // Subtract with carry register
1137 let Uses = [CPSR] in
1138 def tSBC : // A8.6.151
1139 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1141 "sbc", "\t$Rdn, $Rm",
1142 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>,
1145 // Subtract immediate
1146 def tSUBi3 : // A8.6.210 T1
1147 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
1149 "sub", "\t$Rd, $Rm, $imm3",
1150 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1153 let Inst{8-6} = imm3;
1156 def tSUBi8 : // A8.6.210 T2
1157 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1158 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
1159 "sub", "\t$Rdn, $imm8",
1160 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1163 // Subtract register
1164 def tSUBrr : // A8.6.212
1165 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1167 "sub", "\t$Rd, $Rn, $Rm",
1168 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1172 def tSXTB : // A8.6.222
1173 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1175 "sxtb", "\t$Rd, $Rm",
1176 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1177 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1180 // Sign-extend short
1181 def tSXTH : // A8.6.224
1182 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1184 "sxth", "\t$Rd, $Rm",
1185 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1186 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1190 let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
1191 def tTST : // A8.6.230
1192 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1193 "tst", "\t$Rn, $Rm",
1194 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1198 def tUXTB : // A8.6.262
1199 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1201 "uxtb", "\t$Rd, $Rm",
1202 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1203 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1206 // Zero-extend short
1207 def tUXTH : // A8.6.264
1208 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1210 "uxth", "\t$Rd, $Rm",
1211 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1212 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
1214 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
1215 // Expanded after instruction selection into a branch sequence.
1216 let usesCustomInserter = 1 in // Expanded after instruction selection.
1217 def tMOVCCr_pseudo :
1218 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1220 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
1222 // tLEApcrel - Load a pc-relative address into a register without offending the
1225 def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1226 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
1227 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
1230 let Inst{10-8} = Rd;
1231 let Inst{7-0} = addr;
1232 let DecoderMethod = "DecodeThumbAddSpecialReg";
1235 let neverHasSideEffects = 1, isReMaterializable = 1 in
1236 def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1237 2, IIC_iALUi, []>, Sched<[WriteALU]>;
1239 let hasSideEffects = 1 in
1240 def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1241 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1242 2, IIC_iALUi, []>, Sched<[WriteALU]>;
1244 //===----------------------------------------------------------------------===//
1248 // __aeabi_read_tp preserves the registers r1-r3.
1249 // This is a pseudo inst so that we can get the encoding right,
1250 // complete with fixup for the aeabi_read_tp function.
1251 let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
1252 def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
1253 [(set R0, ARMthread_pointer)]>,
1256 //===----------------------------------------------------------------------===//
1257 // SJLJ Exception handling intrinsics
1260 // eh_sjlj_setjmp() is an instruction sequence to store the return address and
1261 // save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1262 // from some other function to get here, and we're using the stack frame for the
1263 // containing function to save/restore registers, we can't keep anything live in
1264 // regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1265 // tromped upon when we get here from a longjmp(). We force everything out of
1266 // registers except for our own input by listing the relevant registers in
1267 // Defs. By doing so, we also cause the prologue/epilogue code to actively
1268 // preserve all of the callee-saved resgisters, which is exactly what we want.
1269 // $val is a scratch register for our use.
1270 let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
1271 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1272 usesCustomInserter = 1 in
1273 def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1274 AddrModeNone, 0, NoItinerary, "","",
1275 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
1277 // FIXME: Non-IOS version(s)
1278 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1279 Defs = [ R7, LR, SP ] in
1280 def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
1281 AddrModeNone, 0, IndexModeNone,
1282 Pseudo, NoItinerary, "", "",
1283 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1284 Requires<[IsThumb, IsIOS]>;
1286 //===----------------------------------------------------------------------===//
1287 // Non-Instruction Patterns
1291 def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1292 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1293 def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1294 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1297 def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1298 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1299 def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
1300 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
1301 def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1302 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
1304 // Subtract with carry
1305 def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1306 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1307 def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1308 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1309 def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1310 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
1313 def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
1316 def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
1319 (ARMWrapperPIC tglobaladdr:$addr))]>,
1320 Requires<[IsThumb, DontUseMovt]>;
1322 def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1325 (ARMWrapper tglobaladdr:$src))]>,
1326 Requires<[IsThumb, DontUseMovt]>;
1330 def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1331 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
1334 def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
1335 Requires<[IsThumb]>;
1337 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
1338 Requires<[IsThumb, HasV5T]>;
1340 // Indirect calls to ARM routines
1341 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1342 Requires<[IsThumb, HasV5T]>;
1344 // zextload i1 -> zextload i8
1345 def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1346 (tLDRBr t_addrmode_rrs1:$addr)>;
1347 def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1348 (tLDRBi t_addrmode_is1:$addr)>;
1350 // extload -> zextload
1351 def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1352 def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1353 def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1354 def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1355 def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1356 def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1358 // If it's impossible to use [r,r] address mode for sextload, select to
1359 // ldr{b|h} + sxt{b|h} instead.
1360 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1361 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1362 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1363 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1364 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
1365 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1366 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1367 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1368 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1369 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1370 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
1371 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1373 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1374 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
1375 def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1376 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1377 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1378 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1379 def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1380 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
1382 def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
1383 (tLDRBi t_addrmode_is1:$src)>;
1384 def : T1Pat<(atomic_load_8 t_addrmode_rrs1:$src),
1385 (tLDRBr t_addrmode_rrs1:$src)>;
1386 def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
1387 (tLDRHi t_addrmode_is2:$src)>;
1388 def : T1Pat<(atomic_load_16 t_addrmode_rrs2:$src),
1389 (tLDRHr t_addrmode_rrs2:$src)>;
1390 def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
1391 (tLDRi t_addrmode_is4:$src)>;
1392 def : T1Pat<(atomic_load_32 t_addrmode_rrs4:$src),
1393 (tLDRr t_addrmode_rrs4:$src)>;
1394 def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1395 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
1396 def : T1Pat<(atomic_store_8 t_addrmode_rrs1:$ptr, tGPR:$val),
1397 (tSTRBr tGPR:$val, t_addrmode_rrs1:$ptr)>;
1398 def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1399 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
1400 def : T1Pat<(atomic_store_16 t_addrmode_rrs2:$ptr, tGPR:$val),
1401 (tSTRHr tGPR:$val, t_addrmode_rrs2:$ptr)>;
1402 def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1403 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
1404 def : T1Pat<(atomic_store_32 t_addrmode_rrs4:$ptr, tGPR:$val),
1405 (tSTRr tGPR:$val, t_addrmode_rrs4:$ptr)>;
1407 // Large immediate handling.
1410 def : T1Pat<(i32 thumb_immshifted:$src),
1411 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1412 (thumb_immshifted_shamt imm:$src))>;
1414 def : T1Pat<(i32 imm0_255_comp:$src),
1415 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
1417 // Pseudo instruction that combines ldr from constpool and add pc. This should
1418 // be expanded into two instructions late to allow if-conversion and
1420 let isReMaterializable = 1 in
1421 def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
1423 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1425 Requires<[IsThumb, IsThumb1Only]>;
1427 // Pseudo-instruction for merged POP and return.
1428 // FIXME: remove when we have a way to marking a MI with these properties.
1429 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1430 hasExtraDefRegAllocReq = 1 in
1431 def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
1433 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
1435 // Indirect branch using "mov pc, $Rm"
1436 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1437 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
1438 2, IIC_Br, [(brind GPR:$Rm)],
1439 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
1443 // In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1444 // encoding is available on ARMv6K, but we don't differentiate that finely.
1445 def : InstAlias<"nop", (tMOVr R8, R8, 14, 0)>,Requires<[IsThumb, IsThumb1Only]>;
1448 // For round-trip assembly/disassembly, we have to handle a CPS instruction
1449 // without any iflags. That's not, strictly speaking, valid syntax, but it's
1450 // a useful extension and assembles to defined behaviour (the insn does
1452 def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1453 def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1455 // "neg" is and alias for "rsb rd, rn, #0"
1456 def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1457 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1460 // Implied destination operand forms for shifts.
1461 def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1462 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1463 def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1464 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1465 def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1466 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;