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