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