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, SDNPOptInFlag, SDNPOutFlag,
22 def imm_neg_XFORM : SDNodeXForm<imm, [{
23 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
25 def imm_comp_XFORM : SDNodeXForm<imm, [{
26 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
30 /// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
31 def imm0_7 : PatLeaf<(i32 imm), [{
32 return (uint32_t)N->getZExtValue() < 8;
34 def imm0_7_neg : PatLeaf<(i32 imm), [{
35 return (uint32_t)-N->getZExtValue() < 8;
38 def imm0_255 : PatLeaf<(i32 imm), [{
39 return (uint32_t)N->getZExtValue() < 256;
41 def imm0_255_comp : PatLeaf<(i32 imm), [{
42 return ~((uint32_t)N->getZExtValue()) < 256;
45 def imm8_255 : PatLeaf<(i32 imm), [{
46 return (uint32_t)N->getZExtValue() >= 8 && (uint32_t)N->getZExtValue() < 256;
48 def imm8_255_neg : PatLeaf<(i32 imm), [{
49 unsigned Val = -N->getZExtValue();
50 return Val >= 8 && Val < 256;
53 // Break imm's up into two pieces: an immediate + a left shift. This uses
54 // thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
55 // to get the val/shift pieces.
56 def thumb_immshifted : PatLeaf<(imm), [{
57 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
60 def thumb_immshifted_val : SDNodeXForm<imm, [{
61 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
62 return CurDAG->getTargetConstant(V, MVT::i32);
65 def thumb_immshifted_shamt : SDNodeXForm<imm, [{
66 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
67 return CurDAG->getTargetConstant(V, MVT::i32);
70 // Scaled 4 immediate.
71 def t_imm_s4 : Operand<i32> {
72 let PrintMethod = "printThumbS4ImmOperand";
75 // Define Thumb specific addressing modes.
77 def t_brtarget : Operand<OtherVT> {
78 let EncoderMethod = "getThumbBRTargetOpValue";
81 def t_bcctarget : Operand<i32> {
82 let EncoderMethod = "getThumbBCCTargetOpValue";
85 def t_cbtarget : Operand<i32> {
86 let EncoderMethod = "getThumbCBTargetOpValue";
89 def t_bltarget : Operand<i32> {
90 let EncoderMethod = "getThumbBLTargetOpValue";
93 def t_blxtarget : Operand<i32> {
94 let EncoderMethod = "getThumbBLXTargetOpValue";
97 def MemModeRegThumbAsmOperand : AsmOperandClass {
98 let Name = "MemModeRegThumb";
99 let SuperClasses = [];
102 def MemModeImmThumbAsmOperand : AsmOperandClass {
103 let Name = "MemModeImmThumb";
104 let SuperClasses = [];
107 // t_addrmode_rr := reg + reg
109 def t_addrmode_rr : Operand<i32>,
110 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
111 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
112 let PrintMethod = "printThumbAddrModeRROperand";
113 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
116 // t_addrmode_rrs := reg + reg
118 def t_addrmode_rrs1 : Operand<i32>,
119 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
120 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
121 let PrintMethod = "printThumbAddrModeRROperand";
122 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
123 let ParserMatchClass = MemModeRegThumbAsmOperand;
126 def t_addrmode_rrs2 : Operand<i32>,
127 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
128 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
129 let PrintMethod = "printThumbAddrModeRROperand";
130 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
131 let ParserMatchClass = MemModeRegThumbAsmOperand;
133 def t_addrmode_rrs4 : Operand<i32>,
134 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
135 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
136 let PrintMethod = "printThumbAddrModeRROperand";
137 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
138 let ParserMatchClass = MemModeRegThumbAsmOperand;
141 // t_addrmode_is4 := reg + imm5 * 4
143 def t_addrmode_is4 : Operand<i32>,
144 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
145 let EncoderMethod = "getAddrModeISOpValue";
146 let PrintMethod = "printThumbAddrModeImm5S4Operand";
147 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
148 let ParserMatchClass = MemModeImmThumbAsmOperand;
151 // t_addrmode_is2 := reg + imm5 * 2
153 def t_addrmode_is2 : Operand<i32>,
154 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
155 let EncoderMethod = "getAddrModeISOpValue";
156 let PrintMethod = "printThumbAddrModeImm5S2Operand";
157 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
158 let ParserMatchClass = MemModeImmThumbAsmOperand;
161 // t_addrmode_is1 := reg + imm5
163 def t_addrmode_is1 : Operand<i32>,
164 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
165 let EncoderMethod = "getAddrModeISOpValue";
166 let PrintMethod = "printThumbAddrModeImm5S1Operand";
167 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
168 let ParserMatchClass = MemModeImmThumbAsmOperand;
171 // t_addrmode_sp := sp + imm8 * 4
173 def t_addrmode_sp : Operand<i32>,
174 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
175 let EncoderMethod = "getAddrModeThumbSPOpValue";
176 let PrintMethod = "printThumbAddrModeSPOperand";
177 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
178 let ParserMatchClass = MemModeImmThumbAsmOperand;
181 // t_addrmode_pc := <label> => pc + imm8 * 4
183 def t_addrmode_pc : Operand<i32> {
184 let EncoderMethod = "getAddrModePCOpValue";
185 let ParserMatchClass = MemModeImmThumbAsmOperand;
188 //===----------------------------------------------------------------------===//
189 // Miscellaneous Instructions.
192 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
193 // from removing one half of the matched pairs. That breaks PEI, which assumes
194 // these will always be in pairs, and asserts if it finds otherwise. Better way?
195 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
196 def tADJCALLSTACKUP :
197 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
198 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
199 Requires<[IsThumb, IsThumb1Only]>;
201 def tADJCALLSTACKDOWN :
202 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
203 [(ARMcallseq_start imm:$amt)]>,
204 Requires<[IsThumb, IsThumb1Only]>;
207 // T1Disassembly - A simple class to make encoding some disassembly patterns
208 // easier and less verbose.
209 class T1Disassembly<bits<2> op1, bits<8> op2>
210 : T1Encoding<0b101111> {
215 def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
216 [/* For disassembly only; pattern left blank */]>,
217 T1Disassembly<0b11, 0x00>; // A8.6.110
219 def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
220 [/* For disassembly only; pattern left blank */]>,
221 T1Disassembly<0b11, 0x10>; // A8.6.410
223 def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
224 [/* For disassembly only; pattern left blank */]>,
225 T1Disassembly<0b11, 0x20>; // A8.6.408
227 def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
228 [/* For disassembly only; pattern left blank */]>,
229 T1Disassembly<0b11, 0x30>; // A8.6.409
231 def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
232 [/* For disassembly only; pattern left blank */]>,
233 T1Disassembly<0b11, 0x40>; // A8.6.157
235 // The i32imm operand $val can be used by a debugger to store more information
236 // about the breakpoint.
237 def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
238 [/* For disassembly only; pattern left blank */]>,
239 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
245 def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
246 [/* For disassembly only; pattern left blank */]>,
247 T1Encoding<0b101101> {
249 let Inst{9-5} = 0b10010;
251 let Inst{3} = 1; // Big-Endian
252 let Inst{2-0} = 0b000;
255 def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
256 [/* For disassembly only; pattern left blank */]>,
257 T1Encoding<0b101101> {
259 let Inst{9-5} = 0b10010;
261 let Inst{3} = 0; // Little-Endian
262 let Inst{2-0} = 0b000;
265 // Change Processor State is a system instruction -- for disassembly only.
266 // The singleton $opt operand contains the following information:
268 // opt{4-0} = mode ==> don't care
269 // opt{5} = changemode ==> 0 (false for 16-bit Thumb instr)
270 // opt{8-6} = AIF from Inst{2-0}
271 // opt{10-9} = 1:imod from Inst{4} with 0b10 as enable and 0b11 as disable
273 // The opt{4-0} and opt{5} sub-fields are to accommodate 32-bit Thumb and ARM
274 // CPS which has more options.
275 def tCPS : T1I<(outs), (ins cps_opt:$opt), NoItinerary, "cps$opt",
276 [/* For disassembly only; pattern left blank */]>,
280 // FIXME: Finish encoding.
283 // For both thumb1 and thumb2.
284 let isNotDuplicable = 1, isCodeGenOnly = 1 in
285 def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
286 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
287 T1Special<{0,0,?,?}> {
290 let Inst{6-3} = 0b1111; // Rm = pc
294 // PC relative add (ADR).
295 def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
296 "add\t$dst, pc, $rhs", []>,
297 T1Encoding<{1,0,1,0,0,?}> {
301 let Inst{10-8} = dst;
305 // ADD <Rd>, sp, #<imm8>
306 // This is rematerializable, which is particularly useful for taking the
307 // address of locals.
308 let isReMaterializable = 1 in
309 def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
310 "add\t$dst, $sp, $rhs", []>,
311 T1Encoding<{1,0,1,0,1,?}> {
315 let Inst{10-8} = dst;
319 // ADD sp, sp, #<imm7>
320 def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
321 "add\t$dst, $rhs", []>,
322 T1Misc<{0,0,0,0,0,?,?}> {
328 // SUB sp, sp, #<imm7>
329 // FIXME: The encoding and the ASM string don't match up.
330 def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
331 "sub\t$dst, $rhs", []>,
332 T1Misc<{0,0,0,0,1,?,?}> {
339 def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
340 "add\t$dst, $rhs", []>,
341 T1Special<{0,0,?,?}> {
342 // A8.6.9 Encoding T1
344 let Inst{7} = dst{3};
345 let Inst{6-3} = 0b1101;
346 let Inst{2-0} = dst{2-0};
350 def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
351 "add\t$dst, $rhs", []>,
352 T1Special<{0,0,?,?}> {
353 // A8.6.9 Encoding T2
357 let Inst{2-0} = 0b101;
360 //===----------------------------------------------------------------------===//
361 // Control Flow Instructions.
364 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
365 def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr",
367 T1Special<{1,1,0,?}> {
369 let Inst{6-3} = 0b1110; // Rm = lr
370 let Inst{2-0} = 0b000;
373 // Alternative return instruction used by vararg functions.
374 def tBX_RET_vararg : TI<(outs), (ins tGPR:$Rm),
377 T1Special<{1,1,0,?}> {
381 let Inst{2-0} = 0b000;
386 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
387 def tBRIND : TI<(outs), (ins GPR:$Rm),
391 T1Special<{1,0,?,?}> {
394 let Inst{7} = 1; // <Rd> = Inst{7:2-0} = pc
396 let Inst{2-0} = 0b111;
400 // FIXME: remove when we have a way to marking a MI with these properties.
401 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
402 hasExtraDefRegAllocReq = 1 in
403 def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
405 "pop${p}\t$regs", []>,
406 T1Misc<{1,1,0,?,?,?,?}> {
409 let Inst{8} = regs{15}; // registers = P:'0000000':register_list
410 let Inst{7-0} = regs{7-0};
413 // All calls clobber the non-callee saved registers. SP is marked as a use to
414 // prevent stack-pointer assignments that appear immediately before calls from
415 // potentially appearing dead.
417 // On non-Darwin platforms R9 is callee-saved.
418 Defs = [R0, R1, R2, R3, R12, LR,
419 D0, D1, D2, D3, D4, D5, D6, D7,
420 D16, D17, D18, D19, D20, D21, D22, D23,
421 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
423 // Also used for Thumb2
424 def tBL : TIx2<0b11110, 0b11, 1,
425 (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
427 [(ARMtcall tglobaladdr:$func)]>,
428 Requires<[IsThumb, IsNotDarwin]> {
430 let Inst{25-16} = func{20-11};
433 let Inst{10-0} = func{10-0};
436 // ARMv5T and above, also used for Thumb2
437 def tBLXi : TIx2<0b11110, 0b11, 0,
438 (outs), (ins t_blxtarget:$func, variable_ops), IIC_Br,
440 [(ARMcall tglobaladdr:$func)]>,
441 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
443 let Inst{25-16} = func{20-11};
446 let Inst{10-1} = func{10-1};
447 let Inst{0} = 0; // func{0} is assumed zero
450 // Also used for Thumb2
451 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
453 [(ARMtcall GPR:$func)]>,
454 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
455 T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24;
458 // FIXME: Should be a pseudo.
459 let isCodeGenOnly = 1 in
460 def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?,
461 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
462 "mov\tlr, pc\n\tbx\t$func",
463 [(ARMcall_nolink tGPR:$func)]>,
464 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
468 // On Darwin R9 is call-clobbered.
469 // R7 is marked as a use to prevent frame-pointer assignments from being
470 // moved above / below calls.
471 Defs = [R0, R1, R2, R3, R9, R12, LR,
472 D0, D1, D2, D3, D4, D5, D6, D7,
473 D16, D17, D18, D19, D20, D21, D22, D23,
474 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
476 // Also used for Thumb2
477 def tBLr9 : TIx2<0b11110, 0b11, 1,
478 (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
479 IIC_Br, "bl${p}\t$func",
480 [(ARMtcall tglobaladdr:$func)]>,
481 Requires<[IsThumb, IsDarwin]> {
483 let Inst{25-16} = func{20-11};
486 let Inst{10-0} = func{10-0};
489 // ARMv5T and above, also used for Thumb2
490 def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
491 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
492 IIC_Br, "blx${p}\t$func",
493 [(ARMcall tglobaladdr:$func)]>,
494 Requires<[IsThumb, HasV5T, IsDarwin]> {
496 let Inst{25-16} = func{20-11};
499 let Inst{10-1} = func{10-1};
500 let Inst{0} = 0; // func{0} is assumed zero
503 // Also used for Thumb2
504 def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
506 [(ARMtcall GPR:$func)]>,
507 Requires<[IsThumb, HasV5T, IsDarwin]>,
508 T1Special<{1,1,1,?}> {
511 let Inst{6-3} = func;
512 let Inst{2-0} = 0b000;
516 let isCodeGenOnly = 1 in
517 // FIXME: Should be a pseudo.
518 def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?,
519 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
520 "mov\tlr, pc\n\tbx\t$func",
521 [(ARMcall_nolink tGPR:$func)]>,
522 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
525 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
526 let isPredicable = 1 in
527 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
528 "b\t$target", [(br bb:$target)]>,
529 T1Encoding<{1,1,1,0,0,?}> {
531 let Inst{10-0} = target;
535 // FIXME: Encoding. This should probably be a pseudo for tBL
537 def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
540 def tBR_JTr : tPseudoInst<(outs),
541 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
543 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
544 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
548 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
549 // a two-value operand where a dag node expects two operands. :(
550 let isBranch = 1, isTerminator = 1 in
551 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
553 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
554 T1Encoding<{1,1,0,1,?,?}> {
558 let Inst{7-0} = target;
561 // Compare and branch on zero / non-zero
562 let isBranch = 1, isTerminator = 1 in {
563 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
564 "cbz\t$Rn, $target", []>,
565 T1Misc<{0,0,?,1,?,?,?}> {
569 let Inst{9} = target{5};
570 let Inst{7-3} = target{4-0};
574 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
575 "cbnz\t$cmp, $target", []>,
576 T1Misc<{1,0,?,1,?,?,?}> {
580 let Inst{9} = target{5};
581 let Inst{7-3} = target{4-0};
586 // A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
587 // A8.6.16 B: Encoding T1
588 // If Inst{11-8} == 0b1111 then SEE SVC
589 let isCall = 1, Uses = [SP] in
590 def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
591 "svc", "\t$imm", []>, Encoding16 {
593 let Inst{15-12} = 0b1101;
594 let Inst{11-8} = 0b1111;
598 // The assembler uses 0xDEFE for a trap instruction.
599 let isBarrier = 1, isTerminator = 1 in
600 def tTRAP : TI<(outs), (ins), IIC_Br,
601 "trap", [(trap)]>, Encoding16 {
605 //===----------------------------------------------------------------------===//
606 // Load Store Instructions.
609 let canFoldAsLoad = 1, isReMaterializable = 1 in
610 def tLDRr : // A8.6.60
611 T1pILdStEncode<0b100, (outs tGPR:$Rt), (ins t_addrmode_rrs4:$addr),
612 AddrModeT1_4, IIC_iLoad_r,
613 "ldr", "\t$Rt, $addr",
614 [(set tGPR:$Rt, (load t_addrmode_rrs4:$addr))]>;
616 def tLDRi : // A8.6.57
617 T1pILdStEncodeImm<0b0110, 1, (outs tGPR:$Rt), (ins t_addrmode_is4:$addr),
618 AddrModeT1_4, IIC_iLoad_r,
619 "ldr", "\t$Rt, $addr",
620 [(set tGPR:$Rt, (load t_addrmode_is4:$addr))]>;
622 def tLDRBr : // A8.6.64
623 T1pILdStEncode<0b110, (outs tGPR:$Rt), (ins t_addrmode_rrs1:$addr),
624 AddrModeT1_1, IIC_iLoad_bh_r,
625 "ldrb", "\t$Rt, $addr",
626 [(set tGPR:$Rt, (zextloadi8 t_addrmode_rrs1:$addr))]>;
628 def tLDRBi : // A8.6.61
629 T1pILdStEncodeImm<0b0111, 1, (outs tGPR:$Rt), (ins t_addrmode_is1:$addr),
630 AddrModeT1_1, IIC_iLoad_bh_r,
631 "ldrb", "\t$Rt, $addr",
632 [(set tGPR:$Rt, (zextloadi8 t_addrmode_is1:$addr))]>;
634 def tLDRHr : // A8.6.76
635 T1pILdStEncode<0b101, (outs tGPR:$Rt), (ins t_addrmode_rrs2:$addr),
636 AddrModeT1_2, IIC_iLoad_bh_r,
637 "ldrh", "\t$Rt, $addr",
638 [(set tGPR:$Rt, (zextloadi16 t_addrmode_rrs2:$addr))]>;
640 def tLDRHi : // A8.6.73
641 T1pILdStEncodeImm<0b1000, 1, (outs tGPR:$Rt), (ins t_addrmode_is2:$addr),
642 AddrModeT1_2, IIC_iLoad_bh_r,
643 "ldrh", "\t$Rt, $addr",
644 [(set tGPR:$Rt, (zextloadi16 t_addrmode_is2:$addr))]>;
646 let AddedComplexity = 10 in
647 def tLDRSB : // A8.6.80
648 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
649 AddrModeT1_1, IIC_iLoad_bh_r,
650 "ldrsb", "\t$dst, $addr",
651 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
653 let AddedComplexity = 10 in
654 def tLDRSH : // A8.6.84
655 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
656 AddrModeT1_2, IIC_iLoad_bh_r,
657 "ldrsh", "\t$dst, $addr",
658 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
660 let canFoldAsLoad = 1 in
661 def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
662 "ldr", "\t$Rt, $addr",
663 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
668 let Inst{7-0} = addr;
671 // Special instruction for restore. It cannot clobber condition register
672 // when it's expanded by eliminateCallFramePseudoInstr().
673 let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1 in
674 // FIXME: Pseudo for tLDRspi
675 def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
676 "ldr", "\t$dst, $addr", []>,
680 // FIXME: Use ldr.n to work around a Darwin assembler bug.
681 let canFoldAsLoad = 1, isReMaterializable = 1 in
682 def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
683 "ldr", ".n\t$Rt, $addr",
684 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
685 T1Encoding<{0,1,0,0,1,?}> {
690 let Inst{7-0} = addr;
693 // Special LDR for loads from non-pc-relative constpools.
694 let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
695 isReMaterializable = 1 in
696 def tLDRcp : T1pIs<(outs tGPR:$Rt), (ins i32imm:$addr), IIC_iLoad_i,
697 "ldr", "\t$Rt, $addr", []>,
703 let Inst{7-0} = addr;
706 def tSTRr : // A8.6.194
707 T1pILdStEncode<0b000, (outs), (ins tGPR:$Rt, t_addrmode_rrs4:$addr),
708 AddrModeT1_4, IIC_iStore_r,
709 "str", "\t$Rt, $addr",
710 [(store tGPR:$Rt, t_addrmode_rrs4:$addr)]>;
712 def tSTRi : // A8.6.192
713 T1pILdStEncodeImm<0b0110, 0, (outs), (ins tGPR:$Rt, t_addrmode_is4:$addr),
714 AddrModeT1_4, IIC_iStore_r,
715 "str", "\t$Rt, $addr",
716 [(store tGPR:$Rt, t_addrmode_is4:$addr)]>;
718 def tSTRBr : // A8.6.197
719 T1pILdStEncode<0b010, (outs), (ins tGPR:$Rt, t_addrmode_rrs1:$addr),
720 AddrModeT1_1, IIC_iStore_bh_r,
721 "strb", "\t$Rt, $addr",
722 [(truncstorei8 tGPR:$Rt, t_addrmode_rrs1:$addr)]>;
724 def tSTRBi : // A8.6.195
725 T1pILdStEncodeImm<0b0111, 0, (outs), (ins tGPR:$Rt, t_addrmode_is1:$addr),
726 AddrModeT1_1, IIC_iStore_bh_r,
727 "strb", "\t$Rt, $addr",
728 [(truncstorei8 tGPR:$Rt, t_addrmode_is1:$addr)]>;
730 def tSTRHr : // A8.6.207
731 T1pILdStEncode<0b001, (outs), (ins tGPR:$Rt, t_addrmode_rrs2:$addr),
732 AddrModeT1_2, IIC_iStore_bh_r,
733 "strh", "\t$Rt, $addr",
734 [(truncstorei16 tGPR:$Rt, t_addrmode_rrs2:$addr)]>;
736 def tSTRHi : // A8.6.205
737 T1pILdStEncodeImm<0b1000, 0, (outs), (ins tGPR:$Rt, t_addrmode_is2:$addr),
738 AddrModeT1_2, IIC_iStore_bh_r,
739 "strh", "\t$Rt, $addr",
740 [(truncstorei16 tGPR:$Rt, t_addrmode_is2:$addr)]>;
742 def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
743 "str", "\t$Rt, $addr",
744 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
749 let Inst{7-0} = addr;
752 let mayStore = 1, neverHasSideEffects = 1 in
753 // Special instruction for spill. It cannot clobber condition register when it's
754 // expanded by eliminateCallFramePseudoInstr().
755 // FIXME: Pseudo for tSTRspi
756 def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore_i,
757 "str", "\t$src, $addr", []>,
760 //===----------------------------------------------------------------------===//
761 // Load / store multiple Instructions.
764 multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
765 InstrItinClass itin_upd, bits<6> T1Enc,
768 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
769 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
774 let Inst{7-0} = regs;
777 T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
778 itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
783 let Inst{7-0} = regs;
787 // These require base address to be written back or one of the loaded regs.
788 let neverHasSideEffects = 1 in {
790 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
791 defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
794 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
795 defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
798 } // neverHasSideEffects
800 let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
801 def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
803 "pop${p}\t$regs", []>,
804 T1Misc<{1,1,0,?,?,?,?}> {
806 let Inst{8} = regs{15};
807 let Inst{7-0} = regs{7-0};
810 let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
811 def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
813 "push${p}\t$regs", []>,
814 T1Misc<{0,1,0,?,?,?,?}> {
816 let Inst{8} = regs{14};
817 let Inst{7-0} = regs{7-0};
820 //===----------------------------------------------------------------------===//
821 // Arithmetic Instructions.
824 // Helper classes for encoding T1pI patterns:
825 class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
826 string opc, string asm, list<dag> pattern>
827 : T1pI<oops, iops, itin, opc, asm, pattern>,
828 T1DataProcessing<opA> {
834 class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
835 string opc, string asm, list<dag> pattern>
836 : T1pI<oops, iops, itin, opc, asm, pattern>,
844 // Helper classes for encoding T1sI patterns:
845 class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
846 string opc, string asm, list<dag> pattern>
847 : T1sI<oops, iops, itin, opc, asm, pattern>,
848 T1DataProcessing<opA> {
854 class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
855 string opc, string asm, list<dag> pattern>
856 : T1sI<oops, iops, itin, opc, asm, pattern>,
865 class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
866 string opc, string asm, list<dag> pattern>
867 : T1sI<oops, iops, itin, opc, asm, pattern>,
875 // Helper classes for encoding T1sIt patterns:
876 class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
877 string opc, string asm, list<dag> pattern>
878 : T1sIt<oops, iops, itin, opc, asm, pattern>,
879 T1DataProcessing<opA> {
885 class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
886 string opc, string asm, list<dag> pattern>
887 : T1sIt<oops, iops, itin, opc, asm, pattern>,
891 let Inst{10-8} = Rdn;
892 let Inst{7-0} = imm8;
895 // Add with carry register
896 let isCommutable = 1, Uses = [CPSR] in
898 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
899 "adc", "\t$Rdn, $Rm",
900 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
903 def tADDi3 : // A8.6.4 T1
904 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3), IIC_iALUi,
905 "add", "\t$Rd, $Rm, $imm3",
906 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
908 let Inst{8-6} = imm3;
911 def tADDi8 : // A8.6.4 T2
912 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
914 "add", "\t$Rdn, $imm8",
915 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
918 let isCommutable = 1 in
919 def tADDrr : // A8.6.6 T1
920 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
922 "add", "\t$Rd, $Rn, $Rm",
923 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
925 let neverHasSideEffects = 1 in
926 def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
927 "add", "\t$Rdn, $Rm", []>,
928 T1Special<{0,0,?,?}> {
932 let Inst{7} = Rdn{3};
934 let Inst{2-0} = Rdn{2-0};
938 let isCommutable = 1 in
939 def tAND : // A8.6.12
940 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
942 "and", "\t$Rdn, $Rm",
943 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
946 def tASRri : // A8.6.14
947 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
949 "asr", "\t$Rd, $Rm, $imm5",
950 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
952 let Inst{10-6} = imm5;
956 def tASRrr : // A8.6.15
957 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
959 "asr", "\t$Rdn, $Rm",
960 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
963 def tBIC : // A8.6.20
964 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
966 "bic", "\t$Rdn, $Rm",
967 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
970 let isCompare = 1, Defs = [CPSR] in {
971 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
972 // Compare-to-zero still works out, just not the relationals
973 //def tCMN : // A8.6.33
974 // T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
976 // "cmn", "\t$lhs, $rhs",
977 // [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
979 def tCMNz : // A8.6.33
980 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
983 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
985 } // isCompare = 1, Defs = [CPSR]
988 let isCompare = 1, Defs = [CPSR] in {
989 def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
990 "cmp", "\t$Rn, $imm8",
991 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
992 T1General<{1,0,1,?,?}> {
997 let Inst{7-0} = imm8;
1001 def tCMPr : // A8.6.36 T1
1002 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1004 "cmp", "\t$Rn, $Rm",
1005 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
1007 def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1008 "cmp", "\t$Rn, $Rm", []>,
1009 T1Special<{0,1,?,?}> {
1013 let Inst{7} = Rn{3};
1015 let Inst{2-0} = Rn{2-0};
1017 } // isCompare = 1, Defs = [CPSR]
1021 let isCommutable = 1 in
1022 def tEOR : // A8.6.45
1023 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1025 "eor", "\t$Rdn, $Rm",
1026 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
1029 def tLSLri : // A8.6.88
1030 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1032 "lsl", "\t$Rd, $Rm, $imm5",
1033 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
1035 let Inst{10-6} = imm5;
1039 def tLSLrr : // A8.6.89
1040 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1042 "lsl", "\t$Rdn, $Rm",
1043 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
1046 def tLSRri : // A8.6.90
1047 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1049 "lsr", "\t$Rd, $Rm, $imm5",
1050 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
1052 let Inst{10-6} = imm5;
1056 def tLSRrr : // A8.6.91
1057 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1059 "lsr", "\t$Rdn, $Rm",
1060 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
1063 let isMoveImm = 1 in
1064 def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins i32imm:$imm8), IIC_iMOVi,
1065 "mov", "\t$Rd, $imm8",
1066 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1067 T1General<{1,0,0,?,?}> {
1071 let Inst{10-8} = Rd;
1072 let Inst{7-0} = imm8;
1075 // TODO: A7-73: MOV(2) - mov setting flag.
1077 let neverHasSideEffects = 1 in {
1078 // FIXME: Make this predicable.
1079 def tMOVr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1080 "mov\t$Rd, $Rm", []>,
1085 // Bits {7-6} are encoded by the T1Special value.
1086 let Inst{5-3} = Rm{2-0};
1087 let Inst{2-0} = Rd{2-0};
1089 let Defs = [CPSR] in
1090 def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1091 "movs\t$Rd, $Rm", []>, Encoding16 {
1095 let Inst{15-6} = 0b0000000000;
1100 // FIXME: Make these predicable.
1101 def tMOVgpr2tgpr : T1I<(outs tGPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1102 "mov\t$Rd, $Rm", []>,
1103 T1Special<{1,0,0,?}> {
1107 // Bit {7} is encoded by the T1Special value.
1109 let Inst{2-0} = Rd{2-0};
1111 def tMOVtgpr2gpr : T1I<(outs GPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1112 "mov\t$Rd, $Rm", []>,
1113 T1Special<{1,0,?,0}> {
1117 // Bit {6} is encoded by the T1Special value.
1118 let Inst{7} = Rd{3};
1119 let Inst{5-3} = Rm{2-0};
1120 let Inst{2-0} = Rd{2-0};
1122 def tMOVgpr2gpr : T1I<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1123 "mov\t$Rd, $Rm", []>,
1124 T1Special<{1,0,?,?}> {
1128 let Inst{7} = Rd{3};
1130 let Inst{2-0} = Rd{2-0};
1132 } // neverHasSideEffects
1134 // Multiply register
1135 let isCommutable = 1 in
1136 def tMUL : // A8.6.105 T1
1137 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1139 "mul", "\t$Rdn, $Rm, $Rdn",
1140 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
1142 // Move inverse register
1143 def tMVN : // A8.6.107
1144 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1145 "mvn", "\t$Rd, $Rn",
1146 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
1148 // Bitwise or register
1149 let isCommutable = 1 in
1150 def tORR : // A8.6.114
1151 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1153 "orr", "\t$Rdn, $Rm",
1154 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
1157 def tREV : // A8.6.134
1158 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1160 "rev", "\t$Rd, $Rm",
1161 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1162 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1164 def tREV16 : // A8.6.135
1165 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1167 "rev16", "\t$Rd, $Rm",
1169 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF),
1170 (or (and (shl tGPR:$Rm, (i32 8)), 0xFF00),
1171 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF0000),
1172 (and (shl tGPR:$Rm, (i32 8)), 0xFF000000)))))]>,
1173 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1175 def tREVSH : // A8.6.136
1176 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1178 "revsh", "\t$Rd, $Rm",
1181 (or (srl (and tGPR:$Rm, 0xFF00), (i32 8)),
1182 (shl tGPR:$Rm, (i32 8))), i16))]>,
1183 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1185 // Rotate right register
1186 def tROR : // A8.6.139
1187 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1189 "ror", "\t$Rdn, $Rm",
1190 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
1193 def tRSB : // A8.6.141
1194 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1196 "rsb", "\t$Rd, $Rn, #0",
1197 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
1199 // Subtract with carry register
1200 let Uses = [CPSR] in
1201 def tSBC : // A8.6.151
1202 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1204 "sbc", "\t$Rdn, $Rm",
1205 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
1207 // Subtract immediate
1208 def tSUBi3 : // A8.6.210 T1
1209 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1211 "sub", "\t$Rd, $Rm, $imm3",
1212 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
1214 let Inst{8-6} = imm3;
1217 def tSUBi8 : // A8.6.210 T2
1218 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1220 "sub", "\t$Rdn, $imm8",
1221 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
1223 // Subtract register
1224 def tSUBrr : // A8.6.212
1225 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1227 "sub", "\t$Rd, $Rn, $Rm",
1228 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
1230 // TODO: A7-96: STMIA - store multiple.
1233 def tSXTB : // A8.6.222
1234 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1236 "sxtb", "\t$Rd, $Rm",
1237 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1238 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1240 // Sign-extend short
1241 def tSXTH : // A8.6.224
1242 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1244 "sxth", "\t$Rd, $Rm",
1245 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1246 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1249 let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
1250 def tTST : // A8.6.230
1251 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1252 "tst", "\t$Rn, $Rm",
1253 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
1256 def tUXTB : // A8.6.262
1257 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1259 "uxtb", "\t$Rd, $Rm",
1260 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1261 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1263 // Zero-extend short
1264 def tUXTH : // A8.6.264
1265 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1267 "uxth", "\t$Rd, $Rm",
1268 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1269 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1271 // Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
1272 // Expanded after instruction selection into a branch sequence.
1273 let usesCustomInserter = 1 in // Expanded after instruction selection.
1274 def tMOVCCr_pseudo :
1275 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
1277 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
1280 // 16-bit movcc in IT blocks for Thumb2.
1281 let neverHasSideEffects = 1 in {
1282 def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1283 "mov", "\t$Rdn, $Rm", []>,
1284 T1Special<{1,0,?,?}> {
1287 let Inst{7} = Rdn{3};
1289 let Inst{2-0} = Rdn{2-0};
1292 let isMoveImm = 1 in
1293 def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1294 "mov", "\t$Rdn, $Rm", []>,
1295 T1General<{1,0,0,?,?}> {
1298 let Inst{10-8} = Rdn;
1302 } // neverHasSideEffects
1304 // tLEApcrel - Load a pc-relative address into a register without offending the
1306 let neverHasSideEffects = 1, isReMaterializable = 1 in
1307 def tLEApcrel : T1I<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p), IIC_iALUi,
1308 "adr${p}\t$Rd, #$label", []>,
1309 T1Encoding<{1,0,1,0,0,?}> {
1312 let Inst{10-8} = Rd;
1313 // FIXME: Add label encoding/fixup
1316 def tLEApcrelJT : T1I<(outs tGPR:$Rd),
1317 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1318 IIC_iALUi, "adr${p}\t$Rd, #${label}_${id}", []>,
1319 T1Encoding<{1,0,1,0,0,?}> {
1322 let Inst{10-8} = Rd;
1323 // FIXME: Add label encoding/fixup
1326 //===----------------------------------------------------------------------===//
1330 // __aeabi_read_tp preserves the registers r1-r3.
1331 let isCall = 1, Defs = [R0, LR], Uses = [SP] in
1332 def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
1333 "bl\t__aeabi_read_tp",
1334 [(set R0, ARMthread_pointer)]> {
1335 // Encoding is 0xf7fffffe.
1336 let Inst = 0xf7fffffe;
1339 //===----------------------------------------------------------------------===//
1340 // SJLJ Exception handling intrinsics
1343 // eh_sjlj_setjmp() is an instruction sequence to store the return address and
1344 // save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1345 // from some other function to get here, and we're using the stack frame for the
1346 // containing function to save/restore registers, we can't keep anything live in
1347 // regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1348 // tromped upon when we get here from a longjmp(). We force everthing out of
1349 // registers except for our own input by listing the relevant registers in
1350 // Defs. By doing so, we also cause the prologue/epilogue code to actively
1351 // preserve all of the callee-saved resgisters, which is exactly what we want.
1352 // $val is a scratch register for our use.
1353 let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12 ],
1354 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1355 def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1356 AddrModeNone, SizeSpecial, NoItinerary, "","",
1357 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
1359 // FIXME: Non-Darwin version(s)
1360 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1361 Defs = [ R7, LR, SP ] in
1362 def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
1363 AddrModeNone, SizeSpecial, IndexModeNone,
1364 Pseudo, NoItinerary, "", "",
1365 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1366 Requires<[IsThumb, IsDarwin]>;
1368 //===----------------------------------------------------------------------===//
1369 // Non-Instruction Patterns
1373 def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1374 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1375 def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1376 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1379 def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1380 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1381 def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
1382 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
1383 def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1384 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
1386 // Subtract with carry
1387 def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1388 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1389 def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1390 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1391 def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1392 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
1394 // ConstantPool, GlobalAddress
1395 def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1396 def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
1399 def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1400 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
1403 def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
1404 Requires<[IsThumb, IsNotDarwin]>;
1405 def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
1406 Requires<[IsThumb, IsDarwin]>;
1408 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
1409 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1410 def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
1411 Requires<[IsThumb, HasV5T, IsDarwin]>;
1413 // Indirect calls to ARM routines
1414 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1415 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1416 def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1417 Requires<[IsThumb, HasV5T, IsDarwin]>;
1419 // zextload i1 -> zextload i8
1420 def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1421 (tLDRBr t_addrmode_rrs1:$addr)>;
1422 def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1423 (tLDRBi t_addrmode_is1:$addr)>;
1425 // extload -> zextload
1426 def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1427 def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1428 def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1429 def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1430 def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1431 def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1433 // If it's impossible to use [r,r] address mode for sextload, select to
1434 // ldr{b|h} + sxt{b|h} instead.
1435 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1436 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
1437 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1438 def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1439 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
1440 Requires<[IsThumb, IsThumb1Only, HasV6]>;
1442 def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1443 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
1444 def : T1Pat<(sextloadi16 t_addrmode_rrs1:$addr),
1445 (tASRri (tLSLri (tLDRHr t_addrmode_rrs1:$addr), 16), 16)>;
1447 // Large immediate handling.
1450 def : T1Pat<(i32 thumb_immshifted:$src),
1451 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1452 (thumb_immshifted_shamt imm:$src))>;
1454 def : T1Pat<(i32 imm0_255_comp:$src),
1455 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
1457 // Pseudo instruction that combines ldr from constpool and add pc. This should
1458 // be expanded into two instructions late to allow if-conversion and
1460 let isReMaterializable = 1 in
1461 def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
1463 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1465 Requires<[IsThumb, IsThumb1Only]>;