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