blob: 17bdd23eaba119105768756666d4f67b8c42313b [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMInstrInfo.td - Target Description for ARM Target -*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the ARM instructions in TableGen format.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// ARM specific DAG Nodes.
16//
17
18// Type profiles.
Bill Wendling7173da52007-11-13 09:19:02 +000019def SDT_ARMCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
20def SDT_ARMCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>, SDTCisVT<1, i32> ]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021
22def SDT_ARMSaveCallPC : SDTypeProfile<0, 1, []>;
23
24def SDT_ARMcall : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
25
26def SDT_ARMCMov : SDTypeProfile<1, 3,
27 [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
28 SDTCisVT<3, i32>]>;
29
30def SDT_ARMBrcond : SDTypeProfile<0, 2,
31 [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
32
33def SDT_ARMBrJT : SDTypeProfile<0, 3,
34 [SDTCisPtrTy<0>, SDTCisVT<1, i32>,
35 SDTCisVT<2, i32>]>;
36
37def SDT_ARMCmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
38
39def SDT_ARMPICAdd : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
40 SDTCisPtrTy<1>, SDTCisVT<2, i32>]>;
41
42def SDT_ARMThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
43
44// Node definitions.
45def ARMWrapper : SDNode<"ARMISD::Wrapper", SDTIntUnaryOp>;
46def ARMWrapperJT : SDNode<"ARMISD::WrapperJT", SDTIntBinOp>;
47
Bill Wendling7173da52007-11-13 09:19:02 +000048def ARMcallseq_start : SDNode<"ISD::CALLSEQ_START", SDT_ARMCallSeqStart,
Bill Wendling6c02cd22008-02-27 06:33:05 +000049 [SDNPHasChain, SDNPOutFlag]>;
Bill Wendling7173da52007-11-13 09:19:02 +000050def ARMcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_ARMCallSeqEnd,
Bill Wendling6c02cd22008-02-27 06:33:05 +000051 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052
53def ARMcall : SDNode<"ARMISD::CALL", SDT_ARMcall,
54 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
55def ARMcall_pred : SDNode<"ARMISD::CALL_PRED", SDT_ARMcall,
56 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
57def ARMcall_nolink : SDNode<"ARMISD::CALL_NOLINK", SDT_ARMcall,
58 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
59
Chris Lattner3d254552008-01-15 22:02:54 +000060def ARMretflag : SDNode<"ARMISD::RET_FLAG", SDTNone,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 [SDNPHasChain, SDNPOptInFlag]>;
62
63def ARMcmov : SDNode<"ARMISD::CMOV", SDT_ARMCMov,
64 [SDNPInFlag]>;
65def ARMcneg : SDNode<"ARMISD::CNEG", SDT_ARMCMov,
66 [SDNPInFlag]>;
67
68def ARMbrcond : SDNode<"ARMISD::BRCOND", SDT_ARMBrcond,
69 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
70
71def ARMbrjt : SDNode<"ARMISD::BR_JT", SDT_ARMBrJT,
72 [SDNPHasChain]>;
73
74def ARMcmp : SDNode<"ARMISD::CMP", SDT_ARMCmp,
75 [SDNPOutFlag]>;
76
77def ARMcmpNZ : SDNode<"ARMISD::CMPNZ", SDT_ARMCmp,
78 [SDNPOutFlag]>;
79
80def ARMpic_add : SDNode<"ARMISD::PIC_ADD", SDT_ARMPICAdd>;
81
82def ARMsrl_flag : SDNode<"ARMISD::SRL_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
83def ARMsra_flag : SDNode<"ARMISD::SRA_FLAG", SDTIntUnaryOp, [SDNPOutFlag]>;
84def ARMrrx : SDNode<"ARMISD::RRX" , SDTIntUnaryOp, [SDNPInFlag ]>;
85
86def ARMthread_pointer: SDNode<"ARMISD::THREAD_POINTER", SDT_ARMThreadPointer>;
87
88//===----------------------------------------------------------------------===//
89// ARM Instruction Predicate Definitions.
90//
91def HasV5T : Predicate<"Subtarget->hasV5TOps()">;
92def HasV5TE : Predicate<"Subtarget->hasV5TEOps()">;
93def HasV6 : Predicate<"Subtarget->hasV6Ops()">;
94def IsThumb : Predicate<"Subtarget->isThumb()">;
95def IsARM : Predicate<"!Subtarget->isThumb()">;
96
97//===----------------------------------------------------------------------===//
98// ARM Flag Definitions.
99
100class RegConstraint<string C> {
101 string Constraints = C;
102}
103
104//===----------------------------------------------------------------------===//
105// ARM specific transformation functions and pattern fragments.
106//
107
108// so_imm_XFORM - Return a so_imm value packed into the format described for
109// so_imm def below.
110def so_imm_XFORM : SDNodeXForm<imm, [{
111 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(N->getValue()),
112 MVT::i32);
113}]>;
114
115// so_imm_neg_XFORM - Return a so_imm value packed into the format described for
116// so_imm_neg def below.
117def so_imm_neg_XFORM : SDNodeXForm<imm, [{
118 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(-(int)N->getValue()),
119 MVT::i32);
120}]>;
121
122// so_imm_not_XFORM - Return a so_imm value packed into the format described for
123// so_imm_not def below.
124def so_imm_not_XFORM : SDNodeXForm<imm, [{
125 return CurDAG->getTargetConstant(ARM_AM::getSOImmVal(~(int)N->getValue()),
126 MVT::i32);
127}]>;
128
129// rot_imm predicate - True if the 32-bit immediate is equal to 8, 16, or 24.
130def rot_imm : PatLeaf<(i32 imm), [{
131 int32_t v = (int32_t)N->getValue();
132 return v == 8 || v == 16 || v == 24;
133}]>;
134
135/// imm1_15 predicate - True if the 32-bit immediate is in the range [1,15].
136def imm1_15 : PatLeaf<(i32 imm), [{
137 return (int32_t)N->getValue() >= 1 && (int32_t)N->getValue() < 16;
138}]>;
139
140/// imm16_31 predicate - True if the 32-bit immediate is in the range [16,31].
141def imm16_31 : PatLeaf<(i32 imm), [{
142 return (int32_t)N->getValue() >= 16 && (int32_t)N->getValue() < 32;
143}]>;
144
145def so_imm_neg :
146 PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(-(int)N->getValue()) != -1; }],
147 so_imm_neg_XFORM>;
148
149def so_imm_not :
150 PatLeaf<(imm), [{ return ARM_AM::getSOImmVal(~(int)N->getValue()) != -1; }],
151 so_imm_not_XFORM>;
152
153// sext_16_node predicate - True if the SDNode is sign-extended 16 or more bits.
154def sext_16_node : PatLeaf<(i32 GPR:$a), [{
Dan Gohman8181bd12008-07-27 21:46:04 +0000155 return CurDAG->ComputeNumSignBits(SDValue(N,0)) >= 17;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000156}]>;
157
Evan Cheng7b0249b2008-08-28 23:39:26 +0000158class BinOpFrag<dag res> : PatFrag<(ops node:$LHS, node:$RHS), res>;
159class UnOpFrag <dag res> : PatFrag<(ops node:$Src), res>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160
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
Evan Cheng7b0249b2008-08-28 23:39:26 +0000335include "ARMInstrFormats.td"
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000336
337//===----------------------------------------------------------------------===//
Evan Cheng7b0249b2008-08-28 23:39:26 +0000338// Multiclass helpers...
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000339//
340
Evan Cheng40d64532008-08-29 07:36:24 +0000341/// AsI1_bin_irs - Defines a set of (op r, {so_imm|r|so_reg}) patterns for a
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342/// binop that produces a value.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000343multiclass AsI1_bin_irs<bits<4> opcod, string opc, PatFrag opnode> {
344 def ri : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000345 opc, " $dst, $a, $b",
346 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000347 def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPRReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348 opc, " $dst, $a, $b",
349 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000350 def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351 opc, " $dst, $a, $b",
352 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
353}
354
355/// ASI1_bin_s_irs - Similar to AsI1_bin_irs except it sets the 's' bit so the
356/// instruction modifies the CSPR register.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000357let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000358multiclass ASI1_bin_s_irs<bits<4> opcod, string opc, PatFrag opnode> {
359 def ri : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRImS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000361 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000362 def rr : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPRRegS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000364 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000365 def rs : AI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoRegS,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000366 opc, "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000367 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
368}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369}
370
371/// AI1_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
372/// patterns. Similar to AsI1_bin_irs except the instruction does not produce
373/// a explicit result, only implicitly set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000374let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000375multiclass AI1_cmp_irs<bits<4> opcod, string opc, PatFrag opnode> {
376 def ri : AI1<opcod, (outs), (ins GPR:$a, so_imm:$b), DPRnIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000377 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000378 [(opnode GPR:$a, so_imm:$b)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000379 def rr : AI1<opcod, (outs), (ins GPR:$a, GPR:$b), DPRnReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000381 [(opnode GPR:$a, GPR:$b)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000382 def rs : AI1<opcod, (outs), (ins GPR:$a, so_reg:$b), DPRnSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000383 opc, " $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000384 [(opnode GPR:$a, so_reg:$b)]>;
385}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000386}
387
388/// AI_unary_rrot - A unary operation with two forms: one whose operand is a
389/// register and one whose operand is a register rotated by 8/16/24.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000390multiclass AI_unary_rrot<bits<4> opcod, string opc, PatFrag opnode> {
391 def r : AI<opcod, (outs GPR:$dst), (ins GPR:$Src), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392 opc, " $dst, $Src",
393 [(set GPR:$dst, (opnode GPR:$Src))]>, Requires<[IsARM, HasV6]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000394 def r_rot : AI<opcod, (outs GPR:$dst), (ins GPR:$Src, i32imm:$rot), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395 opc, " $dst, $Src, ror $rot",
396 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>,
397 Requires<[IsARM, HasV6]>;
398}
399
400/// AI_bin_rrot - A binary operation with two forms: one whose operand is a
401/// register and one whose operand is a register rotated by 8/16/24.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000402multiclass AI_bin_rrot<bits<4> opcod, string opc, PatFrag opnode> {
403 def rr : AI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
404 Pseudo, opc, " $dst, $LHS, $RHS",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>,
406 Requires<[IsARM, HasV6]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000407 def rr_rot : AI<opcod, (outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
408 Pseudo, opc, " $dst, $LHS, $RHS, ror $rot",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409 [(set GPR:$dst, (opnode GPR:$LHS,
410 (rotr GPR:$RHS, rot_imm:$rot)))]>,
411 Requires<[IsARM, HasV6]>;
412}
413
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000414/// AsXI1_bin_c_irs - Same as AsI1_bin_irs but without the predicate operand and
415/// setting carry bit. But it can optionally set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000416let Uses = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000417multiclass AsXI1_bin_c_irs<bits<4> opcod, string opc, PatFrag opnode> {
418 def ri : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
419 DPRIm, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000420 [(set GPR:$dst, (opnode GPR:$a, so_imm:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000421 def rr : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b, cc_out:$s),
422 DPRReg, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000423 [(set GPR:$dst, (opnode GPR:$a, GPR:$b))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000424 def rs : AXI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
425 DPRSoReg, !strconcat(opc, "${s} $dst, $a, $b"),
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000426 [(set GPR:$dst, (opnode GPR:$a, so_reg:$b))]>;
427}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428}
429
430//===----------------------------------------------------------------------===//
431// Instructions
432//===----------------------------------------------------------------------===//
433
434//===----------------------------------------------------------------------===//
435// Miscellaneous Instructions.
436//
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437
438/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool in
439/// the function. The first operand is the ID# for this instruction, the second
440/// is the index into the MachineConstantPool that this is, the third is the
441/// size in bytes of this constant pool entry.
442let isNotDuplicable = 1 in
443def CONSTPOOL_ENTRY :
Evan Chengb783fa32007-07-19 01:14:50 +0000444PseudoInst<(outs), (ins cpinst_operand:$instid, cpinst_operand:$cpidx,
445 i32imm:$size),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446 "${instid:label} ${cpidx:cpentry}", []>;
447
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000448let Defs = [SP], Uses = [SP] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000449def ADJCALLSTACKUP :
Bill Wendling22f8deb2007-11-13 00:44:25 +0000450PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2, pred:$p),
451 "@ ADJCALLSTACKUP $amt1",
452 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453
454def ADJCALLSTACKDOWN :
Evan Chengb783fa32007-07-19 01:14:50 +0000455PseudoInst<(outs), (ins i32imm:$amt, pred:$p),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456 "@ ADJCALLSTACKDOWN $amt",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000457 [(ARMcallseq_start imm:$amt)]>;
458}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459
460def DWARF_LOC :
Evan Chengb783fa32007-07-19 01:14:50 +0000461PseudoInst<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000462 ".loc $file, $line, $col",
463 [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
464
465let isNotDuplicable = 1 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000466def PICADD : AXI1<0x0, (outs GPR:$dst), (ins GPR:$a, pclabel:$cp, pred:$p),
467 Pseudo, "$cp:\n\tadd$p $dst, pc, $a",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000468 [(set GPR:$dst, (ARMpic_add GPR:$a, imm:$cp))]>;
469
Evan Cheng8610a3b2008-01-07 23:56:57 +0000470let AddedComplexity = 10 in {
471let isSimpleLoad = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000472def PICLD : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
473 Pseudo, "${addr:label}:\n\tldr$p $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474 [(set GPR:$dst, (load addrmodepc:$addr))]>;
475
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000476def PICLDZH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
477 Pseudo, "${addr:label}:\n\tldr${p}h $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478 [(set GPR:$dst, (zextloadi16 addrmodepc:$addr))]>;
479
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000480def PICLDZB : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
481 Pseudo, "${addr:label}:\n\tldr${p}b $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482 [(set GPR:$dst, (zextloadi8 addrmodepc:$addr))]>;
483
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000484def PICLDH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
485 Pseudo, "${addr:label}:\n\tldr${p}h $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486 [(set GPR:$dst, (extloadi16 addrmodepc:$addr))]>;
487
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000488def PICLDB : AXI2<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
489 Pseudo, "${addr:label}:\n\tldr${p}b $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490 [(set GPR:$dst, (extloadi8 addrmodepc:$addr))]>;
491
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000492def PICLDSH : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
493 Pseudo, "${addr:label}:\n\tldr${p}sh $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494 [(set GPR:$dst, (sextloadi16 addrmodepc:$addr))]>;
495
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000496def PICLDSB : AXI3<0x0, (outs GPR:$dst), (ins addrmodepc:$addr, pred:$p),
497 Pseudo, "${addr:label}:\n\tldr${p}sb $dst, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498 [(set GPR:$dst, (sextloadi8 addrmodepc:$addr))]>;
499}
Chris Lattnerf823faf2008-01-06 05:55:01 +0000500let AddedComplexity = 10 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000501def PICSTR : AXI2<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
502 Pseudo, "${addr:label}:\n\tstr$p $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000503 [(store GPR:$src, addrmodepc:$addr)]>;
504
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000505def PICSTRH : AXI3<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
506 Pseudo, "${addr:label}:\n\tstr${p}h $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000507 [(truncstorei16 GPR:$src, addrmodepc:$addr)]>;
508
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000509def PICSTRB : AXI2<0x0, (outs), (ins GPR:$src, addrmodepc:$addr, pred:$p),
510 Pseudo, "${addr:label}:\n\tstr${p}b $src, $addr",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511 [(truncstorei8 GPR:$src, addrmodepc:$addr)]>;
512}
513}
514
515//===----------------------------------------------------------------------===//
516// Control Flow Instructions.
517//
518
519let isReturn = 1, isTerminator = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000520 def BX_RET : AI<0x1, (outs), (ins), BranchMisc, "bx", " lr", [(ARMretflag)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521
522// FIXME: remove when we have a way to marking a MI with these properties.
Evan Chengb783fa32007-07-19 01:14:50 +0000523// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
524// operand list.
Evan Cheng8610a3b2008-01-07 23:56:57 +0000525let isReturn = 1, isTerminator = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000526 def LDM_RET : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000527 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000528 LdFrm, "ldm${p}${addr:submode} $addr, $dst1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529 []>;
530
Evan Cheng37e7c752007-07-21 00:34:19 +0000531let isCall = 1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532 Defs = [R0, R1, R2, R3, R12, LR,
533 D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000534 def BL : AXI<0xB, (outs), (ins i32imm:$func, variable_ops), Branch,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535 "bl ${func:call}",
536 [(ARMcall tglobaladdr:$func)]>;
537
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000538 def BL_pred : AI<0xB, (outs), (ins i32imm:$func, variable_ops),
539 Branch, "bl", " ${func:call}",
540 [(ARMcall_pred tglobaladdr:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541
542 // ARMv5T and above
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000543 def BLX : AXI<0x2, (outs), (ins GPR:$func, variable_ops), BranchMisc,
Evan Chengb783fa32007-07-19 01:14:50 +0000544 "blx $func",
545 [(ARMcall GPR:$func)]>, Requires<[IsARM, HasV5T]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546 let Uses = [LR] in {
547 // ARMv4T
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000548 def BX : AXIx2<0x0, (outs), (ins GPR:$func, variable_ops),
549 BranchMisc, "mov lr, pc\n\tbx $func",
550 [(ARMcall_nolink GPR:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551 }
552}
553
Evan Cheng37e7c752007-07-21 00:34:19 +0000554let isBranch = 1, isTerminator = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555 // B is "predicable" since it can be xformed into a Bcc.
556 let isBarrier = 1 in {
557 let isPredicable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000558 def B : AXI<0xA, (outs), (ins brtarget:$target), Branch, "b $target",
Evan Chengb783fa32007-07-19 01:14:50 +0000559 [(br bb:$target)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000560
Owen Andersonf8053082007-11-12 07:39:39 +0000561 let isNotDuplicable = 1, isIndirectBranch = 1 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000562 def BR_JTr : JTI<0x0, (outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
Evan Chengb783fa32007-07-19 01:14:50 +0000563 "mov pc, $target \n$jt",
564 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000565 def BR_JTm : JTI2<0x0, (outs), (ins addrmode2:$target, jtblock_operand:$jt, i32imm:$id),
Evan Chengb783fa32007-07-19 01:14:50 +0000566 "ldr pc, $target \n$jt",
567 [(ARMbrjt (i32 (load addrmode2:$target)), tjumptable:$jt,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568 imm:$id)]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000569 def BR_JTadd : JTI1<0x0, (outs), (ins GPR:$target, GPR:$idx, jtblock_operand:$jt,
Evan Chengb783fa32007-07-19 01:14:50 +0000570 i32imm:$id),
571 "add pc, $target, $idx \n$jt",
572 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000573 imm:$id)]>;
574 }
575 }
576
577 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
578 // a two-value operand where a dag node expects two operands. :(
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000579 def Bcc : AI<0xA, (outs), (ins brtarget:$target), Branch,
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000580 "b", " $target",
581 [/*(ARMbrcond bb:$target, imm:$cc, CCR:$ccr)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582}
583
584//===----------------------------------------------------------------------===//
585// Load / store Instructions.
586//
587
588// Load
Evan Cheng8610a3b2008-01-07 23:56:57 +0000589let isSimpleLoad = 1 in
Evan Chengda020022008-08-31 19:02:21 +0000590def LDR : AI2ldw<0x0, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591 "ldr", " $dst, $addr",
592 [(set GPR:$dst, (load addrmode2:$addr))]>;
593
594// Special LDR for loads from non-pc-relative constpools.
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000595let isSimpleLoad = 1, mayLoad = 1, isReMaterializable = 1 in
Evan Chengda020022008-08-31 19:02:21 +0000596def LDRcp : AI2ldw<0x0, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597 "ldr", " $dst, $addr", []>;
598
599// Loads with zero extension
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000600def LDRH : AI3<0xB, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601 "ldr", "h $dst, $addr",
602 [(set GPR:$dst, (zextloadi16 addrmode3:$addr))]>;
603
Evan Chengda020022008-08-31 19:02:21 +0000604def LDRB : AI2ldb<0x1, (outs GPR:$dst), (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000605 "ldr", "b $dst, $addr",
606 [(set GPR:$dst, (zextloadi8 addrmode2:$addr))]>;
607
608// Loads with sign extension
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000609def LDRSH : AI3<0xE, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000610 "ldr", "sh $dst, $addr",
611 [(set GPR:$dst, (sextloadi16 addrmode3:$addr))]>;
612
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000613def LDRSB : AI3<0xD, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614 "ldr", "sb $dst, $addr",
615 [(set GPR:$dst, (sextloadi8 addrmode3:$addr))]>;
616
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000617let mayLoad = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618// Load doubleword
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000619def LDRD : AI3<0xD, (outs GPR:$dst), (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620 "ldr", "d $dst, $addr",
621 []>, Requires<[IsARM, HasV5T]>;
622
623// Indexed loads
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000624def LDR_PRE : AI2pr<0x0, (outs GPR:$dst, GPR:$base_wb),
625 (ins addrmode2:$addr), LdFrm,
626 "ldr", " $dst, $addr!", "$addr.base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000628def LDR_POST : AI2po<0x0, (outs GPR:$dst, GPR:$base_wb),
629 (ins GPR:$base, am2offset:$offset), LdFrm,
630 "ldr", " $dst, [$base], $offset", "$base = $base_wb", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000631
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000632def LDRH_PRE : AI3pr<0xB, (outs GPR:$dst, GPR:$base_wb),
633 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000634 "ldr", "h $dst, $addr!", "$addr.base = $base_wb", []>;
635
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000636def LDRH_POST : AI3po<0xB, (outs GPR:$dst, GPR:$base_wb),
637 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000638 "ldr", "h $dst, [$base], $offset", "$base = $base_wb", []>;
639
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000640def LDRB_PRE : AI2pr<0x1, (outs GPR:$dst, GPR:$base_wb),
641 (ins addrmode2:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000642 "ldr", "b $dst, $addr!", "$addr.base = $base_wb", []>;
643
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000644def LDRB_POST : AI2po<0x1, (outs GPR:$dst, GPR:$base_wb),
645 (ins GPR:$base,am2offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000646 "ldr", "b $dst, [$base], $offset", "$base = $base_wb", []>;
647
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000648def LDRSH_PRE : AI3pr<0xE, (outs GPR:$dst, GPR:$base_wb),
649 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000650 "ldr", "sh $dst, $addr!", "$addr.base = $base_wb", []>;
651
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000652def LDRSH_POST: AI3po<0xE, (outs GPR:$dst, GPR:$base_wb),
653 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654 "ldr", "sh $dst, [$base], $offset", "$base = $base_wb", []>;
655
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000656def LDRSB_PRE : AI3pr<0xD, (outs GPR:$dst, GPR:$base_wb),
657 (ins addrmode3:$addr), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658 "ldr", "sb $dst, $addr!", "$addr.base = $base_wb", []>;
659
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000660def LDRSB_POST: AI3po<0xD, (outs GPR:$dst, GPR:$base_wb),
661 (ins GPR:$base,am3offset:$offset), LdFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662 "ldr", "sb $dst, [$base], $offset", "$base = $base_wb", []>;
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000663}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000664
665// Store
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000666def STR : AI2<0x0, (outs), (ins GPR:$src, addrmode2:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667 "str", " $src, $addr",
668 [(store GPR:$src, addrmode2:$addr)]>;
669
670// Stores with truncate
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000671def STRH : AI3<0xB, (outs), (ins GPR:$src, addrmode3:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000672 "str", "h $src, $addr",
673 [(truncstorei16 GPR:$src, addrmode3:$addr)]>;
674
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000675def STRB : AI2<0x1, (outs), (ins GPR:$src, addrmode2:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676 "str", "b $src, $addr",
677 [(truncstorei8 GPR:$src, addrmode2:$addr)]>;
678
679// Store doubleword
Chris Lattner6887b142008-01-06 08:36:04 +0000680let mayStore = 1 in
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000681def STRD : AI3<0xF, (outs), (ins GPR:$src, addrmode3:$addr), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000682 "str", "d $src, $addr",
683 []>, Requires<[IsARM, HasV5T]>;
684
685// Indexed stores
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000686def STR_PRE : AI2pr<0x0, (outs GPR:$base_wb),
687 (ins GPR:$src, GPR:$base, am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688 "str", " $src, [$base, $offset]!", "$base = $base_wb",
689 [(set GPR:$base_wb,
690 (pre_store GPR:$src, GPR:$base, am2offset:$offset))]>;
691
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000692def STR_POST : AI2po<0x0, (outs GPR:$base_wb),
693 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694 "str", " $src, [$base], $offset", "$base = $base_wb",
695 [(set GPR:$base_wb,
696 (post_store GPR:$src, GPR:$base, am2offset:$offset))]>;
697
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000698def STRH_PRE : AI3pr<0xB, (outs GPR:$base_wb),
699 (ins GPR:$src, GPR:$base,am3offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000700 "str", "h $src, [$base, $offset]!", "$base = $base_wb",
701 [(set GPR:$base_wb,
702 (pre_truncsti16 GPR:$src, GPR:$base,am3offset:$offset))]>;
703
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000704def STRH_POST: AI3po<0xB, (outs GPR:$base_wb),
705 (ins GPR:$src, GPR:$base,am3offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000706 "str", "h $src, [$base], $offset", "$base = $base_wb",
707 [(set GPR:$base_wb, (post_truncsti16 GPR:$src,
708 GPR:$base, am3offset:$offset))]>;
709
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000710def STRB_PRE : AI2pr<0x1, (outs GPR:$base_wb),
711 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712 "str", "b $src, [$base, $offset]!", "$base = $base_wb",
713 [(set GPR:$base_wb, (pre_truncsti8 GPR:$src,
714 GPR:$base, am2offset:$offset))]>;
715
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000716def STRB_POST: AI2po<0x1, (outs GPR:$base_wb),
717 (ins GPR:$src, GPR:$base,am2offset:$offset), StFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000718 "str", "b $src, [$base], $offset", "$base = $base_wb",
719 [(set GPR:$base_wb, (post_truncsti8 GPR:$src,
720 GPR:$base, am2offset:$offset))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000721
722//===----------------------------------------------------------------------===//
723// Load / store multiple Instructions.
724//
725
Evan Chengb783fa32007-07-19 01:14:50 +0000726// FIXME: $dst1 should be a def.
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000727let mayLoad = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000728def LDM : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000729 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000730 LdFrm, "ldm${p}${addr:submode} $addr, $dst1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000731 []>;
732
Chris Lattner6887b142008-01-06 08:36:04 +0000733let mayStore = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000734def STM : AXI4<0x0, (outs),
Evan Chengb783fa32007-07-19 01:14:50 +0000735 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000736 StFrm, "stm${p}${addr:submode} $addr, $src1",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000737 []>;
738
739//===----------------------------------------------------------------------===//
740// Move Instructions.
741//
742
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000743def MOVr : AsI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000744 "mov", " $dst, $src", []>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000745def MOVs : AsI1<0xD, (outs GPR:$dst), (ins so_reg:$src), DPRdSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000746 "mov", " $dst, $src", [(set GPR:$dst, so_reg:$src)]>;
747
748let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000749def MOVi : AsI1<0xD, (outs GPR:$dst), (ins so_imm:$src), DPRdIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 "mov", " $dst, $src", [(set GPR:$dst, so_imm:$src)]>;
751
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000752def MOVrx : AsI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Evan Chengb783fa32007-07-19 01:14:50 +0000753 "mov", " $dst, $src, rrx",
754 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000755
756// These aren't really mov instructions, but we have to define them this way
757// due to flag operands.
758
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000759let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000760def MOVsrl_flag : AI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000761 "mov", "s $dst, $src, lsr #1",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000762 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000763def MOVsra_flag : AI1<0xD, (outs GPR:$dst), (ins GPR:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764 "mov", "s $dst, $src, asr #1",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000765 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>;
766}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000767
768//===----------------------------------------------------------------------===//
769// Extend Instructions.
770//
771
772// Sign extenders
773
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000774defm SXTB : AI_unary_rrot<0x0, "sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
775defm SXTH : AI_unary_rrot<0x0, "sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000777defm SXTAB : AI_bin_rrot<0x0, "sxtab",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000778 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000779defm SXTAH : AI_bin_rrot<0x0, "sxtah",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000780 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
781
782// TODO: SXT(A){B|H}16
783
784// Zero extenders
785
786let AddedComplexity = 16 in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000787defm UXTB : AI_unary_rrot<0x0, "uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
788defm UXTH : AI_unary_rrot<0x0, "uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
789defm UXTB16 : AI_unary_rrot<0x0, "uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790
791def : ARMV6Pat<(and (shl GPR:$Src, 8), 0xFF00FF),
792 (UXTB16r_rot GPR:$Src, 24)>;
793def : ARMV6Pat<(and (srl GPR:$Src, 8), 0xFF00FF),
794 (UXTB16r_rot GPR:$Src, 8)>;
795
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000796defm UXTAB : AI_bin_rrot<0x0, "uxtab",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000798defm UXTAH : AI_bin_rrot<0x0, "uxtah",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000799 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
800}
801
802// This isn't safe in general, the add is two 16-bit units, not a 32-bit add.
803//defm UXTAB16 : xxx<"uxtab16", 0xff00ff>;
804
805// TODO: UXT(A){B|H}16
806
807//===----------------------------------------------------------------------===//
808// Arithmetic Instructions.
809//
810
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000811defm ADD : AsI1_bin_irs<0x4, "add", BinOpFrag<(add node:$LHS, node:$RHS)>>;
812defm SUB : AsI1_bin_irs<0x2, "sub", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000813
814// ADD and SUB with 's' bit set.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000815defm ADDS : ASI1_bin_s_irs<0x4, "add", BinOpFrag<(addc node:$LHS, node:$RHS)>>;
816defm SUBS : ASI1_bin_s_irs<0x2, "sub", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000817
818// FIXME: Do not allow ADC / SBC to be predicated for now.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000819defm ADC : AsXI1_bin_c_irs<0x5, "adc", BinOpFrag<(adde node:$LHS, node:$RHS)>>;
820defm SBC : AsXI1_bin_c_irs<0x6, "sbc", BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000821
822// These don't define reg/reg forms, because they are handled above.
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000823def RSBri : AsI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000824 "rsb", " $dst, $a, $b",
825 [(set GPR:$dst, (sub so_imm:$b, GPR:$a))]>;
826
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000827def RSBrs : AsI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000828 "rsb", " $dst, $a, $b",
829 [(set GPR:$dst, (sub so_reg:$b, GPR:$a))]>;
830
831// RSB with 's' bit set.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000832let Defs = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000833def RSBSri : AI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_imm:$b), DPRIm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000834 "rsb", "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000835 [(set GPR:$dst, (subc so_imm:$b, GPR:$a))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000836def RSBSrs : AI1<0x3, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPRSoReg,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000837 "rsb", "s $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000838 [(set GPR:$dst, (subc so_reg:$b, GPR:$a))]>;
839}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000840
841// FIXME: Do not allow RSC to be predicated for now. But they can set CPSR.
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000842let Uses = [CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000843def RSCri : AXI1<0x7, (outs GPR:$dst), (ins GPR:$a, so_imm:$b, cc_out:$s),
844 DPRIm, "rsc${s} $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000845 [(set GPR:$dst, (sube so_imm:$b, GPR:$a))]>;
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000846def RSCrs : AXI1<0x7, (outs GPR:$dst), (ins GPR:$a, so_reg:$b, cc_out:$s),
847 DPRSoReg, "rsc${s} $dst, $a, $b",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000848 [(set GPR:$dst, (sube so_reg:$b, GPR:$a))]>;
849}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000850
851// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
852def : ARMPat<(add GPR:$src, so_imm_neg:$imm),
853 (SUBri GPR:$src, so_imm_neg:$imm)>;
854
855//def : ARMPat<(addc GPR:$src, so_imm_neg:$imm),
856// (SUBSri GPR:$src, so_imm_neg:$imm)>;
857//def : ARMPat<(adde GPR:$src, so_imm_neg:$imm),
858// (SBCri GPR:$src, so_imm_neg:$imm)>;
859
860// Note: These are implemented in C++ code, because they have to generate
861// ADD/SUBrs instructions, which use a complex pattern that a xform function
862// cannot produce.
863// (mul X, 2^n+1) -> (add (X << n), X)
864// (mul X, 2^n-1) -> (rsb X, (X << n))
865
866
867//===----------------------------------------------------------------------===//
868// Bitwise Instructions.
869//
870
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000871defm AND : AsI1_bin_irs<0x0, "and", BinOpFrag<(and node:$LHS, node:$RHS)>>;
872defm ORR : AsI1_bin_irs<0xC, "orr", BinOpFrag<(or node:$LHS, node:$RHS)>>;
873defm EOR : AsI1_bin_irs<0x1, "eor", BinOpFrag<(xor node:$LHS, node:$RHS)>>;
874defm BIC : AsI1_bin_irs<0xE, "bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000875
Evan Cheng40d64532008-08-29 07:36:24 +0000876def MVNr : AsI1<0xE, (outs GPR:$dst), (ins GPR:$src), DPRdReg,
877 "mvn", " $dst, $src", [(set GPR:$dst, (not GPR:$src))]>;
878def MVNs : AsI1<0xE, (outs GPR:$dst), (ins so_reg:$src), DPRdSoReg,
879 "mvn", " $dst, $src", [(set GPR:$dst, (not so_reg:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000880let isReMaterializable = 1 in
Evan Cheng40d64532008-08-29 07:36:24 +0000881def MVNi : AsI1<0xE, (outs GPR:$dst), (ins so_imm:$imm), DPRdIm,
882 "mvn", " $dst, $imm", [(set GPR:$dst, so_imm_not:$imm)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000883
884def : ARMPat<(and GPR:$src, so_imm_not:$imm),
885 (BICri GPR:$src, so_imm_not:$imm)>;
886
887//===----------------------------------------------------------------------===//
888// Multiply Instructions.
889//
890
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000891def MUL : AsI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulFrm,
892 "mul", " $dst, $a, $b",
893 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000894
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000895def MLA : AsI<0x2, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
896 MulFrm, "mla", " $dst, $a, $b, $c",
897 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000898
899// Extra precision multiplies with low / high results
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000900def SMULL : AsI<0xC, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
901 MulFrm, "smull", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000902
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000903def UMULL : AsI<0x8, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
904 MulFrm, "umull", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000905
906// Multiply + accumulate
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000907def SMLAL : AsI<0xE, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
908 MulFrm, "smlal", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000909
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000910def UMLAL : AsI<0xA, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
911 MulFrm, "umlal", " $ldst, $hdst, $a, $b", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000912
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000913def UMAAL : AI<0x0, (outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000914 "umaal", " $ldst, $hdst, $a, $b", []>,
915 Requires<[IsARM, HasV6]>;
916
917// Most significant word multiply
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000918def SMMUL : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000919 "smmul", " $dst, $a, $b",
920 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>,
921 Requires<[IsARM, HasV6]>;
922
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000923def SMMLA : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000924 "smmla", " $dst, $a, $b, $c",
925 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>,
926 Requires<[IsARM, HasV6]>;
927
928
Evan Chenga7b3e7c2007-08-07 01:37:15 +0000929def SMMLS : AI<0x0, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c), MulFrm,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000930 "smmls", " $dst, $a, $b, $c",
931 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>,
932 Requires<[IsARM, HasV6]>;
933
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000934multiclass AI_smul<string opc, PatFrag opnode> {
935 def BB : AI<0x8, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000936 !strconcat(opc, "bb"), " $dst, $a, $b",
937 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
938 (sext_inreg GPR:$b, i16)))]>,
939 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000940
941 def BT : AI<0xC, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000942 !strconcat(opc, "bt"), " $dst, $a, $b",
943 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
944 (sra GPR:$b, 16)))]>,
945 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000946
947 def TB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000948 !strconcat(opc, "tb"), " $dst, $a, $b",
949 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
950 (sext_inreg GPR:$b, i16)))]>,
951 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000952
953 def TT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMUL,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000954 !strconcat(opc, "tt"), " $dst, $a, $b",
955 [(set GPR:$dst, (opnode (sra GPR:$a, 16),
956 (sra GPR:$b, 16)))]>,
957 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000958
959 def WB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMULW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000960 !strconcat(opc, "wb"), " $dst, $a, $b",
961 [(set GPR:$dst, (sra (opnode GPR:$a,
962 (sext_inreg GPR:$b, i16)), 16))]>,
963 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000964
965 def WT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b), MulSMULW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000966 !strconcat(opc, "wt"), " $dst, $a, $b",
967 [(set GPR:$dst, (sra (opnode GPR:$a,
968 (sra GPR:$b, 16)), 16))]>,
969 Requires<[IsARM, HasV5TE]>;
970}
971
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000972
973multiclass AI_smla<string opc, PatFrag opnode> {
974 def BB : AI<0x8, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000975 !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
976 [(set GPR:$dst, (add GPR:$acc,
977 (opnode (sext_inreg GPR:$a, i16),
978 (sext_inreg GPR:$b, i16))))]>,
979 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000980
981 def BT : AI<0xC, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000982 !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
983 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
984 (sra GPR:$b, 16))))]>,
985 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000986
987 def TB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000988 !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
989 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
990 (sext_inreg GPR:$b, i16))))]>,
991 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000992
993 def TT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLA,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000994 !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
995 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, 16),
996 (sra GPR:$b, 16))))]>,
997 Requires<[IsARM, HasV5TE]>;
998
Raul Herbster2e07e8d2007-08-30 23:25:47 +0000999 def WB : AI<0xA, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLAW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001000 !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
1001 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1002 (sext_inreg GPR:$b, i16)), 16)))]>,
1003 Requires<[IsARM, HasV5TE]>;
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001004
1005 def WT : AI<0xE, (outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc), MulSMLAW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006 !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
1007 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
1008 (sra GPR:$b, 16)), 16)))]>,
1009 Requires<[IsARM, HasV5TE]>;
1010}
1011
Raul Herbster2e07e8d2007-08-30 23:25:47 +00001012defm SMUL : AI_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
1013defm SMLA : AI_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001014
1015// TODO: Halfword multiple accumulate long: SMLAL<x><y>
1016// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
1017
1018//===----------------------------------------------------------------------===//
1019// Misc. Arithmetic Instructions.
1020//
1021
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001022def CLZ : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001023 "clz", " $dst, $src",
1024 [(set GPR:$dst, (ctlz GPR:$src))]>, Requires<[IsARM, HasV5T]>;
1025
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001026def REV : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001027 "rev", " $dst, $src",
1028 [(set GPR:$dst, (bswap GPR:$src))]>, Requires<[IsARM, HasV6]>;
1029
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001030def REV16 : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031 "rev16", " $dst, $src",
1032 [(set GPR:$dst,
1033 (or (and (srl GPR:$src, 8), 0xFF),
1034 (or (and (shl GPR:$src, 8), 0xFF00),
1035 (or (and (srl GPR:$src, 8), 0xFF0000),
1036 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
1037 Requires<[IsARM, HasV6]>;
1038
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001039def REVSH : AI<0x0, (outs GPR:$dst), (ins GPR:$src), ArithMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001040 "revsh", " $dst, $src",
1041 [(set GPR:$dst,
1042 (sext_inreg
1043 (or (srl (and GPR:$src, 0xFF00), 8),
1044 (shl GPR:$src, 8)), i16))]>,
1045 Requires<[IsARM, HasV6]>;
1046
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001047def PKHBT : AI<0x0, (outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1048 Pseudo, "pkhbt", " $dst, $src1, $src2, LSL $shamt",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001049 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
1050 (and (shl GPR:$src2, (i32 imm:$shamt)),
1051 0xFFFF0000)))]>,
1052 Requires<[IsARM, HasV6]>;
1053
1054// Alternate cases for PKHBT where identities eliminate some nodes.
1055def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
1056 (PKHBT GPR:$src1, GPR:$src2, 0)>;
1057def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
1058 (PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
1059
1060
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001061def PKHTB : AI<0x0, (outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
1062 Pseudo, "pkhtb", " $dst, $src1, $src2, ASR $shamt",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001063 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
1064 (and (sra GPR:$src2, imm16_31:$shamt),
1065 0xFFFF)))]>, Requires<[IsARM, HasV6]>;
1066
1067// Alternate cases for PKHTB where identities eliminate some nodes. Note that
1068// a shift amount of 0 is *not legal* here, it is PKHBT instead.
1069def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, 16)),
1070 (PKHTB GPR:$src1, GPR:$src2, 16)>;
1071def : ARMV6Pat<(or (and GPR:$src1, 0xFFFF0000),
1072 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
1073 (PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
1074
1075
1076//===----------------------------------------------------------------------===//
1077// Comparison Instructions...
1078//
1079
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001080defm CMP : AI1_cmp_irs<0xA, "cmp",
1081 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
1082defm CMN : AI1_cmp_irs<0xB, "cmn",
1083 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001084
1085// Note that TST/TEQ don't set all the same flags that CMP does!
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001086defm TST : AI1_cmp_irs<0x8, "tst",
1087 BinOpFrag<(ARMcmpNZ (and node:$LHS, node:$RHS), 0)>>;
1088defm TEQ : AI1_cmp_irs<0x9, "teq",
1089 BinOpFrag<(ARMcmpNZ (xor node:$LHS, node:$RHS), 0)>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001090
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001091defm CMPnz : AI1_cmp_irs<0xA, "cmp",
1092 BinOpFrag<(ARMcmpNZ node:$LHS, node:$RHS)>>;
1093defm CMNnz : AI1_cmp_irs<0xA, "cmn",
1094 BinOpFrag<(ARMcmpNZ node:$LHS,(ineg node:$RHS))>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001095
1096def : ARMPat<(ARMcmp GPR:$src, so_imm_neg:$imm),
1097 (CMNri GPR:$src, so_imm_neg:$imm)>;
1098
1099def : ARMPat<(ARMcmpNZ GPR:$src, so_imm_neg:$imm),
1100 (CMNri GPR:$src, so_imm_neg:$imm)>;
1101
1102
1103// Conditional moves
1104// FIXME: should be able to write a pattern for ARMcmov, but can't use
1105// a two-value operand where a dag node expects two operands. :(
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001106def MOVCCr : AI<0xD, (outs GPR:$dst), (ins GPR:$false, GPR:$true),
1107 DPRdReg, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001108 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1109 RegConstraint<"$false = $dst">;
1110
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001111def MOVCCs : AI<0xD, (outs GPR:$dst), (ins GPR:$false, so_reg:$true),
1112 DPRdSoReg, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001113 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1114 RegConstraint<"$false = $dst">;
1115
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001116def MOVCCi : AI<0xD, (outs GPR:$dst), (ins GPR:$false, so_imm:$true),
1117 DPRdIm, "mov", " $dst, $true",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001118 [/*(set GPR:$dst, (ARMcmov GPR:$false, so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1119 RegConstraint<"$false = $dst">;
1120
1121
1122// LEApcrel - Load a pc-relative address into a register without offending the
1123// assembler.
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001124def LEApcrel : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, pred:$p), Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001125 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
1126 "${:private}PCRELL${:uid}+8))\n"),
1127 !strconcat("${:private}PCRELL${:uid}:\n\t",
1128 "add$p $dst, pc, #PCRELV${:uid}")),
1129 []>;
1130
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001131def LEApcrelJT : AXI1<0x0, (outs GPR:$dst), (ins i32imm:$label, i32imm:$id, pred:$p),
1132 Pseudo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001133 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
1134 "${:private}PCRELL${:uid}+8))\n"),
1135 !strconcat("${:private}PCRELL${:uid}:\n\t",
1136 "add$p $dst, pc, #PCRELV${:uid}")),
1137 []>;
1138
1139//===----------------------------------------------------------------------===//
1140// TLS Instructions
1141//
1142
1143// __aeabi_read_tp preserves the registers r1-r3.
1144let isCall = 1,
1145 Defs = [R0, R12, LR, CPSR] in {
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001146 def TPsoft : AXI<0x0, (outs), (ins), BranchMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001147 "bl __aeabi_read_tp",
1148 [(set R0, ARMthread_pointer)]>;
1149}
1150
1151//===----------------------------------------------------------------------===//
1152// Non-Instruction Patterns
1153//
1154
1155// ConstantPool, GlobalAddress, and JumpTable
1156def : ARMPat<(ARMWrapper tglobaladdr :$dst), (LEApcrel tglobaladdr :$dst)>;
1157def : ARMPat<(ARMWrapper tconstpool :$dst), (LEApcrel tconstpool :$dst)>;
1158def : ARMPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1159 (LEApcrelJT tjumptable:$dst, imm:$id)>;
1160
1161// Large immediate handling.
1162
1163// Two piece so_imms.
1164let isReMaterializable = 1 in
Evan Chenga7b3e7c2007-08-07 01:37:15 +00001165def MOVi2pieces : AI1x2<0x0, (outs GPR:$dst), (ins so_imm2part:$src), DPRdMisc,
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001166 "mov", " $dst, $src",
1167 [(set GPR:$dst, so_imm2part:$src)]>;
1168
1169def : ARMPat<(or GPR:$LHS, so_imm2part:$RHS),
1170 (ORRri (ORRri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1171 (so_imm2part_2 imm:$RHS))>;
1172def : ARMPat<(xor GPR:$LHS, so_imm2part:$RHS),
1173 (EORri (EORri GPR:$LHS, (so_imm2part_1 imm:$RHS)),
1174 (so_imm2part_2 imm:$RHS))>;
1175
1176// TODO: add,sub,and, 3-instr forms?
1177
1178
1179// Direct calls
1180def : ARMPat<(ARMcall texternalsym:$func), (BL texternalsym:$func)>;
1181
1182// zextload i1 -> zextload i8
1183def : ARMPat<(zextloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1184
1185// extload -> zextload
1186def : ARMPat<(extloadi1 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1187def : ARMPat<(extloadi8 addrmode2:$addr), (LDRB addrmode2:$addr)>;
1188def : ARMPat<(extloadi16 addrmode3:$addr), (LDRH addrmode3:$addr)>;
1189
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001190// smul* and smla*
1191def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra (shl GPR:$b, 16), 16)),
1192 (SMULBB GPR:$a, GPR:$b)>;
1193def : ARMV5TEPat<(mul sext_16_node:$a, sext_16_node:$b),
1194 (SMULBB GPR:$a, GPR:$b)>;
1195def : ARMV5TEPat<(mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16)),
1196 (SMULBT GPR:$a, GPR:$b)>;
1197def : ARMV5TEPat<(mul sext_16_node:$a, (sra GPR:$b, 16)),
1198 (SMULBT GPR:$a, GPR:$b)>;
1199def : ARMV5TEPat<(mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16)),
1200 (SMULTB GPR:$a, GPR:$b)>;
1201def : ARMV5TEPat<(mul (sra GPR:$a, 16), sext_16_node:$b),
1202 (SMULTB GPR:$a, GPR:$b)>;
1203def : ARMV5TEPat<(sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16),
1204 (SMULWB GPR:$a, GPR:$b)>;
1205def : ARMV5TEPat<(sra (mul GPR:$a, sext_16_node:$b), 16),
1206 (SMULWB GPR:$a, GPR:$b)>;
1207
1208def : ARMV5TEPat<(add GPR:$acc,
1209 (mul (sra (shl GPR:$a, 16), 16),
1210 (sra (shl GPR:$b, 16), 16))),
1211 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1212def : ARMV5TEPat<(add GPR:$acc,
1213 (mul sext_16_node:$a, sext_16_node:$b)),
1214 (SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
1215def : ARMV5TEPat<(add GPR:$acc,
1216 (mul (sra (shl GPR:$a, 16), 16), (sra GPR:$b, 16))),
1217 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1218def : ARMV5TEPat<(add GPR:$acc,
1219 (mul sext_16_node:$a, (sra GPR:$b, 16))),
1220 (SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
1221def : ARMV5TEPat<(add GPR:$acc,
1222 (mul (sra GPR:$a, 16), (sra (shl GPR:$b, 16), 16))),
1223 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1224def : ARMV5TEPat<(add GPR:$acc,
1225 (mul (sra GPR:$a, 16), sext_16_node:$b)),
1226 (SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
1227def : ARMV5TEPat<(add GPR:$acc,
1228 (sra (mul GPR:$a, (sra (shl GPR:$b, 16), 16)), 16)),
1229 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1230def : ARMV5TEPat<(add GPR:$acc,
1231 (sra (mul GPR:$a, sext_16_node:$b), 16)),
1232 (SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
1233
1234//===----------------------------------------------------------------------===//
1235// Thumb Support
1236//
1237
1238include "ARMInstrThumb.td"
1239
1240//===----------------------------------------------------------------------===//
1241// Floating Point Support
1242//
1243
1244include "ARMInstrVFP.td"