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