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, [SDTCisPtrTy<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_ARMBr2JT : SDTypeProfile<0, 4,
38 [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
39 SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
41 def SDT_ARMBCC_i64 : SDTypeProfile<0, 6,
43 SDTCisVT<1, i32>, SDTCisVT<2, i32>,
44 SDTCisVT<3, i32>, SDTCisVT<4, i32>,
45 SDTCisVT<5, OtherVT>]>;
47 def SDT_ARMAnd : SDTypeProfile<1, 2,
48 [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
51 def SDT_ARMCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
53 def SDT_ARMPICAdd : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
54 SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
56 def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
57 def SDT_ARMEH_SJLJ_Setjmp : SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisPtrTy<1>,
59 def SDT_ARMEH_SJLJ_Longjmp: SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisInt<1>]>;
61 def SDT_ARMEH_SJLJ_DispatchSetup: SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
63 def SDT_ARMMEMBARRIER : SDTypeProfile<0, 0, []>;
64 def SDT_ARMSYNCBARRIER : SDTypeProfile<0, 0, []>;
65 def SDT_ARMMEMBARRIERMCR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
66 def SDT_ARMSYNCBARRIERMCR : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
68 def SDT_ARMTCRET : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
70 def SDT_ARMBFI : SDTypeProfile<1, 3, [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
71 SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
74 def ARMWrapper : SDNode<"ARMISD::Wrapper", SDTIntUnaryOp>;
75 def ARMWrapperJT : SDNode<"ARMISD::WrapperJT", SDTIntBinOp>;
77 def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
78 [SDNPHasChain, SDNPOutFlag]>;
79 def ARMcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_ARMCallSeqEnd,
80 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
82 def ARMcall : SDNode<"ARMISD::CALL", SDT_ARMcall,
83 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag,
85 def ARMcall_pred : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
86 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag,
88 def ARMcall_nolink : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
89 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag,
92 def ARMretflag : SDNode<"ARMISD::RET_FLAG", SDTNone,
93 [SDNPHasChain, SDNPOptInFlag]>;
95 def ARMcmov : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
97 def ARMcneg : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
100 def ARMbrcond : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
101 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
103 def ARMbrjt : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
105 def ARMbr2jt : SDNode<"ARMISD::BR2_JT", SDT_ARMBr2JT,
108 def ARMBcci64 : SDNode<"ARMISD::BCC_i64", SDT_ARMBCC_i64,
111 def ARMcmp : SDNode<"ARMISD::CMP", SDT_ARMCmp,
114 def ARMcmpZ : SDNode<"ARMISD::CMPZ", SDT_ARMCmp,
115 [SDNPOutFlag, SDNPCommutative]>;
117 def ARMpic_add : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
119 def ARMsrl_flag : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
120 def ARMsra_flag : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
121 def ARMrrx : SDNode<"ARMISD::RRX" , SDTIntUnaryOp, [SDNPInFlag ]>;
123 def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
124 def ARMeh_sjlj_setjmp: SDNode<"ARMISD::EH_SJLJ_SETJMP",
125 SDT_ARMEH_SJLJ_Setjmp, [SDNPHasChain]>;
126 def ARMeh_sjlj_longjmp: SDNode<"ARMISD::EH_SJLJ_LONGJMP",
127 SDT_ARMEH_SJLJ_Longjmp, [SDNPHasChain]>;
128 def ARMeh_sjlj_dispatchsetup: SDNode<"ARMISD::EH_SJLJ_DISPATCHSETUP",
129 SDT_ARMEH_SJLJ_DispatchSetup, [SDNPHasChain]>;
132 def ARMMemBarrier : SDNode<"ARMISD::MEMBARRIER", SDT_ARMMEMBARRIER,
134 def ARMSyncBarrier : SDNode<"ARMISD::SYNCBARRIER", SDT_ARMMEMBARRIER,
136 def ARMMemBarrierMCR : SDNode<"ARMISD::MEMBARRIER", SDT_ARMMEMBARRIERMCR,
138 def ARMSyncBarrierMCR : SDNode<"ARMISD::SYNCBARRIER", SDT_ARMMEMBARRIERMCR,
141 def ARMrbit : SDNode<"ARMISD::RBIT", SDTIntUnaryOp>;
143 def ARMtcret : SDNode<"ARMISD::TC_RETURN", SDT_ARMTCRET,
144 [SDNPHasChain, SDNPOptInFlag, SDNPVariadic]>;
147 def ARMbfi : SDNode<"ARMISD::BFI", SDT_ARMBFI>;
149 //===----------------------------------------------------------------------===//
150 // ARM Instruction Predicate Definitions.
152 def HasV4T : Predicate<"Subtarget->hasV4TOps()">;
153 def NoV4T : Predicate<"!Subtarget->hasV4TOps()">;
154 def HasV5T : Predicate<"Subtarget->hasV5TOps()">;
155 def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">;
156 def HasV6 : Predicate<"Subtarget->hasV6Ops()">;
157 def HasV6T2 : Predicate<"Subtarget->hasV6T2Ops()">;
158 def NoV6T2 : Predicate<"!Subtarget->hasV6T2Ops()">;
159 def HasV7 : Predicate<"Subtarget->hasV7Ops()">;
160 def NoVFP : Predicate<"!Subtarget->hasVFP2()">;
161 def HasVFP2 : Predicate<"Subtarget->hasVFP2()">;
162 def HasVFP3 : Predicate<"Subtarget->hasVFP3()">;
163 def HasNEON : Predicate<"Subtarget->hasNEON()">;
164 def HasDivide : Predicate<"Subtarget->hasDivide()">;
165 def HasT2ExtractPack : Predicate<"Subtarget->hasT2ExtractPack()">;
166 def HasDB : Predicate<"Subtarget->hasDataBarrier()">;
167 def UseNEONForFP : Predicate<"Subtarget->useNEONForSinglePrecisionFP()">;
168 def DontUseNEONForFP : Predicate<"!Subtarget->useNEONForSinglePrecisionFP()">;
169 def IsThumb : Predicate<"Subtarget->isThumb()">;
170 def IsThumb1Only : Predicate<"Subtarget->isThumb1Only()">;
171 def IsThumb2 : Predicate<"Subtarget->isThumb2()">;
172 def IsARM : Predicate<"!Subtarget->isThumb()">;
173 def IsDarwin : Predicate<"Subtarget->isTargetDarwin()">;
174 def IsNotDarwin : Predicate<"!Subtarget->isTargetDarwin()">;
176 // FIXME: Eventually this will be just "hasV6T2Ops".
177 def UseMovt : Predicate<"Subtarget->useMovt()">;
178 def DontUseMovt : Predicate<"!Subtarget->useMovt()">;
179 def UseVMLx : Predicate<"Subtarget->useVMLx()">;
181 //===----------------------------------------------------------------------===//
182 // ARM Flag Definitions.
184 class RegConstraint<string C> {
185 string Constraints = C;
188 //===----------------------------------------------------------------------===//
189 // ARM specific transformation functions and pattern fragments.
192 // so_imm_neg_XFORM - Return a so_imm value packed into the format described for
193 // so_imm_neg def below.
194 def so_imm_neg_XFORM : SDNodeXForm<imm, [{
195 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
198 // so_imm_not_XFORM - Return a so_imm value packed into the format described for
199 // so_imm_not def below.
200 def so_imm_not_XFORM : SDNodeXForm<imm, [{
201 return CurDAG->getTargetConstant(~(int)N->getZExtValue(), MVT::i32);
204 /// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
205 def imm1_15 : PatLeaf<(i32 imm), [{
206 return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 16;
209 /// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
210 def imm16_31 : PatLeaf<(i32 imm), [{
211 return (int32_t)N->getZExtValue() >= 16 && (int32_t)N->getZExtValue() < 32;
216 return ARM_AM::getSOImmVal(-(int)N->getZExtValue()) != -1;
217 }], so_imm_neg_XFORM>;
221 return ARM_AM::getSOImmVal(~(int)N->getZExtValue()) != -1;
222 }], so_imm_not_XFORM>;
224 // sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
225 def sext_16_node : PatLeaf<(i32 GPR:$a), [{
226 return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
229 /// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
231 def bf_inv_mask_imm : Operand<i32>,
233 return ARM::isBitFieldInvertedMask(N->getZExtValue());
235 string EncoderMethod = "getBitfieldInvertedMaskOpValue";
236 let PrintMethod = "printBitfieldInvMaskImmOperand";
239 /// Split a 32-bit immediate into two 16 bit parts.
240 def hi16 : SDNodeXForm<imm, [{
241 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
244 def lo16AllZero : PatLeaf<(i32 imm), [{
245 // Returns true if all low 16-bits are 0.
246 return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
249 /// imm0_65535 predicate - True if the 32-bit immediate is in the range
251 def imm0_65535 : PatLeaf<(i32 imm), [{
252 return (uint32_t)N->getZExtValue() < 65536;
255 class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
256 class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
258 /// adde and sube predicates - True based on whether the carry flag output
259 /// will be needed or not.
260 def adde_dead_carry :
261 PatFrag<(ops node:$LHS, node:$RHS), (adde node:$LHS, node:$RHS),
262 [{return !N->hasAnyUseOfValue(1);}]>;
263 def sube_dead_carry :
264 PatFrag<(ops node:$LHS, node:$RHS), (sube node:$LHS, node:$RHS),
265 [{return !N->hasAnyUseOfValue(1);}]>;
266 def adde_live_carry :
267 PatFrag<(ops node:$LHS, node:$RHS), (adde node:$LHS, node:$RHS),
268 [{return N->hasAnyUseOfValue(1);}]>;
269 def sube_live_carry :
270 PatFrag<(ops node:$LHS, node:$RHS), (sube node:$LHS, node:$RHS),
271 [{return N->hasAnyUseOfValue(1);}]>;
273 //===----------------------------------------------------------------------===//
274 // Operand Definitions.
278 def brtarget : Operand<OtherVT>;
280 // A list of registers separated by comma. Used by load/store multiple.
281 def reglist : Operand<i32> {
282 let PrintMethod = "printRegisterList";
285 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
286 def cpinst_operand : Operand<i32> {
287 let PrintMethod = "printCPInstOperand";
290 def jtblock_operand : Operand<i32> {
291 let PrintMethod = "printJTBlockOperand";
293 def jt2block_operand : Operand<i32> {
294 let PrintMethod = "printJT2BlockOperand";
298 def pclabel : Operand<i32> {
299 let PrintMethod = "printPCLabel";
302 // rot_imm: An integer that encodes a rotate amount. Must be 8, 16, or 24.
303 def rot_imm : Operand<i32>, PatLeaf<(i32 imm), [{
304 int32_t v = (int32_t)N->getZExtValue();
305 return v == 8 || v == 16 || v == 24; }]> {
306 string EncoderMethod = "getRotImmOpValue";
309 // shift_imm: An integer that encodes a shift amount and the type of shift
310 // (currently either asr or lsl) using the same encoding used for the
311 // immediates in so_reg operands.
312 def shift_imm : Operand<i32> {
313 let PrintMethod = "printShiftImmOperand";
316 // shifter_operand operands: so_reg and so_imm.
317 def so_reg : Operand<i32>, // reg reg imm
318 ComplexPattern<i32, 3, "SelectShifterOperandReg",
319 [shl,srl,sra,rotr]> {
320 string EncoderMethod = "getSORegOpValue";
321 let PrintMethod = "printSORegOperand";
322 let MIOperandInfo = (ops GPR, GPR, i32imm);
325 // so_imm - Match a 32-bit shifter_operand immediate operand, which is an
326 // 8-bit immediate rotated by an arbitrary number of bits. so_imm values are
327 // represented in the imm field in the same 12-bit form that they are encoded
328 // into so_imm instructions: the 8-bit immediate is the least significant bits
329 // [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
330 def so_imm : Operand<i32>, PatLeaf<(imm), [{ return Pred_so_imm(N); }]> {
331 string EncoderMethod = "getSOImmOpValue";
332 let PrintMethod = "printSOImmOperand";
335 // Break so_imm's up into two pieces. This handles immediates with up to 16
336 // bits set in them. This uses so_imm2part to match and so_imm2part_[12] to
337 // get the first/second pieces.
338 def so_imm2part : Operand<i32>,
340 return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
342 let PrintMethod = "printSOImm2PartOperand";
345 def so_imm2part_1 : SDNodeXForm<imm, [{
346 unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getZExtValue());
347 return CurDAG->getTargetConstant(V, MVT::i32);
350 def so_imm2part_2 : SDNodeXForm<imm, [{
351 unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getZExtValue());
352 return CurDAG->getTargetConstant(V, MVT::i32);
355 def so_neg_imm2part : Operand<i32>, PatLeaf<(imm), [{
356 return ARM_AM::isSOImmTwoPartVal(-(int)N->getZExtValue());
358 let PrintMethod = "printSOImm2PartOperand";
361 def so_neg_imm2part_1 : SDNodeXForm<imm, [{
362 unsigned V = ARM_AM::getSOImmTwoPartFirst(-(int)N->getZExtValue());
363 return CurDAG->getTargetConstant(V, MVT::i32);
366 def so_neg_imm2part_2 : SDNodeXForm<imm, [{
367 unsigned V = ARM_AM::getSOImmTwoPartSecond(-(int)N->getZExtValue());
368 return CurDAG->getTargetConstant(V, MVT::i32);
371 /// imm0_31 predicate - True if the 32-bit immediate is in the range [0,31].
372 def imm0_31 : Operand<i32>, PatLeaf<(imm), [{
373 return (int32_t)N->getZExtValue() < 32;
376 /// imm0_31_m1 - Matches and prints like imm0_31, but encodes as 'value - 1'.
377 def imm0_31_m1 : Operand<i32>, PatLeaf<(imm), [{
378 return (int32_t)N->getZExtValue() < 32;
380 string EncoderMethod = "getImmMinusOneOpValue";
383 // Define ARM specific addressing modes.
386 // addrmode_imm12 := reg +/- imm12
388 def addrmode_imm12 : Operand<i32>,
389 ComplexPattern<i32, 2, "SelectAddrModeImm12", []> {
391 string EncoderMethod = "getAddrModeImm12OpValue";
392 let PrintMethod = "printAddrModeImm12Operand";
393 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
395 // ldst_so_reg := reg +/- reg shop imm
397 def ldst_so_reg : Operand<i32>,
398 ComplexPattern<i32, 3, "SelectLdStSOReg", []> {
399 // FIXME: Simplify the printer
400 // FIXME: Add EncoderMethod for this addressing mode
401 let PrintMethod = "printAddrMode2Operand";
402 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
405 // addrmode2 := reg +/- imm12
406 // := reg +/- reg shop imm
408 def addrmode2 : Operand<i32>,
409 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
410 let PrintMethod = "printAddrMode2Operand";
411 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
414 def am2offset : Operand<i32>,
415 ComplexPattern<i32, 2, "SelectAddrMode2Offset",
416 [], [SDNPWantRoot]> {
417 let PrintMethod = "printAddrMode2OffsetOperand";
418 let MIOperandInfo = (ops GPR, i32imm);
421 // addrmode3 := reg +/- reg
422 // addrmode3 := reg +/- imm8
424 def addrmode3 : Operand<i32>,
425 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
426 let PrintMethod = "printAddrMode3Operand";
427 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
430 def am3offset : Operand<i32>,
431 ComplexPattern<i32, 2, "SelectAddrMode3Offset",
432 [], [SDNPWantRoot]> {
433 let PrintMethod = "printAddrMode3OffsetOperand";
434 let MIOperandInfo = (ops GPR, i32imm);
437 // addrmode4 := reg, <mode|W>
439 def addrmode4 : Operand<i32>,
440 ComplexPattern<i32, 2, "SelectAddrMode4", []> {
441 let PrintMethod = "printAddrMode4Operand";
442 let MIOperandInfo = (ops GPR:$addr, i32imm);
445 // addrmode5 := reg +/- imm8*4
447 def addrmode5 : Operand<i32>,
448 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
449 let PrintMethod = "printAddrMode5Operand";
450 let MIOperandInfo = (ops GPR:$base, i32imm);
453 // addrmode6 := reg with optional writeback
455 def addrmode6 : Operand<i32>,
456 ComplexPattern<i32, 2, "SelectAddrMode6", []> {
457 let PrintMethod = "printAddrMode6Operand";
458 let MIOperandInfo = (ops GPR:$addr, i32imm);
461 def am6offset : Operand<i32> {
462 let PrintMethod = "printAddrMode6OffsetOperand";
463 let MIOperandInfo = (ops GPR);
466 // addrmodepc := pc + reg
468 def addrmodepc : Operand<i32>,
469 ComplexPattern<i32, 2, "SelectAddrModePC", []> {
470 let PrintMethod = "printAddrModePCOperand";
471 let MIOperandInfo = (ops GPR, i32imm);
474 def nohash_imm : Operand<i32> {
475 let PrintMethod = "printNoHashImmediate";
478 //===----------------------------------------------------------------------===//
480 include "ARMInstrFormats.td"
482 //===----------------------------------------------------------------------===//
483 // Multiclass helpers...
486 /// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
487 /// binop that produces a value.
488 multiclass AsI1_bin_irs<bits<4> opcod, string opc,
489 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
490 PatFrag opnode, bit Commutable = 0> {
491 // The register-immediate version is re-materializable. This is useful
492 // in particular for taking the address of a local.
493 let isReMaterializable = 1 in {
494 def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
495 iii, opc, "\t$Rd, $Rn, $imm",
496 [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]> {
501 let Inst{15-12} = Rd;
502 let Inst{19-16} = Rn;
503 let Inst{11-0} = imm;
506 def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
507 iir, opc, "\t$Rd, $Rn, $Rm",
508 [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]> {
512 let Inst{11-4} = 0b00000000;
514 let isCommutable = Commutable;
516 let Inst{15-12} = Rd;
517 let Inst{19-16} = Rn;
519 def rs : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_reg:$shift), DPSoRegFrm,
520 iis, opc, "\t$Rd, $Rn, $shift",
521 [(set GPR:$Rd, (opnode GPR:$Rn, so_reg:$shift))]> {
526 let Inst{11-0} = shift;
527 let Inst{15-12} = Rd;
528 let Inst{19-16} = Rn;
532 /// AI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
533 /// instruction modifies the CPSR register.
534 let Defs = [CPSR] in {
535 multiclass AI1_bin_s_irs<bits<4> opcod, string opc,
536 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
537 PatFrag opnode, bit Commutable = 0> {
538 def ri : AI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
539 iii, opc, "\t$Rd, $Rn, $imm",
540 [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]> {
545 let Inst{15-12} = Rd;
546 let Inst{19-16} = Rn;
547 let Inst{11-0} = imm;
550 def rr : AI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
551 iir, opc, "\t$Rd, $Rn, $Rm",
552 [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]> {
556 let Inst{11-4} = 0b00000000;
558 let isCommutable = Commutable;
560 let Inst{15-12} = Rd;
561 let Inst{19-16} = Rn;
564 def rs : AI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_reg:$shift), DPSoRegFrm,
565 iis, opc, "\t$Rd, $Rn, $shift",
566 [(set GPR:$Rd, (opnode GPR:$Rn, so_reg:$shift))]> {
571 let Inst{11-0} = shift;
572 let Inst{15-12} = Rd;
573 let Inst{19-16} = Rn;
579 /// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
580 /// patterns. Similar to AsI1_bin_irs except the instruction does not produce
581 /// a explicit result, only implicitly set CPSR.
582 let isCompare = 1, Defs = [CPSR] in {
583 multiclass AI1_cmp_irs<bits<4> opcod, string opc,
584 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
585 PatFrag opnode, bit Commutable = 0> {
586 def ri : AI1<opcod, (outs), (ins GPR:$Rn, so_imm:$imm), DPFrm, iii,
588 [(opnode GPR:$Rn, so_imm:$imm)]> {
592 let Inst{15-12} = 0b0000;
593 let Inst{19-16} = Rn;
594 let Inst{11-0} = imm;
598 def rr : AI1<opcod, (outs), (ins GPR:$Rn, GPR:$Rm), DPFrm, iir,
600 [(opnode GPR:$Rn, GPR:$Rm)]> {
603 let Inst{11-4} = 0b00000000;
605 let isCommutable = Commutable;
607 let Inst{15-12} = 0b0000;
608 let Inst{19-16} = Rn;
611 def rs : AI1<opcod, (outs), (ins GPR:$Rn, so_reg:$shift), DPSoRegFrm, iis,
612 opc, "\t$Rn, $shift",
613 [(opnode GPR:$Rn, so_reg:$shift)]> {
617 let Inst{11-0} = shift;
618 let Inst{15-12} = 0b0000;
619 let Inst{19-16} = Rn;
625 /// AI_ext_rrot - A unary operation with two forms: one whose operand is a
626 /// register and one whose operand is a register rotated by 8/16/24.
627 /// FIXME: Remove the 'r' variant. Its rot_imm is zero.
628 multiclass AI_ext_rrot<bits<8> opcod, string opc, PatFrag opnode> {
629 def r : AExtI<opcod, (outs GPR:$Rd), (ins GPR:$Rm),
630 IIC_iEXTr, opc, "\t$Rd, $Rm",
631 [(set GPR:$Rd, (opnode GPR:$Rm))]>,
632 Requires<[IsARM, HasV6]> {
635 let Inst{15-12} = Rd;
637 let Inst{11-10} = 0b00;
638 let Inst{19-16} = 0b1111;
640 def r_rot : AExtI<opcod, (outs GPR:$Rd), (ins GPR:$Rm, rot_imm:$rot),
641 IIC_iEXTr, opc, "\t$Rd, $Rm, ror $rot",
642 [(set GPR:$Rd, (opnode (rotr GPR:$Rm, rot_imm:$rot)))]>,
643 Requires<[IsARM, HasV6]> {
647 let Inst{15-12} = Rd;
648 let Inst{11-10} = rot;
650 let Inst{19-16} = 0b1111;
654 multiclass AI_ext_rrot_np<bits<8> opcod, string opc> {
655 def r : AExtI<opcod, (outs GPR:$Rd), (ins GPR:$Rm),
656 IIC_iEXTr, opc, "\t$Rd, $Rm",
657 [/* For disassembly only; pattern left blank */]>,
658 Requires<[IsARM, HasV6]> {
659 let Inst{11-10} = 0b00;
660 let Inst{19-16} = 0b1111;
662 def r_rot : AExtI<opcod, (outs GPR:$Rd), (ins GPR:$Rm, rot_imm:$rot),
663 IIC_iEXTr, opc, "\t$Rd, $Rm, ror $rot",
664 [/* For disassembly only; pattern left blank */]>,
665 Requires<[IsARM, HasV6]> {
667 let Inst{11-10} = rot;
668 let Inst{19-16} = 0b1111;
672 /// AI_exta_rrot - A binary operation with two forms: one whose operand is a
673 /// register and one whose operand is a register rotated by 8/16/24.
674 multiclass AI_exta_rrot<bits<8> opcod, string opc, PatFrag opnode> {
675 def rr : AExtI<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
676 IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm",
677 [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]>,
678 Requires<[IsARM, HasV6]> {
679 let Inst{11-10} = 0b00;
681 def rr_rot : AExtI<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm,
683 IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm, ror $rot",
684 [(set GPR:$Rd, (opnode GPR:$Rn,
685 (rotr GPR:$Rm, rot_imm:$rot)))]>,
686 Requires<[IsARM, HasV6]> {
689 let Inst{19-16} = Rn;
690 let Inst{11-10} = rot;
694 // For disassembly only.
695 multiclass AI_exta_rrot_np<bits<8> opcod, string opc> {
696 def rr : AExtI<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
697 IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm",
698 [/* For disassembly only; pattern left blank */]>,
699 Requires<[IsARM, HasV6]> {
700 let Inst{11-10} = 0b00;
702 def rr_rot : AExtI<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm,
704 IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm, ror $rot",
705 [/* For disassembly only; pattern left blank */]>,
706 Requires<[IsARM, HasV6]> {
709 let Inst{19-16} = Rn;
710 let Inst{11-10} = rot;
714 /// AI1_adde_sube_irs - Define instructions and patterns for adde and sube.
715 let Uses = [CPSR] in {
716 multiclass AI1_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
717 bit Commutable = 0> {
718 def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
719 DPFrm, IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
720 [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]>,
726 let Inst{15-12} = Rd;
727 let Inst{19-16} = Rn;
728 let Inst{11-0} = imm;
730 def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
731 DPFrm, IIC_iALUr, opc, "\t$Rd, $Rn, $Rm",
732 [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]>,
737 let Inst{11-4} = 0b00000000;
739 let isCommutable = Commutable;
741 let Inst{15-12} = Rd;
742 let Inst{19-16} = Rn;
744 def rs : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_reg:$shift),
745 DPSoRegFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
746 [(set GPR:$Rd, (opnode GPR:$Rn, so_reg:$shift))]>,
752 let Inst{11-0} = shift;
753 let Inst{15-12} = Rd;
754 let Inst{19-16} = Rn;
757 // Carry setting variants
758 let Defs = [CPSR] in {
759 multiclass AI1_adde_sube_s_irs<bits<4> opcod, string opc, PatFrag opnode,
760 bit Commutable = 0> {
761 def Sri : AXI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
762 DPFrm, IIC_iALUi, !strconcat(opc, "\t$Rd, $Rn, $imm"),
763 [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]>,
768 let Inst{15-12} = Rd;
769 let Inst{19-16} = Rn;
770 let Inst{11-0} = imm;
774 def Srr : AXI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
775 DPFrm, IIC_iALUr, !strconcat(opc, "\t$Rd, $Rn, $Rm"),
776 [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]>,
781 let Inst{11-4} = 0b00000000;
782 let isCommutable = Commutable;
784 let Inst{15-12} = Rd;
785 let Inst{19-16} = Rn;
789 def Srs : AXI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_reg:$shift),
790 DPSoRegFrm, IIC_iALUsr, !strconcat(opc, "\t$Rd, $Rn, $shift"),
791 [(set GPR:$Rd, (opnode GPR:$Rn, so_reg:$shift))]>,
796 let Inst{11-0} = shift;
797 let Inst{15-12} = Rd;
798 let Inst{19-16} = Rn;
806 let canFoldAsLoad = 1, isReMaterializable = 1 in {
807 multiclass AI_ldr1<bit opc22, string opc, InstrItinClass iii,
808 InstrItinClass iir, PatFrag opnode> {
809 // Note: We use the complex addrmode_imm12 rather than just an input
810 // GPR and a constrained immediate so that we can use this to match
811 // frame index references and avoid matching constant pool references.
812 def i12 : AIldr1<0b010, opc22, (outs GPR:$Rt), (ins addrmode_imm12:$addr),
813 AddrMode_i12, LdFrm, iii, opc, "\t$Rt, $addr",
814 [(set GPR:$Rt, (opnode addrmode_imm12:$addr))]> {
817 let Inst{23} = addr{12}; // U (add = ('U' == 1))
818 let Inst{19-16} = addr{16-13}; // Rn
819 let Inst{15-12} = Rt;
820 let Inst{11-0} = addr{11-0}; // imm12
822 def rs : AIldr1<0b011, opc22, (outs GPR:$Rt), (ins ldst_so_reg:$shift),
823 AddrModeNone, LdFrm, iir, opc, "\t$Rt, $shift",
824 [(set GPR:$Rt, (opnode ldst_so_reg:$shift))]> {
827 let Inst{23} = shift{12}; // U (add = ('U' == 1))
828 let Inst{19-16} = shift{16-13}; // Rn
829 let Inst{11-0} = shift{11-0};
834 //===----------------------------------------------------------------------===//
836 //===----------------------------------------------------------------------===//
838 //===----------------------------------------------------------------------===//
839 // Miscellaneous Instructions.
842 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
843 /// the function. The first operand is the ID# for this instruction, the second
844 /// is the index into the MachineConstantPool that this is, the third is the
845 /// size in bytes of this constant pool entry.
846 let neverHasSideEffects = 1, isNotDuplicable = 1 in
847 def CONSTPOOL_ENTRY :
848 PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
849 i32imm:$size), NoItinerary, "", []>;
851 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
852 // from removing one half of the matched pairs. That breaks PEI, which assumes
853 // these will always be in pairs, and asserts if it finds otherwise. Better way?
854 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
856 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p), NoItinerary, "",
857 [(ARMcallseq_end timm:$amt1, timm:$amt2)]>;
859 def ADJCALLSTACKDOWN :
860 PseudoInst<(outs), (ins i32imm:$amt, pred:$p), NoItinerary, "",
861 [(ARMcallseq_start timm:$amt)]>;
864 def NOP : AI<(outs), (ins), MiscFrm, NoItinerary, "nop", "",
865 [/* For disassembly only; pattern left blank */]>,
866 Requires<[IsARM, HasV6T2]> {
867 let Inst{27-16} = 0b001100100000;
868 let Inst{15-8} = 0b11110000;
869 let Inst{7-0} = 0b00000000;
872 def YIELD : AI<(outs), (ins), MiscFrm, NoItinerary, "yield", "",
873 [/* For disassembly only; pattern left blank */]>,
874 Requires<[IsARM, HasV6T2]> {
875 let Inst{27-16} = 0b001100100000;
876 let Inst{15-8} = 0b11110000;
877 let Inst{7-0} = 0b00000001;
880 def WFE : AI<(outs), (ins), MiscFrm, NoItinerary, "wfe", "",
881 [/* For disassembly only; pattern left blank */]>,
882 Requires<[IsARM, HasV6T2]> {
883 let Inst{27-16} = 0b001100100000;
884 let Inst{15-8} = 0b11110000;
885 let Inst{7-0} = 0b00000010;
888 def WFI : AI<(outs), (ins), MiscFrm, NoItinerary, "wfi", "",
889 [/* For disassembly only; pattern left blank */]>,
890 Requires<[IsARM, HasV6T2]> {
891 let Inst{27-16} = 0b001100100000;
892 let Inst{15-8} = 0b11110000;
893 let Inst{7-0} = 0b00000011;
896 def SEL : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm, NoItinerary, "sel",
898 [/* For disassembly only; pattern left blank */]>,
899 Requires<[IsARM, HasV6]> {
904 let Inst{15-12} = Rd;
905 let Inst{19-16} = Rn;
906 let Inst{27-20} = 0b01101000;
907 let Inst{7-4} = 0b1011;
908 let Inst{11-8} = 0b1111;
911 def SEV : AI<(outs), (ins), MiscFrm, NoItinerary, "sev", "",
912 [/* For disassembly only; pattern left blank */]>,
913 Requires<[IsARM, HasV6T2]> {
914 let Inst{27-16} = 0b001100100000;
915 let Inst{15-8} = 0b11110000;
916 let Inst{7-0} = 0b00000100;
919 // The i32imm operand $val can be used by a debugger to store more information
920 // about the breakpoint.
921 def BKPT : AI<(outs), (ins i32imm:$val), MiscFrm, NoItinerary, "bkpt", "\t$val",
922 [/* For disassembly only; pattern left blank */]>,
925 let Inst{3-0} = val{3-0};
926 let Inst{19-8} = val{15-4};
927 let Inst{27-20} = 0b00010010;
928 let Inst{7-4} = 0b0111;
931 // Change Processor State is a system instruction -- for disassembly only.
932 // The singleton $opt operand contains the following information:
933 // opt{4-0} = mode from Inst{4-0}
934 // opt{5} = changemode from Inst{17}
935 // opt{8-6} = AIF from Inst{8-6}
936 // opt{10-9} = imod from Inst{19-18} with 0b10 as enable and 0b11 as disable
937 // FIXME: Integrated assembler will need these split out.
938 def CPS : AXI<(outs), (ins cps_opt:$opt), MiscFrm, NoItinerary, "cps$opt",
939 [/* For disassembly only; pattern left blank */]>,
941 let Inst{31-28} = 0b1111;
942 let Inst{27-20} = 0b00010000;
947 // Preload signals the memory system of possible future data/instruction access.
948 // These are for disassembly only.
950 // A8.6.117, A8.6.118. Different instructions are generated for #0 and #-0.
951 // The neg_zero operand translates -0 to -1, -1 to -2, ..., etc.
952 multiclass APreLoad<bit data, bit read, string opc> {
954 def i : AXI<(outs), (ins GPR:$base, neg_zero:$imm), MiscFrm, NoItinerary,
955 !strconcat(opc, "\t[$base, $imm]"), []> {
956 let Inst{31-26} = 0b111101;
957 let Inst{25} = 0; // 0 for immediate form
960 let Inst{21-20} = 0b01;
963 def r : AXI<(outs), (ins addrmode2:$addr), MiscFrm, NoItinerary,
964 !strconcat(opc, "\t$addr"), []> {
965 let Inst{31-26} = 0b111101;
966 let Inst{25} = 1; // 1 for register form
969 let Inst{21-20} = 0b01;
974 defm PLD : APreLoad<1, 1, "pld">;
975 defm PLDW : APreLoad<1, 0, "pldw">;
976 defm PLI : APreLoad<0, 1, "pli">;
978 def SETEND : AXI<(outs),(ins setend_op:$end), MiscFrm, NoItinerary,
980 [/* For disassembly only; pattern left blank */]>,
983 let Inst{31-10} = 0b1111000100000001000000;
988 def DBG : AI<(outs), (ins i32imm:$opt), MiscFrm, NoItinerary, "dbg", "\t$opt",
989 [/* For disassembly only; pattern left blank */]>,
990 Requires<[IsARM, HasV7]> {
992 let Inst{27-4} = 0b001100100000111100001111;
996 // A5.4 Permanently UNDEFINED instructions.
997 let isBarrier = 1, isTerminator = 1 in
998 def TRAP : AXI<(outs), (ins), MiscFrm, NoItinerary,
1001 let Inst{27-25} = 0b011;
1002 let Inst{24-20} = 0b11111;
1003 let Inst{7-5} = 0b111;
1007 // Address computation and loads and stores in PIC mode.
1008 // FIXME: These PIC insn patterns are pseudos, but derive from the normal insn
1009 // classes (AXI1, et.al.) and so have encoding information and such,
1010 // which is suboptimal. Once the rest of the code emitter (including
1011 // JIT) is MC-ized we should look at refactoring these into true
1013 let isNotDuplicable = 1 in {
1014 def PICADD : AXI1<0b0100, (outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
1015 Pseudo, IIC_iALUr, "",
1016 [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
1018 let AddedComplexity = 10 in {
1019 def PICLDR : AXI2ldw<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
1020 Pseudo, IIC_iLoad_r, "",
1021 [(set GPR:$dst, (load addrmodepc:$addr))]>;
1023 def PICLDRH : AXI3ldh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
1024 Pseudo, IIC_iLoad_bh_r, "",
1025 [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
1027 def PICLDRB : AXI2ldb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
1028 Pseudo, IIC_iLoad_bh_r, "",
1029 [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
1031 def PICLDRSH : AXI3ldsh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
1032 Pseudo, IIC_iLoad_bh_r, "",
1033 [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
1035 def PICLDRSB : AXI3ldsb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
1036 Pseudo, IIC_iLoad_bh_r, "",
1037 [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
1039 let AddedComplexity = 10 in {
1040 def PICSTR : AXI2stw<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1041 Pseudo, IIC_iStore_r, "",
1042 [(store GPR:$src, addrmodepc:$addr)]>;
1044 def PICSTRH : AXI3sth<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1045 Pseudo, IIC_iStore_bh_r, "",
1046 [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
1048 def PICSTRB : AXI2stb<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1049 Pseudo, IIC_iStore_bh_r, "",
1050 [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
1052 } // isNotDuplicable = 1
1055 // LEApcrel - Load a pc-relative address into a register without offending the
1057 // FIXME: These are marked as pseudos, but they're really not(?). They're just
1058 // the ADR instruction. Is this the right way to handle that? They need
1059 // encoding information regardless.
1060 let neverHasSideEffects = 1 in {
1061 let isReMaterializable = 1 in
1062 def LEApcrel : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, pred:$p),
1064 "adr$p\t$dst, #$label", []>;
1066 } // neverHasSideEffects
1067 def LEApcrelJT : AXI1<0x0, (outs GPR:$dst),
1068 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1070 "adr$p\t$dst, #${label}_${id}", []> {
1074 //===----------------------------------------------------------------------===//
1075 // Control Flow Instructions.
1078 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
1080 def BX_RET : AI<(outs), (ins), BrMiscFrm, IIC_Br,
1081 "bx", "\tlr", [(ARMretflag)]>,
1082 Requires<[IsARM, HasV4T]> {
1083 let Inst{27-0} = 0b0001001011111111111100011110;
1087 def MOVPCLR : AI<(outs), (ins), BrMiscFrm, IIC_Br,
1088 "mov", "\tpc, lr", [(ARMretflag)]>,
1089 Requires<[IsARM, NoV4T]> {
1090 let Inst{27-0} = 0b0001101000001111000000001110;
1094 // Indirect branches
1095 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1097 def BRIND : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "bx\t$dst",
1098 [(brind GPR:$dst)]>,
1099 Requires<[IsARM, HasV4T]> {
1101 let Inst{31-4} = 0b1110000100101111111111110001;
1102 let Inst{3-0} = dst;
1106 def MOVPCRX : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "mov\tpc, $dst",
1107 [(brind GPR:$dst)]>,
1108 Requires<[IsARM, NoV4T]> {
1110 let Inst{31-4} = 0b1110000110100000111100000000;
1111 let Inst{3-0} = dst;
1115 // FIXME: remove when we have a way to marking a MI with these properties.
1116 // FIXME: Should pc be an implicit operand like PICADD, etc?
1117 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1118 hasExtraDefRegAllocReq = 1 in
1119 def LDM_RET : AXI4ld<(outs GPR:$wb), (ins addrmode4:$addr, pred:$p,
1120 reglist:$dsts, variable_ops),
1121 IndexModeUpd, LdStMulFrm, IIC_iLoad_mBr,
1122 "ldm${addr:submode}${p}\t$addr!, $dsts",
1123 "$addr.addr = $wb", []>;
1125 // On non-Darwin platforms R9 is callee-saved.
1127 Defs = [R0, R1, R2, R3, R12, LR,
1128 D0, D1, D2, D3, D4, D5, D6, D7,
1129 D16, D17, D18, D19, D20, D21, D22, D23,
1130 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
1131 def BL : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
1132 IIC_Br, "bl\t$func",
1133 [(ARMcall tglobaladdr:$func)]>,
1134 Requires<[IsARM, IsNotDarwin]> {
1135 let Inst{31-28} = 0b1110;
1136 // FIXME: Encoding info for $func. Needs fixups bits.
1139 def BL_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
1140 IIC_Br, "bl", "\t$func",
1141 [(ARMcall_pred tglobaladdr:$func)]>,
1142 Requires<[IsARM, IsNotDarwin]>;
1145 def BLX : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
1146 IIC_Br, "blx\t$func",
1147 [(ARMcall GPR:$func)]>,
1148 Requires<[IsARM, HasV5T, IsNotDarwin]> {
1150 let Inst{27-4} = 0b000100101111111111110011;
1151 let Inst{3-0} = func;
1155 // Note: Restrict $func to the tGPR regclass to prevent it being in LR.
1156 def BX : ABXIx2<(outs), (ins tGPR:$func, variable_ops),
1157 IIC_Br, "mov\tlr, pc\n\tbx\t$func",
1158 [(ARMcall_nolink tGPR:$func)]>,
1159 Requires<[IsARM, HasV4T, IsNotDarwin]> {
1161 let Inst{27-4} = 0b000100101111111111110001;
1162 let Inst{3-0} = func;
1166 def BMOVPCRX : ABXIx2<(outs), (ins tGPR:$func, variable_ops),
1167 IIC_Br, "mov\tlr, pc\n\tmov\tpc, $func",
1168 [(ARMcall_nolink tGPR:$func)]>,
1169 Requires<[IsARM, NoV4T, IsNotDarwin]> {
1171 let Inst{27-4} = 0b000110100000111100000000;
1172 let Inst{3-0} = func;
1176 // On Darwin R9 is call-clobbered.
1178 Defs = [R0, R1, R2, R3, R9, R12, LR,
1179 D0, D1, D2, D3, D4, D5, D6, D7,
1180 D16, D17, D18, D19, D20, D21, D22, D23,
1181 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
1182 def BLr9 : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
1183 IIC_Br, "bl\t$func",
1184 [(ARMcall tglobaladdr:$func)]>, Requires<[IsARM, IsDarwin]> {
1185 let Inst{31-28} = 0b1110;
1186 // FIXME: Encoding info for $func. Needs fixups bits.
1189 def BLr9_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
1190 IIC_Br, "bl", "\t$func",
1191 [(ARMcall_pred tglobaladdr:$func)]>,
1192 Requires<[IsARM, IsDarwin]>;
1195 def BLXr9 : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
1196 IIC_Br, "blx\t$func",
1197 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T, IsDarwin]> {
1199 let Inst{27-4} = 0b000100101111111111110011;
1200 let Inst{3-0} = func;
1204 // Note: Restrict $func to the tGPR regclass to prevent it being in LR.
1205 def BXr9 : ABXIx2<(outs), (ins tGPR:$func, variable_ops),
1206 IIC_Br, "mov\tlr, pc\n\tbx\t$func",
1207 [(ARMcall_nolink tGPR:$func)]>,
1208 Requires<[IsARM, HasV4T, IsDarwin]> {
1210 let Inst{27-4} = 0b000100101111111111110001;
1211 let Inst{3-0} = func;
1215 def BMOVPCRXr9 : ABXIx2<(outs), (ins tGPR:$func, variable_ops),
1216 IIC_Br, "mov\tlr, pc\n\tmov\tpc, $func",
1217 [(ARMcall_nolink tGPR:$func)]>,
1218 Requires<[IsARM, NoV4T, IsDarwin]> {
1220 let Inst{27-4} = 0b000110100000111100000000;
1221 let Inst{3-0} = func;
1227 // FIXME: These should probably be xformed into the non-TC versions of the
1228 // instructions as part of MC lowering.
1229 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
1231 let Defs = [R0, R1, R2, R3, R9, R12,
1232 D0, D1, D2, D3, D4, D5, D6, D7,
1233 D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26,
1234 D27, D28, D29, D30, D31, PC],
1236 def TCRETURNdi : AInoP<(outs), (ins i32imm:$dst, variable_ops),
1238 "@TC_RETURN","\t$dst", []>, Requires<[IsDarwin]>;
1240 def TCRETURNri : AInoP<(outs), (ins tcGPR:$dst, variable_ops),
1242 "@TC_RETURN","\t$dst", []>, Requires<[IsDarwin]>;
1244 def TAILJMPd : ABXI<0b1010, (outs), (ins brtarget:$dst, variable_ops),
1245 IIC_Br, "b\t$dst @ TAILCALL",
1246 []>, Requires<[IsDarwin]>;
1248 def TAILJMPdt: ABXI<0b1010, (outs), (ins brtarget:$dst, variable_ops),
1249 IIC_Br, "b.w\t$dst @ TAILCALL",
1250 []>, Requires<[IsDarwin]>;
1252 def TAILJMPr : AXI<(outs), (ins tcGPR:$dst, variable_ops),
1253 BrMiscFrm, IIC_Br, "bx\t$dst @ TAILCALL",
1254 []>, Requires<[IsDarwin]> {
1256 let Inst{31-4} = 0b1110000100101111111111110001;
1257 let Inst{3-0} = dst;
1261 // Non-Darwin versions (the difference is R9).
1262 let Defs = [R0, R1, R2, R3, R12,
1263 D0, D1, D2, D3, D4, D5, D6, D7,
1264 D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26,
1265 D27, D28, D29, D30, D31, PC],
1267 def TCRETURNdiND : AInoP<(outs), (ins i32imm:$dst, variable_ops),
1269 "@TC_RETURN","\t$dst", []>, Requires<[IsNotDarwin]>;
1271 def TCRETURNriND : AInoP<(outs), (ins tcGPR:$dst, variable_ops),
1273 "@TC_RETURN","\t$dst", []>, Requires<[IsNotDarwin]>;
1275 def TAILJMPdND : ABXI<0b1010, (outs), (ins brtarget:$dst, variable_ops),
1276 IIC_Br, "b\t$dst @ TAILCALL",
1277 []>, Requires<[IsARM, IsNotDarwin]>;
1279 def TAILJMPdNDt : ABXI<0b1010, (outs), (ins brtarget:$dst, variable_ops),
1280 IIC_Br, "b.w\t$dst @ TAILCALL",
1281 []>, Requires<[IsThumb, IsNotDarwin]>;
1283 def TAILJMPrND : AXI<(outs), (ins tcGPR:$dst, variable_ops),
1284 BrMiscFrm, IIC_Br, "bx\t$dst @ TAILCALL",
1285 []>, Requires<[IsNotDarwin]> {
1287 let Inst{31-4} = 0b1110000100101111111111110001;
1288 let Inst{3-0} = dst;
1293 let isBranch = 1, isTerminator = 1 in {
1294 // B is "predicable" since it can be xformed into a Bcc.
1295 let isBarrier = 1 in {
1296 let isPredicable = 1 in
1297 def B : ABXI<0b1010, (outs), (ins brtarget:$target), IIC_Br,
1298 "b\t$target", [(br bb:$target)]>;
1300 let isNotDuplicable = 1, isIndirectBranch = 1 in {
1301 def BR_JTr : JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
1302 IIC_Br, "mov\tpc, $target$jt",
1303 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]> {
1304 let Inst{11-4} = 0b00000000;
1305 let Inst{15-12} = 0b1111;
1306 let Inst{20} = 0; // S Bit
1307 let Inst{24-21} = 0b1101;
1308 let Inst{27-25} = 0b000;
1310 def BR_JTm : JTI<(outs),
1311 (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
1312 IIC_Br, "ldr\tpc, $target$jt",
1313 [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
1315 let Inst{15-12} = 0b1111;
1316 let Inst{20} = 1; // L bit
1317 let Inst{21} = 0; // W bit
1318 let Inst{22} = 0; // B bit
1319 let Inst{24} = 1; // P bit
1320 let Inst{27-25} = 0b011;
1322 def BR_JTadd : JTI<(outs),
1323 (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
1324 IIC_Br, "add\tpc, $target, $idx$jt",
1325 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
1327 let Inst{15-12} = 0b1111;
1328 let Inst{20} = 0; // S bit
1329 let Inst{24-21} = 0b0100;
1330 let Inst{27-25} = 0b000;
1332 } // isNotDuplicable = 1, isIndirectBranch = 1
1335 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
1336 // a two-value operand where a dag node expects two operands. :(
1337 def Bcc : ABI<0b1010, (outs), (ins brtarget:$target),
1338 IIC_Br, "b", "\t$target",
1339 [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
1342 // Branch and Exchange Jazelle -- for disassembly only
1343 def BXJ : ABI<0b0001, (outs), (ins GPR:$func), NoItinerary, "bxj", "\t$func",
1344 [/* For disassembly only; pattern left blank */]> {
1345 let Inst{23-20} = 0b0010;
1346 //let Inst{19-8} = 0xfff;
1347 let Inst{7-4} = 0b0010;
1350 // Secure Monitor Call is a system instruction -- for disassembly only
1351 def SMC : ABI<0b0001, (outs), (ins i32imm:$opt), NoItinerary, "smc", "\t$opt",
1352 [/* For disassembly only; pattern left blank */]> {
1354 let Inst{23-4} = 0b01100000000000000111;
1355 let Inst{3-0} = opt;
1358 // Supervisor Call (Software Interrupt) -- for disassembly only
1360 def SVC : ABI<0b1111, (outs), (ins i32imm:$svc), IIC_Br, "svc", "\t$svc",
1361 [/* For disassembly only; pattern left blank */]> {
1363 let Inst{23-0} = svc;
1367 // Store Return State is a system instruction -- for disassembly only
1368 def SRSW : ABXI<{1,0,0,?}, (outs), (ins addrmode4:$addr, i32imm:$mode),
1369 NoItinerary, "srs${addr:submode}\tsp!, $mode",
1370 [/* For disassembly only; pattern left blank */]> {
1371 let Inst{31-28} = 0b1111;
1372 let Inst{22-20} = 0b110; // W = 1
1375 def SRS : ABXI<{1,0,0,?}, (outs), (ins addrmode4:$addr, i32imm:$mode),
1376 NoItinerary, "srs${addr:submode}\tsp, $mode",
1377 [/* For disassembly only; pattern left blank */]> {
1378 let Inst{31-28} = 0b1111;
1379 let Inst{22-20} = 0b100; // W = 0
1382 // Return From Exception is a system instruction -- for disassembly only
1383 def RFEW : ABXI<{1,0,0,?}, (outs), (ins addrmode4:$addr, GPR:$base),
1384 NoItinerary, "rfe${addr:submode}\t$base!",
1385 [/* For disassembly only; pattern left blank */]> {
1386 let Inst{31-28} = 0b1111;
1387 let Inst{22-20} = 0b011; // W = 1
1390 def RFE : ABXI<{1,0,0,?}, (outs), (ins addrmode4:$addr, GPR:$base),
1391 NoItinerary, "rfe${addr:submode}\t$base",
1392 [/* For disassembly only; pattern left blank */]> {
1393 let Inst{31-28} = 0b1111;
1394 let Inst{22-20} = 0b001; // W = 0
1397 //===----------------------------------------------------------------------===//
1398 // Load / store Instructions.
1404 defm LDR : AI_ldr1<0, "ldr", IIC_iLoad_i, IIC_iLoad_r,
1405 UnOpFrag<(load node:$Src)>>;
1406 defm LDRB : AI_ldr1<1, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_r,
1407 UnOpFrag<(zextloadi8 node:$Src)>>;
1409 // Special LDR for loads from non-pc-relative constpools.
1410 let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
1411 isReMaterializable = 1 in
1412 def LDRcp : AIldr1<0b010, 0, (outs GPR:$Rt), (ins addrmode_imm12:$addr),
1413 AddrMode_i12, LdFrm, IIC_iLoad_r, "ldr", "\t$Rt, $addr", []> {
1416 let Inst{23} = addr{12}; // U (add = ('U' == 1))
1417 let Inst{19-16} = 0b1111;
1418 let Inst{15-12} = Rt;
1419 let Inst{11-0} = addr{11-0}; // imm12
1422 // Loads with zero extension
1423 def LDRH : AI3ldh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
1424 IIC_iLoad_bh_r, "ldrh", "\t$dst, $addr",
1425 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
1427 // Loads with sign extension
1428 def LDRSH : AI3ldsh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
1429 IIC_iLoad_bh_r, "ldrsh", "\t$dst, $addr",
1430 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
1432 def LDRSB : AI3ldsb<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
1433 IIC_iLoad_bh_r, "ldrsb", "\t$dst, $addr",
1434 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
1436 let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
1438 def LDRD : AI3ldd<(outs GPR:$dst1, GPR:$dst2), (ins addrmode3:$addr), LdMiscFrm,
1439 IIC_iLoad_d_r, "ldrd", "\t$dst1, $addr",
1440 []>, Requires<[IsARM, HasV5TE]>;
1443 def LDR_PRE : AI2ldwpr<(outs GPR:$dst, GPR:$base_wb),
1444 (ins addrmode2:$addr), LdFrm, IIC_iLoad_ru,
1445 "ldr", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
1447 def LDR_POST : AI2ldwpo<(outs GPR:$dst, GPR:$base_wb),
1448 (ins GPR:$base, am2offset:$offset), LdFrm, IIC_iLoad_ru,
1449 "ldr", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
1451 def LDRH_PRE : AI3ldhpr<(outs GPR:$dst, GPR:$base_wb),
1452 (ins addrmode3:$addr), LdMiscFrm, IIC_iLoad_bh_ru,
1453 "ldrh", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
1455 def LDRH_POST : AI3ldhpo<(outs GPR:$dst, GPR:$base_wb),
1456 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoad_bh_ru,
1457 "ldrh", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
1459 def LDRB_PRE : AI2ldbpr<(outs GPR:$dst, GPR:$base_wb),
1460 (ins addrmode2:$addr), LdFrm, IIC_iLoad_bh_ru,
1461 "ldrb", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
1463 def LDRB_POST : AI2ldbpo<(outs GPR:$dst, GPR:$base_wb),
1464 (ins GPR:$base,am2offset:$offset), LdFrm, IIC_iLoad_bh_ru,
1465 "ldrb", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
1467 def LDRSH_PRE : AI3ldshpr<(outs GPR:$dst, GPR:$base_wb),
1468 (ins addrmode3:$addr), LdMiscFrm, IIC_iLoad_bh_ru,
1469 "ldrsh", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
1471 def LDRSH_POST: AI3ldshpo<(outs GPR:$dst, GPR:$base_wb),
1472 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoad_bh_ru,
1473 "ldrsh", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
1475 def LDRSB_PRE : AI3ldsbpr<(outs GPR:$dst, GPR:$base_wb),
1476 (ins addrmode3:$addr), LdMiscFrm, IIC_iLoad_bh_ru,
1477 "ldrsb", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
1479 def LDRSB_POST: AI3ldsbpo<(outs GPR:$dst, GPR:$base_wb),
1480 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoad_ru,
1481 "ldrsb", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
1483 // For disassembly only
1484 def LDRD_PRE : AI3lddpr<(outs GPR:$dst1, GPR:$dst2, GPR:$base_wb),
1485 (ins addrmode3:$addr), LdMiscFrm, IIC_iLoad_d_ru,
1486 "ldrd", "\t$dst1, $dst2, $addr!", "$addr.base = $base_wb", []>,
1487 Requires<[IsARM, HasV5TE]>;
1489 // For disassembly only
1490 def LDRD_POST : AI3lddpo<(outs GPR:$dst1, GPR:$dst2, GPR:$base_wb),
1491 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoad_d_ru,
1492 "ldrd", "\t$dst1, $dst2, [$base], $offset", "$base = $base_wb", []>,
1493 Requires<[IsARM, HasV5TE]>;
1495 } // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
1497 // LDRT, LDRBT, LDRSBT, LDRHT, LDRSHT are for disassembly only.
1499 def LDRT : AI2ldwpo<(outs GPR:$dst, GPR:$base_wb),
1500 (ins GPR:$base, am2offset:$offset), LdFrm, IIC_iLoad_ru,
1501 "ldrt", "\t$dst, [$base], $offset", "$base = $base_wb", []> {
1502 let Inst{21} = 1; // overwrite
1505 def LDRBT : AI2ldbpo<(outs GPR:$dst, GPR:$base_wb),
1506 (ins GPR:$base,am2offset:$offset), LdFrm, IIC_iLoad_bh_ru,
1507 "ldrbt", "\t$dst, [$base], $offset", "$base = $base_wb", []> {
1508 let Inst{21} = 1; // overwrite
1511 def LDRSBT : AI3ldsbpo<(outs GPR:$dst, GPR:$base_wb),
1512 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoad_bh_ru,
1513 "ldrsbt", "\t$dst, [$base], $offset", "$base = $base_wb", []> {
1514 let Inst{21} = 1; // overwrite
1517 def LDRHT : AI3ldhpo<(outs GPR:$dst, GPR:$base_wb),
1518 (ins GPR:$base, am3offset:$offset), LdMiscFrm, IIC_iLoad_bh_ru,
1519 "ldrht", "\t$dst, [$base], $offset", "$base = $base_wb", []> {
1520 let Inst{21} = 1; // overwrite
1523 def LDRSHT : AI3ldshpo<(outs GPR:$dst, GPR:$base_wb),
1524 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoad_bh_ru,
1525 "ldrsht", "\t$dst, [$base], $offset", "$base = $base_wb", []> {
1526 let Inst{21} = 1; // overwrite
1530 def STR : AI2stw<(outs), (ins GPR:$src, addrmode2:$addr), StFrm, IIC_iStore_r,
1531 "str", "\t$src, $addr",
1532 [(store GPR:$src, addrmode2:$addr)]>;
1534 // Stores with truncate
1535 def STRH : AI3sth<(outs), (ins GPR:$src, addrmode3:$addr), StMiscFrm,
1536 IIC_iStore_bh_r, "strh", "\t$src, $addr",
1537 [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
1539 def STRB : AI2stb<(outs), (ins GPR:$src, addrmode2:$addr), StFrm,
1540 IIC_iStore_bh_r, "strb", "\t$src, $addr",
1541 [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
1544 let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
1545 def STRD : AI3std<(outs), (ins GPR:$src1, GPR:$src2, addrmode3:$addr),
1546 StMiscFrm, IIC_iStore_d_r,
1547 "strd", "\t$src1, $addr", []>, Requires<[IsARM, HasV5TE]>;
1550 def STR_PRE : AI2stwpr<(outs GPR:$base_wb),
1551 (ins GPR:$src, GPR:$base, am2offset:$offset),
1552 StFrm, IIC_iStore_ru,
1553 "str", "\t$src, [$base, $offset]!", "$base = $base_wb",
1555 (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
1557 def STR_POST : AI2stwpo<(outs GPR:$base_wb),
1558 (ins GPR:$src, GPR:$base,am2offset:$offset),
1559 StFrm, IIC_iStore_ru,
1560 "str", "\t$src, [$base], $offset", "$base = $base_wb",
1562 (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
1564 def STRH_PRE : AI3sthpr<(outs GPR:$base_wb),
1565 (ins GPR:$src, GPR:$base,am3offset:$offset),
1566 StMiscFrm, IIC_iStore_ru,
1567 "strh", "\t$src, [$base, $offset]!", "$base = $base_wb",
1569 (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
1571 def STRH_POST: AI3sthpo<(outs GPR:$base_wb),
1572 (ins GPR:$src, GPR:$base,am3offset:$offset),
1573 StMiscFrm, IIC_iStore_bh_ru,
1574 "strh", "\t$src, [$base], $offset", "$base = $base_wb",
1575 [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
1576 GPR:$base, am3offset:$offset))]>;
1578 def STRB_PRE : AI2stbpr<(outs GPR:$base_wb),
1579 (ins GPR:$src, GPR:$base,am2offset:$offset),
1580 StFrm, IIC_iStore_bh_ru,
1581 "strb", "\t$src, [$base, $offset]!", "$base = $base_wb",
1582 [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
1583 GPR:$base, am2offset:$offset))]>;
1585 def STRB_POST: AI2stbpo<(outs GPR:$base_wb),
1586 (ins GPR:$src, GPR:$base,am2offset:$offset),
1587 StFrm, IIC_iStore_bh_ru,
1588 "strb", "\t$src, [$base], $offset", "$base = $base_wb",
1589 [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
1590 GPR:$base, am2offset:$offset))]>;
1592 // For disassembly only
1593 def STRD_PRE : AI3stdpr<(outs GPR:$base_wb),
1594 (ins GPR:$src1, GPR:$src2, GPR:$base, am3offset:$offset),
1595 StMiscFrm, IIC_iStore_d_ru,
1596 "strd", "\t$src1, $src2, [$base, $offset]!",
1597 "$base = $base_wb", []>;
1599 // For disassembly only
1600 def STRD_POST: AI3stdpo<(outs GPR:$base_wb),
1601 (ins GPR:$src1, GPR:$src2, GPR:$base, am3offset:$offset),
1602 StMiscFrm, IIC_iStore_d_ru,
1603 "strd", "\t$src1, $src2, [$base], $offset",
1604 "$base = $base_wb", []>;
1606 // STRT, STRBT, and STRHT are for disassembly only.
1608 def STRT : AI2stwpo<(outs GPR:$base_wb),
1609 (ins GPR:$src, GPR:$base,am2offset:$offset),
1610 StFrm, IIC_iStore_ru,
1611 "strt", "\t$src, [$base], $offset", "$base = $base_wb",
1612 [/* For disassembly only; pattern left blank */]> {
1613 let Inst{21} = 1; // overwrite
1616 def STRBT : AI2stbpo<(outs GPR:$base_wb),
1617 (ins GPR:$src, GPR:$base,am2offset:$offset),
1618 StFrm, IIC_iStore_bh_ru,
1619 "strbt", "\t$src, [$base], $offset", "$base = $base_wb",
1620 [/* For disassembly only; pattern left blank */]> {
1621 let Inst{21} = 1; // overwrite
1624 def STRHT: AI3sthpo<(outs GPR:$base_wb),
1625 (ins GPR:$src, GPR:$base,am3offset:$offset),
1626 StMiscFrm, IIC_iStore_bh_ru,
1627 "strht", "\t$src, [$base], $offset", "$base = $base_wb",
1628 [/* For disassembly only; pattern left blank */]> {
1629 let Inst{21} = 1; // overwrite
1632 //===----------------------------------------------------------------------===//
1633 // Load / store multiple Instructions.
1636 let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
1637 def LDM : AXI4ld<(outs), (ins addrmode4:$addr, pred:$p,
1638 reglist:$dsts, variable_ops),
1639 IndexModeNone, LdStMulFrm, IIC_iLoad_m,
1640 "ldm${addr:submode}${p}\t$addr, $dsts", "", []>;
1642 def LDM_UPD : AXI4ld<(outs GPR:$wb), (ins addrmode4:$addr, pred:$p,
1643 reglist:$dsts, variable_ops),
1644 IndexModeUpd, LdStMulFrm, IIC_iLoad_mu,
1645 "ldm${addr:submode}${p}\t$addr!, $dsts",
1646 "$addr.addr = $wb", []>;
1647 } // mayLoad, neverHasSideEffects, hasExtraDefRegAllocReq
1649 let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in {
1650 def STM : AXI4st<(outs), (ins addrmode4:$addr, pred:$p,
1651 reglist:$srcs, variable_ops),
1652 IndexModeNone, LdStMulFrm, IIC_iStore_m,
1653 "stm${addr:submode}${p}\t$addr, $srcs", "", []>;
1655 def STM_UPD : AXI4st<(outs GPR:$wb), (ins addrmode4:$addr, pred:$p,
1656 reglist:$srcs, variable_ops),
1657 IndexModeUpd, LdStMulFrm, IIC_iStore_mu,
1658 "stm${addr:submode}${p}\t$addr!, $srcs",
1659 "$addr.addr = $wb", []>;
1660 } // mayStore, neverHasSideEffects, hasExtraSrcRegAllocReq
1662 //===----------------------------------------------------------------------===//
1663 // Move Instructions.
1666 let neverHasSideEffects = 1 in
1667 def MOVr : AsI1<0b1101, (outs GPR:$Rd), (ins GPR:$Rm), DPFrm, IIC_iMOVr,
1668 "mov", "\t$Rd, $Rm", []>, UnaryDP {
1672 let Inst{11-4} = 0b00000000;
1675 let Inst{15-12} = Rd;
1678 // A version for the smaller set of tail call registers.
1679 let neverHasSideEffects = 1 in
1680 def MOVr_TC : AsI1<0b1101, (outs tcGPR:$Rd), (ins tcGPR:$Rm), DPFrm,
1681 IIC_iMOVr, "mov", "\t$Rd, $Rm", []>, UnaryDP {
1685 let Inst{11-4} = 0b00000000;
1688 let Inst{15-12} = Rd;
1691 def MOVs : AsI1<0b1101, (outs GPR:$Rd), (ins so_reg:$src),
1692 DPSoRegFrm, IIC_iMOVsr,
1693 "mov", "\t$Rd, $src", [(set GPR:$Rd, so_reg:$src)]>, UnaryDP {
1696 let Inst{15-12} = Rd;
1697 let Inst{11-0} = src;
1701 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
1702 def MOVi : AsI1<0b1101, (outs GPR:$Rd), (ins so_imm:$imm), DPFrm, IIC_iMOVi,
1703 "mov", "\t$Rd, $imm", [(set GPR:$Rd, so_imm:$imm)]>, UnaryDP {
1707 let Inst{15-12} = Rd;
1708 let Inst{19-16} = 0b0000;
1709 let Inst{11-0} = imm;
1712 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
1713 def MOVi16 : AI1<0b1000, (outs GPR:$Rd), (ins i32imm:$imm),
1715 "movw", "\t$Rd, $imm",
1716 [(set GPR:$Rd, imm0_65535:$imm)]>,
1717 Requires<[IsARM, HasV6T2]>, UnaryDP {
1720 let Inst{15-12} = Rd;
1721 let Inst{11-0} = imm{11-0};
1722 let Inst{19-16} = imm{15-12};
1727 let Constraints = "$src = $Rd" in
1728 def MOVTi16 : AI1<0b1010, (outs GPR:$Rd), (ins GPR:$src, i32imm:$imm),
1730 "movt", "\t$Rd, $imm",
1732 (or (and GPR:$src, 0xffff),
1733 lo16AllZero:$imm))]>, UnaryDP,
1734 Requires<[IsARM, HasV6T2]> {
1737 let Inst{15-12} = Rd;
1738 let Inst{11-0} = imm{11-0};
1739 let Inst{19-16} = imm{15-12};
1744 def : ARMPat<(or GPR:$src, 0xffff0000), (MOVTi16 GPR:$src, 0xffff)>,
1745 Requires<[IsARM, HasV6T2]>;
1747 let Uses = [CPSR] in
1748 def RRX: PseudoInst<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVsi, "",
1749 [(set GPR:$Rd, (ARMrrx GPR:$Rm))]>, UnaryDP,
1752 // These aren't really mov instructions, but we have to define them this way
1753 // due to flag operands.
1755 let Defs = [CPSR] in {
1756 def MOVsrl_flag : PseudoInst<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVsi, "",
1757 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, UnaryDP,
1759 def MOVsra_flag : PseudoInst<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVsi, "",
1760 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, UnaryDP,
1764 //===----------------------------------------------------------------------===//
1765 // Extend Instructions.
1770 defm SXTB : AI_ext_rrot<0b01101010,
1771 "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
1772 defm SXTH : AI_ext_rrot<0b01101011,
1773 "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
1775 defm SXTAB : AI_exta_rrot<0b01101010,
1776 "sxtab", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
1777 defm SXTAH : AI_exta_rrot<0b01101011,
1778 "sxtah", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
1780 // For disassembly only
1781 defm SXTB16 : AI_ext_rrot_np<0b01101000, "sxtb16">;
1783 // For disassembly only
1784 defm SXTAB16 : AI_exta_rrot_np<0b01101000, "sxtab16">;
1788 let AddedComplexity = 16 in {
1789 defm UXTB : AI_ext_rrot<0b01101110,
1790 "uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
1791 defm UXTH : AI_ext_rrot<0b01101111,
1792 "uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1793 defm UXTB16 : AI_ext_rrot<0b01101100,
1794 "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
1796 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1797 // The transformation should probably be done as a combiner action
1798 // instead so we can include a check for masking back in the upper
1799 // eight bits of the source into the lower eight bits of the result.
1800 //def : ARMV6Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
1801 // (UXTB16r_rot GPR:$Src, 24)>;
1802 def : ARMV6Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
1803 (UXTB16r_rot GPR:$Src, 8)>;
1805 defm UXTAB : AI_exta_rrot<0b01101110, "uxtab",
1806 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
1807 defm UXTAH : AI_exta_rrot<0b01101111, "uxtah",
1808 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1811 // This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
1812 // For disassembly only
1813 defm UXTAB16 : AI_exta_rrot_np<0b01101100, "uxtab16">;
1816 def SBFX : I<(outs GPR:$Rd),
1817 (ins GPR:$Rn, imm0_31:$lsb, imm0_31_m1:$width),
1818 AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iUNAsi,
1819 "sbfx", "\t$Rd, $Rn, $lsb, $width", "", []>,
1820 Requires<[IsARM, HasV6T2]> {
1825 let Inst{27-21} = 0b0111101;
1826 let Inst{6-4} = 0b101;
1827 let Inst{20-16} = width;
1828 let Inst{15-12} = Rd;
1829 let Inst{11-7} = lsb;
1833 def UBFX : I<(outs GPR:$Rd),
1834 (ins GPR:$Rn, imm0_31:$lsb, imm0_31_m1:$width),
1835 AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iUNAsi,
1836 "ubfx", "\t$Rd, $Rn, $lsb, $width", "", []>,
1837 Requires<[IsARM, HasV6T2]> {
1842 let Inst{27-21} = 0b0111111;
1843 let Inst{6-4} = 0b101;
1844 let Inst{20-16} = width;
1845 let Inst{15-12} = Rd;
1846 let Inst{11-7} = lsb;
1850 //===----------------------------------------------------------------------===//
1851 // Arithmetic Instructions.
1854 defm ADD : AsI1_bin_irs<0b0100, "add",
1855 IIC_iALUi, IIC_iALUr, IIC_iALUsr,
1856 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
1857 defm SUB : AsI1_bin_irs<0b0010, "sub",
1858 IIC_iALUi, IIC_iALUr, IIC_iALUsr,
1859 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1861 // ADD and SUB with 's' bit set.
1862 defm ADDS : AI1_bin_s_irs<0b0100, "adds",
1863 IIC_iALUi, IIC_iALUr, IIC_iALUsr,
1864 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1865 defm SUBS : AI1_bin_s_irs<0b0010, "subs",
1866 IIC_iALUi, IIC_iALUr, IIC_iALUsr,
1867 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
1869 defm ADC : AI1_adde_sube_irs<0b0101, "adc",
1870 BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>, 1>;
1871 defm SBC : AI1_adde_sube_irs<0b0110, "sbc",
1872 BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>>;
1873 defm ADCS : AI1_adde_sube_s_irs<0b0101, "adcs",
1874 BinOpFrag<(adde_live_carry node:$LHS, node:$RHS)>, 1>;
1875 defm SBCS : AI1_adde_sube_s_irs<0b0110, "sbcs",
1876 BinOpFrag<(sube_live_carry node:$LHS, node:$RHS) >>;
1878 def RSBri : AsI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
1879 IIC_iALUi, "rsb", "\t$Rd, $Rn, $imm",
1880 [(set GPR:$Rd, (sub so_imm:$imm, GPR:$Rn))]> {
1885 let Inst{15-12} = Rd;
1886 let Inst{19-16} = Rn;
1887 let Inst{11-0} = imm;
1890 // The reg/reg form is only defined for the disassembler; for codegen it is
1891 // equivalent to SUBrr.
1892 def RSBrr : AsI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
1893 IIC_iALUr, "rsb", "\t$Rd, $Rn, $Rm",
1894 [/* For disassembly only; pattern left blank */]> {
1898 let Inst{11-4} = 0b00000000;
1901 let Inst{15-12} = Rd;
1902 let Inst{19-16} = Rn;
1905 def RSBrs : AsI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, so_reg:$shift),
1906 DPSoRegFrm, IIC_iALUsr, "rsb", "\t$Rd, $Rn, $shift",
1907 [(set GPR:$Rd, (sub so_reg:$shift, GPR:$Rn))]> {
1912 let Inst{11-0} = shift;
1913 let Inst{15-12} = Rd;
1914 let Inst{19-16} = Rn;
1917 // RSB with 's' bit set.
1918 let Defs = [CPSR] in {
1919 def RSBSri : AI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
1920 IIC_iALUi, "rsbs", "\t$Rd, $Rn, $imm",
1921 [(set GPR:$Rd, (subc so_imm:$imm, GPR:$Rn))]> {
1927 let Inst{15-12} = Rd;
1928 let Inst{19-16} = Rn;
1929 let Inst{11-0} = imm;
1931 def RSBSrs : AI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, so_reg:$shift),
1932 DPSoRegFrm, IIC_iALUsr, "rsbs", "\t$Rd, $Rn, $shift",
1933 [(set GPR:$Rd, (subc so_reg:$shift, GPR:$Rn))]> {
1939 let Inst{11-0} = shift;
1940 let Inst{15-12} = Rd;
1941 let Inst{19-16} = Rn;
1945 let Uses = [CPSR] in {
1946 def RSCri : AsI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
1947 DPFrm, IIC_iALUi, "rsc", "\t$Rd, $Rn, $imm",
1948 [(set GPR:$Rd, (sube_dead_carry so_imm:$imm, GPR:$Rn))]>,
1954 let Inst{15-12} = Rd;
1955 let Inst{19-16} = Rn;
1956 let Inst{11-0} = imm;
1958 // The reg/reg form is only defined for the disassembler; for codegen it is
1959 // equivalent to SUBrr.
1960 def RSCrr : AsI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1961 DPFrm, IIC_iALUr, "rsc", "\t$Rd, $Rn, $Rm",
1962 [/* For disassembly only; pattern left blank */]> {
1966 let Inst{11-4} = 0b00000000;
1969 let Inst{15-12} = Rd;
1970 let Inst{19-16} = Rn;
1972 def RSCrs : AsI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, so_reg:$shift),
1973 DPSoRegFrm, IIC_iALUsr, "rsc", "\t$Rd, $Rn, $shift",
1974 [(set GPR:$Rd, (sube_dead_carry so_reg:$shift, GPR:$Rn))]>,
1980 let Inst{11-0} = shift;
1981 let Inst{15-12} = Rd;
1982 let Inst{19-16} = Rn;
1986 // FIXME: Allow these to be predicated.
1987 let Defs = [CPSR], Uses = [CPSR] in {
1988 def RSCSri : AXI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
1989 DPFrm, IIC_iALUi, "rscs\t$Rd, $Rn, $imm",
1990 [(set GPR:$Rd, (sube_dead_carry so_imm:$imm, GPR:$Rn))]>,
1997 let Inst{15-12} = Rd;
1998 let Inst{19-16} = Rn;
1999 let Inst{11-0} = imm;
2001 def RSCSrs : AXI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, so_reg:$shift),
2002 DPSoRegFrm, IIC_iALUsr, "rscs\t$Rd, $Rn, $shift",
2003 [(set GPR:$Rd, (sube_dead_carry so_reg:$shift, GPR:$Rn))]>,
2010 let Inst{11-0} = shift;
2011 let Inst{15-12} = Rd;
2012 let Inst{19-16} = Rn;
2016 // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
2017 // The assume-no-carry-in form uses the negation of the input since add/sub
2018 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
2019 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
2021 def : ARMPat<(add GPR:$src, so_imm_neg:$imm),
2022 (SUBri GPR:$src, so_imm_neg:$imm)>;
2023 def : ARMPat<(addc GPR:$src, so_imm_neg:$imm),
2024 (SUBSri GPR:$src, so_imm_neg:$imm)>;
2025 // The with-carry-in form matches bitwise not instead of the negation.
2026 // Effectively, the inverse interpretation of the carry flag already accounts
2027 // for part of the negation.
2028 def : ARMPat<(adde GPR:$src, so_imm_not:$imm),
2029 (SBCri GPR:$src, so_imm_not:$imm)>;
2031 // Note: These are implemented in C++ code, because they have to generate
2032 // ADD/SUBrs instructions, which use a complex pattern that a xform function
2034 // (mul X, 2^n+1) -> (add (X << n), X)
2035 // (mul X, 2^n-1) -> (rsb X, (X << n))
2037 // ARM Arithmetic Instruction -- for disassembly only
2038 // GPR:$dst = GPR:$a op GPR:$b
2039 class AAI<bits<8> op27_20, bits<8> op11_4, string opc,
2040 list<dag> pattern = [/* For disassembly only; pattern left blank */]>
2041 : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm, IIC_iALUr,
2042 opc, "\t$Rd, $Rn, $Rm", pattern> {
2046 let Inst{27-20} = op27_20;
2047 let Inst{11-4} = op11_4;
2048 let Inst{19-16} = Rn;
2049 let Inst{15-12} = Rd;
2053 // Saturating add/subtract -- for disassembly only
2055 def QADD : AAI<0b00010000, 0b00000101, "qadd",
2056 [(set GPR:$Rd, (int_arm_qadd GPR:$Rn, GPR:$Rm))]>;
2057 def QSUB : AAI<0b00010010, 0b00000101, "qsub",
2058 [(set GPR:$Rd, (int_arm_qsub GPR:$Rn, GPR:$Rm))]>;
2059 def QDADD : AAI<0b00010100, 0b00000101, "qdadd">;
2060 def QDSUB : AAI<0b00010110, 0b00000101, "qdsub">;
2062 def QADD16 : AAI<0b01100010, 0b11110001, "qadd16">;
2063 def QADD8 : AAI<0b01100010, 0b11111001, "qadd8">;
2064 def QASX : AAI<0b01100010, 0b11110011, "qasx">;
2065 def QSAX : AAI<0b01100010, 0b11110101, "qsax">;
2066 def QSUB16 : AAI<0b01100010, 0b11110111, "qsub16">;
2067 def QSUB8 : AAI<0b01100010, 0b11111111, "qsub8">;
2068 def UQADD16 : AAI<0b01100110, 0b11110001, "uqadd16">;
2069 def UQADD8 : AAI<0b01100110, 0b11111001, "uqadd8">;
2070 def UQASX : AAI<0b01100110, 0b11110011, "uqasx">;
2071 def UQSAX : AAI<0b01100110, 0b11110101, "uqsax">;
2072 def UQSUB16 : AAI<0b01100110, 0b11110111, "uqsub16">;
2073 def UQSUB8 : AAI<0b01100110, 0b11111111, "uqsub8">;
2075 // Signed/Unsigned add/subtract -- for disassembly only
2077 def SASX : AAI<0b01100001, 0b11110011, "sasx">;
2078 def SADD16 : AAI<0b01100001, 0b11110001, "sadd16">;
2079 def SADD8 : AAI<0b01100001, 0b11111001, "sadd8">;
2080 def SSAX : AAI<0b01100001, 0b11110101, "ssax">;
2081 def SSUB16 : AAI<0b01100001, 0b11110111, "ssub16">;
2082 def SSUB8 : AAI<0b01100001, 0b11111111, "ssub8">;
2083 def UASX : AAI<0b01100101, 0b11110011, "uasx">;
2084 def UADD16 : AAI<0b01100101, 0b11110001, "uadd16">;
2085 def UADD8 : AAI<0b01100101, 0b11111001, "uadd8">;
2086 def USAX : AAI<0b01100101, 0b11110101, "usax">;
2087 def USUB16 : AAI<0b01100101, 0b11110111, "usub16">;
2088 def USUB8 : AAI<0b01100101, 0b11111111, "usub8">;
2090 // Signed/Unsigned halving add/subtract -- for disassembly only
2092 def SHASX : AAI<0b01100011, 0b11110011, "shasx">;
2093 def SHADD16 : AAI<0b01100011, 0b11110001, "shadd16">;
2094 def SHADD8 : AAI<0b01100011, 0b11111001, "shadd8">;
2095 def SHSAX : AAI<0b01100011, 0b11110101, "shsax">;
2096 def SHSUB16 : AAI<0b01100011, 0b11110111, "shsub16">;
2097 def SHSUB8 : AAI<0b01100011, 0b11111111, "shsub8">;
2098 def UHASX : AAI<0b01100111, 0b11110011, "uhasx">;
2099 def UHADD16 : AAI<0b01100111, 0b11110001, "uhadd16">;
2100 def UHADD8 : AAI<0b01100111, 0b11111001, "uhadd8">;
2101 def UHSAX : AAI<0b01100111, 0b11110101, "uhsax">;
2102 def UHSUB16 : AAI<0b01100111, 0b11110111, "uhsub16">;
2103 def UHSUB8 : AAI<0b01100111, 0b11111111, "uhsub8">;
2105 // Unsigned Sum of Absolute Differences [and Accumulate] -- for disassembly only
2107 def USAD8 : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2108 MulFrm /* for convenience */, NoItinerary, "usad8",
2109 "\t$Rd, $Rn, $Rm", []>,
2110 Requires<[IsARM, HasV6]> {
2114 let Inst{27-20} = 0b01111000;
2115 let Inst{15-12} = 0b1111;
2116 let Inst{7-4} = 0b0001;
2117 let Inst{19-16} = Rd;
2118 let Inst{11-8} = Rm;
2121 def USADA8 : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2122 MulFrm /* for convenience */, NoItinerary, "usada8",
2123 "\t$Rd, $Rn, $Rm, $Ra", []>,
2124 Requires<[IsARM, HasV6]> {
2129 let Inst{27-20} = 0b01111000;
2130 let Inst{7-4} = 0b0001;
2131 let Inst{19-16} = Rd;
2132 let Inst{15-12} = Ra;
2133 let Inst{11-8} = Rm;
2137 // Signed/Unsigned saturate -- for disassembly only
2139 def SSAT : AI<(outs GPR:$Rd), (ins i32imm:$sat_imm, GPR:$a, shift_imm:$sh),
2140 SatFrm, NoItinerary, "ssat", "\t$Rd, $sat_imm, $a$sh",
2141 [/* For disassembly only; pattern left blank */]> {
2146 let Inst{27-21} = 0b0110101;
2147 let Inst{5-4} = 0b01;
2148 let Inst{20-16} = sat_imm;
2149 let Inst{15-12} = Rd;
2150 let Inst{11-7} = sh{7-3};
2151 let Inst{6} = sh{0};
2155 def SSAT16 : AI<(outs GPR:$Rd), (ins i32imm:$sat_imm, GPR:$Rn), SatFrm,
2156 NoItinerary, "ssat16", "\t$Rd, $sat_imm, $Rn",
2157 [/* For disassembly only; pattern left blank */]> {
2161 let Inst{27-20} = 0b01101010;
2162 let Inst{11-4} = 0b11110011;
2163 let Inst{15-12} = Rd;
2164 let Inst{19-16} = sat_imm;
2168 def USAT : AI<(outs GPR:$Rd), (ins i32imm:$sat_imm, GPR:$a, shift_imm:$sh),
2169 SatFrm, NoItinerary, "usat", "\t$Rd, $sat_imm, $a$sh",
2170 [/* For disassembly only; pattern left blank */]> {
2175 let Inst{27-21} = 0b0110111;
2176 let Inst{5-4} = 0b01;
2177 let Inst{15-12} = Rd;
2178 let Inst{11-7} = sh{7-3};
2179 let Inst{6} = sh{0};
2180 let Inst{20-16} = sat_imm;
2184 def USAT16 : AI<(outs GPR:$Rd), (ins i32imm:$sat_imm, GPR:$a), SatFrm,
2185 NoItinerary, "usat16", "\t$Rd, $sat_imm, $a",
2186 [/* For disassembly only; pattern left blank */]> {
2190 let Inst{27-20} = 0b01101110;
2191 let Inst{11-4} = 0b11110011;
2192 let Inst{15-12} = Rd;
2193 let Inst{19-16} = sat_imm;
2197 def : ARMV6Pat<(int_arm_ssat GPR:$a, imm:$pos), (SSAT imm:$pos, GPR:$a, 0)>;
2198 def : ARMV6Pat<(int_arm_usat GPR:$a, imm:$pos), (USAT imm:$pos, GPR:$a, 0)>;
2200 //===----------------------------------------------------------------------===//
2201 // Bitwise Instructions.
2204 defm AND : AsI1_bin_irs<0b0000, "and",
2205 IIC_iBITi, IIC_iBITr, IIC_iBITsr,
2206 BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
2207 defm ORR : AsI1_bin_irs<0b1100, "orr",
2208 IIC_iBITi, IIC_iBITr, IIC_iBITsr,
2209 BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
2210 defm EOR : AsI1_bin_irs<0b0001, "eor",
2211 IIC_iBITi, IIC_iBITr, IIC_iBITsr,
2212 BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
2213 defm BIC : AsI1_bin_irs<0b1110, "bic",
2214 IIC_iBITi, IIC_iBITr, IIC_iBITsr,
2215 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
2217 def BFC : I<(outs GPR:$Rd), (ins GPR:$src, bf_inv_mask_imm:$imm),
2218 AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iUNAsi,
2219 "bfc", "\t$Rd, $imm", "$src = $Rd",
2220 [(set GPR:$Rd, (and GPR:$src, bf_inv_mask_imm:$imm))]>,
2221 Requires<[IsARM, HasV6T2]> {
2224 let Inst{27-21} = 0b0111110;
2225 let Inst{6-0} = 0b0011111;
2226 let Inst{15-12} = Rd;
2227 let Inst{11-7} = imm{4-0}; // lsb
2228 let Inst{20-16} = imm{9-5}; // width
2231 // A8.6.18 BFI - Bitfield insert (Encoding A1)
2232 def BFI : I<(outs GPR:$Rd), (ins GPR:$src, GPR:$Rn, bf_inv_mask_imm:$imm),
2233 AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iUNAsi,
2234 "bfi", "\t$Rd, $Rn, $imm", "$src = $Rd",
2235 [(set GPR:$Rd, (ARMbfi GPR:$src, GPR:$Rn,
2236 bf_inv_mask_imm:$imm))]>,
2237 Requires<[IsARM, HasV6T2]> {
2241 let Inst{27-21} = 0b0111110;
2242 let Inst{6-4} = 0b001; // Rn: Inst{3-0} != 15
2243 let Inst{15-12} = Rd;
2244 let Inst{11-7} = imm{4-0}; // lsb
2245 let Inst{20-16} = imm{9-5}; // width
2249 def MVNr : AsI1<0b1111, (outs GPR:$Rd), (ins GPR:$Rm), DPFrm, IIC_iMVNr,
2250 "mvn", "\t$Rd, $Rm",
2251 [(set GPR:$Rd, (not GPR:$Rm))]>, UnaryDP {
2255 let Inst{19-16} = 0b0000;
2256 let Inst{11-4} = 0b00000000;
2257 let Inst{15-12} = Rd;
2260 def MVNs : AsI1<0b1111, (outs GPR:$Rd), (ins so_reg:$shift), DPSoRegFrm,
2261 IIC_iMVNsr, "mvn", "\t$Rd, $shift",
2262 [(set GPR:$Rd, (not so_reg:$shift))]>, UnaryDP {
2267 let Inst{19-16} = 0b0000;
2268 let Inst{15-12} = Rd;
2269 let Inst{11-0} = shift;
2271 let isReMaterializable = 1, isAsCheapAsAMove = 1 in
2272 def MVNi : AsI1<0b1111, (outs GPR:$Rd), (ins so_imm:$imm), DPFrm,
2273 IIC_iMVNi, "mvn", "\t$Rd, $imm",
2274 [(set GPR:$Rd, so_imm_not:$imm)]>,UnaryDP {
2279 let Inst{19-16} = 0b0000;
2280 let Inst{15-12} = Rd;
2281 let Inst{11-0} = imm;
2284 def : ARMPat<(and GPR:$src, so_imm_not:$imm),
2285 (BICri GPR:$src, so_imm_not:$imm)>;
2287 //===----------------------------------------------------------------------===//
2288 // Multiply Instructions.
2290 class AsMul1I32<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
2291 string opc, string asm, list<dag> pattern>
2292 : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
2296 let Inst{19-16} = Rd;
2297 let Inst{11-8} = Rm;
2300 class AsMul1I64<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
2301 string opc, string asm, list<dag> pattern>
2302 : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
2307 let Inst{19-16} = RdHi;
2308 let Inst{15-12} = RdLo;
2309 let Inst{11-8} = Rm;
2313 let isCommutable = 1 in
2314 def MUL : AsMul1I32<0b0000000, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2315 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm",
2316 [(set GPR:$Rd, (mul GPR:$Rn, GPR:$Rm))]>;
2318 def MLA : AsMul1I32<0b0000001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2319 IIC_iMAC32, "mla", "\t$Rd, $Rn, $Rm, $Ra",
2320 [(set GPR:$Rd, (add (mul GPR:$Rn, GPR:$Rm), GPR:$Ra))]> {
2322 let Inst{15-12} = Ra;
2325 def MLS : AMul1I<0b0000011, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
2326 IIC_iMAC32, "mls", "\t$dst, $a, $b, $c",
2327 [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>,
2328 Requires<[IsARM, HasV6T2]> {
2332 let Inst{19-16} = Rd;
2333 let Inst{11-8} = Rm;
2337 // Extra precision multiplies with low / high results
2339 let neverHasSideEffects = 1 in {
2340 let isCommutable = 1 in {
2341 def SMULL : AsMul1I64<0b0000110, (outs GPR:$RdLo, GPR:$RdHi),
2342 (ins GPR:$Rn, GPR:$Rm), IIC_iMUL64,
2343 "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2345 def UMULL : AsMul1I64<0b0000100, (outs GPR:$RdLo, GPR:$RdHi),
2346 (ins GPR:$Rn, GPR:$Rm), IIC_iMUL64,
2347 "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2350 // Multiply + accumulate
2351 def SMLAL : AsMul1I64<0b0000111, (outs GPR:$RdLo, GPR:$RdHi),
2352 (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
2353 "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2355 def UMLAL : AsMul1I64<0b0000101, (outs GPR:$RdLo, GPR:$RdHi),
2356 (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
2357 "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
2359 def UMAAL : AMul1I <0b0000010, (outs GPR:$RdLo, GPR:$RdHi),
2360 (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
2361 "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
2362 Requires<[IsARM, HasV6]> {
2367 let Inst{19-16} = RdLo;
2368 let Inst{15-12} = RdHi;
2369 let Inst{11-8} = Rm;
2372 } // neverHasSideEffects
2374 // Most significant word multiply
2375 def SMMUL : AMul2I <0b0111010, 0b0001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2376 IIC_iMUL32, "smmul", "\t$Rd, $Rn, $Rm",
2377 [(set GPR:$Rd, (mulhs GPR:$Rn, GPR:$Rm))]>,
2378 Requires<[IsARM, HasV6]> {
2379 let Inst{15-12} = 0b1111;
2382 def SMMULR : AMul2I <0b0111010, 0b0011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2383 IIC_iMUL32, "smmulr", "\t$Rd, $Rn, $Rm",
2384 [/* For disassembly only; pattern left blank */]>,
2385 Requires<[IsARM, HasV6]> {
2386 let Inst{15-12} = 0b1111;
2389 def SMMLA : AMul2Ia <0b0111010, 0b0001, (outs GPR:$Rd),
2390 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2391 IIC_iMAC32, "smmla", "\t$Rd, $Rn, $Rm, $Ra",
2392 [(set GPR:$Rd, (add (mulhs GPR:$Rn, GPR:$Rm), GPR:$Ra))]>,
2393 Requires<[IsARM, HasV6]>;
2395 def SMMLAR : AMul2Ia <0b0111010, 0b0011, (outs GPR:$Rd),
2396 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2397 IIC_iMAC32, "smmlar", "\t$Rd, $Rn, $Rm, $Ra",
2398 [/* For disassembly only; pattern left blank */]>,
2399 Requires<[IsARM, HasV6]>;
2401 def SMMLS : AMul2Ia <0b0111010, 0b1101, (outs GPR:$Rd),
2402 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2403 IIC_iMAC32, "smmls", "\t$Rd, $Rn, $Rm, $Ra",
2404 [(set GPR:$Rd, (sub GPR:$Ra, (mulhs GPR:$Rn, GPR:$Rm)))]>,
2405 Requires<[IsARM, HasV6]>;
2407 def SMMLSR : AMul2Ia <0b0111010, 0b1111, (outs GPR:$Rd),
2408 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2409 IIC_iMAC32, "smmlsr", "\t$Rd, $Rn, $Rm, $Ra",
2410 [/* For disassembly only; pattern left blank */]>,
2411 Requires<[IsARM, HasV6]>;
2413 multiclass AI_smul<string opc, PatFrag opnode> {
2414 def BB : AMulxyI<0b0001011, 0b00, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2415 IIC_iMUL16, !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
2416 [(set GPR:$Rd, (opnode (sext_inreg GPR:$Rn, i16),
2417 (sext_inreg GPR:$Rm, i16)))]>,
2418 Requires<[IsARM, HasV5TE]>;
2420 def BT : AMulxyI<0b0001011, 0b10, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2421 IIC_iMUL16, !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
2422 [(set GPR:$Rd, (opnode (sext_inreg GPR:$Rn, i16),
2423 (sra GPR:$Rm, (i32 16))))]>,
2424 Requires<[IsARM, HasV5TE]>;
2426 def TB : AMulxyI<0b0001011, 0b01, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2427 IIC_iMUL16, !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
2428 [(set GPR:$Rd, (opnode (sra GPR:$Rn, (i32 16)),
2429 (sext_inreg GPR:$Rm, i16)))]>,
2430 Requires<[IsARM, HasV5TE]>;
2432 def TT : AMulxyI<0b0001011, 0b11, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2433 IIC_iMUL16, !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
2434 [(set GPR:$Rd, (opnode (sra GPR:$Rn, (i32 16)),
2435 (sra GPR:$Rm, (i32 16))))]>,
2436 Requires<[IsARM, HasV5TE]>;
2438 def WB : AMulxyI<0b0001001, 0b01, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2439 IIC_iMUL16, !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
2440 [(set GPR:$Rd, (sra (opnode GPR:$Rn,
2441 (sext_inreg GPR:$Rm, i16)), (i32 16)))]>,
2442 Requires<[IsARM, HasV5TE]>;
2444 def WT : AMulxyI<0b0001001, 0b11, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2445 IIC_iMUL16, !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
2446 [(set GPR:$Rd, (sra (opnode GPR:$Rn,
2447 (sra GPR:$Rm, (i32 16))), (i32 16)))]>,
2448 Requires<[IsARM, HasV5TE]>;
2452 multiclass AI_smla<string opc, PatFrag opnode> {
2453 def BB : AMulxyI<0b0001000, 0b00, (outs GPR:$Rd),
2454 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2455 IIC_iMAC16, !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
2456 [(set GPR:$Rd, (add GPR:$Ra,
2457 (opnode (sext_inreg GPR:$Rn, i16),
2458 (sext_inreg GPR:$Rm, i16))))]>,
2459 Requires<[IsARM, HasV5TE]>;
2461 def BT : AMulxyI<0b0001000, 0b10, (outs GPR:$Rd),
2462 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2463 IIC_iMAC16, !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
2464 [(set GPR:$Rd, (add GPR:$Ra, (opnode (sext_inreg GPR:$Rn, i16),
2465 (sra GPR:$Rm, (i32 16)))))]>,
2466 Requires<[IsARM, HasV5TE]>;
2468 def TB : AMulxyI<0b0001000, 0b01, (outs GPR:$Rd),
2469 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2470 IIC_iMAC16, !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
2471 [(set GPR:$Rd, (add GPR:$Ra, (opnode (sra GPR:$Rn, (i32 16)),
2472 (sext_inreg GPR:$Rm, i16))))]>,
2473 Requires<[IsARM, HasV5TE]>;
2475 def TT : AMulxyI<0b0001000, 0b11, (outs GPR:$Rd),
2476 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2477 IIC_iMAC16, !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
2478 [(set GPR:$Rd, (add GPR:$Ra, (opnode (sra GPR:$Rn, (i32 16)),
2479 (sra GPR:$Rm, (i32 16)))))]>,
2480 Requires<[IsARM, HasV5TE]>;
2482 def WB : AMulxyI<0b0001001, 0b00, (outs GPR:$Rd),
2483 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2484 IIC_iMAC16, !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
2485 [(set GPR:$Rd, (add GPR:$Ra, (sra (opnode GPR:$Rn,
2486 (sext_inreg GPR:$Rm, i16)), (i32 16))))]>,
2487 Requires<[IsARM, HasV5TE]>;
2489 def WT : AMulxyI<0b0001001, 0b10, (outs GPR:$Rd),
2490 (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2491 IIC_iMAC16, !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
2492 [(set GPR:$Rd, (add GPR:$Ra, (sra (opnode GPR:$Rn,
2493 (sra GPR:$Rm, (i32 16))), (i32 16))))]>,
2494 Requires<[IsARM, HasV5TE]>;
2497 defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2498 defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2500 // Halfword multiply accumulate long: SMLAL<x><y> -- for disassembly only
2501 def SMLALBB : AMulxyI64<0b0001010, 0b00, (outs GPR:$RdLo, GPR:$RdHi),
2502 (ins GPR:$Rn, GPR:$Rm),
2503 IIC_iMAC64, "smlalbb", "\t$RdLo, $RdHi, $Rn, $Rm",
2504 [/* For disassembly only; pattern left blank */]>,
2505 Requires<[IsARM, HasV5TE]>;
2507 def SMLALBT : AMulxyI64<0b0001010, 0b10, (outs GPR:$RdLo, GPR:$RdHi),
2508 (ins GPR:$Rn, GPR:$Rm),
2509 IIC_iMAC64, "smlalbt", "\t$RdLo, $RdHi, $Rn, $Rm",
2510 [/* For disassembly only; pattern left blank */]>,
2511 Requires<[IsARM, HasV5TE]>;
2513 def SMLALTB : AMulxyI64<0b0001010, 0b01, (outs GPR:$RdLo, GPR:$RdHi),
2514 (ins GPR:$Rn, GPR:$Rm),
2515 IIC_iMAC64, "smlaltb", "\t$RdLo, $RdHi, $Rn, $Rm",
2516 [/* For disassembly only; pattern left blank */]>,
2517 Requires<[IsARM, HasV5TE]>;
2519 def SMLALTT : AMulxyI64<0b0001010, 0b11, (outs GPR:$RdLo, GPR:$RdHi),
2520 (ins GPR:$Rn, GPR:$Rm),
2521 IIC_iMAC64, "smlaltt", "\t$RdLo, $RdHi, $Rn, $Rm",
2522 [/* For disassembly only; pattern left blank */]>,
2523 Requires<[IsARM, HasV5TE]>;
2525 // Helper class for AI_smld -- for disassembly only
2526 class AMulDualIbase<bit long, bit sub, bit swap, dag oops, dag iops,
2527 InstrItinClass itin, string opc, string asm>
2528 : AI<oops, iops, MulFrm, itin, opc, asm, []>, Requires<[IsARM, HasV6]> {
2535 let Inst{21-20} = 0b00;
2536 let Inst{22} = long;
2537 let Inst{27-23} = 0b01110;
2538 let Inst{11-8} = Rm;
2541 class AMulDualI<bit long, bit sub, bit swap, dag oops, dag iops,
2542 InstrItinClass itin, string opc, string asm>
2543 : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
2545 let Inst{15-12} = 0b1111;
2546 let Inst{19-16} = Rd;
2548 class AMulDualIa<bit long, bit sub, bit swap, dag oops, dag iops,
2549 InstrItinClass itin, string opc, string asm>
2550 : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
2552 let Inst{15-12} = Ra;
2554 class AMulDualI64<bit long, bit sub, bit swap, dag oops, dag iops,
2555 InstrItinClass itin, string opc, string asm>
2556 : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
2559 let Inst{19-16} = RdHi;
2560 let Inst{15-12} = RdLo;
2563 multiclass AI_smld<bit sub, string opc> {
2565 def D : AMulDualIa<0, sub, 0, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2566 NoItinerary, !strconcat(opc, "d"), "\t$Rd, $Rn, $Rm, $Ra">;
2568 def DX: AMulDualIa<0, sub, 1, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
2569 NoItinerary, !strconcat(opc, "dx"), "\t$Rd, $Rn, $Rm, $Ra">;
2571 def LD: AMulDualI64<1, sub, 0, (outs GPR:$RdLo,GPR:$RdHi),
2572 (ins GPR:$Rn, GPR:$Rm), NoItinerary,
2573 !strconcat(opc, "ld"), "\t$RdLo, $RdHi, $Rn, $Rm">;
2575 def LDX : AMulDualI64<1, sub, 1, (outs GPR:$RdLo,GPR:$RdHi),
2576 (ins GPR:$Rn, GPR:$Rm), NoItinerary,
2577 !strconcat(opc, "ldx"),"\t$RdLo, $RdHi, $Rn, $Rm">;
2581 defm SMLA : AI_smld<0, "smla">;
2582 defm SMLS : AI_smld<1, "smls">;
2584 multiclass AI_sdml<bit sub, string opc> {
2586 def D : AMulDualI<0, sub, 0, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2587 NoItinerary, !strconcat(opc, "d"), "\t$Rd, $Rn, $Rm">;
2588 def DX : AMulDualI<0, sub, 1, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2589 NoItinerary, !strconcat(opc, "dx"), "\t$Rd, $Rn, $Rm">;
2592 defm SMUA : AI_sdml<0, "smua">;
2593 defm SMUS : AI_sdml<1, "smus">;
2595 //===----------------------------------------------------------------------===//
2596 // Misc. Arithmetic Instructions.
2599 def CLZ : AMiscA1I<0b000010110, 0b0001, (outs GPR:$Rd), (ins GPR:$Rm),
2600 IIC_iUNAr, "clz", "\t$Rd, $Rm",
2601 [(set GPR:$Rd, (ctlz GPR:$Rm))]>, Requires<[IsARM, HasV5T]>;
2603 def RBIT : AMiscA1I<0b01101111, 0b0011, (outs GPR:$Rd), (ins GPR:$Rm),
2604 IIC_iUNAr, "rbit", "\t$Rd, $Rm",
2605 [(set GPR:$Rd, (ARMrbit GPR:$Rm))]>,
2606 Requires<[IsARM, HasV6T2]>;
2608 def REV : AMiscA1I<0b01101011, 0b0011, (outs GPR:$Rd), (ins GPR:$Rm),
2609 IIC_iUNAr, "rev", "\t$Rd, $Rm",
2610 [(set GPR:$Rd, (bswap GPR:$Rm))]>, Requires<[IsARM, HasV6]>;
2612 def REV16 : AMiscA1I<0b01101011, 0b1011, (outs GPR:$Rd), (ins GPR:$Rm),
2613 IIC_iUNAr, "rev16", "\t$Rd, $Rm",
2615 (or (and (srl GPR:$Rm, (i32 8)), 0xFF),
2616 (or (and (shl GPR:$Rm, (i32 8)), 0xFF00),
2617 (or (and (srl GPR:$Rm, (i32 8)), 0xFF0000),
2618 (and (shl GPR:$Rm, (i32 8)), 0xFF000000)))))]>,
2619 Requires<[IsARM, HasV6]>;
2621 def REVSH : AMiscA1I<0b01101111, 0b1011, (outs GPR:$Rd), (ins GPR:$Rm),
2622 IIC_iUNAr, "revsh", "\t$Rd, $Rm",
2625 (or (srl (and GPR:$Rm, 0xFF00), (i32 8)),
2626 (shl GPR:$Rm, (i32 8))), i16))]>,
2627 Requires<[IsARM, HasV6]>;
2629 def lsl_shift_imm : SDNodeXForm<imm, [{
2630 unsigned Sh = ARM_AM::getSORegOpc(ARM_AM::lsl, N->getZExtValue());
2631 return CurDAG->getTargetConstant(Sh, MVT::i32);
2634 def lsl_amt : PatLeaf<(i32 imm), [{
2635 return (N->getZExtValue() < 32);
2638 def PKHBT : APKHI<0b01101000, 0, (outs GPR:$Rd),
2639 (ins GPR:$Rn, GPR:$Rm, shift_imm:$sh),
2640 IIC_iALUsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
2641 [(set GPR:$Rd, (or (and GPR:$Rn, 0xFFFF),
2642 (and (shl GPR:$Rm, lsl_amt:$sh),
2644 Requires<[IsARM, HasV6]>;
2646 // Alternate cases for PKHBT where identities eliminate some nodes.
2647 def : ARMV6Pat<(or (and GPR:$Rn, 0xFFFF), (and GPR:$Rm, 0xFFFF0000)),
2648 (PKHBT GPR:$Rn, GPR:$Rm, 0)>;
2649 def : ARMV6Pat<(or (and GPR:$Rn, 0xFFFF), (shl GPR:$Rm, imm16_31:$sh)),
2650 (PKHBT GPR:$Rn, GPR:$Rm, (lsl_shift_imm imm16_31:$sh))>;
2652 def asr_shift_imm : SDNodeXForm<imm, [{
2653 unsigned Sh = ARM_AM::getSORegOpc(ARM_AM::asr, N->getZExtValue());
2654 return CurDAG->getTargetConstant(Sh, MVT::i32);
2657 def asr_amt : PatLeaf<(i32 imm), [{
2658 return (N->getZExtValue() <= 32);
2661 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2662 // will match the pattern below.
2663 def PKHTB : APKHI<0b01101000, 1, (outs GPR:$Rd),
2664 (ins GPR:$Rn, GPR:$Rm, shift_imm:$sh),
2665 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
2666 [(set GPR:$Rd, (or (and GPR:$Rn, 0xFFFF0000),
2667 (and (sra GPR:$Rm, asr_amt:$sh),
2669 Requires<[IsARM, HasV6]>;
2671 // Alternate cases for PKHTB where identities eliminate some nodes. Note that
2672 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
2673 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, imm16_31:$sh)),
2674 (PKHTB GPR:$src1, GPR:$src2, (asr_shift_imm imm16_31:$sh))>;
2675 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
2676 (and (srl GPR:$src2, imm1_15:$sh), 0xFFFF)),
2677 (PKHTB GPR:$src1, GPR:$src2, (asr_shift_imm imm1_15:$sh))>;
2679 //===----------------------------------------------------------------------===//
2680 // Comparison Instructions...
2683 defm CMP : AI1_cmp_irs<0b1010, "cmp",
2684 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsr,
2685 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
2687 // FIXME: We have to be careful when using the CMN instruction and comparison
2688 // with 0. One would expect these two pieces of code should give identical
2704 // However, the CMN gives the *opposite* result when r1 is 0. This is because
2705 // the carry flag is set in the CMP case but not in the CMN case. In short, the
2706 // CMP instruction doesn't perform a truncate of the (logical) NOT of 0 plus the
2707 // value of r0 and the carry bit (because the "carry bit" parameter to
2708 // AddWithCarry is defined as 1 in this case, the carry flag will always be set
2709 // when r0 >= 0). The CMN instruction doesn't perform a NOT of 0 so there is
2710 // never a "carry" when this AddWithCarry is performed (because the "carry bit"
2711 // parameter to AddWithCarry is defined as 0).
2713 // When x is 0 and unsigned:
2717 // ~x + 1 = 0x1 0000 0000
2718 // (-x = 0) != (0x1 0000 0000 = ~x + 1)
2720 // Therefore, we should disable CMN when comparing against zero, until we can
2721 // limit when the CMN instruction is used (when we know that the RHS is not 0 or
2722 // when it's a comparison which doesn't look at the 'carry' flag).
2724 // (See the ARM docs for the "AddWithCarry" pseudo-code.)
2726 // This is related to <rdar://problem/7569620>.
2728 //defm CMN : AI1_cmp_irs<0b1011, "cmn",
2729 // BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
2731 // Note that TST/TEQ don't set all the same flags that CMP does!
2732 defm TST : AI1_cmp_irs<0b1000, "tst",
2733 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsr,
2734 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>, 1>;
2735 defm TEQ : AI1_cmp_irs<0b1001, "teq",
2736 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsr,
2737 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>, 1>;
2739 defm CMPz : AI1_cmp_irs<0b1010, "cmp",
2740 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsr,
2741 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
2742 defm CMNz : AI1_cmp_irs<0b1011, "cmn",
2743 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsr,
2744 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
2746 //def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
2747 // (CMNri GPR:$src, so_imm_neg:$imm)>;
2749 def : ARMPat<(ARMcmpZ GPR:$src, so_imm_neg:$imm),
2750 (CMNzri GPR:$src, so_imm_neg:$imm)>;
2752 // Pseudo i64 compares for some floating point compares.
2753 let usesCustomInserter = 1, isBranch = 1, isTerminator = 1,
2755 def BCCi64 : PseudoInst<(outs),
2756 (ins i32imm:$cc, GPR:$lhs1, GPR:$lhs2, GPR:$rhs1, GPR:$rhs2, brtarget:$dst),
2758 [(ARMBcci64 imm:$cc, GPR:$lhs1, GPR:$lhs2, GPR:$rhs1, GPR:$rhs2, bb:$dst)]>;
2760 def BCCZi64 : PseudoInst<(outs),
2761 (ins i32imm:$cc, GPR:$lhs1, GPR:$lhs2, brtarget:$dst), IIC_Br, "",
2762 [(ARMBcci64 imm:$cc, GPR:$lhs1, GPR:$lhs2, 0, 0, bb:$dst)]>;
2763 } // usesCustomInserter
2766 // Conditional moves
2767 // FIXME: should be able to write a pattern for ARMcmov, but can't use
2768 // a two-value operand where a dag node expects two operands. :(
2769 // FIXME: These should all be pseudo-instructions that get expanded to
2770 // the normal MOV instructions. That would fix the dependency on
2771 // special casing them in tblgen.
2772 let neverHasSideEffects = 1 in {
2773 def MOVCCr : AI1<0b1101, (outs GPR:$Rd), (ins GPR:$false, GPR:$Rm), DPFrm,
2774 IIC_iCMOVr, "mov", "\t$Rd, $Rm",
2775 [/*(set GPR:$Rd, (ARMcmov GPR:$false, GPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
2776 RegConstraint<"$false = $Rd">, UnaryDP {
2780 let Inst{11-4} = 0b00000000;
2783 let Inst{15-12} = Rd;
2784 let Inst{11-4} = 0b00000000;
2788 def MOVCCs : AI1<0b1101, (outs GPR:$dst),
2789 (ins GPR:$false, so_reg:$true), DPSoRegFrm, IIC_iCMOVsr,
2790 "mov", "\t$dst, $true",
2791 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
2792 RegConstraint<"$false = $dst">, UnaryDP {
2796 def MOVCCi16 : AI1<0b1000, (outs GPR:$dst), (ins GPR:$false, i32imm:$src),
2798 "movw", "\t$dst, $src",
2800 RegConstraint<"$false = $dst">, Requires<[IsARM, HasV6T2]>,
2806 def MOVCCi : AI1<0b1101, (outs GPR:$dst),
2807 (ins GPR:$false, so_imm:$true), DPFrm, IIC_iCMOVi,
2808 "mov", "\t$dst, $true",
2809 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
2810 RegConstraint<"$false = $dst">, UnaryDP {
2813 } // neverHasSideEffects
2815 //===----------------------------------------------------------------------===//
2816 // Atomic operations intrinsics
2819 // memory barriers protect the atomic sequences
2820 let hasSideEffects = 1 in {
2821 def DMBsy : AInoP<(outs), (ins), MiscFrm, NoItinerary, "dmb", "",
2822 [(ARMMemBarrier)]>, Requires<[IsARM, HasDB]> {
2823 let Inst{31-4} = 0xf57ff05;
2824 // FIXME: add support for options other than a full system DMB
2825 // See DMB disassembly-only variants below.
2826 let Inst{3-0} = 0b1111;
2829 def DSBsy : AInoP<(outs), (ins), MiscFrm, NoItinerary, "dsb", "",
2830 [(ARMSyncBarrier)]>, Requires<[IsARM, HasDB]> {
2831 let Inst{31-4} = 0xf57ff04;
2832 // FIXME: add support for options other than a full system DSB
2833 // See DSB disassembly-only variants below.
2834 let Inst{3-0} = 0b1111;
2837 def DMB_MCR : AInoP<(outs), (ins GPR:$zero), MiscFrm, NoItinerary,
2838 "mcr", "\tp15, 0, $zero, c7, c10, 5",
2839 [(ARMMemBarrierMCR GPR:$zero)]>,
2840 Requires<[IsARM, HasV6]> {
2841 // FIXME: add support for options other than a full system DMB
2842 // FIXME: add encoding
2845 def DSB_MCR : AInoP<(outs), (ins GPR:$zero), MiscFrm, NoItinerary,
2846 "mcr", "\tp15, 0, $zero, c7, c10, 4",
2847 [(ARMSyncBarrierMCR GPR:$zero)]>,
2848 Requires<[IsARM, HasV6]> {
2849 // FIXME: add support for options other than a full system DSB
2850 // FIXME: add encoding
2854 // Memory Barrier Operations Variants -- for disassembly only
2856 def memb_opt : Operand<i32> {
2857 let PrintMethod = "printMemBOption";
2860 class AMBI<bits<4> op7_4, string opc>
2861 : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary, opc, "\t$opt",
2862 [/* For disassembly only; pattern left blank */]>,
2863 Requires<[IsARM, HasDB]> {
2864 let Inst{31-8} = 0xf57ff0;
2865 let Inst{7-4} = op7_4;
2868 // These DMB variants are for disassembly only.
2869 def DMBvar : AMBI<0b0101, "dmb">;
2871 // These DSB variants are for disassembly only.
2872 def DSBvar : AMBI<0b0100, "dsb">;
2874 // ISB has only full system option -- for disassembly only
2875 def ISBsy : AInoP<(outs), (ins), MiscFrm, NoItinerary, "isb", "", []>,
2876 Requires<[IsARM, HasDB]> {
2877 let Inst{31-4} = 0xf57ff06;
2878 let Inst{3-0} = 0b1111;
2881 let usesCustomInserter = 1 in {
2882 let Uses = [CPSR] in {
2883 def ATOMIC_LOAD_ADD_I8 : PseudoInst<
2884 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2885 [(set GPR:$dst, (atomic_load_add_8 GPR:$ptr, GPR:$incr))]>;
2886 def ATOMIC_LOAD_SUB_I8 : PseudoInst<
2887 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2888 [(set GPR:$dst, (atomic_load_sub_8 GPR:$ptr, GPR:$incr))]>;
2889 def ATOMIC_LOAD_AND_I8 : PseudoInst<
2890 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2891 [(set GPR:$dst, (atomic_load_and_8 GPR:$ptr, GPR:$incr))]>;
2892 def ATOMIC_LOAD_OR_I8 : PseudoInst<
2893 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2894 [(set GPR:$dst, (atomic_load_or_8 GPR:$ptr, GPR:$incr))]>;
2895 def ATOMIC_LOAD_XOR_I8 : PseudoInst<
2896 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2897 [(set GPR:$dst, (atomic_load_xor_8 GPR:$ptr, GPR:$incr))]>;
2898 def ATOMIC_LOAD_NAND_I8 : PseudoInst<
2899 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2900 [(set GPR:$dst, (atomic_load_nand_8 GPR:$ptr, GPR:$incr))]>;
2901 def ATOMIC_LOAD_ADD_I16 : PseudoInst<
2902 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2903 [(set GPR:$dst, (atomic_load_add_16 GPR:$ptr, GPR:$incr))]>;
2904 def ATOMIC_LOAD_SUB_I16 : PseudoInst<
2905 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2906 [(set GPR:$dst, (atomic_load_sub_16 GPR:$ptr, GPR:$incr))]>;
2907 def ATOMIC_LOAD_AND_I16 : PseudoInst<
2908 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2909 [(set GPR:$dst, (atomic_load_and_16 GPR:$ptr, GPR:$incr))]>;
2910 def ATOMIC_LOAD_OR_I16 : PseudoInst<
2911 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2912 [(set GPR:$dst, (atomic_load_or_16 GPR:$ptr, GPR:$incr))]>;
2913 def ATOMIC_LOAD_XOR_I16 : PseudoInst<
2914 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2915 [(set GPR:$dst, (atomic_load_xor_16 GPR:$ptr, GPR:$incr))]>;
2916 def ATOMIC_LOAD_NAND_I16 : PseudoInst<
2917 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2918 [(set GPR:$dst, (atomic_load_nand_16 GPR:$ptr, GPR:$incr))]>;
2919 def ATOMIC_LOAD_ADD_I32 : PseudoInst<
2920 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2921 [(set GPR:$dst, (atomic_load_add_32 GPR:$ptr, GPR:$incr))]>;
2922 def ATOMIC_LOAD_SUB_I32 : PseudoInst<
2923 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2924 [(set GPR:$dst, (atomic_load_sub_32 GPR:$ptr, GPR:$incr))]>;
2925 def ATOMIC_LOAD_AND_I32 : PseudoInst<
2926 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2927 [(set GPR:$dst, (atomic_load_and_32 GPR:$ptr, GPR:$incr))]>;
2928 def ATOMIC_LOAD_OR_I32 : PseudoInst<
2929 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2930 [(set GPR:$dst, (atomic_load_or_32 GPR:$ptr, GPR:$incr))]>;
2931 def ATOMIC_LOAD_XOR_I32 : PseudoInst<
2932 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2933 [(set GPR:$dst, (atomic_load_xor_32 GPR:$ptr, GPR:$incr))]>;
2934 def ATOMIC_LOAD_NAND_I32 : PseudoInst<
2935 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary, "",
2936 [(set GPR:$dst, (atomic_load_nand_32 GPR:$ptr, GPR:$incr))]>;
2938 def ATOMIC_SWAP_I8 : PseudoInst<
2939 (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary, "",
2940 [(set GPR:$dst, (atomic_swap_8 GPR:$ptr, GPR:$new))]>;
2941 def ATOMIC_SWAP_I16 : PseudoInst<
2942 (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary, "",
2943 [(set GPR:$dst, (atomic_swap_16 GPR:$ptr, GPR:$new))]>;
2944 def ATOMIC_SWAP_I32 : PseudoInst<
2945 (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary, "",
2946 [(set GPR:$dst, (atomic_swap_32 GPR:$ptr, GPR:$new))]>;
2948 def ATOMIC_CMP_SWAP_I8 : PseudoInst<
2949 (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary, "",
2950 [(set GPR:$dst, (atomic_cmp_swap_8 GPR:$ptr, GPR:$old, GPR:$new))]>;
2951 def ATOMIC_CMP_SWAP_I16 : PseudoInst<
2952 (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary, "",
2953 [(set GPR:$dst, (atomic_cmp_swap_16 GPR:$ptr, GPR:$old, GPR:$new))]>;
2954 def ATOMIC_CMP_SWAP_I32 : PseudoInst<
2955 (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary, "",
2956 [(set GPR:$dst, (atomic_cmp_swap_32 GPR:$ptr, GPR:$old, GPR:$new))]>;
2960 let mayLoad = 1 in {
2961 def LDREXB : AIldrex<0b10, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
2962 "ldrexb", "\t$dest, [$ptr]",
2964 def LDREXH : AIldrex<0b11, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
2965 "ldrexh", "\t$dest, [$ptr]",
2967 def LDREX : AIldrex<0b00, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
2968 "ldrex", "\t$dest, [$ptr]",
2970 def LDREXD : AIldrex<0b01, (outs GPR:$dest, GPR:$dest2), (ins GPR:$ptr),
2972 "ldrexd", "\t$dest, $dest2, [$ptr]",
2976 let mayStore = 1, Constraints = "@earlyclobber $success" in {
2977 def STREXB : AIstrex<0b10, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
2979 "strexb", "\t$success, $src, [$ptr]",
2981 def STREXH : AIstrex<0b11, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
2983 "strexh", "\t$success, $src, [$ptr]",
2985 def STREX : AIstrex<0b00, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
2987 "strex", "\t$success, $src, [$ptr]",
2989 def STREXD : AIstrex<0b01, (outs GPR:$success),
2990 (ins GPR:$src, GPR:$src2, GPR:$ptr),
2992 "strexd", "\t$success, $src, $src2, [$ptr]",
2996 // Clear-Exclusive is for disassembly only.
2997 def CLREX : AXI<(outs), (ins), MiscFrm, NoItinerary, "clrex",
2998 [/* For disassembly only; pattern left blank */]>,
2999 Requires<[IsARM, HasV7]> {
3000 let Inst{31-20} = 0xf57;
3001 let Inst{7-4} = 0b0001;
3004 // SWP/SWPB are deprecated in V6/V7 and for disassembly only.
3005 let mayLoad = 1 in {
3006 def SWP : AI<(outs GPR:$dst), (ins GPR:$src, GPR:$ptr), LdStExFrm, NoItinerary,
3007 "swp", "\t$dst, $src, [$ptr]",
3008 [/* For disassembly only; pattern left blank */]> {
3009 let Inst{27-23} = 0b00010;
3010 let Inst{22} = 0; // B = 0
3011 let Inst{21-20} = 0b00;
3012 let Inst{7-4} = 0b1001;
3015 def SWPB : AI<(outs GPR:$dst), (ins GPR:$src, GPR:$ptr), LdStExFrm, NoItinerary,
3016 "swpb", "\t$dst, $src, [$ptr]",
3017 [/* For disassembly only; pattern left blank */]> {
3018 let Inst{27-23} = 0b00010;
3019 let Inst{22} = 1; // B = 1
3020 let Inst{21-20} = 0b00;
3021 let Inst{7-4} = 0b1001;
3025 //===----------------------------------------------------------------------===//
3029 // __aeabi_read_tp preserves the registers r1-r3.
3031 Defs = [R0, R12, LR, CPSR] in {
3032 def TPsoft : ABXI<0b1011, (outs), (ins), IIC_Br,
3033 "bl\t__aeabi_read_tp",
3034 [(set R0, ARMthread_pointer)]>;
3037 //===----------------------------------------------------------------------===//
3038 // SJLJ Exception handling intrinsics
3039 // eh_sjlj_setjmp() is an instruction sequence to store the return
3040 // address and save #0 in R0 for the non-longjmp case.
3041 // Since by its nature we may be coming from some other function to get
3042 // here, and we're using the stack frame for the containing function to
3043 // save/restore registers, we can't keep anything live in regs across
3044 // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
3045 // when we get here from a longjmp(). We force everthing out of registers
3046 // except for our own input by listing the relevant registers in Defs. By
3047 // doing so, we also cause the prologue/epilogue code to actively preserve
3048 // all of the callee-saved resgisters, which is exactly what we want.
3049 // A constant value is passed in $val, and we use the location as a scratch.
3051 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, D0,
3052 D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
3053 D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30,
3054 D31 ], hasSideEffects = 1, isBarrier = 1 in {
3055 def Int_eh_sjlj_setjmp : XI<(outs), (ins GPR:$src, GPR:$val),
3056 AddrModeNone, SizeSpecial, IndexModeNone,
3057 Pseudo, NoItinerary, "", "",
3058 [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>,
3059 Requires<[IsARM, HasVFP2]>;
3063 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR ],
3064 hasSideEffects = 1, isBarrier = 1 in {
3065 def Int_eh_sjlj_setjmp_nofp : XI<(outs), (ins GPR:$src, GPR:$val),
3066 AddrModeNone, SizeSpecial, IndexModeNone,
3067 Pseudo, NoItinerary, "", "",
3068 [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>,
3069 Requires<[IsARM, NoVFP]>;
3072 // FIXME: Non-Darwin version(s)
3073 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1,
3074 Defs = [ R7, LR, SP ] in {
3075 def Int_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
3076 AddrModeNone, SizeSpecial, IndexModeNone,
3077 Pseudo, NoItinerary, "", "",
3078 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
3079 Requires<[IsARM, IsDarwin]>;
3082 // eh.sjlj.dispatchsetup pseudo-instruction.
3083 // This pseudo is usef for ARM, Thumb1 and Thumb2. Any differences are
3084 // handled when the pseudo is expanded (which happens before any passes
3085 // that need the instruction size).
3086 let isBarrier = 1, hasSideEffects = 1 in
3087 def Int_eh_sjlj_dispatchsetup :
3088 PseudoInst<(outs), (ins GPR:$src), NoItinerary, "",
3089 [(ARMeh_sjlj_dispatchsetup GPR:$src)]>,
3090 Requires<[IsDarwin]>;
3092 //===----------------------------------------------------------------------===//
3093 // Non-Instruction Patterns
3096 // Large immediate handling.
3098 // Two piece so_imms.
3099 // FIXME: Expand this in ARMExpandPseudoInsts.
3100 // FIXME: Remove this when we can do generalized remat.
3101 let isReMaterializable = 1 in
3102 def MOVi2pieces : AI1x2<(outs GPR:$dst), (ins so_imm2part:$src),
3103 Pseudo, IIC_iMOVix2,
3104 "mov", "\t$dst, $src",
3105 [(set GPR:$dst, so_imm2part:$src)]>,
3106 Requires<[IsARM, NoV6T2]>;
3108 def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
3109 (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
3110 (so_imm2part_2 imm:$RHS))>;
3111 def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
3112 (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
3113 (so_imm2part_2 imm:$RHS))>;
3114 def : ARMPat<(add GPR:$LHS, so_imm2part:$RHS),
3115 (ADDri (ADDri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
3116 (so_imm2part_2 imm:$RHS))>;
3117 def : ARMPat<(add GPR:$LHS, so_neg_imm2part:$RHS),
3118 (SUBri (SUBri GPR:$LHS, (so_neg_imm2part_1 imm:$RHS)),
3119 (so_neg_imm2part_2 imm:$RHS))>;
3121 // 32-bit immediate using movw + movt.
3122 // This is a single pseudo instruction, the benefit is that it can be remat'd
3123 // as a single unit instead of having to handle reg inputs.
3124 // FIXME: Remove this when we can do generalized remat.
3125 let isReMaterializable = 1 in
3126 def MOVi32imm : PseudoInst<(outs GPR:$dst), (ins i32imm:$src), IIC_iMOVix2, "",
3127 [(set GPR:$dst, (i32 imm:$src))]>,
3128 Requires<[IsARM, HasV6T2]>;
3130 // ConstantPool, GlobalAddress, and JumpTable
3131 def : ARMPat<(ARMWrapper tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>,
3132 Requires<[IsARM, DontUseMovt]>;
3133 def : ARMPat<(ARMWrapper tconstpool :$dst), (LEApcrel tconstpool :$dst)>;
3134 def : ARMPat<(ARMWrapper tglobaladdr :$dst), (MOVi32imm tglobaladdr :$dst)>,
3135 Requires<[IsARM, UseMovt]>;
3136 def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
3137 (LEApcrelJT tjumptable:$dst, imm:$id)>;
3139 // TODO: add,sub,and, 3-instr forms?
3142 def : ARMPat<(ARMtcret tcGPR:$dst),
3143 (TCRETURNri tcGPR:$dst)>, Requires<[IsDarwin]>;
3145 def : ARMPat<(ARMtcret (i32 tglobaladdr:$dst)),
3146 (TCRETURNdi texternalsym:$dst)>, Requires<[IsDarwin]>;
3148 def : ARMPat<(ARMtcret (i32 texternalsym:$dst)),
3149 (TCRETURNdi texternalsym:$dst)>, Requires<[IsDarwin]>;
3151 def : ARMPat<(ARMtcret tcGPR:$dst),
3152 (TCRETURNriND tcGPR:$dst)>, Requires<[IsNotDarwin]>;
3154 def : ARMPat<(ARMtcret (i32 tglobaladdr:$dst)),
3155 (TCRETURNdiND texternalsym:$dst)>, Requires<[IsNotDarwin]>;
3157 def : ARMPat<(ARMtcret (i32 texternalsym:$dst)),
3158 (TCRETURNdiND texternalsym:$dst)>, Requires<[IsNotDarwin]>;
3161 def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>,
3162 Requires<[IsARM, IsNotDarwin]>;
3163 def : ARMPat<(ARMcall texternalsym:$func), (BLr9 texternalsym:$func)>,
3164 Requires<[IsARM, IsDarwin]>;
3166 // zextload i1 -> zextload i8
3167 //def : ARMPat<(zextloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
3168 def : ARMPat<(zextloadi1 addrmode_imm12:$addr), (LDRBi12 addrmode_imm12:$addr)>;
3169 def : ARMPat<(zextloadi1 ldst_so_reg:$addr), (LDRBrs ldst_so_reg:$addr)>;
3171 // extload -> zextload
3172 def : ARMPat<(extloadi1 addrmode_imm12:$addr), (LDRBi12 addrmode_imm12:$addr)>;
3173 def : ARMPat<(extloadi1 ldst_so_reg:$addr), (LDRBrs ldst_so_reg:$addr)>;
3174 def : ARMPat<(extloadi8 addrmode_imm12:$addr), (LDRBi12 addrmode_imm12:$addr)>;
3175 def : ARMPat<(extloadi8 ldst_so_reg:$addr), (LDRBrs ldst_so_reg:$addr)>;
3177 def : ARMPat<(extloadi16 addrmode3:$addr), (LDRH addrmode3:$addr)>;
3179 def : ARMPat<(extloadi8 addrmodepc:$addr), (PICLDRB addrmodepc:$addr)>;
3180 def : ARMPat<(extloadi16 addrmodepc:$addr), (PICLDRH addrmodepc:$addr)>;
3183 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
3184 (sra (shl GPR:$b, (i32 16)), (i32 16))),
3185 (SMULBB GPR:$a, GPR:$b)>;
3186 def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
3187 (SMULBB GPR:$a, GPR:$b)>;
3188 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
3189 (sra GPR:$b, (i32 16))),
3190 (SMULBT GPR:$a, GPR:$b)>;
3191 def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, (i32 16))),
3192 (SMULBT GPR:$a, GPR:$b)>;
3193 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)),
3194 (sra (shl GPR:$b, (i32 16)), (i32 16))),
3195 (SMULTB GPR:$a, GPR:$b)>;
3196 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)), sext_16_node:$b),
3197 (SMULTB GPR:$a, GPR:$b)>;
3198 def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
3200 (SMULWB GPR:$a, GPR:$b)>;
3201 def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), (i32 16)),
3202 (SMULWB GPR:$a, GPR:$b)>;
3204 def : ARMV5TEPat<(add GPR:$acc,
3205 (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
3206 (sra (shl GPR:$b, (i32 16)), (i32 16)))),
3207 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
3208 def : ARMV5TEPat<(add GPR:$acc,
3209 (mul sext_16_node:$a, sext_16_node:$b)),
3210 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
3211 def : ARMV5TEPat<(add GPR:$acc,
3212 (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
3213 (sra GPR:$b, (i32 16)))),
3214 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
3215 def : ARMV5TEPat<(add GPR:$acc,
3216 (mul sext_16_node:$a, (sra GPR:$b, (i32 16)))),
3217 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
3218 def : ARMV5TEPat<(add GPR:$acc,
3219 (mul (sra GPR:$a, (i32 16)),
3220 (sra (shl GPR:$b, (i32 16)), (i32 16)))),
3221 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
3222 def : ARMV5TEPat<(add GPR:$acc,
3223 (mul (sra GPR:$a, (i32 16)), sext_16_node:$b)),
3224 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
3225 def : ARMV5TEPat<(add GPR:$acc,
3226 (sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
3228 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
3229 def : ARMV5TEPat<(add GPR:$acc,
3230 (sra (mul GPR:$a, sext_16_node:$b), (i32 16))),
3231 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
3233 //===----------------------------------------------------------------------===//
3237 include "ARMInstrThumb.td"
3239 //===----------------------------------------------------------------------===//
3243 include "ARMInstrThumb2.td"
3245 //===----------------------------------------------------------------------===//
3246 // Floating Point Support
3249 include "ARMInstrVFP.td"
3251 //===----------------------------------------------------------------------===//
3252 // Advanced SIMD (NEON) Support
3255 include "ARMInstrNEON.td"
3257 //===----------------------------------------------------------------------===//
3258 // Coprocessor Instructions. For disassembly only.
3261 def CDP : ABI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
3262 nohash_imm:$CRd, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
3263 NoItinerary, "cdp", "\tp$cop, $opc1, cr$CRd, cr$CRn, cr$CRm, $opc2",
3264 [/* For disassembly only; pattern left blank */]> {
3268 def CDP2 : ABXI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
3269 nohash_imm:$CRd, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
3270 NoItinerary, "cdp2\tp$cop, $opc1, cr$CRd, cr$CRn, cr$CRm, $opc2",
3271 [/* For disassembly only; pattern left blank */]> {
3272 let Inst{31-28} = 0b1111;
3276 class ACI<dag oops, dag iops, string opc, string asm>
3277 : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, BrFrm, NoItinerary,
3278 opc, asm, "", [/* For disassembly only; pattern left blank */]> {
3279 let Inst{27-25} = 0b110;
3282 multiclass LdStCop<bits<4> op31_28, bit load, string opc> {
3284 def _OFFSET : ACI<(outs),
3285 (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3286 opc, "\tp$cop, cr$CRd, $addr"> {
3287 let Inst{31-28} = op31_28;
3288 let Inst{24} = 1; // P = 1
3289 let Inst{21} = 0; // W = 0
3290 let Inst{22} = 0; // D = 0
3291 let Inst{20} = load;
3294 def _PRE : ACI<(outs),
3295 (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3296 opc, "\tp$cop, cr$CRd, $addr!"> {
3297 let Inst{31-28} = op31_28;
3298 let Inst{24} = 1; // P = 1
3299 let Inst{21} = 1; // W = 1
3300 let Inst{22} = 0; // D = 0
3301 let Inst{20} = load;
3304 def _POST : ACI<(outs),
3305 (ins nohash_imm:$cop, nohash_imm:$CRd, GPR:$base, am2offset:$offset),
3306 opc, "\tp$cop, cr$CRd, [$base], $offset"> {
3307 let Inst{31-28} = op31_28;
3308 let Inst{24} = 0; // P = 0
3309 let Inst{21} = 1; // W = 1
3310 let Inst{22} = 0; // D = 0
3311 let Inst{20} = load;
3314 def _OPTION : ACI<(outs),
3315 (ins nohash_imm:$cop, nohash_imm:$CRd, GPR:$base, i32imm:$option),
3316 opc, "\tp$cop, cr$CRd, [$base], $option"> {
3317 let Inst{31-28} = op31_28;
3318 let Inst{24} = 0; // P = 0
3319 let Inst{23} = 1; // U = 1
3320 let Inst{21} = 0; // W = 0
3321 let Inst{22} = 0; // D = 0
3322 let Inst{20} = load;
3325 def L_OFFSET : ACI<(outs),
3326 (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3327 !strconcat(opc, "l"), "\tp$cop, cr$CRd, $addr"> {
3328 let Inst{31-28} = op31_28;
3329 let Inst{24} = 1; // P = 1
3330 let Inst{21} = 0; // W = 0
3331 let Inst{22} = 1; // D = 1
3332 let Inst{20} = load;
3335 def L_PRE : ACI<(outs),
3336 (ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr),
3337 !strconcat(opc, "l"), "\tp$cop, cr$CRd, $addr!"> {
3338 let Inst{31-28} = op31_28;
3339 let Inst{24} = 1; // P = 1
3340 let Inst{21} = 1; // W = 1
3341 let Inst{22} = 1; // D = 1
3342 let Inst{20} = load;
3345 def L_POST : ACI<(outs),
3346 (ins nohash_imm:$cop, nohash_imm:$CRd, GPR:$base, am2offset:$offset),
3347 !strconcat(opc, "l"), "\tp$cop, cr$CRd, [$base], $offset"> {
3348 let Inst{31-28} = op31_28;
3349 let Inst{24} = 0; // P = 0
3350 let Inst{21} = 1; // W = 1
3351 let Inst{22} = 1; // D = 1
3352 let Inst{20} = load;
3355 def L_OPTION : ACI<(outs),
3356 (ins nohash_imm:$cop, nohash_imm:$CRd, GPR:$base, nohash_imm:$option),
3357 !strconcat(opc, "l"), "\tp$cop, cr$CRd, [$base], $option"> {
3358 let Inst{31-28} = op31_28;
3359 let Inst{24} = 0; // P = 0
3360 let Inst{23} = 1; // U = 1
3361 let Inst{21} = 0; // W = 0
3362 let Inst{22} = 1; // D = 1
3363 let Inst{20} = load;
3367 defm LDC : LdStCop<{?,?,?,?}, 1, "ldc">;
3368 defm LDC2 : LdStCop<0b1111, 1, "ldc2">;
3369 defm STC : LdStCop<{?,?,?,?}, 0, "stc">;
3370 defm STC2 : LdStCop<0b1111, 0, "stc2">;
3372 def MCR : ABI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
3373 GPR:$Rt, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
3374 NoItinerary, "mcr", "\tp$cop, $opc1, $Rt, cr$CRn, cr$CRm, $opc2",
3375 [/* For disassembly only; pattern left blank */]> {
3380 def MCR2 : ABXI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
3381 GPR:$Rt, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
3382 NoItinerary, "mcr2\tp$cop, $opc1, $Rt, cr$CRn, cr$CRm, $opc2",
3383 [/* For disassembly only; pattern left blank */]> {
3384 let Inst{31-28} = 0b1111;
3389 def MRC : ABI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
3390 GPR:$Rt, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
3391 NoItinerary, "mrc", "\tp$cop, $opc1, $Rt, cr$CRn, cr$CRm, $opc2",
3392 [/* For disassembly only; pattern left blank */]> {
3397 def MRC2 : ABXI<0b1110, (outs), (ins nohash_imm:$cop, i32imm:$opc1,
3398 GPR:$Rt, nohash_imm:$CRn, nohash_imm:$CRm, i32imm:$opc2),
3399 NoItinerary, "mrc2\tp$cop, $opc1, $Rt, cr$CRn, cr$CRm, $opc2",
3400 [/* For disassembly only; pattern left blank */]> {
3401 let Inst{31-28} = 0b1111;
3406 def MCRR : ABI<0b1100, (outs), (ins nohash_imm:$cop, i32imm:$opc,
3407 GPR:$Rt, GPR:$Rt2, nohash_imm:$CRm),
3408 NoItinerary, "mcrr", "\tp$cop, $opc, $Rt, $Rt2, cr$CRm",
3409 [/* For disassembly only; pattern left blank */]> {
3410 let Inst{23-20} = 0b0100;
3413 def MCRR2 : ABXI<0b1100, (outs), (ins nohash_imm:$cop, i32imm:$opc,
3414 GPR:$Rt, GPR:$Rt2, nohash_imm:$CRm),
3415 NoItinerary, "mcrr2\tp$cop, $opc, $Rt, $Rt2, cr$CRm",
3416 [/* For disassembly only; pattern left blank */]> {
3417 let Inst{31-28} = 0b1111;
3418 let Inst{23-20} = 0b0100;
3421 def MRRC : ABI<0b1100, (outs), (ins nohash_imm:$cop, i32imm:$opc,
3422 GPR:$Rt, GPR:$Rt2, nohash_imm:$CRm),
3423 NoItinerary, "mrrc", "\tp$cop, $opc, $Rt, $Rt2, cr$CRm",
3424 [/* For disassembly only; pattern left blank */]> {
3425 let Inst{23-20} = 0b0101;
3428 def MRRC2 : ABXI<0b1100, (outs), (ins nohash_imm:$cop, i32imm:$opc,
3429 GPR:$Rt, GPR:$Rt2, nohash_imm:$CRm),
3430 NoItinerary, "mrrc2\tp$cop, $opc, $Rt, $Rt2, cr$CRm",
3431 [/* For disassembly only; pattern left blank */]> {
3432 let Inst{31-28} = 0b1111;
3433 let Inst{23-20} = 0b0101;
3436 //===----------------------------------------------------------------------===//
3437 // Move between special register and ARM core register -- for disassembly only
3440 def MRS : ABI<0b0001,(outs GPR:$dst),(ins), NoItinerary, "mrs", "\t$dst, cpsr",
3441 [/* For disassembly only; pattern left blank */]> {
3442 let Inst{23-20} = 0b0000;
3443 let Inst{7-4} = 0b0000;
3446 def MRSsys : ABI<0b0001,(outs GPR:$dst),(ins), NoItinerary,"mrs","\t$dst, spsr",
3447 [/* For disassembly only; pattern left blank */]> {
3448 let Inst{23-20} = 0b0100;
3449 let Inst{7-4} = 0b0000;
3452 def MSR : ABI<0b0001, (outs), (ins GPR:$src, msr_mask:$mask), NoItinerary,
3453 "msr", "\tcpsr$mask, $src",
3454 [/* For disassembly only; pattern left blank */]> {
3455 let Inst{23-20} = 0b0010;
3456 let Inst{7-4} = 0b0000;
3459 def MSRi : ABI<0b0011, (outs), (ins so_imm:$a, msr_mask:$mask), NoItinerary,
3460 "msr", "\tcpsr$mask, $a",
3461 [/* For disassembly only; pattern left blank */]> {
3462 let Inst{23-20} = 0b0010;
3463 let Inst{7-4} = 0b0000;
3466 def MSRsys : ABI<0b0001, (outs), (ins GPR:$src, msr_mask:$mask), NoItinerary,
3467 "msr", "\tspsr$mask, $src",
3468 [/* For disassembly only; pattern left blank */]> {
3469 let Inst{23-20} = 0b0110;
3470 let Inst{7-4} = 0b0000;
3473 def MSRsysi : ABI<0b0011, (outs), (ins so_imm:$a, msr_mask:$mask), NoItinerary,
3474 "msr", "\tspsr$mask, $a",
3475 [/* For disassembly only; pattern left blank */]> {
3476 let Inst{23-20} = 0b0110;
3477 let Inst{7-4} = 0b0000;