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