1 //===- ARMInstrInfo.td - Target Description for ARM Target -*- 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 ARM instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // ARM specific DAG Nodes.
19 def SDT_ARMCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
20 def SDT_ARMCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>;
22 def SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
24 def SDT_ARMcall : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
26 def SDT_ARMCMov : SDTypeProfile<1, 3,
27 [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
30 def SDT_ARMBrcond : SDTypeProfile<0, 2,
31 [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
33 def SDT_ARMBrJT : SDTypeProfile<0, 3,
34 [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
37 def SDT_ARMCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
39 def SDT_ARMPICAdd : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
40 SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
42 def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
43 def SDT_ARMEH_SJLJ_Setjmp : SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
46 def ARMWrapper : SDNode<"ARMISD::Wrapper", SDTIntUnaryOp>;
47 def ARMWrapperJT : SDNode<"ARMISD::WrapperJT", SDTIntBinOp>;
49 def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
50 [SDNPHasChain, SDNPOutFlag]>;
51 def ARMcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_ARMCallSeqEnd,
52 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
54 def ARMcall : SDNode<"ARMISD::CALL", SDT_ARMcall,
55 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
56 def ARMcall_pred : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
57 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
58 def ARMcall_nolink : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
59 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
61 def ARMretflag : SDNode<"ARMISD::RET_FLAG", SDTNone,
62 [SDNPHasChain, SDNPOptInFlag]>;
64 def ARMcmov : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
66 def ARMcneg : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
69 def ARMbrcond : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
70 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
72 def ARMbrjt : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
75 def ARMcmp : SDNode<"ARMISD::CMP", SDT_ARMCmp,
78 def ARMcmpNZ : SDNode<"ARMISD::CMPNZ", SDT_ARMCmp,
81 def ARMpic_add : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
83 def ARMsrl_flag : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
84 def ARMsra_flag : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
85 def ARMrrx : SDNode<"ARMISD::RRX" , SDTIntUnaryOp, [SDNPInFlag ]>;
87 def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
88 def ARMeh_sjlj_setjmp: SDNode<"ARMISD::EH_SJLJ_SETJMP", SDT_ARMEH_SJLJ_Setjmp>;
90 //===----------------------------------------------------------------------===//
91 // ARM Instruction Predicate Definitions.
93 def HasV5T : Predicate<"Subtarget->hasV5TOps()">;
94 def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">;
95 def HasV6 : Predicate<"Subtarget->hasV6Ops()">;
96 def IsThumb : Predicate<"Subtarget->isThumb()">;
97 def IsARM : Predicate<"!Subtarget->isThumb()">;
99 //===----------------------------------------------------------------------===//
100 // ARM Flag Definitions.
102 class RegConstraint<string C> {
103 string Constraints = C;
106 //===----------------------------------------------------------------------===//
107 // ARM specific transformation functions and pattern fragments.
110 // so_imm_XFORM - Return a so_imm value packed into the format described for
112 def so_imm_XFORM : SDNodeXForm<imm, [{
113 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(N->getZExtValue()),
117 // so_imm_neg_XFORM - Return a so_imm value packed into the format described for
118 // so_imm_neg def below.
119 def so_imm_neg_XFORM : SDNodeXForm<imm, [{
120 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(-(int)N->getZExtValue()),
124 // so_imm_not_XFORM - Return a so_imm value packed into the format described for
125 // so_imm_not def below.
126 def so_imm_not_XFORM : SDNodeXForm<imm, [{
127 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(~(int)N->getZExtValue()),
131 // rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
132 def rot_imm : PatLeaf<(i32 imm), [{
133 int32_t v = (int32_t)N->getZExtValue();
134 return v == 8 || v == 16 || v == 24;
137 /// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
138 def imm1_15 : PatLeaf<(i32 imm), [{
139 return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 16;
142 /// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
143 def imm16_31 : PatLeaf<(i32 imm), [{
144 return (int32_t)N->getZExtValue() >= 16 && (int32_t)N->getZExtValue() < 32;
149 return ARM_AM::getSOImmVal(-(int)N->getZExtValue()) != -1;
150 }], so_imm_neg_XFORM>;
154 return ARM_AM::getSOImmVal(~(int)N->getZExtValue()) != -1;
155 }], so_imm_not_XFORM>;
157 // sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
158 def sext_16_node : PatLeaf<(i32 GPR:$a), [{
159 return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
162 class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
163 class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
165 //===----------------------------------------------------------------------===//
166 // Operand Definitions.
170 def brtarget : Operand<OtherVT>;
172 // A list of registers separated by comma. Used by load/store multiple.
173 def reglist : Operand<i32> {
174 let PrintMethod = "printRegisterList";
177 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
178 def cpinst_operand : Operand<i32> {
179 let PrintMethod = "printCPInstOperand";
182 def jtblock_operand : Operand<i32> {
183 let PrintMethod = "printJTBlockOperand";
187 def pclabel : Operand<i32> {
188 let PrintMethod = "printPCLabel";
191 // shifter_operand operands: so_reg and so_imm.
192 def so_reg : Operand<i32>, // reg reg imm
193 ComplexPattern<i32, 3, "SelectShifterOperandReg",
194 [shl,srl,sra,rotr]> {
195 let PrintMethod = "printSORegOperand";
196 let MIOperandInfo = (ops GPR, GPR, i32imm);
199 // so_imm - Match a 32-bit shifter_operand immediate operand, which is an
200 // 8-bit immediate rotated by an arbitrary number of bits. so_imm values are
201 // represented in the imm field in the same 12-bit form that they are encoded
202 // into so_imm instructions: the 8-bit immediate is the least significant bits
203 // [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
204 def so_imm : Operand<i32>,
206 [{ return ARM_AM::getSOImmVal(N->getZExtValue()) != -1; }],
208 let PrintMethod = "printSOImmOperand";
211 // Break so_imm's up into two pieces. This handles immediates with up to 16
212 // bits set in them. This uses so_imm2part to match and so_imm2part_[12] to
213 // get the first/second pieces.
214 def so_imm2part : Operand<i32>,
216 return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
218 let PrintMethod = "printSOImm2PartOperand";
221 def so_imm2part_1 : SDNodeXForm<imm, [{
222 unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getZExtValue());
223 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
226 def so_imm2part_2 : SDNodeXForm<imm, [{
227 unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getZExtValue());
228 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
232 // Define ARM specific addressing modes.
234 // addrmode2 := reg +/- reg shop imm
235 // addrmode2 := reg +/- imm12
237 def addrmode2 : Operand<i32>,
238 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
239 let PrintMethod = "printAddrMode2Operand";
240 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
243 def am2offset : Operand<i32>,
244 ComplexPattern<i32, 2, "SelectAddrMode2Offset", []> {
245 let PrintMethod = "printAddrMode2OffsetOperand";
246 let MIOperandInfo = (ops GPR, i32imm);
249 // addrmode3 := reg +/- reg
250 // addrmode3 := reg +/- imm8
252 def addrmode3 : Operand<i32>,
253 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
254 let PrintMethod = "printAddrMode3Operand";
255 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
258 def am3offset : Operand<i32>,
259 ComplexPattern<i32, 2, "SelectAddrMode3Offset", []> {
260 let PrintMethod = "printAddrMode3OffsetOperand";
261 let MIOperandInfo = (ops GPR, i32imm);
264 // addrmode4 := reg, <mode|W>
266 def addrmode4 : Operand<i32>,
267 ComplexPattern<i32, 2, "", []> {
268 let PrintMethod = "printAddrMode4Operand";
269 let MIOperandInfo = (ops GPR, i32imm);
272 // addrmode5 := reg +/- imm8*4
274 def addrmode5 : Operand<i32>,
275 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
276 let PrintMethod = "printAddrMode5Operand";
277 let MIOperandInfo = (ops GPR, i32imm);
280 // addrmodepc := pc + reg
282 def addrmodepc : Operand<i32>,
283 ComplexPattern<i32, 2, "SelectAddrModePC", []> {
284 let PrintMethod = "printAddrModePCOperand";
285 let MIOperandInfo = (ops GPR, i32imm);
288 // ARM Predicate operand. Default to 14 = always (AL). Second part is CC
289 // register whose default is 0 (no register).
290 def pred : PredicateOperand<OtherVT, (ops i32imm, CCR),
291 (ops (i32 14), (i32 zero_reg))> {
292 let PrintMethod = "printPredicateOperand";
295 // Conditional code result for instructions whose 's' bit is set, e.g. subs.
297 def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
298 let PrintMethod = "printSBitModifierOperand";
301 //===----------------------------------------------------------------------===//
302 // ARM Instruction flags. These need to match ARMInstrInfo.h.
306 class AddrMode<bits<4> val> {
309 def AddrModeNone : AddrMode<0>;
310 def AddrMode1 : AddrMode<1>;
311 def AddrMode2 : AddrMode<2>;
312 def AddrMode3 : AddrMode<3>;
313 def AddrMode4 : AddrMode<4>;
314 def AddrMode5 : AddrMode<5>;
315 def AddrModeT1 : AddrMode<6>;
316 def AddrModeT2 : AddrMode<7>;
317 def AddrModeT4 : AddrMode<8>;
318 def AddrModeTs : AddrMode<9>;
321 class SizeFlagVal<bits<3> val> {
324 def SizeInvalid : SizeFlagVal<0>; // Unset.
325 def SizeSpecial : SizeFlagVal<1>; // Pseudo or special.
326 def Size8Bytes : SizeFlagVal<2>;
327 def Size4Bytes : SizeFlagVal<3>;
328 def Size2Bytes : SizeFlagVal<4>;
330 // Load / store index mode.
331 class IndexMode<bits<2> val> {
334 def IndexModeNone : IndexMode<0>;
335 def IndexModePre : IndexMode<1>;
336 def IndexModePost : IndexMode<2>;
338 //===----------------------------------------------------------------------===//
340 include "ARMInstrFormats.td"
342 //===----------------------------------------------------------------------===//
343 // Multiclass helpers...
346 /// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
347 /// binop that produces a value.
348 multiclass AsI1_bin_irs<bits<4> opcod, string opc, PatFrag opnode> {
349 def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
350 opc, " $dst, $a, $b",
351 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
352 def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
353 opc, " $dst, $a, $b",
354 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
355 def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
356 opc, " $dst, $a, $b",
357 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
360 /// ASI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
361 /// instruction modifies the CSPR register.
362 let Defs = [CPSR] in {
363 multiclass ASI1_bin_s_irs<bits<4> opcod, string opc, PatFrag opnode> {
364 def ri : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
365 opc, "s $dst, $a, $b",
366 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
367 def rr : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
368 opc, "s $dst, $a, $b",
369 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
370 def rs : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
371 opc, "s $dst, $a, $b",
372 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
376 /// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
377 /// patterns. Similar to AsI1_bin_irs except the instruction does not produce
378 /// a explicit result, only implicitly set CPSR.
379 let Defs = [CPSR] in {
380 multiclass AI1_cmp_irs<bits<4> opcod, string opc, PatFrag opnode> {
381 def ri : AI1<opcod, (outs), (ins GPR:$a, so_imm:$b), DPFrm,
383 [(opnode GPR:$a, so_imm:$b)]>;
384 def rr : AI1<opcod, (outs), (ins GPR:$a, GPR:$b), DPFrm,
386 [(opnode GPR:$a, GPR:$b)]>;
387 def rs : AI1<opcod, (outs), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
389 [(opnode GPR:$a, so_reg:$b)]>;
393 /// AI_unary_rrot - A unary operation with two forms: one whose operand is a
394 /// register and one whose operand is a register rotated by 8/16/24.
395 /// FIXME: Remove the 'r' variant. Its rot_imm is zero.
396 multiclass AI_unary_rrot<bits<8> opcod, string opc, PatFrag opnode> {
397 def r : AExtI<opcod, (outs GPR:$dst), (ins GPR:$Src),
399 [(set GPR:$dst, (opnode GPR:$Src))]>,
400 Requires<[IsARM, HasV6]> {
401 let Inst{19-16} = 0b1111;
403 def r_rot : AExtI<opcod, (outs GPR:$dst), (ins GPR:$Src, i32imm:$rot),
404 opc, " $dst, $Src, ror $rot",
405 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>,
406 Requires<[IsARM, HasV6]> {
407 let Inst{19-16} = 0b1111;
411 /// AI_bin_rrot - A binary operation with two forms: one whose operand is a
412 /// register and one whose operand is a register rotated by 8/16/24.
413 multiclass AI_bin_rrot<bits<8> opcod, string opc, PatFrag opnode> {
414 def rr : AExtI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
415 opc, " $dst, $LHS, $RHS",
416 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
417 Requires<[IsARM, HasV6]>;
418 def rr_rot : AExtI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
419 opc, " $dst, $LHS, $RHS, ror $rot",
420 [(set GPR:$dst, (opnode GPR:$LHS,
421 (rotr GPR:$RHS, rot_imm:$rot)))]>,
422 Requires<[IsARM, HasV6]>;
425 /// AsXI1_bin_c_irs - Same as AsI1_bin_irs but without the predicate operand and
426 /// setting carry bit. But it can optionally set CPSR.
427 let Uses = [CPSR] in {
428 multiclass AsXI1_bin_c_irs<bits<4> opcod, string opc, PatFrag opnode> {
429 def ri : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
430 DPFrm, !strconcat(opc, "${s} $dst, $a, $b"),
431 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
432 def rr : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b, cc_out:$s),
433 DPFrm, !strconcat(opc, "${s} $dst, $a, $b"),
434 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
435 def rs : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
436 DPSoRegFrm, !strconcat(opc, "${s} $dst, $a, $b"),
437 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
441 //===----------------------------------------------------------------------===//
443 //===----------------------------------------------------------------------===//
445 //===----------------------------------------------------------------------===//
446 // Miscellaneous Instructions.
449 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
450 /// the function. The first operand is the ID# for this instruction, the second
451 /// is the index into the MachineConstantPool that this is, the third is the
452 /// size in bytes of this constant pool entry.
453 let isNotDuplicable = 1 in
454 def CONSTPOOL_ENTRY :
455 PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
457 "${instid:label} ${cpidx:cpentry}", []>;
459 let Defs = [SP], Uses = [SP] in {
461 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p),
462 "@ ADJCALLSTACKUP $amt1",
463 [(ARMcallseq_end timm:$amt1, timm:$amt2)]>;
465 def ADJCALLSTACKDOWN :
466 PseudoInst<(outs), (ins i32imm:$amt, pred:$p),
467 "@ ADJCALLSTACKDOWN $amt",
468 [(ARMcallseq_start timm:$amt)]>;
472 PseudoInst<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
473 ".loc $file, $line, $col",
474 [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
477 // Address computation and loads and stores in PIC mode.
478 let isNotDuplicable = 1 in {
479 def PICADD : AXI1<0b0100, (outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
480 Pseudo, "$cp:\n\tadd$p $dst, pc, $a",
481 [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
483 let AddedComplexity = 10 in {
484 let canFoldAsLoad = 1 in
485 def PICLDR : AXI2ldw<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
486 Pseudo, "${addr:label}:\n\tldr$p $dst, $addr",
487 [(set GPR:$dst, (load addrmodepc:$addr))]>;
489 def PICLDRH : AXI3ldh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
490 Pseudo, "${addr:label}:\n\tldr${p}h $dst, $addr",
491 [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
493 def PICLDRB : AXI2ldb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
494 Pseudo, "${addr:label}:\n\tldr${p}b $dst, $addr",
495 [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
497 def PICLDRSH : AXI3ldsh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
498 Pseudo, "${addr:label}:\n\tldr${p}sh $dst, $addr",
499 [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
501 def PICLDRSB : AXI3ldsb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
502 Pseudo, "${addr:label}:\n\tldr${p}sb $dst, $addr",
503 [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
505 let AddedComplexity = 10 in {
506 def PICSTR : AXI2stw<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
507 Pseudo, "${addr:label}:\n\tstr$p $src, $addr",
508 [(store GPR:$src, addrmodepc:$addr)]>;
510 def PICSTRH : AXI3sth<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
511 Pseudo, "${addr:label}:\n\tstr${p}h $src, $addr",
512 [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
514 def PICSTRB : AXI2stb<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
515 Pseudo, "${addr:label}:\n\tstr${p}b $src, $addr",
516 [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
518 } // isNotDuplicable = 1
520 //===----------------------------------------------------------------------===//
521 // Control Flow Instructions.
524 let isReturn = 1, isTerminator = 1 in
525 def BX_RET : AI<(outs), (ins), BrMiscFrm, "bx", " lr", [(ARMretflag)]> {
526 let Inst{7-4} = 0b0001;
527 let Inst{19-8} = 0b111111111111;
528 let Inst{27-20} = 0b00010010;
531 // FIXME: remove when we have a way to marking a MI with these properties.
532 // FIXME: $dst1 should be a def. But the extra ops must be in the end of the
534 // FIXME: Should pc be an implicit operand like PICADD, etc?
535 let isReturn = 1, isTerminator = 1 in
536 def LDM_RET : AXI4ld<(outs),
537 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
538 LdStMulFrm, "ldm${p}${addr:submode} $addr, $dst1",
542 Defs = [R0, R1, R2, R3, R12, LR,
543 D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
544 def BL : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
546 [(ARMcall tglobaladdr:$func)]>;
548 def BL_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
549 "bl", " ${func:call}",
550 [(ARMcall_pred tglobaladdr:$func)]>;
553 def BLX : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
555 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T]> {
556 let Inst{7-4} = 0b0011;
557 let Inst{19-8} = 0b111111111111;
558 let Inst{27-20} = 0b00010010;
563 def BX : ABXIx2<(outs), (ins GPR:$func, variable_ops),
564 "mov lr, pc\n\tbx $func",
565 [(ARMcall_nolink GPR:$func)]>;
569 let isBranch = 1, isTerminator = 1 in {
570 // B is "predicable" since it can be xformed into a Bcc.
571 let isBarrier = 1 in {
572 let isPredicable = 1 in
573 def B : ABXI<0b1010, (outs), (ins brtarget:$target), "b $target",
576 let isNotDuplicable = 1, isIndirectBranch = 1 in {
577 def BR_JTr : JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
578 "mov pc, $target \n$jt",
579 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]> {
580 let Inst{20} = 0; // S Bit
581 let Inst{24-21} = 0b1101;
582 let Inst{27-26} = {0,0};
584 def BR_JTm : JTI<(outs),
585 (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
586 "ldr pc, $target \n$jt",
587 [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
589 let Inst{20} = 1; // L bit
590 let Inst{21} = 0; // W bit
591 let Inst{22} = 0; // B bit
592 let Inst{24} = 1; // P bit
593 let Inst{27-26} = {0,1};
595 def BR_JTadd : JTI<(outs),
596 (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
597 "add pc, $target, $idx \n$jt",
598 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
600 let Inst{20} = 0; // S bit
601 let Inst{24-21} = 0b0100;
602 let Inst{27-26} = {0,0};
604 } // isNotDuplicable = 1, isIndirectBranch = 1
607 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
608 // a two-value operand where a dag node expects two operands. :(
609 def Bcc : ABI<0b1010, (outs), (ins brtarget:$target),
611 [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
614 //===----------------------------------------------------------------------===//
615 // Load / store Instructions.
619 let canFoldAsLoad = 1 in
620 def LDR : AI2ldw<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
621 "ldr", " $dst, $addr",
622 [(set GPR:$dst, (load addrmode2:$addr))]>;
624 // Special LDR for loads from non-pc-relative constpools.
625 let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1 in
626 def LDRcp : AI2ldw<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
627 "ldr", " $dst, $addr", []>;
629 // Loads with zero extension
630 def LDRH : AI3ldh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
631 "ldr", "h $dst, $addr",
632 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
634 def LDRB : AI2ldb<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
635 "ldr", "b $dst, $addr",
636 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
638 // Loads with sign extension
639 def LDRSH : AI3ldsh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
640 "ldr", "sh $dst, $addr",
641 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
643 def LDRSB : AI3ldsb<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
644 "ldr", "sb $dst, $addr",
645 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
649 def LDRD : AI3ldd<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
650 "ldr", "d $dst, $addr",
651 []>, Requires<[IsARM, HasV5T]>;
654 def LDR_PRE : AI2ldwpr<(outs GPR:$dst, GPR:$base_wb),
655 (ins addrmode2:$addr), LdFrm,
656 "ldr", " $dst, $addr!", "$addr.base = $base_wb", []>;
658 def LDR_POST : AI2ldwpo<(outs GPR:$dst, GPR:$base_wb),
659 (ins GPR:$base, am2offset:$offset), LdFrm,
660 "ldr", " $dst, [$base], $offset", "$base = $base_wb", []>;
662 def LDRH_PRE : AI3ldhpr<(outs GPR:$dst, GPR:$base_wb),
663 (ins addrmode3:$addr), LdMiscFrm,
664 "ldr", "h $dst, $addr!", "$addr.base = $base_wb", []>;
666 def LDRH_POST : AI3ldhpo<(outs GPR:$dst, GPR:$base_wb),
667 (ins GPR:$base,am3offset:$offset), LdMiscFrm,
668 "ldr", "h $dst, [$base], $offset", "$base = $base_wb", []>;
670 def LDRB_PRE : AI2ldbpr<(outs GPR:$dst, GPR:$base_wb),
671 (ins addrmode2:$addr), LdFrm,
672 "ldr", "b $dst, $addr!", "$addr.base = $base_wb", []>;
674 def LDRB_POST : AI2ldbpo<(outs GPR:$dst, GPR:$base_wb),
675 (ins GPR:$base,am2offset:$offset), LdFrm,
676 "ldr", "b $dst, [$base], $offset", "$base = $base_wb", []>;
678 def LDRSH_PRE : AI3ldshpr<(outs GPR:$dst, GPR:$base_wb),
679 (ins addrmode3:$addr), LdMiscFrm,
680 "ldr", "sh $dst, $addr!", "$addr.base = $base_wb", []>;
682 def LDRSH_POST: AI3ldshpo<(outs GPR:$dst, GPR:$base_wb),
683 (ins GPR:$base,am3offset:$offset), LdMiscFrm,
684 "ldr", "sh $dst, [$base], $offset", "$base = $base_wb", []>;
686 def LDRSB_PRE : AI3ldsbpr<(outs GPR:$dst, GPR:$base_wb),
687 (ins addrmode3:$addr), LdMiscFrm,
688 "ldr", "sb $dst, $addr!", "$addr.base = $base_wb", []>;
690 def LDRSB_POST: AI3ldsbpo<(outs GPR:$dst, GPR:$base_wb),
691 (ins GPR:$base,am3offset:$offset), LdMiscFrm,
692 "ldr", "sb $dst, [$base], $offset", "$base = $base_wb", []>;
696 def STR : AI2stw<(outs), (ins GPR:$src, addrmode2:$addr), StFrm,
697 "str", " $src, $addr",
698 [(store GPR:$src, addrmode2:$addr)]>;
700 // Stores with truncate
701 def STRH : AI3sth<(outs), (ins GPR:$src, addrmode3:$addr), StMiscFrm,
702 "str", "h $src, $addr",
703 [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
705 def STRB : AI2stb<(outs), (ins GPR:$src, addrmode2:$addr), StFrm,
706 "str", "b $src, $addr",
707 [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
711 def STRD : AI3std<(outs), (ins GPR:$src, addrmode3:$addr), StMiscFrm,
712 "str", "d $src, $addr",
713 []>, Requires<[IsARM, HasV5T]>;
716 def STR_PRE : AI2stwpr<(outs GPR:$base_wb),
717 (ins GPR:$src, GPR:$base, am2offset:$offset), StFrm,
718 "str", " $src, [$base, $offset]!", "$base = $base_wb",
720 (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
722 def STR_POST : AI2stwpo<(outs GPR:$base_wb),
723 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
724 "str", " $src, [$base], $offset", "$base = $base_wb",
726 (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
728 def STRH_PRE : AI3sthpr<(outs GPR:$base_wb),
729 (ins GPR:$src, GPR:$base,am3offset:$offset), StMiscFrm,
730 "str", "h $src, [$base, $offset]!", "$base = $base_wb",
732 (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
734 def STRH_POST: AI3sthpo<(outs GPR:$base_wb),
735 (ins GPR:$src, GPR:$base,am3offset:$offset), StMiscFrm,
736 "str", "h $src, [$base], $offset", "$base = $base_wb",
737 [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
738 GPR:$base, am3offset:$offset))]>;
740 def STRB_PRE : AI2stbpr<(outs GPR:$base_wb),
741 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
742 "str", "b $src, [$base, $offset]!", "$base = $base_wb",
743 [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
744 GPR:$base, am2offset:$offset))]>;
746 def STRB_POST: AI2stbpo<(outs GPR:$base_wb),
747 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
748 "str", "b $src, [$base], $offset", "$base = $base_wb",
749 [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
750 GPR:$base, am2offset:$offset))]>;
752 //===----------------------------------------------------------------------===//
753 // Load / store multiple Instructions.
756 // FIXME: $dst1 should be a def.
758 def LDM : AXI4ld<(outs),
759 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
760 LdStMulFrm, "ldm${p}${addr:submode} $addr, $dst1",
764 def STM : AXI4st<(outs),
765 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
766 LdStMulFrm, "stm${p}${addr:submode} $addr, $src1",
769 //===----------------------------------------------------------------------===//
770 // Move Instructions.
773 def MOVr : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), DPFrm,
774 "mov", " $dst, $src", []>, UnaryDP;
775 def MOVs : AsI1<0b1101, (outs GPR:$dst), (ins so_reg:$src), DPSoRegFrm,
776 "mov", " $dst, $src", [(set GPR:$dst, so_reg:$src)]>, UnaryDP;
778 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
779 def MOVi : AsI1<0b1101, (outs GPR:$dst), (ins so_imm:$src), DPFrm,
780 "mov", " $dst, $src", [(set GPR:$dst, so_imm:$src)]>, UnaryDP;
782 def MOVrx : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
783 "mov", " $dst, $src, rrx",
784 [(set GPR:$dst, (ARMrrx GPR:$src))]>, UnaryDP;
786 // These aren't really mov instructions, but we have to define them this way
787 // due to flag operands.
789 let Defs = [CPSR] in {
790 def MOVsrl_flag : AI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
791 "mov", "s $dst, $src, lsr #1",
792 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, UnaryDP;
793 def MOVsra_flag : AI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
794 "mov", "s $dst, $src, asr #1",
795 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, UnaryDP;
798 //===----------------------------------------------------------------------===//
799 // Extend Instructions.
804 defm SXTB : AI_unary_rrot<0b01101010,
805 "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
806 defm SXTH : AI_unary_rrot<0b01101011,
807 "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
809 defm SXTAB : AI_bin_rrot<0b01101010,
810 "sxtab", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
811 defm SXTAH : AI_bin_rrot<0b01101011,
812 "sxtah", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
814 // TODO: SXT(A){B|H}16
818 let AddedComplexity = 16 in {
819 defm UXTB : AI_unary_rrot<0b01101110,
820 "uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
821 defm UXTH : AI_unary_rrot<0b01101111,
822 "uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
823 defm UXTB16 : AI_unary_rrot<0b01101100,
824 "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
826 def : ARMV6Pat<(and (shl GPR:$Src, 8), 0xFF00FF),
827 (UXTB16r_rot GPR:$Src, 24)>;
828 def : ARMV6Pat<(and (srl GPR:$Src, 8), 0xFF00FF),
829 (UXTB16r_rot GPR:$Src, 8)>;
831 defm UXTAB : AI_bin_rrot<0b01101110, "uxtab",
832 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
833 defm UXTAH : AI_bin_rrot<0b01101111, "uxtah",
834 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
837 // This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
838 //defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
840 // TODO: UXT(A){B|H}16
842 //===----------------------------------------------------------------------===//
843 // Arithmetic Instructions.
846 defm ADD : AsI1_bin_irs<0b0100, "add",
847 BinOpFrag<(add node:$LHS, node:$RHS)>>;
848 defm SUB : AsI1_bin_irs<0b0010, "sub",
849 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
851 // ADD and SUB with 's' bit set.
852 defm ADDS : ASI1_bin_s_irs<0b0100, "add",
853 BinOpFrag<(addc node:$LHS, node:$RHS)>>;
854 defm SUBS : ASI1_bin_s_irs<0b0010, "sub",
855 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
857 // FIXME: Do not allow ADC / SBC to be predicated for now.
858 defm ADC : AsXI1_bin_c_irs<0b0101, "adc",
859 BinOpFrag<(adde node:$LHS, node:$RHS)>>;
860 defm SBC : AsXI1_bin_c_irs<0b0110, "sbc",
861 BinOpFrag<(sube node:$LHS, node:$RHS)>>;
863 // These don't define reg/reg forms, because they are handled above.
864 def RSBri : AsI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
865 "rsb", " $dst, $a, $b",
866 [(set GPR:$dst, (sub so_imm:$b, GPR:$a))]>;
868 def RSBrs : AsI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
869 "rsb", " $dst, $a, $b",
870 [(set GPR:$dst, (sub so_reg:$b, GPR:$a))]>;
872 // RSB with 's' bit set.
873 let Defs = [CPSR] in {
874 def RSBSri : AI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
875 "rsb", "s $dst, $a, $b",
876 [(set GPR:$dst, (subc so_imm:$b, GPR:$a))]>;
877 def RSBSrs : AI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
878 "rsb", "s $dst, $a, $b",
879 [(set GPR:$dst, (subc so_reg:$b, GPR:$a))]>;
882 // FIXME: Do not allow RSC to be predicated for now. But they can set CPSR.
883 let Uses = [CPSR] in {
884 def RSCri : AXI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
885 DPFrm, "rsc${s} $dst, $a, $b",
886 [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>;
887 def RSCrs : AXI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
888 DPSoRegFrm, "rsc${s} $dst, $a, $b",
889 [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>;
892 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
893 def : ARMPat<(add GPR:$src, so_imm_neg:$imm),
894 (SUBri GPR:$src, so_imm_neg:$imm)>;
896 //def : ARMPat<(addc GPR:$src, so_imm_neg:$imm),
897 // (SUBSri GPR:$src, so_imm_neg:$imm)>;
898 //def : ARMPat<(adde GPR:$src, so_imm_neg:$imm),
899 // (SBCri GPR:$src, so_imm_neg:$imm)>;
901 // Note: These are implemented in C++ code, because they have to generate
902 // ADD/SUBrs instructions, which use a complex pattern that a xform function
904 // (mul X, 2^n+1) -> (add (X << n), X)
905 // (mul X, 2^n-1) -> (rsb X, (X << n))
908 //===----------------------------------------------------------------------===//
909 // Bitwise Instructions.
912 defm AND : AsI1_bin_irs<0b0000, "and",
913 BinOpFrag<(and node:$LHS, node:$RHS)>>;
914 defm ORR : AsI1_bin_irs<0b1100, "orr",
915 BinOpFrag<(or node:$LHS, node:$RHS)>>;
916 defm EOR : AsI1_bin_irs<0b0001, "eor",
917 BinOpFrag<(xor node:$LHS, node:$RHS)>>;
918 defm BIC : AsI1_bin_irs<0b1110, "bic",
919 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
921 def MVNr : AsI1<0b1111, (outs GPR:$dst), (ins GPR:$src), DPFrm,
922 "mvn", " $dst, $src",
923 [(set GPR:$dst, (not GPR:$src))]>, UnaryDP;
924 def MVNs : AsI1<0b1111, (outs GPR:$dst), (ins so_reg:$src), DPSoRegFrm,
925 "mvn", " $dst, $src",
926 [(set GPR:$dst, (not so_reg:$src))]>, UnaryDP;
927 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
928 def MVNi : AsI1<0b1111, (outs GPR:$dst), (ins so_imm:$imm), DPFrm,
929 "mvn", " $dst, $imm",
930 [(set GPR:$dst, so_imm_not:$imm)]>,UnaryDP;
932 def : ARMPat<(and GPR:$src, so_imm_not:$imm),
933 (BICri GPR:$src, so_imm_not:$imm)>;
935 //===----------------------------------------------------------------------===//
936 // Multiply Instructions.
939 def MUL : AsMul1I<0b0000000, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
940 "mul", " $dst, $a, $b",
941 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
943 def MLA : AsMul1I<0b0000001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
944 "mla", " $dst, $a, $b, $c",
945 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
947 // Extra precision multiplies with low / high results
948 def SMULL : AsMul1I<0b0000110, (outs GPR:$ldst, GPR:$hdst),
949 (ins GPR:$a, GPR:$b),
950 "smull", " $ldst, $hdst, $a, $b", []>;
952 def UMULL : AsMul1I<0b0000100, (outs GPR:$ldst, GPR:$hdst),
953 (ins GPR:$a, GPR:$b),
954 "umull", " $ldst, $hdst, $a, $b", []>;
956 // Multiply + accumulate
957 def SMLAL : AsMul1I<0b0000111, (outs GPR:$ldst, GPR:$hdst),
958 (ins GPR:$a, GPR:$b),
959 "smlal", " $ldst, $hdst, $a, $b", []>;
961 def UMLAL : AsMul1I<0b0000101, (outs GPR:$ldst, GPR:$hdst),
962 (ins GPR:$a, GPR:$b),
963 "umlal", " $ldst, $hdst, $a, $b", []>;
965 def UMAAL : AMul1I <0b0000010, (outs GPR:$ldst, GPR:$hdst),
966 (ins GPR:$a, GPR:$b),
967 "umaal", " $ldst, $hdst, $a, $b", []>,
968 Requires<[IsARM, HasV6]>;
970 // Most significant word multiply
971 def SMMUL : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
972 "smmul", " $dst, $a, $b",
973 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>,
974 Requires<[IsARM, HasV6]> {
975 let Inst{7-4} = 0b0001;
976 let Inst{15-12} = 0b1111;
979 def SMMLA : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
980 "smmla", " $dst, $a, $b, $c",
981 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>,
982 Requires<[IsARM, HasV6]> {
983 let Inst{7-4} = 0b0001;
987 def SMMLS : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
988 "smmls", " $dst, $a, $b, $c",
989 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
990 Requires<[IsARM, HasV6]> {
991 let Inst{7-4} = 0b1101;
994 multiclass AI_smul<string opc, PatFrag opnode> {
995 def BB : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
996 !strconcat(opc, "bb"), " $dst, $a, $b",
997 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
998 (sext_inreg GPR:$b, i16)))]>,
999 Requires<[IsARM, HasV5TE]> {
1004 def BT : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1005 !strconcat(opc, "bt"), " $dst, $a, $b",
1006 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1007 (sra GPR:$b, 16)))]>,
1008 Requires<[IsARM, HasV5TE]> {
1013 def TB : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1014 !strconcat(opc, "tb"), " $dst, $a, $b",
1015 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
1016 (sext_inreg GPR:$b, i16)))]>,
1017 Requires<[IsARM, HasV5TE]> {
1022 def TT : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1023 !strconcat(opc, "tt"), " $dst, $a, $b",
1024 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
1025 (sra GPR:$b, 16)))]>,
1026 Requires<[IsARM, HasV5TE]> {
1031 def WB : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1032 !strconcat(opc, "wb"), " $dst, $a, $b",
1033 [(set GPR:$dst, (sra (opnode GPR:$a,
1034 (sext_inreg GPR:$b, i16)), 16))]>,
1035 Requires<[IsARM, HasV5TE]> {
1040 def WT : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
1041 !strconcat(opc, "wt"), " $dst, $a, $b",
1042 [(set GPR:$dst, (sra (opnode GPR:$a,
1043 (sra GPR:$b, 16)), 16))]>,
1044 Requires<[IsARM, HasV5TE]> {
1051 multiclass AI_smla<string opc, PatFrag opnode> {
1052 def BB : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1053 !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
1054 [(set GPR:$dst, (add GPR:$acc,
1055 (opnode (sext_inreg GPR:$a, i16),
1056 (sext_inreg GPR:$b, i16))))]>,
1057 Requires<[IsARM, HasV5TE]> {
1062 def BT : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1063 !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
1064 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
1065 (sra GPR:$b, 16))))]>,
1066 Requires<[IsARM, HasV5TE]> {
1071 def TB : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1072 !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
1073 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1074 (sext_inreg GPR:$b, i16))))]>,
1075 Requires<[IsARM, HasV5TE]> {
1080 def TT : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1081 !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
1082 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1083 (sra GPR:$b, 16))))]>,
1084 Requires<[IsARM, HasV5TE]> {
1089 def WB : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1090 !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
1091 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1092 (sext_inreg GPR:$b, i16)), 16)))]>,
1093 Requires<[IsARM, HasV5TE]> {
1098 def WT : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
1099 !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
1100 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1101 (sra GPR:$b, 16)), 16)))]>,
1102 Requires<[IsARM, HasV5TE]> {
1108 defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1109 defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1111 // TODO: Halfword multiple accumulate long: SMLAL<x><y>
1112 // TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
1114 //===----------------------------------------------------------------------===//
1115 // Misc. Arithmetic Instructions.
1118 def CLZ : AMiscA1I<0b000010110, (outs GPR:$dst), (ins GPR:$src),
1119 "clz", " $dst, $src",
1120 [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]> {
1121 let Inst{7-4} = 0b0001;
1122 let Inst{11-8} = 0b1111;
1123 let Inst{19-16} = 0b1111;
1126 def REV : AMiscA1I<0b01101011, (outs GPR:$dst), (ins GPR:$src),
1127 "rev", " $dst, $src",
1128 [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]> {
1129 let Inst{7-4} = 0b0011;
1130 let Inst{11-8} = 0b1111;
1131 let Inst{19-16} = 0b1111;
1134 def REV16 : AMiscA1I<0b01101011, (outs GPR:$dst), (ins GPR:$src),
1135 "rev16", " $dst, $src",
1137 (or (and (srl GPR:$src, 8), 0xFF),
1138 (or (and (shl GPR:$src, 8), 0xFF00),
1139 (or (and (srl GPR:$src, 8), 0xFF0000),
1140 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
1141 Requires<[IsARM, HasV6]> {
1142 let Inst{7-4} = 0b1011;
1143 let Inst{11-8} = 0b1111;
1144 let Inst{19-16} = 0b1111;
1147 def REVSH : AMiscA1I<0b01101111, (outs GPR:$dst), (ins GPR:$src),
1148 "revsh", " $dst, $src",
1151 (or (srl (and GPR:$src, 0xFF00), 8),
1152 (shl GPR:$src, 8)), i16))]>,
1153 Requires<[IsARM, HasV6]> {
1154 let Inst{7-4} = 0b1011;
1155 let Inst{11-8} = 0b1111;
1156 let Inst{19-16} = 0b1111;
1159 def PKHBT : AMiscA1I<0b01101000, (outs GPR:$dst),
1160 (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1161 "pkhbt", " $dst, $src1, $src2, LSL $shamt",
1162 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1163 (and (shl GPR:$src2, (i32 imm:$shamt)),
1165 Requires<[IsARM, HasV6]> {
1166 let Inst{6-4} = 0b001;
1169 // Alternate cases for PKHBT where identities eliminate some nodes.
1170 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1171 (PKHBT GPR:$src1, GPR:$src2, 0)>;
1172 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1173 (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
1176 def PKHTB : AMiscA1I<0b01101000, (outs GPR:$dst),
1177 (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1178 "pkhtb", " $dst, $src1, $src2, ASR $shamt",
1179 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1180 (and (sra GPR:$src2, imm16_31:$shamt),
1181 0xFFFF)))]>, Requires<[IsARM, HasV6]> {
1182 let Inst{6-4} = 0b101;
1185 // Alternate cases for PKHTB where identities eliminate some nodes. Note that
1186 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
1187 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, 16)),
1188 (PKHTB GPR:$src1, GPR:$src2, 16)>;
1189 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1190 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1191 (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1193 //===----------------------------------------------------------------------===//
1194 // Comparison Instructions...
1197 defm CMP : AI1_cmp_irs<0b1010, "cmp",
1198 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1199 defm CMN : AI1_cmp_irs<0b1011, "cmn",
1200 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
1202 // Note that TST/TEQ don't set all the same flags that CMP does!
1203 defm TST : AI1_cmp_irs<0b1000, "tst",
1204 BinOpFrag<(ARMcmpNZ (and node:$LHS, node:$RHS), 0)>>;
1205 defm TEQ : AI1_cmp_irs<0b1001, "teq",
1206 BinOpFrag<(ARMcmpNZ (xor node:$LHS, node:$RHS), 0)>>;
1208 defm CMPnz : AI1_cmp_irs<0b1010, "cmp",
1209 BinOpFrag<(ARMcmpNZ node:$LHS, node:$RHS)>>;
1210 defm CMNnz : AI1_cmp_irs<0b1011, "cmn",
1211 BinOpFrag<(ARMcmpNZ node:$LHS,(ineg node:$RHS))>>;
1213 def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1214 (CMNri GPR:$src, so_imm_neg:$imm)>;
1216 def : ARMPat<(ARMcmpNZ GPR:$src, so_imm_neg:$imm),
1217 (CMNri GPR:$src, so_imm_neg:$imm)>;
1220 // Conditional moves
1221 // FIXME: should be able to write a pattern for ARMcmov, but can't use
1222 // a two-value operand where a dag node expects two operands. :(
1223 def MOVCCr : AI1<0b1101, (outs GPR:$dst), (ins GPR:$false, GPR:$true), DPFrm,
1224 "mov", " $dst, $true",
1225 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1226 RegConstraint<"$false = $dst">, UnaryDP;
1228 def MOVCCs : AI1<0b1101, (outs GPR:$dst),
1229 (ins GPR:$false, so_reg:$true), DPSoRegFrm,
1230 "mov", " $dst, $true",
1231 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1232 RegConstraint<"$false = $dst">, UnaryDP;
1234 def MOVCCi : AI1<0b1101, (outs GPR:$dst),
1235 (ins GPR:$false, so_imm:$true), DPFrm,
1236 "mov", " $dst, $true",
1237 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1238 RegConstraint<"$false = $dst">, UnaryDP;
1241 // LEApcrel - Load a pc-relative address into a register without offending the
1243 def LEApcrel : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, pred:$p), Pseudo,
1244 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
1245 "${:private}PCRELL${:uid}+8))\n"),
1246 !strconcat("${:private}PCRELL${:uid}:\n\t",
1247 "add$p $dst, pc, #PCRELV${:uid}")),
1250 def LEApcrelJT : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, i32imm:$id, pred:$p),
1252 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
1253 "${:private}PCRELL${:uid}+8))\n"),
1254 !strconcat("${:private}PCRELL${:uid}:\n\t",
1255 "add$p $dst, pc, #PCRELV${:uid}")),
1258 //===----------------------------------------------------------------------===//
1262 // __aeabi_read_tp preserves the registers r1-r3.
1264 Defs = [R0, R12, LR, CPSR] in {
1265 def TPsoft : ABXI<0b1011, (outs), (ins),
1266 "bl __aeabi_read_tp",
1267 [(set R0, ARMthread_pointer)]>;
1270 //===----------------------------------------------------------------------===//
1271 // SJLJ Exception handling intrinsics
1272 // eh_sjlj_setjmp() is a three instruction sequence to store the return
1273 // address and save #0 in R0 for the non-longjmp case.
1274 // Since by its nature we may be coming from some other function to get
1275 // here, and we're using the stack frame for the containing function to
1276 // save/restore registers, we can't keep anything live in regs across
1277 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
1278 // when we get here from a longjmp(). We force everthing out of registers
1279 // except for our own input by listing the relevant registers in Defs. By
1280 // doing so, we also cause the prologue/epilogue code to actively preserve
1281 // all of the callee-saved resgisters, which is exactly what we want.
1283 [ R0, R1, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR,
1284 D0, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15 ] in {
1285 def Int_eh_sjlj_setjmp : XI<(outs), (ins GPR:$src),
1286 AddrModeNone, SizeSpecial, IndexModeNone, Pseudo,
1287 "add r0, pc, #4\n\t"
1288 "str r0, [$src, #+4]\n\t"
1289 "mov r0, #0 @ eh_setjmp", "",
1290 [(set R0, (ARMeh_sjlj_setjmp GPR:$src))]>;
1293 //===----------------------------------------------------------------------===//
1294 // Non-Instruction Patterns
1297 // ConstantPool, GlobalAddress, and JumpTable
1298 def : ARMPat<(ARMWrapper tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>;
1299 def : ARMPat<(ARMWrapper tconstpool :$dst), (LEApcrel tconstpool :$dst)>;
1300 def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1301 (LEApcrelJT tjumptable:$dst, imm:$id)>;
1303 // Large immediate handling.
1305 // Two piece so_imms.
1306 let isReMaterializable = 1 in
1307 def MOVi2pieces : AI1x2<(outs GPR:$dst), (ins so_imm2part:$src), Pseudo,
1308 "mov", " $dst, $src",
1309 [(set GPR:$dst, so_imm2part:$src)]>;
1311 def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1312 (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1313 (so_imm2part_2 imm:$RHS))>;
1314 def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1315 (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1316 (so_imm2part_2 imm:$RHS))>;
1318 // TODO: add,sub,and, 3-instr forms?
1322 def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>;
1324 // zextload i1 -> zextload i8
1325 def : ARMPat<(zextloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1327 // extload -> zextload
1328 def : ARMPat<(extloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1329 def : ARMPat<(extloadi8 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1330 def : ARMPat<(extloadi16 addrmode3:$addr), (LDRH addrmode3:$addr)>;
1332 def : ARMPat<(extloadi8 addrmodepc:$addr), (PICLDRB addrmodepc:$addr)>;
1333 def : ARMPat<(extloadi16 addrmodepc:$addr), (PICLDRH addrmodepc:$addr)>;
1336 def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra (shl GPR:$b, 16), 16)),
1337 (SMULBB GPR:$a, GPR:$b)>;
1338 def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1339 (SMULBB GPR:$a, GPR:$b)>;
1340 def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16)),
1341 (SMULBT GPR:$a, GPR:$b)>;
1342 def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, 16)),
1343 (SMULBT GPR:$a, GPR:$b)>;
1344 def : ARMV5TEPat<(mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16)),
1345 (SMULTB GPR:$a, GPR:$b)>;
1346 def : ARMV5TEPat<(mul (sra GPR:$a, 16), sext_16_node:$b),
1347 (SMULTB GPR:$a, GPR:$b)>;
1348 def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16),
1349 (SMULWB GPR:$a, GPR:$b)>;
1350 def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), 16),
1351 (SMULWB GPR:$a, GPR:$b)>;
1353 def : ARMV5TEPat<(add GPR:$acc,
1354 (mul (sra (shl GPR:$a, 16), 16),
1355 (sra (shl GPR:$b, 16), 16))),
1356 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1357 def : ARMV5TEPat<(add GPR:$acc,
1358 (mul sext_16_node:$a, sext_16_node:$b)),
1359 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1360 def : ARMV5TEPat<(add GPR:$acc,
1361 (mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16))),
1362 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1363 def : ARMV5TEPat<(add GPR:$acc,
1364 (mul sext_16_node:$a, (sra GPR:$b, 16))),
1365 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1366 def : ARMV5TEPat<(add GPR:$acc,
1367 (mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16))),
1368 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1369 def : ARMV5TEPat<(add GPR:$acc,
1370 (mul (sra GPR:$a, 16), sext_16_node:$b)),
1371 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1372 def : ARMV5TEPat<(add GPR:$acc,
1373 (sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16)),
1374 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1375 def : ARMV5TEPat<(add GPR:$acc,
1376 (sra (mul GPR:$a, sext_16_node:$b), 16)),
1377 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1379 //===----------------------------------------------------------------------===//
1383 include "ARMInstrThumb.td"
1385 //===----------------------------------------------------------------------===//
1386 // Floating Point Support
1389 include "ARMInstrVFP.td"