blob: 2709fc83509d1c65031c5debaba5952ba6cb1239 [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
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
Bill Wendling7173da52007-11-13 09:19:02 +000048def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049 [SDNPHasChain, SDNPOutFlag]>;
Bill Wendling7173da52007-11-13 09:19:02 +000050def ARMcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_ARMCallSeqEnd,
Bill Wendling22f8deb2007-11-13 00:44:25 +000051 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052
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//===----------------------------------------------------------------------===//
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000333// ARM Instruction Format Definitions.
334//
335
336// Format specifies the encoding used by the instruction. This is part of the
337// ad-hoc solution used to emit machine instruction encodings by our machine
338// code emitter.
339class Format<bits<5> val> {
340 bits<5> Value = val;
341}
342
343def Pseudo : Format<1>;
344def MulFrm : Format<2>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000345def MulSMLAW : Format<3>;
346def MulSMULW : Format<4>;
347def MulSMLA : Format<5>;
348def MulSMUL : Format<6>;
349def Branch : Format<7>;
350def BranchMisc : Format<8>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000351
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000352def DPRdIm : Format<9>;
353def DPRdReg : Format<10>;
354def DPRdSoReg : Format<11>;
355def DPRdMisc : Format<12>;
356def DPRnIm : Format<13>;
357def DPRnReg : Format<14>;
358def DPRnSoReg : Format<15>;
359def DPRIm : Format<16>;
360def DPRReg : Format<17>;
361def DPRSoReg : Format<18>;
362def DPRImS : Format<19>;
363def DPRRegS : Format<20>;
364def DPRSoRegS : Format<21>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000365
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000366def LdFrm : Format<22>;
367def StFrm : Format<23>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000368
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000369def ArithMisc : Format<24>;
370def ThumbFrm : Format<25>;
371def VFPFrm : Format<26>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000372
373
374
375//===----------------------------------------------------------------------===//
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000376
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000377// ARM Instruction templates.
378//
379
380// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
381class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
382 list<Predicate> Predicates = [IsARM];
383}
384class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
385 list<Predicate> Predicates = [IsARM, HasV5TE];
386}
387class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
388 list<Predicate> Predicates = [IsARM, HasV6];
389}
390
391class InstARM<bits<4> opcod, AddrMode am, SizeFlagVal sz, IndexMode im,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000392 Format f, string cstr>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393 : Instruction {
394 let Namespace = "ARM";
395
396 bits<4> Opcode = opcod;
397 AddrMode AM = am;
398 bits<4> AddrModeBits = AM.Value;
399
400 SizeFlagVal SZ = sz;
401 bits<3> SizeFlag = SZ.Value;
402
403 IndexMode IM = im;
404 bits<2> IndexModeBits = IM.Value;
405
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000406 Format F = f;
407 bits<5> Form = F.Value;
408
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409 let Constraints = cstr;
410}
411
Evan Chengb783fa32007-07-19 01:14:50 +0000412class PseudoInst<dag oops, dag iops, string asm, list<dag> pattern>
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000413 : InstARM<0, AddrModeNone, SizeSpecial, IndexModeNone, Pseudo, ""> {
Evan Chengb783fa32007-07-19 01:14:50 +0000414 let OutOperandList = oops;
415 let InOperandList = iops;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000416 let AsmString = asm;
417 let Pattern = pattern;
418}
419
420// Almost all ARM instructions are predicable.
Evan Chengcce0af52007-09-10 22:22:23 +0000421class I<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
422 IndexMode im, Format f, string opc, string asm, string cstr,
423 list<dag> pattern>
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000424 : InstARM<opcod, am, sz, im, f, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000425 let OutOperandList = oops;
426 let InOperandList = !con(iops, (ops pred:$p));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000427 let AsmString = !strconcat(opc, !strconcat("${p}", asm));
428 let Pattern = pattern;
429 list<Predicate> Predicates = [IsARM];
430}
431
Evan Chengb783fa32007-07-19 01:14:50 +0000432// Same as I except it can optionally modify CPSR. Note it's modeled as
433// an input operand since by default it's a zero register. It will
434// become an implicit def once it's "flipped".
Evan Chengcce0af52007-09-10 22:22:23 +0000435class sI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
436 IndexMode im, Format f, string opc, string asm, string cstr,
437 list<dag> pattern>
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000438 : InstARM<opcod, am, sz, im, f, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000439 let OutOperandList = oops;
440 let InOperandList = !con(iops, (ops pred:$p, cc_out:$s));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000441 let AsmString = !strconcat(opc, !strconcat("${p}${s}", asm));
442 let Pattern = pattern;
443 list<Predicate> Predicates = [IsARM];
444}
445
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000446class AI<bits<4> opcod, dag oops, dag iops, Format f, string opc,
447 string asm, list<dag> pattern>
448 : I<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, opc,
449 asm,"",pattern>;
450class AsI<bits<4> opcod, dag oops, dag iops, Format f, string opc,
451 string asm, list<dag> pattern>
452 : sI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, opc,
453 asm,"",pattern>;
454class AI1<bits<4> opcod, dag oops, dag iops, Format f, string opc,
455 string asm, list<dag> pattern>
456 : I<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc,
457 asm, "", pattern>;
458class AsI1<bits<4> opcod, dag oops, dag iops, Format f, string opc,
459 string asm, list<dag> pattern>
460 : sI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc,
461 asm, "", pattern>;
462class AI2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
463 string asm, list<dag> pattern>
464 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, opc,
465 asm, "", pattern>;
466class AI3<bits<4> opcod, dag oops, dag iops, Format f, string opc,
467 string asm, list<dag> pattern>
468 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, opc,
469 asm, "", pattern>;
470class AI4<bits<4> opcod, dag oops, dag iops, Format f, string opc,
471 string asm, list<dag> pattern>
472 : I<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, opc,
473 asm, "", pattern>;
474class AI1x2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
475 string asm, list<dag> pattern>
476 : I<opcod, oops, iops, AddrMode1, Size8Bytes, IndexModeNone, f, opc,
477 asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478
479// Pre-indexed ops
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000480class AI2pr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
481 string asm, string cstr, list<dag> pattern>
482 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
483 asm, cstr, pattern>;
484class AI3pr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
485 string asm, string cstr, list<dag> pattern>
486 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePre, f, opc,
487 asm, cstr, pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000488
489// Post-indexed ops
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000490class AI2po<bits<4> opcod, dag oops, dag iops, Format f, string opc,
491 string asm, string cstr, list<dag> pattern>
492 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
493 asm, cstr,pattern>;
494class AI3po<bits<4> opcod, dag oops, dag iops, Format f, string opc,
495 string asm, string cstr, list<dag> pattern>
496 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePost, f, opc,
497 asm, cstr,pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498
499
500class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
501class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
502
503
504/// AI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
505/// binop that produces a value.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000506multiclass AsI1_bin_irs<bits<4> opcod, string opc, PatFrag opnode> {
507 def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508 opc, " $dst, $a, $b",
509 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000510 def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPRReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511 opc, " $dst, $a, $b",
512 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000513 def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000514 opc, " $dst, $a, $b",
515 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
516}
517
518/// ASI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
519/// instruction modifies the CSPR register.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000520let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000521multiclass ASI1_bin_s_irs<bits<4> opcod, string opc, PatFrag opnode> {
522 def ri : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRImS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000523 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000524 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000525 def rr : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPRRegS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000527 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000528 def rs : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoRegS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000530 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
531}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532}
533
534/// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
535/// patterns. Similar to AsI1_bin_irs except the instruction does not produce
536/// a explicit result, only implicitly set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000537let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000538multiclass AI1_cmp_irs<bits<4> opcod, string opc, PatFrag opnode> {
539 def ri : AI1<opcod, (outs), (ins GPR:$a, so_imm:$b), DPRnIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000540 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000541 [(opnode GPR:$a, so_imm:$b)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000542 def rr : AI1<opcod, (outs), (ins GPR:$a, GPR:$b), DPRnReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000544 [(opnode GPR:$a, GPR:$b)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000545 def rs : AI1<opcod, (outs), (ins GPR:$a, so_reg:$b), DPRnSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000547 [(opnode GPR:$a, so_reg:$b)]>;
548}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000549}
550
551/// AI_unary_rrot - A unary operation with two forms: one whose operand is a
552/// register and one whose operand is a register rotated by 8/16/24.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000553multiclass AI_unary_rrot<bits<4> opcod, string opc, PatFrag opnode> {
554 def r : AI<opcod, (outs GPR:$dst), (ins GPR:$Src), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555 opc, " $dst, $Src",
556 [(set GPR:$dst, (opnode GPR:$Src))]>, Requires<[IsARM, HasV6]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000557 def r_rot : AI<opcod, (outs GPR:$dst), (ins GPR:$Src, i32imm:$rot), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558 opc, " $dst, $Src, ror $rot",
559 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>,
560 Requires<[IsARM, HasV6]>;
561}
562
563/// AI_bin_rrot - A binary operation with two forms: one whose operand is a
564/// register and one whose operand is a register rotated by 8/16/24.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000565multiclass AI_bin_rrot<bits<4> opcod, string opc, PatFrag opnode> {
566 def rr : AI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
567 Pseudo, opc, " $dst, $LHS, $RHS",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
569 Requires<[IsARM, HasV6]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000570 def rr_rot : AI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
571 Pseudo, opc, " $dst, $LHS, $RHS, ror $rot",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572 [(set GPR:$dst, (opnode GPR:$LHS,
573 (rotr GPR:$RHS, rot_imm:$rot)))]>,
574 Requires<[IsARM, HasV6]>;
575}
576
577// Special cases.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000578class XI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
579 IndexMode im, Format f, string asm, string cstr, list<dag> pattern>
580 : InstARM<opcod, am, sz, im, f, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000581 let OutOperandList = oops;
582 let InOperandList = iops;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000583 let AsmString = asm;
584 let Pattern = pattern;
585 list<Predicate> Predicates = [IsARM];
586}
587
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000588class AXI<bits<4> opcod, dag oops, dag iops, Format f, string asm,
589 list<dag> pattern>
590 : XI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, asm,
591 "", pattern>;
592class AXI1<bits<4> opcod, dag oops, dag iops, Format f, string asm,
593 list<dag> pattern>
594 : XI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, asm,
595 "", pattern>;
596class AXI2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
597 list<dag> pattern>
598 : XI<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, asm,
599 "", pattern>;
600class AXI3<bits<4> opcod, dag oops, dag iops, Format f, string asm,
601 list<dag> pattern>
602 : XI<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, asm,
603 "", pattern>;
604class AXI4<bits<4> opcod, dag oops, dag iops, Format f, string asm,
605 list<dag> pattern>
606 : XI<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, asm,
607 "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000609class AXIx2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
610 list<dag> pattern>
611 : XI<opcod, oops, iops, AddrModeNone, Size8Bytes, IndexModeNone, f, asm,
612 "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613
614// BR_JT instructions
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000615class JTI<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
616 : XI<opcod, oops, iops, AddrModeNone, SizeSpecial, IndexModeNone, BranchMisc,
617 asm, "", pattern>;
618class JTI1<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
619 : XI<opcod, oops, iops, AddrMode1, SizeSpecial, IndexModeNone, BranchMisc,
620 asm, "", pattern>;
621class JTI2<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
622 : XI<opcod, oops, iops, AddrMode2, SizeSpecial, IndexModeNone, BranchMisc,
623 asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624
625/// AsXI1_bin_c_irs - Same as AsI1_bin_irs but without the predicate operand and
626/// setting carry bit. But it can optionally set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000627let Uses = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000628multiclass AsXI1_bin_c_irs<bits<4> opcod, string opc, PatFrag opnode> {
629 def ri : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
630 DPRIm, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000631 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000632 def rr : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b, cc_out:$s),
633 DPRReg, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000634 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000635 def rs : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
636 DPRSoReg, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000637 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
638}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000639}
640
641//===----------------------------------------------------------------------===//
642// Instructions
643//===----------------------------------------------------------------------===//
644
645//===----------------------------------------------------------------------===//
646// Miscellaneous Instructions.
647//
Evan Chenge399fbb2007-12-12 23:12:09 +0000648let isImplicitDef = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000649def IMPLICIT_DEF_GPR :
Evan Chengb783fa32007-07-19 01:14:50 +0000650PseudoInst<(outs GPR:$rD), (ins pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651 "@ IMPLICIT_DEF_GPR $rD",
652 [(set GPR:$rD, (undef))]>;
653
654
655/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
656/// the function. The first operand is the ID# for this instruction, the second
657/// is the index into the MachineConstantPool that this is, the third is the
658/// size in bytes of this constant pool entry.
659let isNotDuplicable = 1 in
660def CONSTPOOL_ENTRY :
Evan Chengb783fa32007-07-19 01:14:50 +0000661PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
662 i32imm:$size),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000663 "${instid:label} ${cpidx:cpentry}", []>;
664
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000665let Defs = [SP], Uses = [SP] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000666def ADJCALLSTACKUP :
Bill Wendling22f8deb2007-11-13 00:44:25 +0000667PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p),
668 "@ ADJCALLSTACKUP $amt1",
669 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670
671def ADJCALLSTACKDOWN :
Evan Chengb783fa32007-07-19 01:14:50 +0000672PseudoInst<(outs), (ins i32imm:$amt, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 "@ ADJCALLSTACKDOWN $amt",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000674 [(ARMcallseq_start imm:$amt)]>;
675}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676
677def DWARF_LOC :
Evan Chengb783fa32007-07-19 01:14:50 +0000678PseudoInst<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000679 ".loc $file, $line, $col",
680 [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
681
682let isNotDuplicable = 1 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000683def PICADD : AXI1<0x0, (outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
684 Pseudo, "$cp:\n\tadd$p $dst, pc, $a",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685 [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
686
Evan Cheng8610a3b2008-01-07 23:56:57 +0000687let AddedComplexity = 10 in {
688let isSimpleLoad = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000689def PICLD : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
690 Pseudo, "${addr:label}:\n\tldr$p $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000691 [(set GPR:$dst, (load addrmodepc:$addr))]>;
692
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000693def PICLDZH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
694 Pseudo, "${addr:label}:\n\tldr${p}h $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000695 [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
696
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000697def PICLDZB : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
698 Pseudo, "${addr:label}:\n\tldr${p}b $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000699 [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
700
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000701def PICLDH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
702 Pseudo, "${addr:label}:\n\tldr${p}h $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000703 [(set GPR:$dst, (extloadi16 addrmodepc:$addr))]>;
704
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000705def PICLDB : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
706 Pseudo, "${addr:label}:\n\tldr${p}b $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000707 [(set GPR:$dst, (extloadi8 addrmodepc:$addr))]>;
708
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000709def PICLDSH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
710 Pseudo, "${addr:label}:\n\tldr${p}sh $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000711 [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
712
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000713def PICLDSB : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
714 Pseudo, "${addr:label}:\n\tldr${p}sb $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000715 [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
716}
Chris Lattnerf823faf2008-01-06 05:55:01 +0000717let AddedComplexity = 10 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000718def PICSTR : AXI2<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
719 Pseudo, "${addr:label}:\n\tstr$p $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000720 [(store GPR:$src, addrmodepc:$addr)]>;
721
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000722def PICSTRH : AXI3<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
723 Pseudo, "${addr:label}:\n\tstr${p}h $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000724 [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
725
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000726def PICSTRB : AXI2<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
727 Pseudo, "${addr:label}:\n\tstr${p}b $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000728 [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
729}
730}
731
732//===----------------------------------------------------------------------===//
733// Control Flow Instructions.
734//
735
736let isReturn = 1, isTerminator = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000737 def BX_RET : AI<0x1, (outs), (ins), BranchMisc, "bx", " lr", [(ARMretflag)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000738
739// FIXME: remove when we have a way to marking a MI with these properties.
Evan Chengb783fa32007-07-19 01:14:50 +0000740// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
741// operand list.
Evan Cheng8610a3b2008-01-07 23:56:57 +0000742let isReturn = 1, isTerminator = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000743 def LDM_RET : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000744 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000745 LdFrm, "ldm${p}${addr:submode} $addr, $dst1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000746 []>;
747
Evan Cheng37e7c752007-07-21 00:34:19 +0000748let isCall = 1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000749 Defs = [R0, R1, R2, R3, R12, LR,
750 D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000751 def BL : AXI<0xB, (outs), (ins i32imm:$func, variable_ops), Branch,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000752 "bl ${func:call}",
753 [(ARMcall tglobaladdr:$func)]>;
754
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000755 def BL_pred : AI<0xB, (outs), (ins i32imm:$func, variable_ops),
756 Branch, "bl", " ${func:call}",
757 [(ARMcall_pred tglobaladdr:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000758
759 // ARMv5T and above
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000760 def BLX : AXI<0x2, (outs), (ins GPR:$func, variable_ops), BranchMisc,
Evan Chengb783fa32007-07-19 01:14:50 +0000761 "blx $func",
762 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000763 let Uses = [LR] in {
764 // ARMv4T
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000765 def BX : AXIx2<0x0, (outs), (ins GPR:$func, variable_ops),
766 BranchMisc, "mov lr, pc\n\tbx $func",
767 [(ARMcall_nolink GPR:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768 }
769}
770
Evan Cheng37e7c752007-07-21 00:34:19 +0000771let isBranch = 1, isTerminator = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000772 // B is "predicable" since it can be xformed into a Bcc.
773 let isBarrier = 1 in {
774 let isPredicable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000775 def B : AXI<0xA, (outs), (ins brtarget:$target), Branch, "b $target",
Evan Chengb783fa32007-07-19 01:14:50 +0000776 [(br bb:$target)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777
Owen Andersonf8053082007-11-12 07:39:39 +0000778 let isNotDuplicable = 1, isIndirectBranch = 1 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000779 def BR_JTr : JTI<0x0, (outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
Evan Chengb783fa32007-07-19 01:14:50 +0000780 "mov pc, $target \n$jt",
781 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000782 def BR_JTm : JTI2<0x0, (outs), (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
Evan Chengb783fa32007-07-19 01:14:50 +0000783 "ldr pc, $target \n$jt",
784 [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000785 imm:$id)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000786 def BR_JTadd : JTI1<0x0, (outs), (ins GPR:$target, GPR:$idx, jtblock_operand:$jt,
Evan Chengb783fa32007-07-19 01:14:50 +0000787 i32imm:$id),
788 "add pc, $target, $idx \n$jt",
789 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790 imm:$id)]>;
791 }
792 }
793
794 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
795 // a two-value operand where a dag node expects two operands. :(
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000796 def Bcc : AI<0xA, (outs), (ins brtarget:$target), Branch,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000797 "b", " $target",
798 [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799}
800
801//===----------------------------------------------------------------------===//
802// Load / store Instructions.
803//
804
805// Load
Evan Cheng8610a3b2008-01-07 23:56:57 +0000806let isSimpleLoad = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000807def LDR : AI2<0x0, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808 "ldr", " $dst, $addr",
809 [(set GPR:$dst, (load addrmode2:$addr))]>;
810
811// Special LDR for loads from non-pc-relative constpools.
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000812let isSimpleLoad = 1, mayLoad = 1, isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000813def LDRcp : AI2<0x0, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000814 "ldr", " $dst, $addr", []>;
815
816// Loads with zero extension
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000817def LDRH : AI3<0xB, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000818 "ldr", "h $dst, $addr",
819 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
820
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000821def LDRB : AI2<0x1, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000822 "ldr", "b $dst, $addr",
823 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
824
825// Loads with sign extension
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000826def LDRSH : AI3<0xE, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000827 "ldr", "sh $dst, $addr",
828 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
829
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000830def LDRSB : AI3<0xD, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000831 "ldr", "sb $dst, $addr",
832 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
833
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000834let mayLoad = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000835// Load doubleword
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000836def LDRD : AI3<0xD, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000837 "ldr", "d $dst, $addr",
838 []>, Requires<[IsARM, HasV5T]>;
839
840// Indexed loads
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000841def LDR_PRE : AI2pr<0x0, (outs GPR:$dst, GPR:$base_wb),
842 (ins addrmode2:$addr), LdFrm,
843 "ldr", " $dst, $addr!", "$addr.base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000844
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000845def LDR_POST : AI2po<0x0, (outs GPR:$dst, GPR:$base_wb),
846 (ins GPR:$base, am2offset:$offset), LdFrm,
847 "ldr", " $dst, [$base], $offset", "$base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000849def LDRH_PRE : AI3pr<0xB, (outs GPR:$dst, GPR:$base_wb),
850 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000851 "ldr", "h $dst, $addr!", "$addr.base = $base_wb", []>;
852
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000853def LDRH_POST : AI3po<0xB, (outs GPR:$dst, GPR:$base_wb),
854 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000855 "ldr", "h $dst, [$base], $offset", "$base = $base_wb", []>;
856
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000857def LDRB_PRE : AI2pr<0x1, (outs GPR:$dst, GPR:$base_wb),
858 (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000859 "ldr", "b $dst, $addr!", "$addr.base = $base_wb", []>;
860
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000861def LDRB_POST : AI2po<0x1, (outs GPR:$dst, GPR:$base_wb),
862 (ins GPR:$base,am2offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000863 "ldr", "b $dst, [$base], $offset", "$base = $base_wb", []>;
864
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000865def LDRSH_PRE : AI3pr<0xE, (outs GPR:$dst, GPR:$base_wb),
866 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867 "ldr", "sh $dst, $addr!", "$addr.base = $base_wb", []>;
868
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000869def LDRSH_POST: AI3po<0xE, (outs GPR:$dst, GPR:$base_wb),
870 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000871 "ldr", "sh $dst, [$base], $offset", "$base = $base_wb", []>;
872
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000873def LDRSB_PRE : AI3pr<0xD, (outs GPR:$dst, GPR:$base_wb),
874 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000875 "ldr", "sb $dst, $addr!", "$addr.base = $base_wb", []>;
876
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000877def LDRSB_POST: AI3po<0xD, (outs GPR:$dst, GPR:$base_wb),
878 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879 "ldr", "sb $dst, [$base], $offset", "$base = $base_wb", []>;
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000880}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000881
882// Store
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000883def STR : AI2<0x0, (outs), (ins GPR:$src, addrmode2:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000884 "str", " $src, $addr",
885 [(store GPR:$src, addrmode2:$addr)]>;
886
887// Stores with truncate
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000888def STRH : AI3<0xB, (outs), (ins GPR:$src, addrmode3:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000889 "str", "h $src, $addr",
890 [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
891
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000892def STRB : AI2<0x1, (outs), (ins GPR:$src, addrmode2:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000893 "str", "b $src, $addr",
894 [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
895
896// Store doubleword
Chris Lattner6887b142008-01-06 08:36:04 +0000897let mayStore = 1 in
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000898def STRD : AI3<0xF, (outs), (ins GPR:$src, addrmode3:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000899 "str", "d $src, $addr",
900 []>, Requires<[IsARM, HasV5T]>;
901
902// Indexed stores
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000903def STR_PRE : AI2pr<0x0, (outs GPR:$base_wb),
904 (ins GPR:$src, GPR:$base, am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000905 "str", " $src, [$base, $offset]!", "$base = $base_wb",
906 [(set GPR:$base_wb,
907 (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
908
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000909def STR_POST : AI2po<0x0, (outs GPR:$base_wb),
910 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000911 "str", " $src, [$base], $offset", "$base = $base_wb",
912 [(set GPR:$base_wb,
913 (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
914
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000915def STRH_PRE : AI3pr<0xB, (outs GPR:$base_wb),
916 (ins GPR:$src, GPR:$base,am3offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000917 "str", "h $src, [$base, $offset]!", "$base = $base_wb",
918 [(set GPR:$base_wb,
919 (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
920
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000921def STRH_POST: AI3po<0xB, (outs GPR:$base_wb),
922 (ins GPR:$src, GPR:$base,am3offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000923 "str", "h $src, [$base], $offset", "$base = $base_wb",
924 [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
925 GPR:$base, am3offset:$offset))]>;
926
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000927def STRB_PRE : AI2pr<0x1, (outs GPR:$base_wb),
928 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000929 "str", "b $src, [$base, $offset]!", "$base = $base_wb",
930 [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
931 GPR:$base, am2offset:$offset))]>;
932
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000933def STRB_POST: AI2po<0x1, (outs GPR:$base_wb),
934 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000935 "str", "b $src, [$base], $offset", "$base = $base_wb",
936 [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
937 GPR:$base, am2offset:$offset))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000938
939//===----------------------------------------------------------------------===//
940// Load / store multiple Instructions.
941//
942
Evan Chengb783fa32007-07-19 01:14:50 +0000943// FIXME: $dst1 should be a def.
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000944let mayLoad = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000945def LDM : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000946 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000947 LdFrm, "ldm${p}${addr:submode} $addr, $dst1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000948 []>;
949
Chris Lattner6887b142008-01-06 08:36:04 +0000950let mayStore = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000951def STM : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000952 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000953 StFrm, "stm${p}${addr:submode} $addr, $src1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000954 []>;
955
956//===----------------------------------------------------------------------===//
957// Move Instructions.
958//
959
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000960def MOVr : AsI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000961 "mov", " $dst, $src", []>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000962def MOVs : AsI1<0xD, (outs GPR:$dst), (ins so_reg:$src), DPRdSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000963 "mov", " $dst, $src", [(set GPR:$dst, so_reg:$src)]>;
964
965let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000966def MOVi : AsI1<0xD, (outs GPR:$dst), (ins so_imm:$src), DPRdIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000967 "mov", " $dst, $src", [(set GPR:$dst, so_imm:$src)]>;
968
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000969def MOVrx : AsI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Evan Chengb783fa32007-07-19 01:14:50 +0000970 "mov", " $dst, $src, rrx",
971 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000972
973// These aren't really mov instructions, but we have to define them this way
974// due to flag operands.
975
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000976let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000977def MOVsrl_flag : AI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000978 "mov", "s $dst, $src, lsr #1",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000979 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000980def MOVsra_flag : AI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000981 "mov", "s $dst, $src, asr #1",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000982 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>;
983}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000984
985//===----------------------------------------------------------------------===//
986// Extend Instructions.
987//
988
989// Sign extenders
990
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000991defm SXTB : AI_unary_rrot<0x0, "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
992defm SXTH : AI_unary_rrot<0x0, "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000993
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000994defm SXTAB : AI_bin_rrot<0x0, "sxtab",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000995 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000996defm SXTAH : AI_bin_rrot<0x0, "sxtah",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000997 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
998
999// TODO: SXT(A){B|H}16
1000
1001// Zero extenders
1002
1003let AddedComplexity = 16 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001004defm UXTB : AI_unary_rrot<0x0, "uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
1005defm UXTH : AI_unary_rrot<0x0, "uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1006defm UXTB16 : AI_unary_rrot<0x0, "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001007
1008def : ARMV6Pat<(and (shl GPR:$Src, 8), 0xFF00FF),
1009 (UXTB16r_rot GPR:$Src, 24)>;
1010def : ARMV6Pat<(and (srl GPR:$Src, 8), 0xFF00FF),
1011 (UXTB16r_rot GPR:$Src, 8)>;
1012
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001013defm UXTAB : AI_bin_rrot<0x0, "uxtab",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001014 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001015defm UXTAH : AI_bin_rrot<0x0, "uxtah",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001016 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1017}
1018
1019// This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
1020//defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
1021
1022// TODO: UXT(A){B|H}16
1023
1024//===----------------------------------------------------------------------===//
1025// Arithmetic Instructions.
1026//
1027
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001028defm ADD : AsI1_bin_irs<0x4, "add", BinOpFrag<(add node:$LHS, node:$RHS)>>;
1029defm SUB : AsI1_bin_irs<0x2, "sub", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001030
1031// ADD and SUB with 's' bit set.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001032defm ADDS : ASI1_bin_s_irs<0x4, "add", BinOpFrag<(addc node:$LHS, node:$RHS)>>;
1033defm SUBS : ASI1_bin_s_irs<0x2, "sub", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001034
1035// FIXME: Do not allow ADC / SBC to be predicated for now.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001036defm ADC : AsXI1_bin_c_irs<0x5, "adc", BinOpFrag<(adde node:$LHS, node:$RHS)>>;
1037defm SBC : AsXI1_bin_c_irs<0x6, "sbc", BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001038
1039// These don't define reg/reg forms, because they are handled above.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001040def RSBri : AsI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041 "rsb", " $dst, $a, $b",
1042 [(set GPR:$dst, (sub so_imm:$b, GPR:$a))]>;
1043
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001044def RSBrs : AsI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001045 "rsb", " $dst, $a, $b",
1046 [(set GPR:$dst, (sub so_reg:$b, GPR:$a))]>;
1047
1048// RSB with 's' bit set.
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001049let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001050def RSBSri : AI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051 "rsb", "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001052 [(set GPR:$dst, (subc so_imm:$b, GPR:$a))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001053def RSBSrs : AI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001054 "rsb", "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001055 [(set GPR:$dst, (subc so_reg:$b, GPR:$a))]>;
1056}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001057
1058// FIXME: Do not allow RSC to be predicated for now. But they can set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001059let Uses = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001060def RSCri : AXI1<0x7, (outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
1061 DPRIm, "rsc${s} $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001062 [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001063def RSCrs : AXI1<0x7, (outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
1064 DPRSoReg, "rsc${s} $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001065 [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>;
1066}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001067
1068// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
1069def : ARMPat<(add GPR:$src, so_imm_neg:$imm),
1070 (SUBri GPR:$src, so_imm_neg:$imm)>;
1071
1072//def : ARMPat<(addc GPR:$src, so_imm_neg:$imm),
1073// (SUBSri GPR:$src, so_imm_neg:$imm)>;
1074//def : ARMPat<(adde GPR:$src, so_imm_neg:$imm),
1075// (SBCri GPR:$src, so_imm_neg:$imm)>;
1076
1077// Note: These are implemented in C++ code, because they have to generate
1078// ADD/SUBrs instructions, which use a complex pattern that a xform function
1079// cannot produce.
1080// (mul X, 2^n+1) -> (add (X << n), X)
1081// (mul X, 2^n-1) -> (rsb X, (X << n))
1082
1083
1084//===----------------------------------------------------------------------===//
1085// Bitwise Instructions.
1086//
1087
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001088defm AND : AsI1_bin_irs<0x0, "and", BinOpFrag<(and node:$LHS, node:$RHS)>>;
1089defm ORR : AsI1_bin_irs<0xC, "orr", BinOpFrag<(or node:$LHS, node:$RHS)>>;
1090defm EOR : AsI1_bin_irs<0x1, "eor", BinOpFrag<(xor node:$LHS, node:$RHS)>>;
1091defm BIC : AsI1_bin_irs<0xE, "bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001092
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001093def MVNr : AsI<0xE, (outs GPR:$dst), (ins GPR:$src), DPRdReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001094 "mvn", " $dst, $src", [(set GPR:$dst, (not GPR:$src))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001095def MVNs : AsI<0xE, (outs GPR:$dst), (ins so_reg:$src), DPRdSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001096 "mvn", " $dst, $src", [(set GPR:$dst, (not so_reg:$src))]>;
1097let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001098def MVNi : AsI<0xE, (outs GPR:$dst), (ins so_imm:$imm), DPRdIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001099 "mvn", " $dst, $imm", [(set GPR:$dst, so_imm_not:$imm)]>;
1100
1101def : ARMPat<(and GPR:$src, so_imm_not:$imm),
1102 (BICri GPR:$src, so_imm_not:$imm)>;
1103
1104//===----------------------------------------------------------------------===//
1105// Multiply Instructions.
1106//
1107
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001108def MUL : AsI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulFrm,
1109 "mul", " $dst, $a, $b",
1110 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001111
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001112def MLA : AsI<0x2, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1113 MulFrm, "mla", " $dst, $a, $b, $c",
1114 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001115
1116// Extra precision multiplies with low / high results
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001117def SMULL : AsI<0xC, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
1118 MulFrm, "smull", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001119
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001120def UMULL : AsI<0x8, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
1121 MulFrm, "umull", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001122
1123// Multiply + accumulate
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001124def SMLAL : AsI<0xE, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
1125 MulFrm, "smlal", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001127def UMLAL : AsI<0xA, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
1128 MulFrm, "umlal", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001129
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001130def UMAAL : AI<0x0, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131 "umaal", " $ldst, $hdst, $a, $b", []>,
1132 Requires<[IsARM, HasV6]>;
1133
1134// Most significant word multiply
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001135def SMMUL : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001136 "smmul", " $dst, $a, $b",
1137 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>,
1138 Requires<[IsARM, HasV6]>;
1139
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001140def SMMLA : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001141 "smmla", " $dst, $a, $b, $c",
1142 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>,
1143 Requires<[IsARM, HasV6]>;
1144
1145
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001146def SMMLS : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001147 "smmls", " $dst, $a, $b, $c",
1148 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
1149 Requires<[IsARM, HasV6]>;
1150
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001151multiclass AI_smul<string opc, PatFrag opnode> {
1152 def BB : AI<0x8, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001153 !strconcat(opc, "bb"), " $dst, $a, $b",
1154 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1155 (sext_inreg GPR:$b, i16)))]>,
1156 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001157
1158 def BT : AI<0xC, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001159 !strconcat(opc, "bt"), " $dst, $a, $b",
1160 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1161 (sra GPR:$b, 16)))]>,
1162 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001163
1164 def TB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001165 !strconcat(opc, "tb"), " $dst, $a, $b",
1166 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
1167 (sext_inreg GPR:$b, i16)))]>,
1168 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001169
1170 def TT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001171 !strconcat(opc, "tt"), " $dst, $a, $b",
1172 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
1173 (sra GPR:$b, 16)))]>,
1174 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001175
1176 def WB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMULW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001177 !strconcat(opc, "wb"), " $dst, $a, $b",
1178 [(set GPR:$dst, (sra (opnode GPR:$a,
1179 (sext_inreg GPR:$b, i16)), 16))]>,
1180 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001181
1182 def WT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMULW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001183 !strconcat(opc, "wt"), " $dst, $a, $b",
1184 [(set GPR:$dst, (sra (opnode GPR:$a,
1185 (sra GPR:$b, 16)), 16))]>,
1186 Requires<[IsARM, HasV5TE]>;
1187}
1188
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001189
1190multiclass AI_smla<string opc, PatFrag opnode> {
1191 def BB : AI<0x8, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001192 !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
1193 [(set GPR:$dst, (add GPR:$acc,
1194 (opnode (sext_inreg GPR:$a, i16),
1195 (sext_inreg GPR:$b, i16))))]>,
1196 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001197
1198 def BT : AI<0xC, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001199 !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
1200 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
1201 (sra GPR:$b, 16))))]>,
1202 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001203
1204 def TB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001205 !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
1206 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1207 (sext_inreg GPR:$b, i16))))]>,
1208 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001209
1210 def TT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001211 !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
1212 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1213 (sra GPR:$b, 16))))]>,
1214 Requires<[IsARM, HasV5TE]>;
1215
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001216 def WB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLAW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001217 !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
1218 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1219 (sext_inreg GPR:$b, i16)), 16)))]>,
1220 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001221
1222 def WT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLAW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001223 !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
1224 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1225 (sra GPR:$b, 16)), 16)))]>,
1226 Requires<[IsARM, HasV5TE]>;
1227}
1228
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001229defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1230defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001231
1232// TODO: Halfword multiple accumulate long: SMLAL<x><y>
1233// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
1234
1235//===----------------------------------------------------------------------===//
1236// Misc. Arithmetic Instructions.
1237//
1238
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001239def CLZ : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001240 "clz", " $dst, $src",
1241 [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]>;
1242
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001243def REV : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001244 "rev", " $dst, $src",
1245 [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]>;
1246
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001247def REV16 : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001248 "rev16", " $dst, $src",
1249 [(set GPR:$dst,
1250 (or (and (srl GPR:$src, 8), 0xFF),
1251 (or (and (shl GPR:$src, 8), 0xFF00),
1252 (or (and (srl GPR:$src, 8), 0xFF0000),
1253 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
1254 Requires<[IsARM, HasV6]>;
1255
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001256def REVSH : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001257 "revsh", " $dst, $src",
1258 [(set GPR:$dst,
1259 (sext_inreg
1260 (or (srl (and GPR:$src, 0xFF00), 8),
1261 (shl GPR:$src, 8)), i16))]>,
1262 Requires<[IsARM, HasV6]>;
1263
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001264def PKHBT : AI<0x0, (outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1265 Pseudo, "pkhbt", " $dst, $src1, $src2, LSL $shamt",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001266 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1267 (and (shl GPR:$src2, (i32 imm:$shamt)),
1268 0xFFFF0000)))]>,
1269 Requires<[IsARM, HasV6]>;
1270
1271// Alternate cases for PKHBT where identities eliminate some nodes.
1272def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1273 (PKHBT GPR:$src1, GPR:$src2, 0)>;
1274def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1275 (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
1276
1277
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001278def PKHTB : AI<0x0, (outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1279 Pseudo, "pkhtb", " $dst, $src1, $src2, ASR $shamt",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001280 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1281 (and (sra GPR:$src2, imm16_31:$shamt),
1282 0xFFFF)))]>, Requires<[IsARM, HasV6]>;
1283
1284// Alternate cases for PKHTB where identities eliminate some nodes. Note that
1285// a shift amount of 0 is *not legal* here, it is PKHBT instead.
1286def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, 16)),
1287 (PKHTB GPR:$src1, GPR:$src2, 16)>;
1288def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1289 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1290 (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1291
1292
1293//===----------------------------------------------------------------------===//
1294// Comparison Instructions...
1295//
1296
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001297defm CMP : AI1_cmp_irs<0xA, "cmp",
1298 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1299defm CMN : AI1_cmp_irs<0xB, "cmn",
1300 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001301
1302// Note that TST/TEQ don't set all the same flags that CMP does!
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001303defm TST : AI1_cmp_irs<0x8, "tst",
1304 BinOpFrag<(ARMcmpNZ (and node:$LHS, node:$RHS), 0)>>;
1305defm TEQ : AI1_cmp_irs<0x9, "teq",
1306 BinOpFrag<(ARMcmpNZ (xor node:$LHS, node:$RHS), 0)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001307
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001308defm CMPnz : AI1_cmp_irs<0xA, "cmp",
1309 BinOpFrag<(ARMcmpNZ node:$LHS, node:$RHS)>>;
1310defm CMNnz : AI1_cmp_irs<0xA, "cmn",
1311 BinOpFrag<(ARMcmpNZ node:$LHS,(ineg node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001312
1313def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1314 (CMNri GPR:$src, so_imm_neg:$imm)>;
1315
1316def : ARMPat<(ARMcmpNZ GPR:$src, so_imm_neg:$imm),
1317 (CMNri GPR:$src, so_imm_neg:$imm)>;
1318
1319
1320// Conditional moves
1321// FIXME: should be able to write a pattern for ARMcmov, but can't use
1322// a two-value operand where a dag node expects two operands. :(
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001323def MOVCCr : AI<0xD, (outs GPR:$dst), (ins GPR:$false, GPR:$true),
1324 DPRdReg, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001325 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1326 RegConstraint<"$false = $dst">;
1327
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001328def MOVCCs : AI<0xD, (outs GPR:$dst), (ins GPR:$false, so_reg:$true),
1329 DPRdSoReg, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001330 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1331 RegConstraint<"$false = $dst">;
1332
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001333def MOVCCi : AI<0xD, (outs GPR:$dst), (ins GPR:$false, so_imm:$true),
1334 DPRdIm, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001335 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1336 RegConstraint<"$false = $dst">;
1337
1338
1339// LEApcrel - Load a pc-relative address into a register without offending the
1340// assembler.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001341def LEApcrel : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, pred:$p), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001342 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
1343 "${:private}PCRELL${:uid}+8))\n"),
1344 !strconcat("${:private}PCRELL${:uid}:\n\t",
1345 "add$p $dst, pc, #PCRELV${:uid}")),
1346 []>;
1347
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001348def LEApcrelJT : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, i32imm:$id, pred:$p),
1349 Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001350 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
1351 "${:private}PCRELL${:uid}+8))\n"),
1352 !strconcat("${:private}PCRELL${:uid}:\n\t",
1353 "add$p $dst, pc, #PCRELV${:uid}")),
1354 []>;
1355
1356//===----------------------------------------------------------------------===//
1357// TLS Instructions
1358//
1359
1360// __aeabi_read_tp preserves the registers r1-r3.
1361let isCall = 1,
1362 Defs = [R0, R12, LR, CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001363 def TPsoft : AXI<0x0, (outs), (ins), BranchMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001364 "bl __aeabi_read_tp",
1365 [(set R0, ARMthread_pointer)]>;
1366}
1367
1368//===----------------------------------------------------------------------===//
1369// Non-Instruction Patterns
1370//
1371
1372// ConstantPool, GlobalAddress, and JumpTable
1373def : ARMPat<(ARMWrapper tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>;
1374def : ARMPat<(ARMWrapper tconstpool :$dst), (LEApcrel tconstpool :$dst)>;
1375def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1376 (LEApcrelJT tjumptable:$dst, imm:$id)>;
1377
1378// Large immediate handling.
1379
1380// Two piece so_imms.
1381let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001382def MOVi2pieces : AI1x2<0x0, (outs GPR:$dst), (ins so_imm2part:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001383 "mov", " $dst, $src",
1384 [(set GPR:$dst, so_imm2part:$src)]>;
1385
1386def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1387 (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1388 (so_imm2part_2 imm:$RHS))>;
1389def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1390 (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1391 (so_imm2part_2 imm:$RHS))>;
1392
1393// TODO: add,sub,and, 3-instr forms?
1394
1395
1396// Direct calls
1397def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>;
1398
1399// zextload i1 -> zextload i8
1400def : ARMPat<(zextloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1401
1402// extload -> zextload
1403def : ARMPat<(extloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1404def : ARMPat<(extloadi8 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1405def : ARMPat<(extloadi16 addrmode3:$addr), (LDRH addrmode3:$addr)>;
1406
1407// truncstore i1 -> truncstore i8
1408def : ARMPat<(truncstorei1 GPR:$src, addrmode2:$dst),
1409 (STRB GPR:$src, addrmode2:$dst)>;
1410def : ARMPat<(pre_truncsti1 GPR:$src, GPR:$base, am2offset:$offset),
1411 (STRB_PRE GPR:$src, GPR:$base, am2offset:$offset)>;
1412def : ARMPat<(post_truncsti1 GPR:$src, GPR:$base, am2offset:$offset),
1413 (STRB_POST GPR:$src, GPR:$base, am2offset:$offset)>;
1414
1415// smul* and smla*
1416def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra (shl GPR:$b, 16), 16)),
1417 (SMULBB GPR:$a, GPR:$b)>;
1418def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1419 (SMULBB GPR:$a, GPR:$b)>;
1420def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16)),
1421 (SMULBT GPR:$a, GPR:$b)>;
1422def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, 16)),
1423 (SMULBT GPR:$a, GPR:$b)>;
1424def : ARMV5TEPat<(mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16)),
1425 (SMULTB GPR:$a, GPR:$b)>;
1426def : ARMV5TEPat<(mul (sra GPR:$a, 16), sext_16_node:$b),
1427 (SMULTB GPR:$a, GPR:$b)>;
1428def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16),
1429 (SMULWB GPR:$a, GPR:$b)>;
1430def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), 16),
1431 (SMULWB GPR:$a, GPR:$b)>;
1432
1433def : ARMV5TEPat<(add GPR:$acc,
1434 (mul (sra (shl GPR:$a, 16), 16),
1435 (sra (shl GPR:$b, 16), 16))),
1436 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1437def : ARMV5TEPat<(add GPR:$acc,
1438 (mul sext_16_node:$a, sext_16_node:$b)),
1439 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1440def : ARMV5TEPat<(add GPR:$acc,
1441 (mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16))),
1442 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1443def : ARMV5TEPat<(add GPR:$acc,
1444 (mul sext_16_node:$a, (sra GPR:$b, 16))),
1445 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1446def : ARMV5TEPat<(add GPR:$acc,
1447 (mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16))),
1448 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1449def : ARMV5TEPat<(add GPR:$acc,
1450 (mul (sra GPR:$a, 16), sext_16_node:$b)),
1451 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1452def : ARMV5TEPat<(add GPR:$acc,
1453 (sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16)),
1454 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1455def : ARMV5TEPat<(add GPR:$acc,
1456 (sra (mul GPR:$a, sext_16_node:$b), 16)),
1457 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1458
1459//===----------------------------------------------------------------------===//
1460// Thumb Support
1461//
1462
1463include "ARMInstrThumb.td"
1464
1465//===----------------------------------------------------------------------===//
1466// Floating Point Support
1467//
1468
1469include "ARMInstrVFP.td"