blob: 53c36f3a556c7d862664913ddcf19ae9e20c00fc [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.
Bill Wendling7173da52007-11-13 09:19:02 +000020def SDT_ARMCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
21def SDT_ARMCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000022
23def SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
24
25def SDT_ARMcall : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
26
27def SDT_ARMCMov : SDTypeProfile<1, 3,
28 [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
29 SDTCisVT<3, i32>]>;
30
31def SDT_ARMBrcond : SDTypeProfile<0, 2,
32 [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
33
34def SDT_ARMBrJT : SDTypeProfile<0, 3,
35 [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
36 SDTCisVT<2, i32>]>;
37
38def SDT_ARMCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
39
40def SDT_ARMPICAdd : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
41 SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
42
43def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
44
45// Node definitions.
46def ARMWrapper : SDNode<"ARMISD::Wrapper", SDTIntUnaryOp>;
47def ARMWrapperJT : SDNode<"ARMISD::WrapperJT", SDTIntBinOp>;
48
Bill Wendling7173da52007-11-13 09:19:02 +000049def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 [SDNPHasChain, SDNPOutFlag]>;
Bill Wendling7173da52007-11-13 09:19:02 +000051def ARMcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_ARMCallSeqEnd,
Bill Wendling22f8deb2007-11-13 00:44:25 +000052 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053
54def ARMcall : SDNode<"ARMISD::CALL", SDT_ARMcall,
55 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
56def ARMcall_pred : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
57 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
58def ARMcall_nolink : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
59 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
60
61def ARMretflag : SDNode<"ARMISD::RET_FLAG", SDTRet,
62 [SDNPHasChain, SDNPOptInFlag]>;
63
64def ARMcmov : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
65 [SDNPInFlag]>;
66def ARMcneg : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
67 [SDNPInFlag]>;
68
69def ARMbrcond : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
70 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
71
72def ARMbrjt : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
73 [SDNPHasChain]>;
74
75def ARMcmp : SDNode<"ARMISD::CMP", SDT_ARMCmp,
76 [SDNPOutFlag]>;
77
78def ARMcmpNZ : SDNode<"ARMISD::CMPNZ", SDT_ARMCmp,
79 [SDNPOutFlag]>;
80
81def ARMpic_add : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
82
83def ARMsrl_flag : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
84def ARMsra_flag : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
85def ARMrrx : SDNode<"ARMISD::RRX" , SDTIntUnaryOp, [SDNPInFlag ]>;
86
87def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
88
89//===----------------------------------------------------------------------===//
90// ARM Instruction Predicate Definitions.
91//
92def HasV5T : Predicate<"Subtarget->hasV5TOps()">;
93def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">;
94def HasV6 : Predicate<"Subtarget->hasV6Ops()">;
95def IsThumb : Predicate<"Subtarget->isThumb()">;
96def IsARM : Predicate<"!Subtarget->isThumb()">;
97
98//===----------------------------------------------------------------------===//
99// ARM Flag Definitions.
100
101class RegConstraint<string C> {
102 string Constraints = C;
103}
104
105//===----------------------------------------------------------------------===//
106// ARM specific transformation functions and pattern fragments.
107//
108
109// so_imm_XFORM - Return a so_imm value packed into the format described for
110// so_imm def below.
111def so_imm_XFORM : SDNodeXForm<imm, [{
112 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(N->getValue()),
113 MVT::i32);
114}]>;
115
116// so_imm_neg_XFORM - Return a so_imm value packed into the format described for
117// so_imm_neg def below.
118def so_imm_neg_XFORM : SDNodeXForm<imm, [{
119 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(-(int)N->getValue()),
120 MVT::i32);
121}]>;
122
123// so_imm_not_XFORM - Return a so_imm value packed into the format described for
124// so_imm_not def below.
125def so_imm_not_XFORM : SDNodeXForm<imm, [{
126 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(~(int)N->getValue()),
127 MVT::i32);
128}]>;
129
130// rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
131def rot_imm : PatLeaf<(i32 imm), [{
132 int32_t v = (int32_t)N->getValue();
133 return v == 8 || v == 16 || v == 24;
134}]>;
135
136/// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
137def imm1_15 : PatLeaf<(i32 imm), [{
138 return (int32_t)N->getValue() >= 1 && (int32_t)N->getValue() < 16;
139}]>;
140
141/// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
142def imm16_31 : PatLeaf<(i32 imm), [{
143 return (int32_t)N->getValue() >= 16 && (int32_t)N->getValue() < 32;
144}]>;
145
146def so_imm_neg :
147 PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(-(int)N->getValue()) != -1; }],
148 so_imm_neg_XFORM>;
149
150def so_imm_not :
151 PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(~(int)N->getValue()) != -1; }],
152 so_imm_not_XFORM>;
153
154// sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
155def sext_16_node : PatLeaf<(i32 GPR:$a), [{
156 return CurDAG->ComputeNumSignBits(SDOperand(N,0)) >= 17;
157}]>;
158
159
160
161//===----------------------------------------------------------------------===//
162// Operand Definitions.
163//
164
165// Branch target.
166def brtarget : Operand<OtherVT>;
167
168// A list of registers separated by comma. Used by load/store multiple.
169def reglist : Operand<i32> {
170 let PrintMethod = "printRegisterList";
171}
172
173// An operand for the CONSTPOOL_ENTRY pseudo-instruction.
174def cpinst_operand : Operand<i32> {
175 let PrintMethod = "printCPInstOperand";
176}
177
178def jtblock_operand : Operand<i32> {
179 let PrintMethod = "printJTBlockOperand";
180}
181
182// Local PC labels.
183def pclabel : Operand<i32> {
184 let PrintMethod = "printPCLabel";
185}
186
187// shifter_operand operands: so_reg and so_imm.
188def so_reg : Operand<i32>, // reg reg imm
189 ComplexPattern<i32, 3, "SelectShifterOperandReg",
190 [shl,srl,sra,rotr]> {
191 let PrintMethod = "printSORegOperand";
192 let MIOperandInfo = (ops GPR, GPR, i32imm);
193}
194
195// so_imm - Match a 32-bit shifter_operand immediate operand, which is an
196// 8-bit immediate rotated by an arbitrary number of bits. so_imm values are
197// represented in the imm field in the same 12-bit form that they are encoded
198// into so_imm instructions: the 8-bit immediate is the least significant bits
199// [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
200def so_imm : Operand<i32>,
201 PatLeaf<(imm),
202 [{ return ARM_AM::getSOImmVal(N->getValue()) != -1; }],
203 so_imm_XFORM> {
204 let PrintMethod = "printSOImmOperand";
205}
206
207// Break so_imm's up into two pieces. This handles immediates with up to 16
208// bits set in them. This uses so_imm2part to match and so_imm2part_[12] to
209// get the first/second pieces.
210def so_imm2part : Operand<i32>,
211 PatLeaf<(imm),
212 [{ return ARM_AM::isSOImmTwoPartVal((unsigned)N->getValue()); }]> {
213 let PrintMethod = "printSOImm2PartOperand";
214}
215
216def so_imm2part_1 : SDNodeXForm<imm, [{
217 unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getValue());
218 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
219}]>;
220
221def so_imm2part_2 : SDNodeXForm<imm, [{
222 unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getValue());
223 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
224}]>;
225
226
227// Define ARM specific addressing modes.
228
229// addrmode2 := reg +/- reg shop imm
230// addrmode2 := reg +/- imm12
231//
232def addrmode2 : Operand<i32>,
233 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
234 let PrintMethod = "printAddrMode2Operand";
235 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
236}
237
238def am2offset : Operand<i32>,
239 ComplexPattern<i32, 2, "SelectAddrMode2Offset", []> {
240 let PrintMethod = "printAddrMode2OffsetOperand";
241 let MIOperandInfo = (ops GPR, i32imm);
242}
243
244// addrmode3 := reg +/- reg
245// addrmode3 := reg +/- imm8
246//
247def addrmode3 : Operand<i32>,
248 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
249 let PrintMethod = "printAddrMode3Operand";
250 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
251}
252
253def am3offset : Operand<i32>,
254 ComplexPattern<i32, 2, "SelectAddrMode3Offset", []> {
255 let PrintMethod = "printAddrMode3OffsetOperand";
256 let MIOperandInfo = (ops GPR, i32imm);
257}
258
259// addrmode4 := reg, <mode|W>
260//
261def addrmode4 : Operand<i32>,
262 ComplexPattern<i32, 2, "", []> {
263 let PrintMethod = "printAddrMode4Operand";
264 let MIOperandInfo = (ops GPR, i32imm);
265}
266
267// addrmode5 := reg +/- imm8*4
268//
269def addrmode5 : Operand<i32>,
270 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
271 let PrintMethod = "printAddrMode5Operand";
272 let MIOperandInfo = (ops GPR, i32imm);
273}
274
275// addrmodepc := pc + reg
276//
277def addrmodepc : Operand<i32>,
278 ComplexPattern<i32, 2, "SelectAddrModePC", []> {
279 let PrintMethod = "printAddrModePCOperand";
280 let MIOperandInfo = (ops GPR, i32imm);
281}
282
283// ARM Predicate operand. Default to 14 = always (AL). Second part is CC
284// register whose default is 0 (no register).
285def pred : PredicateOperand<OtherVT, (ops i32imm, CCR),
286 (ops (i32 14), (i32 zero_reg))> {
287 let PrintMethod = "printPredicateOperand";
288}
289
290// Conditional code result for instructions whose 's' bit is set, e.g. subs.
291//
292def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
293 let PrintMethod = "printSBitModifierOperand";
294}
295
296//===----------------------------------------------------------------------===//
297// ARM Instruction flags. These need to match ARMInstrInfo.h.
298//
299
300// Addressing mode.
301class AddrMode<bits<4> val> {
302 bits<4> Value = val;
303}
304def AddrModeNone : AddrMode<0>;
305def AddrMode1 : AddrMode<1>;
306def AddrMode2 : AddrMode<2>;
307def AddrMode3 : AddrMode<3>;
308def AddrMode4 : AddrMode<4>;
309def AddrMode5 : AddrMode<5>;
310def AddrModeT1 : AddrMode<6>;
311def AddrModeT2 : AddrMode<7>;
312def AddrModeT4 : AddrMode<8>;
313def AddrModeTs : AddrMode<9>;
314
315// Instruction size.
316class SizeFlagVal<bits<3> val> {
317 bits<3> Value = val;
318}
319def SizeInvalid : SizeFlagVal<0>; // Unset.
320def SizeSpecial : SizeFlagVal<1>; // Pseudo or special.
321def Size8Bytes : SizeFlagVal<2>;
322def Size4Bytes : SizeFlagVal<3>;
323def Size2Bytes : SizeFlagVal<4>;
324
325// Load / store index mode.
326class IndexMode<bits<2> val> {
327 bits<2> Value = val;
328}
329def IndexModeNone : IndexMode<0>;
330def IndexModePre : IndexMode<1>;
331def IndexModePost : IndexMode<2>;
332
333//===----------------------------------------------------------------------===//
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000334// ARM Instruction Format Definitions.
335//
336
337// Format specifies the encoding used by the instruction. This is part of the
338// ad-hoc solution used to emit machine instruction encodings by our machine
339// code emitter.
340class Format<bits<5> val> {
341 bits<5> Value = val;
342}
343
344def Pseudo : Format<1>;
345def MulFrm : Format<2>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000346def MulSMLAW : Format<3>;
347def MulSMULW : Format<4>;
348def MulSMLA : Format<5>;
349def MulSMUL : Format<6>;
350def Branch : Format<7>;
351def BranchMisc : Format<8>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000352
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000353def DPRdIm : Format<9>;
354def DPRdReg : Format<10>;
355def DPRdSoReg : Format<11>;
356def DPRdMisc : Format<12>;
357def DPRnIm : Format<13>;
358def DPRnReg : Format<14>;
359def DPRnSoReg : Format<15>;
360def DPRIm : Format<16>;
361def DPRReg : Format<17>;
362def DPRSoReg : Format<18>;
363def DPRImS : Format<19>;
364def DPRRegS : Format<20>;
365def DPRSoRegS : Format<21>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000366
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000367def LdFrm : Format<22>;
368def StFrm : Format<23>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000369
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000370def ArithMisc : Format<24>;
371def ThumbFrm : Format<25>;
372def VFPFrm : Format<26>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000373
374
375
376//===----------------------------------------------------------------------===//
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000377
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000378// ARM Instruction templates.
379//
380
381// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
382class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
383 list<Predicate> Predicates = [IsARM];
384}
385class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
386 list<Predicate> Predicates = [IsARM, HasV5TE];
387}
388class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
389 list<Predicate> Predicates = [IsARM, HasV6];
390}
391
392class InstARM<bits<4> opcod, AddrMode am, SizeFlagVal sz, IndexMode im,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000393 Format f, string cstr>
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394 : Instruction {
395 let Namespace = "ARM";
396
397 bits<4> Opcode = opcod;
398 AddrMode AM = am;
399 bits<4> AddrModeBits = AM.Value;
400
401 SizeFlagVal SZ = sz;
402 bits<3> SizeFlag = SZ.Value;
403
404 IndexMode IM = im;
405 bits<2> IndexModeBits = IM.Value;
406
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000407 Format F = f;
408 bits<5> Form = F.Value;
409
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410 let Constraints = cstr;
411}
412
Evan Chengb783fa32007-07-19 01:14:50 +0000413class PseudoInst<dag oops, dag iops, string asm, list<dag> pattern>
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000414 : InstARM<0, AddrModeNone, SizeSpecial, IndexModeNone, Pseudo, ""> {
Evan Chengb783fa32007-07-19 01:14:50 +0000415 let OutOperandList = oops;
416 let InOperandList = iops;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000417 let AsmString = asm;
418 let Pattern = pattern;
419}
420
421// Almost all ARM instructions are predicable.
Evan Chengcce0af52007-09-10 22:22:23 +0000422class I<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
423 IndexMode im, Format f, string opc, string asm, string cstr,
424 list<dag> pattern>
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000425 : InstARM<opcod, am, sz, im, f, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000426 let OutOperandList = oops;
427 let InOperandList = !con(iops, (ops pred:$p));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428 let AsmString = !strconcat(opc, !strconcat("${p}", asm));
429 let Pattern = pattern;
430 list<Predicate> Predicates = [IsARM];
431}
432
Evan Chengb783fa32007-07-19 01:14:50 +0000433// Same as I except it can optionally modify CPSR. Note it's modeled as
434// an input operand since by default it's a zero register. It will
435// become an implicit def once it's "flipped".
Evan Chengcce0af52007-09-10 22:22:23 +0000436class sI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
437 IndexMode im, Format f, string opc, string asm, string cstr,
438 list<dag> pattern>
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000439 : InstARM<opcod, am, sz, im, f, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000440 let OutOperandList = oops;
441 let InOperandList = !con(iops, (ops pred:$p, cc_out:$s));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000442 let AsmString = !strconcat(opc, !strconcat("${p}${s}", asm));
443 let Pattern = pattern;
444 list<Predicate> Predicates = [IsARM];
445}
446
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000447class AI<bits<4> opcod, dag oops, dag iops, Format f, string opc,
448 string asm, list<dag> pattern>
449 : I<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, opc,
450 asm,"",pattern>;
451class AsI<bits<4> opcod, dag oops, dag iops, Format f, string opc,
452 string asm, list<dag> pattern>
453 : sI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, opc,
454 asm,"",pattern>;
455class AI1<bits<4> opcod, dag oops, dag iops, Format f, string opc,
456 string asm, list<dag> pattern>
457 : I<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc,
458 asm, "", pattern>;
459class AsI1<bits<4> opcod, dag oops, dag iops, Format f, string opc,
460 string asm, list<dag> pattern>
461 : sI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc,
462 asm, "", pattern>;
463class AI2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
464 string asm, list<dag> pattern>
465 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, opc,
466 asm, "", pattern>;
467class AI3<bits<4> opcod, dag oops, dag iops, Format f, string opc,
468 string asm, list<dag> pattern>
469 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, opc,
470 asm, "", pattern>;
471class AI4<bits<4> opcod, dag oops, dag iops, Format f, string opc,
472 string asm, list<dag> pattern>
473 : I<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, opc,
474 asm, "", pattern>;
475class AI1x2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
476 string asm, list<dag> pattern>
477 : I<opcod, oops, iops, AddrMode1, Size8Bytes, IndexModeNone, f, opc,
478 asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000479
480// Pre-indexed ops
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000481class AI2pr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
482 string asm, string cstr, list<dag> pattern>
483 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
484 asm, cstr, pattern>;
485class AI3pr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
486 string asm, string cstr, list<dag> pattern>
487 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePre, f, opc,
488 asm, cstr, pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489
490// Post-indexed ops
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000491class AI2po<bits<4> opcod, dag oops, dag iops, Format f, string opc,
492 string asm, string cstr, list<dag> pattern>
493 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
494 asm, cstr,pattern>;
495class AI3po<bits<4> opcod, dag oops, dag iops, Format f, string opc,
496 string asm, string cstr, list<dag> pattern>
497 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePost, f, opc,
498 asm, cstr,pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499
500
501class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
502class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
503
504
505/// AI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
506/// binop that produces a value.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000507multiclass AsI1_bin_irs<bits<4> opcod, string opc, PatFrag opnode> {
508 def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509 opc, " $dst, $a, $b",
510 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000511 def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPRReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512 opc, " $dst, $a, $b",
513 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000514 def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515 opc, " $dst, $a, $b",
516 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
517}
518
519/// ASI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
520/// instruction modifies the CSPR register.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000521let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000522multiclass ASI1_bin_s_irs<bits<4> opcod, string opc, PatFrag opnode> {
523 def ri : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRImS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000525 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000526 def rr : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPRRegS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000528 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000529 def rs : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoRegS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000531 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
532}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533}
534
535/// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
536/// patterns. Similar to AsI1_bin_irs except the instruction does not produce
537/// a explicit result, only implicitly set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000538let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000539multiclass AI1_cmp_irs<bits<4> opcod, string opc, PatFrag opnode> {
540 def ri : AI1<opcod, (outs), (ins GPR:$a, so_imm:$b), DPRnIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000542 [(opnode GPR:$a, so_imm:$b)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000543 def rr : AI1<opcod, (outs), (ins GPR:$a, GPR:$b), DPRnReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000545 [(opnode GPR:$a, GPR:$b)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000546 def rs : AI1<opcod, (outs), (ins GPR:$a, so_reg:$b), DPRnSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000548 [(opnode GPR:$a, so_reg:$b)]>;
549}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550}
551
552/// AI_unary_rrot - A unary operation with two forms: one whose operand is a
553/// register and one whose operand is a register rotated by 8/16/24.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000554multiclass AI_unary_rrot<bits<4> opcod, string opc, PatFrag opnode> {
555 def r : AI<opcod, (outs GPR:$dst), (ins GPR:$Src), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556 opc, " $dst, $Src",
557 [(set GPR:$dst, (opnode GPR:$Src))]>, Requires<[IsARM, HasV6]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000558 def r_rot : AI<opcod, (outs GPR:$dst), (ins GPR:$Src, i32imm:$rot), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559 opc, " $dst, $Src, ror $rot",
560 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>,
561 Requires<[IsARM, HasV6]>;
562}
563
564/// AI_bin_rrot - A binary operation with two forms: one whose operand is a
565/// register and one whose operand is a register rotated by 8/16/24.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000566multiclass AI_bin_rrot<bits<4> opcod, string opc, PatFrag opnode> {
567 def rr : AI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
568 Pseudo, opc, " $dst, $LHS, $RHS",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
570 Requires<[IsARM, HasV6]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000571 def rr_rot : AI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
572 Pseudo, opc, " $dst, $LHS, $RHS, ror $rot",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000573 [(set GPR:$dst, (opnode GPR:$LHS,
574 (rotr GPR:$RHS, rot_imm:$rot)))]>,
575 Requires<[IsARM, HasV6]>;
576}
577
578// Special cases.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000579class XI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
580 IndexMode im, Format f, string asm, string cstr, list<dag> pattern>
581 : InstARM<opcod, am, sz, im, f, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +0000582 let OutOperandList = oops;
583 let InOperandList = iops;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000584 let AsmString = asm;
585 let Pattern = pattern;
586 list<Predicate> Predicates = [IsARM];
587}
588
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000589class AXI<bits<4> opcod, dag oops, dag iops, Format f, string asm,
590 list<dag> pattern>
591 : XI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, asm,
592 "", pattern>;
593class AXI1<bits<4> opcod, dag oops, dag iops, Format f, string asm,
594 list<dag> pattern>
595 : XI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, asm,
596 "", pattern>;
597class AXI2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
598 list<dag> pattern>
599 : XI<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, asm,
600 "", pattern>;
601class AXI3<bits<4> opcod, dag oops, dag iops, Format f, string asm,
602 list<dag> pattern>
603 : XI<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, asm,
604 "", pattern>;
605class AXI4<bits<4> opcod, dag oops, dag iops, Format f, string asm,
606 list<dag> pattern>
607 : XI<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, asm,
608 "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000610class AXIx2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
611 list<dag> pattern>
612 : XI<opcod, oops, iops, AddrModeNone, Size8Bytes, IndexModeNone, f, asm,
613 "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614
615// BR_JT instructions
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000616class JTI<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
617 : XI<opcod, oops, iops, AddrModeNone, SizeSpecial, IndexModeNone, BranchMisc,
618 asm, "", pattern>;
619class JTI1<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
620 : XI<opcod, oops, iops, AddrMode1, SizeSpecial, IndexModeNone, BranchMisc,
621 asm, "", pattern>;
622class JTI2<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
623 : XI<opcod, oops, iops, AddrMode2, SizeSpecial, IndexModeNone, BranchMisc,
624 asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000625
626/// AsXI1_bin_c_irs - Same as AsI1_bin_irs but without the predicate operand and
627/// setting carry bit. But it can optionally set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000628let Uses = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000629multiclass AsXI1_bin_c_irs<bits<4> opcod, string opc, PatFrag opnode> {
630 def ri : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
631 DPRIm, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000632 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000633 def rr : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b, cc_out:$s),
634 DPRReg, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000635 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000636 def rs : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
637 DPRSoReg, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000638 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
639}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000640}
641
642//===----------------------------------------------------------------------===//
643// Instructions
644//===----------------------------------------------------------------------===//
645
646//===----------------------------------------------------------------------===//
647// Miscellaneous Instructions.
648//
649def 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
687let isLoad = 1, AddedComplexity = 10 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000688def PICLD : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
689 Pseudo, "${addr:label}:\n\tldr$p $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690 [(set GPR:$dst, (load addrmodepc:$addr))]>;
691
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000692def PICLDZH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
693 Pseudo, "${addr:label}:\n\tldr${p}h $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694 [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
695
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000696def PICLDZB : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
697 Pseudo, "${addr:label}:\n\tldr${p}b $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698 [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
699
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000700def PICLDH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
701 Pseudo, "${addr:label}:\n\tldr${p}h $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000702 [(set GPR:$dst, (extloadi16 addrmodepc:$addr))]>;
703
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000704def PICLDB : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
705 Pseudo, "${addr:label}:\n\tldr${p}b $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000706 [(set GPR:$dst, (extloadi8 addrmodepc:$addr))]>;
707
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000708def PICLDSH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
709 Pseudo, "${addr:label}:\n\tldr${p}sh $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000710 [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
711
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000712def PICLDSB : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
713 Pseudo, "${addr:label}:\n\tldr${p}sb $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000714 [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
715}
716let isStore = 1, AddedComplexity = 10 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000717def PICSTR : AXI2<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
718 Pseudo, "${addr:label}:\n\tstr$p $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000719 [(store GPR:$src, addrmodepc:$addr)]>;
720
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000721def PICSTRH : AXI3<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
722 Pseudo, "${addr:label}:\n\tstr${p}h $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000723 [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
724
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000725def PICSTRB : AXI2<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
726 Pseudo, "${addr:label}:\n\tstr${p}b $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000727 [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
728}
729}
730
731//===----------------------------------------------------------------------===//
732// Control Flow Instructions.
733//
734
735let isReturn = 1, isTerminator = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000736 def BX_RET : AI<0x1, (outs), (ins), BranchMisc, "bx", " lr", [(ARMretflag)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737
738// FIXME: remove when we have a way to marking a MI with these properties.
Evan Chengb783fa32007-07-19 01:14:50 +0000739// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
740// operand list.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741let isLoad = 1, isReturn = 1, isTerminator = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000742 def LDM_RET : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000743 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000744 LdFrm, "ldm${p}${addr:submode} $addr, $dst1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000745 []>;
746
Evan Cheng37e7c752007-07-21 00:34:19 +0000747let isCall = 1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000748 Defs = [R0, R1, R2, R3, R12, LR,
749 D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000750 def BL : AXI<0xB, (outs), (ins i32imm:$func, variable_ops), Branch,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751 "bl ${func:call}",
752 [(ARMcall tglobaladdr:$func)]>;
753
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000754 def BL_pred : AI<0xB, (outs), (ins i32imm:$func, variable_ops),
755 Branch, "bl", " ${func:call}",
756 [(ARMcall_pred tglobaladdr:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757
758 // ARMv5T and above
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000759 def BLX : AXI<0x2, (outs), (ins GPR:$func, variable_ops), BranchMisc,
Evan Chengb783fa32007-07-19 01:14:50 +0000760 "blx $func",
761 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000762 let Uses = [LR] in {
763 // ARMv4T
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000764 def BX : AXIx2<0x0, (outs), (ins GPR:$func, variable_ops),
765 BranchMisc, "mov lr, pc\n\tbx $func",
766 [(ARMcall_nolink GPR:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000767 }
768}
769
Evan Cheng37e7c752007-07-21 00:34:19 +0000770let isBranch = 1, isTerminator = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 // B is "predicable" since it can be xformed into a Bcc.
772 let isBarrier = 1 in {
773 let isPredicable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000774 def B : AXI<0xA, (outs), (ins brtarget:$target), Branch, "b $target",
Evan Chengb783fa32007-07-19 01:14:50 +0000775 [(br bb:$target)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776
Owen Andersonf8053082007-11-12 07:39:39 +0000777 let isNotDuplicable = 1, isIndirectBranch = 1 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000778 def BR_JTr : JTI<0x0, (outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
Evan Chengb783fa32007-07-19 01:14:50 +0000779 "mov pc, $target \n$jt",
780 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000781 def BR_JTm : JTI2<0x0, (outs), (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
Evan Chengb783fa32007-07-19 01:14:50 +0000782 "ldr pc, $target \n$jt",
783 [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000784 imm:$id)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000785 def BR_JTadd : JTI1<0x0, (outs), (ins GPR:$target, GPR:$idx, jtblock_operand:$jt,
Evan Chengb783fa32007-07-19 01:14:50 +0000786 i32imm:$id),
787 "add pc, $target, $idx \n$jt",
788 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000789 imm:$id)]>;
790 }
791 }
792
793 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
794 // a two-value operand where a dag node expects two operands. :(
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000795 def Bcc : AI<0xA, (outs), (ins brtarget:$target), Branch,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000796 "b", " $target",
797 [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000798}
799
800//===----------------------------------------------------------------------===//
801// Load / store Instructions.
802//
803
804// Load
805let isLoad = 1 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000806def LDR : AI2<0x0, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000807 "ldr", " $dst, $addr",
808 [(set GPR:$dst, (load addrmode2:$addr))]>;
809
810// Special LDR for loads from non-pc-relative constpools.
811let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000812def LDRcp : AI2<0x0, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000813 "ldr", " $dst, $addr", []>;
814
815// Loads with zero extension
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000816def LDRH : AI3<0xB, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000817 "ldr", "h $dst, $addr",
818 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
819
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000820def LDRB : AI2<0x1, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821 "ldr", "b $dst, $addr",
822 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
823
824// Loads with sign extension
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000825def LDRSH : AI3<0xE, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000826 "ldr", "sh $dst, $addr",
827 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
828
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000829def LDRSB : AI3<0xD, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830 "ldr", "sb $dst, $addr",
831 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
832
833// Load doubleword
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000834def LDRD : AI3<0xD, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000835 "ldr", "d $dst, $addr",
836 []>, Requires<[IsARM, HasV5T]>;
837
838// Indexed loads
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000839def LDR_PRE : AI2pr<0x0, (outs GPR:$dst, GPR:$base_wb),
840 (ins addrmode2:$addr), LdFrm,
841 "ldr", " $dst, $addr!", "$addr.base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000843def LDR_POST : AI2po<0x0, (outs GPR:$dst, GPR:$base_wb),
844 (ins GPR:$base, am2offset:$offset), LdFrm,
845 "ldr", " $dst, [$base], $offset", "$base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000846
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000847def LDRH_PRE : AI3pr<0xB, (outs GPR:$dst, GPR:$base_wb),
848 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000849 "ldr", "h $dst, $addr!", "$addr.base = $base_wb", []>;
850
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000851def LDRH_POST : AI3po<0xB, (outs GPR:$dst, GPR:$base_wb),
852 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853 "ldr", "h $dst, [$base], $offset", "$base = $base_wb", []>;
854
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000855def LDRB_PRE : AI2pr<0x1, (outs GPR:$dst, GPR:$base_wb),
856 (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000857 "ldr", "b $dst, $addr!", "$addr.base = $base_wb", []>;
858
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000859def LDRB_POST : AI2po<0x1, (outs GPR:$dst, GPR:$base_wb),
860 (ins GPR:$base,am2offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000861 "ldr", "b $dst, [$base], $offset", "$base = $base_wb", []>;
862
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000863def LDRSH_PRE : AI3pr<0xE, (outs GPR:$dst, GPR:$base_wb),
864 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865 "ldr", "sh $dst, $addr!", "$addr.base = $base_wb", []>;
866
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000867def LDRSH_POST: AI3po<0xE, (outs GPR:$dst, GPR:$base_wb),
868 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000869 "ldr", "sh $dst, [$base], $offset", "$base = $base_wb", []>;
870
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000871def LDRSB_PRE : AI3pr<0xD, (outs GPR:$dst, GPR:$base_wb),
872 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000873 "ldr", "sb $dst, $addr!", "$addr.base = $base_wb", []>;
874
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000875def LDRSB_POST: AI3po<0xD, (outs GPR:$dst, GPR:$base_wb),
876 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000877 "ldr", "sb $dst, [$base], $offset", "$base = $base_wb", []>;
878} // isLoad
879
880// Store
881let isStore = 1 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000882def STR : AI2<0x0, (outs), (ins GPR:$src, addrmode2:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000883 "str", " $src, $addr",
884 [(store GPR:$src, addrmode2:$addr)]>;
885
886// Stores with truncate
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000887def STRH : AI3<0xB, (outs), (ins GPR:$src, addrmode3:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000888 "str", "h $src, $addr",
889 [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
890
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000891def STRB : AI2<0x1, (outs), (ins GPR:$src, addrmode2:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000892 "str", "b $src, $addr",
893 [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
894
895// Store doubleword
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000896def STRD : AI3<0xF, (outs), (ins GPR:$src, addrmode3:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000897 "str", "d $src, $addr",
898 []>, Requires<[IsARM, HasV5T]>;
899
900// Indexed stores
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000901def STR_PRE : AI2pr<0x0, (outs GPR:$base_wb),
902 (ins GPR:$src, GPR:$base, am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000903 "str", " $src, [$base, $offset]!", "$base = $base_wb",
904 [(set GPR:$base_wb,
905 (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
906
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000907def STR_POST : AI2po<0x0, (outs GPR:$base_wb),
908 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000909 "str", " $src, [$base], $offset", "$base = $base_wb",
910 [(set GPR:$base_wb,
911 (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
912
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000913def STRH_PRE : AI3pr<0xB, (outs GPR:$base_wb),
914 (ins GPR:$src, GPR:$base,am3offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000915 "str", "h $src, [$base, $offset]!", "$base = $base_wb",
916 [(set GPR:$base_wb,
917 (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
918
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000919def STRH_POST: AI3po<0xB, (outs GPR:$base_wb),
920 (ins GPR:$src, GPR:$base,am3offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000921 "str", "h $src, [$base], $offset", "$base = $base_wb",
922 [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
923 GPR:$base, am3offset:$offset))]>;
924
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000925def STRB_PRE : AI2pr<0x1, (outs GPR:$base_wb),
926 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000927 "str", "b $src, [$base, $offset]!", "$base = $base_wb",
928 [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
929 GPR:$base, am2offset:$offset))]>;
930
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000931def STRB_POST: AI2po<0x1, (outs GPR:$base_wb),
932 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000933 "str", "b $src, [$base], $offset", "$base = $base_wb",
934 [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
935 GPR:$base, am2offset:$offset))]>;
936} // isStore
937
938//===----------------------------------------------------------------------===//
939// Load / store multiple Instructions.
940//
941
Evan Chengb783fa32007-07-19 01:14:50 +0000942// FIXME: $dst1 should be a def.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000943let isLoad = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000944def LDM : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000945 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000946 LdFrm, "ldm${p}${addr:submode} $addr, $dst1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000947 []>;
948
949let isStore = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000950def STM : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000951 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000952 StFrm, "stm${p}${addr:submode} $addr, $src1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000953 []>;
954
955//===----------------------------------------------------------------------===//
956// Move Instructions.
957//
958
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000959def MOVr : AsI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000960 "mov", " $dst, $src", []>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000961def MOVs : AsI1<0xD, (outs GPR:$dst), (ins so_reg:$src), DPRdSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000962 "mov", " $dst, $src", [(set GPR:$dst, so_reg:$src)]>;
963
964let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000965def MOVi : AsI1<0xD, (outs GPR:$dst), (ins so_imm:$src), DPRdIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000966 "mov", " $dst, $src", [(set GPR:$dst, so_imm:$src)]>;
967
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000968def MOVrx : AsI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Evan Chengb783fa32007-07-19 01:14:50 +0000969 "mov", " $dst, $src, rrx",
970 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000971
972// These aren't really mov instructions, but we have to define them this way
973// due to flag operands.
974
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000975let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000976def MOVsrl_flag : AI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000977 "mov", "s $dst, $src, lsr #1",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000978 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000979def MOVsra_flag : AI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000980 "mov", "s $dst, $src, asr #1",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000981 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>;
982}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000983
984//===----------------------------------------------------------------------===//
985// Extend Instructions.
986//
987
988// Sign extenders
989
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000990defm SXTB : AI_unary_rrot<0x0, "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
991defm SXTH : AI_unary_rrot<0x0, "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000992
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000993defm SXTAB : AI_bin_rrot<0x0, "sxtab",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000994 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000995defm SXTAH : AI_bin_rrot<0x0, "sxtah",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000996 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
997
998// TODO: SXT(A){B|H}16
999
1000// Zero extenders
1001
1002let AddedComplexity = 16 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001003defm UXTB : AI_unary_rrot<0x0, "uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
1004defm UXTH : AI_unary_rrot<0x0, "uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
1005defm UXTB16 : AI_unary_rrot<0x0, "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006
1007def : ARMV6Pat<(and (shl GPR:$Src, 8), 0xFF00FF),
1008 (UXTB16r_rot GPR:$Src, 24)>;
1009def : ARMV6Pat<(and (srl GPR:$Src, 8), 0xFF00FF),
1010 (UXTB16r_rot GPR:$Src, 8)>;
1011
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001012defm UXTAB : AI_bin_rrot<0x0, "uxtab",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001013 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001014defm UXTAH : AI_bin_rrot<0x0, "uxtah",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001015 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
1016}
1017
1018// This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
1019//defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
1020
1021// TODO: UXT(A){B|H}16
1022
1023//===----------------------------------------------------------------------===//
1024// Arithmetic Instructions.
1025//
1026
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001027defm ADD : AsI1_bin_irs<0x4, "add", BinOpFrag<(add node:$LHS, node:$RHS)>>;
1028defm SUB : AsI1_bin_irs<0x2, "sub", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001029
1030// ADD and SUB with 's' bit set.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001031defm ADDS : ASI1_bin_s_irs<0x4, "add", BinOpFrag<(addc node:$LHS, node:$RHS)>>;
1032defm SUBS : ASI1_bin_s_irs<0x2, "sub", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033
1034// FIXME: Do not allow ADC / SBC to be predicated for now.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001035defm ADC : AsXI1_bin_c_irs<0x5, "adc", BinOpFrag<(adde node:$LHS, node:$RHS)>>;
1036defm SBC : AsXI1_bin_c_irs<0x6, "sbc", BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001037
1038// These don't define reg/reg forms, because they are handled above.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001039def RSBri : AsI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001040 "rsb", " $dst, $a, $b",
1041 [(set GPR:$dst, (sub so_imm:$b, GPR:$a))]>;
1042
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001043def RSBrs : AsI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001044 "rsb", " $dst, $a, $b",
1045 [(set GPR:$dst, (sub so_reg:$b, GPR:$a))]>;
1046
1047// RSB with 's' bit set.
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001048let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001049def RSBSri : AI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001050 "rsb", "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001051 [(set GPR:$dst, (subc so_imm:$b, GPR:$a))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001052def RSBSrs : AI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001053 "rsb", "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001054 [(set GPR:$dst, (subc so_reg:$b, GPR:$a))]>;
1055}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001056
1057// FIXME: Do not allow RSC to be predicated for now. But they can set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001058let Uses = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001059def RSCri : AXI1<0x7, (outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
1060 DPRIm, "rsc${s} $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001061 [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001062def RSCrs : AXI1<0x7, (outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
1063 DPRSoReg, "rsc${s} $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +00001064 [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>;
1065}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001066
1067// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
1068def : ARMPat<(add GPR:$src, so_imm_neg:$imm),
1069 (SUBri GPR:$src, so_imm_neg:$imm)>;
1070
1071//def : ARMPat<(addc GPR:$src, so_imm_neg:$imm),
1072// (SUBSri GPR:$src, so_imm_neg:$imm)>;
1073//def : ARMPat<(adde GPR:$src, so_imm_neg:$imm),
1074// (SBCri GPR:$src, so_imm_neg:$imm)>;
1075
1076// Note: These are implemented in C++ code, because they have to generate
1077// ADD/SUBrs instructions, which use a complex pattern that a xform function
1078// cannot produce.
1079// (mul X, 2^n+1) -> (add (X << n), X)
1080// (mul X, 2^n-1) -> (rsb X, (X << n))
1081
1082
1083//===----------------------------------------------------------------------===//
1084// Bitwise Instructions.
1085//
1086
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001087defm AND : AsI1_bin_irs<0x0, "and", BinOpFrag<(and node:$LHS, node:$RHS)>>;
1088defm ORR : AsI1_bin_irs<0xC, "orr", BinOpFrag<(or node:$LHS, node:$RHS)>>;
1089defm EOR : AsI1_bin_irs<0x1, "eor", BinOpFrag<(xor node:$LHS, node:$RHS)>>;
1090defm BIC : AsI1_bin_irs<0xE, "bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001091
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001092def MVNr : AsI<0xE, (outs GPR:$dst), (ins GPR:$src), DPRdReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001093 "mvn", " $dst, $src", [(set GPR:$dst, (not GPR:$src))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001094def MVNs : AsI<0xE, (outs GPR:$dst), (ins so_reg:$src), DPRdSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095 "mvn", " $dst, $src", [(set GPR:$dst, (not so_reg:$src))]>;
1096let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001097def MVNi : AsI<0xE, (outs GPR:$dst), (ins so_imm:$imm), DPRdIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001098 "mvn", " $dst, $imm", [(set GPR:$dst, so_imm_not:$imm)]>;
1099
1100def : ARMPat<(and GPR:$src, so_imm_not:$imm),
1101 (BICri GPR:$src, so_imm_not:$imm)>;
1102
1103//===----------------------------------------------------------------------===//
1104// Multiply Instructions.
1105//
1106
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001107def MUL : AsI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulFrm,
1108 "mul", " $dst, $a, $b",
1109 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001110
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001111def MLA : AsI<0x2, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
1112 MulFrm, "mla", " $dst, $a, $b, $c",
1113 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001114
1115// Extra precision multiplies with low / high results
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001116def SMULL : AsI<0xC, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
1117 MulFrm, "smull", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001118
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001119def UMULL : AsI<0x8, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
1120 MulFrm, "umull", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001121
1122// Multiply + accumulate
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001123def SMLAL : AsI<0xE, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
1124 MulFrm, "smlal", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001125
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001126def UMLAL : AsI<0xA, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
1127 MulFrm, "umlal", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001128
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001129def UMAAL : AI<0x0, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001130 "umaal", " $ldst, $hdst, $a, $b", []>,
1131 Requires<[IsARM, HasV6]>;
1132
1133// Most significant word multiply
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001134def SMMUL : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001135 "smmul", " $dst, $a, $b",
1136 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>,
1137 Requires<[IsARM, HasV6]>;
1138
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001139def SMMLA : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001140 "smmla", " $dst, $a, $b, $c",
1141 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>,
1142 Requires<[IsARM, HasV6]>;
1143
1144
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001145def SMMLS : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001146 "smmls", " $dst, $a, $b, $c",
1147 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
1148 Requires<[IsARM, HasV6]>;
1149
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001150multiclass AI_smul<string opc, PatFrag opnode> {
1151 def BB : AI<0x8, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001152 !strconcat(opc, "bb"), " $dst, $a, $b",
1153 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1154 (sext_inreg GPR:$b, i16)))]>,
1155 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001156
1157 def BT : AI<0xC, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001158 !strconcat(opc, "bt"), " $dst, $a, $b",
1159 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
1160 (sra GPR:$b, 16)))]>,
1161 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001162
1163 def TB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001164 !strconcat(opc, "tb"), " $dst, $a, $b",
1165 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
1166 (sext_inreg GPR:$b, i16)))]>,
1167 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001168
1169 def TT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001170 !strconcat(opc, "tt"), " $dst, $a, $b",
1171 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
1172 (sra GPR:$b, 16)))]>,
1173 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001174
1175 def WB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMULW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001176 !strconcat(opc, "wb"), " $dst, $a, $b",
1177 [(set GPR:$dst, (sra (opnode GPR:$a,
1178 (sext_inreg GPR:$b, i16)), 16))]>,
1179 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001180
1181 def WT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMULW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001182 !strconcat(opc, "wt"), " $dst, $a, $b",
1183 [(set GPR:$dst, (sra (opnode GPR:$a,
1184 (sra GPR:$b, 16)), 16))]>,
1185 Requires<[IsARM, HasV5TE]>;
1186}
1187
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001188
1189multiclass AI_smla<string opc, PatFrag opnode> {
1190 def BB : AI<0x8, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001191 !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
1192 [(set GPR:$dst, (add GPR:$acc,
1193 (opnode (sext_inreg GPR:$a, i16),
1194 (sext_inreg GPR:$b, i16))))]>,
1195 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001196
1197 def BT : AI<0xC, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001198 !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
1199 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
1200 (sra GPR:$b, 16))))]>,
1201 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001202
1203 def TB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001204 !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
1205 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1206 (sext_inreg GPR:$b, i16))))]>,
1207 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001208
1209 def TT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001210 !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
1211 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1212 (sra GPR:$b, 16))))]>,
1213 Requires<[IsARM, HasV5TE]>;
1214
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001215 def WB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLAW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001216 !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
1217 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1218 (sext_inreg GPR:$b, i16)), 16)))]>,
1219 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001220
1221 def WT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLAW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001222 !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
1223 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1224 (sra GPR:$b, 16)), 16)))]>,
1225 Requires<[IsARM, HasV5TE]>;
1226}
1227
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001228defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1229defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001230
1231// TODO: Halfword multiple accumulate long: SMLAL<x><y>
1232// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
1233
1234//===----------------------------------------------------------------------===//
1235// Misc. Arithmetic Instructions.
1236//
1237
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001238def CLZ : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001239 "clz", " $dst, $src",
1240 [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]>;
1241
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001242def REV : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001243 "rev", " $dst, $src",
1244 [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]>;
1245
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001246def REV16 : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001247 "rev16", " $dst, $src",
1248 [(set GPR:$dst,
1249 (or (and (srl GPR:$src, 8), 0xFF),
1250 (or (and (shl GPR:$src, 8), 0xFF00),
1251 (or (and (srl GPR:$src, 8), 0xFF0000),
1252 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
1253 Requires<[IsARM, HasV6]>;
1254
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001255def REVSH : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001256 "revsh", " $dst, $src",
1257 [(set GPR:$dst,
1258 (sext_inreg
1259 (or (srl (and GPR:$src, 0xFF00), 8),
1260 (shl GPR:$src, 8)), i16))]>,
1261 Requires<[IsARM, HasV6]>;
1262
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001263def PKHBT : AI<0x0, (outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1264 Pseudo, "pkhbt", " $dst, $src1, $src2, LSL $shamt",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001265 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1266 (and (shl GPR:$src2, (i32 imm:$shamt)),
1267 0xFFFF0000)))]>,
1268 Requires<[IsARM, HasV6]>;
1269
1270// Alternate cases for PKHBT where identities eliminate some nodes.
1271def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1272 (PKHBT GPR:$src1, GPR:$src2, 0)>;
1273def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1274 (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
1275
1276
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001277def PKHTB : AI<0x0, (outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1278 Pseudo, "pkhtb", " $dst, $src1, $src2, ASR $shamt",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001279 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1280 (and (sra GPR:$src2, imm16_31:$shamt),
1281 0xFFFF)))]>, Requires<[IsARM, HasV6]>;
1282
1283// Alternate cases for PKHTB where identities eliminate some nodes. Note that
1284// a shift amount of 0 is *not legal* here, it is PKHBT instead.
1285def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, 16)),
1286 (PKHTB GPR:$src1, GPR:$src2, 16)>;
1287def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1288 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1289 (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1290
1291
1292//===----------------------------------------------------------------------===//
1293// Comparison Instructions...
1294//
1295
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001296defm CMP : AI1_cmp_irs<0xA, "cmp",
1297 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1298defm CMN : AI1_cmp_irs<0xB, "cmn",
1299 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001300
1301// Note that TST/TEQ don't set all the same flags that CMP does!
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001302defm TST : AI1_cmp_irs<0x8, "tst",
1303 BinOpFrag<(ARMcmpNZ (and node:$LHS, node:$RHS), 0)>>;
1304defm TEQ : AI1_cmp_irs<0x9, "teq",
1305 BinOpFrag<(ARMcmpNZ (xor node:$LHS, node:$RHS), 0)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001306
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001307defm CMPnz : AI1_cmp_irs<0xA, "cmp",
1308 BinOpFrag<(ARMcmpNZ node:$LHS, node:$RHS)>>;
1309defm CMNnz : AI1_cmp_irs<0xA, "cmn",
1310 BinOpFrag<(ARMcmpNZ node:$LHS,(ineg node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001311
1312def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1313 (CMNri GPR:$src, so_imm_neg:$imm)>;
1314
1315def : ARMPat<(ARMcmpNZ GPR:$src, so_imm_neg:$imm),
1316 (CMNri GPR:$src, so_imm_neg:$imm)>;
1317
1318
1319// Conditional moves
1320// FIXME: should be able to write a pattern for ARMcmov, but can't use
1321// a two-value operand where a dag node expects two operands. :(
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001322def MOVCCr : AI<0xD, (outs GPR:$dst), (ins GPR:$false, GPR:$true),
1323 DPRdReg, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001324 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1325 RegConstraint<"$false = $dst">;
1326
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001327def MOVCCs : AI<0xD, (outs GPR:$dst), (ins GPR:$false, so_reg:$true),
1328 DPRdSoReg, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001329 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1330 RegConstraint<"$false = $dst">;
1331
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001332def MOVCCi : AI<0xD, (outs GPR:$dst), (ins GPR:$false, so_imm:$true),
1333 DPRdIm, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001334 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1335 RegConstraint<"$false = $dst">;
1336
1337
1338// LEApcrel - Load a pc-relative address into a register without offending the
1339// assembler.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001340def LEApcrel : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, pred:$p), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001341 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
1342 "${:private}PCRELL${:uid}+8))\n"),
1343 !strconcat("${:private}PCRELL${:uid}:\n\t",
1344 "add$p $dst, pc, #PCRELV${:uid}")),
1345 []>;
1346
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001347def LEApcrelJT : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, i32imm:$id, pred:$p),
1348 Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001349 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
1350 "${:private}PCRELL${:uid}+8))\n"),
1351 !strconcat("${:private}PCRELL${:uid}:\n\t",
1352 "add$p $dst, pc, #PCRELV${:uid}")),
1353 []>;
1354
1355//===----------------------------------------------------------------------===//
1356// TLS Instructions
1357//
1358
1359// __aeabi_read_tp preserves the registers r1-r3.
1360let isCall = 1,
1361 Defs = [R0, R12, LR, CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001362 def TPsoft : AXI<0x0, (outs), (ins), BranchMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001363 "bl __aeabi_read_tp",
1364 [(set R0, ARMthread_pointer)]>;
1365}
1366
1367//===----------------------------------------------------------------------===//
1368// Non-Instruction Patterns
1369//
1370
1371// ConstantPool, GlobalAddress, and JumpTable
1372def : ARMPat<(ARMWrapper tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>;
1373def : ARMPat<(ARMWrapper tconstpool :$dst), (LEApcrel tconstpool :$dst)>;
1374def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1375 (LEApcrelJT tjumptable:$dst, imm:$id)>;
1376
1377// Large immediate handling.
1378
1379// Two piece so_imms.
1380let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001381def MOVi2pieces : AI1x2<0x0, (outs GPR:$dst), (ins so_imm2part:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001382 "mov", " $dst, $src",
1383 [(set GPR:$dst, so_imm2part:$src)]>;
1384
1385def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1386 (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1387 (so_imm2part_2 imm:$RHS))>;
1388def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1389 (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1390 (so_imm2part_2 imm:$RHS))>;
1391
1392// TODO: add,sub,and, 3-instr forms?
1393
1394
1395// Direct calls
1396def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>;
1397
1398// zextload i1 -> zextload i8
1399def : ARMPat<(zextloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1400
1401// extload -> zextload
1402def : ARMPat<(extloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1403def : ARMPat<(extloadi8 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1404def : ARMPat<(extloadi16 addrmode3:$addr), (LDRH addrmode3:$addr)>;
1405
1406// truncstore i1 -> truncstore i8
1407def : ARMPat<(truncstorei1 GPR:$src, addrmode2:$dst),
1408 (STRB GPR:$src, addrmode2:$dst)>;
1409def : ARMPat<(pre_truncsti1 GPR:$src, GPR:$base, am2offset:$offset),
1410 (STRB_PRE GPR:$src, GPR:$base, am2offset:$offset)>;
1411def : ARMPat<(post_truncsti1 GPR:$src, GPR:$base, am2offset:$offset),
1412 (STRB_POST GPR:$src, GPR:$base, am2offset:$offset)>;
1413
1414// smul* and smla*
1415def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra (shl GPR:$b, 16), 16)),
1416 (SMULBB GPR:$a, GPR:$b)>;
1417def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1418 (SMULBB GPR:$a, GPR:$b)>;
1419def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16)),
1420 (SMULBT GPR:$a, GPR:$b)>;
1421def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, 16)),
1422 (SMULBT GPR:$a, GPR:$b)>;
1423def : ARMV5TEPat<(mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16)),
1424 (SMULTB GPR:$a, GPR:$b)>;
1425def : ARMV5TEPat<(mul (sra GPR:$a, 16), sext_16_node:$b),
1426 (SMULTB GPR:$a, GPR:$b)>;
1427def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16),
1428 (SMULWB GPR:$a, GPR:$b)>;
1429def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), 16),
1430 (SMULWB GPR:$a, GPR:$b)>;
1431
1432def : ARMV5TEPat<(add GPR:$acc,
1433 (mul (sra (shl GPR:$a, 16), 16),
1434 (sra (shl GPR:$b, 16), 16))),
1435 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1436def : ARMV5TEPat<(add GPR:$acc,
1437 (mul sext_16_node:$a, sext_16_node:$b)),
1438 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1439def : ARMV5TEPat<(add GPR:$acc,
1440 (mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16))),
1441 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1442def : ARMV5TEPat<(add GPR:$acc,
1443 (mul sext_16_node:$a, (sra GPR:$b, 16))),
1444 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1445def : ARMV5TEPat<(add GPR:$acc,
1446 (mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16))),
1447 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1448def : ARMV5TEPat<(add GPR:$acc,
1449 (mul (sra GPR:$a, 16), sext_16_node:$b)),
1450 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1451def : ARMV5TEPat<(add GPR:$acc,
1452 (sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16)),
1453 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1454def : ARMV5TEPat<(add GPR:$acc,
1455 (sra (mul GPR:$a, sext_16_node:$b), 16)),
1456 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1457
1458//===----------------------------------------------------------------------===//
1459// Thumb Support
1460//
1461
1462include "ARMInstrThumb.td"
1463
1464//===----------------------------------------------------------------------===//
1465// Floating Point Support
1466//
1467
1468include "ARMInstrVFP.td"