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