Fix predicate for imm1_32
[oota-llvm.git] / lib / Target / ARM / ARMInstrInfo.td
1 //===- ARMInstrInfo.td - Target Description for ARM Target -*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the ARM instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // ARM specific DAG Nodes.
16 //
17
18 // Type profiles.
19 def SDT_ARMCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
20 def SDT_ARMCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>;
21
22 def SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
23
24 def SDT_ARMcall    : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
25
26 def SDT_ARMCMov    : SDTypeProfile<1, 3,
27                                    [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
28                                     SDTCisVT<3, i32>]>;
29
30 def SDT_ARMBrcond  : SDTypeProfile<0, 2,
31                                    [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
32
33 def SDT_ARMBrJT    : SDTypeProfile<0, 3,
34                                   [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
35                                    SDTCisVT<2, i32>]>;
36
37 def SDT_ARMBr2JT   : SDTypeProfile<0, 4,
38                                   [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
39                                    SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
40
41 def SDT_ARMBCC_i64 : SDTypeProfile<0, 6,
42                                   [SDTCisVT<0, i32>,
43                                    SDTCisVT<1, i32>, SDTCisVT<2, i32>,
44                                    SDTCisVT<3, i32>, SDTCisVT<4, i32>,
45                                    SDTCisVT<5, OtherVT>]>;
46
47 def SDT_ARMAnd     : SDTypeProfile<1, 2,
48                                    [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
49                                     SDTCisVT<2, i32>]>;
50
51 def SDT_ARMCmp     : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
52
53 def SDT_ARMPICAdd  : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
54                                           SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
55
56 def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
57 def SDT_ARMEH_SJLJ_Setjmp : SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisPtrTy<1>,
58                                                  SDTCisInt<2>]>;
59 def SDT_ARMEH_SJLJ_Longjmp: SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisInt<1>]>;
60
61 def SDT_ARMEH_SJLJ_DispatchSetup: SDTypeProfile<0, 1, [SDTCisInt<0>]>;
62
63 def SDT_ARMMEMBARRIER     : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
64
65 def SDT_ARMPREFETCH : SDTypeProfile<0, 3, [SDTCisPtrTy<0>, SDTCisSameAs<1, 2>,
66                                            SDTCisInt<1>]>;
67
68 def SDT_ARMTCRET : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
69
70 def SDT_ARMBFI : SDTypeProfile<1, 3, [SDTCisVT<0, i32>, SDTCisVT<1, i32>,
71                                       SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
72
73 // Node definitions.
74 def ARMWrapper       : SDNode<"ARMISD::Wrapper",     SDTIntUnaryOp>;
75 def ARMWrapperDYN    : SDNode<"ARMISD::WrapperDYN",  SDTIntUnaryOp>;
76 def ARMWrapperPIC    : SDNode<"ARMISD::WrapperPIC",  SDTIntUnaryOp>;
77 def ARMWrapperJT     : SDNode<"ARMISD::WrapperJT",   SDTIntBinOp>;
78
79 def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
80                               [SDNPHasChain, SDNPOutGlue]>;
81 def ARMcallseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_ARMCallSeqEnd,
82                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
83
84 def ARMcall          : SDNode<"ARMISD::CALL", SDT_ARMcall,
85                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
86                                SDNPVariadic]>;
87 def ARMcall_pred    : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
88                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
89                                SDNPVariadic]>;
90 def ARMcall_nolink   : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
91                               [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
92                                SDNPVariadic]>;
93
94 def ARMretflag       : SDNode<"ARMISD::RET_FLAG", SDTNone,
95                               [SDNPHasChain, SDNPOptInGlue]>;
96
97 def ARMcmov          : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
98                               [SDNPInGlue]>;
99
100 def ARMbrcond        : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
101                               [SDNPHasChain, SDNPInGlue, SDNPOutGlue]>;
102
103 def ARMbrjt          : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
104                               [SDNPHasChain]>;
105 def ARMbr2jt         : SDNode<"ARMISD::BR2_JT", SDT_ARMBr2JT,
106                               [SDNPHasChain]>;
107
108 def ARMBcci64        : SDNode<"ARMISD::BCC_i64", SDT_ARMBCC_i64,
109                               [SDNPHasChain]>;
110
111 def ARMcmp           : SDNode<"ARMISD::CMP", SDT_ARMCmp,
112                               [SDNPOutGlue]>;
113
114 def ARMcmpZ          : SDNode<"ARMISD::CMPZ", SDT_ARMCmp,
115                               [SDNPOutGlue, SDNPCommutative]>;
116
117 def ARMpic_add       : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
118
119 def ARMsrl_flag      : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutGlue]>;
120 def ARMsra_flag      : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutGlue]>;
121 def ARMrrx           : SDNode<"ARMISD::RRX"     , SDTIntUnaryOp, [SDNPInGlue ]>;
122
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]>;
130
131
132 def ARMMemBarrier     : SDNode<"ARMISD::MEMBARRIER", SDT_ARMMEMBARRIER,
133                                [SDNPHasChain]>;
134 def ARMMemBarrierMCR  : SDNode<"ARMISD::MEMBARRIER_MCR", SDT_ARMMEMBARRIER,
135                                [SDNPHasChain]>;
136 def ARMPreload        : SDNode<"ARMISD::PRELOAD", SDT_ARMPREFETCH,
137                                [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
138
139 def ARMrbit          : SDNode<"ARMISD::RBIT", SDTIntUnaryOp>;
140
141 def ARMtcret         : SDNode<"ARMISD::TC_RETURN", SDT_ARMTCRET,
142                         [SDNPHasChain,  SDNPOptInGlue, SDNPVariadic]>;
143
144
145 def ARMbfi           : SDNode<"ARMISD::BFI", SDT_ARMBFI>;
146
147 //===----------------------------------------------------------------------===//
148 // ARM Instruction Predicate Definitions.
149 //
150 def HasV4T           : Predicate<"Subtarget->hasV4TOps()">,
151                                  AssemblerPredicate<"HasV4TOps">;
152 def NoV4T            : Predicate<"!Subtarget->hasV4TOps()">;
153 def HasV5T           : Predicate<"Subtarget->hasV5TOps()">;
154 def HasV5TE          : Predicate<"Subtarget->hasV5TEOps()">,
155                                  AssemblerPredicate<"HasV5TEOps">;
156 def HasV6            : Predicate<"Subtarget->hasV6Ops()">,
157                                  AssemblerPredicate<"HasV6Ops">;
158 def NoV6             : Predicate<"!Subtarget->hasV6Ops()">;
159 def HasV6T2          : Predicate<"Subtarget->hasV6T2Ops()">,
160                                  AssemblerPredicate<"HasV6T2Ops">;
161 def NoV6T2           : Predicate<"!Subtarget->hasV6T2Ops()">;
162 def HasV7            : Predicate<"Subtarget->hasV7Ops()">,
163                                  AssemblerPredicate<"HasV7Ops">;
164 def NoVFP            : Predicate<"!Subtarget->hasVFP2()">;
165 def HasVFP2          : Predicate<"Subtarget->hasVFP2()">,
166                                  AssemblerPredicate<"FeatureVFP2">;
167 def HasVFP3          : Predicate<"Subtarget->hasVFP3()">,
168                                  AssemblerPredicate<"FeatureVFP3">;
169 def HasNEON          : Predicate<"Subtarget->hasNEON()">,
170                                  AssemblerPredicate<"FeatureNEON">;
171 def HasFP16          : Predicate<"Subtarget->hasFP16()">,
172                                  AssemblerPredicate<"FeatureFP16">;
173 def HasDivide        : Predicate<"Subtarget->hasDivide()">,
174                                  AssemblerPredicate<"FeatureHWDiv">;
175 def HasT2ExtractPack : Predicate<"Subtarget->hasT2ExtractPack()">,
176                                  AssemblerPredicate<"FeatureT2XtPk">;
177 def HasThumb2DSP     : Predicate<"Subtarget->hasThumb2DSP()">,
178                                  AssemblerPredicate<"FeatureDSPThumb2">;
179 def HasDB            : Predicate<"Subtarget->hasDataBarrier()">,
180                                  AssemblerPredicate<"FeatureDB">;
181 def HasMP            : Predicate<"Subtarget->hasMPExtension()">,
182                                  AssemblerPredicate<"FeatureMP">;
183 def UseNEONForFP     : Predicate<"Subtarget->useNEONForSinglePrecisionFP()">;
184 def DontUseNEONForFP : Predicate<"!Subtarget->useNEONForSinglePrecisionFP()">;
185 def IsThumb          : Predicate<"Subtarget->isThumb()">,
186                                  AssemblerPredicate<"ModeThumb">;
187 def IsThumb1Only     : Predicate<"Subtarget->isThumb1Only()">;
188 def IsThumb2         : Predicate<"Subtarget->isThumb2()">,
189                                  AssemblerPredicate<"ModeThumb,FeatureThumb2">;
190 def IsARM            : Predicate<"!Subtarget->isThumb()">,
191                                  AssemblerPredicate<"!ModeThumb">;
192 def IsDarwin         : Predicate<"Subtarget->isTargetDarwin()">;
193 def IsNotDarwin      : Predicate<"!Subtarget->isTargetDarwin()">;
194
195 // FIXME: Eventually this will be just "hasV6T2Ops".
196 def UseMovt          : Predicate<"Subtarget->useMovt()">;
197 def DontUseMovt      : Predicate<"!Subtarget->useMovt()">;
198 def UseFPVMLx        : Predicate<"Subtarget->useFPVMLx()">;
199
200 //===----------------------------------------------------------------------===//
201 // ARM Flag Definitions.
202
203 class RegConstraint<string C> {
204   string Constraints = C;
205 }
206
207 //===----------------------------------------------------------------------===//
208 //  ARM specific transformation functions and pattern fragments.
209 //
210
211 // so_imm_neg_XFORM - Return a so_imm value packed into the format described for
212 // so_imm_neg def below.
213 def so_imm_neg_XFORM : SDNodeXForm<imm, [{
214   return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
215 }]>;
216
217 // so_imm_not_XFORM - Return a so_imm value packed into the format described for
218 // so_imm_not def below.
219 def so_imm_not_XFORM : SDNodeXForm<imm, [{
220   return CurDAG->getTargetConstant(~(int)N->getZExtValue(), MVT::i32);
221 }]>;
222
223 /// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
224 def imm1_15 : ImmLeaf<i32, [{
225   return (int32_t)Imm >= 1 && (int32_t)Imm < 16;
226 }]>;
227
228 /// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
229 def imm16_31 : ImmLeaf<i32, [{
230   return (int32_t)Imm >= 16 && (int32_t)Imm < 32;
231 }]>;
232
233 def so_imm_neg :
234   PatLeaf<(imm), [{
235     return ARM_AM::getSOImmVal(-(uint32_t)N->getZExtValue()) != -1;
236   }], so_imm_neg_XFORM>;
237
238 def so_imm_not :
239   PatLeaf<(imm), [{
240     return ARM_AM::getSOImmVal(~(uint32_t)N->getZExtValue()) != -1;
241   }], so_imm_not_XFORM>;
242
243 // sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
244 def sext_16_node : PatLeaf<(i32 GPR:$a), [{
245   return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
246 }]>;
247
248 /// Split a 32-bit immediate into two 16 bit parts.
249 def hi16 : SDNodeXForm<imm, [{
250   return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
251 }]>;
252
253 def lo16AllZero : PatLeaf<(i32 imm), [{
254   // Returns true if all low 16-bits are 0.
255   return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
256 }], hi16>;
257
258 /// imm0_65535 - An immediate is in the range [0.65535].
259 def Imm0_65535AsmOperand: AsmOperandClass { let Name = "Imm0_65535"; }
260 def imm0_65535 : Operand<i32>, ImmLeaf<i32, [{
261   return Imm >= 0 && Imm < 65536;
262 }]> {
263   let ParserMatchClass = Imm0_65535AsmOperand;
264 }
265
266 class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
267 class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
268
269 /// adde and sube predicates - True based on whether the carry flag output
270 /// will be needed or not.
271 def adde_dead_carry :
272   PatFrag<(ops node:$LHS, node:$RHS), (adde node:$LHS, node:$RHS),
273   [{return !N->hasAnyUseOfValue(1);}]>;
274 def sube_dead_carry :
275   PatFrag<(ops node:$LHS, node:$RHS), (sube node:$LHS, node:$RHS),
276   [{return !N->hasAnyUseOfValue(1);}]>;
277 def adde_live_carry :
278   PatFrag<(ops node:$LHS, node:$RHS), (adde node:$LHS, node:$RHS),
279   [{return N->hasAnyUseOfValue(1);}]>;
280 def sube_live_carry :
281   PatFrag<(ops node:$LHS, node:$RHS), (sube node:$LHS, node:$RHS),
282   [{return N->hasAnyUseOfValue(1);}]>;
283
284 // An 'and' node with a single use.
285 def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
286   return N->hasOneUse();
287 }]>;
288
289 // An 'xor' node with a single use.
290 def xor_su : PatFrag<(ops node:$lhs, node:$rhs), (xor node:$lhs, node:$rhs), [{
291   return N->hasOneUse();
292 }]>;
293
294 // An 'fmul' node with a single use.
295 def fmul_su : PatFrag<(ops node:$lhs, node:$rhs), (fmul node:$lhs, node:$rhs),[{
296   return N->hasOneUse();
297 }]>;
298
299 // An 'fadd' node which checks for single non-hazardous use.
300 def fadd_mlx : PatFrag<(ops node:$lhs, node:$rhs),(fadd node:$lhs, node:$rhs),[{
301   return hasNoVMLxHazardUse(N);
302 }]>;
303
304 // An 'fsub' node which checks for single non-hazardous use.
305 def fsub_mlx : PatFrag<(ops node:$lhs, node:$rhs),(fsub node:$lhs, node:$rhs),[{
306   return hasNoVMLxHazardUse(N);
307 }]>;
308
309 //===----------------------------------------------------------------------===//
310 // Operand Definitions.
311 //
312
313 // Branch target.
314 // FIXME: rename brtarget to t2_brtarget
315 def brtarget : Operand<OtherVT> {
316   let EncoderMethod = "getBranchTargetOpValue";
317   let OperandType = "OPERAND_PCREL";
318   let DecoderMethod = "DecodeT2BROperand";
319 }
320
321 // FIXME: get rid of this one?
322 def uncondbrtarget : Operand<OtherVT> {
323   let EncoderMethod = "getUnconditionalBranchTargetOpValue";
324   let OperandType = "OPERAND_PCREL";
325 }
326
327 // Branch target for ARM. Handles conditional/unconditional
328 def br_target : Operand<OtherVT> {
329   let EncoderMethod = "getARMBranchTargetOpValue";
330   let OperandType = "OPERAND_PCREL";
331 }
332
333 // Call target.
334 // FIXME: rename bltarget to t2_bl_target?
335 def bltarget : Operand<i32> {
336   // Encoded the same as branch targets.
337   let EncoderMethod = "getBranchTargetOpValue";
338   let OperandType = "OPERAND_PCREL";
339 }
340
341 // Call target for ARM. Handles conditional/unconditional
342 // FIXME: rename bl_target to t2_bltarget?
343 def bl_target : Operand<i32> {
344   // Encoded the same as branch targets.
345   let EncoderMethod = "getARMBranchTargetOpValue";
346   let OperandType = "OPERAND_PCREL";
347   let DecoderMethod = "DecodeBLTargetOperand";
348 }
349
350
351 // A list of registers separated by comma. Used by load/store multiple.
352 def RegListAsmOperand : AsmOperandClass { let Name = "RegList"; }
353 def reglist : Operand<i32> {
354   let EncoderMethod = "getRegisterListOpValue";
355   let ParserMatchClass = RegListAsmOperand;
356   let PrintMethod = "printRegisterList";
357   let DecoderMethod = "DecodeRegListOperand";
358 }
359
360 def DPRRegListAsmOperand : AsmOperandClass { let Name = "DPRRegList"; }
361 def dpr_reglist : Operand<i32> {
362   let EncoderMethod = "getRegisterListOpValue";
363   let ParserMatchClass = DPRRegListAsmOperand;
364   let PrintMethod = "printRegisterList";
365   let DecoderMethod = "DecodeDPRRegListOperand";
366 }
367
368 def SPRRegListAsmOperand : AsmOperandClass { let Name = "SPRRegList"; }
369 def spr_reglist : Operand<i32> {
370   let EncoderMethod = "getRegisterListOpValue";
371   let ParserMatchClass = SPRRegListAsmOperand;
372   let PrintMethod = "printRegisterList";
373   let DecoderMethod = "DecodeSPRRegListOperand";
374 }
375
376 // An operand for the CONSTPOOL_ENTRY pseudo-instruction.
377 def cpinst_operand : Operand<i32> {
378   let PrintMethod = "printCPInstOperand";
379 }
380
381 // Local PC labels.
382 def pclabel : Operand<i32> {
383   let PrintMethod = "printPCLabel";
384 }
385
386 // ADR instruction labels.
387 def adrlabel : Operand<i32> {
388   let EncoderMethod = "getAdrLabelOpValue";
389 }
390
391 def neon_vcvt_imm32 : Operand<i32> {
392   let EncoderMethod = "getNEONVcvtImm32OpValue";
393   let DecoderMethod = "DecodeVCVTImmOperand";
394 }
395
396 // rot_imm: An integer that encodes a rotate amount. Must be 8, 16, or 24.
397 def rot_imm_XFORM: SDNodeXForm<imm, [{
398   switch (N->getZExtValue()){
399   default: assert(0);
400   case 0:  return CurDAG->getTargetConstant(0, MVT::i32);
401   case 8:  return CurDAG->getTargetConstant(1, MVT::i32);
402   case 16: return CurDAG->getTargetConstant(2, MVT::i32);
403   case 24: return CurDAG->getTargetConstant(3, MVT::i32);
404   }
405 }]>;
406 def RotImmAsmOperand : AsmOperandClass {
407   let Name = "RotImm";
408   let ParserMethod = "parseRotImm";
409 }
410 def rot_imm : Operand<i32>, PatLeaf<(i32 imm), [{
411     int32_t v = N->getZExtValue();
412     return v == 8 || v == 16 || v == 24; }],
413     rot_imm_XFORM> {
414   let PrintMethod = "printRotImmOperand";
415   let ParserMatchClass = RotImmAsmOperand;
416 }
417
418 // shift_imm: An integer that encodes a shift amount and the type of shift
419 // (asr or lsl). The 6-bit immediate encodes as:
420 //    {5}     0 ==> lsl
421 //            1     asr
422 //    {4-0}   imm5 shift amount.
423 //            asr #32 encoded as imm5 == 0.
424 def ShifterImmAsmOperand : AsmOperandClass {
425   let Name = "ShifterImm";
426   let ParserMethod = "parseShifterImm";
427 }
428 def shift_imm : Operand<i32> {
429   let PrintMethod = "printShiftImmOperand";
430   let ParserMatchClass = ShifterImmAsmOperand;
431 }
432
433 // shifter_operand operands: so_reg_reg, so_reg_imm, and so_imm.
434 def ShiftedRegAsmOperand : AsmOperandClass { let Name = "RegShiftedReg"; }
435 def so_reg_reg : Operand<i32>,  // reg reg imm
436                  ComplexPattern<i32, 3, "SelectRegShifterOperand",
437                                 [shl, srl, sra, rotr]> {
438   let EncoderMethod = "getSORegRegOpValue";
439   let PrintMethod = "printSORegRegOperand";
440   let DecoderMethod = "DecodeSORegRegOperand";
441   let ParserMatchClass = ShiftedRegAsmOperand;
442   let MIOperandInfo = (ops GPRnopc, GPRnopc, i32imm);
443 }
444
445 def ShiftedImmAsmOperand : AsmOperandClass { let Name = "RegShiftedImm"; }
446 def so_reg_imm : Operand<i32>, // reg imm
447                  ComplexPattern<i32, 2, "SelectImmShifterOperand",
448                                 [shl, srl, sra, rotr]> {
449   let EncoderMethod = "getSORegImmOpValue";
450   let PrintMethod = "printSORegImmOperand";
451   let DecoderMethod = "DecodeSORegImmOperand";
452   let ParserMatchClass = ShiftedImmAsmOperand;
453   let MIOperandInfo = (ops GPR, i32imm);
454 }
455
456 // FIXME: Does this need to be distinct from so_reg?
457 def shift_so_reg_reg : Operand<i32>,    // reg reg imm
458                    ComplexPattern<i32, 3, "SelectShiftRegShifterOperand",
459                                   [shl,srl,sra,rotr]> {
460   let EncoderMethod = "getSORegRegOpValue";
461   let PrintMethod = "printSORegRegOperand";
462   let DecoderMethod = "DecodeSORegRegOperand";
463   let MIOperandInfo = (ops GPR, GPR, i32imm);
464 }
465
466 // FIXME: Does this need to be distinct from so_reg?
467 def shift_so_reg_imm : Operand<i32>,    // reg reg imm
468                    ComplexPattern<i32, 2, "SelectShiftImmShifterOperand",
469                                   [shl,srl,sra,rotr]> {
470   let EncoderMethod = "getSORegImmOpValue";
471   let PrintMethod = "printSORegImmOperand";
472   let DecoderMethod = "DecodeSORegImmOperand";
473   let MIOperandInfo = (ops GPR, i32imm);
474 }
475
476
477 // so_imm - Match a 32-bit shifter_operand immediate operand, which is an
478 // 8-bit immediate rotated by an arbitrary number of bits.
479 def SOImmAsmOperand: AsmOperandClass { let Name = "ARMSOImm"; }
480 def so_imm : Operand<i32>, ImmLeaf<i32, [{
481     return ARM_AM::getSOImmVal(Imm) != -1;
482   }]> {
483   let EncoderMethod = "getSOImmOpValue";
484   let ParserMatchClass = SOImmAsmOperand;
485   let DecoderMethod = "DecodeSOImmOperand";
486 }
487
488 // Break so_imm's up into two pieces.  This handles immediates with up to 16
489 // bits set in them.  This uses so_imm2part to match and so_imm2part_[12] to
490 // get the first/second pieces.
491 def so_imm2part : PatLeaf<(imm), [{
492       return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
493 }]>;
494
495 /// arm_i32imm - True for +V6T2, or true only if so_imm2part is true.
496 ///
497 def arm_i32imm : PatLeaf<(imm), [{
498   if (Subtarget->hasV6T2Ops())
499     return true;
500   return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
501 }]>;
502
503 /// imm0_7 predicate - Immediate in the range [0,7].
504 def Imm0_7AsmOperand: AsmOperandClass { let Name = "Imm0_7"; }
505 def imm0_7 : Operand<i32>, ImmLeaf<i32, [{
506   return Imm >= 0 && Imm < 8;
507 }]> {
508   let ParserMatchClass = Imm0_7AsmOperand;
509 }
510
511 /// imm0_15 predicate - Immediate in the range [0,15].
512 def Imm0_15AsmOperand: AsmOperandClass { let Name = "Imm0_15"; }
513 def imm0_15 : Operand<i32>, ImmLeaf<i32, [{
514   return Imm >= 0 && Imm < 16;
515 }]> {
516   let ParserMatchClass = Imm0_15AsmOperand;
517 }
518
519 /// imm0_31 predicate - True if the 32-bit immediate is in the range [0,31].
520 def Imm0_31AsmOperand: AsmOperandClass { let Name = "Imm0_31"; }
521 def imm0_31 : Operand<i32>, ImmLeaf<i32, [{
522   return Imm >= 0 && Imm < 32;
523 }]> {
524   let ParserMatchClass = Imm0_31AsmOperand;
525 }
526
527 /// imm0_255 predicate - Immediate in the range [0,255].
528 def Imm0_255AsmOperand : AsmOperandClass { let Name = "Imm0_255"; }
529 def imm0_255 : Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 256; }]> {
530   let ParserMatchClass = Imm0_255AsmOperand;
531 }
532
533 // imm0_65535_expr - For movt/movw - 16-bit immediate that can also reference
534 // a relocatable expression.
535 //
536 // FIXME: This really needs a Thumb version separate from the ARM version.
537 // While the range is the same, and can thus use the same match class,
538 // the encoding is different so it should have a different encoder method.
539 def Imm0_65535ExprAsmOperand: AsmOperandClass { let Name = "Imm0_65535Expr"; }
540 def imm0_65535_expr : Operand<i32> {
541   let EncoderMethod = "getHiLo16ImmOpValue";
542   let ParserMatchClass = Imm0_65535ExprAsmOperand;
543 }
544
545 /// imm24b - True if the 32-bit immediate is encodable in 24 bits.
546 def Imm24bitAsmOperand: AsmOperandClass { let Name = "Imm24bit"; }
547 def imm24b : Operand<i32>, ImmLeaf<i32, [{
548   return Imm >= 0 && Imm <= 0xffffff;
549 }]> {
550   let ParserMatchClass = Imm24bitAsmOperand;
551 }
552
553
554 /// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
555 /// e.g., 0xf000ffff
556 def BitfieldAsmOperand : AsmOperandClass {
557   let Name = "Bitfield";
558   let ParserMethod = "parseBitfield";
559 }
560 def bf_inv_mask_imm : Operand<i32>,
561                       PatLeaf<(imm), [{
562   return ARM::isBitFieldInvertedMask(N->getZExtValue());
563 }] > {
564   let EncoderMethod = "getBitfieldInvertedMaskOpValue";
565   let PrintMethod = "printBitfieldInvMaskImmOperand";
566   let DecoderMethod = "DecodeBitfieldMaskOperand";
567   let ParserMatchClass = BitfieldAsmOperand;
568 }
569
570 /// lsb_pos_imm - position of the lsb bit, used by BFI4p and t2BFI4p
571 def lsb_pos_imm : Operand<i32>, ImmLeaf<i32, [{
572   return isInt<5>(Imm);
573 }]>;
574
575 /// width_imm - number of bits to be copied, used by BFI4p and t2BFI4p
576 def width_imm : Operand<i32>, ImmLeaf<i32, [{
577   return Imm > 0 &&  Imm <= 32;
578 }] > {
579   let EncoderMethod = "getMsbOpValue";
580 }
581
582 def imm1_32_XFORM: SDNodeXForm<imm, [{
583   return CurDAG->getTargetConstant((int)N->getZExtValue() - 1, MVT::i32);
584 }]>;
585 def Imm1_32AsmOperand: AsmOperandClass { let Name = "Imm1_32"; }
586 def imm1_32 : Operand<i32>, PatLeaf<(imm), [{
587    uint64_t Imm = N->getZExtValue();
588    return Imm > 0 && Imm <= 32;
589  }],
590     imm1_32_XFORM> {
591   let PrintMethod = "printImmPlusOneOperand";
592   let ParserMatchClass = Imm1_32AsmOperand;
593 }
594
595 def imm1_16_XFORM: SDNodeXForm<imm, [{
596   return CurDAG->getTargetConstant((int)N->getZExtValue() - 1, MVT::i32);
597 }]>;
598 def Imm1_16AsmOperand: AsmOperandClass { let Name = "Imm1_16"; }
599 def imm1_16 : Operand<i32>, PatLeaf<(imm), [{ return Imm > 0 && Imm <= 16; }],
600     imm1_16_XFORM> {
601   let PrintMethod = "printImmPlusOneOperand";
602   let ParserMatchClass = Imm1_16AsmOperand;
603 }
604
605 // Define ARM specific addressing modes.
606 // addrmode_imm12 := reg +/- imm12
607 //
608 def MemImm12OffsetAsmOperand : AsmOperandClass { let Name = "MemImm12Offset"; }
609 def addrmode_imm12 : Operand<i32>,
610                      ComplexPattern<i32, 2, "SelectAddrModeImm12", []> {
611   // 12-bit immediate operand. Note that instructions using this encode
612   // #0 and #-0 differently. We flag #-0 as the magic value INT32_MIN. All other
613   // immediate values are as normal.
614
615   let EncoderMethod = "getAddrModeImm12OpValue";
616   let PrintMethod = "printAddrModeImm12Operand";
617   let DecoderMethod = "DecodeAddrModeImm12Operand";
618   let ParserMatchClass = MemImm12OffsetAsmOperand;
619   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
620 }
621 // ldst_so_reg := reg +/- reg shop imm
622 //
623 def MemRegOffsetAsmOperand : AsmOperandClass { let Name = "MemRegOffset"; }
624 def ldst_so_reg : Operand<i32>,
625                   ComplexPattern<i32, 3, "SelectLdStSOReg", []> {
626   let EncoderMethod = "getLdStSORegOpValue";
627   // FIXME: Simplify the printer
628   let PrintMethod = "printAddrMode2Operand";
629   let DecoderMethod = "DecodeSORegMemOperand";
630   let ParserMatchClass = MemRegOffsetAsmOperand;
631   let MIOperandInfo = (ops GPR:$base, GPRnopc:$offsreg, i32imm:$shift);
632 }
633
634 // postidx_imm8 := +/- [0,255]
635 //
636 // 9 bit value:
637 //  {8}       1 is imm8 is non-negative. 0 otherwise.
638 //  {7-0}     [0,255] imm8 value.
639 def PostIdxImm8AsmOperand : AsmOperandClass { let Name = "PostIdxImm8"; }
640 def postidx_imm8 : Operand<i32> {
641   let PrintMethod = "printPostIdxImm8Operand";
642   let ParserMatchClass = PostIdxImm8AsmOperand;
643   let MIOperandInfo = (ops i32imm);
644 }
645
646 // postidx_imm8s4 := +/- [0,1020]
647 //
648 // 9 bit value:
649 //  {8}       1 is imm8 is non-negative. 0 otherwise.
650 //  {7-0}     [0,255] imm8 value, scaled by 4.
651 def postidx_imm8s4 : Operand<i32> {
652   let PrintMethod = "printPostIdxImm8s4Operand";
653   let MIOperandInfo = (ops i32imm);
654 }
655
656
657 // postidx_reg := +/- reg
658 //
659 def PostIdxRegAsmOperand : AsmOperandClass {
660   let Name = "PostIdxReg";
661   let ParserMethod = "parsePostIdxReg";
662 }
663 def postidx_reg : Operand<i32> {
664   let EncoderMethod = "getPostIdxRegOpValue";
665   let DecoderMethod = "DecodePostIdxReg";
666   let PrintMethod = "printPostIdxRegOperand";
667   let ParserMatchClass = PostIdxRegAsmOperand;
668   let MIOperandInfo = (ops GPR, i32imm);
669 }
670
671
672 // addrmode2 := reg +/- imm12
673 //           := reg +/- reg shop imm
674 //
675 // FIXME: addrmode2 should be refactored the rest of the way to always
676 // use explicit imm vs. reg versions above (addrmode_imm12 and ldst_so_reg).
677 def AddrMode2AsmOperand : AsmOperandClass { let Name = "AddrMode2"; }
678 def addrmode2 : Operand<i32>,
679                 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
680   let EncoderMethod = "getAddrMode2OpValue";
681   let PrintMethod = "printAddrMode2Operand";
682   let ParserMatchClass = AddrMode2AsmOperand;
683   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
684 }
685
686 def PostIdxRegShiftedAsmOperand : AsmOperandClass {
687   let Name = "PostIdxRegShifted";
688   let ParserMethod = "parsePostIdxReg";
689 }
690 def am2offset_reg : Operand<i32>,
691                 ComplexPattern<i32, 2, "SelectAddrMode2OffsetReg",
692                 [], [SDNPWantRoot]> {
693   let EncoderMethod = "getAddrMode2OffsetOpValue";
694   let PrintMethod = "printAddrMode2OffsetOperand";
695   // When using this for assembly, it's always as a post-index offset.
696   let ParserMatchClass = PostIdxRegShiftedAsmOperand;
697   let MIOperandInfo = (ops GPR, i32imm);
698 }
699
700 // FIXME: am2offset_imm should only need the immediate, not the GPR. Having
701 // the GPR is purely vestigal at this point.
702 def AM2OffsetImmAsmOperand : AsmOperandClass { let Name = "AM2OffsetImm"; }
703 def am2offset_imm : Operand<i32>,
704                 ComplexPattern<i32, 2, "SelectAddrMode2OffsetImm",
705                 [], [SDNPWantRoot]> {
706   let EncoderMethod = "getAddrMode2OffsetOpValue";
707   let PrintMethod = "printAddrMode2OffsetOperand";
708   let ParserMatchClass = AM2OffsetImmAsmOperand;
709   let MIOperandInfo = (ops GPR, i32imm);
710 }
711
712
713 // addrmode3 := reg +/- reg
714 // addrmode3 := reg +/- imm8
715 //
716 // FIXME: split into imm vs. reg versions.
717 def AddrMode3AsmOperand : AsmOperandClass { let Name = "AddrMode3"; }
718 def addrmode3 : Operand<i32>,
719                 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
720   let EncoderMethod = "getAddrMode3OpValue";
721   let PrintMethod = "printAddrMode3Operand";
722   let ParserMatchClass = AddrMode3AsmOperand;
723   let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
724 }
725
726 // FIXME: split into imm vs. reg versions.
727 // FIXME: parser method to handle +/- register.
728 def AM3OffsetAsmOperand : AsmOperandClass {
729   let Name = "AM3Offset";
730   let ParserMethod = "parseAM3Offset";
731 }
732 def am3offset : Operand<i32>,
733                 ComplexPattern<i32, 2, "SelectAddrMode3Offset",
734                                [], [SDNPWantRoot]> {
735   let EncoderMethod = "getAddrMode3OffsetOpValue";
736   let PrintMethod = "printAddrMode3OffsetOperand";
737   let ParserMatchClass = AM3OffsetAsmOperand;
738   let MIOperandInfo = (ops GPR, i32imm);
739 }
740
741 // ldstm_mode := {ia, ib, da, db}
742 //
743 def ldstm_mode : OptionalDefOperand<OtherVT, (ops i32), (ops (i32 1))> {
744   let EncoderMethod = "getLdStmModeOpValue";
745   let PrintMethod = "printLdStmModeOperand";
746 }
747
748 // addrmode5 := reg +/- imm8*4
749 //
750 def AddrMode5AsmOperand : AsmOperandClass { let Name = "AddrMode5"; }
751 def addrmode5 : Operand<i32>,
752                 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
753   let PrintMethod = "printAddrMode5Operand";
754   let EncoderMethod = "getAddrMode5OpValue";
755   let DecoderMethod = "DecodeAddrMode5Operand";
756   let ParserMatchClass = AddrMode5AsmOperand;
757   let MIOperandInfo = (ops GPR:$base, i32imm);
758 }
759
760 // addrmode6 := reg with optional alignment
761 //
762 def addrmode6 : Operand<i32>,
763                 ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
764   let PrintMethod = "printAddrMode6Operand";
765   let MIOperandInfo = (ops GPR:$addr, i32imm);
766   let EncoderMethod = "getAddrMode6AddressOpValue";
767   let DecoderMethod = "DecodeAddrMode6Operand";
768 }
769
770 def am6offset : Operand<i32>,
771                 ComplexPattern<i32, 1, "SelectAddrMode6Offset",
772                                [], [SDNPWantRoot]> {
773   let PrintMethod = "printAddrMode6OffsetOperand";
774   let MIOperandInfo = (ops GPR);
775   let EncoderMethod = "getAddrMode6OffsetOpValue";
776   let DecoderMethod = "DecodeGPRRegisterClass";
777 }
778
779 // Special version of addrmode6 to handle alignment encoding for VST1/VLD1
780 // (single element from one lane) for size 32.
781 def addrmode6oneL32 : Operand<i32>,
782                 ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
783   let PrintMethod = "printAddrMode6Operand";
784   let MIOperandInfo = (ops GPR:$addr, i32imm);
785   let EncoderMethod = "getAddrMode6OneLane32AddressOpValue";
786 }
787
788 // Special version of addrmode6 to handle alignment encoding for VLD-dup
789 // instructions, specifically VLD4-dup.
790 def addrmode6dup : Operand<i32>,
791                 ComplexPattern<i32, 2, "SelectAddrMode6", [], [SDNPWantParent]>{
792   let PrintMethod = "printAddrMode6Operand";
793   let MIOperandInfo = (ops GPR:$addr, i32imm);
794   let EncoderMethod = "getAddrMode6DupAddressOpValue";
795 }
796
797 // addrmodepc := pc + reg
798 //
799 def addrmodepc : Operand<i32>,
800                  ComplexPattern<i32, 2, "SelectAddrModePC", []> {
801   let PrintMethod = "printAddrModePCOperand";
802   let MIOperandInfo = (ops GPR, i32imm);
803 }
804
805 // addr_offset_none := reg
806 //
807 def MemNoOffsetAsmOperand : AsmOperandClass { let Name = "MemNoOffset"; }
808 def addr_offset_none : Operand<i32>,
809                        ComplexPattern<i32, 1, "SelectAddrOffsetNone", []> {
810   let PrintMethod = "printAddrMode7Operand";
811   let DecoderMethod = "DecodeAddrMode7Operand";
812   let ParserMatchClass = MemNoOffsetAsmOperand;
813   let MIOperandInfo = (ops GPR:$base);
814 }
815
816 def nohash_imm : Operand<i32> {
817   let PrintMethod = "printNoHashImmediate";
818 }
819
820 def CoprocNumAsmOperand : AsmOperandClass {
821   let Name = "CoprocNum";
822   let ParserMethod = "parseCoprocNumOperand";
823 }
824 def p_imm : Operand<i32> {
825   let PrintMethod = "printPImmediate";
826   let ParserMatchClass = CoprocNumAsmOperand;
827   let DecoderMethod = "DecodeCoprocessor";
828 }
829
830 def CoprocRegAsmOperand : AsmOperandClass {
831   let Name = "CoprocReg";
832   let ParserMethod = "parseCoprocRegOperand";
833 }
834 def c_imm : Operand<i32> {
835   let PrintMethod = "printCImmediate";
836   let ParserMatchClass = CoprocRegAsmOperand;
837 }
838
839 //===----------------------------------------------------------------------===//
840
841 include "ARMInstrFormats.td"
842
843 //===----------------------------------------------------------------------===//
844 // Multiclass helpers...
845 //
846
847 /// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
848 /// binop that produces a value.
849 multiclass AsI1_bin_irs<bits<4> opcod, string opc,
850                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
851                         PatFrag opnode, string baseOpc, bit Commutable = 0> {
852   // The register-immediate version is re-materializable. This is useful
853   // in particular for taking the address of a local.
854   let isReMaterializable = 1 in {
855   def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
856                iii, opc, "\t$Rd, $Rn, $imm",
857                [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]> {
858     bits<4> Rd;
859     bits<4> Rn;
860     bits<12> imm;
861     let Inst{25} = 1;
862     let Inst{19-16} = Rn;
863     let Inst{15-12} = Rd;
864     let Inst{11-0} = imm;
865   }
866   }
867   def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
868                iir, opc, "\t$Rd, $Rn, $Rm",
869                [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]> {
870     bits<4> Rd;
871     bits<4> Rn;
872     bits<4> Rm;
873     let Inst{25} = 0;
874     let isCommutable = Commutable;
875     let Inst{19-16} = Rn;
876     let Inst{15-12} = Rd;
877     let Inst{11-4} = 0b00000000;
878     let Inst{3-0} = Rm;
879   }
880
881   def rsi : AsI1<opcod, (outs GPR:$Rd),
882                (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm,
883                iis, opc, "\t$Rd, $Rn, $shift",
884                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_imm:$shift))]> {
885     bits<4> Rd;
886     bits<4> Rn;
887     bits<12> shift;
888     let Inst{25} = 0;
889     let Inst{19-16} = Rn;
890     let Inst{15-12} = Rd;
891     let Inst{11-5} = shift{11-5};
892     let Inst{4} = 0;
893     let Inst{3-0} = shift{3-0};
894   }
895
896   def rsr : AsI1<opcod, (outs GPR:$Rd),
897                (ins GPR:$Rn, so_reg_reg:$shift), DPSoRegRegFrm,
898                iis, opc, "\t$Rd, $Rn, $shift",
899                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_reg:$shift))]> {
900     bits<4> Rd;
901     bits<4> Rn;
902     bits<12> shift;
903     let Inst{25} = 0;
904     let Inst{19-16} = Rn;
905     let Inst{15-12} = Rd;
906     let Inst{11-8} = shift{11-8};
907     let Inst{7} = 0;
908     let Inst{6-5} = shift{6-5};
909     let Inst{4} = 1;
910     let Inst{3-0} = shift{3-0};
911   }
912
913   // Assembly aliases for optional destination operand when it's the same
914   // as the source operand.
915   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
916      (!cast<Instruction>(!strconcat(baseOpc, "ri")) GPR:$Rdn, GPR:$Rdn,
917                                                     so_imm:$imm, pred:$p,
918                                                     cc_out:$s)>,
919      Requires<[IsARM]>;
920   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $Rm"),
921      (!cast<Instruction>(!strconcat(baseOpc, "rr")) GPR:$Rdn, GPR:$Rdn,
922                                                     GPR:$Rm, pred:$p,
923                                                     cc_out:$s)>,
924      Requires<[IsARM]>;
925   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
926      (!cast<Instruction>(!strconcat(baseOpc, "rsi")) GPR:$Rdn, GPR:$Rdn,
927                                                     so_reg_imm:$shift, pred:$p,
928                                                     cc_out:$s)>,
929      Requires<[IsARM]>;
930   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
931      (!cast<Instruction>(!strconcat(baseOpc, "rsr")) GPR:$Rdn, GPR:$Rdn,
932                                                     so_reg_reg:$shift, pred:$p,
933                                                     cc_out:$s)>,
934      Requires<[IsARM]>;
935
936 }
937
938 /// AI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
939 /// instruction modifies the CPSR register.
940 let isCodeGenOnly = 1, Defs = [CPSR] in {
941 multiclass AI1_bin_s_irs<bits<4> opcod, string opc,
942                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
943                          PatFrag opnode, bit Commutable = 0> {
944   def ri : AI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
945                iii, opc, "\t$Rd, $Rn, $imm",
946                [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]> {
947     bits<4> Rd;
948     bits<4> Rn;
949     bits<12> imm;
950     let Inst{25} = 1;
951     let Inst{20} = 1;
952     let Inst{19-16} = Rn;
953     let Inst{15-12} = Rd;
954     let Inst{11-0} = imm;
955   }
956   def rr : AI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
957                iir, opc, "\t$Rd, $Rn, $Rm",
958                [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]> {
959     bits<4> Rd;
960     bits<4> Rn;
961     bits<4> Rm;
962     let isCommutable = Commutable;
963     let Inst{25} = 0;
964     let Inst{20} = 1;
965     let Inst{19-16} = Rn;
966     let Inst{15-12} = Rd;
967     let Inst{11-4} = 0b00000000;
968     let Inst{3-0} = Rm;
969   }
970   def rsi : AI1<opcod, (outs GPR:$Rd),
971                (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm,
972                iis, opc, "\t$Rd, $Rn, $shift",
973                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_imm:$shift))]> {
974     bits<4> Rd;
975     bits<4> Rn;
976     bits<12> shift;
977     let Inst{25} = 0;
978     let Inst{20} = 1;
979     let Inst{19-16} = Rn;
980     let Inst{15-12} = Rd;
981     let Inst{11-5} = shift{11-5};
982     let Inst{4} = 0;
983     let Inst{3-0} = shift{3-0};
984   }
985
986     def rsr : AI1<opcod, (outs GPR:$Rd),
987                (ins GPR:$Rn, so_reg_reg:$shift), DPSoRegRegFrm,
988                iis, opc, "\t$Rd, $Rn, $shift",
989                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_reg:$shift))]> {
990     bits<4> Rd;
991     bits<4> Rn;
992     bits<12> shift;
993     let Inst{25} = 0;
994     let Inst{20} = 1;
995     let Inst{19-16} = Rn;
996     let Inst{15-12} = Rd;
997     let Inst{11-8} = shift{11-8};
998     let Inst{7} = 0;
999     let Inst{6-5} = shift{6-5};
1000     let Inst{4} = 1;
1001     let Inst{3-0} = shift{3-0};
1002   }
1003 }
1004 }
1005
1006 /// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
1007 /// patterns. Similar to AsI1_bin_irs except the instruction does not produce
1008 /// a explicit result, only implicitly set CPSR.
1009 let isCompare = 1, Defs = [CPSR] in {
1010 multiclass AI1_cmp_irs<bits<4> opcod, string opc,
1011                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
1012                        PatFrag opnode, bit Commutable = 0> {
1013   def ri : AI1<opcod, (outs), (ins GPR:$Rn, so_imm:$imm), DPFrm, iii,
1014                opc, "\t$Rn, $imm",
1015                [(opnode GPR:$Rn, so_imm:$imm)]> {
1016     bits<4> Rn;
1017     bits<12> imm;
1018     let Inst{25} = 1;
1019     let Inst{20} = 1;
1020     let Inst{19-16} = Rn;
1021     let Inst{15-12} = 0b0000;
1022     let Inst{11-0} = imm;
1023   }
1024   def rr : AI1<opcod, (outs), (ins GPR:$Rn, GPR:$Rm), DPFrm, iir,
1025                opc, "\t$Rn, $Rm",
1026                [(opnode GPR:$Rn, GPR:$Rm)]> {
1027     bits<4> Rn;
1028     bits<4> Rm;
1029     let isCommutable = Commutable;
1030     let Inst{25} = 0;
1031     let Inst{20} = 1;
1032     let Inst{19-16} = Rn;
1033     let Inst{15-12} = 0b0000;
1034     let Inst{11-4} = 0b00000000;
1035     let Inst{3-0} = Rm;
1036   }
1037   def rsi : AI1<opcod, (outs),
1038                (ins GPR:$Rn, so_reg_imm:$shift), DPSoRegImmFrm, iis,
1039                opc, "\t$Rn, $shift",
1040                [(opnode GPR:$Rn, so_reg_imm:$shift)]> {
1041     bits<4> Rn;
1042     bits<12> shift;
1043     let Inst{25} = 0;
1044     let Inst{20} = 1;
1045     let Inst{19-16} = Rn;
1046     let Inst{15-12} = 0b0000;
1047     let Inst{11-5} = shift{11-5};
1048     let Inst{4} = 0;
1049     let Inst{3-0} = shift{3-0};
1050   }
1051   def rsr : AI1<opcod, (outs),
1052                (ins GPR:$Rn, so_reg_reg:$shift), DPSoRegRegFrm, iis,
1053                opc, "\t$Rn, $shift",
1054                [(opnode GPR:$Rn, so_reg_reg:$shift)]> {
1055     bits<4> Rn;
1056     bits<12> shift;
1057     let Inst{25} = 0;
1058     let Inst{20} = 1;
1059     let Inst{19-16} = Rn;
1060     let Inst{15-12} = 0b0000;
1061     let Inst{11-8} = shift{11-8};
1062     let Inst{7} = 0;
1063     let Inst{6-5} = shift{6-5};
1064     let Inst{4} = 1;
1065     let Inst{3-0} = shift{3-0};
1066   }
1067
1068 }
1069 }
1070
1071 /// AI_ext_rrot - A unary operation with two forms: one whose operand is a
1072 /// register and one whose operand is a register rotated by 8/16/24.
1073 /// FIXME: Remove the 'r' variant. Its rot_imm is zero.
1074 class AI_ext_rrot<bits<8> opcod, string opc, PatFrag opnode>
1075   : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPRnopc:$Rm, rot_imm:$rot),
1076           IIC_iEXTr, opc, "\t$Rd, $Rm$rot",
1077           [(set GPRnopc:$Rd, (opnode (rotr GPRnopc:$Rm, rot_imm:$rot)))]>,
1078        Requires<[IsARM, HasV6]> {
1079   bits<4> Rd;
1080   bits<4> Rm;
1081   bits<2> rot;
1082   let Inst{19-16} = 0b1111;
1083   let Inst{15-12} = Rd;
1084   let Inst{11-10} = rot;
1085   let Inst{3-0}   = Rm;
1086 }
1087
1088 class AI_ext_rrot_np<bits<8> opcod, string opc>
1089   : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPRnopc:$Rm, rot_imm:$rot),
1090           IIC_iEXTr, opc, "\t$Rd, $Rm$rot", []>,
1091        Requires<[IsARM, HasV6]> {
1092   bits<2> rot;
1093   let Inst{19-16} = 0b1111;
1094   let Inst{11-10} = rot;
1095 }
1096
1097 /// AI_exta_rrot - A binary operation with two forms: one whose operand is a
1098 /// register and one whose operand is a register rotated by 8/16/24.
1099 class AI_exta_rrot<bits<8> opcod, string opc, PatFrag opnode>
1100   : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPR:$Rn, GPRnopc:$Rm, rot_imm:$rot),
1101           IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm$rot",
1102           [(set GPRnopc:$Rd, (opnode GPR:$Rn,
1103                                      (rotr GPRnopc:$Rm, rot_imm:$rot)))]>,
1104         Requires<[IsARM, HasV6]> {
1105   bits<4> Rd;
1106   bits<4> Rm;
1107   bits<4> Rn;
1108   bits<2> rot;
1109   let Inst{19-16} = Rn;
1110   let Inst{15-12} = Rd;
1111   let Inst{11-10} = rot;
1112   let Inst{9-4}   = 0b000111;
1113   let Inst{3-0}   = Rm;
1114 }
1115
1116 class AI_exta_rrot_np<bits<8> opcod, string opc>
1117   : AExtI<opcod, (outs GPRnopc:$Rd), (ins GPR:$Rn, GPRnopc:$Rm, rot_imm:$rot),
1118           IIC_iEXTAr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
1119        Requires<[IsARM, HasV6]> {
1120   bits<4> Rn;
1121   bits<2> rot;
1122   let Inst{19-16} = Rn;
1123   let Inst{11-10} = rot;
1124 }
1125
1126 /// AI1_adde_sube_irs - Define instructions and patterns for adde and sube.
1127 multiclass AI1_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
1128                              string baseOpc, bit Commutable = 0> {
1129   let Uses = [CPSR] in {
1130   def ri : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
1131                 DPFrm, IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
1132                [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]>,
1133                Requires<[IsARM]> {
1134     bits<4> Rd;
1135     bits<4> Rn;
1136     bits<12> imm;
1137     let Inst{25} = 1;
1138     let Inst{15-12} = Rd;
1139     let Inst{19-16} = Rn;
1140     let Inst{11-0} = imm;
1141   }
1142   def rr : AsI1<opcod, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1143                 DPFrm, IIC_iALUr, opc, "\t$Rd, $Rn, $Rm",
1144                [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]>,
1145                Requires<[IsARM]> {
1146     bits<4> Rd;
1147     bits<4> Rn;
1148     bits<4> Rm;
1149     let Inst{11-4} = 0b00000000;
1150     let Inst{25} = 0;
1151     let isCommutable = Commutable;
1152     let Inst{3-0} = Rm;
1153     let Inst{15-12} = Rd;
1154     let Inst{19-16} = Rn;
1155   }
1156   def rsi : AsI1<opcod, (outs GPR:$Rd),
1157                 (ins GPR:$Rn, so_reg_imm:$shift),
1158                 DPSoRegImmFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1159                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_imm:$shift))]>,
1160                Requires<[IsARM]> {
1161     bits<4> Rd;
1162     bits<4> Rn;
1163     bits<12> shift;
1164     let Inst{25} = 0;
1165     let Inst{19-16} = Rn;
1166     let Inst{15-12} = Rd;
1167     let Inst{11-5} = shift{11-5};
1168     let Inst{4} = 0;
1169     let Inst{3-0} = shift{3-0};
1170   }
1171   def rsr : AsI1<opcod, (outs GPR:$Rd),
1172                 (ins GPR:$Rn, so_reg_reg:$shift),
1173                 DPSoRegRegFrm, IIC_iALUsr, opc, "\t$Rd, $Rn, $shift",
1174                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_reg:$shift))]>,
1175                Requires<[IsARM]> {
1176     bits<4> Rd;
1177     bits<4> Rn;
1178     bits<12> shift;
1179     let Inst{25} = 0;
1180     let Inst{19-16} = Rn;
1181     let Inst{15-12} = Rd;
1182     let Inst{11-8} = shift{11-8};
1183     let Inst{7} = 0;
1184     let Inst{6-5} = shift{6-5};
1185     let Inst{4} = 1;
1186     let Inst{3-0} = shift{3-0};
1187   }
1188   }
1189   // Assembly aliases for optional destination operand when it's the same
1190   // as the source operand.
1191   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
1192      (!cast<Instruction>(!strconcat(baseOpc, "ri")) GPR:$Rdn, GPR:$Rdn,
1193                                                     so_imm:$imm, pred:$p,
1194                                                     cc_out:$s)>,
1195      Requires<[IsARM]>;
1196   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $Rm"),
1197      (!cast<Instruction>(!strconcat(baseOpc, "rr")) GPR:$Rdn, GPR:$Rdn,
1198                                                     GPR:$Rm, pred:$p,
1199                                                     cc_out:$s)>,
1200      Requires<[IsARM]>;
1201   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1202      (!cast<Instruction>(!strconcat(baseOpc, "rsi")) GPR:$Rdn, GPR:$Rdn,
1203                                                     so_reg_imm:$shift, pred:$p,
1204                                                     cc_out:$s)>,
1205      Requires<[IsARM]>;
1206   def : InstAlias<!strconcat(opc, "${s}${p} $Rdn, $shift"),
1207      (!cast<Instruction>(!strconcat(baseOpc, "rsr")) GPR:$Rdn, GPR:$Rdn,
1208                                                     so_reg_reg:$shift, pred:$p,
1209                                                     cc_out:$s)>,
1210      Requires<[IsARM]>;
1211 }
1212
1213 // Carry setting variants
1214 // NOTE: CPSR def omitted because it will be handled by the custom inserter.
1215 let usesCustomInserter = 1 in {
1216 multiclass AI1_adde_sube_s_irs<PatFrag opnode, bit Commutable = 0> {
1217   def ri : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
1218                4, IIC_iALUi,
1219                [(set GPR:$Rd, (opnode GPR:$Rn, so_imm:$imm))]>;
1220   def rr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
1221                4, IIC_iALUr,
1222                [(set GPR:$Rd, (opnode GPR:$Rn, GPR:$Rm))]> {
1223     let isCommutable = Commutable;
1224   }
1225   def rsi : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_reg_imm:$shift),
1226                4, IIC_iALUsr,
1227                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_imm:$shift))]>;
1228   def rsr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_reg_reg:$shift),
1229                4, IIC_iALUsr,
1230                [(set GPR:$Rd, (opnode GPR:$Rn, so_reg_reg:$shift))]>;
1231 }
1232 }
1233
1234 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1235 multiclass AI_ldr1<bit isByte, string opc, InstrItinClass iii,
1236            InstrItinClass iir, PatFrag opnode> {
1237   // Note: We use the complex addrmode_imm12 rather than just an input
1238   // GPR and a constrained immediate so that we can use this to match
1239   // frame index references and avoid matching constant pool references.
1240   def i12: AI2ldst<0b010, 1, isByte, (outs GPR:$Rt), (ins addrmode_imm12:$addr),
1241                    AddrMode_i12, LdFrm, iii, opc, "\t$Rt, $addr",
1242                   [(set GPR:$Rt, (opnode addrmode_imm12:$addr))]> {
1243     bits<4>  Rt;
1244     bits<17> addr;
1245     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1246     let Inst{19-16} = addr{16-13};  // Rn
1247     let Inst{15-12} = Rt;
1248     let Inst{11-0}  = addr{11-0};   // imm12
1249   }
1250   def rs : AI2ldst<0b011, 1, isByte, (outs GPR:$Rt), (ins ldst_so_reg:$shift),
1251                   AddrModeNone, LdFrm, iir, opc, "\t$Rt, $shift",
1252                  [(set GPR:$Rt, (opnode ldst_so_reg:$shift))]> {
1253     bits<4>  Rt;
1254     bits<17> shift;
1255     let shift{4}    = 0;            // Inst{4} = 0
1256     let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1257     let Inst{19-16} = shift{16-13}; // Rn
1258     let Inst{15-12} = Rt;
1259     let Inst{11-0}  = shift{11-0};
1260   }
1261 }
1262 }
1263
1264 let canFoldAsLoad = 1, isReMaterializable = 1 in {
1265 multiclass AI_ldr1nopc<bit isByte, string opc, InstrItinClass iii,
1266            InstrItinClass iir, PatFrag opnode> {
1267   // Note: We use the complex addrmode_imm12 rather than just an input
1268   // GPR and a constrained immediate so that we can use this to match
1269   // frame index references and avoid matching constant pool references.
1270   def i12: AI2ldst<0b010, 1, isByte, (outs GPRnopc:$Rt), (ins addrmode_imm12:$addr),
1271                    AddrMode_i12, LdFrm, iii, opc, "\t$Rt, $addr",
1272                   [(set GPRnopc:$Rt, (opnode addrmode_imm12:$addr))]> {
1273     bits<4>  Rt;
1274     bits<17> addr;
1275     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1276     let Inst{19-16} = addr{16-13};  // Rn
1277     let Inst{15-12} = Rt;
1278     let Inst{11-0}  = addr{11-0};   // imm12
1279   }
1280   def rs : AI2ldst<0b011, 1, isByte, (outs GPRnopc:$Rt), (ins ldst_so_reg:$shift),
1281                   AddrModeNone, LdFrm, iir, opc, "\t$Rt, $shift",
1282                  [(set GPRnopc:$Rt, (opnode ldst_so_reg:$shift))]> {
1283     bits<4>  Rt;
1284     bits<17> shift;
1285     let shift{4}    = 0;            // Inst{4} = 0
1286     let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1287     let Inst{19-16} = shift{16-13}; // Rn
1288     let Inst{15-12} = Rt;
1289     let Inst{11-0}  = shift{11-0};
1290   }
1291 }
1292 }
1293
1294
1295 multiclass AI_str1<bit isByte, string opc, InstrItinClass iii,
1296            InstrItinClass iir, PatFrag opnode> {
1297   // Note: We use the complex addrmode_imm12 rather than just an input
1298   // GPR and a constrained immediate so that we can use this to match
1299   // frame index references and avoid matching constant pool references.
1300   def i12 : AI2ldst<0b010, 0, isByte, (outs),
1301                    (ins GPR:$Rt, addrmode_imm12:$addr),
1302                    AddrMode_i12, StFrm, iii, opc, "\t$Rt, $addr",
1303                   [(opnode GPR:$Rt, addrmode_imm12:$addr)]> {
1304     bits<4> Rt;
1305     bits<17> addr;
1306     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1307     let Inst{19-16} = addr{16-13};  // Rn
1308     let Inst{15-12} = Rt;
1309     let Inst{11-0}  = addr{11-0};   // imm12
1310   }
1311   def rs : AI2ldst<0b011, 0, isByte, (outs), (ins GPR:$Rt, ldst_so_reg:$shift),
1312                   AddrModeNone, StFrm, iir, opc, "\t$Rt, $shift",
1313                  [(opnode GPR:$Rt, ldst_so_reg:$shift)]> {
1314     bits<4> Rt;
1315     bits<17> shift;
1316     let shift{4}    = 0;            // Inst{4} = 0
1317     let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1318     let Inst{19-16} = shift{16-13}; // Rn
1319     let Inst{15-12} = Rt;
1320     let Inst{11-0}  = shift{11-0};
1321   }
1322 }
1323
1324 multiclass AI_str1nopc<bit isByte, string opc, InstrItinClass iii,
1325            InstrItinClass iir, PatFrag opnode> {
1326   // Note: We use the complex addrmode_imm12 rather than just an input
1327   // GPR and a constrained immediate so that we can use this to match
1328   // frame index references and avoid matching constant pool references.
1329   def i12 : AI2ldst<0b010, 0, isByte, (outs),
1330                    (ins GPRnopc:$Rt, addrmode_imm12:$addr),
1331                    AddrMode_i12, StFrm, iii, opc, "\t$Rt, $addr",
1332                   [(opnode GPRnopc:$Rt, addrmode_imm12:$addr)]> {
1333     bits<4> Rt;
1334     bits<17> addr;
1335     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1336     let Inst{19-16} = addr{16-13};  // Rn
1337     let Inst{15-12} = Rt;
1338     let Inst{11-0}  = addr{11-0};   // imm12
1339   }
1340   def rs : AI2ldst<0b011, 0, isByte, (outs), (ins GPRnopc:$Rt, ldst_so_reg:$shift),
1341                   AddrModeNone, StFrm, iir, opc, "\t$Rt, $shift",
1342                  [(opnode GPRnopc:$Rt, ldst_so_reg:$shift)]> {
1343     bits<4> Rt;
1344     bits<17> shift;
1345     let shift{4}    = 0;            // Inst{4} = 0
1346     let Inst{23}    = shift{12};    // U (add = ('U' == 1))
1347     let Inst{19-16} = shift{16-13}; // Rn
1348     let Inst{15-12} = Rt;
1349     let Inst{11-0}  = shift{11-0};
1350   }
1351 }
1352
1353
1354 //===----------------------------------------------------------------------===//
1355 // Instructions
1356 //===----------------------------------------------------------------------===//
1357
1358 //===----------------------------------------------------------------------===//
1359 //  Miscellaneous Instructions.
1360 //
1361
1362 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
1363 /// the function.  The first operand is the ID# for this instruction, the second
1364 /// is the index into the MachineConstantPool that this is, the third is the
1365 /// size in bytes of this constant pool entry.
1366 let neverHasSideEffects = 1, isNotDuplicable = 1 in
1367 def CONSTPOOL_ENTRY :
1368 PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
1369                     i32imm:$size), NoItinerary, []>;
1370
1371 // FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
1372 // from removing one half of the matched pairs. That breaks PEI, which assumes
1373 // these will always be in pairs, and asserts if it finds otherwise. Better way?
1374 let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
1375 def ADJCALLSTACKUP :
1376 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p), NoItinerary,
1377            [(ARMcallseq_end timm:$amt1, timm:$amt2)]>;
1378
1379 def ADJCALLSTACKDOWN :
1380 PseudoInst<(outs), (ins i32imm:$amt, pred:$p), NoItinerary,
1381            [(ARMcallseq_start timm:$amt)]>;
1382 }
1383
1384 def NOP : AI<(outs), (ins), MiscFrm, NoItinerary, "nop", "", []>,
1385           Requires<[IsARM, HasV6T2]> {
1386   let Inst{27-16} = 0b001100100000;
1387   let Inst{15-8} = 0b11110000;
1388   let Inst{7-0} = 0b00000000;
1389 }
1390
1391 def YIELD : AI<(outs), (ins), MiscFrm, NoItinerary, "yield", "", []>,
1392           Requires<[IsARM, HasV6T2]> {
1393   let Inst{27-16} = 0b001100100000;
1394   let Inst{15-8} = 0b11110000;
1395   let Inst{7-0} = 0b00000001;
1396 }
1397
1398 def WFE : AI<(outs), (ins), MiscFrm, NoItinerary, "wfe", "", []>,
1399           Requires<[IsARM, HasV6T2]> {
1400   let Inst{27-16} = 0b001100100000;
1401   let Inst{15-8} = 0b11110000;
1402   let Inst{7-0} = 0b00000010;
1403 }
1404
1405 def WFI : AI<(outs), (ins), MiscFrm, NoItinerary, "wfi", "", []>,
1406           Requires<[IsARM, HasV6T2]> {
1407   let Inst{27-16} = 0b001100100000;
1408   let Inst{15-8} = 0b11110000;
1409   let Inst{7-0} = 0b00000011;
1410 }
1411
1412 def SEL : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm, NoItinerary, "sel",
1413              "\t$Rd, $Rn, $Rm", []>, Requires<[IsARM, HasV6]> {
1414   bits<4> Rd;
1415   bits<4> Rn;
1416   bits<4> Rm;
1417   let Inst{3-0} = Rm;
1418   let Inst{15-12} = Rd;
1419   let Inst{19-16} = Rn;
1420   let Inst{27-20} = 0b01101000;
1421   let Inst{7-4} = 0b1011;
1422   let Inst{11-8} = 0b1111;
1423 }
1424
1425 def SEV : AI<(outs), (ins), MiscFrm, NoItinerary, "sev", "",
1426              []>, Requires<[IsARM, HasV6T2]> {
1427   let Inst{27-16} = 0b001100100000;
1428   let Inst{15-8} = 0b11110000;
1429   let Inst{7-0} = 0b00000100;
1430 }
1431
1432 // The i32imm operand $val can be used by a debugger to store more information
1433 // about the breakpoint.
1434 def BKPT : AI<(outs), (ins imm0_65535:$val), MiscFrm, NoItinerary,
1435               "bkpt", "\t$val", []>, Requires<[IsARM]> {
1436   bits<16> val;
1437   let Inst{3-0} = val{3-0};
1438   let Inst{19-8} = val{15-4};
1439   let Inst{27-20} = 0b00010010;
1440   let Inst{7-4} = 0b0111;
1441 }
1442
1443 // Change Processor State
1444 // FIXME: We should use InstAlias to handle the optional operands.
1445 class CPS<dag iops, string asm_ops>
1446   : AXI<(outs), iops, MiscFrm, NoItinerary, !strconcat("cps", asm_ops),
1447         []>, Requires<[IsARM]> {
1448   bits<2> imod;
1449   bits<3> iflags;
1450   bits<5> mode;
1451   bit M;
1452
1453   let Inst{31-28} = 0b1111;
1454   let Inst{27-20} = 0b00010000;
1455   let Inst{19-18} = imod;
1456   let Inst{17}    = M; // Enabled if mode is set;
1457   let Inst{16}    = 0;
1458   let Inst{8-6}   = iflags;
1459   let Inst{5}     = 0;
1460   let Inst{4-0}   = mode;
1461 }
1462
1463 let DecoderMethod = "DecodeCPSInstruction" in {
1464 let M = 1 in
1465   def CPS3p : CPS<(ins imod_op:$imod, iflags_op:$iflags, imm0_31:$mode),
1466                   "$imod\t$iflags, $mode">;
1467 let mode = 0, M = 0 in
1468   def CPS2p : CPS<(ins imod_op:$imod, iflags_op:$iflags), "$imod\t$iflags">;
1469
1470 let imod = 0, iflags = 0, M = 1 in
1471   def CPS1p : CPS<(ins imm0_31:$mode), "\t$mode">;
1472 }
1473
1474 // Preload signals the memory system of possible future data/instruction access.
1475 multiclass APreLoad<bits<1> read, bits<1> data, string opc> {
1476
1477   def i12 : AXI<(outs), (ins addrmode_imm12:$addr), MiscFrm, IIC_Preload,
1478                 !strconcat(opc, "\t$addr"),
1479                 [(ARMPreload addrmode_imm12:$addr, (i32 read), (i32 data))]> {
1480     bits<4> Rt;
1481     bits<17> addr;
1482     let Inst{31-26} = 0b111101;
1483     let Inst{25} = 0; // 0 for immediate form
1484     let Inst{24} = data;
1485     let Inst{23} = addr{12};        // U (add = ('U' == 1))
1486     let Inst{22} = read;
1487     let Inst{21-20} = 0b01;
1488     let Inst{19-16} = addr{16-13};  // Rn
1489     let Inst{15-12} = 0b1111;
1490     let Inst{11-0}  = addr{11-0};   // imm12
1491   }
1492
1493   def rs : AXI<(outs), (ins ldst_so_reg:$shift), MiscFrm, IIC_Preload,
1494                !strconcat(opc, "\t$shift"),
1495                [(ARMPreload ldst_so_reg:$shift, (i32 read), (i32 data))]> {
1496     bits<17> shift;
1497     let Inst{31-26} = 0b111101;
1498     let Inst{25} = 1; // 1 for register form
1499     let Inst{24} = data;
1500     let Inst{23} = shift{12};    // U (add = ('U' == 1))
1501     let Inst{22} = read;
1502     let Inst{21-20} = 0b01;
1503     let Inst{19-16} = shift{16-13}; // Rn
1504     let Inst{15-12} = 0b1111;
1505     let Inst{11-0}  = shift{11-0};
1506   }
1507 }
1508
1509 defm PLD  : APreLoad<1, 1, "pld">,  Requires<[IsARM]>;
1510 defm PLDW : APreLoad<0, 1, "pldw">, Requires<[IsARM,HasV7,HasMP]>;
1511 defm PLI  : APreLoad<1, 0, "pli">,  Requires<[IsARM,HasV7]>;
1512
1513 def SETEND : AXI<(outs), (ins setend_op:$end), MiscFrm, NoItinerary,
1514                  "setend\t$end", []>, Requires<[IsARM]> {
1515   bits<1> end;
1516   let Inst{31-10} = 0b1111000100000001000000;
1517   let Inst{9} = end;
1518   let Inst{8-0} = 0;
1519 }
1520
1521 def DBG : AI<(outs), (ins imm0_15:$opt), MiscFrm, NoItinerary, "dbg", "\t$opt",
1522              []>, Requires<[IsARM, HasV7]> {
1523   bits<4> opt;
1524   let Inst{27-4} = 0b001100100000111100001111;
1525   let Inst{3-0} = opt;
1526 }
1527
1528 // A5.4 Permanently UNDEFINED instructions.
1529 let isBarrier = 1, isTerminator = 1 in
1530 def TRAP : AXI<(outs), (ins), MiscFrm, NoItinerary,
1531                "trap", [(trap)]>,
1532            Requires<[IsARM]> {
1533   let Inst = 0xe7ffdefe;
1534 }
1535
1536 // Address computation and loads and stores in PIC mode.
1537 let isNotDuplicable = 1 in {
1538 def PICADD  : ARMPseudoInst<(outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
1539                             4, IIC_iALUr,
1540                             [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
1541
1542 let AddedComplexity = 10 in {
1543 def PICLDR  : ARMPseudoInst<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
1544                             4, IIC_iLoad_r,
1545                             [(set GPR:$dst, (load addrmodepc:$addr))]>;
1546
1547 def PICLDRH : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1548                             4, IIC_iLoad_bh_r,
1549                             [(set GPR:$Rt, (zextloadi16 addrmodepc:$addr))]>;
1550
1551 def PICLDRB : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1552                             4, IIC_iLoad_bh_r,
1553                             [(set GPR:$Rt, (zextloadi8 addrmodepc:$addr))]>;
1554
1555 def PICLDRSH : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1556                             4, IIC_iLoad_bh_r,
1557                             [(set GPR:$Rt, (sextloadi16 addrmodepc:$addr))]>;
1558
1559 def PICLDRSB : ARMPseudoInst<(outs GPR:$Rt), (ins addrmodepc:$addr, pred:$p),
1560                             4, IIC_iLoad_bh_r,
1561                             [(set GPR:$Rt, (sextloadi8 addrmodepc:$addr))]>;
1562 }
1563 let AddedComplexity = 10 in {
1564 def PICSTR  : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1565       4, IIC_iStore_r, [(store GPR:$src, addrmodepc:$addr)]>;
1566
1567 def PICSTRH : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1568       4, IIC_iStore_bh_r, [(truncstorei16 GPR:$src,
1569                                                    addrmodepc:$addr)]>;
1570
1571 def PICSTRB : ARMPseudoInst<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
1572       4, IIC_iStore_bh_r, [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
1573 }
1574 } // isNotDuplicable = 1
1575
1576
1577 // LEApcrel - Load a pc-relative address into a register without offending the
1578 // assembler.
1579 let neverHasSideEffects = 1, isReMaterializable = 1 in
1580 // The 'adr' mnemonic encodes differently if the label is before or after
1581 // the instruction. The {24-21} opcode bits are set by the fixup, as we don't
1582 // know until then which form of the instruction will be used.
1583 def ADR : AI1<{0,?,?,0}, (outs GPR:$Rd), (ins adrlabel:$label),
1584                  MiscFrm, IIC_iALUi, "adr", "\t$Rd, $label", []> {
1585   bits<4> Rd;
1586   bits<12> label;
1587   let Inst{27-25} = 0b001;
1588   let Inst{20} = 0;
1589   let Inst{19-16} = 0b1111;
1590   let Inst{15-12} = Rd;
1591   let Inst{11-0} = label;
1592 }
1593 def LEApcrel : ARMPseudoInst<(outs GPR:$Rd), (ins i32imm:$label, pred:$p),
1594                     4, IIC_iALUi, []>;
1595
1596 def LEApcrelJT : ARMPseudoInst<(outs GPR:$Rd),
1597                       (ins i32imm:$label, nohash_imm:$id, pred:$p),
1598                       4, IIC_iALUi, []>;
1599
1600 //===----------------------------------------------------------------------===//
1601 //  Control Flow Instructions.
1602 //
1603
1604 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
1605   // ARMV4T and above
1606   def BX_RET : AI<(outs), (ins), BrMiscFrm, IIC_Br,
1607                   "bx", "\tlr", [(ARMretflag)]>,
1608                Requires<[IsARM, HasV4T]> {
1609     let Inst{27-0}  = 0b0001001011111111111100011110;
1610   }
1611
1612   // ARMV4 only
1613   def MOVPCLR : AI<(outs), (ins), BrMiscFrm, IIC_Br,
1614                   "mov", "\tpc, lr", [(ARMretflag)]>,
1615                Requires<[IsARM, NoV4T]> {
1616     let Inst{27-0} = 0b0001101000001111000000001110;
1617   }
1618 }
1619
1620 // Indirect branches
1621 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1622   // ARMV4T and above
1623   def BX : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "bx\t$dst",
1624                   [(brind GPR:$dst)]>,
1625               Requires<[IsARM, HasV4T]> {
1626     bits<4> dst;
1627     let Inst{31-4} = 0b1110000100101111111111110001;
1628     let Inst{3-0}  = dst;
1629   }
1630
1631   def BX_pred : AI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br,
1632                   "bx", "\t$dst", [/* pattern left blank */]>,
1633               Requires<[IsARM, HasV4T]> {
1634     bits<4> dst;
1635     let Inst{27-4} = 0b000100101111111111110001;
1636     let Inst{3-0}  = dst;
1637   }
1638 }
1639
1640 // All calls clobber the non-callee saved registers. SP is marked as
1641 // a use to prevent stack-pointer assignments that appear immediately
1642 // before calls from potentially appearing dead.
1643 let isCall = 1,
1644   // On non-Darwin platforms R9 is callee-saved.
1645   // FIXME:  Do we really need a non-predicated version? If so, it should
1646   // at least be a pseudo instruction expanding to the predicated version
1647   // at MC lowering time.
1648   Defs = [R0,  R1,  R2,  R3,  R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
1649   Uses = [SP] in {
1650   def BL  : ABXI<0b1011, (outs), (ins bl_target:$func, variable_ops),
1651                 IIC_Br, "bl\t$func",
1652                 [(ARMcall tglobaladdr:$func)]>,
1653             Requires<[IsARM, IsNotDarwin]> {
1654     let Inst{31-28} = 0b1110;
1655     bits<24> func;
1656     let Inst{23-0} = func;
1657   }
1658
1659   def BL_pred : ABI<0b1011, (outs), (ins bl_target:$func, variable_ops),
1660                    IIC_Br, "bl", "\t$func",
1661                    [(ARMcall_pred tglobaladdr:$func)]>,
1662                 Requires<[IsARM, IsNotDarwin]> {
1663     bits<24> func;
1664     let Inst{23-0} = func;
1665   }
1666
1667   // ARMv5T and above
1668   def BLX : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
1669                 IIC_Br, "blx\t$func",
1670                 [(ARMcall GPR:$func)]>,
1671             Requires<[IsARM, HasV5T, IsNotDarwin]> {
1672     bits<4> func;
1673     let Inst{31-4} = 0b1110000100101111111111110011;
1674     let Inst{3-0}  = func;
1675   }
1676
1677   def BLX_pred : AI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
1678                     IIC_Br, "blx", "\t$func",
1679                     [(ARMcall_pred GPR:$func)]>,
1680                  Requires<[IsARM, HasV5T, IsNotDarwin]> {
1681     bits<4> func;
1682     let Inst{27-4} = 0b000100101111111111110011;
1683     let Inst{3-0}  = func;
1684   }
1685
1686   // ARMv4T
1687   // Note: Restrict $func to the tGPR regclass to prevent it being in LR.
1688   def BX_CALL : ARMPseudoInst<(outs), (ins tGPR:$func, variable_ops),
1689                    8, IIC_Br, [(ARMcall_nolink tGPR:$func)]>,
1690                    Requires<[IsARM, HasV4T, IsNotDarwin]>;
1691
1692   // ARMv4
1693   def BMOVPCRX_CALL : ARMPseudoInst<(outs), (ins tGPR:$func, variable_ops),
1694                    8, IIC_Br, [(ARMcall_nolink tGPR:$func)]>,
1695                    Requires<[IsARM, NoV4T, IsNotDarwin]>;
1696 }
1697
1698 let isCall = 1,
1699   // On Darwin R9 is call-clobbered.
1700   // R7 is marked as a use to prevent frame-pointer assignments from being
1701   // moved above / below calls.
1702   Defs = [R0,  R1,  R2,  R3,  R9,  R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
1703   Uses = [R7, SP] in {
1704   def BLr9  : ARMPseudoExpand<(outs), (ins bl_target:$func, variable_ops),
1705                 4, IIC_Br,
1706                 [(ARMcall tglobaladdr:$func)], (BL bl_target:$func)>,
1707               Requires<[IsARM, IsDarwin]>;
1708
1709   def BLr9_pred : ARMPseudoExpand<(outs),
1710                    (ins bl_target:$func, pred:$p, variable_ops),
1711                    4, IIC_Br,
1712                    [(ARMcall_pred tglobaladdr:$func)],
1713                    (BL_pred bl_target:$func, pred:$p)>,
1714                   Requires<[IsARM, IsDarwin]>;
1715
1716   // ARMv5T and above
1717   def BLXr9 : ARMPseudoExpand<(outs), (ins GPR:$func, variable_ops),
1718                 4, IIC_Br,
1719                 [(ARMcall GPR:$func)],
1720                 (BLX GPR:$func)>,
1721                Requires<[IsARM, HasV5T, IsDarwin]>;
1722
1723   def BLXr9_pred: ARMPseudoExpand<(outs), (ins GPR:$func, pred:$p,variable_ops),
1724                 4, IIC_Br,
1725                 [(ARMcall_pred GPR:$func)],
1726                 (BLX_pred GPR:$func, pred:$p)>,
1727                    Requires<[IsARM, HasV5T, IsDarwin]>;
1728
1729   // ARMv4T
1730   // Note: Restrict $func to the tGPR regclass to prevent it being in LR.
1731   def BXr9_CALL : ARMPseudoInst<(outs), (ins tGPR:$func, variable_ops),
1732                   8, IIC_Br, [(ARMcall_nolink tGPR:$func)]>,
1733                   Requires<[IsARM, HasV4T, IsDarwin]>;
1734
1735   // ARMv4
1736   def BMOVPCRXr9_CALL : ARMPseudoInst<(outs), (ins tGPR:$func, variable_ops),
1737                   8, IIC_Br, [(ARMcall_nolink tGPR:$func)]>,
1738                   Requires<[IsARM, NoV4T, IsDarwin]>;
1739 }
1740
1741 let isBranch = 1, isTerminator = 1 in {
1742   // FIXME: should be able to write a pattern for ARMBrcond, but can't use
1743   // a two-value operand where a dag node expects two operands. :(
1744   def Bcc : ABI<0b1010, (outs), (ins br_target:$target),
1745                IIC_Br, "b", "\t$target",
1746                [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]> {
1747     bits<24> target;
1748     let Inst{23-0} = target;
1749     let DecoderMethod = "DecodeBranchImmInstruction";
1750   }
1751
1752   let isBarrier = 1 in {
1753     // B is "predicable" since it's just a Bcc with an 'always' condition.
1754     let isPredicable = 1 in
1755     // FIXME: We shouldn't need this pseudo at all. Just using Bcc directly
1756     // should be sufficient.
1757     // FIXME: Is B really a Barrier? That doesn't seem right.
1758     def B : ARMPseudoExpand<(outs), (ins br_target:$target), 4, IIC_Br,
1759                 [(br bb:$target)], (Bcc br_target:$target, (ops 14, zero_reg))>;
1760
1761     let isNotDuplicable = 1, isIndirectBranch = 1 in {
1762     def BR_JTr : ARMPseudoInst<(outs),
1763                       (ins GPR:$target, i32imm:$jt, i32imm:$id),
1764                       0, IIC_Br,
1765                       [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
1766     // FIXME: This shouldn't use the generic "addrmode2," but rather be split
1767     // into i12 and rs suffixed versions.
1768     def BR_JTm : ARMPseudoInst<(outs),
1769                      (ins addrmode2:$target, i32imm:$jt, i32imm:$id),
1770                      0, IIC_Br,
1771                      [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
1772                        imm:$id)]>;
1773     def BR_JTadd : ARMPseudoInst<(outs),
1774                    (ins GPR:$target, GPR:$idx, i32imm:$jt, i32imm:$id),
1775                    0, IIC_Br,
1776                    [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
1777                      imm:$id)]>;
1778     } // isNotDuplicable = 1, isIndirectBranch = 1
1779   } // isBarrier = 1
1780
1781 }
1782
1783 // BLX (immediate)
1784 def BLXi : AXI<(outs), (ins br_target:$target), BrMiscFrm, NoItinerary,
1785                "blx\t$target", []>,
1786            Requires<[IsARM, HasV5T]> {
1787   let Inst{31-25} = 0b1111101;
1788   bits<25> target;
1789   let Inst{23-0} = target{24-1};
1790   let Inst{24} = target{0};
1791 }
1792
1793 // Branch and Exchange Jazelle
1794 def BXJ : ABI<0b0001, (outs), (ins GPR:$func), NoItinerary, "bxj", "\t$func",
1795               [/* pattern left blank */]> {
1796   bits<4> func;
1797   let Inst{23-20} = 0b0010;
1798   let Inst{19-8} = 0xfff;
1799   let Inst{7-4} = 0b0010;
1800   let Inst{3-0} = func;
1801 }
1802
1803 // Tail calls.
1804
1805 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
1806   // Darwin versions.
1807   let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
1808       Uses = [SP] in {
1809     def TCRETURNdi : PseudoInst<(outs), (ins i32imm:$dst, variable_ops),
1810                        IIC_Br, []>, Requires<[IsDarwin]>;
1811
1812     def TCRETURNri : PseudoInst<(outs), (ins tcGPR:$dst, variable_ops),
1813                        IIC_Br, []>, Requires<[IsDarwin]>;
1814
1815     def TAILJMPd : ARMPseudoExpand<(outs), (ins br_target:$dst, variable_ops),
1816                    4, IIC_Br, [],
1817                    (Bcc br_target:$dst, (ops 14, zero_reg))>,
1818                    Requires<[IsARM, IsDarwin]>;
1819
1820     def TAILJMPr : ARMPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
1821                    4, IIC_Br, [],
1822                    (BX GPR:$dst)>,
1823                    Requires<[IsARM, IsDarwin]>;
1824
1825   }
1826
1827   // Non-Darwin versions (the difference is R9).
1828   let Defs = [R0, R1, R2, R3, R12, QQQQ0, QQQQ2, QQQQ3, PC],
1829       Uses = [SP] in {
1830     def TCRETURNdiND : PseudoInst<(outs), (ins i32imm:$dst, variable_ops),
1831                        IIC_Br, []>, Requires<[IsNotDarwin]>;
1832
1833     def TCRETURNriND : PseudoInst<(outs), (ins tcGPR:$dst, variable_ops),
1834                        IIC_Br, []>, Requires<[IsNotDarwin]>;
1835
1836     def TAILJMPdND : ARMPseudoExpand<(outs), (ins brtarget:$dst, variable_ops),
1837                    4, IIC_Br, [],
1838                    (Bcc br_target:$dst, (ops 14, zero_reg))>,
1839                    Requires<[IsARM, IsNotDarwin]>;
1840
1841     def TAILJMPrND : ARMPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
1842                      4, IIC_Br, [],
1843                      (BX GPR:$dst)>,
1844                      Requires<[IsARM, IsNotDarwin]>;
1845   }
1846 }
1847
1848 // Secure Monitor Call is a system instruction.
1849 def SMC : ABI<0b0001, (outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
1850               []> {
1851   bits<4> opt;
1852   let Inst{23-4} = 0b01100000000000000111;
1853   let Inst{3-0} = opt;
1854 }
1855
1856 // Supervisor Call (Software Interrupt)
1857 let isCall = 1, Uses = [SP] in {
1858 def SVC : ABI<0b1111, (outs), (ins imm24b:$svc), IIC_Br, "svc", "\t$svc", []> {
1859   bits<24> svc;
1860   let Inst{23-0} = svc;
1861 }
1862 }
1863
1864 // Store Return State
1865 class SRSI<bit wb, string asm>
1866   : XI<(outs), (ins imm0_31:$mode), AddrModeNone, 4, IndexModeNone, BrFrm,
1867        NoItinerary, asm, "", []> {
1868   bits<5> mode;
1869   let Inst{31-28} = 0b1111;
1870   let Inst{27-25} = 0b100;
1871   let Inst{22} = 1;
1872   let Inst{21} = wb;
1873   let Inst{20} = 0;
1874   let Inst{19-16} = 0b1101;  // SP
1875   let Inst{15-5} = 0b00000101000;
1876   let Inst{4-0} = mode;
1877 }
1878
1879 def SRSDA : SRSI<0, "srsda\tsp, $mode"> {
1880   let Inst{24-23} = 0;
1881 }
1882 def SRSDA_UPD : SRSI<1, "srsda\tsp!, $mode"> {
1883   let Inst{24-23} = 0;
1884 }
1885 def SRSDB : SRSI<0, "srsdb\tsp, $mode"> {
1886   let Inst{24-23} = 0b10;
1887 }
1888 def SRSDB_UPD : SRSI<1, "srsdb\tsp!, $mode"> {
1889   let Inst{24-23} = 0b10;
1890 }
1891 def SRSIA : SRSI<0, "srsia\tsp, $mode"> {
1892   let Inst{24-23} = 0b01;
1893 }
1894 def SRSIA_UPD : SRSI<1, "srsia\tsp!, $mode"> {
1895   let Inst{24-23} = 0b01;
1896 }
1897 def SRSIB : SRSI<0, "srsib\tsp, $mode"> {
1898   let Inst{24-23} = 0b11;
1899 }
1900 def SRSIB_UPD : SRSI<1, "srsib\tsp!, $mode"> {
1901   let Inst{24-23} = 0b11;
1902 }
1903
1904 // Return From Exception
1905 class RFEI<bit wb, string asm>
1906   : XI<(outs), (ins GPR:$Rn), AddrModeNone, 4, IndexModeNone, BrFrm,
1907        NoItinerary, asm, "", []> {
1908   bits<4> Rn;
1909   let Inst{31-28} = 0b1111;
1910   let Inst{27-25} = 0b100;
1911   let Inst{22} = 0;
1912   let Inst{21} = wb;
1913   let Inst{20} = 1;
1914   let Inst{19-16} = Rn;
1915   let Inst{15-0} = 0xa00;
1916 }
1917
1918 def RFEDA : RFEI<0, "rfeda\t$Rn"> {
1919   let Inst{24-23} = 0;
1920 }
1921 def RFEDA_UPD : RFEI<1, "rfeda\t$Rn!"> {
1922   let Inst{24-23} = 0;
1923 }
1924 def RFEDB : RFEI<0, "rfedb\t$Rn"> {
1925   let Inst{24-23} = 0b10;
1926 }
1927 def RFEDB_UPD : RFEI<1, "rfedb\t$Rn!"> {
1928   let Inst{24-23} = 0b10;
1929 }
1930 def RFEIA : RFEI<0, "rfeia\t$Rn"> {
1931   let Inst{24-23} = 0b01;
1932 }
1933 def RFEIA_UPD : RFEI<1, "rfeia\t$Rn!"> {
1934   let Inst{24-23} = 0b01;
1935 }
1936 def RFEIB : RFEI<0, "rfeib\t$Rn"> {
1937   let Inst{24-23} = 0b11;
1938 }
1939 def RFEIB_UPD : RFEI<1, "rfeib\t$Rn!"> {
1940   let Inst{24-23} = 0b11;
1941 }
1942
1943 //===----------------------------------------------------------------------===//
1944 //  Load / store Instructions.
1945 //
1946
1947 // Load
1948
1949
1950 defm LDR  : AI_ldr1<0, "ldr", IIC_iLoad_r, IIC_iLoad_si,
1951                     UnOpFrag<(load node:$Src)>>;
1952 defm LDRB : AI_ldr1nopc<1, "ldrb", IIC_iLoad_bh_r, IIC_iLoad_bh_si,
1953                     UnOpFrag<(zextloadi8 node:$Src)>>;
1954 defm STR  : AI_str1<0, "str", IIC_iStore_r, IIC_iStore_si,
1955                    BinOpFrag<(store node:$LHS, node:$RHS)>>;
1956 defm STRB : AI_str1nopc<1, "strb", IIC_iStore_bh_r, IIC_iStore_bh_si,
1957                    BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
1958
1959 // Special LDR for loads from non-pc-relative constpools.
1960 let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
1961     isReMaterializable = 1, isCodeGenOnly = 1 in
1962 def LDRcp : AI2ldst<0b010, 1, 0, (outs GPR:$Rt), (ins addrmode_imm12:$addr),
1963                  AddrMode_i12, LdFrm, IIC_iLoad_r, "ldr", "\t$Rt, $addr",
1964                  []> {
1965   bits<4> Rt;
1966   bits<17> addr;
1967   let Inst{23}    = addr{12};     // U (add = ('U' == 1))
1968   let Inst{19-16} = 0b1111;
1969   let Inst{15-12} = Rt;
1970   let Inst{11-0}  = addr{11-0};   // imm12
1971 }
1972
1973 // Loads with zero extension
1974 def LDRH  : AI3ld<0b1011, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
1975                   IIC_iLoad_bh_r, "ldrh", "\t$Rt, $addr",
1976                   [(set GPR:$Rt, (zextloadi16 addrmode3:$addr))]>;
1977
1978 // Loads with sign extension
1979 def LDRSH : AI3ld<0b1111, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
1980                    IIC_iLoad_bh_r, "ldrsh", "\t$Rt, $addr",
1981                    [(set GPR:$Rt, (sextloadi16 addrmode3:$addr))]>;
1982
1983 def LDRSB : AI3ld<0b1101, 1, (outs GPR:$Rt), (ins addrmode3:$addr), LdMiscFrm,
1984                    IIC_iLoad_bh_r, "ldrsb", "\t$Rt, $addr",
1985                    [(set GPR:$Rt, (sextloadi8 addrmode3:$addr))]>;
1986
1987 let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
1988 // Load doubleword
1989 def LDRD : AI3ld<0b1101, 0, (outs GPR:$Rd, GPR:$dst2),
1990                  (ins addrmode3:$addr), LdMiscFrm,
1991                  IIC_iLoad_d_r, "ldrd", "\t$Rd, $dst2, $addr",
1992                  []>, Requires<[IsARM, HasV5TE]>;
1993 }
1994
1995 // Indexed loads
1996 multiclass AI2_ldridx<bit isByte, string opc, InstrItinClass itin> {
1997   def _PRE  : AI2ldstidx<1, isByte, 1, (outs GPR:$Rt, GPR:$Rn_wb),
1998                       (ins addrmode2:$addr), IndexModePre, LdFrm, itin,
1999                       opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2000     // {17-14}  Rn
2001     // {13}     reg vs. imm
2002     // {12}     isAdd
2003     // {11-0}   imm12/Rm
2004     bits<18> addr;
2005     let Inst{25} = addr{13};
2006     let Inst{23} = addr{12};
2007     let Inst{19-16} = addr{17-14};
2008     let Inst{11-0} = addr{11-0};
2009     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2010     let AsmMatchConverter = "cvtLdWriteBackRegAddrMode2";
2011   }
2012
2013   def _POST_REG : AI2ldstidx<1, isByte, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2014                        (ins addr_offset_none:$addr, am2offset_reg:$offset),
2015                        IndexModePost, LdFrm, itin,
2016                        opc, "\t$Rt, $addr, $offset",
2017                        "$addr.base = $Rn_wb", []> {
2018      // {12}     isAdd
2019      // {11-0}   imm12/Rm
2020      bits<14> offset;
2021      bits<4> addr;
2022      let Inst{25} = 1;
2023      let Inst{23} = offset{12};
2024      let Inst{19-16} = addr;
2025      let Inst{11-0} = offset{11-0};
2026
2027     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2028    }
2029
2030    def _POST_IMM : AI2ldstidx<1, isByte, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2031                        (ins addr_offset_none:$addr, am2offset_imm:$offset),
2032                       IndexModePost, LdFrm, itin,
2033                       opc, "\t$Rt, $addr, $offset",
2034                       "$addr.base = $Rn_wb", []> {
2035     // {12}     isAdd
2036     // {11-0}   imm12/Rm
2037     bits<14> offset;
2038     bits<4> addr;
2039     let Inst{25} = 0;
2040     let Inst{23} = offset{12};
2041     let Inst{19-16} = addr;
2042     let Inst{11-0} = offset{11-0};
2043
2044     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2045   }
2046
2047 }
2048
2049 let mayLoad = 1, neverHasSideEffects = 1 in {
2050 defm LDR  : AI2_ldridx<0, "ldr", IIC_iLoad_ru>;
2051 defm LDRB : AI2_ldridx<1, "ldrb", IIC_iLoad_bh_ru>;
2052 }
2053
2054 multiclass AI3_ldridx<bits<4> op, string opc, InstrItinClass itin> {
2055   def _PRE  : AI3ldstidx<op, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
2056                         (ins addrmode3:$addr), IndexModePre,
2057                         LdMiscFrm, itin,
2058                         opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2059     bits<14> addr;
2060     let Inst{23}    = addr{8};      // U bit
2061     let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2062     let Inst{19-16} = addr{12-9};   // Rn
2063     let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2064     let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2065     let AsmMatchConverter = "cvtLdWriteBackRegAddrMode3";
2066     let DecoderMethod = "DecodeAddrMode3Instruction";
2067   }
2068   def _POST : AI3ldstidx<op, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2069                         (ins addr_offset_none:$addr, am3offset:$offset),
2070                         IndexModePost, LdMiscFrm, itin,
2071                         opc, "\t$Rt, $addr, $offset", "$addr.base = $Rn_wb",
2072                         []> {
2073     bits<10> offset;
2074     bits<4> addr;
2075     let Inst{23}    = offset{8};      // U bit
2076     let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2077     let Inst{19-16} = addr;
2078     let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2079     let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2080     let DecoderMethod = "DecodeAddrMode3Instruction";
2081   }
2082 }
2083
2084 let mayLoad = 1, neverHasSideEffects = 1 in {
2085 defm LDRH  : AI3_ldridx<0b1011, "ldrh", IIC_iLoad_bh_ru>;
2086 defm LDRSH : AI3_ldridx<0b1111, "ldrsh", IIC_iLoad_bh_ru>;
2087 defm LDRSB : AI3_ldridx<0b1101, "ldrsb", IIC_iLoad_bh_ru>;
2088 let hasExtraDefRegAllocReq = 1 in {
2089 def LDRD_PRE : AI3ldstidx<0b1101, 0, 1, (outs GPR:$Rt, GPR:$Rt2, GPR:$Rn_wb),
2090                           (ins addrmode3:$addr), IndexModePre,
2091                           LdMiscFrm, IIC_iLoad_d_ru,
2092                           "ldrd", "\t$Rt, $Rt2, $addr!",
2093                           "$addr.base = $Rn_wb", []> {
2094   bits<14> addr;
2095   let Inst{23}    = addr{8};      // U bit
2096   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2097   let Inst{19-16} = addr{12-9};   // Rn
2098   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2099   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2100   let DecoderMethod = "DecodeAddrMode3Instruction";
2101   let AsmMatchConverter = "cvtLdrdPre";
2102 }
2103 def LDRD_POST: AI3ldstidx<0b1101, 0, 0, (outs GPR:$Rt, GPR:$Rt2, GPR:$Rn_wb),
2104                           (ins addr_offset_none:$addr, am3offset:$offset),
2105                           IndexModePost, LdMiscFrm, IIC_iLoad_d_ru,
2106                           "ldrd", "\t$Rt, $Rt2, $addr, $offset",
2107                           "$addr.base = $Rn_wb", []> {
2108   bits<10> offset;
2109   bits<4> addr;
2110   let Inst{23}    = offset{8};      // U bit
2111   let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2112   let Inst{19-16} = addr;
2113   let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2114   let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2115   let DecoderMethod = "DecodeAddrMode3Instruction";
2116 }
2117 } // hasExtraDefRegAllocReq = 1
2118 } // mayLoad = 1, neverHasSideEffects = 1
2119
2120 // LDRT, LDRBT, LDRSBT, LDRHT, LDRSHT.
2121 let mayLoad = 1, neverHasSideEffects = 1 in {
2122 def LDRT_POST_REG : AI2ldstidx<1, 0, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2123                     (ins addr_offset_none:$addr, am2offset_reg:$offset),
2124                     IndexModePost, LdFrm, IIC_iLoad_ru,
2125                     "ldrt", "\t$Rt, $addr, $offset",
2126                     "$addr.base = $Rn_wb", []> {
2127   // {12}     isAdd
2128   // {11-0}   imm12/Rm
2129   bits<14> offset;
2130   bits<4> addr;
2131   let Inst{25} = 1;
2132   let Inst{23} = offset{12};
2133   let Inst{21} = 1; // overwrite
2134   let Inst{19-16} = addr;
2135   let Inst{11-5} = offset{11-5};
2136   let Inst{4} = 0;
2137   let Inst{3-0} = offset{3-0};
2138   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2139 }
2140
2141 def LDRT_POST_IMM : AI2ldstidx<1, 0, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2142                     (ins addr_offset_none:$addr, am2offset_imm:$offset),
2143                    IndexModePost, LdFrm, IIC_iLoad_ru,
2144                    "ldrt", "\t$Rt, $addr, $offset",
2145                    "$addr.base = $Rn_wb", []> {
2146   // {12}     isAdd
2147   // {11-0}   imm12/Rm
2148   bits<14> offset;
2149   bits<4> addr;
2150   let Inst{25} = 0;
2151   let Inst{23} = offset{12};
2152   let Inst{21} = 1; // overwrite
2153   let Inst{19-16} = addr;
2154   let Inst{11-0} = offset{11-0};
2155   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2156 }
2157
2158 def LDRBT_POST_REG : AI2ldstidx<1, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2159                      (ins addr_offset_none:$addr, am2offset_reg:$offset),
2160                      IndexModePost, LdFrm, IIC_iLoad_bh_ru,
2161                      "ldrbt", "\t$Rt, $addr, $offset",
2162                      "$addr.base = $Rn_wb", []> {
2163   // {12}     isAdd
2164   // {11-0}   imm12/Rm
2165   bits<14> offset;
2166   bits<4> addr;
2167   let Inst{25} = 1;
2168   let Inst{23} = offset{12};
2169   let Inst{21} = 1; // overwrite
2170   let Inst{19-16} = addr;
2171   let Inst{11-5} = offset{11-5};
2172   let Inst{4} = 0;
2173   let Inst{3-0} = offset{3-0};
2174   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2175 }
2176
2177 def LDRBT_POST_IMM : AI2ldstidx<1, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
2178                      (ins addr_offset_none:$addr, am2offset_imm:$offset),
2179                     IndexModePost, LdFrm, IIC_iLoad_bh_ru,
2180                     "ldrbt", "\t$Rt, $addr, $offset",
2181                     "$addr.base = $Rn_wb", []> {
2182   // {12}     isAdd
2183   // {11-0}   imm12/Rm
2184   bits<14> offset;
2185   bits<4> addr;
2186   let Inst{25} = 0;
2187   let Inst{23} = offset{12};
2188   let Inst{21} = 1; // overwrite
2189   let Inst{19-16} = addr;
2190   let Inst{11-0} = offset{11-0};
2191   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2192 }
2193
2194 multiclass AI3ldrT<bits<4> op, string opc> {
2195   def i : AI3ldstidxT<op, 1, (outs GPR:$Rt, GPR:$base_wb),
2196                       (ins addr_offset_none:$addr, postidx_imm8:$offset),
2197                       IndexModePost, LdMiscFrm, IIC_iLoad_bh_ru, opc,
2198                       "\t$Rt, $addr, $offset", "$addr.base = $base_wb", []> {
2199     bits<9> offset;
2200     let Inst{23} = offset{8};
2201     let Inst{22} = 1;
2202     let Inst{11-8} = offset{7-4};
2203     let Inst{3-0} = offset{3-0};
2204     let AsmMatchConverter = "cvtLdExtTWriteBackImm";
2205   }
2206   def r : AI3ldstidxT<op, 1, (outs GPR:$Rt, GPR:$base_wb),
2207                       (ins addr_offset_none:$addr, postidx_reg:$Rm),
2208                       IndexModePost, LdMiscFrm, IIC_iLoad_bh_ru, opc,
2209                       "\t$Rt, $addr, $Rm", "$addr.base = $base_wb", []> {
2210     bits<5> Rm;
2211     let Inst{23} = Rm{4};
2212     let Inst{22} = 0;
2213     let Inst{11-8} = 0;
2214     let Inst{3-0} = Rm{3-0};
2215     let AsmMatchConverter = "cvtLdExtTWriteBackReg";
2216   }
2217 }
2218
2219 defm LDRSBT : AI3ldrT<0b1101, "ldrsbt">;
2220 defm LDRHT  : AI3ldrT<0b1011, "ldrht">;
2221 defm LDRSHT : AI3ldrT<0b1111, "ldrsht">;
2222 }
2223
2224 // Store
2225
2226 // Stores with truncate
2227 def STRH : AI3str<0b1011, (outs), (ins GPR:$Rt, addrmode3:$addr), StMiscFrm,
2228                IIC_iStore_bh_r, "strh", "\t$Rt, $addr",
2229                [(truncstorei16 GPR:$Rt, addrmode3:$addr)]>;
2230
2231 // Store doubleword
2232 let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
2233 def STRD : AI3str<0b1111, (outs), (ins GPR:$Rt, GPR:$src2, addrmode3:$addr),
2234                StMiscFrm, IIC_iStore_d_r,
2235                "strd", "\t$Rt, $src2, $addr", []>,
2236            Requires<[IsARM, HasV5TE]> {
2237   let Inst{21} = 0;
2238 }
2239
2240 // Indexed stores
2241 multiclass AI2_stridx<bit isByte, string opc, InstrItinClass itin> {
2242   def _PRE_IMM : AI2ldstidx<0, isByte, 1, (outs GPR:$Rn_wb),
2243                             (ins GPR:$Rt, addrmode_imm12:$addr), IndexModePre,
2244                             StFrm, itin,
2245                             opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2246     bits<17> addr;
2247     let Inst{25} = 0;
2248     let Inst{23}    = addr{12};     // U (add = ('U' == 1))
2249     let Inst{19-16} = addr{16-13};  // Rn
2250     let Inst{11-0}  = addr{11-0};   // imm12
2251     let AsmMatchConverter = "cvtStWriteBackRegAddrModeImm12";
2252     let DecoderMethod = "DecodeSTRPreImm";
2253   }
2254
2255   def _PRE_REG  : AI2ldstidx<0, isByte, 1, (outs GPR:$Rn_wb),
2256                       (ins GPR:$Rt, ldst_so_reg:$addr),
2257                       IndexModePre, StFrm, itin,
2258                       opc, "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2259     bits<17> addr;
2260     let Inst{25} = 1;
2261     let Inst{23}    = addr{12};    // U (add = ('U' == 1))
2262     let Inst{19-16} = addr{16-13}; // Rn
2263     let Inst{11-0}  = addr{11-0};
2264     let Inst{4}     = 0;           // Inst{4} = 0
2265     let AsmMatchConverter = "cvtStWriteBackRegAddrMode2";
2266     let DecoderMethod = "DecodeSTRPreReg";
2267   }
2268   def _POST_REG : AI2ldstidx<0, isByte, 0, (outs GPR:$Rn_wb),
2269                 (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2270                 IndexModePost, StFrm, itin,
2271                 opc, "\t$Rt, $addr, $offset",
2272                 "$addr.base = $Rn_wb", []> {
2273      // {12}     isAdd
2274      // {11-0}   imm12/Rm
2275      bits<14> offset;
2276      bits<4> addr;
2277      let Inst{25} = 1;
2278      let Inst{23} = offset{12};
2279      let Inst{19-16} = addr;
2280      let Inst{11-0} = offset{11-0};
2281
2282     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2283    }
2284
2285    def _POST_IMM : AI2ldstidx<0, isByte, 0, (outs GPR:$Rn_wb),
2286                 (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2287                 IndexModePost, StFrm, itin,
2288                 opc, "\t$Rt, $addr, $offset",
2289                 "$addr.base = $Rn_wb", []> {
2290     // {12}     isAdd
2291     // {11-0}   imm12/Rm
2292     bits<14> offset;
2293     bits<4> addr;
2294     let Inst{25} = 0;
2295     let Inst{23} = offset{12};
2296     let Inst{19-16} = addr;
2297     let Inst{11-0} = offset{11-0};
2298
2299     let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2300   }
2301 }
2302
2303 let mayStore = 1, neverHasSideEffects = 1 in {
2304 defm STR  : AI2_stridx<0, "str", IIC_iStore_ru>;
2305 defm STRB : AI2_stridx<1, "strb", IIC_iStore_bh_ru>;
2306 }
2307
2308 def : ARMPat<(post_store GPR:$Rt, addr_offset_none:$addr,
2309                          am2offset_reg:$offset),
2310              (STR_POST_REG GPR:$Rt, addr_offset_none:$addr,
2311                            am2offset_reg:$offset)>;
2312 def : ARMPat<(post_store GPR:$Rt, addr_offset_none:$addr,
2313                          am2offset_imm:$offset),
2314              (STR_POST_IMM GPR:$Rt, addr_offset_none:$addr,
2315                            am2offset_imm:$offset)>;
2316 def : ARMPat<(post_truncsti8 GPR:$Rt, addr_offset_none:$addr,
2317                              am2offset_reg:$offset),
2318              (STRB_POST_REG GPR:$Rt, addr_offset_none:$addr,
2319                             am2offset_reg:$offset)>;
2320 def : ARMPat<(post_truncsti8 GPR:$Rt, addr_offset_none:$addr,
2321                              am2offset_imm:$offset),
2322              (STRB_POST_IMM GPR:$Rt, addr_offset_none:$addr,
2323                             am2offset_imm:$offset)>;
2324
2325 // Pseudo-instructions for pattern matching the pre-indexed stores. We can't
2326 // put the patterns on the instruction definitions directly as ISel wants
2327 // the address base and offset to be separate operands, not a single
2328 // complex operand like we represent the instructions themselves. The
2329 // pseudos map between the two.
2330 let usesCustomInserter = 1,
2331     Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
2332 def STRi_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2333                (ins GPR:$Rt, GPR:$Rn, am2offset_imm:$offset, pred:$p),
2334                4, IIC_iStore_ru,
2335             [(set GPR:$Rn_wb,
2336                   (pre_store GPR:$Rt, GPR:$Rn, am2offset_imm:$offset))]>;
2337 def STRr_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2338                (ins GPR:$Rt, GPR:$Rn, am2offset_reg:$offset, pred:$p),
2339                4, IIC_iStore_ru,
2340             [(set GPR:$Rn_wb,
2341                   (pre_store GPR:$Rt, GPR:$Rn, am2offset_reg:$offset))]>;
2342 def STRBi_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2343                (ins GPR:$Rt, GPR:$Rn, am2offset_imm:$offset, pred:$p),
2344                4, IIC_iStore_ru,
2345             [(set GPR:$Rn_wb,
2346                   (pre_truncsti8 GPR:$Rt, GPR:$Rn, am2offset_imm:$offset))]>;
2347 def STRBr_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2348                (ins GPR:$Rt, GPR:$Rn, am2offset_reg:$offset, pred:$p),
2349                4, IIC_iStore_ru,
2350             [(set GPR:$Rn_wb,
2351                   (pre_truncsti8 GPR:$Rt, GPR:$Rn, am2offset_reg:$offset))]>;
2352 def STRH_preidx: ARMPseudoInst<(outs GPR:$Rn_wb),
2353                (ins GPR:$Rt, GPR:$Rn, am3offset:$offset, pred:$p),
2354                4, IIC_iStore_ru,
2355             [(set GPR:$Rn_wb,
2356                   (pre_truncsti16 GPR:$Rt, GPR:$Rn, am3offset:$offset))]>;
2357 }
2358
2359
2360
2361 def STRH_PRE  : AI3ldstidx<0b1011, 0, 1, (outs GPR:$Rn_wb),
2362                            (ins GPR:$Rt, addrmode3:$addr), IndexModePre,
2363                            StMiscFrm, IIC_iStore_bh_ru,
2364                            "strh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []> {
2365   bits<14> addr;
2366   let Inst{23}    = addr{8};      // U bit
2367   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2368   let Inst{19-16} = addr{12-9};   // Rn
2369   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2370   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2371   let AsmMatchConverter = "cvtStWriteBackRegAddrMode3";
2372   let DecoderMethod = "DecodeAddrMode3Instruction";
2373 }
2374
2375 def STRH_POST : AI3ldstidx<0b1011, 0, 0, (outs GPR:$Rn_wb),
2376                        (ins GPR:$Rt, addr_offset_none:$addr, am3offset:$offset),
2377                        IndexModePost, StMiscFrm, IIC_iStore_bh_ru,
2378                        "strh", "\t$Rt, $addr, $offset", "$addr.base = $Rn_wb",
2379                    [(set GPR:$Rn_wb, (post_truncsti16 GPR:$Rt,
2380                                                       addr_offset_none:$addr,
2381                                                       am3offset:$offset))]> {
2382   bits<10> offset;
2383   bits<4> addr;
2384   let Inst{23}    = offset{8};      // U bit
2385   let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2386   let Inst{19-16} = addr;
2387   let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2388   let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2389   let DecoderMethod = "DecodeAddrMode3Instruction";
2390 }
2391
2392 let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in {
2393 def STRD_PRE : AI3ldstidx<0b1111, 0, 1, (outs GPR:$Rn_wb),
2394                           (ins GPR:$Rt, GPR:$Rt2, addrmode3:$addr),
2395                           IndexModePre, StMiscFrm, IIC_iStore_d_ru,
2396                           "strd", "\t$Rt, $Rt2, $addr!",
2397                           "$addr.base = $Rn_wb", []> {
2398   bits<14> addr;
2399   let Inst{23}    = addr{8};      // U bit
2400   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
2401   let Inst{19-16} = addr{12-9};   // Rn
2402   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
2403   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
2404   let DecoderMethod = "DecodeAddrMode3Instruction";
2405   let AsmMatchConverter = "cvtStrdPre";
2406 }
2407
2408 def STRD_POST: AI3ldstidx<0b1111, 0, 0, (outs GPR:$Rn_wb),
2409                           (ins GPR:$Rt, GPR:$Rt2, addr_offset_none:$addr,
2410                                am3offset:$offset),
2411                           IndexModePost, StMiscFrm, IIC_iStore_d_ru,
2412                           "strd", "\t$Rt, $Rt2, $addr, $offset",
2413                           "$addr.base = $Rn_wb", []> {
2414   bits<10> offset;
2415   bits<4> addr;
2416   let Inst{23}    = offset{8};      // U bit
2417   let Inst{22}    = offset{9};      // 1 == imm8, 0 == Rm
2418   let Inst{19-16} = addr;
2419   let Inst{11-8}  = offset{7-4};    // imm7_4/zero
2420   let Inst{3-0}   = offset{3-0};    // imm3_0/Rm
2421   let DecoderMethod = "DecodeAddrMode3Instruction";
2422 }
2423 } // mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1
2424
2425 // STRT, STRBT, and STRHT
2426
2427 def STRBT_POST_REG : AI2ldstidx<0, 1, 0, (outs GPR:$Rn_wb),
2428                    (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2429                    IndexModePost, StFrm, IIC_iStore_bh_ru,
2430                    "strbt", "\t$Rt, $addr, $offset",
2431                    "$addr.base = $Rn_wb", []> {
2432   // {12}     isAdd
2433   // {11-0}   imm12/Rm
2434   bits<14> offset;
2435   bits<4> addr;
2436   let Inst{25} = 1;
2437   let Inst{23} = offset{12};
2438   let Inst{21} = 1; // overwrite
2439   let Inst{19-16} = addr;
2440   let Inst{11-5} = offset{11-5};
2441   let Inst{4} = 0;
2442   let Inst{3-0} = offset{3-0};
2443   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2444 }
2445
2446 def STRBT_POST_IMM : AI2ldstidx<0, 1, 0, (outs GPR:$Rn_wb),
2447                    (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2448                    IndexModePost, StFrm, IIC_iStore_bh_ru,
2449                    "strbt", "\t$Rt, $addr, $offset",
2450                    "$addr.base = $Rn_wb", []> {
2451   // {12}     isAdd
2452   // {11-0}   imm12/Rm
2453   bits<14> offset;
2454   bits<4> addr;
2455   let Inst{25} = 0;
2456   let Inst{23} = offset{12};
2457   let Inst{21} = 1; // overwrite
2458   let Inst{19-16} = addr;
2459   let Inst{11-0} = offset{11-0};
2460   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2461 }
2462
2463 let mayStore = 1, neverHasSideEffects = 1 in {
2464 def STRT_POST_REG : AI2ldstidx<0, 0, 0, (outs GPR:$Rn_wb),
2465                    (ins GPR:$Rt, addr_offset_none:$addr, am2offset_reg:$offset),
2466                    IndexModePost, StFrm, IIC_iStore_ru,
2467                    "strt", "\t$Rt, $addr, $offset",
2468                    "$addr.base = $Rn_wb", []> {
2469   // {12}     isAdd
2470   // {11-0}   imm12/Rm
2471   bits<14> offset;
2472   bits<4> addr;
2473   let Inst{25} = 1;
2474   let Inst{23} = offset{12};
2475   let Inst{21} = 1; // overwrite
2476   let Inst{19-16} = addr;
2477   let Inst{11-5} = offset{11-5};
2478   let Inst{4} = 0;
2479   let Inst{3-0} = offset{3-0};
2480   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2481 }
2482
2483 def STRT_POST_IMM : AI2ldstidx<0, 0, 0, (outs GPR:$Rn_wb),
2484                    (ins GPR:$Rt, addr_offset_none:$addr, am2offset_imm:$offset),
2485                    IndexModePost, StFrm, IIC_iStore_ru,
2486                    "strt", "\t$Rt, $addr, $offset",
2487                    "$addr.base = $Rn_wb", []> {
2488   // {12}     isAdd
2489   // {11-0}   imm12/Rm
2490   bits<14> offset;
2491   bits<4> addr;
2492   let Inst{25} = 0;
2493   let Inst{23} = offset{12};
2494   let Inst{21} = 1; // overwrite
2495   let Inst{19-16} = addr;
2496   let Inst{11-0} = offset{11-0};
2497   let DecoderMethod = "DecodeAddrMode2IdxInstruction";
2498 }
2499 }
2500
2501
2502 multiclass AI3strT<bits<4> op, string opc> {
2503   def i : AI3ldstidxT<op, 0, (outs GPR:$base_wb),
2504                     (ins GPR:$Rt, addr_offset_none:$addr, postidx_imm8:$offset),
2505                     IndexModePost, StMiscFrm, IIC_iStore_bh_ru, opc,
2506                     "\t$Rt, $addr, $offset", "$addr.base = $base_wb", []> {
2507     bits<9> offset;
2508     let Inst{23} = offset{8};
2509     let Inst{22} = 1;
2510     let Inst{11-8} = offset{7-4};
2511     let Inst{3-0} = offset{3-0};
2512     let AsmMatchConverter = "cvtStExtTWriteBackImm";
2513   }
2514   def r : AI3ldstidxT<op, 0, (outs GPR:$base_wb),
2515                       (ins GPR:$Rt, addr_offset_none:$addr, postidx_reg:$Rm),
2516                       IndexModePost, StMiscFrm, IIC_iStore_bh_ru, opc,
2517                       "\t$Rt, $addr, $Rm", "$addr.base = $base_wb", []> {
2518     bits<5> Rm;
2519     let Inst{23} = Rm{4};
2520     let Inst{22} = 0;
2521     let Inst{11-8} = 0;
2522     let Inst{3-0} = Rm{3-0};
2523     let AsmMatchConverter = "cvtStExtTWriteBackReg";
2524   }
2525 }
2526
2527
2528 defm STRHT : AI3strT<0b1011, "strht">;
2529
2530
2531 //===----------------------------------------------------------------------===//
2532 //  Load / store multiple Instructions.
2533 //
2534
2535 multiclass arm_ldst_mult<string asm, bit L_bit, Format f,
2536                          InstrItinClass itin, InstrItinClass itin_upd> {
2537   // IA is the default, so no need for an explicit suffix on the
2538   // mnemonic here. Without it is the cannonical spelling.
2539   def IA :
2540     AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2541          IndexModeNone, f, itin,
2542          !strconcat(asm, "${p}\t$Rn, $regs"), "", []> {
2543     let Inst{24-23} = 0b01;       // Increment After
2544     let Inst{21}    = 0;          // No writeback
2545     let Inst{20}    = L_bit;
2546   }
2547   def IA_UPD :
2548     AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2549          IndexModeUpd, f, itin_upd,
2550          !strconcat(asm, "${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
2551     let Inst{24-23} = 0b01;       // Increment After
2552     let Inst{21}    = 1;          // Writeback
2553     let Inst{20}    = L_bit;
2554
2555     let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2556   }
2557   def DA :
2558     AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2559          IndexModeNone, f, itin,
2560          !strconcat(asm, "da${p}\t$Rn, $regs"), "", []> {
2561     let Inst{24-23} = 0b00;       // Decrement After
2562     let Inst{21}    = 0;          // No writeback
2563     let Inst{20}    = L_bit;
2564   }
2565   def DA_UPD :
2566     AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2567          IndexModeUpd, f, itin_upd,
2568          !strconcat(asm, "da${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
2569     let Inst{24-23} = 0b00;       // Decrement After
2570     let Inst{21}    = 1;          // Writeback
2571     let Inst{20}    = L_bit;
2572
2573     let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2574   }
2575   def DB :
2576     AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2577          IndexModeNone, f, itin,
2578          !strconcat(asm, "db${p}\t$Rn, $regs"), "", []> {
2579     let Inst{24-23} = 0b10;       // Decrement Before
2580     let Inst{21}    = 0;          // No writeback
2581     let Inst{20}    = L_bit;
2582   }
2583   def DB_UPD :
2584     AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2585          IndexModeUpd, f, itin_upd,
2586          !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
2587     let Inst{24-23} = 0b10;       // Decrement Before
2588     let Inst{21}    = 1;          // Writeback
2589     let Inst{20}    = L_bit;
2590
2591     let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2592   }
2593   def IB :
2594     AXI4<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2595          IndexModeNone, f, itin,
2596          !strconcat(asm, "ib${p}\t$Rn, $regs"), "", []> {
2597     let Inst{24-23} = 0b11;       // Increment Before
2598     let Inst{21}    = 0;          // No writeback
2599     let Inst{20}    = L_bit;
2600   }
2601   def IB_UPD :
2602     AXI4<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
2603          IndexModeUpd, f, itin_upd,
2604          !strconcat(asm, "ib${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
2605     let Inst{24-23} = 0b11;       // Increment Before
2606     let Inst{21}    = 1;          // Writeback
2607     let Inst{20}    = L_bit;
2608
2609     let DecoderMethod = "DecodeMemMultipleWritebackInstruction";
2610   }
2611 }
2612
2613 let neverHasSideEffects = 1 in {
2614
2615 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
2616 defm LDM : arm_ldst_mult<"ldm", 1, LdStMulFrm, IIC_iLoad_m, IIC_iLoad_mu>;
2617
2618 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
2619 defm STM : arm_ldst_mult<"stm", 0, LdStMulFrm, IIC_iStore_m, IIC_iStore_mu>;
2620
2621 } // neverHasSideEffects
2622
2623 // FIXME: remove when we have a way to marking a MI with these properties.
2624 // FIXME: Should pc be an implicit operand like PICADD, etc?
2625 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
2626     hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
2627 def LDMIA_RET : ARMPseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
2628                                                  reglist:$regs, variable_ops),
2629                      4, IIC_iLoad_mBr, [],
2630                      (LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
2631       RegConstraint<"$Rn = $wb">;
2632
2633 //===----------------------------------------------------------------------===//
2634 //  Move Instructions.
2635 //
2636
2637 let neverHasSideEffects = 1 in
2638 def MOVr : AsI1<0b1101, (outs GPR:$Rd), (ins GPR:$Rm), DPFrm, IIC_iMOVr,
2639                 "mov", "\t$Rd, $Rm", []>, UnaryDP {
2640   bits<4> Rd;
2641   bits<4> Rm;
2642
2643   let Inst{19-16} = 0b0000;
2644   let Inst{11-4} = 0b00000000;
2645   let Inst{25} = 0;
2646   let Inst{3-0} = Rm;
2647   let Inst{15-12} = Rd;
2648 }
2649
2650 // A version for the smaller set of tail call registers.
2651 let neverHasSideEffects = 1 in
2652 def MOVr_TC : AsI1<0b1101, (outs tcGPR:$Rd), (ins tcGPR:$Rm), DPFrm,
2653                 IIC_iMOVr, "mov", "\t$Rd, $Rm", []>, UnaryDP {
2654   bits<4> Rd;
2655   bits<4> Rm;
2656
2657   let Inst{11-4} = 0b00000000;
2658   let Inst{25} = 0;
2659   let Inst{3-0} = Rm;
2660   let Inst{15-12} = Rd;
2661 }
2662
2663 def MOVsr : AsI1<0b1101, (outs GPRnopc:$Rd), (ins shift_so_reg_reg:$src),
2664                 DPSoRegRegFrm, IIC_iMOVsr,
2665                 "mov", "\t$Rd, $src",
2666                 [(set GPRnopc:$Rd, shift_so_reg_reg:$src)]>, UnaryDP {
2667   bits<4> Rd;
2668   bits<12> src;
2669   let Inst{15-12} = Rd;
2670   let Inst{19-16} = 0b0000;
2671   let Inst{11-8} = src{11-8};
2672   let Inst{7} = 0;
2673   let Inst{6-5} = src{6-5};
2674   let Inst{4} = 1;
2675   let Inst{3-0} = src{3-0};
2676   let Inst{25} = 0;
2677 }
2678
2679 def MOVsi : AsI1<0b1101, (outs GPR:$Rd), (ins shift_so_reg_imm:$src),
2680                 DPSoRegImmFrm, IIC_iMOVsr,
2681                 "mov", "\t$Rd, $src", [(set GPR:$Rd, shift_so_reg_imm:$src)]>,
2682                 UnaryDP {
2683   bits<4> Rd;
2684   bits<12> src;
2685   let Inst{15-12} = Rd;
2686   let Inst{19-16} = 0b0000;
2687   let Inst{11-5} = src{11-5};
2688   let Inst{4} = 0;
2689   let Inst{3-0} = src{3-0};
2690   let Inst{25} = 0;
2691 }
2692
2693 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
2694 def MOVi : AsI1<0b1101, (outs GPR:$Rd), (ins so_imm:$imm), DPFrm, IIC_iMOVi,
2695                 "mov", "\t$Rd, $imm", [(set GPR:$Rd, so_imm:$imm)]>, UnaryDP {
2696   bits<4> Rd;
2697   bits<12> imm;
2698   let Inst{25} = 1;
2699   let Inst{15-12} = Rd;
2700   let Inst{19-16} = 0b0000;
2701   let Inst{11-0} = imm;
2702 }
2703
2704 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
2705 def MOVi16 : AI1<0b1000, (outs GPR:$Rd), (ins imm0_65535_expr:$imm),
2706                  DPFrm, IIC_iMOVi,
2707                  "movw", "\t$Rd, $imm",
2708                  [(set GPR:$Rd, imm0_65535:$imm)]>,
2709                  Requires<[IsARM, HasV6T2]>, UnaryDP {
2710   bits<4> Rd;
2711   bits<16> imm;
2712   let Inst{15-12} = Rd;
2713   let Inst{11-0}  = imm{11-0};
2714   let Inst{19-16} = imm{15-12};
2715   let Inst{20} = 0;
2716   let Inst{25} = 1;
2717 }
2718
2719 def : InstAlias<"mov${p} $Rd, $imm",
2720                 (MOVi16 GPR:$Rd, imm0_65535_expr:$imm, pred:$p)>,
2721         Requires<[IsARM]>;
2722
2723 def MOVi16_ga_pcrel : PseudoInst<(outs GPR:$Rd),
2724                                 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
2725
2726 let Constraints = "$src = $Rd" in {
2727 def MOVTi16 : AI1<0b1010, (outs GPRnopc:$Rd),
2728                   (ins GPR:$src, imm0_65535_expr:$imm),
2729                   DPFrm, IIC_iMOVi,
2730                   "movt", "\t$Rd, $imm",
2731                   [(set GPRnopc:$Rd,
2732                         (or (and GPR:$src, 0xffff),
2733                             lo16AllZero:$imm))]>, UnaryDP,
2734                   Requires<[IsARM, HasV6T2]> {
2735   bits<4> Rd;
2736   bits<16> imm;
2737   let Inst{15-12} = Rd;
2738   let Inst{11-0}  = imm{11-0};
2739   let Inst{19-16} = imm{15-12};
2740   let Inst{20} = 0;
2741   let Inst{25} = 1;
2742 }
2743
2744 def MOVTi16_ga_pcrel : PseudoInst<(outs GPR:$Rd),
2745                       (ins GPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
2746
2747 } // Constraints
2748
2749 def : ARMPat<(or GPR:$src, 0xffff0000), (MOVTi16 GPR:$src, 0xffff)>,
2750       Requires<[IsARM, HasV6T2]>;
2751
2752 let Uses = [CPSR] in
2753 def RRX: PseudoInst<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVsi,
2754                     [(set GPR:$Rd, (ARMrrx GPR:$Rm))]>, UnaryDP,
2755                     Requires<[IsARM]>;
2756
2757 // These aren't really mov instructions, but we have to define them this way
2758 // due to flag operands.
2759
2760 let Defs = [CPSR] in {
2761 def MOVsrl_flag : PseudoInst<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVsi,
2762                       [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, UnaryDP,
2763                       Requires<[IsARM]>;
2764 def MOVsra_flag : PseudoInst<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVsi,
2765                       [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, UnaryDP,
2766                       Requires<[IsARM]>;
2767 }
2768
2769 //===----------------------------------------------------------------------===//
2770 //  Extend Instructions.
2771 //
2772
2773 // Sign extenders
2774
2775 def SXTB  : AI_ext_rrot<0b01101010,
2776                          "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
2777 def SXTH  : AI_ext_rrot<0b01101011,
2778                          "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
2779
2780 def SXTAB : AI_exta_rrot<0b01101010,
2781                "sxtab", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
2782 def SXTAH : AI_exta_rrot<0b01101011,
2783                "sxtah", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
2784
2785 def SXTB16  : AI_ext_rrot_np<0b01101000, "sxtb16">;
2786
2787 def SXTAB16 : AI_exta_rrot_np<0b01101000, "sxtab16">;
2788
2789 // Zero extenders
2790
2791 let AddedComplexity = 16 in {
2792 def UXTB   : AI_ext_rrot<0b01101110,
2793                           "uxtb"  , UnOpFrag<(and node:$Src, 0x000000FF)>>;
2794 def UXTH   : AI_ext_rrot<0b01101111,
2795                           "uxth"  , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
2796 def UXTB16 : AI_ext_rrot<0b01101100,
2797                           "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
2798
2799 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
2800 //        The transformation should probably be done as a combiner action
2801 //        instead so we can include a check for masking back in the upper
2802 //        eight bits of the source into the lower eight bits of the result.
2803 //def : ARMV6Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
2804 //               (UXTB16r_rot GPR:$Src, 3)>;
2805 def : ARMV6Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
2806                (UXTB16 GPR:$Src, 1)>;
2807
2808 def UXTAB : AI_exta_rrot<0b01101110, "uxtab",
2809                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
2810 def UXTAH : AI_exta_rrot<0b01101111, "uxtah",
2811                         BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
2812 }
2813
2814 // This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
2815 def UXTAB16 : AI_exta_rrot_np<0b01101100, "uxtab16">;
2816
2817
2818 def SBFX  : I<(outs GPRnopc:$Rd),
2819               (ins GPRnopc:$Rn, imm0_31:$lsb, imm1_32:$width),
2820                AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
2821                "sbfx", "\t$Rd, $Rn, $lsb, $width", "", []>,
2822                Requires<[IsARM, HasV6T2]> {
2823   bits<4> Rd;
2824   bits<4> Rn;
2825   bits<5> lsb;
2826   bits<5> width;
2827   let Inst{27-21} = 0b0111101;
2828   let Inst{6-4}   = 0b101;
2829   let Inst{20-16} = width;
2830   let Inst{15-12} = Rd;
2831   let Inst{11-7}  = lsb;
2832   let Inst{3-0}   = Rn;
2833 }
2834
2835 def UBFX  : I<(outs GPR:$Rd),
2836               (ins GPR:$Rn, imm0_31:$lsb, imm1_32:$width),
2837                AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
2838                "ubfx", "\t$Rd, $Rn, $lsb, $width", "", []>,
2839                Requires<[IsARM, HasV6T2]> {
2840   bits<4> Rd;
2841   bits<4> Rn;
2842   bits<5> lsb;
2843   bits<5> width;
2844   let Inst{27-21} = 0b0111111;
2845   let Inst{6-4}   = 0b101;
2846   let Inst{20-16} = width;
2847   let Inst{15-12} = Rd;
2848   let Inst{11-7}  = lsb;
2849   let Inst{3-0}   = Rn;
2850 }
2851
2852 //===----------------------------------------------------------------------===//
2853 //  Arithmetic Instructions.
2854 //
2855
2856 defm ADD  : AsI1_bin_irs<0b0100, "add",
2857                          IIC_iALUi, IIC_iALUr, IIC_iALUsr,
2858                          BinOpFrag<(add  node:$LHS, node:$RHS)>, "ADD", 1>;
2859 defm SUB  : AsI1_bin_irs<0b0010, "sub",
2860                          IIC_iALUi, IIC_iALUr, IIC_iALUsr,
2861                          BinOpFrag<(sub  node:$LHS, node:$RHS)>, "SUB">;
2862
2863 // ADD and SUB with 's' bit set.
2864 defm ADDS : AI1_bin_s_irs<0b0100, "adds",
2865                           IIC_iALUi, IIC_iALUr, IIC_iALUsr,
2866                           BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
2867 defm SUBS : AI1_bin_s_irs<0b0010, "subs",
2868                           IIC_iALUi, IIC_iALUr, IIC_iALUsr,
2869                           BinOpFrag<(subc node:$LHS, node:$RHS)>>;
2870
2871 defm ADC : AI1_adde_sube_irs<0b0101, "adc",
2872                           BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>,
2873                           "ADC", 1>;
2874 defm SBC : AI1_adde_sube_irs<0b0110, "sbc",
2875                           BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>,
2876                           "SBC">;
2877
2878 // ADC and SUBC with 's' bit set.
2879 let usesCustomInserter = 1 in {
2880 defm ADCS : AI1_adde_sube_s_irs<
2881               BinOpFrag<(adde_live_carry node:$LHS, node:$RHS)>, 1>;
2882 defm SBCS : AI1_adde_sube_s_irs<
2883               BinOpFrag<(sube_live_carry node:$LHS, node:$RHS) >>;
2884 }
2885
2886 def RSBri : AsI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm), DPFrm,
2887                  IIC_iALUi, "rsb", "\t$Rd, $Rn, $imm",
2888                  [(set GPR:$Rd, (sub so_imm:$imm, GPR:$Rn))]> {
2889   bits<4> Rd;
2890   bits<4> Rn;
2891   bits<12> imm;
2892   let Inst{25} = 1;
2893   let Inst{15-12} = Rd;
2894   let Inst{19-16} = Rn;
2895   let Inst{11-0} = imm;
2896 }
2897
2898 def RSBrr : AsI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), DPFrm,
2899                  IIC_iALUr, "rsb", "\t$Rd, $Rn, $Rm", []> {
2900   bits<4> Rd;
2901   bits<4> Rn;
2902   bits<4> Rm;
2903   let Inst{11-4} = 0b00000000;
2904   let Inst{25} = 0;
2905   let Inst{3-0} = Rm;
2906   let Inst{15-12} = Rd;
2907   let Inst{19-16} = Rn;
2908 }
2909
2910 def RSBrsi : AsI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, so_reg_imm:$shift),
2911                  DPSoRegImmFrm, IIC_iALUsr, "rsb", "\t$Rd, $Rn, $shift",
2912                  [(set GPR:$Rd, (sub so_reg_imm:$shift, GPR:$Rn))]> {
2913   bits<4> Rd;
2914   bits<4> Rn;
2915   bits<12> shift;
2916   let Inst{25} = 0;
2917   let Inst{19-16} = Rn;
2918   let Inst{15-12} = Rd;
2919   let Inst{11-5} = shift{11-5};
2920   let Inst{4} = 0;
2921   let Inst{3-0} = shift{3-0};
2922 }
2923
2924 def RSBrsr : AsI1<0b0011, (outs GPR:$Rd), (ins GPR:$Rn, so_reg_reg:$shift),
2925                  DPSoRegRegFrm, IIC_iALUsr, "rsb", "\t$Rd, $Rn, $shift",
2926                  [(set GPR:$Rd, (sub so_reg_reg:$shift, GPR:$Rn))]> {
2927   bits<4> Rd;
2928   bits<4> Rn;
2929   bits<12> shift;
2930   let Inst{25} = 0;
2931   let Inst{19-16} = Rn;
2932   let Inst{15-12} = Rd;
2933   let Inst{11-8} = shift{11-8};
2934   let Inst{7} = 0;
2935   let Inst{6-5} = shift{6-5};
2936   let Inst{4} = 1;
2937   let Inst{3-0} = shift{3-0};
2938 }
2939
2940 // RSB with 's' bit set.
2941 // NOTE: CPSR def omitted because it will be handled by the custom inserter.
2942 let usesCustomInserter = 1 in {
2943 def RSBSri : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
2944                  4, IIC_iALUi,
2945                  [(set GPR:$Rd, (subc so_imm:$imm, GPR:$Rn))]>;
2946 def RSBSrr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2947                  4, IIC_iALUr, []>;
2948 def RSBSrsi : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_reg_imm:$shift),
2949                  4, IIC_iALUsr,
2950                  [(set GPR:$Rd, (subc so_reg_imm:$shift, GPR:$Rn))]>;
2951 def RSBSrsr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_reg_reg:$shift),
2952                  4, IIC_iALUsr,
2953                  [(set GPR:$Rd, (subc so_reg_reg:$shift, GPR:$Rn))]>;
2954 }
2955
2956 let Uses = [CPSR] in {
2957 def RSCri : AsI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
2958                  DPFrm, IIC_iALUi, "rsc", "\t$Rd, $Rn, $imm",
2959                  [(set GPR:$Rd, (sube_dead_carry so_imm:$imm, GPR:$Rn))]>,
2960                  Requires<[IsARM]> {
2961   bits<4> Rd;
2962   bits<4> Rn;
2963   bits<12> imm;
2964   let Inst{25} = 1;
2965   let Inst{15-12} = Rd;
2966   let Inst{19-16} = Rn;
2967   let Inst{11-0} = imm;
2968 }
2969 def RSCrr : AsI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
2970                  DPFrm, IIC_iALUr, "rsc", "\t$Rd, $Rn, $Rm", []> {
2971   bits<4> Rd;
2972   bits<4> Rn;
2973   bits<4> Rm;
2974   let Inst{11-4} = 0b00000000;
2975   let Inst{25} = 0;
2976   let Inst{3-0} = Rm;
2977   let Inst{15-12} = Rd;
2978   let Inst{19-16} = Rn;
2979 }
2980 def RSCrsi : AsI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, so_reg_imm:$shift),
2981                  DPSoRegImmFrm, IIC_iALUsr, "rsc", "\t$Rd, $Rn, $shift",
2982                  [(set GPR:$Rd, (sube_dead_carry so_reg_imm:$shift, GPR:$Rn))]>,
2983                  Requires<[IsARM]> {
2984   bits<4> Rd;
2985   bits<4> Rn;
2986   bits<12> shift;
2987   let Inst{25} = 0;
2988   let Inst{19-16} = Rn;
2989   let Inst{15-12} = Rd;
2990   let Inst{11-5} = shift{11-5};
2991   let Inst{4} = 0;
2992   let Inst{3-0} = shift{3-0};
2993 }
2994 def RSCrsr : AsI1<0b0111, (outs GPR:$Rd), (ins GPR:$Rn, so_reg_reg:$shift),
2995                  DPSoRegRegFrm, IIC_iALUsr, "rsc", "\t$Rd, $Rn, $shift",
2996                  [(set GPR:$Rd, (sube_dead_carry so_reg_reg:$shift, GPR:$Rn))]>,
2997                  Requires<[IsARM]> {
2998   bits<4> Rd;
2999   bits<4> Rn;
3000   bits<12> shift;
3001   let Inst{25} = 0;
3002   let Inst{19-16} = Rn;
3003   let Inst{15-12} = Rd;
3004   let Inst{11-8} = shift{11-8};
3005   let Inst{7} = 0;
3006   let Inst{6-5} = shift{6-5};
3007   let Inst{4} = 1;
3008   let Inst{3-0} = shift{3-0};
3009 }
3010 }
3011
3012
3013 // NOTE: CPSR def omitted because it will be handled by the custom inserter.
3014 let usesCustomInserter = 1, Uses = [CPSR] in {
3015 def RSCSri : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_imm:$imm),
3016                   4, IIC_iALUi,
3017                   [(set GPR:$Rd, (sube_dead_carry so_imm:$imm, GPR:$Rn))]>;
3018 def RSCSrsi : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_reg_imm:$shift),
3019                   4, IIC_iALUsr,
3020                 [(set GPR:$Rd, (sube_dead_carry so_reg_imm:$shift, GPR:$Rn))]>;
3021 def RSCSrsr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$Rn, so_reg_reg:$shift),
3022                   4, IIC_iALUsr,
3023                 [(set GPR:$Rd, (sube_dead_carry so_reg_reg:$shift, GPR:$Rn))]>;
3024 }
3025
3026 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
3027 // The assume-no-carry-in form uses the negation of the input since add/sub
3028 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
3029 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
3030 // details.
3031 def : ARMPat<(add    GPR:$src, so_imm_neg:$imm),
3032              (SUBri  GPR:$src, so_imm_neg:$imm)>;
3033 def : ARMPat<(addc   GPR:$src, so_imm_neg:$imm),
3034              (SUBSri GPR:$src, so_imm_neg:$imm)>;
3035 // The with-carry-in form matches bitwise not instead of the negation.
3036 // Effectively, the inverse interpretation of the carry flag already accounts
3037 // for part of the negation.
3038 def : ARMPat<(adde_dead_carry   GPR:$src, so_imm_not:$imm),
3039              (SBCri  GPR:$src, so_imm_not:$imm)>;
3040 def : ARMPat<(adde_live_carry   GPR:$src, so_imm_not:$imm),
3041              (SBCSri GPR:$src, so_imm_not:$imm)>;
3042
3043 // Note: These are implemented in C++ code, because they have to generate
3044 // ADD/SUBrs instructions, which use a complex pattern that a xform function
3045 // cannot produce.
3046 // (mul X, 2^n+1) -> (add (X << n), X)
3047 // (mul X, 2^n-1) -> (rsb X, (X << n))
3048
3049 // ARM Arithmetic Instruction
3050 // GPR:$dst = GPR:$a op GPR:$b
3051 class AAI<bits<8> op27_20, bits<8> op11_4, string opc,
3052           list<dag> pattern = [],
3053           dag iops = (ins GPRnopc:$Rn, GPRnopc:$Rm),
3054           string asm = "\t$Rd, $Rn, $Rm">
3055   : AI<(outs GPRnopc:$Rd), iops, DPFrm, IIC_iALUr, opc, asm, pattern> {
3056   bits<4> Rn;
3057   bits<4> Rd;
3058   bits<4> Rm;
3059   let Inst{27-20} = op27_20;
3060   let Inst{11-4} = op11_4;
3061   let Inst{19-16} = Rn;
3062   let Inst{15-12} = Rd;
3063   let Inst{3-0}   = Rm;
3064 }
3065
3066 // Saturating add/subtract
3067
3068 def QADD    : AAI<0b00010000, 0b00000101, "qadd",
3069                   [(set GPRnopc:$Rd, (int_arm_qadd GPRnopc:$Rm, GPRnopc:$Rn))],
3070                   (ins GPRnopc:$Rm, GPRnopc:$Rn), "\t$Rd, $Rm, $Rn">;
3071 def QSUB    : AAI<0b00010010, 0b00000101, "qsub",
3072                   [(set GPRnopc:$Rd, (int_arm_qsub GPRnopc:$Rm, GPRnopc:$Rn))],
3073                   (ins GPRnopc:$Rm, GPRnopc:$Rn), "\t$Rd, $Rm, $Rn">;
3074 def QDADD   : AAI<0b00010100, 0b00000101, "qdadd", [],
3075                   (ins GPRnopc:$Rm, GPRnopc:$Rn),
3076                   "\t$Rd, $Rm, $Rn">;
3077 def QDSUB   : AAI<0b00010110, 0b00000101, "qdsub", [],
3078                   (ins GPRnopc:$Rm, GPRnopc:$Rn),
3079                   "\t$Rd, $Rm, $Rn">;
3080
3081 def QADD16  : AAI<0b01100010, 0b11110001, "qadd16">;
3082 def QADD8   : AAI<0b01100010, 0b11111001, "qadd8">;
3083 def QASX    : AAI<0b01100010, 0b11110011, "qasx">;
3084 def QSAX    : AAI<0b01100010, 0b11110101, "qsax">;
3085 def QSUB16  : AAI<0b01100010, 0b11110111, "qsub16">;
3086 def QSUB8   : AAI<0b01100010, 0b11111111, "qsub8">;
3087 def UQADD16 : AAI<0b01100110, 0b11110001, "uqadd16">;
3088 def UQADD8  : AAI<0b01100110, 0b11111001, "uqadd8">;
3089 def UQASX   : AAI<0b01100110, 0b11110011, "uqasx">;
3090 def UQSAX   : AAI<0b01100110, 0b11110101, "uqsax">;
3091 def UQSUB16 : AAI<0b01100110, 0b11110111, "uqsub16">;
3092 def UQSUB8  : AAI<0b01100110, 0b11111111, "uqsub8">;
3093
3094 // Signed/Unsigned add/subtract
3095
3096 def SASX   : AAI<0b01100001, 0b11110011, "sasx">;
3097 def SADD16 : AAI<0b01100001, 0b11110001, "sadd16">;
3098 def SADD8  : AAI<0b01100001, 0b11111001, "sadd8">;
3099 def SSAX   : AAI<0b01100001, 0b11110101, "ssax">;
3100 def SSUB16 : AAI<0b01100001, 0b11110111, "ssub16">;
3101 def SSUB8  : AAI<0b01100001, 0b11111111, "ssub8">;
3102 def UASX   : AAI<0b01100101, 0b11110011, "uasx">;
3103 def UADD16 : AAI<0b01100101, 0b11110001, "uadd16">;
3104 def UADD8  : AAI<0b01100101, 0b11111001, "uadd8">;
3105 def USAX   : AAI<0b01100101, 0b11110101, "usax">;
3106 def USUB16 : AAI<0b01100101, 0b11110111, "usub16">;
3107 def USUB8  : AAI<0b01100101, 0b11111111, "usub8">;
3108
3109 // Signed/Unsigned halving add/subtract
3110
3111 def SHASX   : AAI<0b01100011, 0b11110011, "shasx">;
3112 def SHADD16 : AAI<0b01100011, 0b11110001, "shadd16">;
3113 def SHADD8  : AAI<0b01100011, 0b11111001, "shadd8">;
3114 def SHSAX   : AAI<0b01100011, 0b11110101, "shsax">;
3115 def SHSUB16 : AAI<0b01100011, 0b11110111, "shsub16">;
3116 def SHSUB8  : AAI<0b01100011, 0b11111111, "shsub8">;
3117 def UHASX   : AAI<0b01100111, 0b11110011, "uhasx">;
3118 def UHADD16 : AAI<0b01100111, 0b11110001, "uhadd16">;
3119 def UHADD8  : AAI<0b01100111, 0b11111001, "uhadd8">;
3120 def UHSAX   : AAI<0b01100111, 0b11110101, "uhsax">;
3121 def UHSUB16 : AAI<0b01100111, 0b11110111, "uhsub16">;
3122 def UHSUB8  : AAI<0b01100111, 0b11111111, "uhsub8">;
3123
3124 // Unsigned Sum of Absolute Differences [and Accumulate].
3125
3126 def USAD8  : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3127                 MulFrm /* for convenience */, NoItinerary, "usad8",
3128                 "\t$Rd, $Rn, $Rm", []>,
3129              Requires<[IsARM, HasV6]> {
3130   bits<4> Rd;
3131   bits<4> Rn;
3132   bits<4> Rm;
3133   let Inst{27-20} = 0b01111000;
3134   let Inst{15-12} = 0b1111;
3135   let Inst{7-4} = 0b0001;
3136   let Inst{19-16} = Rd;
3137   let Inst{11-8} = Rm;
3138   let Inst{3-0} = Rn;
3139 }
3140 def USADA8 : AI<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3141                 MulFrm /* for convenience */, NoItinerary, "usada8",
3142                 "\t$Rd, $Rn, $Rm, $Ra", []>,
3143              Requires<[IsARM, HasV6]> {
3144   bits<4> Rd;
3145   bits<4> Rn;
3146   bits<4> Rm;
3147   bits<4> Ra;
3148   let Inst{27-20} = 0b01111000;
3149   let Inst{7-4} = 0b0001;
3150   let Inst{19-16} = Rd;
3151   let Inst{15-12} = Ra;
3152   let Inst{11-8} = Rm;
3153   let Inst{3-0} = Rn;
3154 }
3155
3156 // Signed/Unsigned saturate
3157
3158 def SSAT : AI<(outs GPRnopc:$Rd),
3159               (ins imm1_32:$sat_imm, GPRnopc:$Rn, shift_imm:$sh),
3160               SatFrm, NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", []> {
3161   bits<4> Rd;
3162   bits<5> sat_imm;
3163   bits<4> Rn;
3164   bits<8> sh;
3165   let Inst{27-21} = 0b0110101;
3166   let Inst{5-4} = 0b01;
3167   let Inst{20-16} = sat_imm;
3168   let Inst{15-12} = Rd;
3169   let Inst{11-7} = sh{4-0};
3170   let Inst{6} = sh{5};
3171   let Inst{3-0} = Rn;
3172 }
3173
3174 def SSAT16 : AI<(outs GPRnopc:$Rd),
3175                 (ins imm1_16:$sat_imm, GPRnopc:$Rn), SatFrm,
3176                 NoItinerary, "ssat16", "\t$Rd, $sat_imm, $Rn", []> {
3177   bits<4> Rd;
3178   bits<4> sat_imm;
3179   bits<4> Rn;
3180   let Inst{27-20} = 0b01101010;
3181   let Inst{11-4} = 0b11110011;
3182   let Inst{15-12} = Rd;
3183   let Inst{19-16} = sat_imm;
3184   let Inst{3-0} = Rn;
3185 }
3186
3187 def USAT : AI<(outs GPRnopc:$Rd),
3188               (ins imm0_31:$sat_imm, GPRnopc:$Rn, shift_imm:$sh),
3189               SatFrm, NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", []> {
3190   bits<4> Rd;
3191   bits<5> sat_imm;
3192   bits<4> Rn;
3193   bits<8> sh;
3194   let Inst{27-21} = 0b0110111;
3195   let Inst{5-4} = 0b01;
3196   let Inst{15-12} = Rd;
3197   let Inst{11-7} = sh{4-0};
3198   let Inst{6} = sh{5};
3199   let Inst{20-16} = sat_imm;
3200   let Inst{3-0} = Rn;
3201 }
3202
3203 def USAT16 : AI<(outs GPRnopc:$Rd),
3204                 (ins imm0_15:$sat_imm, GPRnopc:$Rn), SatFrm,
3205                 NoItinerary, "usat16", "\t$Rd, $sat_imm, $Rn", []> {
3206   bits<4> Rd;
3207   bits<4> sat_imm;
3208   bits<4> Rn;
3209   let Inst{27-20} = 0b01101110;
3210   let Inst{11-4} = 0b11110011;
3211   let Inst{15-12} = Rd;
3212   let Inst{19-16} = sat_imm;
3213   let Inst{3-0} = Rn;
3214 }
3215
3216 def : ARMV6Pat<(int_arm_ssat GPRnopc:$a, imm:$pos),
3217                (SSAT imm:$pos, GPRnopc:$a, 0)>;
3218 def : ARMV6Pat<(int_arm_usat GPRnopc:$a, imm:$pos),
3219                (USAT imm:$pos, GPRnopc:$a, 0)>;
3220
3221 //===----------------------------------------------------------------------===//
3222 //  Bitwise Instructions.
3223 //
3224
3225 defm AND   : AsI1_bin_irs<0b0000, "and",
3226                           IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3227                           BinOpFrag<(and node:$LHS, node:$RHS)>, "AND", 1>;
3228 defm ORR   : AsI1_bin_irs<0b1100, "orr",
3229                           IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3230                           BinOpFrag<(or  node:$LHS, node:$RHS)>, "ORR", 1>;
3231 defm EOR   : AsI1_bin_irs<0b0001, "eor",
3232                           IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3233                           BinOpFrag<(xor node:$LHS, node:$RHS)>, "EOR", 1>;
3234 defm BIC   : AsI1_bin_irs<0b1110, "bic",
3235                           IIC_iBITi, IIC_iBITr, IIC_iBITsr,
3236                           BinOpFrag<(and node:$LHS, (not node:$RHS))>, "BIC">;
3237
3238 // FIXME: bf_inv_mask_imm should be two operands, the lsb and the msb, just
3239 // like in the actual instruction encoding. The complexity of mapping the mask
3240 // to the lsb/msb pair should be handled by ISel, not encapsulated in the
3241 // instruction description.
3242 def BFC    : I<(outs GPR:$Rd), (ins GPR:$src, bf_inv_mask_imm:$imm),
3243                AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3244                "bfc", "\t$Rd, $imm", "$src = $Rd",
3245                [(set GPR:$Rd, (and GPR:$src, bf_inv_mask_imm:$imm))]>,
3246                Requires<[IsARM, HasV6T2]> {
3247   bits<4> Rd;
3248   bits<10> imm;
3249   let Inst{27-21} = 0b0111110;
3250   let Inst{6-0}   = 0b0011111;
3251   let Inst{15-12} = Rd;
3252   let Inst{11-7}  = imm{4-0}; // lsb
3253   let Inst{20-16} = imm{9-5}; // msb
3254 }
3255
3256 // A8.6.18  BFI - Bitfield insert (Encoding A1)
3257 def BFI:I<(outs GPRnopc:$Rd), (ins GPRnopc:$src, GPR:$Rn, bf_inv_mask_imm:$imm),
3258           AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3259           "bfi", "\t$Rd, $Rn, $imm", "$src = $Rd",
3260           [(set GPRnopc:$Rd, (ARMbfi GPRnopc:$src, GPR:$Rn,
3261                            bf_inv_mask_imm:$imm))]>,
3262           Requires<[IsARM, HasV6T2]> {
3263   bits<4> Rd;
3264   bits<4> Rn;
3265   bits<10> imm;
3266   let Inst{27-21} = 0b0111110;
3267   let Inst{6-4}   = 0b001; // Rn: Inst{3-0} != 15
3268   let Inst{15-12} = Rd;
3269   let Inst{11-7}  = imm{4-0}; // lsb
3270   let Inst{20-16} = imm{9-5}; // width
3271   let Inst{3-0}   = Rn;
3272 }
3273
3274 // GNU as only supports this form of bfi (w/ 4 arguments)
3275 let isAsmParserOnly = 1 in
3276 def BFI4p : I<(outs GPRnopc:$Rd), (ins GPRnopc:$src, GPR:$Rn,
3277                                    lsb_pos_imm:$lsb, width_imm:$width),
3278                AddrMode1, 4, IndexModeNone, DPFrm, IIC_iUNAsi,
3279                "bfi", "\t$Rd, $Rn, $lsb, $width", "$src = $Rd",
3280                []>, Requires<[IsARM, HasV6T2]> {
3281   bits<4> Rd;
3282   bits<4> Rn;
3283   bits<5> lsb;
3284   bits<5> width;
3285   let Inst{27-21} = 0b0111110;
3286   let Inst{6-4}   = 0b001; // Rn: Inst{3-0} != 15
3287   let Inst{15-12} = Rd;
3288   let Inst{11-7}  = lsb;
3289   let Inst{20-16} = width; // Custom encoder => lsb+width-1
3290   let Inst{3-0}   = Rn;
3291 }
3292
3293 def  MVNr  : AsI1<0b1111, (outs GPR:$Rd), (ins GPR:$Rm), DPFrm, IIC_iMVNr,
3294                   "mvn", "\t$Rd, $Rm",
3295                   [(set GPR:$Rd, (not GPR:$Rm))]>, UnaryDP {
3296   bits<4> Rd;
3297   bits<4> Rm;
3298   let Inst{25} = 0;
3299   let Inst{19-16} = 0b0000;
3300   let Inst{11-4} = 0b00000000;
3301   let Inst{15-12} = Rd;
3302   let Inst{3-0} = Rm;
3303 }
3304 def  MVNsi  : AsI1<0b1111, (outs GPR:$Rd), (ins so_reg_imm:$shift),
3305                   DPSoRegImmFrm, IIC_iMVNsr, "mvn", "\t$Rd, $shift",
3306                   [(set GPR:$Rd, (not so_reg_imm:$shift))]>, UnaryDP {
3307   bits<4> Rd;
3308   bits<12> shift;
3309   let Inst{25} = 0;
3310   let Inst{19-16} = 0b0000;
3311   let Inst{15-12} = Rd;
3312   let Inst{11-5} = shift{11-5};
3313   let Inst{4} = 0;
3314   let Inst{3-0} = shift{3-0};
3315 }
3316 def  MVNsr  : AsI1<0b1111, (outs GPR:$Rd), (ins so_reg_reg:$shift),
3317                   DPSoRegRegFrm, IIC_iMVNsr, "mvn", "\t$Rd, $shift",
3318                   [(set GPR:$Rd, (not so_reg_reg:$shift))]>, UnaryDP {
3319   bits<4> Rd;
3320   bits<12> shift;
3321   let Inst{25} = 0;
3322   let Inst{19-16} = 0b0000;
3323   let Inst{15-12} = Rd;
3324   let Inst{11-8} = shift{11-8};
3325   let Inst{7} = 0;
3326   let Inst{6-5} = shift{6-5};
3327   let Inst{4} = 1;
3328   let Inst{3-0} = shift{3-0};
3329 }
3330 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
3331 def  MVNi  : AsI1<0b1111, (outs GPR:$Rd), (ins so_imm:$imm), DPFrm,
3332                   IIC_iMVNi, "mvn", "\t$Rd, $imm",
3333                   [(set GPR:$Rd, so_imm_not:$imm)]>,UnaryDP {
3334   bits<4> Rd;
3335   bits<12> imm;
3336   let Inst{25} = 1;
3337   let Inst{19-16} = 0b0000;
3338   let Inst{15-12} = Rd;
3339   let Inst{11-0} = imm;
3340 }
3341
3342 def : ARMPat<(and   GPR:$src, so_imm_not:$imm),
3343              (BICri GPR:$src, so_imm_not:$imm)>;
3344
3345 //===----------------------------------------------------------------------===//
3346 //  Multiply Instructions.
3347 //
3348 class AsMul1I32<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
3349              string opc, string asm, list<dag> pattern>
3350   : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
3351   bits<4> Rd;
3352   bits<4> Rm;
3353   bits<4> Rn;
3354   let Inst{19-16} = Rd;
3355   let Inst{11-8}  = Rm;
3356   let Inst{3-0}   = Rn;
3357 }
3358 class AsMul1I64<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
3359              string opc, string asm, list<dag> pattern>
3360   : AsMul1I<opcod, oops, iops, itin, opc, asm, pattern> {
3361   bits<4> RdLo;
3362   bits<4> RdHi;
3363   bits<4> Rm;
3364   bits<4> Rn;
3365   let Inst{19-16} = RdHi;
3366   let Inst{15-12} = RdLo;
3367   let Inst{11-8}  = Rm;
3368   let Inst{3-0}   = Rn;
3369 }
3370
3371 // FIXME: The v5 pseudos are only necessary for the additional Constraint
3372 //        property. Remove them when it's possible to add those properties
3373 //        on an individual MachineInstr, not just an instuction description.
3374 let isCommutable = 1 in {
3375 def MUL  : AsMul1I32<0b0000000, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3376                    IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm",
3377                    [(set GPR:$Rd, (mul GPR:$Rn, GPR:$Rm))]>,
3378                    Requires<[IsARM, HasV6]> {
3379   let Inst{15-12} = 0b0000;
3380 }
3381
3382 let Constraints = "@earlyclobber $Rd" in
3383 def MULv5: ARMPseudoExpand<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm,
3384                                             pred:$p, cc_out:$s),
3385                           4, IIC_iMUL32,
3386                          [(set GPR:$Rd, (mul GPR:$Rn, GPR:$Rm))],
3387                          (MUL GPR:$Rd, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3388                         Requires<[IsARM, NoV6]>;
3389 }
3390
3391 def MLA  : AsMul1I32<0b0000001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3392                     IIC_iMAC32, "mla", "\t$Rd, $Rn, $Rm, $Ra",
3393                    [(set GPR:$Rd, (add (mul GPR:$Rn, GPR:$Rm), GPR:$Ra))]>,
3394                    Requires<[IsARM, HasV6]> {
3395   bits<4> Ra;
3396   let Inst{15-12} = Ra;
3397 }
3398
3399 let Constraints = "@earlyclobber $Rd" in
3400 def MLAv5: ARMPseudoExpand<(outs GPR:$Rd),
3401                           (ins GPR:$Rn, GPR:$Rm, GPR:$Ra, pred:$p, cc_out:$s),
3402                           4, IIC_iMAC32,
3403                         [(set GPR:$Rd, (add (mul GPR:$Rn, GPR:$Rm), GPR:$Ra))],
3404                   (MLA GPR:$Rd, GPR:$Rn, GPR:$Rm, GPR:$Ra, pred:$p, cc_out:$s)>,
3405                         Requires<[IsARM, NoV6]>;
3406
3407 def MLS  : AMul1I<0b0000011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3408                    IIC_iMAC32, "mls", "\t$Rd, $Rn, $Rm, $Ra",
3409                    [(set GPR:$Rd, (sub GPR:$Ra, (mul GPR:$Rn, GPR:$Rm)))]>,
3410                    Requires<[IsARM, HasV6T2]> {
3411   bits<4> Rd;
3412   bits<4> Rm;
3413   bits<4> Rn;
3414   bits<4> Ra;
3415   let Inst{19-16} = Rd;
3416   let Inst{15-12} = Ra;
3417   let Inst{11-8}  = Rm;
3418   let Inst{3-0}   = Rn;
3419 }
3420
3421 // Extra precision multiplies with low / high results
3422 let neverHasSideEffects = 1 in {
3423 let isCommutable = 1 in {
3424 def SMULL : AsMul1I64<0b0000110, (outs GPR:$RdLo, GPR:$RdHi),
3425                                  (ins GPR:$Rn, GPR:$Rm), IIC_iMUL64,
3426                     "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3427                     Requires<[IsARM, HasV6]>;
3428
3429 def UMULL : AsMul1I64<0b0000100, (outs GPR:$RdLo, GPR:$RdHi),
3430                                  (ins GPR:$Rn, GPR:$Rm), IIC_iMUL64,
3431                     "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3432                     Requires<[IsARM, HasV6]>;
3433
3434 let Constraints = "@earlyclobber $RdLo,@earlyclobber $RdHi" in {
3435 def SMULLv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3436                             (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3437                             4, IIC_iMUL64, [],
3438           (SMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3439                            Requires<[IsARM, NoV6]>;
3440
3441 def UMULLv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3442                             (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3443                             4, IIC_iMUL64, [],
3444           (UMULL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3445                            Requires<[IsARM, NoV6]>;
3446 }
3447 }
3448
3449 // Multiply + accumulate
3450 def SMLAL : AsMul1I64<0b0000111, (outs GPR:$RdLo, GPR:$RdHi),
3451                                (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
3452                     "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3453                     Requires<[IsARM, HasV6]>;
3454 def UMLAL : AsMul1I64<0b0000101, (outs GPR:$RdLo, GPR:$RdHi),
3455                                (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
3456                     "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3457                     Requires<[IsARM, HasV6]>;
3458
3459 def UMAAL : AMul1I <0b0000010, (outs GPR:$RdLo, GPR:$RdHi),
3460                                (ins GPR:$Rn, GPR:$Rm), IIC_iMAC64,
3461                     "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3462                     Requires<[IsARM, HasV6]> {
3463   bits<4> RdLo;
3464   bits<4> RdHi;
3465   bits<4> Rm;
3466   bits<4> Rn;
3467   let Inst{19-16} = RdHi;
3468   let Inst{15-12} = RdLo;
3469   let Inst{11-8}  = Rm;
3470   let Inst{3-0}   = Rn;
3471 }
3472
3473 let Constraints = "@earlyclobber $RdLo,@earlyclobber $RdHi" in {
3474 def SMLALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3475                               (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3476                               4, IIC_iMAC64, [],
3477           (SMLAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3478                            Requires<[IsARM, NoV6]>;
3479 def UMLALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3480                               (ins GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s),
3481                               4, IIC_iMAC64, [],
3482           (UMLAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p, cc_out:$s)>,
3483                            Requires<[IsARM, NoV6]>;
3484 def UMAALv5 : ARMPseudoExpand<(outs GPR:$RdLo, GPR:$RdHi),
3485                               (ins GPR:$Rn, GPR:$Rm, pred:$p),
3486                               4, IIC_iMAC64, [],
3487           (UMAAL GPR:$RdLo, GPR:$RdHi, GPR:$Rn, GPR:$Rm, pred:$p)>,
3488                            Requires<[IsARM, NoV6]>;
3489 }
3490
3491 } // neverHasSideEffects
3492
3493 // Most significant word multiply
3494 def SMMUL : AMul2I <0b0111010, 0b0001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3495                IIC_iMUL32, "smmul", "\t$Rd, $Rn, $Rm",
3496                [(set GPR:$Rd, (mulhs GPR:$Rn, GPR:$Rm))]>,
3497             Requires<[IsARM, HasV6]> {
3498   let Inst{15-12} = 0b1111;
3499 }
3500
3501 def SMMULR : AMul2I <0b0111010, 0b0011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3502                IIC_iMUL32, "smmulr", "\t$Rd, $Rn, $Rm", []>,
3503             Requires<[IsARM, HasV6]> {
3504   let Inst{15-12} = 0b1111;
3505 }
3506
3507 def SMMLA : AMul2Ia <0b0111010, 0b0001, (outs GPR:$Rd),
3508                (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3509                IIC_iMAC32, "smmla", "\t$Rd, $Rn, $Rm, $Ra",
3510                [(set GPR:$Rd, (add (mulhs GPR:$Rn, GPR:$Rm), GPR:$Ra))]>,
3511             Requires<[IsARM, HasV6]>;
3512
3513 def SMMLAR : AMul2Ia <0b0111010, 0b0011, (outs GPR:$Rd),
3514                (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3515                IIC_iMAC32, "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
3516             Requires<[IsARM, HasV6]>;
3517
3518 def SMMLS : AMul2Ia <0b0111010, 0b1101, (outs GPR:$Rd),
3519                (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3520                IIC_iMAC32, "smmls", "\t$Rd, $Rn, $Rm, $Ra",
3521                [(set GPR:$Rd, (sub GPR:$Ra, (mulhs GPR:$Rn, GPR:$Rm)))]>,
3522             Requires<[IsARM, HasV6]>;
3523
3524 def SMMLSR : AMul2Ia <0b0111010, 0b1111, (outs GPR:$Rd),
3525                (ins GPR:$Rn, GPR:$Rm, GPR:$Ra),
3526                IIC_iMAC32, "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
3527             Requires<[IsARM, HasV6]>;
3528
3529 multiclass AI_smul<string opc, PatFrag opnode> {
3530   def BB : AMulxyI<0b0001011, 0b00, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3531               IIC_iMUL16, !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
3532               [(set GPR:$Rd, (opnode (sext_inreg GPR:$Rn, i16),
3533                                       (sext_inreg GPR:$Rm, i16)))]>,
3534            Requires<[IsARM, HasV5TE]>;
3535
3536   def BT : AMulxyI<0b0001011, 0b10, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3537               IIC_iMUL16, !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
3538               [(set GPR:$Rd, (opnode (sext_inreg GPR:$Rn, i16),
3539                                       (sra GPR:$Rm, (i32 16))))]>,
3540            Requires<[IsARM, HasV5TE]>;
3541
3542   def TB : AMulxyI<0b0001011, 0b01, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3543               IIC_iMUL16, !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
3544               [(set GPR:$Rd, (opnode (sra GPR:$Rn, (i32 16)),
3545                                       (sext_inreg GPR:$Rm, i16)))]>,
3546            Requires<[IsARM, HasV5TE]>;
3547
3548   def TT : AMulxyI<0b0001011, 0b11, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3549               IIC_iMUL16, !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
3550               [(set GPR:$Rd, (opnode (sra GPR:$Rn, (i32 16)),
3551                                       (sra GPR:$Rm, (i32 16))))]>,
3552             Requires<[IsARM, HasV5TE]>;
3553
3554   def WB : AMulxyI<0b0001001, 0b01, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3555               IIC_iMUL16, !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
3556               [(set GPR:$Rd, (sra (opnode GPR:$Rn,
3557                                     (sext_inreg GPR:$Rm, i16)), (i32 16)))]>,
3558            Requires<[IsARM, HasV5TE]>;
3559
3560   def WT : AMulxyI<0b0001001, 0b11, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
3561               IIC_iMUL16, !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
3562               [(set GPR:$Rd, (sra (opnode GPR:$Rn,
3563                                     (sra GPR:$Rm, (i32 16))), (i32 16)))]>,
3564             Requires<[IsARM, HasV5TE]>;
3565 }
3566
3567
3568 multiclass AI_smla<string opc, PatFrag opnode> {
3569   let DecoderMethod = "DecodeSMLAInstruction" in {
3570   def BB : AMulxyIa<0b0001000, 0b00, (outs GPRnopc:$Rd),
3571               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3572               IIC_iMAC16, !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
3573               [(set GPRnopc:$Rd, (add GPR:$Ra,
3574                                (opnode (sext_inreg GPRnopc:$Rn, i16),
3575                                        (sext_inreg GPRnopc:$Rm, i16))))]>,
3576            Requires<[IsARM, HasV5TE]>;
3577
3578   def BT : AMulxyIa<0b0001000, 0b10, (outs GPRnopc:$Rd),
3579               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3580               IIC_iMAC16, !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
3581               [(set GPRnopc:$Rd,
3582                     (add GPR:$Ra, (opnode (sext_inreg GPRnopc:$Rn, i16),
3583                                           (sra GPRnopc:$Rm, (i32 16)))))]>,
3584            Requires<[IsARM, HasV5TE]>;
3585
3586   def TB : AMulxyIa<0b0001000, 0b01, (outs GPRnopc:$Rd),
3587               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3588               IIC_iMAC16, !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
3589               [(set GPRnopc:$Rd,
3590                     (add GPR:$Ra, (opnode (sra GPRnopc:$Rn, (i32 16)),
3591                                           (sext_inreg GPRnopc:$Rm, i16))))]>,
3592            Requires<[IsARM, HasV5TE]>;
3593
3594   def TT : AMulxyIa<0b0001000, 0b11, (outs GPRnopc:$Rd),
3595               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3596               IIC_iMAC16, !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
3597              [(set GPRnopc:$Rd,
3598                    (add GPR:$Ra, (opnode (sra GPRnopc:$Rn, (i32 16)),
3599                                          (sra GPRnopc:$Rm, (i32 16)))))]>,
3600             Requires<[IsARM, HasV5TE]>;
3601
3602   def WB : AMulxyIa<0b0001001, 0b00, (outs GPRnopc:$Rd),
3603               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3604               IIC_iMAC16, !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
3605               [(set GPRnopc:$Rd,
3606                     (add GPR:$Ra, (sra (opnode GPRnopc:$Rn,
3607                                   (sext_inreg GPRnopc:$Rm, i16)), (i32 16))))]>,
3608            Requires<[IsARM, HasV5TE]>;
3609
3610   def WT : AMulxyIa<0b0001001, 0b10, (outs GPRnopc:$Rd),
3611               (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3612               IIC_iMAC16, !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
3613               [(set GPRnopc:$Rd,
3614                  (add GPR:$Ra, (sra (opnode GPRnopc:$Rn,
3615                                     (sra GPRnopc:$Rm, (i32 16))), (i32 16))))]>,
3616             Requires<[IsARM, HasV5TE]>;
3617   }
3618 }
3619
3620 defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
3621 defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
3622
3623 // Halfword multiply accumulate long: SMLAL<x><y>.
3624 def SMLALBB : AMulxyI64<0b0001010, 0b00, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3625                       (ins GPRnopc:$Rn, GPRnopc:$Rm),
3626                       IIC_iMAC64, "smlalbb", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3627               Requires<[IsARM, HasV5TE]>;
3628
3629 def SMLALBT : AMulxyI64<0b0001010, 0b10, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3630                       (ins GPRnopc:$Rn, GPRnopc:$Rm),
3631                       IIC_iMAC64, "smlalbt", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3632               Requires<[IsARM, HasV5TE]>;
3633
3634 def SMLALTB : AMulxyI64<0b0001010, 0b01, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3635                       (ins GPRnopc:$Rn, GPRnopc:$Rm),
3636                       IIC_iMAC64, "smlaltb", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3637               Requires<[IsARM, HasV5TE]>;
3638
3639 def SMLALTT : AMulxyI64<0b0001010, 0b11, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3640                       (ins GPRnopc:$Rn, GPRnopc:$Rm),
3641                       IIC_iMAC64, "smlaltt", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
3642               Requires<[IsARM, HasV5TE]>;
3643
3644 // Helper class for AI_smld.
3645 class AMulDualIbase<bit long, bit sub, bit swap, dag oops, dag iops,
3646                     InstrItinClass itin, string opc, string asm>
3647   : AI<oops, iops, MulFrm, itin, opc, asm, []>, Requires<[IsARM, HasV6]> {
3648   bits<4> Rn;
3649   bits<4> Rm;
3650   let Inst{27-23} = 0b01110;
3651   let Inst{22}    = long;
3652   let Inst{21-20} = 0b00;
3653   let Inst{11-8}  = Rm;
3654   let Inst{7}     = 0;
3655   let Inst{6}     = sub;
3656   let Inst{5}     = swap;
3657   let Inst{4}     = 1;
3658   let Inst{3-0}   = Rn;
3659 }
3660 class AMulDualI<bit long, bit sub, bit swap, dag oops, dag iops,
3661                 InstrItinClass itin, string opc, string asm>
3662   : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3663   bits<4> Rd;
3664   let Inst{15-12} = 0b1111;
3665   let Inst{19-16} = Rd;
3666 }
3667 class AMulDualIa<bit long, bit sub, bit swap, dag oops, dag iops,
3668                 InstrItinClass itin, string opc, string asm>
3669   : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3670   bits<4> Ra;
3671   bits<4> Rd;
3672   let Inst{19-16} = Rd;
3673   let Inst{15-12} = Ra;
3674 }
3675 class AMulDualI64<bit long, bit sub, bit swap, dag oops, dag iops,
3676                   InstrItinClass itin, string opc, string asm>
3677   : AMulDualIbase<long, sub, swap, oops, iops, itin, opc, asm> {
3678   bits<4> RdLo;
3679   bits<4> RdHi;
3680   let Inst{19-16} = RdHi;
3681   let Inst{15-12} = RdLo;
3682 }
3683
3684 multiclass AI_smld<bit sub, string opc> {
3685
3686   def D : AMulDualIa<0, sub, 0, (outs GPRnopc:$Rd),
3687                   (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3688                   NoItinerary, !strconcat(opc, "d"), "\t$Rd, $Rn, $Rm, $Ra">;
3689
3690   def DX: AMulDualIa<0, sub, 1, (outs GPRnopc:$Rd),
3691                   (ins GPRnopc:$Rn, GPRnopc:$Rm, GPR:$Ra),
3692                   NoItinerary, !strconcat(opc, "dx"), "\t$Rd, $Rn, $Rm, $Ra">;
3693
3694   def LD: AMulDualI64<1, sub, 0, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3695                   (ins GPRnopc:$Rn, GPRnopc:$Rm), NoItinerary,
3696                   !strconcat(opc, "ld"), "\t$RdLo, $RdHi, $Rn, $Rm">;
3697
3698   def LDX : AMulDualI64<1, sub, 1, (outs GPRnopc:$RdLo, GPRnopc:$RdHi),
3699                   (ins GPRnopc:$Rn, GPRnopc:$Rm), NoItinerary,
3700                   !strconcat(opc, "ldx"),"\t$RdLo, $RdHi, $Rn, $Rm">;
3701
3702 }
3703
3704 defm SMLA : AI_smld<0, "smla">;
3705 defm SMLS : AI_smld<1, "smls">;
3706
3707 multiclass AI_sdml<bit sub, string opc> {
3708
3709   def D:AMulDualI<0, sub, 0, (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, GPRnopc:$Rm),
3710                   NoItinerary, !strconcat(opc, "d"), "\t$Rd, $Rn, $Rm">;
3711   def DX:AMulDualI<0, sub, 1, (outs GPRnopc:$Rd),(ins GPRnopc:$Rn, GPRnopc:$Rm),
3712                   NoItinerary, !strconcat(opc, "dx"), "\t$Rd, $Rn, $Rm">;
3713 }
3714
3715 defm SMUA : AI_sdml<0, "smua">;
3716 defm SMUS : AI_sdml<1, "smus">;
3717
3718 //===----------------------------------------------------------------------===//
3719 //  Misc. Arithmetic Instructions.
3720 //
3721
3722 def CLZ  : AMiscA1I<0b000010110, 0b0001, (outs GPR:$Rd), (ins GPR:$Rm),
3723               IIC_iUNAr, "clz", "\t$Rd, $Rm",
3724               [(set GPR:$Rd, (ctlz GPR:$Rm))]>, Requires<[IsARM, HasV5T]>;
3725
3726 def RBIT : AMiscA1I<0b01101111, 0b0011, (outs GPR:$Rd), (ins GPR:$Rm),
3727               IIC_iUNAr, "rbit", "\t$Rd, $Rm",
3728               [(set GPR:$Rd, (ARMrbit GPR:$Rm))]>,
3729            Requires<[IsARM, HasV6T2]>;
3730
3731 def REV  : AMiscA1I<0b01101011, 0b0011, (outs GPR:$Rd), (ins GPR:$Rm),
3732               IIC_iUNAr, "rev", "\t$Rd, $Rm",
3733               [(set GPR:$Rd, (bswap GPR:$Rm))]>, Requires<[IsARM, HasV6]>;
3734
3735 let AddedComplexity = 5 in
3736 def REV16 : AMiscA1I<0b01101011, 0b1011, (outs GPR:$Rd), (ins GPR:$Rm),
3737                IIC_iUNAr, "rev16", "\t$Rd, $Rm",
3738                [(set GPR:$Rd, (rotr (bswap GPR:$Rm), (i32 16)))]>,
3739                Requires<[IsARM, HasV6]>;
3740
3741 let AddedComplexity = 5 in
3742 def REVSH : AMiscA1I<0b01101111, 0b1011, (outs GPR:$Rd), (ins GPR:$Rm),
3743                IIC_iUNAr, "revsh", "\t$Rd, $Rm",
3744                [(set GPR:$Rd, (sra (bswap GPR:$Rm), (i32 16)))]>,
3745                Requires<[IsARM, HasV6]>;
3746
3747 def : ARMV6Pat<(or (sra (shl GPR:$Rm, (i32 24)), (i32 16)),
3748                    (and (srl GPR:$Rm, (i32 8)), 0xFF)),
3749                (REVSH GPR:$Rm)>;
3750
3751 def PKHBT : APKHI<0b01101000, 0, (outs GPR:$Rd),
3752                               (ins GPR:$Rn, GPR:$Rm, pkh_lsl_amt:$sh),
3753                IIC_iALUsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
3754                [(set GPR:$Rd, (or (and GPR:$Rn, 0xFFFF),
3755                                   (and (shl GPR:$Rm, pkh_lsl_amt:$sh),
3756                                        0xFFFF0000)))]>,
3757                Requires<[IsARM, HasV6]>;
3758
3759 // Alternate cases for PKHBT where identities eliminate some nodes.
3760 def : ARMV6Pat<(or (and GPR:$Rn, 0xFFFF), (and GPR:$Rm, 0xFFFF0000)),
3761                (PKHBT GPR:$Rn, GPR:$Rm, 0)>;
3762 def : ARMV6Pat<(or (and GPR:$Rn, 0xFFFF), (shl GPR:$Rm, imm16_31:$sh)),
3763                (PKHBT GPR:$Rn, GPR:$Rm, imm16_31:$sh)>;
3764
3765 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
3766 // will match the pattern below.
3767 def PKHTB : APKHI<0b01101000, 1, (outs GPR:$Rd),
3768                               (ins GPR:$Rn, GPR:$Rm, pkh_asr_amt:$sh),
3769                IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
3770                [(set GPR:$Rd, (or (and GPR:$Rn, 0xFFFF0000),
3771                                   (and (sra GPR:$Rm, pkh_asr_amt:$sh),
3772                                        0xFFFF)))]>,
3773                Requires<[IsARM, HasV6]>;
3774
3775 // Alternate cases for PKHTB where identities eliminate some nodes.  Note that
3776 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
3777 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, imm16_31:$sh)),
3778                (PKHTB GPR:$src1, GPR:$src2, imm16_31:$sh)>;
3779 def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
3780                    (and (srl GPR:$src2, imm1_15:$sh), 0xFFFF)),
3781                (PKHTB GPR:$src1, GPR:$src2, imm1_15:$sh)>;
3782
3783 //===----------------------------------------------------------------------===//
3784 //  Comparison Instructions...
3785 //
3786
3787 defm CMP  : AI1_cmp_irs<0b1010, "cmp",
3788                         IIC_iCMPi, IIC_iCMPr, IIC_iCMPsr,
3789                         BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
3790
3791 // ARMcmpZ can re-use the above instruction definitions.
3792 def : ARMPat<(ARMcmpZ GPR:$src, so_imm:$imm),
3793              (CMPri   GPR:$src, so_imm:$imm)>;
3794 def : ARMPat<(ARMcmpZ GPR:$src, GPR:$rhs),
3795              (CMPrr   GPR:$src, GPR:$rhs)>;
3796 def : ARMPat<(ARMcmpZ GPR:$src, so_reg_imm:$rhs),
3797              (CMPrsi   GPR:$src, so_reg_imm:$rhs)>;
3798 def : ARMPat<(ARMcmpZ GPR:$src, so_reg_reg:$rhs),
3799              (CMPrsr   GPR:$src, so_reg_reg:$rhs)>;
3800
3801 // FIXME: We have to be careful when using the CMN instruction and comparison
3802 // with 0. One would expect these two pieces of code should give identical
3803 // results:
3804 //
3805 //   rsbs r1, r1, 0
3806 //   cmp  r0, r1
3807 //   mov  r0, #0
3808 //   it   ls
3809 //   mov  r0, #1
3810 //
3811 // and:
3812 //
3813 //   cmn  r0, r1
3814 //   mov  r0, #0
3815 //   it   ls
3816 //   mov  r0, #1
3817 //
3818 // However, the CMN gives the *opposite* result when r1 is 0. This is because
3819 // the carry flag is set in the CMP case but not in the CMN case. In short, the
3820 // CMP instruction doesn't perform a truncate of the (logical) NOT of 0 plus the
3821 // value of r0 and the carry bit (because the "carry bit" parameter to
3822 // AddWithCarry is defined as 1 in this case, the carry flag will always be set
3823 // when r0 >= 0). The CMN instruction doesn't perform a NOT of 0 so there is
3824 // never a "carry" when this AddWithCarry is performed (because the "carry bit"
3825 // parameter to AddWithCarry is defined as 0).
3826 //
3827 // When x is 0 and unsigned:
3828 //
3829 //    x = 0
3830 //   ~x = 0xFFFF FFFF
3831 //   ~x + 1 = 0x1 0000 0000
3832 //   (-x = 0) != (0x1 0000 0000 = ~x + 1)
3833 //
3834 // Therefore, we should disable CMN when comparing against zero, until we can
3835 // limit when the CMN instruction is used (when we know that the RHS is not 0 or
3836 // when it's a comparison which doesn't look at the 'carry' flag).
3837 //
3838 // (See the ARM docs for the "AddWithCarry" pseudo-code.)
3839 //
3840 // This is related to <rdar://problem/7569620>.
3841 //
3842 //defm CMN  : AI1_cmp_irs<0b1011, "cmn",
3843 //                        BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
3844
3845 // Note that TST/TEQ don't set all the same flags that CMP does!
3846 defm TST  : AI1_cmp_irs<0b1000, "tst",
3847                         IIC_iTSTi, IIC_iTSTr, IIC_iTSTsr,
3848                       BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>, 1>;
3849 defm TEQ  : AI1_cmp_irs<0b1001, "teq",
3850                         IIC_iTSTi, IIC_iTSTr, IIC_iTSTsr,
3851                       BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>, 1>;
3852
3853 defm CMNz  : AI1_cmp_irs<0b1011, "cmn",
3854                          IIC_iCMPi, IIC_iCMPr, IIC_iCMPsr,
3855                          BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
3856
3857 //def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
3858 //             (CMNri  GPR:$src, so_imm_neg:$imm)>;
3859
3860 def : ARMPat<(ARMcmpZ GPR:$src, so_imm_neg:$imm),
3861              (CMNzri  GPR:$src, so_imm_neg:$imm)>;
3862
3863 // Pseudo i64 compares for some floating point compares.
3864 let usesCustomInserter = 1, isBranch = 1, isTerminator = 1,
3865     Defs = [CPSR] in {
3866 def BCCi64 : PseudoInst<(outs),
3867     (ins i32imm:$cc, GPR:$lhs1, GPR:$lhs2, GPR:$rhs1, GPR:$rhs2, brtarget:$dst),
3868      IIC_Br,
3869     [(ARMBcci64 imm:$cc, GPR:$lhs1, GPR:$lhs2, GPR:$rhs1, GPR:$rhs2, bb:$dst)]>;
3870
3871 def BCCZi64 : PseudoInst<(outs),
3872      (ins i32imm:$cc, GPR:$lhs1, GPR:$lhs2, brtarget:$dst), IIC_Br,
3873     [(ARMBcci64 imm:$cc, GPR:$lhs1, GPR:$lhs2, 0, 0, bb:$dst)]>;
3874 } // usesCustomInserter
3875
3876
3877 // Conditional moves
3878 // FIXME: should be able to write a pattern for ARMcmov, but can't use
3879 // a two-value operand where a dag node expects two operands. :(
3880 let neverHasSideEffects = 1 in {
3881 def MOVCCr : ARMPseudoInst<(outs GPR:$Rd), (ins GPR:$false, GPR:$Rm, pred:$p),
3882                            4, IIC_iCMOVr,
3883   [/*(set GPR:$Rd, (ARMcmov GPR:$false, GPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
3884       RegConstraint<"$false = $Rd">;
3885 def MOVCCsi : ARMPseudoInst<(outs GPR:$Rd),
3886                            (ins GPR:$false, so_reg_imm:$shift, pred:$p),
3887                            4, IIC_iCMOVsr,
3888   [/*(set GPR:$Rd, (ARMcmov GPR:$false, so_reg_imm:$shift,
3889                             imm:$cc, CCR:$ccr))*/]>,
3890       RegConstraint<"$false = $Rd">;
3891 def MOVCCsr : ARMPseudoInst<(outs GPR:$Rd),
3892                            (ins GPR:$false, so_reg_reg:$shift, pred:$p),
3893                            4, IIC_iCMOVsr,
3894   [/*(set GPR:$Rd, (ARMcmov GPR:$false, so_reg_reg:$shift,
3895                             imm:$cc, CCR:$ccr))*/]>,
3896       RegConstraint<"$false = $Rd">;
3897
3898
3899 let isMoveImm = 1 in
3900 def MOVCCi16 : ARMPseudoInst<(outs GPR:$Rd),
3901                              (ins GPR:$false, imm0_65535_expr:$imm, pred:$p),
3902                              4, IIC_iMOVi,
3903                              []>,
3904       RegConstraint<"$false = $Rd">, Requires<[IsARM, HasV6T2]>;
3905
3906 let isMoveImm = 1 in
3907 def MOVCCi : ARMPseudoInst<(outs GPR:$Rd),
3908                            (ins GPR:$false, so_imm:$imm, pred:$p),
3909                            4, IIC_iCMOVi,
3910    [/*(set GPR:$Rd, (ARMcmov GPR:$false, so_imm:$imm, imm:$cc, CCR:$ccr))*/]>,
3911       RegConstraint<"$false = $Rd">;
3912
3913 // Two instruction predicate mov immediate.
3914 let isMoveImm = 1 in
3915 def MOVCCi32imm : ARMPseudoInst<(outs GPR:$Rd),
3916                                 (ins GPR:$false, i32imm:$src, pred:$p),
3917                   8, IIC_iCMOVix2, []>, RegConstraint<"$false = $Rd">;
3918
3919 let isMoveImm = 1 in
3920 def MVNCCi : ARMPseudoInst<(outs GPR:$Rd),
3921                            (ins GPR:$false, so_imm:$imm, pred:$p),
3922                            4, IIC_iCMOVi,
3923  [/*(set GPR:$Rd, (ARMcmov GPR:$false, so_imm_not:$imm, imm:$cc, CCR:$ccr))*/]>,
3924                 RegConstraint<"$false = $Rd">;
3925 } // neverHasSideEffects
3926
3927 //===----------------------------------------------------------------------===//
3928 // Atomic operations intrinsics
3929 //
3930
3931 def MemBarrierOptOperand : AsmOperandClass {
3932   let Name = "MemBarrierOpt";
3933   let ParserMethod = "parseMemBarrierOptOperand";
3934 }
3935 def memb_opt : Operand<i32> {
3936   let PrintMethod = "printMemBOption";
3937   let ParserMatchClass = MemBarrierOptOperand;
3938   let DecoderMethod = "DecodeMemBarrierOption";
3939 }
3940
3941 // memory barriers protect the atomic sequences
3942 let hasSideEffects = 1 in {
3943 def DMB : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary,
3944                 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
3945                 Requires<[IsARM, HasDB]> {
3946   bits<4> opt;
3947   let Inst{31-4} = 0xf57ff05;
3948   let Inst{3-0} = opt;
3949 }
3950 }
3951
3952 def DSB : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary,
3953                 "dsb", "\t$opt", []>,
3954                 Requires<[IsARM, HasDB]> {
3955   bits<4> opt;
3956   let Inst{31-4} = 0xf57ff04;
3957   let Inst{3-0} = opt;
3958 }
3959
3960 // ISB has only full system option
3961 def ISB : AInoP<(outs), (ins memb_opt:$opt), MiscFrm, NoItinerary,
3962                 "isb", "\t$opt", []>,
3963                 Requires<[IsARM, HasDB]> {
3964   bits<4> opt;
3965   let Inst{31-4} = 0xf57ff06;
3966   let Inst{3-0} = opt;
3967 }
3968
3969 let usesCustomInserter = 1 in {
3970   let Uses = [CPSR] in {
3971     def ATOMIC_LOAD_ADD_I8 : PseudoInst<
3972       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
3973       [(set GPR:$dst, (atomic_load_add_8 GPR:$ptr, GPR:$incr))]>;
3974     def ATOMIC_LOAD_SUB_I8 : PseudoInst<
3975       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
3976       [(set GPR:$dst, (atomic_load_sub_8 GPR:$ptr, GPR:$incr))]>;
3977     def ATOMIC_LOAD_AND_I8 : PseudoInst<
3978       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
3979       [(set GPR:$dst, (atomic_load_and_8 GPR:$ptr, GPR:$incr))]>;
3980     def ATOMIC_LOAD_OR_I8 : PseudoInst<
3981       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
3982       [(set GPR:$dst, (atomic_load_or_8 GPR:$ptr, GPR:$incr))]>;
3983     def ATOMIC_LOAD_XOR_I8 : PseudoInst<
3984       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
3985       [(set GPR:$dst, (atomic_load_xor_8 GPR:$ptr, GPR:$incr))]>;
3986     def ATOMIC_LOAD_NAND_I8 : PseudoInst<
3987       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
3988       [(set GPR:$dst, (atomic_load_nand_8 GPR:$ptr, GPR:$incr))]>;
3989     def ATOMIC_LOAD_MIN_I8 : PseudoInst<
3990       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
3991       [(set GPR:$dst, (atomic_load_min_8 GPR:$ptr, GPR:$val))]>;
3992     def ATOMIC_LOAD_MAX_I8 : PseudoInst<
3993       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
3994       [(set GPR:$dst, (atomic_load_max_8 GPR:$ptr, GPR:$val))]>;
3995     def ATOMIC_LOAD_UMIN_I8 : PseudoInst<
3996       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
3997       [(set GPR:$dst, (atomic_load_min_8 GPR:$ptr, GPR:$val))]>;
3998     def ATOMIC_LOAD_UMAX_I8 : PseudoInst<
3999       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4000       [(set GPR:$dst, (atomic_load_max_8 GPR:$ptr, GPR:$val))]>;
4001     def ATOMIC_LOAD_ADD_I16 : PseudoInst<
4002       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4003       [(set GPR:$dst, (atomic_load_add_16 GPR:$ptr, GPR:$incr))]>;
4004     def ATOMIC_LOAD_SUB_I16 : PseudoInst<
4005       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4006       [(set GPR:$dst, (atomic_load_sub_16 GPR:$ptr, GPR:$incr))]>;
4007     def ATOMIC_LOAD_AND_I16 : PseudoInst<
4008       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4009       [(set GPR:$dst, (atomic_load_and_16 GPR:$ptr, GPR:$incr))]>;
4010     def ATOMIC_LOAD_OR_I16 : PseudoInst<
4011       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4012       [(set GPR:$dst, (atomic_load_or_16 GPR:$ptr, GPR:$incr))]>;
4013     def ATOMIC_LOAD_XOR_I16 : PseudoInst<
4014       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4015       [(set GPR:$dst, (atomic_load_xor_16 GPR:$ptr, GPR:$incr))]>;
4016     def ATOMIC_LOAD_NAND_I16 : PseudoInst<
4017       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4018       [(set GPR:$dst, (atomic_load_nand_16 GPR:$ptr, GPR:$incr))]>;
4019     def ATOMIC_LOAD_MIN_I16 : PseudoInst<
4020       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4021       [(set GPR:$dst, (atomic_load_min_16 GPR:$ptr, GPR:$val))]>;
4022     def ATOMIC_LOAD_MAX_I16 : PseudoInst<
4023       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4024       [(set GPR:$dst, (atomic_load_max_16 GPR:$ptr, GPR:$val))]>;
4025     def ATOMIC_LOAD_UMIN_I16 : PseudoInst<
4026       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4027       [(set GPR:$dst, (atomic_load_min_16 GPR:$ptr, GPR:$val))]>;
4028     def ATOMIC_LOAD_UMAX_I16 : PseudoInst<
4029       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4030       [(set GPR:$dst, (atomic_load_max_16 GPR:$ptr, GPR:$val))]>;
4031     def ATOMIC_LOAD_ADD_I32 : PseudoInst<
4032       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4033       [(set GPR:$dst, (atomic_load_add_32 GPR:$ptr, GPR:$incr))]>;
4034     def ATOMIC_LOAD_SUB_I32 : PseudoInst<
4035       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4036       [(set GPR:$dst, (atomic_load_sub_32 GPR:$ptr, GPR:$incr))]>;
4037     def ATOMIC_LOAD_AND_I32 : PseudoInst<
4038       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4039       [(set GPR:$dst, (atomic_load_and_32 GPR:$ptr, GPR:$incr))]>;
4040     def ATOMIC_LOAD_OR_I32 : PseudoInst<
4041       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4042       [(set GPR:$dst, (atomic_load_or_32 GPR:$ptr, GPR:$incr))]>;
4043     def ATOMIC_LOAD_XOR_I32 : PseudoInst<
4044       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4045       [(set GPR:$dst, (atomic_load_xor_32 GPR:$ptr, GPR:$incr))]>;
4046     def ATOMIC_LOAD_NAND_I32 : PseudoInst<
4047       (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
4048       [(set GPR:$dst, (atomic_load_nand_32 GPR:$ptr, GPR:$incr))]>;
4049     def ATOMIC_LOAD_MIN_I32 : PseudoInst<
4050       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4051       [(set GPR:$dst, (atomic_load_min_32 GPR:$ptr, GPR:$val))]>;
4052     def ATOMIC_LOAD_MAX_I32 : PseudoInst<
4053       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4054       [(set GPR:$dst, (atomic_load_max_32 GPR:$ptr, GPR:$val))]>;
4055     def ATOMIC_LOAD_UMIN_I32 : PseudoInst<
4056       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4057       [(set GPR:$dst, (atomic_load_min_32 GPR:$ptr, GPR:$val))]>;
4058     def ATOMIC_LOAD_UMAX_I32 : PseudoInst<
4059       (outs GPR:$dst), (ins GPR:$ptr, GPR:$val), NoItinerary,
4060       [(set GPR:$dst, (atomic_load_max_32 GPR:$ptr, GPR:$val))]>;
4061
4062     def ATOMIC_SWAP_I8 : PseudoInst<
4063       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
4064       [(set GPR:$dst, (atomic_swap_8 GPR:$ptr, GPR:$new))]>;
4065     def ATOMIC_SWAP_I16 : PseudoInst<
4066       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
4067       [(set GPR:$dst, (atomic_swap_16 GPR:$ptr, GPR:$new))]>;
4068     def ATOMIC_SWAP_I32 : PseudoInst<
4069       (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
4070       [(set GPR:$dst, (atomic_swap_32 GPR:$ptr, GPR:$new))]>;
4071
4072     def ATOMIC_CMP_SWAP_I8 : PseudoInst<
4073       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
4074       [(set GPR:$dst, (atomic_cmp_swap_8 GPR:$ptr, GPR:$old, GPR:$new))]>;
4075     def ATOMIC_CMP_SWAP_I16 : PseudoInst<
4076       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
4077       [(set GPR:$dst, (atomic_cmp_swap_16 GPR:$ptr, GPR:$old, GPR:$new))]>;
4078     def ATOMIC_CMP_SWAP_I32 : PseudoInst<
4079       (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
4080       [(set GPR:$dst, (atomic_cmp_swap_32 GPR:$ptr, GPR:$old, GPR:$new))]>;
4081 }
4082 }
4083
4084 let mayLoad = 1 in {
4085 def LDREXB : AIldrex<0b10, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4086                      NoItinerary,
4087                     "ldrexb", "\t$Rt, $addr", []>;
4088 def LDREXH : AIldrex<0b11, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4089                      NoItinerary, "ldrexh", "\t$Rt, $addr", []>;
4090 def LDREX  : AIldrex<0b00, (outs GPR:$Rt), (ins addr_offset_none:$addr),
4091                      NoItinerary, "ldrex", "\t$Rt, $addr", []>;
4092 let hasExtraDefRegAllocReq = 1 in
4093 def LDREXD: AIldrex<0b01, (outs GPR:$Rt, GPR:$Rt2),(ins addr_offset_none:$addr),
4094                       NoItinerary, "ldrexd", "\t$Rt, $Rt2, $addr", []> {
4095   let DecoderMethod = "DecodeDoubleRegLoad";
4096 }
4097 }
4098
4099 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
4100 def STREXB: AIstrex<0b10, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4101                     NoItinerary, "strexb", "\t$Rd, $Rt, $addr", []>;
4102 def STREXH: AIstrex<0b11, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4103                     NoItinerary, "strexh", "\t$Rd, $Rt, $addr", []>;
4104 def STREX : AIstrex<0b00, (outs GPR:$Rd), (ins GPR:$Rt, addr_offset_none:$addr),
4105                     NoItinerary, "strex", "\t$Rd, $Rt, $addr", []>;
4106 }
4107
4108 let hasExtraSrcRegAllocReq = 1, Constraints = "@earlyclobber $Rd" in
4109 def STREXD : AIstrex<0b01, (outs GPR:$Rd),
4110                     (ins GPR:$Rt, GPR:$Rt2, addr_offset_none:$addr),
4111                     NoItinerary, "strexd", "\t$Rd, $Rt, $Rt2, $addr", []> {
4112   let DecoderMethod = "DecodeDoubleRegStore";
4113 }
4114
4115 def CLREX : AXI<(outs), (ins), MiscFrm, NoItinerary, "clrex", []>,
4116             Requires<[IsARM, HasV7]>  {
4117   let Inst{31-0} = 0b11110101011111111111000000011111;
4118 }
4119
4120 // SWP/SWPB are deprecated in V6/V7.
4121 let mayLoad = 1, mayStore = 1 in {
4122 def SWP : AIswp<0, (outs GPR:$Rt), (ins GPR:$Rt2, addr_offset_none:$addr),
4123                 "swp", []>;
4124 def SWPB: AIswp<1, (outs GPR:$Rt), (ins GPR:$Rt2, addr_offset_none:$addr),
4125                 "swpb", []>;
4126 }
4127
4128 //===----------------------------------------------------------------------===//
4129 // Coprocessor Instructions.
4130 //
4131
4132 def CDP : ABI<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4133             c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4134             NoItinerary, "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4135             [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4136                           imm:$CRm, imm:$opc2)]> {
4137   bits<4> opc1;
4138   bits<4> CRn;
4139   bits<4> CRd;
4140   bits<4> cop;
4141   bits<3> opc2;
4142   bits<4> CRm;
4143
4144   let Inst{3-0}   = CRm;
4145   let Inst{4}     = 0;
4146   let Inst{7-5}   = opc2;
4147   let Inst{11-8}  = cop;
4148   let Inst{15-12} = CRd;
4149   let Inst{19-16} = CRn;
4150   let Inst{23-20} = opc1;
4151 }
4152
4153 def CDP2 : ABXI<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4154                c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
4155                NoItinerary, "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
4156                [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
4157                               imm:$CRm, imm:$opc2)]> {
4158   let Inst{31-28} = 0b1111;
4159   bits<4> opc1;
4160   bits<4> CRn;
4161   bits<4> CRd;
4162   bits<4> cop;
4163   bits<3> opc2;
4164   bits<4> CRm;
4165
4166   let Inst{3-0}   = CRm;
4167   let Inst{4}     = 0;
4168   let Inst{7-5}   = opc2;
4169   let Inst{11-8}  = cop;
4170   let Inst{15-12} = CRd;
4171   let Inst{19-16} = CRn;
4172   let Inst{23-20} = opc1;
4173 }
4174
4175 class ACI<dag oops, dag iops, string opc, string asm,
4176           IndexMode im = IndexModeNone>
4177   : InoP<oops, iops, AddrModeNone, 4, im, BrFrm, NoItinerary,
4178          opc, asm, "", []> {
4179   let Inst{27-25} = 0b110;
4180 }
4181
4182 multiclass LdStCop<bits<4> op31_28, bit load, dag ops, string opc, string cond>{
4183   let DecoderNamespace = "Common" in {
4184   def _OFFSET : ACI<(outs),
4185       !con((ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr), ops),
4186       !strconcat(opc, cond), "\tp$cop, cr$CRd, $addr"> {
4187     let Inst{31-28} = op31_28;
4188     let Inst{24} = 1; // P = 1
4189     let Inst{21} = 0; // W = 0
4190     let Inst{22} = 0; // D = 0
4191     let Inst{20} = load;
4192     let DecoderMethod = "DecodeCopMemInstruction";
4193   }
4194
4195   def _PRE : ACI<(outs),
4196       !con((ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr), ops),
4197       !strconcat(opc, cond), "\tp$cop, cr$CRd, $addr!", IndexModePre> {
4198     let Inst{31-28} = op31_28;
4199     let Inst{24} = 1; // P = 1
4200     let Inst{21} = 1; // W = 1
4201     let Inst{22} = 0; // D = 0
4202     let Inst{20} = load;
4203     let DecoderMethod = "DecodeCopMemInstruction";
4204   }
4205
4206   def _POST : ACI<(outs),
4207       !con((ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr), ops),
4208       !strconcat(opc, cond), "\tp$cop, cr$CRd, $addr", IndexModePost> {
4209     let Inst{31-28} = op31_28;
4210     let Inst{24} = 0; // P = 0
4211     let Inst{21} = 1; // W = 1
4212     let Inst{22} = 0; // D = 0
4213     let Inst{20} = load;
4214     let DecoderMethod = "DecodeCopMemInstruction";
4215   }
4216
4217   def _OPTION : ACI<(outs),
4218       !con((ins nohash_imm:$cop,nohash_imm:$CRd,GPR:$base, nohash_imm:$option),
4219             ops),
4220       !strconcat(opc, cond), "\tp$cop, cr$CRd, [$base], \\{$option\\}"> {
4221     let Inst{31-28} = op31_28;
4222     let Inst{24} = 0; // P = 0
4223     let Inst{23} = 1; // U = 1
4224     let Inst{21} = 0; // W = 0
4225     let Inst{22} = 0; // D = 0
4226     let Inst{20} = load;
4227     let DecoderMethod = "DecodeCopMemInstruction";
4228   }
4229
4230   def L_OFFSET : ACI<(outs),
4231       !con((ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr), ops),
4232       !strconcat(!strconcat(opc, "l"), cond), "\tp$cop, cr$CRd, $addr"> {
4233     let Inst{31-28} = op31_28;
4234     let Inst{24} = 1; // P = 1
4235     let Inst{21} = 0; // W = 0
4236     let Inst{22} = 1; // D = 1
4237     let Inst{20} = load;
4238     let DecoderMethod = "DecodeCopMemInstruction";
4239   }
4240
4241   def L_PRE : ACI<(outs),
4242       !con((ins nohash_imm:$cop, nohash_imm:$CRd, addrmode2:$addr), ops),
4243       !strconcat(!strconcat(opc, "l"), cond), "\tp$cop, cr$CRd, $addr!",
4244       IndexModePre> {
4245     let Inst{31-28} = op31_28;
4246     let Inst{24} = 1; // P = 1
4247     let Inst{21} = 1; // W = 1
4248     let Inst{22} = 1; // D = 1
4249     let Inst{20} = load;
4250     let DecoderMethod = "DecodeCopMemInstruction";
4251   }
4252
4253   def L_POST : ACI<(outs),
4254       !con((ins nohash_imm:$cop, nohash_imm:$CRd, addr_offset_none:$addr,
4255             postidx_imm8s4:$offset), ops),
4256       !strconcat(!strconcat(opc, "l"), cond), "\tp$cop, cr$CRd, $addr, $offset",
4257       IndexModePost> {
4258     let Inst{31-28} = op31_28;
4259     let Inst{24} = 0; // P = 0
4260     let Inst{21} = 1; // W = 1
4261     let Inst{22} = 1; // D = 1
4262     let Inst{20} = load;
4263     let DecoderMethod = "DecodeCopMemInstruction";
4264   }
4265
4266   def L_OPTION : ACI<(outs),
4267       !con((ins nohash_imm:$cop, nohash_imm:$CRd,GPR:$base,nohash_imm:$option),
4268             ops),
4269       !strconcat(!strconcat(opc, "l"), cond),
4270       "\tp$cop, cr$CRd, [$base], \\{$option\\}"> {
4271     let Inst{31-28} = op31_28;
4272     let Inst{24} = 0; // P = 0
4273     let Inst{23} = 1; // U = 1
4274     let Inst{21} = 0; // W = 0
4275     let Inst{22} = 1; // D = 1
4276     let Inst{20} = load;
4277     let DecoderMethod = "DecodeCopMemInstruction";
4278   }
4279   }
4280 }
4281
4282 defm LDC  : LdStCop<{?,?,?,?}, 1, (ins pred:$p), "ldc",  "${p}">;
4283 defm LDC2 : LdStCop<0b1111,    1, (ins),         "ldc2", "">;
4284 defm STC  : LdStCop<{?,?,?,?}, 0, (ins pred:$p), "stc",  "${p}">;
4285 defm STC2 : LdStCop<0b1111,    0, (ins),         "stc2", "">;
4286
4287 //===----------------------------------------------------------------------===//
4288 // Move between coprocessor and ARM core register.
4289 //
4290
4291 class MovRCopro<string opc, bit direction, dag oops, dag iops,
4292                 list<dag> pattern>
4293   : ABI<0b1110, oops, iops, NoItinerary, opc,
4294         "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2", pattern> {
4295   let Inst{20} = direction;
4296   let Inst{4} = 1;
4297
4298   bits<4> Rt;
4299   bits<4> cop;
4300   bits<3> opc1;
4301   bits<3> opc2;
4302   bits<4> CRm;
4303   bits<4> CRn;
4304
4305   let Inst{15-12} = Rt;
4306   let Inst{11-8}  = cop;
4307   let Inst{23-21} = opc1;
4308   let Inst{7-5}   = opc2;
4309   let Inst{3-0}   = CRm;
4310   let Inst{19-16} = CRn;
4311 }
4312
4313 def MCR : MovRCopro<"mcr", 0 /* from ARM core register to coprocessor */,
4314                     (outs),
4315                     (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4316                          c_imm:$CRm, imm0_7:$opc2),
4317                     [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4318                                   imm:$CRm, imm:$opc2)]>;
4319 def MRC : MovRCopro<"mrc", 1 /* from coprocessor to ARM core register */,
4320                     (outs GPR:$Rt),
4321                     (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm,
4322                          imm0_7:$opc2), []>;
4323
4324 def : ARMPat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
4325              (MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4326
4327 class MovRCopro2<string opc, bit direction, dag oops, dag iops,
4328                  list<dag> pattern>
4329   : ABXI<0b1110, oops, iops, NoItinerary,
4330          !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"), pattern> {
4331   let Inst{31-28} = 0b1111;
4332   let Inst{20} = direction;
4333   let Inst{4} = 1;
4334
4335   bits<4> Rt;
4336   bits<4> cop;
4337   bits<3> opc1;
4338   bits<3> opc2;
4339   bits<4> CRm;
4340   bits<4> CRn;
4341
4342   let Inst{15-12} = Rt;
4343   let Inst{11-8}  = cop;
4344   let Inst{23-21} = opc1;
4345   let Inst{7-5}   = opc2;
4346   let Inst{3-0}   = CRm;
4347   let Inst{19-16} = CRn;
4348 }
4349
4350 def MCR2 : MovRCopro2<"mcr2", 0 /* from ARM core register to coprocessor */,
4351                       (outs),
4352                       (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
4353                            c_imm:$CRm, imm0_7:$opc2),
4354                       [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
4355                                      imm:$CRm, imm:$opc2)]>;
4356 def MRC2 : MovRCopro2<"mrc2", 1 /* from coprocessor to ARM core register */,
4357                       (outs GPR:$Rt),
4358                       (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm,
4359                            imm0_7:$opc2), []>;
4360
4361 def : ARMV5TPat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn,
4362                               imm:$CRm, imm:$opc2),
4363                 (MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
4364
4365 class MovRRCopro<string opc, bit direction, list<dag> pattern = []>
4366   : ABI<0b1100, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4367         GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
4368         NoItinerary, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
4369   let Inst{23-21} = 0b010;
4370   let Inst{20} = direction;
4371
4372   bits<4> Rt;
4373   bits<4> Rt2;
4374   bits<4> cop;
4375   bits<4> opc1;
4376   bits<4> CRm;
4377
4378   let Inst{15-12} = Rt;
4379   let Inst{19-16} = Rt2;
4380   let Inst{11-8}  = cop;
4381   let Inst{7-4}   = opc1;
4382   let Inst{3-0}   = CRm;
4383 }
4384
4385 def MCRR : MovRRCopro<"mcrr", 0 /* from ARM core register to coprocessor */,
4386                       [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
4387                                      imm:$CRm)]>;
4388 def MRRC : MovRRCopro<"mrrc", 1 /* from coprocessor to ARM core register */>;
4389
4390 class MovRRCopro2<string opc, bit direction, list<dag> pattern = []>
4391   : ABXI<0b1100, (outs), (ins p_imm:$cop, imm0_15:$opc1,
4392          GPR:$Rt, GPR:$Rt2, c_imm:$CRm), NoItinerary,
4393          !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
4394   let Inst{31-28} = 0b1111;
4395   let Inst{23-21} = 0b010;
4396   let Inst{20} = direction;
4397
4398   bits<4> Rt;
4399   bits<4> Rt2;
4400   bits<4> cop;
4401   bits<4> opc1;
4402   bits<4> CRm;
4403
4404   let Inst{15-12} = Rt;
4405   let Inst{19-16} = Rt2;
4406   let Inst{11-8}  = cop;
4407   let Inst{7-4}   = opc1;
4408   let Inst{3-0}   = CRm;
4409 }
4410
4411 def MCRR2 : MovRRCopro2<"mcrr2", 0 /* from ARM core register to coprocessor */,
4412                         [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
4413                                         imm:$CRm)]>;
4414 def MRRC2 : MovRRCopro2<"mrrc2", 1 /* from coprocessor to ARM core register */>;
4415
4416 //===----------------------------------------------------------------------===//
4417 // Move between special register and ARM core register
4418 //
4419
4420 // Move to ARM core register from Special Register
4421 def MRS : ABI<0b0001, (outs GPR:$Rd), (ins), NoItinerary,
4422               "mrs", "\t$Rd, apsr", []> {
4423   bits<4> Rd;
4424   let Inst{23-16} = 0b00001111;
4425   let Inst{15-12} = Rd;
4426   let Inst{7-4} = 0b0000;
4427 }
4428
4429 def : InstAlias<"mrs${p} $Rd, cpsr", (MRS GPR:$Rd, pred:$p)>, Requires<[IsARM]>;
4430
4431 def MRSsys : ABI<0b0001, (outs GPR:$Rd), (ins), NoItinerary,
4432                  "mrs", "\t$Rd, spsr", []> {
4433   bits<4> Rd;
4434   let Inst{23-16} = 0b01001111;
4435   let Inst{15-12} = Rd;
4436   let Inst{7-4} = 0b0000;
4437 }
4438
4439 // Move from ARM core register to Special Register
4440 //
4441 // No need to have both system and application versions, the encodings are the
4442 // same and the assembly parser has no way to distinguish between them. The mask
4443 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
4444 // the mask with the fields to be accessed in the special register.
4445 def MSR : ABI<0b0001, (outs), (ins msr_mask:$mask, GPR:$Rn), NoItinerary,
4446               "msr", "\t$mask, $Rn", []> {
4447   bits<5> mask;
4448   bits<4> Rn;
4449
4450   let Inst{23} = 0;
4451   let Inst{22} = mask{4}; // R bit
4452   let Inst{21-20} = 0b10;
4453   let Inst{19-16} = mask{3-0};
4454   let Inst{15-12} = 0b1111;
4455   let Inst{11-4} = 0b00000000;
4456   let Inst{3-0} = Rn;
4457 }
4458
4459 def MSRi : ABI<0b0011, (outs), (ins msr_mask:$mask,  so_imm:$a), NoItinerary,
4460                "msr", "\t$mask, $a", []> {
4461   bits<5> mask;
4462   bits<12> a;
4463
4464   let Inst{23} = 0;
4465   let Inst{22} = mask{4}; // R bit
4466   let Inst{21-20} = 0b10;
4467   let Inst{19-16} = mask{3-0};
4468   let Inst{15-12} = 0b1111;
4469   let Inst{11-0} = a;
4470 }
4471
4472 //===----------------------------------------------------------------------===//
4473 // TLS Instructions
4474 //
4475
4476 // __aeabi_read_tp preserves the registers r1-r3.
4477 // This is a pseudo inst so that we can get the encoding right,
4478 // complete with fixup for the aeabi_read_tp function.
4479 let isCall = 1,
4480   Defs = [R0, R12, LR, CPSR], Uses = [SP] in {
4481   def TPsoft : PseudoInst<(outs), (ins), IIC_Br,
4482                [(set R0, ARMthread_pointer)]>;
4483 }
4484
4485 //===----------------------------------------------------------------------===//
4486 // SJLJ Exception handling intrinsics
4487 //   eh_sjlj_setjmp() is an instruction sequence to store the return
4488 //   address and save #0 in R0 for the non-longjmp case.
4489 //   Since by its nature we may be coming from some other function to get
4490 //   here, and we're using the stack frame for the containing function to
4491 //   save/restore registers, we can't keep anything live in regs across
4492 //   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
4493 //   when we get here from a longjmp(). We force everything out of registers
4494 //   except for our own input by listing the relevant registers in Defs. By
4495 //   doing so, we also cause the prologue/epilogue code to actively preserve
4496 //   all of the callee-saved resgisters, which is exactly what we want.
4497 //   A constant value is passed in $val, and we use the location as a scratch.
4498 //
4499 // These are pseudo-instructions and are lowered to individual MC-insts, so
4500 // no encoding information is necessary.
4501 let Defs =
4502   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR,
4503     QQQQ0, QQQQ1, QQQQ2, QQQQ3 ], hasSideEffects = 1, isBarrier = 1 in {
4504   def Int_eh_sjlj_setjmp : PseudoInst<(outs), (ins GPR:$src, GPR:$val),
4505                                NoItinerary,
4506                          [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>,
4507                            Requires<[IsARM, HasVFP2]>;
4508 }
4509
4510 let Defs =
4511   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR ],
4512   hasSideEffects = 1, isBarrier = 1 in {
4513   def Int_eh_sjlj_setjmp_nofp : PseudoInst<(outs), (ins GPR:$src, GPR:$val),
4514                                    NoItinerary,
4515                          [(set R0, (ARMeh_sjlj_setjmp GPR:$src, GPR:$val))]>,
4516                                 Requires<[IsARM, NoVFP]>;
4517 }
4518
4519 // FIXME: Non-Darwin version(s)
4520 let isBarrier = 1, hasSideEffects = 1, isTerminator = 1,
4521     Defs = [ R7, LR, SP ] in {
4522 def Int_eh_sjlj_longjmp : PseudoInst<(outs), (ins GPR:$src, GPR:$scratch),
4523                              NoItinerary,
4524                          [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
4525                                 Requires<[IsARM, IsDarwin]>;
4526 }
4527
4528 // eh.sjlj.dispatchsetup pseudo-instruction.
4529 // This pseudo is used for ARM, Thumb1 and Thumb2. Any differences are
4530 // handled when the pseudo is expanded (which happens before any passes
4531 // that need the instruction size).
4532 let isBarrier = 1, hasSideEffects = 1 in
4533 def Int_eh_sjlj_dispatchsetup :
4534  PseudoInst<(outs), (ins GPR:$src), NoItinerary,
4535             [(ARMeh_sjlj_dispatchsetup GPR:$src)]>,
4536               Requires<[IsDarwin]>;
4537
4538 //===----------------------------------------------------------------------===//
4539 // Non-Instruction Patterns
4540 //
4541
4542 // ARMv4 indirect branch using (MOVr PC, dst)
4543 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
4544   def MOVPCRX : ARMPseudoExpand<(outs), (ins GPR:$dst),
4545                     4, IIC_Br, [(brind GPR:$dst)],
4546                     (MOVr PC, GPR:$dst, (ops 14, zero_reg), zero_reg)>,
4547                   Requires<[IsARM, NoV4T]>;
4548
4549 // Large immediate handling.
4550
4551 // 32-bit immediate using two piece so_imms or movw + movt.
4552 // This is a single pseudo instruction, the benefit is that it can be remat'd
4553 // as a single unit instead of having to handle reg inputs.
4554 // FIXME: Remove this when we can do generalized remat.
4555 let isReMaterializable = 1, isMoveImm = 1 in
4556 def MOVi32imm : PseudoInst<(outs GPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
4557                            [(set GPR:$dst, (arm_i32imm:$src))]>,
4558                            Requires<[IsARM]>;
4559
4560 // Pseudo instruction that combines movw + movt + add pc (if PIC).
4561 // It also makes it possible to rematerialize the instructions.
4562 // FIXME: Remove this when we can do generalized remat and when machine licm
4563 // can properly the instructions.
4564 let isReMaterializable = 1 in {
4565 def MOV_ga_pcrel : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
4566                               IIC_iMOVix2addpc,
4567                         [(set GPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
4568                         Requires<[IsARM, UseMovt]>;
4569
4570 def MOV_ga_dyn : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
4571                              IIC_iMOVix2,
4572                         [(set GPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
4573                         Requires<[IsARM, UseMovt]>;
4574
4575 let AddedComplexity = 10 in
4576 def MOV_ga_pcrel_ldr : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr),
4577                                 IIC_iMOVix2ld,
4578                     [(set GPR:$dst, (load (ARMWrapperPIC tglobaladdr:$addr)))]>,
4579                     Requires<[IsARM, UseMovt]>;
4580 } // isReMaterializable
4581
4582 // ConstantPool, GlobalAddress, and JumpTable
4583 def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>,
4584             Requires<[IsARM, DontUseMovt]>;
4585 def : ARMPat<(ARMWrapper  tconstpool  :$dst), (LEApcrel tconstpool  :$dst)>;
4586 def : ARMPat<(ARMWrapper  tglobaladdr :$dst), (MOVi32imm tglobaladdr :$dst)>,
4587             Requires<[IsARM, UseMovt]>;
4588 def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
4589              (LEApcrelJT tjumptable:$dst, imm:$id)>;
4590
4591 // TODO: add,sub,and, 3-instr forms?
4592
4593 // Tail calls
4594 def : ARMPat<(ARMtcret tcGPR:$dst),
4595           (TCRETURNri tcGPR:$dst)>, Requires<[IsDarwin]>;
4596
4597 def : ARMPat<(ARMtcret (i32 tglobaladdr:$dst)),
4598           (TCRETURNdi texternalsym:$dst)>, Requires<[IsDarwin]>;
4599
4600 def : ARMPat<(ARMtcret (i32 texternalsym:$dst)),
4601           (TCRETURNdi texternalsym:$dst)>, Requires<[IsDarwin]>;
4602
4603 def : ARMPat<(ARMtcret tcGPR:$dst),
4604           (TCRETURNriND tcGPR:$dst)>, Requires<[IsNotDarwin]>;
4605
4606 def : ARMPat<(ARMtcret (i32 tglobaladdr:$dst)),
4607           (TCRETURNdiND texternalsym:$dst)>, Requires<[IsNotDarwin]>;
4608
4609 def : ARMPat<(ARMtcret (i32 texternalsym:$dst)),
4610           (TCRETURNdiND texternalsym:$dst)>, Requires<[IsNotDarwin]>;
4611
4612 // Direct calls
4613 def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>,
4614       Requires<[IsARM, IsNotDarwin]>;
4615 def : ARMPat<(ARMcall texternalsym:$func), (BLr9 texternalsym:$func)>,
4616       Requires<[IsARM, IsDarwin]>;
4617
4618 // zextload i1 -> zextload i8
4619 def : ARMPat<(zextloadi1 addrmode_imm12:$addr), (LDRBi12 addrmode_imm12:$addr)>;
4620 def : ARMPat<(zextloadi1 ldst_so_reg:$addr),    (LDRBrs ldst_so_reg:$addr)>;
4621
4622 // extload -> zextload
4623 def : ARMPat<(extloadi1 addrmode_imm12:$addr),  (LDRBi12 addrmode_imm12:$addr)>;
4624 def : ARMPat<(extloadi1 ldst_so_reg:$addr),     (LDRBrs ldst_so_reg:$addr)>;
4625 def : ARMPat<(extloadi8 addrmode_imm12:$addr),  (LDRBi12 addrmode_imm12:$addr)>;
4626 def : ARMPat<(extloadi8 ldst_so_reg:$addr),     (LDRBrs ldst_so_reg:$addr)>;
4627
4628 def : ARMPat<(extloadi16 addrmode3:$addr),  (LDRH addrmode3:$addr)>;
4629
4630 def : ARMPat<(extloadi8  addrmodepc:$addr), (PICLDRB addrmodepc:$addr)>;
4631 def : ARMPat<(extloadi16 addrmodepc:$addr), (PICLDRH addrmodepc:$addr)>;
4632
4633 // smul* and smla*
4634 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
4635                       (sra (shl GPR:$b, (i32 16)), (i32 16))),
4636                  (SMULBB GPR:$a, GPR:$b)>;
4637 def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
4638                  (SMULBB GPR:$a, GPR:$b)>;
4639 def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
4640                       (sra GPR:$b, (i32 16))),
4641                  (SMULBT GPR:$a, GPR:$b)>;
4642 def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, (i32 16))),
4643                  (SMULBT GPR:$a, GPR:$b)>;
4644 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)),
4645                       (sra (shl GPR:$b, (i32 16)), (i32 16))),
4646                  (SMULTB GPR:$a, GPR:$b)>;
4647 def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)), sext_16_node:$b),
4648                 (SMULTB GPR:$a, GPR:$b)>;
4649 def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
4650                       (i32 16)),
4651                  (SMULWB GPR:$a, GPR:$b)>;
4652 def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), (i32 16)),
4653                  (SMULWB GPR:$a, GPR:$b)>;
4654
4655 def : ARMV5TEPat<(add GPR:$acc,
4656                       (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
4657                            (sra (shl GPR:$b, (i32 16)), (i32 16)))),
4658                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
4659 def : ARMV5TEPat<(add GPR:$acc,
4660                       (mul sext_16_node:$a, sext_16_node:$b)),
4661                  (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
4662 def : ARMV5TEPat<(add GPR:$acc,
4663                       (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
4664                            (sra GPR:$b, (i32 16)))),
4665                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
4666 def : ARMV5TEPat<(add GPR:$acc,
4667                       (mul sext_16_node:$a, (sra GPR:$b, (i32 16)))),
4668                  (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
4669 def : ARMV5TEPat<(add GPR:$acc,
4670                       (mul (sra GPR:$a, (i32 16)),
4671                            (sra (shl GPR:$b, (i32 16)), (i32 16)))),
4672                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
4673 def : ARMV5TEPat<(add GPR:$acc,
4674                       (mul (sra GPR:$a, (i32 16)), sext_16_node:$b)),
4675                  (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
4676 def : ARMV5TEPat<(add GPR:$acc,
4677                       (sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
4678                            (i32 16))),
4679                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
4680 def : ARMV5TEPat<(add GPR:$acc,
4681                       (sra (mul GPR:$a, sext_16_node:$b), (i32 16))),
4682                  (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
4683
4684
4685 // Pre-v7 uses MCR for synchronization barriers.
4686 def : ARMPat<(ARMMemBarrierMCR GPR:$zero), (MCR 15, 0, GPR:$zero, 7, 10, 5)>,
4687          Requires<[IsARM, HasV6]>;
4688
4689 // SXT/UXT with no rotate
4690 let AddedComplexity = 16 in {
4691 def : ARMV6Pat<(and GPR:$Src, 0x000000FF), (UXTB GPR:$Src, 0)>;
4692 def : ARMV6Pat<(and GPR:$Src, 0x0000FFFF), (UXTH GPR:$Src, 0)>;
4693 def : ARMV6Pat<(and GPR:$Src, 0x00FF00FF), (UXTB16 GPR:$Src, 0)>;
4694 def : ARMV6Pat<(add GPR:$Rn, (and GPR:$Rm, 0x00FF)),
4695                (UXTAB GPR:$Rn, GPR:$Rm, 0)>;
4696 def : ARMV6Pat<(add GPR:$Rn, (and GPR:$Rm, 0xFFFF)),
4697                (UXTAH GPR:$Rn, GPR:$Rm, 0)>;
4698 }
4699
4700 def : ARMV6Pat<(sext_inreg GPR:$Src, i8),  (SXTB GPR:$Src, 0)>;
4701 def : ARMV6Pat<(sext_inreg GPR:$Src, i16), (SXTH GPR:$Src, 0)>;
4702
4703 def : ARMV6Pat<(add GPR:$Rn, (sext_inreg GPRnopc:$Rm, i8)),
4704                (SXTAB GPR:$Rn, GPRnopc:$Rm, 0)>;
4705 def : ARMV6Pat<(add GPR:$Rn, (sext_inreg GPRnopc:$Rm, i16)),
4706                (SXTAH GPR:$Rn, GPRnopc:$Rm, 0)>;
4707
4708 //===----------------------------------------------------------------------===//
4709 // Thumb Support
4710 //
4711
4712 include "ARMInstrThumb.td"
4713
4714 //===----------------------------------------------------------------------===//
4715 // Thumb2 Support
4716 //
4717
4718 include "ARMInstrThumb2.td"
4719
4720 //===----------------------------------------------------------------------===//
4721 // Floating Point Support
4722 //
4723
4724 include "ARMInstrVFP.td"
4725
4726 //===----------------------------------------------------------------------===//
4727 // Advanced SIMD (NEON) Support
4728 //
4729
4730 include "ARMInstrNEON.td"
4731
4732 //===----------------------------------------------------------------------===//
4733 // Assembler aliases
4734 //
4735
4736 // Memory barriers
4737 def : InstAlias<"dmb", (DMB 0xf)>, Requires<[IsARM, HasDB]>;
4738 def : InstAlias<"dsb", (DSB 0xf)>, Requires<[IsARM, HasDB]>;
4739 def : InstAlias<"isb", (ISB 0xf)>, Requires<[IsARM, HasDB]>;
4740
4741 // System instructions
4742 def : MnemonicAlias<"swi", "svc">;
4743
4744 // Load / Store Multiple
4745 def : MnemonicAlias<"ldmfd", "ldm">;
4746 def : MnemonicAlias<"ldmia", "ldm">;
4747 def : MnemonicAlias<"stmfd", "stmdb">;
4748 def : MnemonicAlias<"stmia", "stm">;
4749 def : MnemonicAlias<"stmea", "stm">;
4750
4751 // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT when the
4752 // shift amount is zero (i.e., unspecified).
4753 def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
4754                 (PKHBT GPR:$Rd, GPR:$Rn, GPR:$Rm, 0, pred:$p)>;
4755 def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
4756                 (PKHBT GPR:$Rd, GPR:$Rn, GPR:$Rm, 0, pred:$p)>;
4757
4758 // PUSH/POP aliases for STM/LDM
4759 def : InstAlias<"push${p} $regs",
4760                 (STMDB_UPD SP, pred:$p, reglist:$regs)>;
4761 def : InstAlias<"pop${p} $regs",
4762                 (LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4763
4764 // RSB two-operand forms (optional explicit destination operand)
4765 def : InstAlias<"rsb${s}${p} $Rdn, $imm",
4766                 (RSBri GPR:$Rdn, GPR:$Rdn, so_imm:$imm, pred:$p, cc_out:$s)>,
4767          Requires<[IsARM]>;
4768 def : InstAlias<"rsb${s}${p} $Rdn, $Rm",
4769                 (RSBrr GPR:$Rdn, GPR:$Rdn, GPR:$Rm, pred:$p, cc_out:$s)>,
4770          Requires<[IsARM]>;
4771 def : InstAlias<"rsb${s}${p} $Rdn, $shift",
4772                 (RSBrsi GPR:$Rdn, GPR:$Rdn, so_reg_imm:$shift, pred:$p,
4773                         cc_out:$s)>, Requires<[IsARM]>;
4774 def : InstAlias<"rsb${s}${p} $Rdn, $shift",
4775                 (RSBrsr GPR:$Rdn, GPR:$Rdn, so_reg_reg:$shift, pred:$p,
4776                         cc_out:$s)>, Requires<[IsARM]>;
4777 // RSC two-operand forms (optional explicit destination operand)
4778 def : InstAlias<"rsc${s}${p} $Rdn, $imm",
4779                 (RSCri GPR:$Rdn, GPR:$Rdn, so_imm:$imm, pred:$p, cc_out:$s)>,
4780          Requires<[IsARM]>;
4781 def : InstAlias<"rsc${s}${p} $Rdn, $Rm",
4782                 (RSCrr GPR:$Rdn, GPR:$Rdn, GPR:$Rm, pred:$p, cc_out:$s)>,
4783          Requires<[IsARM]>;
4784 def : InstAlias<"rsc${s}${p} $Rdn, $shift",
4785                 (RSCrsi GPR:$Rdn, GPR:$Rdn, so_reg_imm:$shift, pred:$p,
4786                         cc_out:$s)>, Requires<[IsARM]>;
4787 def : InstAlias<"rsc${s}${p} $Rdn, $shift",
4788                 (RSCrsr GPR:$Rdn, GPR:$Rdn, so_reg_reg:$shift, pred:$p,
4789                         cc_out:$s)>, Requires<[IsARM]>;
4790
4791 // SSAT/USAT optional shift operand.
4792 def : InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
4793                 (SSAT GPRnopc:$Rd, imm1_32:$sat_imm, GPRnopc:$Rn, 0, pred:$p)>;
4794 def : InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
4795                 (USAT GPRnopc:$Rd, imm0_31:$sat_imm, GPRnopc:$Rn, 0, pred:$p)>;
4796
4797
4798 // Extend instruction optional rotate operand.
4799 def : InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
4800                 (SXTAB GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
4801 def : InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
4802                 (SXTAH GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
4803 def : InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
4804                 (SXTAB16 GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
4805 def : InstAlias<"sxtb${p} $Rd, $Rm",
4806                 (SXTB GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
4807 def : InstAlias<"sxtb16${p} $Rd, $Rm",
4808                 (SXTB16 GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
4809 def : InstAlias<"sxth${p} $Rd, $Rm",
4810                 (SXTH GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
4811
4812 def : InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
4813                 (UXTAB GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
4814 def : InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
4815                 (UXTAH GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
4816 def : InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
4817                 (UXTAB16 GPRnopc:$Rd, GPR:$Rn, GPRnopc:$Rm, 0, pred:$p)>;
4818 def : InstAlias<"uxtb${p} $Rd, $Rm",
4819                 (UXTB GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
4820 def : InstAlias<"uxtb16${p} $Rd, $Rm",
4821                 (UXTB16 GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
4822 def : InstAlias<"uxth${p} $Rd, $Rm",
4823                 (UXTH GPRnopc:$Rd, GPRnopc:$Rm, 0, pred:$p)>;
4824
4825
4826 // RFE aliases
4827 def : MnemonicAlias<"rfefa", "rfeda">;
4828 def : MnemonicAlias<"rfeea", "rfedb">;
4829 def : MnemonicAlias<"rfefd", "rfeia">;
4830 def : MnemonicAlias<"rfeed", "rfeib">;
4831 def : MnemonicAlias<"rfe", "rfeia">;
4832
4833 // SRS aliases
4834 def : MnemonicAlias<"srsfa", "srsda">;
4835 def : MnemonicAlias<"srsea", "srsdb">;
4836 def : MnemonicAlias<"srsfd", "srsia">;
4837 def : MnemonicAlias<"srsed", "srsib">;
4838 def : MnemonicAlias<"srs", "srsia">;
4839
4840 // LDRSBT/LDRHT/LDRSHT post-index offset if optional.
4841 // Note that the write-back output register is a dummy operand for MC (it's
4842 // only meaningful for codegen), so we just pass zero here.
4843 // FIXME: tblgen not cooperating with argument conversions.
4844 //def : InstAlias<"ldrsbt${p} $Rt, $addr",
4845 //                (LDRSBTi GPR:$Rt, GPR:$Rt, addr_offset_none:$addr, 0,pred:$p)>;
4846 //def : InstAlias<"ldrht${p} $Rt, $addr",
4847 //                (LDRHTi GPR:$Rt, GPR:$Rt, addr_offset_none:$addr, 0, pred:$p)>;
4848 //def : InstAlias<"ldrsht${p} $Rt, $addr",
4849 //                (LDRSHTi GPR:$Rt, GPR:$Rt, addr_offset_none:$addr, 0, pred:$p)>;