blob: c984ee1e5fea9cfcb76eca57f68b10f4cb3e5968 [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//
5// This file was developed by the "Instituto Nokia de Tecnologia" and
6// is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10//
11// This file describes the ARM instructions in TableGen format.
12//
13//===----------------------------------------------------------------------===//
14
15//===----------------------------------------------------------------------===//
16// ARM specific DAG Nodes.
17//
18
19// Type profiles.
20def SDT_ARMCallSeq : SDTypeProfile<0, 1, [ SDTCisVT<0, i32> ]>;
21
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
37def SDT_ARMCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
38
39def SDT_ARMPICAdd : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
40 SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
41
42def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
43
44// Node definitions.
45def ARMWrapper : SDNode<"ARMISD::Wrapper", SDTIntUnaryOp>;
46def ARMWrapperJT : SDNode<"ARMISD::WrapperJT", SDTIntBinOp>;
47
48def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeq,
49 [SDNPHasChain, SDNPOutFlag]>;
50def ARMcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_ARMCallSeq,
51 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
52
53def ARMcall : SDNode<"ARMISD::CALL", SDT_ARMcall,
54 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
55def ARMcall_pred : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
56 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
57def ARMcall_nolink : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
58 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
59
60def ARMretflag : SDNode<"ARMISD::RET_FLAG", SDTRet,
61 [SDNPHasChain, SDNPOptInFlag]>;
62
63def ARMcmov : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
64 [SDNPInFlag]>;
65def ARMcneg : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
66 [SDNPInFlag]>;
67
68def ARMbrcond : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
69 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
70
71def ARMbrjt : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
72 [SDNPHasChain]>;
73
74def ARMcmp : SDNode<"ARMISD::CMP", SDT_ARMCmp,
75 [SDNPOutFlag]>;
76
77def ARMcmpNZ : SDNode<"ARMISD::CMPNZ", SDT_ARMCmp,
78 [SDNPOutFlag]>;
79
80def ARMpic_add : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
81
82def ARMsrl_flag : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
83def ARMsra_flag : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
84def ARMrrx : SDNode<"ARMISD::RRX" , SDTIntUnaryOp, [SDNPInFlag ]>;
85
86def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
87
88//===----------------------------------------------------------------------===//
89// ARM Instruction Predicate Definitions.
90//
91def HasV5T : Predicate<"Subtarget->hasV5TOps()">;
92def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">;
93def HasV6 : Predicate<"Subtarget->hasV6Ops()">;
94def IsThumb : Predicate<"Subtarget->isThumb()">;
95def IsARM : Predicate<"!Subtarget->isThumb()">;
96
97//===----------------------------------------------------------------------===//
98// ARM Flag Definitions.
99
100class RegConstraint<string C> {
101 string Constraints = C;
102}
103
104//===----------------------------------------------------------------------===//
105// ARM specific transformation functions and pattern fragments.
106//
107
108// so_imm_XFORM - Return a so_imm value packed into the format described for
109// so_imm def below.
110def so_imm_XFORM : SDNodeXForm<imm, [{
111 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(N->getValue()),
112 MVT::i32);
113}]>;
114
115// so_imm_neg_XFORM - Return a so_imm value packed into the format described for
116// so_imm_neg def below.
117def so_imm_neg_XFORM : SDNodeXForm<imm, [{
118 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(-(int)N->getValue()),
119 MVT::i32);
120}]>;
121
122// so_imm_not_XFORM - Return a so_imm value packed into the format described for
123// so_imm_not def below.
124def so_imm_not_XFORM : SDNodeXForm<imm, [{
125 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(~(int)N->getValue()),
126 MVT::i32);
127}]>;
128
129// rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
130def rot_imm : PatLeaf<(i32 imm), [{
131 int32_t v = (int32_t)N->getValue();
132 return v == 8 || v == 16 || v == 24;
133}]>;
134
135/// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
136def imm1_15 : PatLeaf<(i32 imm), [{
137 return (int32_t)N->getValue() >= 1 && (int32_t)N->getValue() < 16;
138}]>;
139
140/// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
141def imm16_31 : PatLeaf<(i32 imm), [{
142 return (int32_t)N->getValue() >= 16 && (int32_t)N->getValue() < 32;
143}]>;
144
145def so_imm_neg :
146 PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(-(int)N->getValue()) != -1; }],
147 so_imm_neg_XFORM>;
148
149def so_imm_not :
150 PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(~(int)N->getValue()) != -1; }],
151 so_imm_not_XFORM>;
152
153// sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
154def sext_16_node : PatLeaf<(i32 GPR:$a), [{
155 return CurDAG->ComputeNumSignBits(SDOperand(N,0)) >= 17;
156}]>;
157
158
159
160//===----------------------------------------------------------------------===//
161// Operand Definitions.
162//
163
164// Branch target.
165def brtarget : Operand<OtherVT>;
166
167// A list of registers separated by comma. Used by load/store multiple.
168def reglist : Operand<i32> {
169 let PrintMethod = "printRegisterList";
170}
171
172// An operand for the CONSTPOOL_ENTRY pseudo-instruction.
173def cpinst_operand : Operand<i32> {
174 let PrintMethod = "printCPInstOperand";
175}
176
177def jtblock_operand : Operand<i32> {
178 let PrintMethod = "printJTBlockOperand";
179}
180
181// Local PC labels.
182def pclabel : Operand<i32> {
183 let PrintMethod = "printPCLabel";
184}
185
186// shifter_operand operands: so_reg and so_imm.
187def so_reg : Operand<i32>, // reg reg imm
188 ComplexPattern<i32, 3, "SelectShifterOperandReg",
189 [shl,srl,sra,rotr]> {
190 let PrintMethod = "printSORegOperand";
191 let MIOperandInfo = (ops GPR, GPR, i32imm);
192}
193
194// so_imm - Match a 32-bit shifter_operand immediate operand, which is an
195// 8-bit immediate rotated by an arbitrary number of bits. so_imm values are
196// represented in the imm field in the same 12-bit form that they are encoded
197// into so_imm instructions: the 8-bit immediate is the least significant bits
198// [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
199def so_imm : Operand<i32>,
200 PatLeaf<(imm),
201 [{ return ARM_AM::getSOImmVal(N->getValue()) != -1; }],
202 so_imm_XFORM> {
203 let PrintMethod = "printSOImmOperand";
204}
205
206// Break so_imm's up into two pieces. This handles immediates with up to 16
207// bits set in them. This uses so_imm2part to match and so_imm2part_[12] to
208// get the first/second pieces.
209def so_imm2part : Operand<i32>,
210 PatLeaf<(imm),
211 [{ return ARM_AM::isSOImmTwoPartVal((unsigned)N->getValue()); }]> {
212 let PrintMethod = "printSOImm2PartOperand";
213}
214
215def so_imm2part_1 : SDNodeXForm<imm, [{
216 unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getValue());
217 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
218}]>;
219
220def so_imm2part_2 : SDNodeXForm<imm, [{
221 unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getValue());
222 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
223}]>;
224
225
226// Define ARM specific addressing modes.
227
228// addrmode2 := reg +/- reg shop imm
229// addrmode2 := reg +/- imm12
230//
231def addrmode2 : Operand<i32>,
232 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
233 let PrintMethod = "printAddrMode2Operand";
234 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
235}
236
237def am2offset : Operand<i32>,
238 ComplexPattern<i32, 2, "SelectAddrMode2Offset", []> {
239 let PrintMethod = "printAddrMode2OffsetOperand";
240 let MIOperandInfo = (ops GPR, i32imm);
241}
242
243// addrmode3 := reg +/- reg
244// addrmode3 := reg +/- imm8
245//
246def addrmode3 : Operand<i32>,
247 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
248 let PrintMethod = "printAddrMode3Operand";
249 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
250}
251
252def am3offset : Operand<i32>,
253 ComplexPattern<i32, 2, "SelectAddrMode3Offset", []> {
254 let PrintMethod = "printAddrMode3OffsetOperand";
255 let MIOperandInfo = (ops GPR, i32imm);
256}
257
258// addrmode4 := reg, <mode|W>
259//
260def addrmode4 : Operand<i32>,
261 ComplexPattern<i32, 2, "", []> {
262 let PrintMethod = "printAddrMode4Operand";
263 let MIOperandInfo = (ops GPR, i32imm);
264}
265
266// addrmode5 := reg +/- imm8*4
267//
268def addrmode5 : Operand<i32>,
269 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
270 let PrintMethod = "printAddrMode5Operand";
271 let MIOperandInfo = (ops GPR, i32imm);
272}
273
274// addrmodepc := pc + reg
275//
276def addrmodepc : Operand<i32>,
277 ComplexPattern<i32, 2, "SelectAddrModePC", []> {
278 let PrintMethod = "printAddrModePCOperand";
279 let MIOperandInfo = (ops GPR, i32imm);
280}
281
282// ARM Predicate operand. Default to 14 = always (AL). Second part is CC
283// register whose default is 0 (no register).
284def pred : PredicateOperand<OtherVT, (ops i32imm, CCR),
285 (ops (i32 14), (i32 zero_reg))> {
286 let PrintMethod = "printPredicateOperand";
287}
288
289// Conditional code result for instructions whose 's' bit is set, e.g. subs.
290//
291def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
292 let PrintMethod = "printSBitModifierOperand";
293}
294
295//===----------------------------------------------------------------------===//
296// ARM Instruction flags. These need to match ARMInstrInfo.h.
297//
298
299// Addressing mode.
300class AddrMode<bits<4> val> {
301 bits<4> Value = val;
302}
303def AddrModeNone : AddrMode<0>;
304def AddrMode1 : AddrMode<1>;
305def AddrMode2 : AddrMode<2>;
306def AddrMode3 : AddrMode<3>;
307def AddrMode4 : AddrMode<4>;
308def AddrMode5 : AddrMode<5>;
309def AddrModeT1 : AddrMode<6>;
310def AddrModeT2 : AddrMode<7>;
311def AddrModeT4 : AddrMode<8>;
312def AddrModeTs : AddrMode<9>;
313
314// Instruction size.
315class SizeFlagVal<bits<3> val> {
316 bits<3> Value = val;
317}
318def SizeInvalid : SizeFlagVal<0>; // Unset.
319def SizeSpecial : SizeFlagVal<1>; // Pseudo or special.
320def Size8Bytes : SizeFlagVal<2>;
321def Size4Bytes : SizeFlagVal<3>;
322def Size2Bytes : SizeFlagVal<4>;
323
324// Load / store index mode.
325class IndexMode<bits<2> val> {
326 bits<2> Value = val;
327}
328def IndexModeNone : IndexMode<0>;
329def IndexModePre : IndexMode<1>;
330def IndexModePost : IndexMode<2>;
331
332//===----------------------------------------------------------------------===//
333// ARM Instruction templates.
334//
335
336// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
337class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
338 list<Predicate> Predicates = [IsARM];
339}
340class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
341 list<Predicate> Predicates = [IsARM, HasV5TE];
342}
343class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
344 list<Predicate> Predicates = [IsARM, HasV6];
345}
346
347class InstARM<bits<4> opcod, AddrMode am, SizeFlagVal sz, IndexMode im,
348 string cstr>
349 : Instruction {
350 let Namespace = "ARM";
351
352 bits<4> Opcode = opcod;
353 AddrMode AM = am;
354 bits<4> AddrModeBits = AM.Value;
355
356 SizeFlagVal SZ = sz;
357 bits<3> SizeFlag = SZ.Value;
358
359 IndexMode IM = im;
360 bits<2> IndexModeBits = IM.Value;
361
362 let Constraints = cstr;
363}
364
Evan Chengb783fa32007-07-19 01:14:50 +0000365class PseudoInst<dag oops, dag iops, string asm, list<dag> pattern>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000366 : InstARM<0, AddrModeNone, SizeSpecial, IndexModeNone, ""> {
Evan Chengb783fa32007-07-19 01:14:50 +0000367 let OutOperandList = oops;
368 let InOperandList = iops;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369 let AsmString = asm;
370 let Pattern = pattern;
371}
372
373// Almost all ARM instructions are predicable.
Evan Chengb783fa32007-07-19 01:14:50 +0000374class I<dag oops, dag iops, AddrMode am, SizeFlagVal sz, IndexMode im,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000375 string opc, string asm, string cstr, list<dag> pattern>
376 // FIXME: Set all opcodes to 0 for now.
377 : InstARM<0, am, sz, im, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000378 let OutOperandList = oops;
379 let InOperandList = !con(iops, (ops pred:$p));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380 let AsmString = !strconcat(opc, !strconcat("${p}", asm));
381 let Pattern = pattern;
382 list<Predicate> Predicates = [IsARM];
383}
384
Evan Chengb783fa32007-07-19 01:14:50 +0000385// Same as I except it can optionally modify CPSR. Note it's modeled as
386// an input operand since by default it's a zero register. It will
387// become an implicit def once it's "flipped".
388class sI<dag oops, dag iops, AddrMode am, SizeFlagVal sz, IndexMode im,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389 string opc, string asm, string cstr, list<dag> pattern>
390 // FIXME: Set all opcodes to 0 for now.
391 : InstARM<0, am, sz, im, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000392 let OutOperandList = oops;
393 let InOperandList = !con(iops, (ops pred:$p, cc_out:$s));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394 let AsmString = !strconcat(opc, !strconcat("${p}${s}", asm));
395 let Pattern = pattern;
396 list<Predicate> Predicates = [IsARM];
397}
398
Evan Chengb783fa32007-07-19 01:14:50 +0000399class AI<dag oops, dag iops, string opc, string asm, list<dag> pattern>
400 : I<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, opc, asm,"",pattern>;
401class AsI<dag oops, dag iops, string opc, string asm, list<dag> pattern>
402 : sI<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, opc,asm,"",pattern>;
403class AI1<dag oops, dag iops, string opc, string asm, list<dag> pattern>
404 : I<oops, iops, AddrMode1, Size4Bytes, IndexModeNone, opc, asm, "", pattern>;
405class AsI1<dag oops, dag iops, string opc, string asm, list<dag> pattern>
406 : sI<oops, iops, AddrMode1, Size4Bytes, IndexModeNone, opc, asm, "", pattern>;
407class AI2<dag oops, dag iops, string opc, string asm, list<dag> pattern>
408 : I<oops, iops, AddrMode2, Size4Bytes, IndexModeNone, opc, asm, "", pattern>;
409class AI3<dag oops, dag iops, string opc, string asm, list<dag> pattern>
410 : I<oops, iops, AddrMode3, Size4Bytes, IndexModeNone, opc, asm, "", pattern>;
411class AI4<dag oops, dag iops, string opc, string asm, list<dag> pattern>
412 : I<oops, iops, AddrMode4, Size4Bytes, IndexModeNone, opc, asm, "", pattern>;
413class AI1x2<dag oops, dag iops, string opc, string asm, list<dag> pattern>
414 : I<oops, iops, AddrMode1, Size8Bytes, IndexModeNone, opc, asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415
416// Pre-indexed ops
Evan Chengb783fa32007-07-19 01:14:50 +0000417class AI2pr<dag oops, dag iops, string opc, string asm, string cstr,
418 list<dag> pattern>
419 : I<oops, iops, AddrMode2, Size4Bytes, IndexModePre, opc, asm, cstr, pattern>;
420class AI3pr<dag oops, dag iops, string opc, string asm, string cstr,
421 list<dag> pattern>
422 : I<oops, iops, AddrMode3, Size4Bytes, IndexModePre, opc, asm, cstr, pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000423
424// Post-indexed ops
Evan Chengb783fa32007-07-19 01:14:50 +0000425class AI2po<dag oops, dag iops, string opc, string asm, string cstr,
426 list<dag> pattern>
427 : I<oops, iops, AddrMode2, Size4Bytes, IndexModePost, opc, asm, cstr,pattern>;
428class AI3po<dag oops, dag iops, string opc, string asm, string cstr,
429 list<dag> pattern>
430 : I<oops, iops, AddrMode3, Size4Bytes, IndexModePost, opc, asm, cstr,pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431
432
433class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
434class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
435
436
437/// AI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
438/// binop that produces a value.
439multiclass AsI1_bin_irs<string opc, PatFrag opnode> {
Evan Chengb783fa32007-07-19 01:14:50 +0000440 def ri : AsI1<(outs GPR:$dst), (ins GPR:$a, so_imm:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000441 opc, " $dst, $a, $b",
442 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000443 def rr : AsI1<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444 opc, " $dst, $a, $b",
445 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000446 def rs : AsI1<(outs GPR:$dst), (ins GPR:$a, so_reg:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 opc, " $dst, $a, $b",
448 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
449}
450
451/// ASI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
452/// instruction modifies the CSPR register.
453multiclass ASI1_bin_s_irs<string opc, PatFrag opnode> {
Evan Chengb783fa32007-07-19 01:14:50 +0000454 def ri : AI1<(outs GPR:$dst), (ins GPR:$a, so_imm:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000455 opc, "s $dst, $a, $b",
456 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>, Imp<[], [CPSR]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000457 def rr : AI1<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458 opc, "s $dst, $a, $b",
459 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>, Imp<[], [CPSR]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000460 def rs : AI1<(outs GPR:$dst), (ins GPR:$a, so_reg:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461 opc, "s $dst, $a, $b",
462 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>, Imp<[], [CPSR]>;
463}
464
465/// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
466/// patterns. Similar to AsI1_bin_irs except the instruction does not produce
467/// a explicit result, only implicitly set CPSR.
468multiclass AI1_cmp_irs<string opc, PatFrag opnode> {
Evan Chengb783fa32007-07-19 01:14:50 +0000469 def ri : AI1<(outs), (ins GPR:$a, so_imm:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000470 opc, " $a, $b",
471 [(opnode GPR:$a, so_imm:$b)]>, Imp<[], [CPSR]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000472 def rr : AI1<(outs), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473 opc, " $a, $b",
474 [(opnode GPR:$a, GPR:$b)]>, Imp<[], [CPSR]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000475 def rs : AI1<(outs), (ins GPR:$a, so_reg:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476 opc, " $a, $b",
477 [(opnode GPR:$a, so_reg:$b)]>, Imp<[], [CPSR]>;
478}
479
480/// AI_unary_rrot - A unary operation with two forms: one whose operand is a
481/// register and one whose operand is a register rotated by 8/16/24.
482multiclass AI_unary_rrot<string opc, PatFrag opnode> {
Evan Chengb783fa32007-07-19 01:14:50 +0000483 def r : AI<(outs GPR:$dst), (ins GPR:$Src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000484 opc, " $dst, $Src",
485 [(set GPR:$dst, (opnode GPR:$Src))]>, Requires<[IsARM, HasV6]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000486 def r_rot : AI<(outs GPR:$dst), (ins GPR:$Src, i32imm:$rot),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487 opc, " $dst, $Src, ror $rot",
488 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>,
489 Requires<[IsARM, HasV6]>;
490}
491
492/// AI_bin_rrot - A binary operation with two forms: one whose operand is a
493/// register and one whose operand is a register rotated by 8/16/24.
494multiclass AI_bin_rrot<string opc, PatFrag opnode> {
Evan Chengb783fa32007-07-19 01:14:50 +0000495 def rr : AI<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496 opc, " $dst, $LHS, $RHS",
497 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
498 Requires<[IsARM, HasV6]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000499 def rr_rot : AI<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000500 opc, " $dst, $LHS, $RHS, ror $rot",
501 [(set GPR:$dst, (opnode GPR:$LHS,
502 (rotr GPR:$RHS, rot_imm:$rot)))]>,
503 Requires<[IsARM, HasV6]>;
504}
505
506// Special cases.
Evan Chengb783fa32007-07-19 01:14:50 +0000507class XI<dag oops, dag iops, AddrMode am, SizeFlagVal sz, IndexMode im,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508 string asm, string cstr, list<dag> pattern>
509 // FIXME: Set all opcodes to 0 for now.
510 : InstARM<0, am, sz, im, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000511 let OutOperandList = oops;
512 let InOperandList = iops;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513 let AsmString = asm;
514 let Pattern = pattern;
515 list<Predicate> Predicates = [IsARM];
516}
517
Evan Chengb783fa32007-07-19 01:14:50 +0000518class AXI<dag oops, dag iops, string asm, list<dag> pattern>
519 : XI<oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, asm, "", pattern>;
520class AXI1<dag oops, dag iops, string asm, list<dag> pattern>
521 : XI<oops, iops, AddrMode1, Size4Bytes, IndexModeNone, asm, "", pattern>;
522class AXI2<dag oops, dag iops, string asm, list<dag> pattern>
523 : XI<oops, iops, AddrMode2, Size4Bytes, IndexModeNone, asm, "", pattern>;
524class AXI3<dag oops, dag iops, string asm, list<dag> pattern>
525 : XI<oops, iops, AddrMode3, Size4Bytes, IndexModeNone, asm, "", pattern>;
526class AXI4<dag oops, dag iops, string asm, list<dag> pattern>
527 : XI<oops, iops, AddrMode4, Size4Bytes, IndexModeNone, asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528
Evan Chengb783fa32007-07-19 01:14:50 +0000529class AXIx2<dag oops, dag iops, string asm, list<dag> pattern>
530 : XI<oops, iops, AddrModeNone, Size8Bytes, IndexModeNone, asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000531
532// BR_JT instructions
Evan Chengb783fa32007-07-19 01:14:50 +0000533class JTI<dag oops, dag iops, string asm, list<dag> pattern>
534 : XI<oops, iops, AddrModeNone, SizeSpecial, IndexModeNone, asm, "", pattern>;
535class JTI1<dag oops, dag iops, string asm, list<dag> pattern>
536 : XI<oops, iops, AddrMode1, SizeSpecial, IndexModeNone, asm, "", pattern>;
537class JTI2<dag oops, dag iops, string asm, list<dag> pattern>
538 : XI<oops, iops, AddrMode2, SizeSpecial, IndexModeNone, asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539
540/// AsXI1_bin_c_irs - Same as AsI1_bin_irs but without the predicate operand and
541/// setting carry bit. But it can optionally set CPSR.
542multiclass AsXI1_bin_c_irs<string opc, PatFrag opnode> {
Evan Chengb783fa32007-07-19 01:14:50 +0000543 def ri : AXI1<(outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544 !strconcat(opc, "${s} $dst, $a, $b"),
545 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>, Imp<[CPSR], []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000546 def rr : AXI1<(outs GPR:$dst), (ins GPR:$a, GPR:$b, cc_out:$s),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547 !strconcat(opc, "${s} $dst, $a, $b"),
548 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>, Imp<[CPSR], []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000549 def rs : AXI1<(outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550 !strconcat(opc, "${s} $dst, $a, $b"),
551 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>, Imp<[CPSR], []>;
552}
553
554//===----------------------------------------------------------------------===//
555// Instructions
556//===----------------------------------------------------------------------===//
557
558//===----------------------------------------------------------------------===//
559// Miscellaneous Instructions.
560//
561def IMPLICIT_DEF_GPR :
Evan Chengb783fa32007-07-19 01:14:50 +0000562PseudoInst<(outs GPR:$rD), (ins pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000563 "@ IMPLICIT_DEF_GPR $rD",
564 [(set GPR:$rD, (undef))]>;
565
566
567/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
568/// the function. The first operand is the ID# for this instruction, the second
569/// is the index into the MachineConstantPool that this is, the third is the
570/// size in bytes of this constant pool entry.
571let isNotDuplicable = 1 in
572def CONSTPOOL_ENTRY :
Evan Chengb783fa32007-07-19 01:14:50 +0000573PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
574 i32imm:$size),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575 "${instid:label} ${cpidx:cpentry}", []>;
576
577def ADJCALLSTACKUP :
Evan Chengb783fa32007-07-19 01:14:50 +0000578PseudoInst<(outs), (ins i32imm:$amt, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000579 "@ ADJCALLSTACKUP $amt",
580 [(ARMcallseq_end imm:$amt)]>, Imp<[SP],[SP]>;
581
582def ADJCALLSTACKDOWN :
Evan Chengb783fa32007-07-19 01:14:50 +0000583PseudoInst<(outs), (ins i32imm:$amt, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000584 "@ ADJCALLSTACKDOWN $amt",
585 [(ARMcallseq_start imm:$amt)]>, Imp<[SP],[SP]>;
586
587def DWARF_LOC :
Evan Chengb783fa32007-07-19 01:14:50 +0000588PseudoInst<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589 ".loc $file, $line, $col",
590 [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
591
592let isNotDuplicable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000593def PICADD : AXI1<(outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000594 "$cp:\n\tadd$p $dst, pc, $a",
595 [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
596
597let isLoad = 1, AddedComplexity = 10 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000598def PICLD : AXI2<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000599 "${addr:label}:\n\tldr$p $dst, $addr",
600 [(set GPR:$dst, (load addrmodepc:$addr))]>;
601
Evan Chengb783fa32007-07-19 01:14:50 +0000602def PICLDZH : AXI3<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000603 "${addr:label}:\n\tldr${p}h $dst, $addr",
604 [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
605
Evan Chengb783fa32007-07-19 01:14:50 +0000606def PICLDZB : AXI2<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607 "${addr:label}:\n\tldr${p}b $dst, $addr",
608 [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
609
Evan Chengb783fa32007-07-19 01:14:50 +0000610def PICLDH : AXI3<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611 "${addr:label}:\n\tldr${p}h $dst, $addr",
612 [(set GPR:$dst, (extloadi16 addrmodepc:$addr))]>;
613
Evan Chengb783fa32007-07-19 01:14:50 +0000614def PICLDB : AXI2<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615 "${addr:label}:\n\tldr${p}b $dst, $addr",
616 [(set GPR:$dst, (extloadi8 addrmodepc:$addr))]>;
617
Evan Chengb783fa32007-07-19 01:14:50 +0000618def PICLDSH : AXI3<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000619 "${addr:label}:\n\tldr${p}sh $dst, $addr",
620 [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
621
Evan Chengb783fa32007-07-19 01:14:50 +0000622def PICLDSB : AXI3<(outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623 "${addr:label}:\n\tldr${p}sb $dst, $addr",
624 [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
625}
626let isStore = 1, AddedComplexity = 10 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000627def PICSTR : AXI2<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000628 "${addr:label}:\n\tstr$p $src, $addr",
629 [(store GPR:$src, addrmodepc:$addr)]>;
630
Evan Chengb783fa32007-07-19 01:14:50 +0000631def PICSTRH : AXI3<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632 "${addr:label}:\n\tstr${p}h $src, $addr",
633 [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
634
Evan Chengb783fa32007-07-19 01:14:50 +0000635def PICSTRB : AXI2<(outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000636 "${addr:label}:\n\tstr${p}b $src, $addr",
637 [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
638}
639}
640
641//===----------------------------------------------------------------------===//
642// Control Flow Instructions.
643//
644
645let isReturn = 1, isTerminator = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000646 def BX_RET : AI<(outs), (ins), "bx", " lr", [(ARMretflag)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000647
648// FIXME: remove when we have a way to marking a MI with these properties.
Evan Chengb783fa32007-07-19 01:14:50 +0000649// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
650// operand list.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651let isLoad = 1, isReturn = 1, isTerminator = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000652 def LDM_RET : AXI4<(outs),
653 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654 "ldm${p}${addr:submode} $addr, $dst1",
655 []>;
656
657let isCall = 1, noResults = 1,
658 Defs = [R0, R1, R2, R3, R12, LR,
659 D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000660 def BL : AXI<(outs), (ins i32imm:$func, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000661 "bl ${func:call}",
662 [(ARMcall tglobaladdr:$func)]>;
663
Evan Chengb783fa32007-07-19 01:14:50 +0000664 def BL_pred : AI<(outs), (ins i32imm:$func, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000665 "bl", " ${func:call}",
666 [(ARMcall_pred tglobaladdr:$func)]>;
667
668 // ARMv5T and above
Evan Chengb783fa32007-07-19 01:14:50 +0000669 def BLX : AXI<(outs), (ins GPR:$func, variable_ops),
670 "blx $func",
671 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000672 let Uses = [LR] in {
673 // ARMv4T
Evan Chengb783fa32007-07-19 01:14:50 +0000674 def BX : AXIx2<(outs), (ins GPR:$func, variable_ops),
675 "mov lr, pc\n\tbx $func",
676 [(ARMcall_nolink GPR:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000677 }
678}
679
680let isBranch = 1, isTerminator = 1, noResults = 1 in {
681 // B is "predicable" since it can be xformed into a Bcc.
682 let isBarrier = 1 in {
683 let isPredicable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000684 def B : AXI<(outs), (ins brtarget:$target), "b $target",
685 [(br bb:$target)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000686
687 let isNotDuplicable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000688 def BR_JTr : JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
689 "mov pc, $target \n$jt",
690 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
691 def BR_JTm : JTI2<(outs), (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
692 "ldr pc, $target \n$jt",
693 [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694 imm:$id)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000695 def BR_JTadd : JTI1<(outs), (ins GPR:$target, GPR:$idx, jtblock_operand:$jt,
696 i32imm:$id),
697 "add pc, $target, $idx \n$jt",
698 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000699 imm:$id)]>;
700 }
701 }
702
703 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
704 // a two-value operand where a dag node expects two operands. :(
Evan Chengb783fa32007-07-19 01:14:50 +0000705 def Bcc : AI<(outs), (ins brtarget:$target), "b", " $target",
706 [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000707}
708
709//===----------------------------------------------------------------------===//
710// Load / store Instructions.
711//
712
713// Load
714let isLoad = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000715def LDR : AI2<(outs GPR:$dst), (ins addrmode2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 "ldr", " $dst, $addr",
717 [(set GPR:$dst, (load addrmode2:$addr))]>;
718
719// Special LDR for loads from non-pc-relative constpools.
720let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000721def LDRcp : AI2<(outs GPR:$dst), (ins addrmode2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000722 "ldr", " $dst, $addr", []>;
723
724// Loads with zero extension
Evan Chengb783fa32007-07-19 01:14:50 +0000725def LDRH : AI3<(outs GPR:$dst), (ins addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000726 "ldr", "h $dst, $addr",
727 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
728
Evan Chengb783fa32007-07-19 01:14:50 +0000729def LDRB : AI2<(outs GPR:$dst), (ins addrmode2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000730 "ldr", "b $dst, $addr",
731 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
732
733// Loads with sign extension
Evan Chengb783fa32007-07-19 01:14:50 +0000734def LDRSH : AI3<(outs GPR:$dst), (ins addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000735 "ldr", "sh $dst, $addr",
736 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
737
Evan Chengb783fa32007-07-19 01:14:50 +0000738def LDRSB : AI3<(outs GPR:$dst), (ins addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739 "ldr", "sb $dst, $addr",
740 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
741
742// Load doubleword
Evan Chengb783fa32007-07-19 01:14:50 +0000743def LDRD : AI3<(outs GPR:$dst), (ins addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000744 "ldr", "d $dst, $addr",
745 []>, Requires<[IsARM, HasV5T]>;
746
747// Indexed loads
Evan Chengb783fa32007-07-19 01:14:50 +0000748def LDR_PRE : AI2pr<(outs GPR:$dst), (ins GPR:$base_wb, addrmode2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000749 "ldr", " $dst, $addr!", "$addr.base = $base_wb", []>;
750
Evan Chengb783fa32007-07-19 01:14:50 +0000751def LDR_POST : AI2po<(outs GPR:$dst), (ins GPR:$base_wb, GPR:$base, am2offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000752 "ldr", " $dst, [$base], $offset", "$base = $base_wb", []>;
753
Evan Chengb783fa32007-07-19 01:14:50 +0000754def LDRH_PRE : AI3pr<(outs GPR:$dst), (ins GPR:$base_wb, addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000755 "ldr", "h $dst, $addr!", "$addr.base = $base_wb", []>;
756
Evan Chengb783fa32007-07-19 01:14:50 +0000757def LDRH_POST : AI3po<(outs GPR:$dst), (ins GPR:$base_wb, GPR:$base,am3offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000758 "ldr", "h $dst, [$base], $offset", "$base = $base_wb", []>;
759
Evan Chengb783fa32007-07-19 01:14:50 +0000760def LDRB_PRE : AI2pr<(outs GPR:$dst), (ins GPR:$base_wb, addrmode2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000761 "ldr", "b $dst, $addr!", "$addr.base = $base_wb", []>;
762
Evan Chengb783fa32007-07-19 01:14:50 +0000763def LDRB_POST : AI2po<(outs GPR:$dst), (ins GPR:$base_wb, GPR:$base,am2offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764 "ldr", "b $dst, [$base], $offset", "$base = $base_wb", []>;
765
Evan Chengb783fa32007-07-19 01:14:50 +0000766def LDRSH_PRE : AI3pr<(outs GPR:$dst), (ins GPR:$base_wb, addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000767 "ldr", "sh $dst, $addr!", "$addr.base = $base_wb", []>;
768
Evan Chengb783fa32007-07-19 01:14:50 +0000769def LDRSH_POST: AI3po<(outs GPR:$dst), (ins GPR:$base_wb, GPR:$base,am3offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000770 "ldr", "sh $dst, [$base], $offset", "$base = $base_wb", []>;
771
Evan Chengb783fa32007-07-19 01:14:50 +0000772def LDRSB_PRE : AI3pr<(outs GPR:$dst), (ins GPR:$base_wb, addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 "ldr", "sb $dst, $addr!", "$addr.base = $base_wb", []>;
774
Evan Chengb783fa32007-07-19 01:14:50 +0000775def LDRSB_POST: AI3po<(outs GPR:$dst), (ins GPR:$base_wb, GPR:$base,am3offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776 "ldr", "sb $dst, [$base], $offset", "$base = $base_wb", []>;
777} // isLoad
778
779// Store
780let isStore = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000781def STR : AI2<(outs), (ins GPR:$src, addrmode2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000782 "str", " $src, $addr",
783 [(store GPR:$src, addrmode2:$addr)]>;
784
785// Stores with truncate
Evan Chengb783fa32007-07-19 01:14:50 +0000786def STRH : AI3<(outs), (ins GPR:$src, addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000787 "str", "h $src, $addr",
788 [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
789
Evan Chengb783fa32007-07-19 01:14:50 +0000790def STRB : AI2<(outs), (ins GPR:$src, addrmode2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000791 "str", "b $src, $addr",
792 [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
793
794// Store doubleword
Evan Chengb783fa32007-07-19 01:14:50 +0000795def STRD : AI3<(outs), (ins GPR:$src, addrmode3:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 "str", "d $src, $addr",
797 []>, Requires<[IsARM, HasV5T]>;
798
799// Indexed stores
Evan Chengb783fa32007-07-19 01:14:50 +0000800def STR_PRE : AI2pr<(outs GPR:$base_wb),
801 (ins GPR:$src, GPR:$base, am2offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000802 "str", " $src, [$base, $offset]!", "$base = $base_wb",
803 [(set GPR:$base_wb,
804 (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
805
Evan Chengb783fa32007-07-19 01:14:50 +0000806def STR_POST : AI2po<(outs GPR:$base_wb),
807 (ins GPR:$src, GPR:$base,am2offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808 "str", " $src, [$base], $offset", "$base = $base_wb",
809 [(set GPR:$base_wb,
810 (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
811
Evan Chengb783fa32007-07-19 01:14:50 +0000812def STRH_PRE : AI3pr<(outs GPR:$base_wb),
813 (ins GPR:$src, GPR:$base,am3offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000814 "str", "h $src, [$base, $offset]!", "$base = $base_wb",
815 [(set GPR:$base_wb,
816 (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
817
Evan Chengb783fa32007-07-19 01:14:50 +0000818def STRH_POST: AI3po<(outs GPR:$base_wb),
819 (ins GPR:$src, GPR:$base,am3offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000820 "str", "h $src, [$base], $offset", "$base = $base_wb",
821 [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
822 GPR:$base, am3offset:$offset))]>;
823
Evan Chengb783fa32007-07-19 01:14:50 +0000824def STRB_PRE : AI2pr<(outs GPR:$base_wb),
825 (ins GPR:$src, GPR:$base,am2offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000826 "str", "b $src, [$base, $offset]!", "$base = $base_wb",
827 [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
828 GPR:$base, am2offset:$offset))]>;
829
Evan Chengb783fa32007-07-19 01:14:50 +0000830def STRB_POST: AI2po<(outs GPR:$base_wb),
831 (ins GPR:$src, GPR:$base,am2offset:$offset),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000832 "str", "b $src, [$base], $offset", "$base = $base_wb",
833 [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
834 GPR:$base, am2offset:$offset))]>;
835} // isStore
836
837//===----------------------------------------------------------------------===//
838// Load / store multiple Instructions.
839//
840
Evan Chengb783fa32007-07-19 01:14:50 +0000841// FIXME: $dst1 should be a def.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842let isLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000843def LDM : AXI4<(outs),
844 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000845 "ldm${p}${addr:submode} $addr, $dst1",
846 []>;
847
848let isStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000849def STM : AXI4<(outs),
850 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000851 "stm${p}${addr:submode} $addr, $src1",
852 []>;
853
854//===----------------------------------------------------------------------===//
855// Move Instructions.
856//
857
Evan Chengb783fa32007-07-19 01:14:50 +0000858def MOVr : AsI1<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859 "mov", " $dst, $src", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000860def MOVs : AsI1<(outs GPR:$dst), (ins so_reg:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861 "mov", " $dst, $src", [(set GPR:$dst, so_reg:$src)]>;
862
863let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000864def MOVi : AsI1<(outs GPR:$dst), (ins so_imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865 "mov", " $dst, $src", [(set GPR:$dst, so_imm:$src)]>;
866
Evan Chengb783fa32007-07-19 01:14:50 +0000867def MOVrx : AsI1<(outs GPR:$dst), (ins GPR:$src),
868 "mov", " $dst, $src, rrx",
869 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870
871// These aren't really mov instructions, but we have to define them this way
872// due to flag operands.
873
Evan Chengb783fa32007-07-19 01:14:50 +0000874def MOVsrl_flag : AI1<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000875 "mov", "s $dst, $src, lsr #1",
876 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>, Imp<[], [CPSR]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000877def MOVsra_flag : AI1<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000878 "mov", "s $dst, $src, asr #1",
879 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>, Imp<[], [CPSR]>;
880
881//===----------------------------------------------------------------------===//
882// Extend Instructions.
883//
884
885// Sign extenders
886
887defm SXTB : AI_unary_rrot<"sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
888defm SXTH : AI_unary_rrot<"sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
889
890defm SXTAB : AI_bin_rrot<"sxtab",
891 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
892defm SXTAH : AI_bin_rrot<"sxtah",
893 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
894
895// TODO: SXT(A){B|H}16
896
897// Zero extenders
898
899let AddedComplexity = 16 in {
900defm UXTB : AI_unary_rrot<"uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
901defm UXTH : AI_unary_rrot<"uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
902defm UXTB16 : AI_unary_rrot<"uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
903
904def : ARMV6Pat<(and (shl GPR:$Src, 8), 0xFF00FF),
905 (UXTB16r_rot GPR:$Src, 24)>;
906def : ARMV6Pat<(and (srl GPR:$Src, 8), 0xFF00FF),
907 (UXTB16r_rot GPR:$Src, 8)>;
908
909defm UXTAB : AI_bin_rrot<"uxtab",
910 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
911defm UXTAH : AI_bin_rrot<"uxtah",
912 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
913}
914
915// This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
916//defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
917
918// TODO: UXT(A){B|H}16
919
920//===----------------------------------------------------------------------===//
921// Arithmetic Instructions.
922//
923
924defm ADD : AsI1_bin_irs<"add", BinOpFrag<(add node:$LHS, node:$RHS)>>;
925defm SUB : AsI1_bin_irs<"sub", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
926
927// ADD and SUB with 's' bit set.
928defm ADDS : ASI1_bin_s_irs<"add", BinOpFrag<(addc node:$LHS, node:$RHS)>>;
929defm SUBS : ASI1_bin_s_irs<"sub", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
930
931// FIXME: Do not allow ADC / SBC to be predicated for now.
932defm ADC : AsXI1_bin_c_irs<"adc", BinOpFrag<(adde node:$LHS, node:$RHS)>>;
933defm SBC : AsXI1_bin_c_irs<"sbc", BinOpFrag<(sube node:$LHS, node:$RHS)>>;
934
935// These don't define reg/reg forms, because they are handled above.
Evan Chengb783fa32007-07-19 01:14:50 +0000936def RSBri : AsI1<(outs GPR:$dst), (ins GPR:$a, so_imm:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000937 "rsb", " $dst, $a, $b",
938 [(set GPR:$dst, (sub so_imm:$b, GPR:$a))]>;
939
Evan Chengb783fa32007-07-19 01:14:50 +0000940def RSBrs : AsI1<(outs GPR:$dst), (ins GPR:$a, so_reg:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000941 "rsb", " $dst, $a, $b",
942 [(set GPR:$dst, (sub so_reg:$b, GPR:$a))]>;
943
944// RSB with 's' bit set.
Evan Chengb783fa32007-07-19 01:14:50 +0000945def RSBSri : AI1<(outs GPR:$dst), (ins GPR:$a, so_imm:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000946 "rsb", "s $dst, $a, $b",
947 [(set GPR:$dst, (subc so_imm:$b, GPR:$a))]>, Imp<[], [CPSR]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000948def RSBSrs : AI1<(outs GPR:$dst), (ins GPR:$a, so_reg:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000949 "rsb", "s $dst, $a, $b",
950 [(set GPR:$dst, (subc so_reg:$b, GPR:$a))]>, Imp<[], [CPSR]>;
951
952// FIXME: Do not allow RSC to be predicated for now. But they can set CPSR.
Evan Chengb783fa32007-07-19 01:14:50 +0000953def RSCri : AXI1<(outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000954 "rsc${s} $dst, $a, $b",
955 [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>, Imp<[CPSR], []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000956def RSCrs : AXI1<(outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000957 "rsc${s} $dst, $a, $b",
958 [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>, Imp<[CPSR], []>;
959
960// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
961def : ARMPat<(add GPR:$src, so_imm_neg:$imm),
962 (SUBri GPR:$src, so_imm_neg:$imm)>;
963
964//def : ARMPat<(addc GPR:$src, so_imm_neg:$imm),
965// (SUBSri GPR:$src, so_imm_neg:$imm)>;
966//def : ARMPat<(adde GPR:$src, so_imm_neg:$imm),
967// (SBCri GPR:$src, so_imm_neg:$imm)>;
968
969// Note: These are implemented in C++ code, because they have to generate
970// ADD/SUBrs instructions, which use a complex pattern that a xform function
971// cannot produce.
972// (mul X, 2^n+1) -> (add (X << n), X)
973// (mul X, 2^n-1) -> (rsb X, (X << n))
974
975
976//===----------------------------------------------------------------------===//
977// Bitwise Instructions.
978//
979
980defm AND : AsI1_bin_irs<"and", BinOpFrag<(and node:$LHS, node:$RHS)>>;
981defm ORR : AsI1_bin_irs<"orr", BinOpFrag<(or node:$LHS, node:$RHS)>>;
982defm EOR : AsI1_bin_irs<"eor", BinOpFrag<(xor node:$LHS, node:$RHS)>>;
983defm BIC : AsI1_bin_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
984
Evan Chengb783fa32007-07-19 01:14:50 +0000985def MVNr : AsI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000986 "mvn", " $dst, $src", [(set GPR:$dst, (not GPR:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000987def MVNs : AsI<(outs GPR:$dst), (ins so_reg:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000988 "mvn", " $dst, $src", [(set GPR:$dst, (not so_reg:$src))]>;
989let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000990def MVNi : AsI<(outs GPR:$dst), (ins so_imm:$imm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000991 "mvn", " $dst, $imm", [(set GPR:$dst, so_imm_not:$imm)]>;
992
993def : ARMPat<(and GPR:$src, so_imm_not:$imm),
994 (BICri GPR:$src, so_imm_not:$imm)>;
995
996//===----------------------------------------------------------------------===//
997// Multiply Instructions.
998//
999
Evan Chengb783fa32007-07-19 01:14:50 +00001000def MUL : AsI<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001001 "mul", " $dst, $a, $b",
1002 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
1003
Evan Chengb783fa32007-07-19 01:14:50 +00001004def MLA : AsI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001005 "mla", " $dst, $a, $b, $c",
1006 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
1007
1008// Extra precision multiplies with low / high results
Evan Chengb783fa32007-07-19 01:14:50 +00001009def SMULL : AsI<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001010 "smull", " $ldst, $hdst, $a, $b", []>;
1011
Evan Chengb783fa32007-07-19 01:14:50 +00001012def UMULL : AsI<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001013 "umull", " $ldst, $hdst, $a, $b", []>;
1014
1015// Multiply + accumulate
Evan Chengb783fa32007-07-19 01:14:50 +00001016def SMLAL : AsI<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001017 "smlal", " $ldst, $hdst, $a, $b", []>;
1018
Evan Chengb783fa32007-07-19 01:14:50 +00001019def UMLAL : AsI<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001020 "umlal", " $ldst, $hdst, $a, $b", []>;
1021
Evan Chengb783fa32007-07-19 01:14:50 +00001022def UMAAL : AI<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023 "umaal", " $ldst, $hdst, $a, $b", []>,
1024 Requires<[IsARM, HasV6]>;
1025
1026// Most significant word multiply
Evan Chengb783fa32007-07-19 01:14:50 +00001027def SMMUL : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001028 "smmul", " $dst, $a, $b",
1029 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>,
1030 Requires<[IsARM, HasV6]>;
1031
Evan Chengb783fa32007-07-19 01:14:50 +00001032def SMMLA : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033 "smmla", " $dst, $a, $b, $c",
1034 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>,
1035 Requires<[IsARM, HasV6]>;
1036
1037
Evan Chengb783fa32007-07-19 01:14:50 +00001038def SMMLS : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001039 "smmls", " $dst, $a, $b, $c",
1040 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
1041 Requires<[IsARM, HasV6]>;
1042
1043multiclass AI_smul<string opc, PatFrag opnode> {
Evan Chengb783fa32007-07-19 01:14:50 +00001044 def BB : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001045 !strconcat(opc, "bb"), " $dst, $a, $b",
1046 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1047 (sext_inreg GPR:$b, i16)))]>,
1048 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001049 def BT : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001050 !strconcat(opc, "bt"), " $dst, $a, $b",
1051 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1052 (sra GPR:$b, 16)))]>,
1053 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001054 def TB : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001055 !strconcat(opc, "tb"), " $dst, $a, $b",
1056 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
1057 (sext_inreg GPR:$b, i16)))]>,
1058 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001059 def TT : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001060 !strconcat(opc, "tt"), " $dst, $a, $b",
1061 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
1062 (sra GPR:$b, 16)))]>,
1063 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001064 def WB : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001065 !strconcat(opc, "wb"), " $dst, $a, $b",
1066 [(set GPR:$dst, (sra (opnode GPR:$a,
1067 (sext_inreg GPR:$b, i16)), 16))]>,
1068 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001069 def WT : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001070 !strconcat(opc, "wt"), " $dst, $a, $b",
1071 [(set GPR:$dst, (sra (opnode GPR:$a,
1072 (sra GPR:$b, 16)), 16))]>,
1073 Requires<[IsARM, HasV5TE]>;
1074}
1075
1076multiclass AI_smla<string opc, PatFrag opnode> {
Evan Chengb783fa32007-07-19 01:14:50 +00001077 def BB : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078 !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
1079 [(set GPR:$dst, (add GPR:$acc,
1080 (opnode (sext_inreg GPR:$a, i16),
1081 (sext_inreg GPR:$b, i16))))]>,
1082 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001083 def BT : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084 !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
1085 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
1086 (sra GPR:$b, 16))))]>,
1087 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001088 def TB : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001089 !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
1090 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1091 (sext_inreg GPR:$b, i16))))]>,
1092 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001093 def TT : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001094 !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
1095 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1096 (sra GPR:$b, 16))))]>,
1097 Requires<[IsARM, HasV5TE]>;
1098
Evan Chengb783fa32007-07-19 01:14:50 +00001099 def WB : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001100 !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
1101 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1102 (sext_inreg GPR:$b, i16)), 16)))]>,
1103 Requires<[IsARM, HasV5TE]>;
Evan Chengb783fa32007-07-19 01:14:50 +00001104 def WT : AI<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001105 !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
1106 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1107 (sra GPR:$b, 16)), 16)))]>,
1108 Requires<[IsARM, HasV5TE]>;
1109}
1110
1111defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1112defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1113
1114// TODO: Halfword multiple accumulate long: SMLAL<x><y>
1115// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
1116
1117//===----------------------------------------------------------------------===//
1118// Misc. Arithmetic Instructions.
1119//
1120
Evan Chengb783fa32007-07-19 01:14:50 +00001121def CLZ : AI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001122 "clz", " $dst, $src",
1123 [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]>;
1124
Evan Chengb783fa32007-07-19 01:14:50 +00001125def REV : AI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126 "rev", " $dst, $src",
1127 [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]>;
1128
Evan Chengb783fa32007-07-19 01:14:50 +00001129def REV16 : AI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001130 "rev16", " $dst, $src",
1131 [(set GPR:$dst,
1132 (or (and (srl GPR:$src, 8), 0xFF),
1133 (or (and (shl GPR:$src, 8), 0xFF00),
1134 (or (and (srl GPR:$src, 8), 0xFF0000),
1135 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
1136 Requires<[IsARM, HasV6]>;
1137
Evan Chengb783fa32007-07-19 01:14:50 +00001138def REVSH : AI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001139 "revsh", " $dst, $src",
1140 [(set GPR:$dst,
1141 (sext_inreg
1142 (or (srl (and GPR:$src, 0xFF00), 8),
1143 (shl GPR:$src, 8)), i16))]>,
1144 Requires<[IsARM, HasV6]>;
1145
Evan Chengb783fa32007-07-19 01:14:50 +00001146def PKHBT : AI<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001147 "pkhbt", " $dst, $src1, $src2, LSL $shamt",
1148 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1149 (and (shl GPR:$src2, (i32 imm:$shamt)),
1150 0xFFFF0000)))]>,
1151 Requires<[IsARM, HasV6]>;
1152
1153// Alternate cases for PKHBT where identities eliminate some nodes.
1154def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1155 (PKHBT GPR:$src1, GPR:$src2, 0)>;
1156def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1157 (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
1158
1159
Evan Chengb783fa32007-07-19 01:14:50 +00001160def PKHTB : AI<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001161 "pkhtb", " $dst, $src1, $src2, ASR $shamt",
1162 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1163 (and (sra GPR:$src2, imm16_31:$shamt),
1164 0xFFFF)))]>, Requires<[IsARM, HasV6]>;
1165
1166// Alternate cases for PKHTB where identities eliminate some nodes. Note that
1167// a shift amount of 0 is *not legal* here, it is PKHBT instead.
1168def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, 16)),
1169 (PKHTB GPR:$src1, GPR:$src2, 16)>;
1170def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1171 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1172 (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1173
1174
1175//===----------------------------------------------------------------------===//
1176// Comparison Instructions...
1177//
1178
1179defm CMP : AI1_cmp_irs<"cmp", BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1180defm CMN : AI1_cmp_irs<"cmn", BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
1181
1182// Note that TST/TEQ don't set all the same flags that CMP does!
1183defm TST : AI1_cmp_irs<"tst", BinOpFrag<(ARMcmpNZ (and node:$LHS, node:$RHS), 0)>>;
1184defm TEQ : AI1_cmp_irs<"teq", BinOpFrag<(ARMcmpNZ (xor node:$LHS, node:$RHS), 0)>>;
1185
1186defm CMPnz : AI1_cmp_irs<"cmp", BinOpFrag<(ARMcmpNZ node:$LHS, node:$RHS)>>;
1187defm CMNnz : AI1_cmp_irs<"cmn", BinOpFrag<(ARMcmpNZ node:$LHS,(ineg node:$RHS))>>;
1188
1189def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1190 (CMNri GPR:$src, so_imm_neg:$imm)>;
1191
1192def : ARMPat<(ARMcmpNZ GPR:$src, so_imm_neg:$imm),
1193 (CMNri GPR:$src, so_imm_neg:$imm)>;
1194
1195
1196// Conditional moves
1197// FIXME: should be able to write a pattern for ARMcmov, but can't use
1198// a two-value operand where a dag node expects two operands. :(
Evan Chengb783fa32007-07-19 01:14:50 +00001199def MOVCCr : AI<(outs GPR:$dst), (ins GPR:$false, GPR:$true),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001200 "mov", " $dst, $true",
1201 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1202 RegConstraint<"$false = $dst">;
1203
Evan Chengb783fa32007-07-19 01:14:50 +00001204def MOVCCs : AI<(outs GPR:$dst), (ins GPR:$false, so_reg:$true),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001205 "mov", " $dst, $true",
1206 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1207 RegConstraint<"$false = $dst">;
1208
Evan Chengb783fa32007-07-19 01:14:50 +00001209def MOVCCi : AI<(outs GPR:$dst), (ins GPR:$false, so_imm:$true),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001210 "mov", " $dst, $true",
1211 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1212 RegConstraint<"$false = $dst">;
1213
1214
1215// LEApcrel - Load a pc-relative address into a register without offending the
1216// assembler.
Evan Chengb783fa32007-07-19 01:14:50 +00001217def LEApcrel : AXI1<(outs GPR:$dst), (ins i32imm:$label, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001218 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
1219 "${:private}PCRELL${:uid}+8))\n"),
1220 !strconcat("${:private}PCRELL${:uid}:\n\t",
1221 "add$p $dst, pc, #PCRELV${:uid}")),
1222 []>;
1223
Evan Chengb783fa32007-07-19 01:14:50 +00001224def LEApcrelJT : AXI1<(outs GPR:$dst), (ins i32imm:$label, i32imm:$id, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001225 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
1226 "${:private}PCRELL${:uid}+8))\n"),
1227 !strconcat("${:private}PCRELL${:uid}:\n\t",
1228 "add$p $dst, pc, #PCRELV${:uid}")),
1229 []>;
1230
1231//===----------------------------------------------------------------------===//
1232// TLS Instructions
1233//
1234
1235// __aeabi_read_tp preserves the registers r1-r3.
1236let isCall = 1,
1237 Defs = [R0, R12, LR, CPSR] in {
Evan Chengb783fa32007-07-19 01:14:50 +00001238 def TPsoft : AXI<(outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001239 "bl __aeabi_read_tp",
1240 [(set R0, ARMthread_pointer)]>;
1241}
1242
1243//===----------------------------------------------------------------------===//
1244// Non-Instruction Patterns
1245//
1246
1247// ConstantPool, GlobalAddress, and JumpTable
1248def : ARMPat<(ARMWrapper tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>;
1249def : ARMPat<(ARMWrapper tconstpool :$dst), (LEApcrel tconstpool :$dst)>;
1250def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1251 (LEApcrelJT tjumptable:$dst, imm:$id)>;
1252
1253// Large immediate handling.
1254
1255// Two piece so_imms.
1256let isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +00001257def MOVi2pieces : AI1x2<(outs GPR:$dst), (ins so_imm2part:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001258 "mov", " $dst, $src",
1259 [(set GPR:$dst, so_imm2part:$src)]>;
1260
1261def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1262 (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1263 (so_imm2part_2 imm:$RHS))>;
1264def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1265 (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1266 (so_imm2part_2 imm:$RHS))>;
1267
1268// TODO: add,sub,and, 3-instr forms?
1269
1270
1271// Direct calls
1272def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>;
1273
1274// zextload i1 -> zextload i8
1275def : ARMPat<(zextloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1276
1277// extload -> zextload
1278def : ARMPat<(extloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1279def : ARMPat<(extloadi8 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1280def : ARMPat<(extloadi16 addrmode3:$addr), (LDRH addrmode3:$addr)>;
1281
1282// truncstore i1 -> truncstore i8
1283def : ARMPat<(truncstorei1 GPR:$src, addrmode2:$dst),
1284 (STRB GPR:$src, addrmode2:$dst)>;
1285def : ARMPat<(pre_truncsti1 GPR:$src, GPR:$base, am2offset:$offset),
1286 (STRB_PRE GPR:$src, GPR:$base, am2offset:$offset)>;
1287def : ARMPat<(post_truncsti1 GPR:$src, GPR:$base, am2offset:$offset),
1288 (STRB_POST GPR:$src, GPR:$base, am2offset:$offset)>;
1289
1290// smul* and smla*
1291def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra (shl GPR:$b, 16), 16)),
1292 (SMULBB GPR:$a, GPR:$b)>;
1293def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1294 (SMULBB GPR:$a, GPR:$b)>;
1295def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16)),
1296 (SMULBT GPR:$a, GPR:$b)>;
1297def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, 16)),
1298 (SMULBT GPR:$a, GPR:$b)>;
1299def : ARMV5TEPat<(mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16)),
1300 (SMULTB GPR:$a, GPR:$b)>;
1301def : ARMV5TEPat<(mul (sra GPR:$a, 16), sext_16_node:$b),
1302 (SMULTB GPR:$a, GPR:$b)>;
1303def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16),
1304 (SMULWB GPR:$a, GPR:$b)>;
1305def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), 16),
1306 (SMULWB GPR:$a, GPR:$b)>;
1307
1308def : ARMV5TEPat<(add GPR:$acc,
1309 (mul (sra (shl GPR:$a, 16), 16),
1310 (sra (shl GPR:$b, 16), 16))),
1311 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1312def : ARMV5TEPat<(add GPR:$acc,
1313 (mul sext_16_node:$a, sext_16_node:$b)),
1314 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1315def : ARMV5TEPat<(add GPR:$acc,
1316 (mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16))),
1317 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1318def : ARMV5TEPat<(add GPR:$acc,
1319 (mul sext_16_node:$a, (sra GPR:$b, 16))),
1320 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1321def : ARMV5TEPat<(add GPR:$acc,
1322 (mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16))),
1323 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1324def : ARMV5TEPat<(add GPR:$acc,
1325 (mul (sra GPR:$a, 16), sext_16_node:$b)),
1326 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1327def : ARMV5TEPat<(add GPR:$acc,
1328 (sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16)),
1329 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1330def : ARMV5TEPat<(add GPR:$acc,
1331 (sra (mul GPR:$a, sext_16_node:$b), 16)),
1332 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1333
1334//===----------------------------------------------------------------------===//
1335// Thumb Support
1336//
1337
1338include "ARMInstrThumb.td"
1339
1340//===----------------------------------------------------------------------===//
1341// Floating Point Support
1342//
1343
1344include "ARMInstrVFP.td"