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