OSDN Git Service

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