blob: da8b3733c9a37b9461f78f0c8e5537fb8000d150 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMInstrInfo.td - Target Description for ARM Target -*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006// 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.
Bill Wendling7173da52007-11-13 09:19:02 +000019def SDT_ARMCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
20def SDT_ARMCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021
22def SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
23
24def SDT_ARMcall : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
25
26def SDT_ARMCMov : SDTypeProfile<1, 3,
27 [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
28 SDTCisVT<3, i32>]>;
29
30def SDT_ARMBrcond : SDTypeProfile<0, 2,
31 [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
32
33def SDT_ARMBrJT : SDTypeProfile<0, 3,
34 [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
35 SDTCisVT<2, i32>]>;
36
Evan Cheng1b2b3e22009-07-29 02:18:14 +000037def SDT_ARMBr2JT : SDTypeProfile<0, 4,
38 [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
39 SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
40
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041def SDT_ARMCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
42
43def SDT_ARMPICAdd : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
44 SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
45
46def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
Jim Grosbach4a9025e2009-05-14 00:46:35 +000047def SDT_ARMEH_SJLJ_Setjmp : SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048
Jim Grosbach6eee9032009-12-14 21:24:16 +000049def SDT_ARMMEMBARRIERV7 : SDTypeProfile<0, 0, []>;
50def SDT_ARMSYNCBARRIERV7 : SDTypeProfile<0, 0, []>;
51def SDT_ARMMEMBARRIERV6 : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
52def SDT_ARMSYNCBARRIERV6 : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
Jim Grosbachba744f62009-12-10 00:11:09 +000053
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054// Node definitions.
55def ARMWrapper : SDNode<"ARMISD::Wrapper", SDTIntUnaryOp>;
56def ARMWrapperJT : SDNode<"ARMISD::WrapperJT", SDTIntBinOp>;
57
Bill Wendling7173da52007-11-13 09:19:02 +000058def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
Bill Wendling6c02cd22008-02-27 06:33:05 +000059 [SDNPHasChain, SDNPOutFlag]>;
Bill Wendling7173da52007-11-13 09:19:02 +000060def ARMcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_ARMCallSeqEnd,
Bill Wendling6c02cd22008-02-27 06:33:05 +000061 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062
63def ARMcall : SDNode<"ARMISD::CALL", SDT_ARMcall,
64 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
65def ARMcall_pred : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
66 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
67def ARMcall_nolink : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
68 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
69
Chris Lattner3d254552008-01-15 22:02:54 +000070def ARMretflag : SDNode<"ARMISD::RET_FLAG", SDTNone,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071 [SDNPHasChain, SDNPOptInFlag]>;
72
73def ARMcmov : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
74 [SDNPInFlag]>;
75def ARMcneg : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
76 [SDNPInFlag]>;
77
78def ARMbrcond : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
79 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
80
81def ARMbrjt : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
82 [SDNPHasChain]>;
Evan Cheng1b2b3e22009-07-29 02:18:14 +000083def ARMbr2jt : SDNode<"ARMISD::BR2_JT", SDT_ARMBr2JT,
84 [SDNPHasChain]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000085
86def ARMcmp : SDNode<"ARMISD::CMP", SDT_ARMCmp,
87 [SDNPOutFlag]>;
88
David Goodwin8bdcbb32009-06-29 15:33:01 +000089def ARMcmpZ : SDNode<"ARMISD::CMPZ", SDT_ARMCmp,
90 [SDNPOutFlag,SDNPCommutative]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091
92def ARMpic_add : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
93
94def ARMsrl_flag : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
95def ARMsra_flag : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
96def ARMrrx : SDNode<"ARMISD::RRX" , SDTIntUnaryOp, [SDNPInFlag ]>;
97
98def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
Jim Grosbach4a9025e2009-05-14 00:46:35 +000099def ARMeh_sjlj_setjmp: SDNode<"ARMISD::EH_SJLJ_SETJMP", SDT_ARMEH_SJLJ_Setjmp>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000100
Jim Grosbach6eee9032009-12-14 21:24:16 +0000101def ARMMemBarrierV7 : SDNode<"ARMISD::MEMBARRIER", SDT_ARMMEMBARRIERV7,
Jim Grosbachba744f62009-12-10 00:11:09 +0000102 [SDNPHasChain]>;
Jim Grosbach6eee9032009-12-14 21:24:16 +0000103def ARMSyncBarrierV7 : SDNode<"ARMISD::SYNCBARRIER", SDT_ARMMEMBARRIERV7,
104 [SDNPHasChain]>;
105def ARMMemBarrierV6 : SDNode<"ARMISD::MEMBARRIER", SDT_ARMMEMBARRIERV6,
106 [SDNPHasChain]>;
107def ARMSyncBarrierV6 : SDNode<"ARMISD::SYNCBARRIER", SDT_ARMMEMBARRIERV6,
Jim Grosbachba744f62009-12-10 00:11:09 +0000108 [SDNPHasChain]>;
109
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110//===----------------------------------------------------------------------===//
111// ARM Instruction Predicate Definitions.
112//
Anton Korobeynikovcba02692009-06-15 21:46:20 +0000113def HasV5T : Predicate<"Subtarget->hasV5TOps()">;
114def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">;
115def HasV6 : Predicate<"Subtarget->hasV6Ops()">;
Evan Chengc8147e12009-07-06 22:05:45 +0000116def HasV6T2 : Predicate<"Subtarget->hasV6T2Ops()">;
Evan Cheng16c012d2009-09-28 09:14:39 +0000117def NoV6T2 : Predicate<"!Subtarget->hasV6T2Ops()">;
Bob Wilsone60fee02009-06-22 23:27:02 +0000118def HasV7 : Predicate<"Subtarget->hasV7Ops()">;
119def HasVFP2 : Predicate<"Subtarget->hasVFP2()">;
120def HasVFP3 : Predicate<"Subtarget->hasVFP3()">;
121def HasNEON : Predicate<"Subtarget->hasNEON()">;
David Goodwindd19ce42009-08-04 17:53:06 +0000122def UseNEONForFP : Predicate<"Subtarget->useNEONForSinglePrecisionFP()">;
123def DontUseNEONForFP : Predicate<"!Subtarget->useNEONForSinglePrecisionFP()">;
Anton Korobeynikovcba02692009-06-15 21:46:20 +0000124def IsThumb : Predicate<"Subtarget->isThumb()">;
Evan Cheng36173712009-06-23 17:48:47 +0000125def IsThumb1Only : Predicate<"Subtarget->isThumb1Only()">;
Evan Chengb1b2abc2009-07-02 06:38:40 +0000126def IsThumb2 : Predicate<"Subtarget->isThumb2()">;
Anton Korobeynikovcba02692009-06-15 21:46:20 +0000127def IsARM : Predicate<"!Subtarget->isThumb()">;
Bob Wilson243b37c2009-06-22 21:01:46 +0000128def IsDarwin : Predicate<"Subtarget->isTargetDarwin()">;
129def IsNotDarwin : Predicate<"!Subtarget->isTargetDarwin()">;
Evan Cheng3e9a99e2009-06-26 06:10:18 +0000130def CarryDefIsUnused : Predicate<"!N.getNode()->hasAnyUseOfValue(1)">;
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000131def CarryDefIsUsed : Predicate<"N.getNode()->hasAnyUseOfValue(1)">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000132
Anton Korobeynikova414f362009-11-24 00:44:37 +0000133// FIXME: Eventually this will be just "hasV6T2Ops".
134def UseMovt : Predicate<"Subtarget->useMovt()">;
135def DontUseMovt : Predicate<"!Subtarget->useMovt()">;
136
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000137//===----------------------------------------------------------------------===//
138// ARM Flag Definitions.
139
140class RegConstraint<string C> {
141 string Constraints = C;
142}
143
144//===----------------------------------------------------------------------===//
145// ARM specific transformation functions and pattern fragments.
146//
147
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000148// so_imm_neg_XFORM - Return a so_imm value packed into the format described for
149// so_imm_neg def below.
150def so_imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000151 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000152}]>;
153
154// so_imm_not_XFORM - Return a so_imm value packed into the format described for
155// so_imm_not def below.
156def so_imm_not_XFORM : SDNodeXForm<imm, [{
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000157 return CurDAG->getTargetConstant(~(int)N->getZExtValue(), MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158}]>;
159
160// rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
161def rot_imm : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000162 int32_t v = (int32_t)N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163 return v == 8 || v == 16 || v == 24;
164}]>;
165
166/// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
167def imm1_15 : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000168 return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169}]>;
170
171/// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
172def imm16_31 : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000173 return (int32_t)N->getZExtValue() >= 16 && (int32_t)N->getZExtValue() < 32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000174}]>;
175
176def so_imm_neg :
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000177 PatLeaf<(imm), [{
178 return ARM_AM::getSOImmVal(-(int)N->getZExtValue()) != -1;
179 }], so_imm_neg_XFORM>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000180
181def so_imm_not :
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000182 PatLeaf<(imm), [{
183 return ARM_AM::getSOImmVal(~(int)N->getZExtValue()) != -1;
184 }], so_imm_not_XFORM>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185
186// sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
187def sext_16_node : PatLeaf<(i32 GPR:$a), [{
Dan Gohman8181bd12008-07-27 21:46:04 +0000188 return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189}]>;
190
Evan Cheng299ee652009-07-06 22:23:46 +0000191/// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
192/// e.g., 0xf000ffff
193def bf_inv_mask_imm : Operand<i32>,
194 PatLeaf<(imm), [{
195 uint32_t v = (uint32_t)N->getZExtValue();
196 if (v == 0xffffffff)
197 return 0;
David Goodwinf354d362009-07-14 00:57:56 +0000198 // there can be 1's on either or both "outsides", all the "inside"
199 // bits must be 0's
200 unsigned int lsb = 0, msb = 31;
201 while (v & (1 << msb)) --msb;
202 while (v & (1 << lsb)) ++lsb;
203 for (unsigned int i = lsb; i <= msb; ++i) {
204 if (v & (1 << i))
205 return 0;
206 }
207 return 1;
Evan Cheng299ee652009-07-06 22:23:46 +0000208}] > {
209 let PrintMethod = "printBitfieldInvMaskImmOperand";
210}
211
Anton Korobeynikov60928952009-09-27 23:52:58 +0000212/// Split a 32-bit immediate into two 16 bit parts.
213def lo16 : SDNodeXForm<imm, [{
214 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() & 0xffff,
215 MVT::i32);
216}]>;
217
218def hi16 : SDNodeXForm<imm, [{
219 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
220}]>;
221
222def lo16AllZero : PatLeaf<(i32 imm), [{
223 // Returns true if all low 16-bits are 0.
224 return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
Anton Korobeynikova414f362009-11-24 00:44:37 +0000225}], hi16>;
Anton Korobeynikov60928952009-09-27 23:52:58 +0000226
227/// imm0_65535 predicate - True if the 32-bit immediate is in the range
228/// [0.65535].
229def imm0_65535 : PatLeaf<(i32 imm), [{
230 return (uint32_t)N->getZExtValue() < 65536;
231}]>;
232
Evan Cheng7b0249b2008-08-28 23:39:26 +0000233class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
234class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000235
236//===----------------------------------------------------------------------===//
237// Operand Definitions.
238//
239
240// Branch target.
241def brtarget : Operand<OtherVT>;
242
243// A list of registers separated by comma. Used by load/store multiple.
244def reglist : Operand<i32> {
245 let PrintMethod = "printRegisterList";
246}
247
248// An operand for the CONSTPOOL_ENTRY pseudo-instruction.
249def cpinst_operand : Operand<i32> {
250 let PrintMethod = "printCPInstOperand";
251}
252
253def jtblock_operand : Operand<i32> {
254 let PrintMethod = "printJTBlockOperand";
255}
Evan Cheng6e2ebc92009-07-25 00:33:29 +0000256def jt2block_operand : Operand<i32> {
257 let PrintMethod = "printJT2BlockOperand";
258}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259
260// Local PC labels.
261def pclabel : Operand<i32> {
262 let PrintMethod = "printPCLabel";
263}
264
265// shifter_operand operands: so_reg and so_imm.
266def so_reg : Operand<i32>, // reg reg imm
267 ComplexPattern<i32, 3, "SelectShifterOperandReg",
268 [shl,srl,sra,rotr]> {
269 let PrintMethod = "printSORegOperand";
270 let MIOperandInfo = (ops GPR, GPR, i32imm);
271}
272
273// so_imm - Match a 32-bit shifter_operand immediate operand, which is an
274// 8-bit immediate rotated by an arbitrary number of bits. so_imm values are
275// represented in the imm field in the same 12-bit form that they are encoded
276// into so_imm instructions: the 8-bit immediate is the least significant bits
277// [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
278def so_imm : Operand<i32>,
Evan Cheng8be2a5b2009-07-08 21:03:57 +0000279 PatLeaf<(imm), [{
280 return ARM_AM::getSOImmVal(N->getZExtValue()) != -1;
281 }]> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282 let PrintMethod = "printSOImmOperand";
283}
284
285// Break so_imm's up into two pieces. This handles immediates with up to 16
286// bits set in them. This uses so_imm2part to match and so_imm2part_[12] to
287// get the first/second pieces.
288def so_imm2part : Operand<i32>,
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000289 PatLeaf<(imm), [{
290 return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
291 }]> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 let PrintMethod = "printSOImm2PartOperand";
293}
294
295def so_imm2part_1 : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000296 unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getZExtValue());
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000297 return CurDAG->getTargetConstant(V, MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298}]>;
299
300def so_imm2part_2 : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +0000301 unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getZExtValue());
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000302 return CurDAG->getTargetConstant(V, MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303}]>;
304
Jim Grosbach66e70cd2009-11-23 20:35:53 +0000305def so_neg_imm2part : Operand<i32>, PatLeaf<(imm), [{
306 return ARM_AM::isSOImmTwoPartVal(-(int)N->getZExtValue());
307 }]> {
308 let PrintMethod = "printSOImm2PartOperand";
309}
310
311def so_neg_imm2part_1 : SDNodeXForm<imm, [{
312 unsigned V = ARM_AM::getSOImmTwoPartFirst(-(int)N->getZExtValue());
313 return CurDAG->getTargetConstant(V, MVT::i32);
314}]>;
315
316def so_neg_imm2part_2 : SDNodeXForm<imm, [{
317 unsigned V = ARM_AM::getSOImmTwoPartSecond(-(int)N->getZExtValue());
318 return CurDAG->getTargetConstant(V, MVT::i32);
319}]>;
320
Sandeep Patelbb4648a2009-10-13 18:59:48 +0000321/// imm0_31 predicate - True if the 32-bit immediate is in the range [0,31].
322def imm0_31 : Operand<i32>, PatLeaf<(imm), [{
323 return (int32_t)N->getZExtValue() < 32;
324}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325
326// Define ARM specific addressing modes.
327
328// addrmode2 := reg +/- reg shop imm
329// addrmode2 := reg +/- imm12
330//
331def addrmode2 : Operand<i32>,
332 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
333 let PrintMethod = "printAddrMode2Operand";
334 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
335}
336
337def am2offset : Operand<i32>,
338 ComplexPattern<i32, 2, "SelectAddrMode2Offset", []> {
339 let PrintMethod = "printAddrMode2OffsetOperand";
340 let MIOperandInfo = (ops GPR, i32imm);
341}
342
343// addrmode3 := reg +/- reg
344// addrmode3 := reg +/- imm8
345//
346def addrmode3 : Operand<i32>,
347 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
348 let PrintMethod = "printAddrMode3Operand";
349 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
350}
351
352def am3offset : Operand<i32>,
353 ComplexPattern<i32, 2, "SelectAddrMode3Offset", []> {
354 let PrintMethod = "printAddrMode3OffsetOperand";
355 let MIOperandInfo = (ops GPR, i32imm);
356}
357
358// addrmode4 := reg, <mode|W>
359//
360def addrmode4 : Operand<i32>,
Anton Korobeynikov3f087662009-08-08 13:35:48 +0000361 ComplexPattern<i32, 2, "SelectAddrMode4", []> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000362 let PrintMethod = "printAddrMode4Operand";
363 let MIOperandInfo = (ops GPR, i32imm);
364}
365
366// addrmode5 := reg +/- imm8*4
367//
368def addrmode5 : Operand<i32>,
369 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
370 let PrintMethod = "printAddrMode5Operand";
371 let MIOperandInfo = (ops GPR, i32imm);
372}
373
Bob Wilson970a10d2009-07-01 23:16:05 +0000374// addrmode6 := reg with optional writeback
375//
376def addrmode6 : Operand<i32>,
Jim Grosbach04d92822009-11-07 21:25:39 +0000377 ComplexPattern<i32, 4, "SelectAddrMode6", []> {
Bob Wilson970a10d2009-07-01 23:16:05 +0000378 let PrintMethod = "printAddrMode6Operand";
Jim Grosbach04d92822009-11-07 21:25:39 +0000379 let MIOperandInfo = (ops GPR:$addr, GPR:$upd, i32imm, i32imm);
Bob Wilson970a10d2009-07-01 23:16:05 +0000380}
381
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382// addrmodepc := pc + reg
383//
384def addrmodepc : Operand<i32>,
385 ComplexPattern<i32, 2, "SelectAddrModePC", []> {
386 let PrintMethod = "printAddrModePCOperand";
387 let MIOperandInfo = (ops GPR, i32imm);
388}
389
Bob Wilson30ff4492009-08-21 21:58:55 +0000390def nohash_imm : Operand<i32> {
391 let PrintMethod = "printNoHashImmediate";
Anton Korobeynikove2be3382009-08-08 23:10:41 +0000392}
393
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394//===----------------------------------------------------------------------===//
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000395
Evan Cheng7b0249b2008-08-28 23:39:26 +0000396include "ARMInstrFormats.td"
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000397
398//===----------------------------------------------------------------------===//
Evan Cheng7b0249b2008-08-28 23:39:26 +0000399// Multiclass helpers...
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400//
401
Evan Cheng40d64532008-08-29 07:36:24 +0000402/// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403/// binop that produces a value.
Evan Chengbdd679a2009-06-26 00:19:44 +0000404multiclass AsI1_bin_irs<bits<4> opcod, string opc, PatFrag opnode,
405 bit Commutable = 0> {
Evan Cheng86a926a2008-11-05 18:35:52 +0000406 def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000407 IIC_iALUi, opc, "\t$dst, $a, $b",
Evan Cheng83a32b42009-07-07 23:40:25 +0000408 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]> {
409 let Inst{25} = 1;
410 }
Evan Cheng86a926a2008-11-05 18:35:52 +0000411 def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000412 IIC_iALUr, opc, "\t$dst, $a, $b",
Evan Chengbdd679a2009-06-26 00:19:44 +0000413 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]> {
Johnny Chend139b942009-11-07 00:54:36 +0000414 let Inst{11-4} = 0b00000000;
Evan Cheng83a32b42009-07-07 23:40:25 +0000415 let Inst{25} = 0;
Evan Chengbdd679a2009-06-26 00:19:44 +0000416 let isCommutable = Commutable;
417 }
Evan Cheng86a926a2008-11-05 18:35:52 +0000418 def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000419 IIC_iALUsr, opc, "\t$dst, $a, $b",
Evan Cheng83a32b42009-07-07 23:40:25 +0000420 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]> {
421 let Inst{25} = 0;
422 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000423}
424
Evan Chengd4e2f052009-06-25 20:59:23 +0000425/// AI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
Bob Wilson3443c212009-10-06 20:18:46 +0000426/// instruction modifies the CPSR register.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000427let Defs = [CPSR] in {
Evan Chengbdd679a2009-06-26 00:19:44 +0000428multiclass AI1_bin_s_irs<bits<4> opcod, string opc, PatFrag opnode,
429 bit Commutable = 0> {
Evan Cheng86a926a2008-11-05 18:35:52 +0000430 def ri : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +0000431 IIC_iALUi, opc, "\t$dst, $a, $b",
Evan Cheng83a32b42009-07-07 23:40:25 +0000432 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]> {
Bob Wilson3a308522009-10-26 22:34:44 +0000433 let Inst{20} = 1;
Evan Cheng83a32b42009-07-07 23:40:25 +0000434 let Inst{25} = 1;
435 }
Evan Cheng86a926a2008-11-05 18:35:52 +0000436 def rr : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +0000437 IIC_iALUr, opc, "\t$dst, $a, $b",
Evan Chengbdd679a2009-06-26 00:19:44 +0000438 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]> {
439 let isCommutable = Commutable;
Johnny Chend139b942009-11-07 00:54:36 +0000440 let Inst{11-4} = 0b00000000;
Bob Wilson3a308522009-10-26 22:34:44 +0000441 let Inst{20} = 1;
Bob Wilsonb072c752009-10-13 15:27:23 +0000442 let Inst{25} = 0;
Evan Chengbdd679a2009-06-26 00:19:44 +0000443 }
Evan Cheng86a926a2008-11-05 18:35:52 +0000444 def rs : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +0000445 IIC_iALUsr, opc, "\t$dst, $a, $b",
Evan Cheng83a32b42009-07-07 23:40:25 +0000446 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]> {
Bob Wilson3a308522009-10-26 22:34:44 +0000447 let Inst{20} = 1;
Evan Cheng83a32b42009-07-07 23:40:25 +0000448 let Inst{25} = 0;
449 }
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000450}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451}
452
453/// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
454/// patterns. Similar to AsI1_bin_irs except the instruction does not produce
455/// a explicit result, only implicitly set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000456let Defs = [CPSR] in {
Evan Chengbdd679a2009-06-26 00:19:44 +0000457multiclass AI1_cmp_irs<bits<4> opcod, string opc, PatFrag opnode,
458 bit Commutable = 0> {
David Goodwin236ccb52009-08-19 18:00:44 +0000459 def ri : AI1<opcod, (outs), (ins GPR:$a, so_imm:$b), DPFrm, IIC_iCMPi,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000460 opc, "\t$a, $b",
Evan Cheng83a32b42009-07-07 23:40:25 +0000461 [(opnode GPR:$a, so_imm:$b)]> {
Bob Wilsonce7c9eb2009-10-13 17:35:30 +0000462 let Inst{20} = 1;
Evan Cheng83a32b42009-07-07 23:40:25 +0000463 let Inst{25} = 1;
464 }
David Goodwin236ccb52009-08-19 18:00:44 +0000465 def rr : AI1<opcod, (outs), (ins GPR:$a, GPR:$b), DPFrm, IIC_iCMPr,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000466 opc, "\t$a, $b",
Evan Chengbdd679a2009-06-26 00:19:44 +0000467 [(opnode GPR:$a, GPR:$b)]> {
Johnny Chend139b942009-11-07 00:54:36 +0000468 let Inst{11-4} = 0b00000000;
Bob Wilsonce7c9eb2009-10-13 17:35:30 +0000469 let Inst{20} = 1;
Evan Cheng83a32b42009-07-07 23:40:25 +0000470 let Inst{25} = 0;
Evan Chengbdd679a2009-06-26 00:19:44 +0000471 let isCommutable = Commutable;
472 }
David Goodwin236ccb52009-08-19 18:00:44 +0000473 def rs : AI1<opcod, (outs), (ins GPR:$a, so_reg:$b), DPSoRegFrm, IIC_iCMPsr,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000474 opc, "\t$a, $b",
Evan Cheng83a32b42009-07-07 23:40:25 +0000475 [(opnode GPR:$a, so_reg:$b)]> {
Bob Wilsonce7c9eb2009-10-13 17:35:30 +0000476 let Inst{20} = 1;
Evan Cheng83a32b42009-07-07 23:40:25 +0000477 let Inst{25} = 0;
478 }
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000479}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480}
481
482/// AI_unary_rrot - A unary operation with two forms: one whose operand is a
483/// register and one whose operand is a register rotated by 8/16/24.
Evan Cheng37afa432008-11-06 22:15:19 +0000484/// FIXME: Remove the 'r' variant. Its rot_imm is zero.
485multiclass AI_unary_rrot<bits<8> opcod, string opc, PatFrag opnode> {
David Goodwin236ccb52009-08-19 18:00:44 +0000486 def r : AExtI<opcod, (outs GPR:$dst), (ins GPR:$src),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000487 IIC_iUNAr, opc, "\t$dst, $src",
David Goodwin236ccb52009-08-19 18:00:44 +0000488 [(set GPR:$dst, (opnode GPR:$src))]>,
Evan Cheng37afa432008-11-06 22:15:19 +0000489 Requires<[IsARM, HasV6]> {
Johnny Chen1bf79442009-10-27 18:44:24 +0000490 let Inst{11-10} = 0b00;
491 let Inst{19-16} = 0b1111;
492 }
David Goodwin236ccb52009-08-19 18:00:44 +0000493 def r_rot : AExtI<opcod, (outs GPR:$dst), (ins GPR:$src, i32imm:$rot),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000494 IIC_iUNAsi, opc, "\t$dst, $src, ror $rot",
David Goodwin236ccb52009-08-19 18:00:44 +0000495 [(set GPR:$dst, (opnode (rotr GPR:$src, rot_imm:$rot)))]>,
Evan Cheng37afa432008-11-06 22:15:19 +0000496 Requires<[IsARM, HasV6]> {
Johnny Chen1bf79442009-10-27 18:44:24 +0000497 let Inst{19-16} = 0b1111;
498 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499}
500
501/// AI_bin_rrot - A binary operation with two forms: one whose operand is a
502/// register and one whose operand is a register rotated by 8/16/24.
Evan Cheng37afa432008-11-06 22:15:19 +0000503multiclass AI_bin_rrot<bits<8> opcod, string opc, PatFrag opnode> {
504 def rr : AExtI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000505 IIC_iALUr, opc, "\t$dst, $LHS, $RHS",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
Johnny Chen1bf79442009-10-27 18:44:24 +0000507 Requires<[IsARM, HasV6]> {
508 let Inst{11-10} = 0b00;
509 }
Evan Cheng37afa432008-11-06 22:15:19 +0000510 def rr_rot : AExtI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000511 IIC_iALUsi, opc, "\t$dst, $LHS, $RHS, ror $rot",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512 [(set GPR:$dst, (opnode GPR:$LHS,
513 (rotr GPR:$RHS, rot_imm:$rot)))]>,
514 Requires<[IsARM, HasV6]>;
515}
516
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000517/// AI1_adde_sube_irs - Define instructions and patterns for adde and sube.
518let Uses = [CPSR] in {
Evan Chengbdd679a2009-06-26 00:19:44 +0000519multiclass AI1_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
520 bit Commutable = 0> {
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000521 def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000522 DPFrm, IIC_iALUi, opc, "\t$dst, $a, $b",
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000523 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>,
Evan Cheng83a32b42009-07-07 23:40:25 +0000524 Requires<[IsARM, CarryDefIsUnused]> {
525 let Inst{25} = 1;
526 }
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000527 def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000528 DPFrm, IIC_iALUr, opc, "\t$dst, $a, $b",
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000529 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>,
Evan Chengbdd679a2009-06-26 00:19:44 +0000530 Requires<[IsARM, CarryDefIsUnused]> {
531 let isCommutable = Commutable;
Johnny Chend139b942009-11-07 00:54:36 +0000532 let Inst{11-4} = 0b00000000;
Evan Cheng83a32b42009-07-07 23:40:25 +0000533 let Inst{25} = 0;
Evan Chengbdd679a2009-06-26 00:19:44 +0000534 }
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000535 def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000536 DPSoRegFrm, IIC_iALUsr, opc, "\t$dst, $a, $b",
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000537 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>,
Evan Cheng83a32b42009-07-07 23:40:25 +0000538 Requires<[IsARM, CarryDefIsUnused]> {
539 let Inst{25} = 0;
540 }
Jim Grosbache2fda532009-11-09 00:11:35 +0000541}
542// Carry setting variants
543let Defs = [CPSR] in {
544multiclass AI1_adde_sube_s_irs<bits<4> opcod, string opc, PatFrag opnode,
545 bit Commutable = 0> {
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000546 def Sri : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
Jim Grosbache2fda532009-11-09 00:11:35 +0000547 DPFrm, IIC_iALUi, !strconcat(opc, "\t$dst, $a, $b"),
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000548 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>,
549 Requires<[IsARM, CarryDefIsUsed]> {
Evan Cheng83a32b42009-07-07 23:40:25 +0000550 let Defs = [CPSR];
Bob Wilson3a308522009-10-26 22:34:44 +0000551 let Inst{20} = 1;
Evan Cheng83a32b42009-07-07 23:40:25 +0000552 let Inst{25} = 1;
Evan Chengbdd679a2009-06-26 00:19:44 +0000553 }
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000554 def Srr : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Jim Grosbache2fda532009-11-09 00:11:35 +0000555 DPFrm, IIC_iALUr, !strconcat(opc, "\t$dst, $a, $b"),
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000556 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>,
557 Requires<[IsARM, CarryDefIsUsed]> {
Evan Cheng83a32b42009-07-07 23:40:25 +0000558 let Defs = [CPSR];
Johnny Chend139b942009-11-07 00:54:36 +0000559 let Inst{11-4} = 0b00000000;
Bob Wilson3a308522009-10-26 22:34:44 +0000560 let Inst{20} = 1;
Evan Cheng83a32b42009-07-07 23:40:25 +0000561 let Inst{25} = 0;
Evan Chengbdd679a2009-06-26 00:19:44 +0000562 }
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000563 def Srs : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
Jim Grosbache2fda532009-11-09 00:11:35 +0000564 DPSoRegFrm, IIC_iALUsr, !strconcat(opc, "\t$dst, $a, $b"),
Evan Cheng9b4d26f2009-06-25 23:34:10 +0000565 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>,
566 Requires<[IsARM, CarryDefIsUsed]> {
Evan Cheng83a32b42009-07-07 23:40:25 +0000567 let Defs = [CPSR];
Bob Wilson3a308522009-10-26 22:34:44 +0000568 let Inst{20} = 1;
Evan Cheng83a32b42009-07-07 23:40:25 +0000569 let Inst{25} = 0;
Evan Chengbdd679a2009-06-26 00:19:44 +0000570 }
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000571}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572}
Jim Grosbache2fda532009-11-09 00:11:35 +0000573}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574
575//===----------------------------------------------------------------------===//
576// Instructions
577//===----------------------------------------------------------------------===//
578
579//===----------------------------------------------------------------------===//
580// Miscellaneous Instructions.
581//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582
583/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
584/// the function. The first operand is the ID# for this instruction, the second
585/// is the index into the MachineConstantPool that this is, the third is the
586/// size in bytes of this constant pool entry.
Evan Chengd97d7142009-06-12 20:46:18 +0000587let neverHasSideEffects = 1, isNotDuplicable = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588def CONSTPOOL_ENTRY :
Evan Chengb783fa32007-07-19 01:14:50 +0000589PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
David Goodwincfd67652009-08-06 16:52:47 +0000590 i32imm:$size), NoItinerary,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591 "${instid:label} ${cpidx:cpentry}", []>;
592
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000593let Defs = [SP], Uses = [SP] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000594def ADJCALLSTACKUP :
David Goodwincfd67652009-08-06 16:52:47 +0000595PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p), NoItinerary,
Bill Wendling22f8deb2007-11-13 00:44:25 +0000596 "@ ADJCALLSTACKUP $amt1",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000597 [(ARMcallseq_end timm:$amt1, timm:$amt2)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598
599def ADJCALLSTACKDOWN :
David Goodwincfd67652009-08-06 16:52:47 +0000600PseudoInst<(outs), (ins i32imm:$amt, pred:$p), NoItinerary,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 "@ ADJCALLSTACKDOWN $amt",
Chris Lattnerfe5d4022008-10-11 22:08:30 +0000602 [(ARMcallseq_start timm:$amt)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000603}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604
Evan Chengf8e8b622008-11-06 17:48:05 +0000605// Address computation and loads and stores in PIC mode.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000606let isNotDuplicable = 1 in {
Evan Cheng0d28b382008-10-31 19:11:09 +0000607def PICADD : AXI1<0b0100, (outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000608 Pseudo, IIC_iALUr, "\n$cp:\n\tadd$p\t$dst, pc, $a",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609 [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
610
Evan Cheng8610a3b2008-01-07 23:56:57 +0000611let AddedComplexity = 10 in {
Evan Chengbe998242008-11-06 08:47:38 +0000612def PICLDR : AXI2ldw<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000613 Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldr$p\t$dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614 [(set GPR:$dst, (load addrmodepc:$addr))]>;
615
Evan Chengbe998242008-11-06 08:47:38 +0000616def PICLDRH : AXI3ldh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Bob Wilson3bff42e2009-11-30 17:47:19 +0000617 Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldrh${p}\t$dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618 [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
619
Evan Chengbe998242008-11-06 08:47:38 +0000620def PICLDRB : AXI2ldb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Bob Wilson3bff42e2009-11-30 17:47:19 +0000621 Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldrb${p}\t$dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000622 [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
623
Evan Chengbe998242008-11-06 08:47:38 +0000624def PICLDRSH : AXI3ldsh<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Bob Wilson3bff42e2009-11-30 17:47:19 +0000625 Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldrsh${p}\t$dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000626 [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
627
Evan Chengbe998242008-11-06 08:47:38 +0000628def PICLDRSB : AXI3ldsb<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Bob Wilson3bff42e2009-11-30 17:47:19 +0000629 Pseudo, IIC_iLoadr, "\n${addr:label}:\n\tldrsb${p}\t$dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000630 [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
631}
Chris Lattnerf823faf2008-01-06 05:55:01 +0000632let AddedComplexity = 10 in {
Evan Chengbe998242008-11-06 08:47:38 +0000633def PICSTR : AXI2stw<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000634 Pseudo, IIC_iStorer, "\n${addr:label}:\n\tstr$p\t$src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000635 [(store GPR:$src, addrmodepc:$addr)]>;
636
Evan Chengbe998242008-11-06 08:47:38 +0000637def PICSTRH : AXI3sth<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
Bob Wilsonecce4b72009-11-18 18:10:35 +0000638 Pseudo, IIC_iStorer, "\n${addr:label}:\n\tstrh${p}\t$src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000639 [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
640
Evan Chengbe998242008-11-06 08:47:38 +0000641def PICSTRB : AXI2stb<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
Bob Wilsonecce4b72009-11-18 18:10:35 +0000642 Pseudo, IIC_iStorer, "\n${addr:label}:\n\tstrb${p}\t$src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643 [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
644}
Evan Chengf8e8b622008-11-06 17:48:05 +0000645} // isNotDuplicable = 1
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000646
Evan Chenga1366cd2009-06-23 05:25:29 +0000647
648// LEApcrel - Load a pc-relative address into a register without offending the
649// assembler.
David Goodwincfd67652009-08-06 16:52:47 +0000650def LEApcrel : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, pred:$p),
David Goodwin236ccb52009-08-19 18:00:44 +0000651 Pseudo, IIC_iALUi,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000652 !strconcat(!strconcat(".set ${:private}PCRELV${:uid}, ($label-(",
653 "${:private}PCRELL${:uid}+8))\n"),
654 !strconcat("${:private}PCRELL${:uid}:\n\t",
655 "add$p\t$dst, pc, #${:private}PCRELV${:uid}")),
Evan Chenga1366cd2009-06-23 05:25:29 +0000656 []>;
657
Evan Chengba83d7c2009-06-24 23:14:45 +0000658def LEApcrelJT : AXI1<0x0, (outs GPR:$dst),
Bob Wilson30ff4492009-08-21 21:58:55 +0000659 (ins i32imm:$label, nohash_imm:$id, pred:$p),
David Goodwin236ccb52009-08-19 18:00:44 +0000660 Pseudo, IIC_iALUi,
Evan Cheng9cf1e3e2009-07-22 22:03:29 +0000661 !strconcat(!strconcat(".set ${:private}PCRELV${:uid}, "
Anton Korobeynikove2be3382009-08-08 23:10:41 +0000662 "(${label}_${id}-(",
Evan Cheng9cf1e3e2009-07-22 22:03:29 +0000663 "${:private}PCRELL${:uid}+8))\n"),
664 !strconcat("${:private}PCRELL${:uid}:\n\t",
Evan Chengd3f9bc42009-10-26 23:45:59 +0000665 "add$p\t$dst, pc, #${:private}PCRELV${:uid}")),
Evan Cheng83a32b42009-07-07 23:40:25 +0000666 []> {
667 let Inst{25} = 1;
668}
Evan Chenga1366cd2009-06-23 05:25:29 +0000669
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670//===----------------------------------------------------------------------===//
671// Control Flow Instructions.
672//
673
Jim Grosbachc6f0c022009-09-30 01:35:11 +0000674let isReturn = 1, isTerminator = 1, isBarrier = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000675 def BX_RET : AI<(outs), (ins), BrMiscFrm, IIC_Br,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000676 "bx", "\tlr", [(ARMretflag)]> {
Johnny Chenff43a622009-11-16 23:57:56 +0000677 let Inst{3-0} = 0b1110;
Jim Grosbach88c246f2008-10-14 20:36:24 +0000678 let Inst{7-4} = 0b0001;
679 let Inst{19-8} = 0b111111111111;
680 let Inst{27-20} = 0b00010010;
Evan Cheng469bc762008-09-17 07:53:38 +0000681}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000682
Bob Wilsonf061fc82009-10-28 00:37:03 +0000683// Indirect branches
684let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Bob Wilsonea698652009-10-28 18:26:41 +0000685 def BRIND : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "bx\t$dst",
Bob Wilsonf061fc82009-10-28 00:37:03 +0000686 [(brind GPR:$dst)]> {
687 let Inst{7-4} = 0b0001;
688 let Inst{19-8} = 0b111111111111;
689 let Inst{27-20} = 0b00010010;
Johnny Chenff43a622009-11-16 23:57:56 +0000690 let Inst{31-28} = 0b1110;
Bob Wilsonf061fc82009-10-28 00:37:03 +0000691 }
692}
693
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694// FIXME: remove when we have a way to marking a MI with these properties.
Evan Chengf8e8b622008-11-06 17:48:05 +0000695// FIXME: Should pc be an implicit operand like PICADD, etc?
Evan Cheng7c8d5ea2009-10-01 08:22:27 +0000696let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
697 hasExtraDefRegAllocReq = 1 in
Evan Chengf8e8b622008-11-06 17:48:05 +0000698 def LDM_RET : AXI4ld<(outs),
Evan Chengb43a20e2009-10-01 01:33:39 +0000699 (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
Jim Grosbache2fda532009-11-09 00:11:35 +0000700 LdStMulFrm, IIC_Br, "ldm${addr:submode}${p}\t$addr, $wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000701 []>;
702
Bob Wilson243b37c2009-06-22 21:01:46 +0000703// On non-Darwin platforms R9 is callee-saved.
David Goodwin4b6e4982009-08-12 18:31:53 +0000704let isCall = 1,
Evan Cheng27396a62009-07-22 06:46:53 +0000705 Defs = [R0, R1, R2, R3, R12, LR,
706 D0, D1, D2, D3, D4, D5, D6, D7,
707 D16, D17, D18, D19, D20, D21, D22, D23,
David Goodwin3d88e912009-09-03 22:12:28 +0000708 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
Evan Chengf8e8b622008-11-06 17:48:05 +0000709 def BL : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000710 IIC_Br, "bl\t${func:call}",
Evan Cheng9e734482009-07-29 21:26:42 +0000711 [(ARMcall tglobaladdr:$func)]>,
Johnny Chen2b4d1db2009-10-27 20:45:15 +0000712 Requires<[IsARM, IsNotDarwin]> {
713 let Inst{31-28} = 0b1110;
714 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000715
Evan Chengf8e8b622008-11-06 17:48:05 +0000716 def BL_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000717 IIC_Br, "bl", "\t${func:call}",
Evan Cheng9e734482009-07-29 21:26:42 +0000718 [(ARMcall_pred tglobaladdr:$func)]>,
719 Requires<[IsARM, IsNotDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000720
721 // ARMv5T and above
Evan Chengf8e8b622008-11-06 17:48:05 +0000722 def BLX : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000723 IIC_Br, "blx\t$func",
Evan Cheng9e734482009-07-29 21:26:42 +0000724 [(ARMcall GPR:$func)]>,
725 Requires<[IsARM, HasV5T, IsNotDarwin]> {
Jim Grosbach88c246f2008-10-14 20:36:24 +0000726 let Inst{7-4} = 0b0011;
727 let Inst{19-8} = 0b111111111111;
728 let Inst{27-20} = 0b00010010;
Evan Cheng469bc762008-09-17 07:53:38 +0000729 }
730
Evan Chengfb1d1472009-07-14 01:49:27 +0000731 // ARMv4T
732 def BX : ABXIx2<(outs), (ins GPR:$func, variable_ops),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000733 IIC_Br, "mov\tlr, pc\n\tbx\t$func",
Evan Cheng9e734482009-07-29 21:26:42 +0000734 [(ARMcall_nolink GPR:$func)]>,
735 Requires<[IsARM, IsNotDarwin]> {
Evan Chengfb1d1472009-07-14 01:49:27 +0000736 let Inst{7-4} = 0b0001;
737 let Inst{19-8} = 0b111111111111;
738 let Inst{27-20} = 0b00010010;
Bob Wilson243b37c2009-06-22 21:01:46 +0000739 }
740}
741
742// On Darwin R9 is call-clobbered.
David Goodwin4b6e4982009-08-12 18:31:53 +0000743let isCall = 1,
Evan Cheng27396a62009-07-22 06:46:53 +0000744 Defs = [R0, R1, R2, R3, R9, R12, LR,
745 D0, D1, D2, D3, D4, D5, D6, D7,
746 D16, D17, D18, D19, D20, D21, D22, D23,
David Goodwin3d88e912009-09-03 22:12:28 +0000747 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] in {
Bob Wilson243b37c2009-06-22 21:01:46 +0000748 def BLr9 : ABXI<0b1011, (outs), (ins i32imm:$func, variable_ops),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000749 IIC_Br, "bl\t${func:call}",
Johnny Chen2b4d1db2009-10-27 20:45:15 +0000750 [(ARMcall tglobaladdr:$func)]>, Requires<[IsARM, IsDarwin]> {
751 let Inst{31-28} = 0b1110;
752 }
Bob Wilson243b37c2009-06-22 21:01:46 +0000753
754 def BLr9_pred : ABI<0b1011, (outs), (ins i32imm:$func, variable_ops),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000755 IIC_Br, "bl", "\t${func:call}",
Evan Cheng9e734482009-07-29 21:26:42 +0000756 [(ARMcall_pred tglobaladdr:$func)]>,
757 Requires<[IsARM, IsDarwin]>;
Bob Wilson243b37c2009-06-22 21:01:46 +0000758
759 // ARMv5T and above
760 def BLXr9 : AXI<(outs), (ins GPR:$func, variable_ops), BrMiscFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000761 IIC_Br, "blx\t$func",
Bob Wilson243b37c2009-06-22 21:01:46 +0000762 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T, IsDarwin]> {
763 let Inst{7-4} = 0b0011;
764 let Inst{19-8} = 0b111111111111;
765 let Inst{27-20} = 0b00010010;
766 }
767
Evan Chengfb1d1472009-07-14 01:49:27 +0000768 // ARMv4T
769 def BXr9 : ABXIx2<(outs), (ins GPR:$func, variable_ops),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000770 IIC_Br, "mov\tlr, pc\n\tbx\t$func",
Evan Chengfb1d1472009-07-14 01:49:27 +0000771 [(ARMcall_nolink GPR:$func)]>, Requires<[IsARM, IsDarwin]> {
772 let Inst{7-4} = 0b0001;
773 let Inst{19-8} = 0b111111111111;
774 let Inst{27-20} = 0b00010010;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000775 }
776}
777
David Goodwin4b6e4982009-08-12 18:31:53 +0000778let isBranch = 1, isTerminator = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779 // B is "predicable" since it can be xformed into a Bcc.
780 let isBarrier = 1 in {
781 let isPredicable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000782 def B : ABXI<0b1010, (outs), (ins brtarget:$target), IIC_Br,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000783 "b\t$target", [(br bb:$target)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000784
Owen Andersonf8053082007-11-12 07:39:39 +0000785 let isNotDuplicable = 1, isIndirectBranch = 1 in {
Evan Cheng0f63ae12008-11-07 09:06:08 +0000786 def BR_JTr : JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000787 IIC_Br, "mov\tpc, $target \n$jt",
Evan Cheng0f63ae12008-11-07 09:06:08 +0000788 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]> {
Johnny Chen6fdbe652009-12-14 21:51:34 +0000789 let Inst{11-4} = 0b00000000;
Johnny Chen3f647402009-11-17 17:17:50 +0000790 let Inst{15-12} = 0b1111;
Evan Cheng0f63ae12008-11-07 09:06:08 +0000791 let Inst{20} = 0; // S Bit
792 let Inst{24-21} = 0b1101;
Evan Chenge5f32ae2009-07-07 23:45:10 +0000793 let Inst{27-25} = 0b000;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794 }
Evan Cheng0f63ae12008-11-07 09:06:08 +0000795 def BR_JTm : JTI<(outs),
796 (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000797 IIC_Br, "ldr\tpc, $target \n$jt",
David Goodwincfd67652009-08-06 16:52:47 +0000798 [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
799 imm:$id)]> {
Johnny Chen3f647402009-11-17 17:17:50 +0000800 let Inst{15-12} = 0b1111;
Evan Cheng0f63ae12008-11-07 09:06:08 +0000801 let Inst{20} = 1; // L bit
802 let Inst{21} = 0; // W bit
803 let Inst{22} = 0; // B bit
804 let Inst{24} = 1; // P bit
Evan Chenge5f32ae2009-07-07 23:45:10 +0000805 let Inst{27-25} = 0b011;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000806 }
Evan Cheng0f63ae12008-11-07 09:06:08 +0000807 def BR_JTadd : JTI<(outs),
808 (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000809 IIC_Br, "add\tpc, $target, $idx \n$jt",
Evan Cheng0f63ae12008-11-07 09:06:08 +0000810 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
811 imm:$id)]> {
Johnny Chen3f647402009-11-17 17:17:50 +0000812 let Inst{15-12} = 0b1111;
Evan Cheng0f63ae12008-11-07 09:06:08 +0000813 let Inst{20} = 0; // S bit
814 let Inst{24-21} = 0b0100;
Evan Chenge5f32ae2009-07-07 23:45:10 +0000815 let Inst{27-25} = 0b000;
Evan Cheng0f63ae12008-11-07 09:06:08 +0000816 }
817 } // isNotDuplicable = 1, isIndirectBranch = 1
818 } // isBarrier = 1
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000819
820 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
821 // a two-value operand where a dag node expects two operands. :(
Evan Chengf8e8b622008-11-06 17:48:05 +0000822 def Bcc : ABI<0b1010, (outs), (ins brtarget:$target),
Evan Chengd3f9bc42009-10-26 23:45:59 +0000823 IIC_Br, "b", "\t$target",
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000824 [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000825}
826
827//===----------------------------------------------------------------------===//
828// Load / store Instructions.
829//
830
831// Load
Evan Cheng2f6bfd42009-11-20 19:57:15 +0000832let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in
David Goodwin236ccb52009-08-19 18:00:44 +0000833def LDR : AI2ldw<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm, IIC_iLoadr,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000834 "ldr", "\t$dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000835 [(set GPR:$dst, (load addrmode2:$addr))]>;
836
837// Special LDR for loads from non-pc-relative constpools.
Evan Cheng2f6bfd42009-11-20 19:57:15 +0000838let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1,
839 mayHaveSideEffects = 1 in
David Goodwin236ccb52009-08-19 18:00:44 +0000840def LDRcp : AI2ldw<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm, IIC_iLoadr,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000841 "ldr", "\t$dst, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842
843// Loads with zero extension
David Goodwin236ccb52009-08-19 18:00:44 +0000844def LDRH : AI3ldh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +0000845 IIC_iLoadr, "ldrh", "\t$dst, $addr",
David Goodwin236ccb52009-08-19 18:00:44 +0000846 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000847
David Goodwin236ccb52009-08-19 18:00:44 +0000848def LDRB : AI2ldb<(outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +0000849 IIC_iLoadr, "ldrb", "\t$dst, $addr",
David Goodwin236ccb52009-08-19 18:00:44 +0000850 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000851
852// Loads with sign extension
David Goodwin236ccb52009-08-19 18:00:44 +0000853def LDRSH : AI3ldsh<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +0000854 IIC_iLoadr, "ldrsh", "\t$dst, $addr",
David Goodwin236ccb52009-08-19 18:00:44 +0000855 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000856
David Goodwin236ccb52009-08-19 18:00:44 +0000857def LDRSB : AI3ldsb<(outs GPR:$dst), (ins addrmode3:$addr), LdMiscFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +0000858 IIC_iLoadr, "ldrsb", "\t$dst, $addr",
David Goodwin236ccb52009-08-19 18:00:44 +0000859 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000860
Evan Cheng7c8d5ea2009-10-01 08:22:27 +0000861let mayLoad = 1, hasExtraDefRegAllocReq = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000862// Load doubleword
Evan Cheng41169552009-06-15 08:28:29 +0000863def LDRD : AI3ldd<(outs GPR:$dst1, GPR:$dst2), (ins addrmode3:$addr), LdMiscFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +0000864 IIC_iLoadr, "ldrd", "\t$dst1, $addr",
Misha Brukman9daa0672009-08-27 14:14:21 +0000865 []>, Requires<[IsARM, HasV5TE]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000866
867// Indexed loads
Evan Chengbe998242008-11-06 08:47:38 +0000868def LDR_PRE : AI2ldwpr<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000869 (ins addrmode2:$addr), LdFrm, IIC_iLoadru,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000870 "ldr", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000871
Evan Chengbe998242008-11-06 08:47:38 +0000872def LDR_POST : AI2ldwpo<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000873 (ins GPR:$base, am2offset:$offset), LdFrm, IIC_iLoadru,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000874 "ldr", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000875
Evan Chengbe998242008-11-06 08:47:38 +0000876def LDRH_PRE : AI3ldhpr<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000877 (ins addrmode3:$addr), LdMiscFrm, IIC_iLoadru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000878 "ldrh", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879
Evan Chengbe998242008-11-06 08:47:38 +0000880def LDRH_POST : AI3ldhpo<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000881 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoadru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000882 "ldrh", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000883
Evan Chengbe998242008-11-06 08:47:38 +0000884def LDRB_PRE : AI2ldbpr<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000885 (ins addrmode2:$addr), LdFrm, IIC_iLoadru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000886 "ldrb", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000887
Evan Chengbe998242008-11-06 08:47:38 +0000888def LDRB_POST : AI2ldbpo<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000889 (ins GPR:$base,am2offset:$offset), LdFrm, IIC_iLoadru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000890 "ldrb", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000891
Evan Chengbe998242008-11-06 08:47:38 +0000892def LDRSH_PRE : AI3ldshpr<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000893 (ins addrmode3:$addr), LdMiscFrm, IIC_iLoadru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000894 "ldrsh", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000895
Evan Chengbe998242008-11-06 08:47:38 +0000896def LDRSH_POST: AI3ldshpo<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000897 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoadru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000898 "ldrsh", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000899
Evan Chengbe998242008-11-06 08:47:38 +0000900def LDRSB_PRE : AI3ldsbpr<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000901 (ins addrmode3:$addr), LdMiscFrm, IIC_iLoadru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000902 "ldrsb", "\t$dst, $addr!", "$addr.base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000903
Evan Chengbe998242008-11-06 08:47:38 +0000904def LDRSB_POST: AI3ldsbpo<(outs GPR:$dst, GPR:$base_wb),
David Goodwin236ccb52009-08-19 18:00:44 +0000905 (ins GPR:$base,am3offset:$offset), LdMiscFrm, IIC_iLoadru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000906 "ldrsb", "\t$dst, [$base], $offset", "$base = $base_wb", []>;
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000907}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000908
909// Store
David Goodwin236ccb52009-08-19 18:00:44 +0000910def STR : AI2stw<(outs), (ins GPR:$src, addrmode2:$addr), StFrm, IIC_iStorer,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000911 "str", "\t$src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000912 [(store GPR:$src, addrmode2:$addr)]>;
913
914// Stores with truncate
David Goodwin236ccb52009-08-19 18:00:44 +0000915def STRH : AI3sth<(outs), (ins GPR:$src, addrmode3:$addr), StMiscFrm, IIC_iStorer,
Jim Grosbache2fda532009-11-09 00:11:35 +0000916 "strh", "\t$src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000917 [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
918
David Goodwin236ccb52009-08-19 18:00:44 +0000919def STRB : AI2stb<(outs), (ins GPR:$src, addrmode2:$addr), StFrm, IIC_iStorer,
Jim Grosbache2fda532009-11-09 00:11:35 +0000920 "strb", "\t$src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000921 [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
922
923// Store doubleword
Evan Cheng7c8d5ea2009-10-01 08:22:27 +0000924let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000925def STRD : AI3std<(outs), (ins GPR:$src1, GPR:$src2, addrmode3:$addr),
David Goodwin236ccb52009-08-19 18:00:44 +0000926 StMiscFrm, IIC_iStorer,
Jim Grosbache2fda532009-11-09 00:11:35 +0000927 "strd", "\t$src1, $addr", []>, Requires<[IsARM, HasV5TE]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000928
929// Indexed stores
Evan Chengbe998242008-11-06 08:47:38 +0000930def STR_PRE : AI2stwpr<(outs GPR:$base_wb),
David Goodwincfd67652009-08-06 16:52:47 +0000931 (ins GPR:$src, GPR:$base, am2offset:$offset),
David Goodwin236ccb52009-08-19 18:00:44 +0000932 StFrm, IIC_iStoreru,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000933 "str", "\t$src, [$base, $offset]!", "$base = $base_wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000934 [(set GPR:$base_wb,
935 (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
936
Evan Chengbe998242008-11-06 08:47:38 +0000937def STR_POST : AI2stwpo<(outs GPR:$base_wb),
David Goodwincfd67652009-08-06 16:52:47 +0000938 (ins GPR:$src, GPR:$base,am2offset:$offset),
David Goodwin236ccb52009-08-19 18:00:44 +0000939 StFrm, IIC_iStoreru,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000940 "str", "\t$src, [$base], $offset", "$base = $base_wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000941 [(set GPR:$base_wb,
942 (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
943
Evan Chengbe998242008-11-06 08:47:38 +0000944def STRH_PRE : AI3sthpr<(outs GPR:$base_wb),
David Goodwincfd67652009-08-06 16:52:47 +0000945 (ins GPR:$src, GPR:$base,am3offset:$offset),
David Goodwin236ccb52009-08-19 18:00:44 +0000946 StMiscFrm, IIC_iStoreru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000947 "strh", "\t$src, [$base, $offset]!", "$base = $base_wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000948 [(set GPR:$base_wb,
949 (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
950
Evan Chengbe998242008-11-06 08:47:38 +0000951def STRH_POST: AI3sthpo<(outs GPR:$base_wb),
David Goodwincfd67652009-08-06 16:52:47 +0000952 (ins GPR:$src, GPR:$base,am3offset:$offset),
David Goodwin236ccb52009-08-19 18:00:44 +0000953 StMiscFrm, IIC_iStoreru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000954 "strh", "\t$src, [$base], $offset", "$base = $base_wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000955 [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
956 GPR:$base, am3offset:$offset))]>;
957
Evan Chengbe998242008-11-06 08:47:38 +0000958def STRB_PRE : AI2stbpr<(outs GPR:$base_wb),
David Goodwincfd67652009-08-06 16:52:47 +0000959 (ins GPR:$src, GPR:$base,am2offset:$offset),
David Goodwin236ccb52009-08-19 18:00:44 +0000960 StFrm, IIC_iStoreru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000961 "strb", "\t$src, [$base, $offset]!", "$base = $base_wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000962 [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
963 GPR:$base, am2offset:$offset))]>;
964
Evan Chengbe998242008-11-06 08:47:38 +0000965def STRB_POST: AI2stbpo<(outs GPR:$base_wb),
David Goodwincfd67652009-08-06 16:52:47 +0000966 (ins GPR:$src, GPR:$base,am2offset:$offset),
David Goodwin236ccb52009-08-19 18:00:44 +0000967 StFrm, IIC_iStoreru,
Jim Grosbache2fda532009-11-09 00:11:35 +0000968 "strb", "\t$src, [$base], $offset", "$base = $base_wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000969 [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
970 GPR:$base, am2offset:$offset))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000971
972//===----------------------------------------------------------------------===//
973// Load / store multiple Instructions.
974//
975
Evan Cheng7c8d5ea2009-10-01 08:22:27 +0000976let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Evan Chengbe998242008-11-06 08:47:38 +0000977def LDM : AXI4ld<(outs),
Evan Chengb43a20e2009-10-01 01:33:39 +0000978 (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
Jim Grosbache2fda532009-11-09 00:11:35 +0000979 LdStMulFrm, IIC_iLoadm, "ldm${addr:submode}${p}\t$addr, $wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000980 []>;
981
Evan Cheng7c8d5ea2009-10-01 08:22:27 +0000982let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
Evan Chengbe998242008-11-06 08:47:38 +0000983def STM : AXI4st<(outs),
Evan Chengb43a20e2009-10-01 01:33:39 +0000984 (ins addrmode4:$addr, pred:$p, reglist:$wb, variable_ops),
Jim Grosbache2fda532009-11-09 00:11:35 +0000985 LdStMulFrm, IIC_iStorem, "stm${addr:submode}${p}\t$addr, $wb",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000986 []>;
987
988//===----------------------------------------------------------------------===//
989// Move Instructions.
990//
991
Evan Chengd97d7142009-06-12 20:46:18 +0000992let neverHasSideEffects = 1 in
David Goodwin236ccb52009-08-19 18:00:44 +0000993def MOVr : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), DPFrm, IIC_iMOVr,
Evan Chengd3f9bc42009-10-26 23:45:59 +0000994 "mov", "\t$dst, $src", []>, UnaryDP {
Johnny Chend139b942009-11-07 00:54:36 +0000995 let Inst{11-4} = 0b00000000;
Bob Wilsoncfb46c52009-10-14 19:00:24 +0000996 let Inst{25} = 0;
997}
998
David Goodwincfd67652009-08-06 16:52:47 +0000999def MOVs : AsI1<0b1101, (outs GPR:$dst), (ins so_reg:$src),
Anton Korobeynikov60928952009-09-27 23:52:58 +00001000 DPSoRegFrm, IIC_iMOVsr,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001001 "mov", "\t$dst, $src", [(set GPR:$dst, so_reg:$src)]>, UnaryDP {
Bob Wilsoncfb46c52009-10-14 19:00:24 +00001002 let Inst{25} = 0;
1003}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001004
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001005let isReMaterializable = 1, isAsCheapAsAMove = 1 in
David Goodwin236ccb52009-08-19 18:00:44 +00001006def MOVi : AsI1<0b1101, (outs GPR:$dst), (ins so_imm:$src), DPFrm, IIC_iMOVi,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001007 "mov", "\t$dst, $src", [(set GPR:$dst, so_imm:$src)]>, UnaryDP {
Anton Korobeynikov60928952009-09-27 23:52:58 +00001008 let Inst{25} = 1;
1009}
1010
1011let isReMaterializable = 1, isAsCheapAsAMove = 1 in
1012def MOVi16 : AI1<0b1000, (outs GPR:$dst), (ins i32imm:$src),
1013 DPFrm, IIC_iMOVi,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001014 "movw", "\t$dst, $src",
Anton Korobeynikov60928952009-09-27 23:52:58 +00001015 [(set GPR:$dst, imm0_65535:$src)]>,
1016 Requires<[IsARM, HasV6T2]> {
Bob Wilsonce7c9eb2009-10-13 17:35:30 +00001017 let Inst{20} = 0;
Anton Korobeynikov60928952009-09-27 23:52:58 +00001018 let Inst{25} = 1;
1019}
1020
Evan Cheng16c012d2009-09-28 09:14:39 +00001021let Constraints = "$src = $dst" in
Anton Korobeynikov60928952009-09-27 23:52:58 +00001022def MOVTi16 : AI1<0b1010, (outs GPR:$dst), (ins GPR:$src, i32imm:$imm),
1023 DPFrm, IIC_iMOVi,
Anton Korobeynikova414f362009-11-24 00:44:37 +00001024 "movt", "\t$dst, $imm",
Anton Korobeynikov60928952009-09-27 23:52:58 +00001025 [(set GPR:$dst,
1026 (or (and GPR:$src, 0xffff),
1027 lo16AllZero:$imm))]>, UnaryDP,
1028 Requires<[IsARM, HasV6T2]> {
Bob Wilsonce7c9eb2009-10-13 17:35:30 +00001029 let Inst{20} = 0;
Anton Korobeynikov60928952009-09-27 23:52:58 +00001030 let Inst{25} = 1;
Evan Chenga9892932009-09-09 01:47:07 +00001031}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001032
Evan Cheng89ef2852009-10-21 08:15:52 +00001033def : ARMPat<(or GPR:$src, 0xffff0000), (MOVTi16 GPR:$src, 0xffff)>,
1034 Requires<[IsARM, HasV6T2]>;
1035
David Goodwin02b0e352009-09-01 18:32:09 +00001036let Uses = [CPSR] in
David Goodwin236ccb52009-08-19 18:00:44 +00001037def MOVrx : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo, IIC_iMOVsi,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001038 "mov", "\t$dst, $src, rrx",
Evan Cheng86a926a2008-11-05 18:35:52 +00001039 [(set GPR:$dst, (ARMrrx GPR:$src))]>, UnaryDP;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001040
1041// These aren't really mov instructions, but we have to define them this way
1042// due to flag operands.
1043
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001044let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +00001045def MOVsrl_flag : AI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
Jim Grosbache2fda532009-11-09 00:11:35 +00001046 IIC_iMOVsi, "movs", "\t$dst, $src, lsr #1",
Evan Cheng86a926a2008-11-05 18:35:52 +00001047 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, UnaryDP;
Evan Cheng7f240d22008-11-14 20:09:11 +00001048def MOVsra_flag : AI1<0b1101, (outs GPR:$dst), (ins GPR:$src), Pseudo,
Jim Grosbache2fda532009-11-09 00:11:35 +00001049 IIC_iMOVsi, "movs", "\t$dst, $src, asr #1",
Evan Cheng86a926a2008-11-05 18:35:52 +00001050 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, UnaryDP;
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001051}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001052
1053//===----------------------------------------------------------------------===//
1054// Extend Instructions.
1055//
1056
1057// Sign extenders
1058
Evan Cheng37afa432008-11-06 22:15:19 +00001059defm SXTB : AI_unary_rrot<0b01101010,
1060 "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
1061defm SXTH : AI_unary_rrot<0b01101011,
1062 "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063
Evan Cheng37afa432008-11-06 22:15:19 +00001064defm SXTAB : AI_bin_rrot<0b01101010,
1065 "sxtab", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
1066defm SXTAH : AI_bin_rrot<0b01101011,
1067 "sxtah", BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001068
1069// TODO: SXT(A){B|H}16
1070
1071// Zero extenders
1072
1073let AddedComplexity = 16 in {
Evan Cheng37afa432008-11-06 22:15:19 +00001074defm UXTB : AI_unary_rrot<0b01101110,
1075 "uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
1076defm UXTH : AI_unary_rrot<0b01101111,
1077 "uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1078defm UXTB16 : AI_unary_rrot<0b01101100,
1079 "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080
Bob Wilson74590a02009-06-22 22:08:29 +00001081def : ARMV6Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001082 (UXTB16r_rot GPR:$Src, 24)>;
Bob Wilson74590a02009-06-22 22:08:29 +00001083def : ARMV6Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084 (UXTB16r_rot GPR:$Src, 8)>;
1085
Evan Cheng37afa432008-11-06 22:15:19 +00001086defm UXTAB : AI_bin_rrot<0b01101110, "uxtab",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001087 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Evan Cheng37afa432008-11-06 22:15:19 +00001088defm UXTAH : AI_bin_rrot<0b01101111, "uxtah",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001089 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1090}
1091
1092// This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
1093//defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
1094
1095// TODO: UXT(A){B|H}16
1096
Sandeep Patelbb4648a2009-10-13 18:59:48 +00001097def SBFX : I<(outs GPR:$dst),
1098 (ins GPR:$src, imm0_31:$lsb, imm0_31:$width),
1099 AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iALUi,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001100 "sbfx", "\t$dst, $src, $lsb, $width", "", []>,
Sandeep Patelbb4648a2009-10-13 18:59:48 +00001101 Requires<[IsARM, HasV6T2]> {
1102 let Inst{27-21} = 0b0111101;
1103 let Inst{6-4} = 0b101;
1104}
1105
1106def UBFX : I<(outs GPR:$dst),
1107 (ins GPR:$src, imm0_31:$lsb, imm0_31:$width),
1108 AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iALUi,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001109 "ubfx", "\t$dst, $src, $lsb, $width", "", []>,
Sandeep Patelbb4648a2009-10-13 18:59:48 +00001110 Requires<[IsARM, HasV6T2]> {
1111 let Inst{27-21} = 0b0111111;
1112 let Inst{6-4} = 0b101;
1113}
1114
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001115//===----------------------------------------------------------------------===//
1116// Arithmetic Instructions.
1117//
1118
Jim Grosbach88c246f2008-10-14 20:36:24 +00001119defm ADD : AsI1_bin_irs<0b0100, "add",
Evan Chengbdd679a2009-06-26 00:19:44 +00001120 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
Jim Grosbach88c246f2008-10-14 20:36:24 +00001121defm SUB : AsI1_bin_irs<0b0010, "sub",
Evan Cheng469bc762008-09-17 07:53:38 +00001122 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001123
1124// ADD and SUB with 's' bit set.
Jim Grosbache2fda532009-11-09 00:11:35 +00001125defm ADDS : AI1_bin_s_irs<0b0100, "adds",
1126 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1127defm SUBS : AI1_bin_s_irs<0b0010, "subs",
Evan Chengd4e2f052009-06-25 20:59:23 +00001128 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001129
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001130defm ADC : AI1_adde_sube_irs<0b0101, "adc",
Evan Chengbdd679a2009-06-26 00:19:44 +00001131 BinOpFrag<(adde node:$LHS, node:$RHS)>, 1>;
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001132defm SBC : AI1_adde_sube_irs<0b0110, "sbc",
1133 BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Jim Grosbache2fda532009-11-09 00:11:35 +00001134defm ADCS : AI1_adde_sube_s_irs<0b0101, "adcs",
1135 BinOpFrag<(adde node:$LHS, node:$RHS)>, 1>;
1136defm SBCS : AI1_adde_sube_s_irs<0b0110, "sbcs",
1137 BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001138
1139// These don't define reg/reg forms, because they are handled above.
Evan Cheng86a926a2008-11-05 18:35:52 +00001140def RSBri : AsI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001141 IIC_iALUi, "rsb", "\t$dst, $a, $b",
Evan Chenga9892932009-09-09 01:47:07 +00001142 [(set GPR:$dst, (sub so_imm:$b, GPR:$a))]> {
1143 let Inst{25} = 1;
1144}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001145
Evan Cheng86a926a2008-11-05 18:35:52 +00001146def RSBrs : AsI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001147 IIC_iALUsr, "rsb", "\t$dst, $a, $b",
Bob Wilson3a308522009-10-26 22:34:44 +00001148 [(set GPR:$dst, (sub so_reg:$b, GPR:$a))]> {
Bob Wilson3a308522009-10-26 22:34:44 +00001149 let Inst{25} = 0;
1150}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001151
1152// RSB with 's' bit set.
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001153let Defs = [CPSR] in {
Evan Cheng86a926a2008-11-05 18:35:52 +00001154def RSBSri : AI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +00001155 IIC_iALUi, "rsbs", "\t$dst, $a, $b",
Evan Chenga9892932009-09-09 01:47:07 +00001156 [(set GPR:$dst, (subc so_imm:$b, GPR:$a))]> {
Bob Wilson3a308522009-10-26 22:34:44 +00001157 let Inst{20} = 1;
Evan Chenga9892932009-09-09 01:47:07 +00001158 let Inst{25} = 1;
1159}
Evan Cheng86a926a2008-11-05 18:35:52 +00001160def RSBSrs : AI1<0b0011, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
Jim Grosbache2fda532009-11-09 00:11:35 +00001161 IIC_iALUsr, "rsbs", "\t$dst, $a, $b",
Bob Wilson3a308522009-10-26 22:34:44 +00001162 [(set GPR:$dst, (subc so_reg:$b, GPR:$a))]> {
Bob Wilson3a308522009-10-26 22:34:44 +00001163 let Inst{20} = 1;
1164 let Inst{25} = 0;
1165}
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001166}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001167
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001168let Uses = [CPSR] in {
1169def RSCri : AsI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001170 DPFrm, IIC_iALUi, "rsc", "\t$dst, $a, $b",
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001171 [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>,
Evan Chenga9892932009-09-09 01:47:07 +00001172 Requires<[IsARM, CarryDefIsUnused]> {
1173 let Inst{25} = 1;
1174}
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001175def RSCrs : AsI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001176 DPSoRegFrm, IIC_iALUsr, "rsc", "\t$dst, $a, $b",
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001177 [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>,
Bob Wilson2aec46e2009-10-26 22:59:12 +00001178 Requires<[IsARM, CarryDefIsUnused]> {
Bob Wilson2aec46e2009-10-26 22:59:12 +00001179 let Inst{25} = 0;
1180}
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001181}
1182
1183// FIXME: Allow these to be predicated.
Evan Chengd4e2f052009-06-25 20:59:23 +00001184let Defs = [CPSR], Uses = [CPSR] in {
1185def RSCSri : AXI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_imm:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001186 DPFrm, IIC_iALUi, "rscs\t$dst, $a, $b",
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001187 [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>,
Evan Chenga9892932009-09-09 01:47:07 +00001188 Requires<[IsARM, CarryDefIsUnused]> {
Bob Wilson2aec46e2009-10-26 22:59:12 +00001189 let Inst{20} = 1;
Evan Chenga9892932009-09-09 01:47:07 +00001190 let Inst{25} = 1;
1191}
Evan Chengd4e2f052009-06-25 20:59:23 +00001192def RSCSrs : AXI1<0b0111, (outs GPR:$dst), (ins GPR:$a, so_reg:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001193 DPSoRegFrm, IIC_iALUsr, "rscs\t$dst, $a, $b",
Evan Cheng9b4d26f2009-06-25 23:34:10 +00001194 [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>,
Bob Wilson2aec46e2009-10-26 22:59:12 +00001195 Requires<[IsARM, CarryDefIsUnused]> {
Bob Wilson2aec46e2009-10-26 22:59:12 +00001196 let Inst{20} = 1;
1197 let Inst{25} = 0;
1198}
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001199}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001200
1201// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
1202def : ARMPat<(add GPR:$src, so_imm_neg:$imm),
1203 (SUBri GPR:$src, so_imm_neg:$imm)>;
1204
1205//def : ARMPat<(addc GPR:$src, so_imm_neg:$imm),
1206// (SUBSri GPR:$src, so_imm_neg:$imm)>;
1207//def : ARMPat<(adde GPR:$src, so_imm_neg:$imm),
1208// (SBCri GPR:$src, so_imm_neg:$imm)>;
1209
1210// Note: These are implemented in C++ code, because they have to generate
1211// ADD/SUBrs instructions, which use a complex pattern that a xform function
1212// cannot produce.
1213// (mul X, 2^n+1) -> (add (X << n), X)
1214// (mul X, 2^n-1) -> (rsb X, (X << n))
1215
1216
1217//===----------------------------------------------------------------------===//
1218// Bitwise Instructions.
1219//
1220
Jim Grosbach88c246f2008-10-14 20:36:24 +00001221defm AND : AsI1_bin_irs<0b0000, "and",
Evan Chengbdd679a2009-06-26 00:19:44 +00001222 BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
Jim Grosbach88c246f2008-10-14 20:36:24 +00001223defm ORR : AsI1_bin_irs<0b1100, "orr",
Evan Chengbdd679a2009-06-26 00:19:44 +00001224 BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
Jim Grosbach88c246f2008-10-14 20:36:24 +00001225defm EOR : AsI1_bin_irs<0b0001, "eor",
Evan Chengbdd679a2009-06-26 00:19:44 +00001226 BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Jim Grosbach88c246f2008-10-14 20:36:24 +00001227defm BIC : AsI1_bin_irs<0b1110, "bic",
Evan Cheng469bc762008-09-17 07:53:38 +00001228 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001229
Evan Cheng299ee652009-07-06 22:23:46 +00001230def BFC : I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm),
David Goodwin9a8ec822009-11-02 17:28:36 +00001231 AddrMode1, Size4Bytes, IndexModeNone, DPFrm, IIC_iUNAsi,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001232 "bfc", "\t$dst, $imm", "$src = $dst",
Evan Cheng299ee652009-07-06 22:23:46 +00001233 [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>,
1234 Requires<[IsARM, HasV6T2]> {
1235 let Inst{27-21} = 0b0111110;
1236 let Inst{6-0} = 0b0011111;
1237}
1238
David Goodwin236ccb52009-08-19 18:00:44 +00001239def MVNr : AsI1<0b1111, (outs GPR:$dst), (ins GPR:$src), DPFrm, IIC_iMOVr,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001240 "mvn", "\t$dst, $src",
Bob Wilsoncfb46c52009-10-14 19:00:24 +00001241 [(set GPR:$dst, (not GPR:$src))]>, UnaryDP {
Johnny Chend139b942009-11-07 00:54:36 +00001242 let Inst{11-4} = 0b00000000;
Bob Wilsoncfb46c52009-10-14 19:00:24 +00001243}
Evan Cheng86a926a2008-11-05 18:35:52 +00001244def MVNs : AsI1<0b1111, (outs GPR:$dst), (ins so_reg:$src), DPSoRegFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001245 IIC_iMOVsr, "mvn", "\t$dst, $src",
Johnny Chend139b942009-11-07 00:54:36 +00001246 [(set GPR:$dst, (not so_reg:$src))]>, UnaryDP;
Evan Chengbd0ca9c2009-02-05 08:42:55 +00001247let isReMaterializable = 1, isAsCheapAsAMove = 1 in
David Goodwin236ccb52009-08-19 18:00:44 +00001248def MVNi : AsI1<0b1111, (outs GPR:$dst), (ins so_imm:$imm), DPFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001249 IIC_iMOVi, "mvn", "\t$dst, $imm",
Evan Chenga9892932009-09-09 01:47:07 +00001250 [(set GPR:$dst, so_imm_not:$imm)]>,UnaryDP {
1251 let Inst{25} = 1;
1252}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001253
1254def : ARMPat<(and GPR:$src, so_imm_not:$imm),
1255 (BICri GPR:$src, so_imm_not:$imm)>;
1256
1257//===----------------------------------------------------------------------===//
1258// Multiply Instructions.
1259//
1260
Evan Chengbdd679a2009-06-26 00:19:44 +00001261let isCommutable = 1 in
David Goodwin236ccb52009-08-19 18:00:44 +00001262def MUL : AsMul1I<0b0000000, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001263 IIC_iMUL32, "mul", "\t$dst, $a, $b",
Evan Chengf8e8b622008-11-06 17:48:05 +00001264 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001265
Evan Chengee80fb72008-11-06 01:21:28 +00001266def MLA : AsMul1I<0b0000001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001267 IIC_iMAC32, "mla", "\t$dst, $a, $b, $c",
Evan Chengf8e8b622008-11-06 17:48:05 +00001268 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001269
David Goodwincfd67652009-08-06 16:52:47 +00001270def MLS : AMul1I<0b0000011, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001271 IIC_iMAC32, "mls", "\t$dst, $a, $b, $c",
Evan Chengc8147e12009-07-06 22:05:45 +00001272 [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>,
1273 Requires<[IsARM, HasV6T2]>;
1274
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001275// Extra precision multiplies with low / high results
Evan Chengd97d7142009-06-12 20:46:18 +00001276let neverHasSideEffects = 1 in {
Evan Chengbdd679a2009-06-26 00:19:44 +00001277let isCommutable = 1 in {
Evan Chengee80fb72008-11-06 01:21:28 +00001278def SMULL : AsMul1I<0b0000110, (outs GPR:$ldst, GPR:$hdst),
David Goodwin236ccb52009-08-19 18:00:44 +00001279 (ins GPR:$a, GPR:$b), IIC_iMUL64,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001280 "smull", "\t$ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001281
Evan Chengee80fb72008-11-06 01:21:28 +00001282def UMULL : AsMul1I<0b0000100, (outs GPR:$ldst, GPR:$hdst),
David Goodwin236ccb52009-08-19 18:00:44 +00001283 (ins GPR:$a, GPR:$b), IIC_iMUL64,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001284 "umull", "\t$ldst, $hdst, $a, $b", []>;
Evan Chengbdd679a2009-06-26 00:19:44 +00001285}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001286
1287// Multiply + accumulate
Evan Chengee80fb72008-11-06 01:21:28 +00001288def SMLAL : AsMul1I<0b0000111, (outs GPR:$ldst, GPR:$hdst),
David Goodwin236ccb52009-08-19 18:00:44 +00001289 (ins GPR:$a, GPR:$b), IIC_iMAC64,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001290 "smlal", "\t$ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001291
Evan Chengee80fb72008-11-06 01:21:28 +00001292def UMLAL : AsMul1I<0b0000101, (outs GPR:$ldst, GPR:$hdst),
David Goodwin236ccb52009-08-19 18:00:44 +00001293 (ins GPR:$a, GPR:$b), IIC_iMAC64,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001294 "umlal", "\t$ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001295
Evan Chengee80fb72008-11-06 01:21:28 +00001296def UMAAL : AMul1I <0b0000010, (outs GPR:$ldst, GPR:$hdst),
David Goodwin236ccb52009-08-19 18:00:44 +00001297 (ins GPR:$a, GPR:$b), IIC_iMAC64,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001298 "umaal", "\t$ldst, $hdst, $a, $b", []>,
Evan Chengee80fb72008-11-06 01:21:28 +00001299 Requires<[IsARM, HasV6]>;
Evan Chengd97d7142009-06-12 20:46:18 +00001300} // neverHasSideEffects
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001301
1302// Most significant word multiply
Evan Chengee80fb72008-11-06 01:21:28 +00001303def SMMUL : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001304 IIC_iMUL32, "smmul", "\t$dst, $a, $b",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001305 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>,
Evan Chengee80fb72008-11-06 01:21:28 +00001306 Requires<[IsARM, HasV6]> {
1307 let Inst{7-4} = 0b0001;
1308 let Inst{15-12} = 0b1111;
1309}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001310
Evan Chengee80fb72008-11-06 01:21:28 +00001311def SMMLA : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001312 IIC_iMAC32, "smmla", "\t$dst, $a, $b, $c",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001313 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>,
Evan Chengee80fb72008-11-06 01:21:28 +00001314 Requires<[IsARM, HasV6]> {
1315 let Inst{7-4} = 0b0001;
1316}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001317
1318
Evan Chengee80fb72008-11-06 01:21:28 +00001319def SMMLS : AMul2I <0b0111010, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001320 IIC_iMAC32, "smmls", "\t$dst, $a, $b, $c",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001321 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
Evan Chengee80fb72008-11-06 01:21:28 +00001322 Requires<[IsARM, HasV6]> {
1323 let Inst{7-4} = 0b1101;
1324}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001325
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001326multiclass AI_smul<string opc, PatFrag opnode> {
Evan Cheng38396be2008-11-06 03:35:07 +00001327 def BB : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001328 IIC_iMUL32, !strconcat(opc, "bb"), "\t$dst, $a, $b",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001329 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1330 (sext_inreg GPR:$b, i16)))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001331 Requires<[IsARM, HasV5TE]> {
1332 let Inst{5} = 0;
1333 let Inst{6} = 0;
1334 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001335
Evan Cheng38396be2008-11-06 03:35:07 +00001336 def BT : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001337 IIC_iMUL32, !strconcat(opc, "bt"), "\t$dst, $a, $b",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001338 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
Bob Wilson74590a02009-06-22 22:08:29 +00001339 (sra GPR:$b, (i32 16))))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001340 Requires<[IsARM, HasV5TE]> {
1341 let Inst{5} = 0;
1342 let Inst{6} = 1;
1343 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001344
Evan Cheng38396be2008-11-06 03:35:07 +00001345 def TB : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001346 IIC_iMUL32, !strconcat(opc, "tb"), "\t$dst, $a, $b",
Bob Wilson74590a02009-06-22 22:08:29 +00001347 [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001348 (sext_inreg GPR:$b, i16)))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001349 Requires<[IsARM, HasV5TE]> {
1350 let Inst{5} = 1;
1351 let Inst{6} = 0;
1352 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001353
Evan Cheng38396be2008-11-06 03:35:07 +00001354 def TT : AMulxyI<0b0001011, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001355 IIC_iMUL32, !strconcat(opc, "tt"), "\t$dst, $a, $b",
Bob Wilson74590a02009-06-22 22:08:29 +00001356 [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
1357 (sra GPR:$b, (i32 16))))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001358 Requires<[IsARM, HasV5TE]> {
1359 let Inst{5} = 1;
1360 let Inst{6} = 1;
1361 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001362
Evan Cheng38396be2008-11-06 03:35:07 +00001363 def WB : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001364 IIC_iMUL16, !strconcat(opc, "wb"), "\t$dst, $a, $b",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001365 [(set GPR:$dst, (sra (opnode GPR:$a,
Bob Wilson74590a02009-06-22 22:08:29 +00001366 (sext_inreg GPR:$b, i16)), (i32 16)))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001367 Requires<[IsARM, HasV5TE]> {
1368 let Inst{5} = 1;
1369 let Inst{6} = 0;
1370 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001371
Evan Cheng38396be2008-11-06 03:35:07 +00001372 def WT : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001373 IIC_iMUL16, !strconcat(opc, "wt"), "\t$dst, $a, $b",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001374 [(set GPR:$dst, (sra (opnode GPR:$a,
Bob Wilson74590a02009-06-22 22:08:29 +00001375 (sra GPR:$b, (i32 16))), (i32 16)))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001376 Requires<[IsARM, HasV5TE]> {
1377 let Inst{5} = 1;
1378 let Inst{6} = 1;
1379 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001380}
1381
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001382
1383multiclass AI_smla<string opc, PatFrag opnode> {
Evan Cheng38396be2008-11-06 03:35:07 +00001384 def BB : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001385 IIC_iMAC16, !strconcat(opc, "bb"), "\t$dst, $a, $b, $acc",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001386 [(set GPR:$dst, (add GPR:$acc,
1387 (opnode (sext_inreg GPR:$a, i16),
1388 (sext_inreg GPR:$b, i16))))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001389 Requires<[IsARM, HasV5TE]> {
1390 let Inst{5} = 0;
1391 let Inst{6} = 0;
1392 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001393
Evan Cheng38396be2008-11-06 03:35:07 +00001394 def BT : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001395 IIC_iMAC16, !strconcat(opc, "bt"), "\t$dst, $a, $b, $acc",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001396 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
Bob Wilson74590a02009-06-22 22:08:29 +00001397 (sra GPR:$b, (i32 16)))))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001398 Requires<[IsARM, HasV5TE]> {
1399 let Inst{5} = 0;
1400 let Inst{6} = 1;
1401 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001402
Evan Cheng38396be2008-11-06 03:35:07 +00001403 def TB : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001404 IIC_iMAC16, !strconcat(opc, "tb"), "\t$dst, $a, $b, $acc",
Bob Wilson74590a02009-06-22 22:08:29 +00001405 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001406 (sext_inreg GPR:$b, i16))))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001407 Requires<[IsARM, HasV5TE]> {
1408 let Inst{5} = 1;
1409 let Inst{6} = 0;
1410 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001411
Evan Cheng38396be2008-11-06 03:35:07 +00001412 def TT : AMulxyI<0b0001000, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001413 IIC_iMAC16, !strconcat(opc, "tt"), "\t$dst, $a, $b, $acc",
1414 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
1415 (sra GPR:$b, (i32 16)))))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001416 Requires<[IsARM, HasV5TE]> {
1417 let Inst{5} = 1;
1418 let Inst{6} = 1;
1419 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001420
Evan Cheng38396be2008-11-06 03:35:07 +00001421 def WB : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001422 IIC_iMAC16, !strconcat(opc, "wb"), "\t$dst, $a, $b, $acc",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001423 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
Bob Wilson74590a02009-06-22 22:08:29 +00001424 (sext_inreg GPR:$b, i16)), (i32 16))))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001425 Requires<[IsARM, HasV5TE]> {
1426 let Inst{5} = 0;
1427 let Inst{6} = 0;
1428 }
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001429
Evan Cheng38396be2008-11-06 03:35:07 +00001430 def WT : AMulxyI<0b0001001, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001431 IIC_iMAC16, !strconcat(opc, "wt"), "\t$dst, $a, $b, $acc",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001432 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
Bob Wilson74590a02009-06-22 22:08:29 +00001433 (sra GPR:$b, (i32 16))), (i32 16))))]>,
Evan Cheng38396be2008-11-06 03:35:07 +00001434 Requires<[IsARM, HasV5TE]> {
1435 let Inst{5} = 0;
1436 let Inst{6} = 1;
1437 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001438}
1439
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001440defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1441defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001442
1443// TODO: Halfword multiple accumulate long: SMLAL<x><y>
1444// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
1445
1446//===----------------------------------------------------------------------===//
1447// Misc. Arithmetic Instructions.
1448//
1449
David Goodwin236ccb52009-08-19 18:00:44 +00001450def CLZ : AMiscA1I<0b000010110, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001451 "clz", "\t$dst, $src",
Evan Chengc2121a22008-11-07 01:41:35 +00001452 [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]> {
1453 let Inst{7-4} = 0b0001;
1454 let Inst{11-8} = 0b1111;
1455 let Inst{19-16} = 0b1111;
1456}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001457
David Goodwin236ccb52009-08-19 18:00:44 +00001458def REV : AMiscA1I<0b01101011, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001459 "rev", "\t$dst, $src",
Evan Chengc2121a22008-11-07 01:41:35 +00001460 [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]> {
1461 let Inst{7-4} = 0b0011;
1462 let Inst{11-8} = 0b1111;
1463 let Inst{19-16} = 0b1111;
1464}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001465
David Goodwin236ccb52009-08-19 18:00:44 +00001466def REV16 : AMiscA1I<0b01101011, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001467 "rev16", "\t$dst, $src",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001468 [(set GPR:$dst,
Bob Wilson74590a02009-06-22 22:08:29 +00001469 (or (and (srl GPR:$src, (i32 8)), 0xFF),
1470 (or (and (shl GPR:$src, (i32 8)), 0xFF00),
1471 (or (and (srl GPR:$src, (i32 8)), 0xFF0000),
1472 (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>,
Evan Chengc2121a22008-11-07 01:41:35 +00001473 Requires<[IsARM, HasV6]> {
1474 let Inst{7-4} = 0b1011;
1475 let Inst{11-8} = 0b1111;
1476 let Inst{19-16} = 0b1111;
1477}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001478
David Goodwin236ccb52009-08-19 18:00:44 +00001479def REVSH : AMiscA1I<0b01101111, (outs GPR:$dst), (ins GPR:$src), IIC_iUNAr,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001480 "revsh", "\t$dst, $src",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001481 [(set GPR:$dst,
1482 (sext_inreg
Bob Wilson74590a02009-06-22 22:08:29 +00001483 (or (srl (and GPR:$src, 0xFF00), (i32 8)),
1484 (shl GPR:$src, (i32 8))), i16))]>,
Evan Chengc2121a22008-11-07 01:41:35 +00001485 Requires<[IsARM, HasV6]> {
1486 let Inst{7-4} = 0b1011;
1487 let Inst{11-8} = 0b1111;
1488 let Inst{19-16} = 0b1111;
1489}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001490
Evan Chengc2121a22008-11-07 01:41:35 +00001491def PKHBT : AMiscA1I<0b01101000, (outs GPR:$dst),
1492 (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001493 IIC_iALUsi, "pkhbt", "\t$dst, $src1, $src2, LSL $shamt",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001494 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1495 (and (shl GPR:$src2, (i32 imm:$shamt)),
1496 0xFFFF0000)))]>,
Evan Chengc2121a22008-11-07 01:41:35 +00001497 Requires<[IsARM, HasV6]> {
1498 let Inst{6-4} = 0b001;
1499}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001500
1501// Alternate cases for PKHBT where identities eliminate some nodes.
1502def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1503 (PKHBT GPR:$src1, GPR:$src2, 0)>;
1504def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1505 (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
1506
1507
Evan Chengc2121a22008-11-07 01:41:35 +00001508def PKHTB : AMiscA1I<0b01101000, (outs GPR:$dst),
1509 (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
Evan Chengd3f9bc42009-10-26 23:45:59 +00001510 IIC_iALUsi, "pkhtb", "\t$dst, $src1, $src2, ASR $shamt",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001511 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1512 (and (sra GPR:$src2, imm16_31:$shamt),
Evan Chengc2121a22008-11-07 01:41:35 +00001513 0xFFFF)))]>, Requires<[IsARM, HasV6]> {
1514 let Inst{6-4} = 0b101;
1515}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001516
1517// Alternate cases for PKHTB where identities eliminate some nodes. Note that
1518// a shift amount of 0 is *not legal* here, it is PKHBT instead.
Bob Wilson74590a02009-06-22 22:08:29 +00001519def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, (i32 16))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001520 (PKHTB GPR:$src1, GPR:$src2, 16)>;
1521def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1522 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1523 (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1524
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001525//===----------------------------------------------------------------------===//
1526// Comparison Instructions...
1527//
1528
Jim Grosbach88c246f2008-10-14 20:36:24 +00001529defm CMP : AI1_cmp_irs<0b1010, "cmp",
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001530 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
Jim Grosbach88c246f2008-10-14 20:36:24 +00001531defm CMN : AI1_cmp_irs<0b1011, "cmn",
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001532 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001533
1534// Note that TST/TEQ don't set all the same flags that CMP does!
Evan Chengbe998242008-11-06 08:47:38 +00001535defm TST : AI1_cmp_irs<0b1000, "tst",
David Goodwin8bdcbb32009-06-29 15:33:01 +00001536 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>, 1>;
Evan Chengbe998242008-11-06 08:47:38 +00001537defm TEQ : AI1_cmp_irs<0b1001, "teq",
David Goodwin8bdcbb32009-06-29 15:33:01 +00001538 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>, 1>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001539
David Goodwin8bdcbb32009-06-29 15:33:01 +00001540defm CMPz : AI1_cmp_irs<0b1010, "cmp",
1541 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
1542defm CMNz : AI1_cmp_irs<0b1011, "cmn",
1543 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001544
1545def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1546 (CMNri GPR:$src, so_imm_neg:$imm)>;
1547
David Goodwin8bdcbb32009-06-29 15:33:01 +00001548def : ARMPat<(ARMcmpZ GPR:$src, so_imm_neg:$imm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001549 (CMNri GPR:$src, so_imm_neg:$imm)>;
1550
1551
1552// Conditional moves
1553// FIXME: should be able to write a pattern for ARMcmov, but can't use
1554// a two-value operand where a dag node expects two operands. :(
Evan Chengbe998242008-11-06 08:47:38 +00001555def MOVCCr : AI1<0b1101, (outs GPR:$dst), (ins GPR:$false, GPR:$true), DPFrm,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001556 IIC_iCMOVr, "mov", "\t$dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001557 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
Bob Wilsoncfb46c52009-10-14 19:00:24 +00001558 RegConstraint<"$false = $dst">, UnaryDP {
Johnny Chend139b942009-11-07 00:54:36 +00001559 let Inst{11-4} = 0b00000000;
Bob Wilsoncfb46c52009-10-14 19:00:24 +00001560 let Inst{25} = 0;
1561}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001562
Evan Chengbe998242008-11-06 08:47:38 +00001563def MOVCCs : AI1<0b1101, (outs GPR:$dst),
David Goodwin236ccb52009-08-19 18:00:44 +00001564 (ins GPR:$false, so_reg:$true), DPSoRegFrm, IIC_iCMOVsr,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001565 "mov", "\t$dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001566 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
Bob Wilsoncfb46c52009-10-14 19:00:24 +00001567 RegConstraint<"$false = $dst">, UnaryDP {
Bob Wilsoncfb46c52009-10-14 19:00:24 +00001568 let Inst{25} = 0;
1569}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001570
Evan Chengbe998242008-11-06 08:47:38 +00001571def MOVCCi : AI1<0b1101, (outs GPR:$dst),
David Goodwin236ccb52009-08-19 18:00:44 +00001572 (ins GPR:$false, so_imm:$true), DPFrm, IIC_iCMOVi,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001573 "mov", "\t$dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001574 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
Evan Chenga9892932009-09-09 01:47:07 +00001575 RegConstraint<"$false = $dst">, UnaryDP {
Bob Wilsoncfb46c52009-10-14 19:00:24 +00001576 let Inst{25} = 1;
Evan Chenga9892932009-09-09 01:47:07 +00001577}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001578
Jim Grosbachba744f62009-12-10 00:11:09 +00001579//===----------------------------------------------------------------------===//
1580// Atomic operations intrinsics
1581//
1582
1583// memory barriers protect the atomic sequences
Jim Grosbach63437d92009-12-14 18:31:20 +00001584let hasSideEffects = 1 in {
1585def Int_MemBarrierV7 : AInoP<(outs), (ins),
Jim Grosbachba744f62009-12-10 00:11:09 +00001586 Pseudo, NoItinerary,
1587 "dmb", "",
Jim Grosbach6eee9032009-12-14 21:24:16 +00001588 [(ARMMemBarrierV7)]>,
Jim Grosbach2d6e2492009-12-14 19:24:11 +00001589 Requires<[IsARM, HasV7]> {
Jim Grosbach37582c32009-12-10 18:35:32 +00001590 let Inst{31-4} = 0xf57ff05;
1591 // FIXME: add support for options other than a full system DMB
1592 let Inst{3-0} = 0b1111;
1593}
Jim Grosbachba744f62009-12-10 00:11:09 +00001594
Jim Grosbach63437d92009-12-14 18:31:20 +00001595def Int_SyncBarrierV7 : AInoP<(outs), (ins),
Jim Grosbachba744f62009-12-10 00:11:09 +00001596 Pseudo, NoItinerary,
1597 "dsb", "",
Jim Grosbach6eee9032009-12-14 21:24:16 +00001598 [(ARMSyncBarrierV7)]>,
Jim Grosbach2d6e2492009-12-14 19:24:11 +00001599 Requires<[IsARM, HasV7]> {
Jim Grosbach37582c32009-12-10 18:35:32 +00001600 let Inst{31-4} = 0xf57ff04;
1601 // FIXME: add support for options other than a full system DSB
1602 let Inst{3-0} = 0b1111;
1603}
Jim Grosbach6eee9032009-12-14 21:24:16 +00001604
1605def Int_MemBarrierV6 : AInoP<(outs), (ins GPR:$zero),
1606 Pseudo, NoItinerary,
1607 "mcr", "\tp15, 0, $zero, c7, c10, 5",
1608 [(ARMMemBarrierV6 GPR:$zero)]>,
1609 Requires<[IsARM, HasV6]> {
1610 // FIXME: add support for options other than a full system DMB
1611 // FIXME: add encoding
1612}
1613
1614def Int_SyncBarrierV6 : AInoP<(outs), (ins GPR:$zero),
1615 Pseudo, NoItinerary,
Jim Grosbachba16e072009-12-14 21:33:32 +00001616 "mcr", "\tp15, 0, $zero, c7, c10, 4",
Jim Grosbach6eee9032009-12-14 21:24:16 +00001617 [(ARMSyncBarrierV6 GPR:$zero)]>,
1618 Requires<[IsARM, HasV6]> {
1619 // FIXME: add support for options other than a full system DSB
1620 // FIXME: add encoding
1621}
Jim Grosbachba744f62009-12-10 00:11:09 +00001622}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001623
Jim Grosbach78539672009-12-11 18:52:41 +00001624let usesCustomInserter = 1 in {
Jim Grosbach24189692009-12-12 01:40:06 +00001625 let Uses = [CPSR] in {
1626 def ATOMIC_LOAD_ADD_I8 : PseudoInst<
1627 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1628 "${:comment} ATOMIC_LOAD_ADD_I8 PSEUDO!",
1629 [(set GPR:$dst, (atomic_load_add_8 GPR:$ptr, GPR:$incr))]>;
1630 def ATOMIC_LOAD_SUB_I8 : PseudoInst<
1631 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1632 "${:comment} ATOMIC_LOAD_SUB_I8 PSEUDO!",
1633 [(set GPR:$dst, (atomic_load_sub_8 GPR:$ptr, GPR:$incr))]>;
1634 def ATOMIC_LOAD_AND_I8 : PseudoInst<
1635 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1636 "${:comment} ATOMIC_LOAD_AND_I8 PSEUDO!",
1637 [(set GPR:$dst, (atomic_load_and_8 GPR:$ptr, GPR:$incr))]>;
1638 def ATOMIC_LOAD_OR_I8 : PseudoInst<
1639 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1640 "${:comment} ATOMIC_LOAD_OR_I8 PSEUDO!",
1641 [(set GPR:$dst, (atomic_load_or_8 GPR:$ptr, GPR:$incr))]>;
1642 def ATOMIC_LOAD_XOR_I8 : PseudoInst<
1643 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1644 "${:comment} ATOMIC_LOAD_XOR_I8 PSEUDO!",
1645 [(set GPR:$dst, (atomic_load_xor_8 GPR:$ptr, GPR:$incr))]>;
1646 def ATOMIC_LOAD_NAND_I8 : PseudoInst<
1647 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1648 "${:comment} ATOMIC_LOAD_NAND_I8 PSEUDO!",
1649 [(set GPR:$dst, (atomic_load_nand_8 GPR:$ptr, GPR:$incr))]>;
1650 def ATOMIC_LOAD_ADD_I16 : PseudoInst<
1651 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1652 "${:comment} ATOMIC_LOAD_ADD_I16 PSEUDO!",
1653 [(set GPR:$dst, (atomic_load_add_16 GPR:$ptr, GPR:$incr))]>;
1654 def ATOMIC_LOAD_SUB_I16 : PseudoInst<
1655 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1656 "${:comment} ATOMIC_LOAD_SUB_I16 PSEUDO!",
1657 [(set GPR:$dst, (atomic_load_sub_16 GPR:$ptr, GPR:$incr))]>;
1658 def ATOMIC_LOAD_AND_I16 : PseudoInst<
1659 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1660 "${:comment} ATOMIC_LOAD_AND_I16 PSEUDO!",
1661 [(set GPR:$dst, (atomic_load_and_16 GPR:$ptr, GPR:$incr))]>;
1662 def ATOMIC_LOAD_OR_I16 : PseudoInst<
1663 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1664 "${:comment} ATOMIC_LOAD_OR_I16 PSEUDO!",
1665 [(set GPR:$dst, (atomic_load_or_16 GPR:$ptr, GPR:$incr))]>;
1666 def ATOMIC_LOAD_XOR_I16 : PseudoInst<
1667 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1668 "${:comment} ATOMIC_LOAD_XOR_I16 PSEUDO!",
1669 [(set GPR:$dst, (atomic_load_xor_16 GPR:$ptr, GPR:$incr))]>;
1670 def ATOMIC_LOAD_NAND_I16 : PseudoInst<
1671 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1672 "${:comment} ATOMIC_LOAD_NAND_I16 PSEUDO!",
1673 [(set GPR:$dst, (atomic_load_nand_16 GPR:$ptr, GPR:$incr))]>;
1674 def ATOMIC_LOAD_ADD_I32 : PseudoInst<
1675 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1676 "${:comment} ATOMIC_LOAD_ADD_I32 PSEUDO!",
1677 [(set GPR:$dst, (atomic_load_add_32 GPR:$ptr, GPR:$incr))]>;
1678 def ATOMIC_LOAD_SUB_I32 : PseudoInst<
1679 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1680 "${:comment} ATOMIC_LOAD_SUB_I32 PSEUDO!",
1681 [(set GPR:$dst, (atomic_load_sub_32 GPR:$ptr, GPR:$incr))]>;
1682 def ATOMIC_LOAD_AND_I32 : PseudoInst<
1683 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1684 "${:comment} ATOMIC_LOAD_AND_I32 PSEUDO!",
1685 [(set GPR:$dst, (atomic_load_and_32 GPR:$ptr, GPR:$incr))]>;
1686 def ATOMIC_LOAD_OR_I32 : PseudoInst<
1687 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1688 "${:comment} ATOMIC_LOAD_OR_I32 PSEUDO!",
1689 [(set GPR:$dst, (atomic_load_or_32 GPR:$ptr, GPR:$incr))]>;
1690 def ATOMIC_LOAD_XOR_I32 : PseudoInst<
1691 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1692 "${:comment} ATOMIC_LOAD_XOR_I32 PSEUDO!",
1693 [(set GPR:$dst, (atomic_load_xor_32 GPR:$ptr, GPR:$incr))]>;
1694 def ATOMIC_LOAD_NAND_I32 : PseudoInst<
1695 (outs GPR:$dst), (ins GPR:$ptr, GPR:$incr), NoItinerary,
1696 "${:comment} ATOMIC_LOAD_NAND_I32 PSEUDO!",
1697 [(set GPR:$dst, (atomic_load_nand_32 GPR:$ptr, GPR:$incr))]>;
1698
1699 def ATOMIC_SWAP_I8 : PseudoInst<
1700 (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
1701 "${:comment} ATOMIC_SWAP_I8 PSEUDO!",
1702 [(set GPR:$dst, (atomic_swap_8 GPR:$ptr, GPR:$new))]>;
1703 def ATOMIC_SWAP_I16 : PseudoInst<
1704 (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
1705 "${:comment} ATOMIC_SWAP_I16 PSEUDO!",
1706 [(set GPR:$dst, (atomic_swap_16 GPR:$ptr, GPR:$new))]>;
1707 def ATOMIC_SWAP_I32 : PseudoInst<
1708 (outs GPR:$dst), (ins GPR:$ptr, GPR:$new), NoItinerary,
1709 "${:comment} ATOMIC_SWAP_I32 PSEUDO!",
1710 [(set GPR:$dst, (atomic_swap_32 GPR:$ptr, GPR:$new))]>;
1711
Jim Grosbach24189692009-12-12 01:40:06 +00001712 def ATOMIC_CMP_SWAP_I8 : PseudoInst<
1713 (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
1714 "${:comment} ATOMIC_CMP_SWAP_I8 PSEUDO!",
1715 [(set GPR:$dst, (atomic_cmp_swap_8 GPR:$ptr, GPR:$old, GPR:$new))]>;
1716 def ATOMIC_CMP_SWAP_I16 : PseudoInst<
1717 (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
1718 "${:comment} ATOMIC_CMP_SWAP_I16 PSEUDO!",
1719 [(set GPR:$dst, (atomic_cmp_swap_16 GPR:$ptr, GPR:$old, GPR:$new))]>;
1720 def ATOMIC_CMP_SWAP_I32 : PseudoInst<
1721 (outs GPR:$dst), (ins GPR:$ptr, GPR:$old, GPR:$new), NoItinerary,
1722 "${:comment} ATOMIC_CMP_SWAP_I32 PSEUDO!",
1723 [(set GPR:$dst, (atomic_cmp_swap_32 GPR:$ptr, GPR:$old, GPR:$new))]>;
1724}
Jim Grosbach437d6992009-12-11 01:42:04 +00001725}
1726
1727let mayLoad = 1 in {
1728def LDREXB : AIldrex<0b10, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
1729 "ldrexb", "\t$dest, [$ptr]",
1730 []>;
1731def LDREXH : AIldrex<0b11, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
1732 "ldrexh", "\t$dest, [$ptr]",
1733 []>;
1734def LDREX : AIldrex<0b00, (outs GPR:$dest), (ins GPR:$ptr), NoItinerary,
1735 "ldrex", "\t$dest, [$ptr]",
1736 []>;
Johnny Chen8ac1d372009-12-14 21:01:46 +00001737def LDREXD : AIldrex<0b01, (outs GPR:$dest, GPR:$dest2), (ins GPR:$ptr),
Jim Grosbachc83030d2009-12-14 17:02:55 +00001738 NoItinerary,
1739 "ldrexd", "\t$dest, $dest2, [$ptr]",
1740 []>;
Jim Grosbach437d6992009-12-11 01:42:04 +00001741}
1742
Jim Grosbach724d7a12009-12-16 19:44:06 +00001743let mayStore = 1, Constraints = "@earlyclobber $success" in {
Jim Grosbach437d6992009-12-11 01:42:04 +00001744def STREXB : AIstrex<0b10, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
Jim Grosbachc83030d2009-12-14 17:02:55 +00001745 NoItinerary,
Jim Grosbach437d6992009-12-11 01:42:04 +00001746 "strexb", "\t$success, $src, [$ptr]",
1747 []>;
1748def STREXH : AIstrex<0b11, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
1749 NoItinerary,
1750 "strexh", "\t$success, $src, [$ptr]",
1751 []>;
1752def STREX : AIstrex<0b00, (outs GPR:$success), (ins GPR:$src, GPR:$ptr),
Jim Grosbachc83030d2009-12-14 17:02:55 +00001753 NoItinerary,
Jim Grosbach437d6992009-12-11 01:42:04 +00001754 "strex", "\t$success, $src, [$ptr]",
1755 []>;
Johnny Chen8ac1d372009-12-14 21:01:46 +00001756def STREXD : AIstrex<0b01, (outs GPR:$success),
Jim Grosbachc83030d2009-12-14 17:02:55 +00001757 (ins GPR:$src, GPR:$src2, GPR:$ptr),
1758 NoItinerary,
1759 "strexd", "\t$success, $src, $src2, [$ptr]",
1760 []>;
Jim Grosbach437d6992009-12-11 01:42:04 +00001761}
1762
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001763//===----------------------------------------------------------------------===//
1764// TLS Instructions
1765//
1766
1767// __aeabi_read_tp preserves the registers r1-r3.
1768let isCall = 1,
1769 Defs = [R0, R12, LR, CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +00001770 def TPsoft : ABXI<0b1011, (outs), (ins), IIC_Br,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001771 "bl\t__aeabi_read_tp",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001772 [(set R0, ARMthread_pointer)]>;
1773}
1774
1775//===----------------------------------------------------------------------===//
Jim Grosbachc10915b2009-05-12 23:59:14 +00001776// SJLJ Exception handling intrinsics
Jim Grosbach207a4ba2009-08-13 15:11:43 +00001777// eh_sjlj_setjmp() is an instruction sequence to store the return
Jim Grosbach4a9025e2009-05-14 00:46:35 +00001778// address and save #0 in R0 for the non-longjmp case.
Jim Grosbachc10915b2009-05-12 23:59:14 +00001779// Since by its nature we may be coming from some other function to get
1780// here, and we're using the stack frame for the containing function to
1781// save/restore registers, we can't keep anything live in regs across
Jim Grosbach4a9025e2009-05-14 00:46:35 +00001782// the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
Jim Grosbachc10915b2009-05-12 23:59:14 +00001783// when we get here from a longjmp(). We force everthing out of registers
Jim Grosbach4a9025e2009-05-14 00:46:35 +00001784// except for our own input by listing the relevant registers in Defs. By
1785// doing so, we also cause the prologue/epilogue code to actively preserve
1786// all of the callee-saved resgisters, which is exactly what we want.
Jim Grosbachc10915b2009-05-12 23:59:14 +00001787let Defs =
Jim Grosbach3990e392009-08-13 16:59:44 +00001788 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, D0,
1789 D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
Evan Cheng80ab2a82009-07-29 20:10:36 +00001790 D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30,
Evan Cheng27396a62009-07-22 06:46:53 +00001791 D31 ] in {
Jim Grosbach4a9025e2009-05-14 00:46:35 +00001792 def Int_eh_sjlj_setjmp : XI<(outs), (ins GPR:$src),
David Goodwincfd67652009-08-06 16:52:47 +00001793 AddrModeNone, SizeSpecial, IndexModeNone,
1794 Pseudo, NoItinerary,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001795 "str\tsp, [$src, #+8] @ eh_setjmp begin\n\t"
1796 "add\tr12, pc, #8\n\t"
1797 "str\tr12, [$src, #+4]\n\t"
1798 "mov\tr0, #0\n\t"
1799 "add\tpc, pc, #0\n\t"
1800 "mov\tr0, #1 @ eh_setjmp end", "",
Jim Grosbach4a9025e2009-05-14 00:46:35 +00001801 [(set R0, (ARMeh_sjlj_setjmp GPR:$src))]>;
Jim Grosbachc10915b2009-05-12 23:59:14 +00001802}
1803
1804//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001805// Non-Instruction Patterns
1806//
1807
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001808// Large immediate handling.
1809
1810// Two piece so_imms.
1811let isReMaterializable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +00001812def MOVi2pieces : AI1x2<(outs GPR:$dst), (ins so_imm2part:$src),
David Goodwin236ccb52009-08-19 18:00:44 +00001813 Pseudo, IIC_iMOVi,
Evan Chengd3f9bc42009-10-26 23:45:59 +00001814 "mov", "\t$dst, $src",
Evan Cheng16c012d2009-09-28 09:14:39 +00001815 [(set GPR:$dst, so_imm2part:$src)]>,
1816 Requires<[IsARM, NoV6T2]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001817
1818def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
Evan Cheng8be2a5b2009-07-08 21:03:57 +00001819 (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1820 (so_imm2part_2 imm:$RHS))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001821def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
Evan Cheng8be2a5b2009-07-08 21:03:57 +00001822 (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1823 (so_imm2part_2 imm:$RHS))>;
Jim Grosbach1afc8e22009-10-21 20:44:34 +00001824def : ARMPat<(add GPR:$LHS, so_imm2part:$RHS),
1825 (ADDri (ADDri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1826 (so_imm2part_2 imm:$RHS))>;
Jim Grosbach66e70cd2009-11-23 20:35:53 +00001827def : ARMPat<(add GPR:$LHS, so_neg_imm2part:$RHS),
1828 (SUBri (SUBri GPR:$LHS, (so_neg_imm2part_1 imm:$RHS)),
1829 (so_neg_imm2part_2 imm:$RHS))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001830
Evan Cheng16c012d2009-09-28 09:14:39 +00001831// 32-bit immediate using movw + movt.
Chris Lattnere4eb7342009-10-20 00:40:56 +00001832// This is a single pseudo instruction, the benefit is that it can be remat'd
1833// as a single unit instead of having to handle reg inputs.
1834// FIXME: Remove this when we can do generalized remat.
Evan Cheng16c012d2009-09-28 09:14:39 +00001835let isReMaterializable = 1 in
1836def MOVi32imm : AI1x2<(outs GPR:$dst), (ins i32imm:$src), Pseudo, IIC_iMOVi,
Anton Korobeynikova414f362009-11-24 00:44:37 +00001837 "movw", "\t$dst, ${src:lo16}\n\tmovt${p}\t$dst, ${src:hi16}",
Evan Cheng16c012d2009-09-28 09:14:39 +00001838 [(set GPR:$dst, (i32 imm:$src))]>,
1839 Requires<[IsARM, HasV6T2]>;
Anton Korobeynikov60928952009-09-27 23:52:58 +00001840
Anton Korobeynikova414f362009-11-24 00:44:37 +00001841// ConstantPool, GlobalAddress, and JumpTable
1842def : ARMPat<(ARMWrapper tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>,
1843 Requires<[IsARM, DontUseMovt]>;
1844def : ARMPat<(ARMWrapper tconstpool :$dst), (LEApcrel tconstpool :$dst)>;
1845def : ARMPat<(ARMWrapper tglobaladdr :$dst), (MOVi32imm tglobaladdr :$dst)>,
1846 Requires<[IsARM, UseMovt]>;
1847def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1848 (LEApcrelJT tjumptable:$dst, imm:$id)>;
1849
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001850// TODO: add,sub,and, 3-instr forms?
1851
1852
1853// Direct calls
Bob Wilson243b37c2009-06-22 21:01:46 +00001854def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>,
Evan Cheng9e734482009-07-29 21:26:42 +00001855 Requires<[IsARM, IsNotDarwin]>;
Bob Wilson243b37c2009-06-22 21:01:46 +00001856def : ARMPat<(ARMcall texternalsym:$func), (BLr9 texternalsym:$func)>,
Evan Cheng9e734482009-07-29 21:26:42 +00001857 Requires<[IsARM, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001858
1859// zextload i1 -> zextload i8
1860def : ARMPat<(zextloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1861
1862// extload -> zextload
1863def : ARMPat<(extloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1864def : ARMPat<(extloadi8 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1865def : ARMPat<(extloadi16 addrmode3:$addr), (LDRH addrmode3:$addr)>;
1866
Evan Chengc41fb3152008-11-05 23:22:34 +00001867def : ARMPat<(extloadi8 addrmodepc:$addr), (PICLDRB addrmodepc:$addr)>;
1868def : ARMPat<(extloadi16 addrmodepc:$addr), (PICLDRH addrmodepc:$addr)>;
1869
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001870// smul* and smla*
Bob Wilson74590a02009-06-22 22:08:29 +00001871def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1872 (sra (shl GPR:$b, (i32 16)), (i32 16))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001873 (SMULBB GPR:$a, GPR:$b)>;
1874def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1875 (SMULBB GPR:$a, GPR:$b)>;
Bob Wilson74590a02009-06-22 22:08:29 +00001876def : ARMV5TEPat<(mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1877 (sra GPR:$b, (i32 16))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001878 (SMULBT GPR:$a, GPR:$b)>;
Bob Wilson74590a02009-06-22 22:08:29 +00001879def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, (i32 16))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001880 (SMULBT GPR:$a, GPR:$b)>;
Bob Wilson74590a02009-06-22 22:08:29 +00001881def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)),
1882 (sra (shl GPR:$b, (i32 16)), (i32 16))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001883 (SMULTB GPR:$a, GPR:$b)>;
Bob Wilson74590a02009-06-22 22:08:29 +00001884def : ARMV5TEPat<(mul (sra GPR:$a, (i32 16)), sext_16_node:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001885 (SMULTB GPR:$a, GPR:$b)>;
Bob Wilson74590a02009-06-22 22:08:29 +00001886def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
1887 (i32 16)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001888 (SMULWB GPR:$a, GPR:$b)>;
Bob Wilson74590a02009-06-22 22:08:29 +00001889def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), (i32 16)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001890 (SMULWB GPR:$a, GPR:$b)>;
1891
1892def : ARMV5TEPat<(add GPR:$acc,
Bob Wilson74590a02009-06-22 22:08:29 +00001893 (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1894 (sra (shl GPR:$b, (i32 16)), (i32 16)))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001895 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1896def : ARMV5TEPat<(add GPR:$acc,
1897 (mul sext_16_node:$a, sext_16_node:$b)),
1898 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1899def : ARMV5TEPat<(add GPR:$acc,
Bob Wilson74590a02009-06-22 22:08:29 +00001900 (mul (sra (shl GPR:$a, (i32 16)), (i32 16)),
1901 (sra GPR:$b, (i32 16)))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001902 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1903def : ARMV5TEPat<(add GPR:$acc,
Bob Wilson74590a02009-06-22 22:08:29 +00001904 (mul sext_16_node:$a, (sra GPR:$b, (i32 16)))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001905 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1906def : ARMV5TEPat<(add GPR:$acc,
Bob Wilson74590a02009-06-22 22:08:29 +00001907 (mul (sra GPR:$a, (i32 16)),
1908 (sra (shl GPR:$b, (i32 16)), (i32 16)))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001909 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1910def : ARMV5TEPat<(add GPR:$acc,
Bob Wilson74590a02009-06-22 22:08:29 +00001911 (mul (sra GPR:$a, (i32 16)), sext_16_node:$b)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001912 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1913def : ARMV5TEPat<(add GPR:$acc,
Bob Wilson74590a02009-06-22 22:08:29 +00001914 (sra (mul GPR:$a, (sra (shl GPR:$b, (i32 16)), (i32 16))),
1915 (i32 16))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001916 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1917def : ARMV5TEPat<(add GPR:$acc,
Bob Wilson74590a02009-06-22 22:08:29 +00001918 (sra (mul GPR:$a, sext_16_node:$b), (i32 16))),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001919 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1920
1921//===----------------------------------------------------------------------===//
1922// Thumb Support
1923//
1924
1925include "ARMInstrThumb.td"
1926
1927//===----------------------------------------------------------------------===//
Anton Korobeynikovac869fc2009-06-17 18:13:58 +00001928// Thumb2 Support
1929//
1930
1931include "ARMInstrThumb2.td"
1932
1933//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001934// Floating Point Support
1935//
1936
1937include "ARMInstrVFP.td"
Bob Wilsone60fee02009-06-22 23:27:02 +00001938
1939//===----------------------------------------------------------------------===//
1940// Advanced SIMD (NEON) Support
1941//
1942
1943include "ARMInstrNEON.td"