blob: bde81bcfe8ad8f06d94dfc08dccb04227cb5ed66 [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===- ARMInstrInfo.td - Target Description for ARM Target -*- tablegen -*-===//
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002//
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
Evan Chenga8e29892007-01-19 07:51:42 +000015//===----------------------------------------------------------------------===//
16// ARM specific DAG Nodes.
17//
Rafael Espindola7cca7c52006-09-11 17:25:40 +000018
Evan Chenga8e29892007-01-19 07:51:42 +000019// Type profiles.
20def SDT_ARMCallSeq : SDTypeProfile<0, 1, [ SDTCisVT<0, i32> ]>;
Rafael Espindola6e8c6492006-11-08 17:07:32 +000021
Evan Chenga8e29892007-01-19 07:51:42 +000022def SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
Rafael Espindola32bd5f42006-10-17 18:04:53 +000023
Evan Chenga8e29892007-01-19 07:51:42 +000024def SDT_ARMcall : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
Rafael Espindola7cca7c52006-09-11 17:25:40 +000025
Evan Chenga8e29892007-01-19 07:51:42 +000026def SDT_ARMCMov : SDTypeProfile<1, 3,
27 [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
28 SDTCisVT<3, i32>]>;
Rafael Espindola6e8c6492006-11-08 17:07:32 +000029
Evan Chenga8e29892007-01-19 07:51:42 +000030def 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
42// Node definitions.
43def ARMWrapper : SDNode<"ARMISD::Wrapper", SDTIntUnaryOp>;
44def ARMWrapperCall : SDNode<"ARMISD::WrapperCall", SDTIntUnaryOp>;
45def ARMWrapperJT : SDNode<"ARMISD::WrapperJT", SDTIntBinOp>;
46
47def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeq,
48 [SDNPHasChain, SDNPOutFlag]>;
49def ARMcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_ARMCallSeq,
50 [SDNPHasChain, SDNPOutFlag]>;
51
52def ARMcall : SDNode<"ARMISD::CALL", SDT_ARMcall,
53 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
54def ARMcall_nolink : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
55 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
56
57def ARMretflag : SDNode<"ARMISD::RET_FLAG", SDTRet,
58 [SDNPHasChain, SDNPOptInFlag]>;
59
60def ARMcmov : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
61 [SDNPInFlag]>;
62def ARMcneg : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
63 [SDNPInFlag]>;
64
65def ARMbrcond : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
66 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
67
68def ARMbrjt : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
69 [SDNPHasChain]>;
70
71def ARMcmp : SDNode<"ARMISD::CMP", SDT_ARMCmp,
72 [SDNPOutFlag]>;
73
74def ARMpic_add : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
75
76def ARMsrl_flag : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
77def ARMsra_flag : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
78def ARMrrx : SDNode<"ARMISD::RRX" , SDTIntUnaryOp, [SDNPInFlag ]>;
Rafael Espindola32bd5f42006-10-17 18:04:53 +000079
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000080//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +000081// ARM Instruction Predicate Definitions.
82//
83def HasV5T : Predicate<"Subtarget->hasV5TOps()">;
84def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">;
85def HasV6 : Predicate<"Subtarget->hasV6Ops()">;
86def IsThumb : Predicate<"Subtarget->isThumb()">;
87def IsARM : Predicate<"!Subtarget->isThumb()">;
88
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000089//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +000090// ARM Flag Definitions.
91
92class RegConstraint<string C> {
93 string Constraints = C;
94}
95
96//===----------------------------------------------------------------------===//
97// ARM specific transformation functions and pattern fragments.
98//
99
100// so_imm_XFORM - Return a so_imm value packed into the format described for
101// so_imm def below.
102def so_imm_XFORM : SDNodeXForm<imm, [{
103 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(N->getValue()),
104 MVT::i32);
105}]>;
106
107// so_imm_neg_XFORM - Return a so_imm value packed into the format described for
108// so_imm_neg def below.
109def so_imm_neg_XFORM : SDNodeXForm<imm, [{
110 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(-(int)N->getValue()),
111 MVT::i32);
112}]>;
113
114// so_imm_not_XFORM - Return a so_imm value packed into the format described for
115// so_imm_not def below.
116def so_imm_not_XFORM : SDNodeXForm<imm, [{
117 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(~(int)N->getValue()),
118 MVT::i32);
119}]>;
120
121// rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
122def rot_imm : PatLeaf<(i32 imm), [{
123 int32_t v = (int32_t)N->getValue();
124 return v == 8 || v == 16 || v == 24;
125}]>;
126
127/// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
128def imm1_15 : PatLeaf<(i32 imm), [{
129 return (int32_t)N->getValue() >= 1 && (int32_t)N->getValue() < 16;
130}]>;
131
132/// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
133def imm16_31 : PatLeaf<(i32 imm), [{
134 return (int32_t)N->getValue() >= 16 && (int32_t)N->getValue() < 32;
135}]>;
136
137def so_imm_neg :
138 PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(-(int)N->getValue()) != -1; }],
139 so_imm_neg_XFORM>;
140
141def so_imm_not :
142 PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(~(int)N->getValue()) != -1; }],
143 so_imm_not_XFORM>;
144
145// sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
146def sext_16_node : PatLeaf<(i32 GPR:$a), [{
147 return TLI.ComputeNumSignBits(SDOperand(N,0)) >= 17;
148}]>;
149
150
151// Break so_imm's up into two pieces. This handles immediates with up to 16
152// bits set in them. This uses so_imm2part to match and so_imm2part_[12] to
153// get the first/second pieces.
154def so_imm2part : PatLeaf<(imm), [{
155 return ARM_AM::isSOImmTwoPartVal((unsigned)N->getValue());
156}]>;
157
158def so_imm2part_1 : SDNodeXForm<imm, [{
159 unsigned V = ARM_AM::getSOImmTwoPartFirst((unsigned)N->getValue());
160 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
161}]>;
162
163def so_imm2part_2 : SDNodeXForm<imm, [{
164 unsigned V = ARM_AM::getSOImmTwoPartSecond((unsigned)N->getValue());
165 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(V), MVT::i32);
166}]>;
167
168
169
170//===----------------------------------------------------------------------===//
171// Operand Definitions.
172//
173
174// Branch target.
175def brtarget : Operand<OtherVT>;
176
177// Operand for printing out a condition code.
178def CCOp : Operand<i32> {
179 let PrintMethod = "printCCOperand";
180}
181
182// A list of registers separated by comma. Used by load/store multiple.
183def reglist : Operand<i32> {
184 let PrintMethod = "printRegisterList";
185}
186
187// An operand for the CONSTPOOL_ENTRY pseudo-instruction.
188def cpinst_operand : Operand<i32> {
189 let PrintMethod = "printCPInstOperand";
190}
191
192def jtblock_operand : Operand<i32> {
193 let PrintMethod = "printJTBlockOperand";
194}
195
196// Local PC labels.
197def pclabel : Operand<i32> {
198 let PrintMethod = "printPCLabel";
199}
200
201// shifter_operand operands: so_reg and so_imm.
202def so_reg : Operand<i32>, // reg reg imm
203 ComplexPattern<i32, 3, "SelectShifterOperandReg",
204 [shl,srl,sra,rotr]> {
205 let PrintMethod = "printSORegOperand";
206 let MIOperandInfo = (ops GPR, GPR, i32imm);
207}
208
209// so_imm - Match a 32-bit shifter_operand immediate operand, which is an
210// 8-bit immediate rotated by an arbitrary number of bits. so_imm values are
211// represented in the imm field in the same 12-bit form that they are encoded
212// into so_imm instructions: the 8-bit immediate is the least significant bits
213// [bits 0-7], the 4-bit shift amount is the next 4 bits [bits 8-11].
214def so_imm : Operand<i32>,
215 PatLeaf<(imm),
216 [{ return ARM_AM::getSOImmVal(N->getValue()) != -1; }],
217 so_imm_XFORM> {
218 let PrintMethod = "printSOImmOperand";
219}
220
221
222// Define ARM specific addressing modes.
223
224// addrmode2 := reg +/- reg shop imm
225// addrmode2 := reg +/- imm12
226//
227def addrmode2 : Operand<i32>,
228 ComplexPattern<i32, 3, "SelectAddrMode2", []> {
229 let PrintMethod = "printAddrMode2Operand";
230 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
231}
232
233def am2offset : Operand<i32>,
234 ComplexPattern<i32, 2, "SelectAddrMode2Offset", []> {
235 let PrintMethod = "printAddrMode2OffsetOperand";
236 let MIOperandInfo = (ops GPR, i32imm);
237}
238
239// addrmode3 := reg +/- reg
240// addrmode3 := reg +/- imm8
241//
242def addrmode3 : Operand<i32>,
243 ComplexPattern<i32, 3, "SelectAddrMode3", []> {
244 let PrintMethod = "printAddrMode3Operand";
245 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
246}
247
248def am3offset : Operand<i32>,
249 ComplexPattern<i32, 2, "SelectAddrMode3Offset", []> {
250 let PrintMethod = "printAddrMode3OffsetOperand";
251 let MIOperandInfo = (ops GPR, i32imm);
252}
253
254// addrmode4 := reg, <mode|W>
255//
256def addrmode4 : Operand<i32>,
257 ComplexPattern<i32, 2, "", []> {
258 let PrintMethod = "printAddrMode4Operand";
259 let MIOperandInfo = (ops GPR, i32imm);
260}
261
262// addrmode5 := reg +/- imm8*4
263//
264def addrmode5 : Operand<i32>,
265 ComplexPattern<i32, 2, "SelectAddrMode5", []> {
266 let PrintMethod = "printAddrMode5Operand";
267 let MIOperandInfo = (ops GPR, i32imm);
268}
269
270// addrmodepc := pc + reg
271//
272def addrmodepc : Operand<i32>,
273 ComplexPattern<i32, 2, "SelectAddrModePC", []> {
274 let PrintMethod = "printAddrModePCOperand";
275 let MIOperandInfo = (ops GPR, i32imm);
276}
277
278//===----------------------------------------------------------------------===//
279// ARM Instruction flags. These need to match ARMInstrInfo.h.
280//
281
282// Addressing mode.
283class AddrMode<bits<4> val> {
284 bits<4> Value = val;
285}
286def AddrModeNone : AddrMode<0>;
287def AddrMode1 : AddrMode<1>;
288def AddrMode2 : AddrMode<2>;
289def AddrMode3 : AddrMode<3>;
290def AddrMode4 : AddrMode<4>;
291def AddrMode5 : AddrMode<5>;
292def AddrModeT1 : AddrMode<6>;
293def AddrModeT2 : AddrMode<7>;
294def AddrModeT4 : AddrMode<8>;
295def AddrModeTs : AddrMode<9>;
296
297// Instruction size.
298class SizeFlagVal<bits<3> val> {
299 bits<3> Value = val;
300}
301def SizeInvalid : SizeFlagVal<0>; // Unset.
302def SizeSpecial : SizeFlagVal<1>; // Pseudo or special.
303def Size8Bytes : SizeFlagVal<2>;
304def Size4Bytes : SizeFlagVal<3>;
305def Size2Bytes : SizeFlagVal<4>;
306
307// Load / store index mode.
308class IndexMode<bits<2> val> {
309 bits<2> Value = val;
310}
311def IndexModeNone : IndexMode<0>;
312def IndexModePre : IndexMode<1>;
313def IndexModePost : IndexMode<2>;
314
315//===----------------------------------------------------------------------===//
316// ARM Instruction templates.
317//
318
319// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
320class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
321 list<Predicate> Predicates = [IsARM];
322}
323class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
324 list<Predicate> Predicates = [IsARM, HasV6];
325}
326
327
328class InstARM<bits<4> opcod, AddrMode am, SizeFlagVal sz, IndexMode im,
329 dag ops, string asmstr, string cstr>
330 : Instruction {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000331 let Namespace = "ARM";
332
Evan Chenga8e29892007-01-19 07:51:42 +0000333 bits<4> Opcode = opcod;
334 AddrMode AM = am;
335 bits<4> AddrModeBits = AM.Value;
336
337 SizeFlagVal SZ = sz;
338 bits<3> SizeFlag = SZ.Value;
339
340 IndexMode IM = im;
341 bits<2> IndexModeBits = IM.Value;
342
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000343 dag OperandList = ops;
344 let AsmString = asmstr;
Evan Chenga8e29892007-01-19 07:51:42 +0000345 let Constraints = cstr;
346}
347
348class PseudoInst<dag ops, string asm, list<dag> pattern>
349 : InstARM<0, AddrModeNone, SizeSpecial, IndexModeNone, ops, asm, ""> {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000350 let Pattern = pattern;
351}
352
Evan Chenga8e29892007-01-19 07:51:42 +0000353class I<dag ops, AddrMode am, SizeFlagVal sz, IndexMode im,
354 string asm, string cstr, list<dag> pattern>
355 // FIXME: Set all opcodes to 0 for now.
356 : InstARM<0, am, sz, im, ops, asm, cstr> {
357 let Pattern = pattern;
358 list<Predicate> Predicates = [IsARM];
359}
Rafael Espindola15a6c3e2006-10-16 17:57:20 +0000360
Evan Chenga8e29892007-01-19 07:51:42 +0000361class AI<dag ops, string asm, list<dag> pattern>
362 : I<ops, AddrModeNone, Size4Bytes, IndexModeNone, asm, "", pattern>;
363class AI1<dag ops, string asm, list<dag> pattern>
364 : I<ops, AddrMode1, Size4Bytes, IndexModeNone, asm, "", pattern>;
365class AI2<dag ops, string asm, list<dag> pattern>
366 : I<ops, AddrMode2, Size4Bytes, IndexModeNone, asm, "", pattern>;
367class AI3<dag ops, string asm, list<dag> pattern>
368 : I<ops, AddrMode3, Size4Bytes, IndexModeNone, asm, "", pattern>;
369class AI4<dag ops, string asm, list<dag> pattern>
370 : I<ops, AddrMode4, Size4Bytes, IndexModeNone, asm, "", pattern>;
371class AIx2<dag ops, string asm, list<dag> pattern>
372 : I<ops, AddrModeNone, Size8Bytes, IndexModeNone, asm, "", pattern>;
Rafael Espindolaa6f149d2006-10-16 18:32:36 +0000373
Evan Chenga8e29892007-01-19 07:51:42 +0000374// Pre-indexed ops
375class AI2pr<dag ops, string asm, string cstr, list<dag> pattern>
376 : I<ops, AddrMode2, Size4Bytes, IndexModePre, asm, cstr, pattern>;
377class AI3pr<dag ops, string asm, string cstr, list<dag> pattern>
378 : I<ops, AddrMode3, Size4Bytes, IndexModePre, asm, cstr, pattern>;
Rafael Espindola27e469e2006-10-16 18:39:22 +0000379
Evan Chenga8e29892007-01-19 07:51:42 +0000380// Post-indexed ops
381class AI2po<dag ops, string asm, string cstr, list<dag> pattern>
382 : I<ops, AddrMode2, Size4Bytes, IndexModePost, asm, cstr, pattern>;
383class AI3po<dag ops, string asm, string cstr, list<dag> pattern>
384 : I<ops, AddrMode3, Size4Bytes, IndexModePost, asm, cstr, pattern>;
Rafael Espindola04d88ff2006-10-17 20:45:22 +0000385
Evan Chenga8e29892007-01-19 07:51:42 +0000386// BR_JT instructions
387class JTI<dag ops, string asm, list<dag> pattern>
388 : I<ops, AddrModeNone, SizeSpecial, IndexModeNone, asm, "", pattern>;
389class JTI1<dag ops, string asm, list<dag> pattern>
390 : I<ops, AddrMode1, SizeSpecial, IndexModeNone, asm, "", pattern>;
391class JTI2<dag ops, string asm, list<dag> pattern>
392 : I<ops, AddrMode2, SizeSpecial, IndexModeNone, asm, "", pattern>;
Rafael Espindola04d88ff2006-10-17 20:45:22 +0000393
Evan Chenga8e29892007-01-19 07:51:42 +0000394
395class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
396class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
397
398
399/// AI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
400/// binop that produces a value.
401multiclass AI1_bin_irs<string opc, PatFrag opnode> {
402 def ri : AI1<(ops GPR:$dst, GPR:$a, so_imm:$b),
403 !strconcat(opc, " $dst, $a, $b"),
404 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
405 def rr : AI1<(ops GPR:$dst, GPR:$a, GPR:$b),
406 !strconcat(opc, " $dst, $a, $b"),
407 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
408 def rs : AI1<(ops GPR:$dst, GPR:$a, so_reg:$b),
409 !strconcat(opc, " $dst, $a, $b"),
410 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
411}
412
413/// AI1_bin0_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns.
414/// Similar to AI1_bin_irs except the instruction does not produce a result.
415multiclass AI1_bin0_irs<string opc, PatFrag opnode> {
416 def ri : AI1<(ops GPR:$a, so_imm:$b),
417 !strconcat(opc, " $a, $b"),
418 [(opnode GPR:$a, so_imm:$b)]>;
419 def rr : AI1<(ops GPR:$a, GPR:$b),
420 !strconcat(opc, " $a, $b"),
421 [(opnode GPR:$a, GPR:$b)]>;
422 def rs : AI1<(ops GPR:$a, so_reg:$b),
423 !strconcat(opc, " $a, $b"),
424 [(opnode GPR:$a, so_reg:$b)]>;
425}
426
427/// AI1_bin_is - Defines a set of (op r, {so_imm|so_reg}) patterns for a binop.
428multiclass AI1_bin_is<string opc, PatFrag opnode> {
429 def ri : AI1<(ops GPR:$dst, GPR:$a, so_imm:$b),
430 !strconcat(opc, " $dst, $a, $b"),
431 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
432 def rs : AI1<(ops GPR:$dst, GPR:$a, so_reg:$b),
433 !strconcat(opc, " $dst, $a, $b"),
434 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
435}
436
437/// AI1_unary_irs - Defines a set of (op {so_imm|r|so_reg}) patterns for unary
438/// ops.
439multiclass AI1_unary_irs<string opc, PatFrag opnode> {
440 def i : AI1<(ops GPR:$dst, so_imm:$a),
441 !strconcat(opc, " $dst, $a"),
442 [(set GPR:$dst, (opnode so_imm:$a))]>;
443 def r : AI1<(ops GPR:$dst, GPR:$a),
444 !strconcat(opc, " $dst, $a"),
445 [(set GPR:$dst, (opnode GPR:$a))]>;
446 def s : AI1<(ops GPR:$dst, so_reg:$a),
447 !strconcat(opc, " $dst, $a"),
448 [(set GPR:$dst, (opnode so_reg:$a))]>;
449}
450
451/// AI_unary_rrot - A unary operation with two forms: one whose operand is a
452/// register and one whose operand is a register rotated by 8/16/24.
453multiclass AI_unary_rrot<string opc, PatFrag opnode> {
454 def r : AI<(ops GPR:$dst, GPR:$Src),
455 !strconcat(opc, " $dst, $Src"),
456 [(set GPR:$dst, (opnode GPR:$Src))]>, Requires<[IsARM, HasV6]>;
457 def r_rot : AI<(ops GPR:$dst, GPR:$Src, i32imm:$rot),
458 !strconcat(opc, " $dst, $Src, ror $rot"),
459 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>,
460 Requires<[IsARM, HasV6]>;
461}
462
463/// AI_bin_rrot - A binary operation with two forms: one whose operand is a
464/// register and one whose operand is a register rotated by 8/16/24.
465multiclass AI_bin_rrot<string opc, PatFrag opnode> {
466 def rr : AI<(ops GPR:$dst, GPR:$LHS, GPR:$RHS),
467 !strconcat(opc, " $dst, $LHS, $RHS"),
468 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
469 Requires<[IsARM, HasV6]>;
470 def rr_rot : AI<(ops GPR:$dst, GPR:$LHS, GPR:$RHS, i32imm:$rot),
471 !strconcat(opc, " $dst, $LHS, $RHS, ror $rot"),
472 [(set GPR:$dst, (opnode GPR:$LHS,
473 (rotr GPR:$RHS, rot_imm:$rot)))]>,
474 Requires<[IsARM, HasV6]>;
475}
476
Rafael Espindola90057aa2006-10-16 18:18:14 +0000477
Rafael Espindola15a6c3e2006-10-16 17:57:20 +0000478//===----------------------------------------------------------------------===//
479// Instructions
480//===----------------------------------------------------------------------===//
481
Evan Chenga8e29892007-01-19 07:51:42 +0000482//===----------------------------------------------------------------------===//
483// Miscellaneous Instructions.
484//
485def IMPLICIT_DEF_GPR :
486PseudoInst<(ops GPR:$rD),
487 "@ IMPLICIT_DEF_GPR $rD",
488 [(set GPR:$rD, (undef))]>;
Rafael Espindola687bc492006-08-24 13:45:55 +0000489
Rafael Espindola6f602de2006-08-24 16:13:15 +0000490
Evan Chenga8e29892007-01-19 07:51:42 +0000491/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
492/// the function. The first operand is the ID# for this instruction, the second
493/// is the index into the MachineConstantPool that this is, the third is the
494/// size in bytes of this constant pool entry.
495def CONSTPOOL_ENTRY :
496PseudoInst<(ops cpinst_operand:$instid, cpinst_operand:$cpidx, i32imm:$size),
497 "${instid:label} ${cpidx:cpentry}", []>;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000498
Evan Chenga8e29892007-01-19 07:51:42 +0000499def ADJCALLSTACKUP :
500PseudoInst<(ops i32imm:$amt),
501 "@ ADJCALLSTACKUP $amt",
502 [(ARMcallseq_end imm:$amt)]>, Imp<[SP],[SP]>;
Rafael Espindolacdda88c2006-08-24 17:19:08 +0000503
Evan Chenga8e29892007-01-19 07:51:42 +0000504def ADJCALLSTACKDOWN :
505PseudoInst<(ops i32imm:$amt),
506 "@ ADJCALLSTACKDOWN $amt",
507 [(ARMcallseq_start imm:$amt)]>, Imp<[SP],[SP]>;
Rafael Espindola3c000bf2006-08-21 22:00:32 +0000508
Evan Chenga8e29892007-01-19 07:51:42 +0000509def DWARF_LOC :
510PseudoInst<(ops i32imm:$line, i32imm:$col, i32imm:$file),
511 ".loc $file, $line, $col",
512 [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
Rafael Espindola4b20fbc2006-10-10 12:56:00 +0000513
Evan Chenga8e29892007-01-19 07:51:42 +0000514def DWARF_LABEL :
515PseudoInst<(ops i32imm:$id),
516 "\nLdebug_loc${id:no_hash}:",
517 [(dwarf_label (i32 imm:$id))]>;
Rafael Espindola687bc492006-08-24 13:45:55 +0000518
Evan Chenga8e29892007-01-19 07:51:42 +0000519def PICADD : AI1<(ops GPR:$dst, GPR:$a, pclabel:$cp),
520 "\n$cp:\n\tadd $dst, pc, $a",
521 [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
522let AddedComplexity = 10 in
523def PICLD : AI2<(ops GPR:$dst, addrmodepc:$addr),
524 "\n${addr:label}:\n\tldr $dst, $addr",
525 [(set GPR:$dst, (load addrmodepc:$addr))]>;
Rafael Espindola84b19be2006-07-16 01:02:57 +0000526
Evan Chenga8e29892007-01-19 07:51:42 +0000527//===----------------------------------------------------------------------===//
528// Control Flow Instructions.
529//
Rafael Espindola9e071f02006-10-02 19:30:56 +0000530
Evan Chenga8e29892007-01-19 07:51:42 +0000531let isReturn = 1, isTerminator = 1 in
532 def BX_RET : AI<(ops), "bx lr", [(ARMretflag)]>;
Rafael Espindola27185192006-09-29 21:20:16 +0000533
Evan Chenga8e29892007-01-19 07:51:42 +0000534// FIXME: remove when we have a way to marking a MI with these properties.
535let isLoad = 1, isReturn = 1, isTerminator = 1 in
536 def LDM_RET : AI4<(ops addrmode4:$addr, reglist:$dst1, variable_ops),
537 "ldm${addr:submode} $addr, $dst1",
538 []>;
Rafael Espindolaa2845842006-10-05 16:48:49 +0000539
Evan Chenga8e29892007-01-19 07:51:42 +0000540let isCall = 1, noResults = 1,
541 Defs = [R0, R1, R2, R3, R12, LR,
542 D0, D1, D2, D3, D4, D5, D6, D7] in {
543 def BL : AI<(ops i32imm:$func, variable_ops),
544 "bl ${func:call}",
545 [(ARMcall tglobaladdr:$func)]>;
546 // ARMv5T and above
547 def BLX : AI<(ops GPR:$dst, variable_ops),
548 "blx $dst",
549 [(ARMcall GPR:$dst)]>, Requires<[IsARM, HasV5T]>;
550 // ARMv4T
551 def BX : AIx2<(ops GPR:$dst, variable_ops),
552 "mov lr, pc\n\tbx $dst",
553 [(ARMcall_nolink GPR:$dst)]>;
Rafael Espindola35574632006-07-18 17:00:30 +0000554}
Rafael Espindoladc124a22006-05-18 21:45:49 +0000555
Evan Chenga8e29892007-01-19 07:51:42 +0000556let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
557 def B : AI<(ops brtarget:$dst), "b $dst",
558 [(br bb:$dst)]>;
559
560 def BR_JTr : JTI<(ops GPR:$dst, jtblock_operand:$jt, i32imm:$id),
561 "mov pc, $dst \n$jt",
562 [(ARMbrjt GPR:$dst, tjumptable:$jt, imm:$id)]>;
563 def BR_JTm : JTI2<(ops addrmode2:$dst, jtblock_operand:$jt, i32imm:$id),
564 "ldr pc, $dst \n$jt",
565 [(ARMbrjt (i32 (load addrmode2:$dst)), tjumptable:$jt,
566 imm:$id)]>;
567 def BR_JTadd : JTI1<(ops GPR:$dst, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
568 "add pc, $dst, $idx \n$jt",
569 [(ARMbrjt (add GPR:$dst, GPR:$idx), tjumptable:$jt,
570 imm:$id)]>;
Rafael Espindola1ed3af12006-08-01 18:53:10 +0000571}
Rafael Espindola84b19be2006-07-16 01:02:57 +0000572
Evan Chenga8e29892007-01-19 07:51:42 +0000573let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
574 def Bcc : AI<(ops brtarget:$dst, CCOp:$cc), "b$cc $dst",
575 [(ARMbrcond bb:$dst, imm:$cc)]>;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000576
Evan Chenga8e29892007-01-19 07:51:42 +0000577//===----------------------------------------------------------------------===//
578// Load / store Instructions.
579//
Rafael Espindola82c678b2006-10-16 17:17:22 +0000580
Evan Chenga8e29892007-01-19 07:51:42 +0000581// Load
582let isLoad = 1 in {
583def LDR : AI2<(ops GPR:$dst, addrmode2:$addr),
584 "ldr $dst, $addr",
585 [(set GPR:$dst, (load addrmode2:$addr))]>;
Rafael Espindola82c678b2006-10-16 17:17:22 +0000586
Evan Chenga8e29892007-01-19 07:51:42 +0000587// Loads with zero extension
588def LDRH : AI3<(ops GPR:$dst, addrmode3:$addr),
589 "ldrh $dst, $addr",
590 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
Rafael Espindola82c678b2006-10-16 17:17:22 +0000591
Evan Chenga8e29892007-01-19 07:51:42 +0000592def LDRB : AI2<(ops GPR:$dst, addrmode2:$addr),
593 "ldrb $dst, $addr",
594 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
Rafael Espindola82c678b2006-10-16 17:17:22 +0000595
Evan Chenga8e29892007-01-19 07:51:42 +0000596// Loads with sign extension
597def LDRSH : AI3<(ops GPR:$dst, addrmode3:$addr),
598 "ldrsh $dst, $addr",
599 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000600
Evan Chenga8e29892007-01-19 07:51:42 +0000601def LDRSB : AI3<(ops GPR:$dst, addrmode3:$addr),
602 "ldrsb $dst, $addr",
603 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
Rafael Espindolac391d162006-10-23 20:34:27 +0000604
Evan Chenga8e29892007-01-19 07:51:42 +0000605// Load doubleword
606def LDRD : AI3<(ops GPR:$dst, addrmode3:$addr),
607 "ldrd $dst, $addr",
608 []>, Requires<[IsARM, HasV5T]>;
Rafael Espindolac391d162006-10-23 20:34:27 +0000609
Evan Chenga8e29892007-01-19 07:51:42 +0000610// Indexed loads
611def LDR_PRE : AI2pr<(ops GPR:$dst, GPR:$base_wb, addrmode2:$addr),
612 "ldr $dst, $addr!", "$addr.base = $base_wb", []>;
Rafael Espindoladc124a22006-05-18 21:45:49 +0000613
Evan Chenga8e29892007-01-19 07:51:42 +0000614def LDR_POST : AI2po<(ops GPR:$dst, GPR:$base_wb, GPR:$base, am2offset:$offset),
615 "ldr $dst, [$base], $offset", "$base = $base_wb", []>;
Rafael Espindola450856d2006-12-12 00:37:38 +0000616
Evan Chenga8e29892007-01-19 07:51:42 +0000617def LDRH_PRE : AI3pr<(ops GPR:$dst, GPR:$base_wb, addrmode3:$addr),
618 "ldrh $dst, $addr!", "$addr.base = $base_wb", []>;
Rafael Espindola4e307642006-09-08 16:59:47 +0000619
Evan Chenga8e29892007-01-19 07:51:42 +0000620def LDRH_POST : AI3po<(ops GPR:$dst, GPR:$base_wb, GPR:$base,am3offset:$offset),
621 "ldrh $dst, [$base], $offset", "$base = $base_wb", []>;
Lauro Ramos Venancio301009a2006-12-28 13:11:14 +0000622
Evan Chenga8e29892007-01-19 07:51:42 +0000623def LDRB_PRE : AI2pr<(ops GPR:$dst, GPR:$base_wb, addrmode2:$addr),
624 "ldrb $dst, $addr!", "$addr.base = $base_wb", []>;
Lauro Ramos Venancio301009a2006-12-28 13:11:14 +0000625
Evan Chenga8e29892007-01-19 07:51:42 +0000626def LDRB_POST : AI2po<(ops GPR:$dst, GPR:$base_wb, GPR:$base,am2offset:$offset),
627 "ldrb $dst, [$base], $offset", "$base = $base_wb", []>;
628
629def LDRSH_PRE : AI3pr<(ops GPR:$dst, GPR:$base_wb, addrmode3:$addr),
630 "ldrsh $dst, $addr!", "$addr.base = $base_wb", []>;
631
632def LDRSH_POST: AI3po<(ops GPR:$dst, GPR:$base_wb, GPR:$base,am3offset:$offset),
633 "ldrsh $dst, [$base], $offset", "$base = $base_wb", []>;
634
635def LDRSB_PRE : AI3pr<(ops GPR:$dst, GPR:$base_wb, addrmode3:$addr),
636 "ldrsb $dst, $addr!", "$addr.base = $base_wb", []>;
637
638def LDRSB_POST: AI3po<(ops GPR:$dst, GPR:$base_wb, GPR:$base,am3offset:$offset),
639 "ldrsb $dst, [$base], $offset", "$base = $base_wb", []>;
640} // isLoad
641
642// Store
643let isStore = 1 in {
644def STR : AI2<(ops GPR:$src, addrmode2:$addr),
645 "str $src, $addr",
646 [(store GPR:$src, addrmode2:$addr)]>;
647
648// Stores with truncate
649def STRH : AI3<(ops GPR:$src, addrmode3:$addr),
650 "strh $src, $addr",
651 [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
652
653def STRB : AI2<(ops GPR:$src, addrmode2:$addr),
654 "strb $src, $addr",
655 [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
656
657// Store doubleword
658def STRD : AI3<(ops GPR:$src, addrmode3:$addr),
659 "strd $src, $addr",
660 []>, Requires<[IsARM, HasV5T]>;
661
662// Indexed stores
663def STR_PRE : AI2pr<(ops GPR:$base_wb, GPR:$src, GPR:$base, am2offset:$offset),
664 "str $src, [$base, $offset]!", "$base = $base_wb",
665 [(set GPR:$base_wb,
666 (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
667
668def STR_POST : AI2po<(ops GPR:$base_wb, GPR:$src, GPR:$base,am2offset:$offset),
669 "str $src, [$base], $offset", "$base = $base_wb",
670 [(set GPR:$base_wb,
671 (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
672
673def STRH_PRE : AI3pr<(ops GPR:$base_wb, GPR:$src, GPR:$base,am3offset:$offset),
674 "strh $src, [$base, $offset]!", "$base = $base_wb",
675 [(set GPR:$base_wb,
676 (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
677
678def STRH_POST: AI3po<(ops GPR:$base_wb, GPR:$src, GPR:$base,am3offset:$offset),
679 "strh $src, [$base], $offset", "$base = $base_wb",
680 [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
681 GPR:$base, am3offset:$offset))]>;
682
683def STRB_PRE : AI2pr<(ops GPR:$base_wb, GPR:$src, GPR:$base,am2offset:$offset),
684 "strb $src, [$base, $offset]!", "$base = $base_wb",
685 [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
686 GPR:$base, am2offset:$offset))]>;
687
688def STRB_POST: AI2po<(ops GPR:$base_wb, GPR:$src, GPR:$base,am2offset:$offset),
689 "strb $src, [$base], $offset", "$base = $base_wb",
690 [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
691 GPR:$base, am2offset:$offset))]>;
692} // isStore
693
694//===----------------------------------------------------------------------===//
695// Load / store multiple Instructions.
696//
697
698let isLoad = 1 in
699def LDM : AI4<(ops addrmode4:$addr, reglist:$dst1, variable_ops),
700 "ldm${addr:submode} $addr, $dst1",
701 []>;
702
703let isStore = 1 in
704def STM : AI4<(ops addrmode4:$addr, reglist:$src1, variable_ops),
705 "stm${addr:submode} $addr, $src1",
706 []>;
707
708//===----------------------------------------------------------------------===//
709// Move Instructions.
710//
711
712def MOVrr : AI1<(ops GPR:$dst, GPR:$src),
713 "mov $dst, $src", []>;
714def MOVrs : AI1<(ops GPR:$dst, so_reg:$src),
715 "mov $dst, $src", [(set GPR:$dst, so_reg:$src)]>;
716def MOVri : AI1<(ops GPR:$dst, so_imm:$src),
717 "mov $dst, $src", [(set GPR:$dst, so_imm:$src)]>;
718
719// These aren't really mov instructions, but we have to define them this way
720// due to flag operands.
721
722def MOVsrl_flag : AI1<(ops GPR:$dst, GPR:$src),
723 "movs $dst, $src, lsr #1",
724 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>;
725def MOVsra_flag : AI1<(ops GPR:$dst, GPR:$src),
726 "movs $dst, $src, asr #1",
727 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>;
728def MOVrrx : AI1<(ops GPR:$dst, GPR:$src),
729 "mov $dst, $src, rrx",
730 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
731
732
733//===----------------------------------------------------------------------===//
734// Extend Instructions.
735//
736
737// Sign extenders
738
739defm SXTB : AI_unary_rrot<"sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
740defm SXTH : AI_unary_rrot<"sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
741
742defm SXTAB : AI_bin_rrot<"sxtab",
743 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
744defm SXTAH : AI_bin_rrot<"sxtah",
745 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
746
747// TODO: SXT(A){B|H}16
748
749// Zero extenders
750
751let AddedComplexity = 16 in {
752defm UXTB : AI_unary_rrot<"uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
753defm UXTH : AI_unary_rrot<"uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
754defm UXTB16 : AI_unary_rrot<"uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
755
756def : ARMV6Pat<(and (shl GPR:$Src, 8), 0xFF00FF),
757 (UXTB16r_rot GPR:$Src, 24)>;
758def : ARMV6Pat<(and (srl GPR:$Src, 8), 0xFF00FF),
759 (UXTB16r_rot GPR:$Src, 8)>;
760
761defm UXTAB : AI_bin_rrot<"uxtab",
762 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
763defm UXTAH : AI_bin_rrot<"uxtah",
764 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
Rafael Espindola3c000bf2006-08-21 22:00:32 +0000765}
766
Evan Chenga8e29892007-01-19 07:51:42 +0000767// This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
768//defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
Rafael Espindola817e7fd2006-09-11 19:24:19 +0000769
Evan Chenga8e29892007-01-19 07:51:42 +0000770// TODO: UXT(A){B|H}16
771
772//===----------------------------------------------------------------------===//
773// Arithmetic Instructions.
774//
775
776defm ADD : AI1_bin_irs<"add" , BinOpFrag<(add node:$LHS, node:$RHS)>>;
777defm ADDS : AI1_bin_irs<"adds", BinOpFrag<(addc node:$LHS, node:$RHS)>>;
778defm ADC : AI1_bin_irs<"adc" , BinOpFrag<(adde node:$LHS, node:$RHS)>>;
779defm SUB : AI1_bin_irs<"sub" , BinOpFrag<(sub node:$LHS, node:$RHS)>>;
780defm SUBS : AI1_bin_irs<"subs", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
781defm SBC : AI1_bin_irs<"sbc" , BinOpFrag<(sube node:$LHS, node:$RHS)>>;
782
783// These don't define reg/reg forms, because they are handled above.
784defm RSB : AI1_bin_is <"rsb" , BinOpFrag<(sub node:$RHS, node:$LHS)>>;
785defm RSBS : AI1_bin_is <"rsbs", BinOpFrag<(subc node:$RHS, node:$LHS)>>;
786defm RSC : AI1_bin_is <"rsc" , BinOpFrag<(sube node:$RHS, node:$LHS)>>;
787
788// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
789def : ARMPat<(add GPR:$src, so_imm_neg:$imm),
790 (SUBri GPR:$src, so_imm_neg:$imm)>;
791
792//def : ARMPat<(addc GPR:$src, so_imm_neg:$imm),
793// (SUBSri GPR:$src, so_imm_neg:$imm)>;
794//def : ARMPat<(adde GPR:$src, so_imm_neg:$imm),
795// (SBCri GPR:$src, so_imm_neg:$imm)>;
796
797// Note: These are implemented in C++ code, because they have to generate
798// ADD/SUBrs instructions, which use a complex pattern that a xform function
799// cannot produce.
800// (mul X, 2^n+1) -> (add (X << n), X)
801// (mul X, 2^n-1) -> (rsb X, (X << n))
802
803
804//===----------------------------------------------------------------------===//
805// Bitwise Instructions.
806//
807
808defm AND : AI1_bin_irs<"and", BinOpFrag<(and node:$LHS, node:$RHS)>>;
809defm ORR : AI1_bin_irs<"orr", BinOpFrag<(or node:$LHS, node:$RHS)>>;
810defm EOR : AI1_bin_irs<"eor", BinOpFrag<(xor node:$LHS, node:$RHS)>>;
811defm BIC : AI1_bin_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
812
813defm MVN : AI1_unary_irs<"mvn", not>;
814
815def : ARMPat<(i32 so_imm_not:$imm),
816 (MVNi so_imm_not:$imm)>;
817
818def : ARMPat<(and GPR:$src, so_imm_not:$imm),
819 (BICri GPR:$src, so_imm_not:$imm)>;
820
821//===----------------------------------------------------------------------===//
822// Multiply Instructions.
823//
824
825// AI_orr - Defines a (op r, r) pattern.
826class AI_orr<string opc, SDNode opnode>
827 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
828 !strconcat(opc, " $dst, $a, $b"),
829 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
830
831// AI_oorr - Defines a (op (op r, r), r) pattern.
832class AI_oorr<string opc, SDNode opnode1, SDNode opnode2>
833 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$c),
834 !strconcat(opc, " $dst, $a, $b, $c"),
835 [(set GPR:$dst, (opnode1 (opnode2 GPR:$a, GPR:$b), GPR:$c))]>;
836
837def MUL : AI_orr<"mul", mul>;
838def MLA : AI_oorr<"mla", add, mul>;
839
840// Extra precision multiplies with low / high results
841def SMULL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
842 "smull $ldst, $hdst, $a, $b",
843 []>;
844
845def UMULL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
846 "umull $ldst, $hdst, $a, $b",
847 []>;
848
849// Multiply + accumulate
850def SMLAL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
851 "smlal $ldst, $hdst, $a, $b",
852 []>;
853
854def UMLAL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
855 "umlal $ldst, $hdst, $a, $b",
856 []>;
857
858def UMAAL : AI<(ops GPR:$ldst, GPR:$hdst, GPR:$a, GPR:$b),
859 "umaal $ldst, $hdst, $a, $b",
860 []>, Requires<[IsARM, HasV6]>;
861
862// Most significant word multiply
863def SMMUL : AI_orr<"smmul", mulhs>, Requires<[IsARM, HasV6]>;
864def SMMLA : AI_oorr<"smmla", add, mulhs>, Requires<[IsARM, HasV6]>;
865
866
867def SMMLS : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$c),
868 "smmls $dst, $a, $b, $c",
869 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
870 Requires<[IsARM, HasV6]>;
871
872multiclass AI_smul<string opc, PatFrag opnode> {
873 def BB1 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
874 !strconcat(opc, "bb $dst, $a, $b"),
875 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
876 (sext_inreg GPR:$b, i16)))]>,
877 Requires<[IsARM, HasV5TE]>;
878 def BB2 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
879 !strconcat(opc, "bb $dst, $a, $b"),
880 [(set GPR:$dst, (opnode (sra (shl GPR:$a, 16), 16),
881 (sra (shl GPR:$b, 16), 16)))]>,
882 Requires<[IsARM, HasV5TE]>;
883 def BB3 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
884 !strconcat(opc, "bb $dst, $a, $b"),
885 [(set GPR:$dst, (opnode sext_16_node:$a, sext_16_node:$b))]>,
886 Requires<[IsARM, HasV5TE]>;
887
888 def BT1 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
889 !strconcat(opc, "bt $dst, $a, $b"),
890 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
891 (sra GPR:$b, 16)))]>,
892 Requires<[IsARM, HasV5TE]>;
893 def BT2 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
894 !strconcat(opc, "bt $dst, $a, $b"),
895 [(set GPR:$dst, (opnode (sra (shl GPR:$a, 16), 16),
896 (sra GPR:$b, 16)))]>,
897 Requires<[IsARM, HasV5TE]>;
898 def BT3 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
899 !strconcat(opc, "bt $dst, $a, $b"),
900 [(set GPR:$dst, (opnode sext_16_node:$a, (sra GPR:$b, 16)))]>,
901 Requires<[IsARM, HasV5TE]>;
902
903 def TB1 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
904 !strconcat(opc, "tb $dst, $a, $b"),
905 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
906 (sext_inreg GPR:$b, i16)))]>,
907 Requires<[IsARM, HasV5TE]>;
908 def TB2 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
909 !strconcat(opc, "tb $dst, $a, $b"),
910 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
911 (sra (shl GPR:$b, 16), 16)))]>,
912 Requires<[IsARM, HasV5TE]>;
913 def TB3 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
914 !strconcat(opc, "tb $dst, $a, $b"),
915 [(set GPR:$dst, (opnode (sra GPR:$a, 16), sext_16_node:$b))]>,
916 Requires<[IsARM, HasV5TE]>;
917
918 def TT : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
919 !strconcat(opc, "tt $dst, $a, $b"),
920 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
921 (sra GPR:$b, 16)))]>,
922 Requires<[IsARM, HasV5TE]>;
923
924 def WB1 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
925 !strconcat(opc, "wb $dst, $a, $b"),
926 [(set GPR:$dst, (sra (opnode GPR:$a,
927 (sext_inreg GPR:$b, i16)), 16))]>,
928 Requires<[IsARM, HasV5TE]>;
929 def WB2 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
930 !strconcat(opc, "wb $dst, $a, $b"),
931 [(set GPR:$dst, (sra (opnode GPR:$a,
932 (sra (shl GPR:$b, 16), 16)), 16))]>,
933 Requires<[IsARM, HasV5TE]>;
934 def WB3 : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
935 !strconcat(opc, "wb $dst, $a, $b"),
936 [(set GPR:$dst, (sra (opnode GPR:$a, sext_16_node:$b), 16))]>,
937 Requires<[IsARM, HasV5TE]>;
938
939 def WT : AI<(ops GPR:$dst, GPR:$a, GPR:$b),
940 !strconcat(opc, "wt $dst, $a, $b"),
941 [(set GPR:$dst, (sra (opnode GPR:$a,
942 (sra GPR:$b, 16)), 16))]>,
943 Requires<[IsARM, HasV5TE]>;
Rafael Espindolabec2e382006-10-16 16:33:29 +0000944}
945
Evan Chenga8e29892007-01-19 07:51:42 +0000946multiclass AI_smla<string opc, PatFrag opnode> {
947 def BB1 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
948 !strconcat(opc, "bb $dst, $a, $b, $acc"),
949 [(set GPR:$dst, (add GPR:$acc,
950 (opnode (sext_inreg GPR:$a, i16),
951 (sext_inreg GPR:$b, i16))))]>,
952 Requires<[IsARM, HasV5TE]>;
953 def BB2 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
954 !strconcat(opc, "bb $dst, $a, $b, $acc"),
955 [(set GPR:$dst, (add GPR:$acc,
956 (opnode (sra (shl GPR:$a, 16), 16),
957 (sra (shl GPR:$b, 16), 16))))]>,
958 Requires<[IsARM, HasV5TE]>;
959 def BB3 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
960 !strconcat(opc, "bb $dst, $a, $b, $acc"),
961 [(set GPR:$dst, (add GPR:$acc,
962 (opnode sext_16_node:$a, sext_16_node:$b)))]>,
963 Requires<[IsARM, HasV5TE]>;
Rafael Espindola687bc492006-08-24 13:45:55 +0000964
Evan Chenga8e29892007-01-19 07:51:42 +0000965 def BT1 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
966 !strconcat(opc, "bt $dst, $a, $b, $acc"),
967 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
968 (sra GPR:$b, 16))))]>,
969 Requires<[IsARM, HasV5TE]>;
970 def BT2 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
971 !strconcat(opc, "bt $dst, $a, $b, $acc"),
972 [(set GPR:$dst, (add GPR:$acc, (opnode (sra (shl GPR:$a, 16), 16),
973 (sra GPR:$b, 16))))]>,
974 Requires<[IsARM, HasV5TE]>;
975 def BT3 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
976 !strconcat(opc, "bt $dst, $a, $b, $acc"),
977 [(set GPR:$dst, (add GPR:$acc, (opnode sext_16_node:$a,
978 (sra GPR:$b, 16))))]>,
979 Requires<[IsARM, HasV5TE]>;
980
981 def TB1 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
982 !strconcat(opc, "tb $dst, $a, $b, $acc"),
983 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
984 (sext_inreg GPR:$b, i16))))]>,
985 Requires<[IsARM, HasV5TE]>;
986 def TB2 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
987 !strconcat(opc, "tb $dst, $a, $b, $acc"),
988 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
989 (sra (shl GPR:$b, 16), 16))))]>,
990 Requires<[IsARM, HasV5TE]>;
991 def TB3 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
992 !strconcat(opc, "tb $dst, $a, $b, $acc"),
993 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
994 sext_16_node:$b)))]>,
995 Requires<[IsARM, HasV5TE]>;
996
997 def TT : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
998 !strconcat(opc, "tt $dst, $a, $b, $acc"),
999 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
1000 (sra GPR:$b, 16))))]>,
1001 Requires<[IsARM, HasV5TE]>;
1002
1003 def WB1 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
1004 !strconcat(opc, "wb $dst, $a, $b, $acc"),
1005 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1006 (sext_inreg GPR:$b, i16)), 16)))]>,
1007 Requires<[IsARM, HasV5TE]>;
1008 def WB2 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
1009 !strconcat(opc, "wb $dst, $a, $b, $acc"),
1010 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1011 (sra (shl GPR:$b, 16), 16)), 16)))]>,
1012 Requires<[IsARM, HasV5TE]>;
1013 def WB3 : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
1014 !strconcat(opc, "wb $dst, $a, $b, $acc"),
1015 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1016 sext_16_node:$b), 16)))]>,
1017 Requires<[IsARM, HasV5TE]>;
1018
1019 def WT : AI<(ops GPR:$dst, GPR:$a, GPR:$b, GPR:$acc),
1020 !strconcat(opc, "wt $dst, $a, $b, $acc"),
1021 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1022 (sra GPR:$b, 16)), 16)))]>,
1023 Requires<[IsARM, HasV5TE]>;
Rafael Espindola70673a12006-10-18 16:20:57 +00001024}
Rafael Espindola5c2aa0a2006-09-08 12:47:03 +00001025
Evan Chenga8e29892007-01-19 07:51:42 +00001026defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1027defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
Rafael Espindola27185192006-09-29 21:20:16 +00001028
Evan Chenga8e29892007-01-19 07:51:42 +00001029// TODO: Halfword multiple accumulate long: SMLAL<x><y>
1030// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
Rafael Espindola42b62f32006-10-13 13:14:59 +00001031
Evan Chenga8e29892007-01-19 07:51:42 +00001032//===----------------------------------------------------------------------===//
1033// Misc. Arithmetic Instructions.
1034//
Rafael Espindola0d9fe762006-10-10 16:33:47 +00001035
Evan Chenga8e29892007-01-19 07:51:42 +00001036def CLZ : AI<(ops GPR:$dst, GPR:$src),
1037 "clz $dst, $src",
1038 [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]>;
Rafael Espindola199dd672006-10-17 13:13:23 +00001039
Evan Chenga8e29892007-01-19 07:51:42 +00001040def REV : AI<(ops GPR:$dst, GPR:$src),
1041 "rev $dst, $src",
1042 [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]>;
Rafael Espindola199dd672006-10-17 13:13:23 +00001043
Evan Chenga8e29892007-01-19 07:51:42 +00001044def REV16 : AI<(ops GPR:$dst, GPR:$src),
1045 "rev16 $dst, $src",
1046 [(set GPR:$dst,
1047 (or (and (srl GPR:$src, 8), 0xFF),
1048 (or (and (shl GPR:$src, 8), 0xFF00),
1049 (or (and (srl GPR:$src, 8), 0xFF0000),
1050 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
1051 Requires<[IsARM, HasV6]>;
Rafael Espindola27185192006-09-29 21:20:16 +00001052
Evan Chenga8e29892007-01-19 07:51:42 +00001053def REVSH : AI<(ops GPR:$dst, GPR:$src),
1054 "revsh $dst, $src",
1055 [(set GPR:$dst,
1056 (sext_inreg
1057 (or (srl (and GPR:$src, 0xFFFF), 8),
1058 (shl GPR:$src, 8)), i16))]>,
1059 Requires<[IsARM, HasV6]>;
Rafael Espindola27185192006-09-29 21:20:16 +00001060
Evan Chenga8e29892007-01-19 07:51:42 +00001061def PKHBT : AI<(ops GPR:$dst, GPR:$src1, GPR:$src2, i32imm:$shamt),
1062 "pkhbt $dst, $src1, $src2, LSL $shamt",
1063 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1064 (and (shl GPR:$src2, (i32 imm:$shamt)),
1065 0xFFFF0000)))]>,
1066 Requires<[IsARM, HasV6]>;
Rafael Espindola27185192006-09-29 21:20:16 +00001067
Evan Chenga8e29892007-01-19 07:51:42 +00001068// Alternate cases for PKHBT where identities eliminate some nodes.
1069def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1070 (PKHBT GPR:$src1, GPR:$src2, 0)>;
1071def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1072 (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
Rafael Espindola9e071f02006-10-02 19:30:56 +00001073
Rafael Espindolaa2845842006-10-05 16:48:49 +00001074
Evan Chenga8e29892007-01-19 07:51:42 +00001075def PKHTB : AI<(ops GPR:$dst, GPR:$src1, GPR:$src2, i32imm:$shamt),
1076 "pkhtb $dst, $src1, $src2, ASR $shamt",
1077 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1078 (and (sra GPR:$src2, imm16_31:$shamt),
1079 0xFFFF)))]>, Requires<[IsARM, HasV6]>;
Rafael Espindola9e071f02006-10-02 19:30:56 +00001080
Evan Chenga8e29892007-01-19 07:51:42 +00001081// Alternate cases for PKHTB where identities eliminate some nodes. Note that
1082// a shift amount of 0 is *not legal* here, it is PKHBT instead.
1083def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, 16)),
1084 (PKHTB GPR:$src1, GPR:$src2, 16)>;
1085def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1086 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1087 (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
Rafael Espindolab47e1d02006-10-10 18:55:14 +00001088
Rafael Espindolad9ae7782006-10-07 13:46:42 +00001089
Evan Chenga8e29892007-01-19 07:51:42 +00001090//===----------------------------------------------------------------------===//
1091// Comparison Instructions...
1092//
Rafael Espindolab47e1d02006-10-10 18:55:14 +00001093
Evan Chenga8e29892007-01-19 07:51:42 +00001094defm CMP : AI1_bin0_irs<"cmp", BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1095defm CMN : AI1_bin0_irs<"cmn", BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Rafael Espindolae5bbd6d2006-10-07 14:24:52 +00001096
Evan Chenga8e29892007-01-19 07:51:42 +00001097def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1098 (CMNri GPR:$src, so_imm_neg:$imm)>;
Rafael Espindola493a7fc2006-10-10 20:38:57 +00001099
Evan Chenga8e29892007-01-19 07:51:42 +00001100// Note that TST/TEQ don't set all the same flags that CMP does!
1101def TSTrr : AI1<(ops GPR:$a, so_reg:$b), "tst $a, $b", []>;
1102def TSTri : AI1<(ops GPR:$a, so_imm:$b), "tst $a, $b", []>;
1103def TEQrr : AI1<(ops GPR:$a, so_reg:$b), "teq $a, $b", []>;
1104def TEQri : AI1<(ops GPR:$a, so_imm:$b), "teq $a, $b", []>;
Rafael Espindolae5bbd6d2006-10-07 14:24:52 +00001105
Evan Chenga8e29892007-01-19 07:51:42 +00001106// Conditional moves
1107def MOVCCr : AI<(ops GPR:$dst, GPR:$false, GPR:$true, CCOp:$cc),
1108 "mov$cc $dst, $true",
1109 [(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))]>,
1110 RegConstraint<"$false = $dst">;
Rafael Espindola493a7fc2006-10-10 20:38:57 +00001111
Evan Chenga8e29892007-01-19 07:51:42 +00001112def MOVCCs : AI<(ops GPR:$dst, GPR:$false, so_reg:$true, CCOp:$cc),
1113 "mov$cc $dst, $true",
1114 [(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true,imm:$cc))]>,
1115 RegConstraint<"$false = $dst">;
Rafael Espindola2dc0f2b2006-10-09 17:50:29 +00001116
Evan Chenga8e29892007-01-19 07:51:42 +00001117def MOVCCi : AI<(ops GPR:$dst, GPR:$false, so_imm:$true, CCOp:$cc),
1118 "mov$cc $dst, $true",
1119 [(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true,imm:$cc))]>,
1120 RegConstraint<"$false = $dst">;
Rafael Espindolad9ae7782006-10-07 13:46:42 +00001121
Rafael Espindola4b20fbc2006-10-10 12:56:00 +00001122
Evan Chenga8e29892007-01-19 07:51:42 +00001123// LEApcrel - Load a pc-relative address into a register without offending the
1124// assembler.
1125def LEApcrel : AI1<(ops GPR:$dst, i32imm:$label),
1126 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
1127 "${:private}PCRELL${:uid}+8))\n"),
1128 !strconcat("${:private}PCRELL${:uid}:\n\t",
1129 "add $dst, pc, #PCRELV${:uid}")),
1130 []>;
Rafael Espindola667c3492006-10-10 19:35:01 +00001131
Evan Chenga8e29892007-01-19 07:51:42 +00001132def LEApcrelJT : AI1<(ops GPR:$dst, i32imm:$label, i32imm:$id),
1133 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
1134 "${:private}PCRELL${:uid}+8))\n"),
1135 !strconcat("${:private}PCRELL${:uid}:\n\t",
1136 "add $dst, pc, #PCRELV${:uid}")),
1137 []>;
Rafael Espindolac01c87c2006-10-17 20:33:13 +00001138
Evan Chenga8e29892007-01-19 07:51:42 +00001139//===----------------------------------------------------------------------===//
1140// Non-Instruction Patterns
1141//
Rafael Espindola5aca9272006-10-07 14:03:39 +00001142
Evan Chenga8e29892007-01-19 07:51:42 +00001143// ConstantPool, GlobalAddress, and JumpTable
1144def : ARMPat<(ARMWrapper tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>;
1145def : ARMPat<(ARMWrapper tconstpool :$dst), (LEApcrel tconstpool :$dst)>;
1146def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1147 (LEApcrelJT tjumptable:$dst, imm:$id)>;
Rafael Espindola5aca9272006-10-07 14:03:39 +00001148
Evan Chenga8e29892007-01-19 07:51:42 +00001149// Large immediate handling.
Rafael Espindola0505be02006-10-16 21:10:32 +00001150
Evan Chenga8e29892007-01-19 07:51:42 +00001151// Two piece so_imms.
1152def : ARMPat<(i32 so_imm2part:$src),
1153 (ORRri (MOVri (so_imm2part_1 imm:$src)),
1154 (so_imm2part_2 imm:$src))>;
Rafael Espindolaf621abc2006-10-17 13:36:07 +00001155
Evan Chenga8e29892007-01-19 07:51:42 +00001156def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1157 (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1158 (so_imm2part_2 imm:$RHS))>;
1159def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1160 (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1161 (so_imm2part_2 imm:$RHS))>;
Rafael Espindolaf621abc2006-10-17 13:36:07 +00001162
Evan Chenga8e29892007-01-19 07:51:42 +00001163// TODO: add,sub,and, 3-instr forms?
Rafael Espindola0505be02006-10-16 21:10:32 +00001164
Rafael Espindola24357862006-10-19 17:05:03 +00001165
Evan Chenga8e29892007-01-19 07:51:42 +00001166// Direct calls
1167def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>;
Rafael Espindola9dca7ad2006-11-01 14:13:27 +00001168
Evan Chenga8e29892007-01-19 07:51:42 +00001169// zextload i1 -> zextload i8
1170def : ARMPat<(zextloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
Lauro Ramos Venancioa8f9f4a2006-12-26 19:30:42 +00001171
Evan Chenga8e29892007-01-19 07:51:42 +00001172// extload -> zextload
1173def : ARMPat<(extloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1174def : ARMPat<(extloadi8 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1175def : ARMPat<(extloadi16 addrmode3:$addr), (LDRH addrmode3:$addr)>;
Rafael Espindola9dca7ad2006-11-01 14:13:27 +00001176
Evan Chenga8e29892007-01-19 07:51:42 +00001177// truncstore i1 -> truncstore i8
1178def : Pat<(truncstorei1 GPR:$src, addrmode2:$dst),
1179 (STRB GPR:$src, addrmode2:$dst)>;
1180def : Pat<(pre_truncsti1 GPR:$src, GPR:$base, am2offset:$offset),
1181 (STRB_PRE GPR:$src, GPR:$base, am2offset:$offset)>;
1182def : Pat<(post_truncsti1 GPR:$src, GPR:$base, am2offset:$offset),
1183 (STRB_POST GPR:$src, GPR:$base, am2offset:$offset)>;
1184
1185//===----------------------------------------------------------------------===//
1186// Thumb Support
1187//
1188
1189include "ARMInstrThumb.td"
1190
1191//===----------------------------------------------------------------------===//
1192// Floating Point Support
1193//
1194
1195include "ARMInstrVFP.td"