blob: 2bc71f873102c7316d63d13b84b6a9e1452a4911 [file] [log] [blame]
Anton Korobeynikovd4022c32009-05-29 23:41:08 +00001//===- ARMInstrThumb2.td - Thumb2 support for ARM -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb2 instruction set.
11//
12//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +000013
14// Shifted operands. No register controlled shifts for Thumb2.
15// Note: We do not support rrx shifted operands yet.
16def t2_so_reg : Operand<i32>, // reg imm
Evan Cheng9cb9e672009-06-27 02:26:13 +000017 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
Anton Korobeynikov52237112009-06-17 18:13:58 +000018 [shl,srl,sra,rotr]> {
Evan Cheng9cb9e672009-06-27 02:26:13 +000019 let PrintMethod = "printT2SOOperand";
Anton Korobeynikov52237112009-06-17 18:13:58 +000020 let MIOperandInfo = (ops GPR, i32imm);
21}
22
Evan Chengf49810c2009-06-23 17:48:47 +000023// t2_so_imm_XFORM - Return a t2_so_imm value packed into the format
24// described for t2_so_imm def below.
25def t2_so_imm_XFORM : SDNodeXForm<imm, [{
26 return CurDAG->getTargetConstant(
27 ARM_AM::getT2SOImmVal(N->getZExtValue()), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000028}]>;
29
Evan Chengf49810c2009-06-23 17:48:47 +000030// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
31def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
32 return CurDAG->getTargetConstant(
33 ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000034}]>;
35
Evan Chengf49810c2009-06-23 17:48:47 +000036// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
37def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
38 return CurDAG->getTargetConstant(
39 ARM_AM::getT2SOImmVal(-((int)N->getZExtValue())), MVT::i32);
40}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000041
Evan Chengf49810c2009-06-23 17:48:47 +000042// t2_so_imm - Match a 32-bit immediate operand, which is an
43// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
44// immediate splatted into multiple bytes of the word. t2_so_imm values are
45// represented in the imm field in the same 12-bit form that they are encoded
46// into t2_so_imm instructions: the 8-bit immediate is the least significant bits
47// [bits 0-7], the 4-bit shift/splat amount is the next 4 bits [bits 8-11].
48def t2_so_imm : Operand<i32>,
49 PatLeaf<(imm), [{
50 return ARM_AM::getT2SOImmVal((uint32_t)N->getZExtValue()) != -1;
51 }], t2_so_imm_XFORM> {
52 let PrintMethod = "printT2SOImmOperand";
53}
Anton Korobeynikov52237112009-06-17 18:13:58 +000054
Evan Chengf49810c2009-06-23 17:48:47 +000055// t2_so_imm_not - Match an immediate that is a complement
56// of a t2_so_imm.
57def t2_so_imm_not : Operand<i32>,
58 PatLeaf<(imm), [{
59 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
60 }], t2_so_imm_not_XFORM> {
61 let PrintMethod = "printT2SOImmOperand";
62}
63
64// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
65def t2_so_imm_neg : Operand<i32>,
66 PatLeaf<(imm), [{
67 return ARM_AM::getT2SOImmVal(-((int)N->getZExtValue())) != -1;
68 }], t2_so_imm_neg_XFORM> {
69 let PrintMethod = "printT2SOImmOperand";
70}
71
Evan Chenga67efd12009-06-23 19:39:13 +000072/// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
73def imm1_31 : PatLeaf<(i32 imm), [{
74 return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 32;
75}]>;
76
Evan Chengf49810c2009-06-23 17:48:47 +000077/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
78def imm0_4095 : PatLeaf<(i32 imm), [{
79 return (uint32_t)N->getZExtValue() < 4096;
80}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000081
82def imm0_4095_neg : PatLeaf<(i32 imm), [{
Evan Chengf49810c2009-06-23 17:48:47 +000083 return (uint32_t)(-N->getZExtValue()) < 4096;
Anton Korobeynikov52237112009-06-17 18:13:58 +000084}], imm_neg_XFORM>;
85
Evan Chengf49810c2009-06-23 17:48:47 +000086/// imm0_65535 predicate - True if the 32-bit immediate is in the range
87/// [0.65535].
88def imm0_65535 : PatLeaf<(i32 imm), [{
89 return (uint32_t)N->getZExtValue() < 65536;
Anton Korobeynikov52237112009-06-17 18:13:58 +000090}]>;
91
92
Evan Chengf49810c2009-06-23 17:48:47 +000093/// bf_inv_mask_imm predicate - An AND mask to clear an arbitrary width bitfield
94/// e.g., 0xf000ffff
95def bf_inv_mask_imm : Operand<i32>,
96 PatLeaf<(imm), [{
97 uint32_t v = (uint32_t)N->getZExtValue();
98 if (v == 0xffffffff)
99 return 0;
100 // naive checker. should do better, but simple is best for now since it's
101 // more likely to be correct.
102 while (v & 1) v >>= 1; // shift off the leading 1's
103 if (v)
104 {
105 while (!(v & 1)) v >>=1; // shift off the mask
106 while (v & 1) v >>= 1; // shift off the trailing 1's
107 }
108 // if this is a mask for clearing a bitfield, what's left should be zero.
109 return (v == 0);
110}] > {
111 let PrintMethod = "printBitfieldInvMaskImmOperand";
112}
113
114/// Split a 32-bit immediate into two 16 bit parts.
115def t2_lo16 : SDNodeXForm<imm, [{
116 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() & 0xffff,
117 MVT::i32);
118}]>;
119
120def t2_hi16 : SDNodeXForm<imm, [{
121 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
122}]>;
123
124def t2_lo16AllZero : PatLeaf<(i32 imm), [{
125 // Returns true if all low 16-bits are 0.
126 return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
127 }], t2_hi16>;
128
Evan Cheng9cb9e672009-06-27 02:26:13 +0000129
Evan Cheng055b0312009-06-29 07:51:04 +0000130// Define Thumb2 specific addressing modes.
131
132// t2addrmode_imm12 := reg + imm12
133def t2addrmode_imm12 : Operand<i32>,
134 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
135 let PrintMethod = "printT2AddrModeImm12Operand";
136 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
137}
138
Evan Chengf3c21b82009-06-30 02:15:48 +0000139// t2addrmode_imm8 := reg - imm8 (also reg + imm8 for some instructions)
Evan Cheng055b0312009-06-29 07:51:04 +0000140def t2addrmode_imm8 : Operand<i32>,
141 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
142 let PrintMethod = "printT2AddrModeImm8Operand";
143 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
144}
145
David Goodwin6647cea2009-06-30 22:50:01 +0000146// t2addrmode_imm8s4 := reg + (imm8 << 2)
147def t2addrmode_imm8s4 : Operand<i32>,
148 ComplexPattern<i32, 2, "SelectT2AddrModeImm8s4", []> {
149 let PrintMethod = "printT2AddrModeImm8Operand";
150 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
151}
152
Evan Cheng055b0312009-06-29 07:51:04 +0000153// t2addrmode_so_reg := reg + reg << imm2
154def t2addrmode_so_reg : Operand<i32>,
155 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
156 let PrintMethod = "printT2AddrModeSoRegOperand";
157 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
158}
159
160
Anton Korobeynikov52237112009-06-17 18:13:58 +0000161//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000162// Multiclass helpers...
Anton Korobeynikov52237112009-06-17 18:13:58 +0000163//
164
Evan Chenga67efd12009-06-23 19:39:13 +0000165/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000166/// unary operation that produces a value. These are predicable and can be
167/// changed to modify CPSR.
Evan Chenga67efd12009-06-23 19:39:13 +0000168multiclass T2I_un_irs<string opc, PatFrag opnode, bit Cheap = 0, bit ReMat = 0>{
169 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000170 def i : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
171 opc, " $dst, $src",
Evan Chenga67efd12009-06-23 19:39:13 +0000172 [(set GPR:$dst, (opnode t2_so_imm:$src))]> {
173 let isAsCheapAsAMove = Cheap;
174 let isReMaterializable = ReMat;
175 }
176 // register
177 def r : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000178 opc, " $dst, $src",
Evan Chenga67efd12009-06-23 19:39:13 +0000179 [(set GPR:$dst, (opnode GPR:$src))]>;
180 // shifted register
181 def s : T2I<(outs GPR:$dst), (ins t2_so_reg:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000182 opc, " $dst, $src",
183 [(set GPR:$dst, (opnode t2_so_reg:$src))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000184}
185
186/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000187// binary operation that produces a value. These are predicable and can be
188/// changed to modify CPSR.
Evan Cheng8de898a2009-06-26 00:19:44 +0000189multiclass T2I_bin_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000190 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000191 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
192 opc, " $dst, $lhs, $rhs",
193 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000194 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000195 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
196 opc, " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000197 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
198 let isCommutable = Commutable;
199 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000200 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000201 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
202 opc, " $dst, $lhs, $rhs",
203 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000204}
205
Evan Cheng1e249e32009-06-25 20:59:23 +0000206/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
207/// reversed. It doesn't define the 'rr' form since it's handled by its
208/// T2I_bin_irs counterpart.
209multiclass T2I_rbin_is<string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000210 // shifted imm
211 def ri : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000212 opc, " $dst, $rhs, $lhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000213 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
214 // shifted register
215 def rs : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000216 opc, " $dst, $rhs, $lhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000217 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
218}
219
Evan Chenga67efd12009-06-23 19:39:13 +0000220/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000221/// instruction modifies the CPSR register.
222let Defs = [CPSR] in {
Evan Cheng8de898a2009-06-26 00:19:44 +0000223multiclass T2I_bin_s_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000224 // shifted imm
Evan Chengf49810c2009-06-23 17:48:47 +0000225 def ri : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000226 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000227 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000228 // register
229 def rr : T2I<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000230 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000231 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
232 let isCommutable = Commutable;
233 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000234 // shifted register
Evan Chengf49810c2009-06-23 17:48:47 +0000235 def rs : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000236 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000237 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000238}
239}
240
Evan Chenga67efd12009-06-23 19:39:13 +0000241/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
242/// patterns for a binary operation that produces a value.
Evan Cheng8de898a2009-06-26 00:19:44 +0000243multiclass T2I_bin_ii12rs<string opc, PatFrag opnode, bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000244 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000245 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
246 opc, " $dst, $lhs, $rhs",
247 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000248 // 12-bit imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000249 def ri12 : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
250 !strconcat(opc, "w"), " $dst, $lhs, $rhs",
251 [(set GPR:$dst, (opnode GPR:$lhs, imm0_4095:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000252 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000253 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
254 opc, " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000255 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
256 let isCommutable = Commutable;
257 }
Evan Chengf49810c2009-06-23 17:48:47 +0000258 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000259 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
260 opc, " $dst, $lhs, $rhs",
261 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000262}
263
Evan Cheng62674222009-06-25 23:34:10 +0000264/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng1e249e32009-06-25 20:59:23 +0000265/// binary operation that produces a value and use and define the carry bit.
266/// It's not predicable.
Evan Cheng62674222009-06-25 23:34:10 +0000267let Uses = [CPSR] in {
Evan Cheng8de898a2009-06-26 00:19:44 +0000268multiclass T2I_adde_sube_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000269 // shifted imm
Evan Cheng62674222009-06-25 23:34:10 +0000270 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000271 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000272 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
273 Requires<[IsThumb, HasThumb2, CarryDefIsUnused]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000274 // register
Evan Cheng62674222009-06-25 23:34:10 +0000275 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000276 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000277 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
Evan Cheng8de898a2009-06-26 00:19:44 +0000278 Requires<[IsThumb, HasThumb2, CarryDefIsUnused]> {
279 let isCommutable = Commutable;
280 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000281 // shifted register
Evan Cheng62674222009-06-25 23:34:10 +0000282 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000283 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000284 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
285 Requires<[IsThumb, HasThumb2, CarryDefIsUnused]>;
286 // Carry setting variants
287 // shifted imm
288 def Sri : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
289 !strconcat(opc, "s $dst, $lhs, $rhs"),
290 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
291 Requires<[IsThumb, HasThumb2, CarryDefIsUsed]> {
292 let Defs = [CPSR];
293 }
294 // register
295 def Srr : T2XI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
296 !strconcat(opc, "s $dst, $lhs, $rhs"),
297 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
298 Requires<[IsThumb, HasThumb2, CarryDefIsUsed]> {
299 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000300 let isCommutable = Commutable;
301 }
Evan Cheng62674222009-06-25 23:34:10 +0000302 // shifted register
303 def Srs : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
304 !strconcat(opc, "s $dst, $lhs, $rhs"),
305 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
306 Requires<[IsThumb, HasThumb2, CarryDefIsUsed]> {
307 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000308 }
Evan Chengf49810c2009-06-23 17:48:47 +0000309}
310}
311
Evan Cheng62674222009-06-25 23:34:10 +0000312/// T2I_rsc_is - Same as T2I_adde_sube_irs except the order of operands are
Evan Cheng1e249e32009-06-25 20:59:23 +0000313/// reversed. It doesn't define the 'rr' form since it's handled by its
Evan Cheng62674222009-06-25 23:34:10 +0000314/// T2I_adde_sube_irs counterpart.
Evan Cheng1e249e32009-06-25 20:59:23 +0000315let Defs = [CPSR], Uses = [CPSR] in {
Evan Cheng62674222009-06-25 23:34:10 +0000316multiclass T2I_rsc_is<string opc, PatFrag opnode> {
Evan Cheng1e249e32009-06-25 20:59:23 +0000317 // shifted imm
Evan Cheng62674222009-06-25 23:34:10 +0000318 def ri : T2sI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
319 opc, " $dst, $rhs, $lhs",
320 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>,
321 Requires<[IsThumb, HasThumb2, CarryDefIsUnused]>;
Evan Cheng1e249e32009-06-25 20:59:23 +0000322 // shifted register
Evan Cheng62674222009-06-25 23:34:10 +0000323 def rs : T2sI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
324 opc, " $dst, $rhs, $lhs",
325 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>,
326 Requires<[IsThumb, HasThumb2, CarryDefIsUnused]>;
327 // shifted imm
328 def Sri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
Evan Cheng1e249e32009-06-25 20:59:23 +0000329 !strconcat(opc, "s $dst, $rhs, $lhs"),
Evan Cheng62674222009-06-25 23:34:10 +0000330 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>,
331 Requires<[IsThumb, HasThumb2, CarryDefIsUsed]> {
332 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000333 }
Evan Cheng62674222009-06-25 23:34:10 +0000334 // shifted register
335 def Srs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
336 !strconcat(opc, "s $dst, $rhs, $lhs"),
337 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>,
338 Requires<[IsThumb, HasThumb2, CarryDefIsUsed]> {
339 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000340 }
Evan Cheng1e249e32009-06-25 20:59:23 +0000341}
342}
343
344/// T2I_rbin_s_is - Same as T2I_bin_s_irs except the order of operands are
345/// reversed. It doesn't define the 'rr' form since it's handled by its
346/// T2I_bin_s_irs counterpart.
347let Defs = [CPSR] in {
348multiclass T2I_rbin_s_is<string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000349 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000350 def ri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs, cc_out:$s),
351 !strconcat(opc, "${s} $dst, $rhs, $lhs"),
352 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000353 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000354 def rs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs, cc_out:$s),
355 !strconcat(opc, "${s} $dst, $rhs, $lhs"),
356 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000357}
358}
359
Evan Chenga67efd12009-06-23 19:39:13 +0000360/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
361// rotate operation that produces a value.
362multiclass T2I_sh_ir<string opc, PatFrag opnode> {
363 // 5-bit imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000364 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
365 opc, " $dst, $lhs, $rhs",
366 [(set GPR:$dst, (opnode GPR:$lhs, imm1_31:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000367 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000368 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
369 opc, " $dst, $lhs, $rhs",
370 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000371}
Evan Chengf49810c2009-06-23 17:48:47 +0000372
Evan Chenga67efd12009-06-23 19:39:13 +0000373/// T21_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
374/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000375/// a explicit result, only implicitly set CPSR.
376let Uses = [CPSR] in {
377multiclass T2I_cmp_is<string opc, PatFrag opnode> {
378 // shifted imm
379 def ri : T2I<(outs), (ins GPR:$lhs, t2_so_imm:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000380 opc, " $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000381 [(opnode GPR:$lhs, t2_so_imm:$rhs)]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000382 // register
383 def rr : T2I<(outs), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000384 opc, " $lhs, $rhs",
Evan Chenga67efd12009-06-23 19:39:13 +0000385 [(opnode GPR:$lhs, GPR:$rhs)]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000386 // shifted register
387 def rs : T2I<(outs), (ins GPR:$lhs, t2_so_reg:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000388 opc, " $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000389 [(opnode GPR:$lhs, t2_so_reg:$rhs)]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000390}
391}
392
Evan Chengf3c21b82009-06-30 02:15:48 +0000393/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
394multiclass T2I_ld<string opc, PatFrag opnode> {
395 def i12 : T2Ii12<(outs GPR:$dst), (ins t2addrmode_imm12:$addr),
396 opc, " $dst, $addr",
397 [(set GPR:$dst, (opnode t2addrmode_imm12:$addr))]>;
398 def i8 : T2Ii8 <(outs GPR:$dst), (ins t2addrmode_imm8:$addr),
399 opc, " $dst, $addr",
400 [(set GPR:$dst, (opnode t2addrmode_imm8:$addr))]>;
401 def s : T2Iso <(outs GPR:$dst), (ins t2addrmode_so_reg:$addr),
402 opc, " $dst, $addr",
403 [(set GPR:$dst, (opnode t2addrmode_so_reg:$addr))]>;
404 def pci : T2Ipc <(outs GPR:$dst), (ins i32imm:$addr),
405 opc, " $dst, $addr",
406 [(set GPR:$dst, (opnode (ARMWrapper tconstpool:$addr)))]>;
407}
408
David Goodwin73b8f162009-06-30 22:11:34 +0000409/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
410multiclass T2I_st<string opc, PatFrag opnode> {
411 def i12 : T2Ii12<(outs), (ins GPR:$src, t2addrmode_imm12:$addr),
412 opc, " $src, $addr",
413 [(opnode GPR:$src, t2addrmode_imm12:$addr)]>;
414 def i8 : T2Ii8 <(outs), (ins GPR:$src, t2addrmode_imm8:$addr),
415 opc, " $src, $addr",
416 [(opnode GPR:$src, t2addrmode_imm8:$addr)]>;
417 def s : T2Iso <(outs), (ins GPR:$src, t2addrmode_so_reg:$addr),
418 opc, " $src, $addr",
419 [(opnode GPR:$src, t2addrmode_so_reg:$addr)]>;
420}
421
Anton Korobeynikov52237112009-06-17 18:13:58 +0000422//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000423// Instructions
424//===----------------------------------------------------------------------===//
425
426//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +0000427// Miscellaneous Instructions.
428//
429
430let isNotDuplicable = 1 in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000431def t2PICADD : T2XI<(outs tGPR:$dst), (ins tGPR:$lhs, pclabel:$cp),
432 "$cp:\n\tadd $dst, pc",
433 [(set tGPR:$dst, (ARMpic_add tGPR:$lhs, imm:$cp))]>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000434
435
436// LEApcrel - Load a pc-relative address into a register without offending the
437// assembler.
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000438def t2LEApcrel : T2XI<(outs GPR:$dst), (ins i32imm:$label, pred:$p),
Evan Chenga09b9ca2009-06-24 23:47:58 +0000439 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
440 "${:private}PCRELL${:uid}+8))\n"),
441 !strconcat("${:private}PCRELL${:uid}:\n\t",
442 "add$p $dst, pc, #PCRELV${:uid}")),
443 []>;
444
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000445def t2LEApcrelJT : T2XI<(outs GPR:$dst),
Evan Chenga09b9ca2009-06-24 23:47:58 +0000446 (ins i32imm:$label, i32imm:$id, pred:$p),
447 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
448 "${:private}PCRELL${:uid}+8))\n"),
449 !strconcat("${:private}PCRELL${:uid}:\n\t",
450 "add$p $dst, pc, #PCRELV${:uid}")),
451 []>;
452
Evan Chengb6c29d52009-06-25 01:21:30 +0000453// ADD rd, sp, #so_imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000454def t2ADDrSPi : T2XI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
455 "add $dst, $sp, $imm",
456 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000457
458// ADD rd, sp, #imm12
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000459def t2ADDrSPi12 : T2XI<(outs GPR:$dst), (ins GPR:$sp, i32imm:$imm),
460 "addw $dst, $sp, $imm",
461 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000462
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000463def t2ADDrSPs : T2XI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
464 "addw $dst, $sp, $rhs",
465 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000466
467
Evan Chenga09b9ca2009-06-24 23:47:58 +0000468//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000469// Load / store Instructions.
470//
471
Evan Cheng055b0312009-06-29 07:51:04 +0000472// Load
Evan Chengf3c21b82009-06-30 02:15:48 +0000473let canFoldAsLoad = 1 in
474defm t2LDR : T2I_ld<"ldr", UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000475
Evan Chengf3c21b82009-06-30 02:15:48 +0000476// Loads with zero extension
477defm t2LDRH : T2I_ld<"ldrh", UnOpFrag<(zextloadi16 node:$Src)>>;
478defm t2LDRB : T2I_ld<"ldrb", UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000479
Evan Chengf3c21b82009-06-30 02:15:48 +0000480// Loads with sign extension
481defm t2LDRSH : T2I_ld<"ldrsh", UnOpFrag<(sextloadi16 node:$Src)>>;
482defm t2LDRSB : T2I_ld<"ldrsb", UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000483
Evan Chengf3c21b82009-06-30 02:15:48 +0000484let mayLoad = 1 in {
485// Load doubleword
David Goodwin6647cea2009-06-30 22:50:01 +0000486def t2LDRDi8 : T2Ii8s4<(outs GPR:$dst), (ins t2addrmode_imm8s4:$addr),
Evan Chengf3c21b82009-06-30 02:15:48 +0000487 "ldrd", " $dst, $addr", []>;
488def t2LDRDpci : T2Ii8s4<(outs GPR:$dst), (ins i32imm:$addr),
489 "ldrd", " $dst, $addr", []>;
490}
491
492// zextload i1 -> zextload i8
493def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
494 (t2LDRBi12 t2addrmode_imm12:$addr)>;
495def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
496 (t2LDRBi8 t2addrmode_imm8:$addr)>;
497def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
498 (t2LDRBs t2addrmode_so_reg:$addr)>;
499def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
500 (t2LDRBpci tconstpool:$addr)>;
501
502// extload -> zextload
503// FIXME: Reduce the number of patterns by legalizing extload to zextload
504// earlier?
505def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
506 (t2LDRBi12 t2addrmode_imm12:$addr)>;
507def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
508 (t2LDRBi8 t2addrmode_imm8:$addr)>;
509def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
510 (t2LDRBs t2addrmode_so_reg:$addr)>;
511def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
512 (t2LDRBpci tconstpool:$addr)>;
513
514def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
515 (t2LDRBi12 t2addrmode_imm12:$addr)>;
516def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
517 (t2LDRBi8 t2addrmode_imm8:$addr)>;
518def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
519 (t2LDRBs t2addrmode_so_reg:$addr)>;
520def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
521 (t2LDRBpci tconstpool:$addr)>;
522
523def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
524 (t2LDRHi12 t2addrmode_imm12:$addr)>;
525def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
526 (t2LDRHi8 t2addrmode_imm8:$addr)>;
527def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
528 (t2LDRHs t2addrmode_so_reg:$addr)>;
529def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
530 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +0000531
David Goodwin73b8f162009-06-30 22:11:34 +0000532// Store
533defm t2STR : T2I_st<"str", BinOpFrag<(store node:$LHS, node:$RHS)>>;
534defm t2STRB : T2I_st<"strb", BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
535defm t2STRH : T2I_st<"strh", BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
536
David Goodwin6647cea2009-06-30 22:50:01 +0000537// Store doubleword
538let mayLoad = 1 in
539def t2STRDi8 : T2Ii8s4<(outs), (ins GPR:$src, t2addrmode_imm8s4:$addr),
540 "strd", " $src, $addr", []>;
541
Evan Cheng9cb9e672009-06-27 02:26:13 +0000542//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000543// Move Instructions.
544//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000545
Evan Chengf49810c2009-06-23 17:48:47 +0000546let neverHasSideEffects = 1 in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000547def t2MOVr : T2sI<(outs GPR:$dst), (ins GPR:$src),
548 "mov", " $dst, $src", []>;
Evan Chengf49810c2009-06-23 17:48:47 +0000549
Evan Chenga67efd12009-06-23 19:39:13 +0000550let isReMaterializable = 1, isAsCheapAsAMove = 1 in
David Goodwin83b35932009-06-26 16:10:07 +0000551def t2MOVi : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
552 "mov", " $dst, $src",
553 [(set GPR:$dst, t2_so_imm:$src)]>;
554
555let isReMaterializable = 1, isAsCheapAsAMove = 1 in
556def t2MOVi16 : T2I<(outs GPR:$dst), (ins i32imm:$src),
557 "movw", " $dst, $src",
558 [(set GPR:$dst, imm0_65535:$src)]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000559
Evan Chengf49810c2009-06-23 17:48:47 +0000560// FIXME: Also available in ARM mode.
Evan Cheng3850a6a2009-06-23 05:23:49 +0000561let Constraints = "$src = $dst" in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000562def t2MOVTi16 : T2sI<(outs GPR:$dst), (ins GPR:$src, i32imm:$imm),
563 "movt", " $dst, $imm",
564 [(set GPR:$dst,
565 (or (and GPR:$src, 0xffff), t2_lo16AllZero:$imm))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000566
567//===----------------------------------------------------------------------===//
568// Arithmetic Instructions.
569//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000570
Evan Cheng8de898a2009-06-26 00:19:44 +0000571defm t2ADD : T2I_bin_ii12rs<"add", BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
Evan Chenga67efd12009-06-23 19:39:13 +0000572defm t2SUB : T2I_bin_ii12rs<"sub", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000573
Evan Chengf49810c2009-06-23 17:48:47 +0000574// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Evan Cheng8de898a2009-06-26 00:19:44 +0000575defm t2ADDS : T2I_bin_s_irs <"add", BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
Evan Cheng1e249e32009-06-25 20:59:23 +0000576defm t2SUBS : T2I_bin_s_irs <"sub", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000577
Evan Cheng8de898a2009-06-26 00:19:44 +0000578defm t2ADC : T2I_adde_sube_irs<"adc",BinOpFrag<(adde node:$LHS, node:$RHS)>,1>;
579defm t2SBC : T2I_adde_sube_irs<"sbc",BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000580
581// RSB, RSC
Evan Cheng1e249e32009-06-25 20:59:23 +0000582defm t2RSB : T2I_rbin_is <"rsb", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
583defm t2RSBS : T2I_rbin_s_is <"rsb", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Evan Cheng62674222009-06-25 23:34:10 +0000584defm t2RSC : T2I_rsc_is <"rsc", BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000585
586// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Evan Cheng9cb9e672009-06-27 02:26:13 +0000587def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
588 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
589def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
590 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000591
592
Evan Chengf49810c2009-06-23 17:48:47 +0000593//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +0000594// Shift and rotate Instructions.
595//
596
597defm t2LSL : T2I_sh_ir<"lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
598defm t2LSR : T2I_sh_ir<"lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
599defm t2ASR : T2I_sh_ir<"asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
600defm t2ROR : T2I_sh_ir<"ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
601
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000602def t2MOVrx : T2sI<(outs GPR:$dst), (ins GPR:$src),
603 "mov", " $dst, $src, rrx",
604 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000605
606//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +0000607// Bitwise Instructions.
608//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000609
Evan Cheng8de898a2009-06-26 00:19:44 +0000610defm t2AND : T2I_bin_irs<"and", BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
611defm t2ORR : T2I_bin_irs<"orr", BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
612defm t2EOR : T2I_bin_irs<"eor", BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +0000613
Evan Chenga67efd12009-06-23 19:39:13 +0000614defm t2BIC : T2I_bin_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000615
Evan Cheng9cb9e672009-06-27 02:26:13 +0000616def : T2Pat<(and GPR:$src, t2_so_imm_not:$imm),
617 (t2BICri GPR:$src, t2_so_imm_not:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000618
Evan Chenga67efd12009-06-23 19:39:13 +0000619defm t2ORN : T2I_bin_irs<"orn", BinOpFrag<(or node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000620
Evan Cheng9cb9e672009-06-27 02:26:13 +0000621def : T2Pat<(or GPR:$src, t2_so_imm_not:$imm),
622 (t2ORNri GPR:$src, t2_so_imm_not:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000623
David Goodwindcdaebc2009-06-26 23:13:13 +0000624// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
625let AddedComplexity = 1 in
Evan Chenga67efd12009-06-23 19:39:13 +0000626defm t2MVN : T2I_un_irs <"mvn", UnOpFrag<(not node:$Src)>, 1, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +0000627
Evan Cheng9cb9e672009-06-27 02:26:13 +0000628def : T2Pat<(t2_so_imm_not:$src),
629 (t2MVNi t2_so_imm_not:$src)>;
David Goodwin0919a912009-06-25 23:11:21 +0000630
Evan Chengf49810c2009-06-23 17:48:47 +0000631// A8.6.17 BFC - Bitfield clear
632// FIXME: Also available in ARM mode.
633let Constraints = "$src = $dst" in
634def t2BFC : T2I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000635 "bfc", " $dst, $imm",
Evan Chengf49810c2009-06-23 17:48:47 +0000636 [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>;
637
638// FIXME: A8.6.18 BFI - Bitfield insert (Encoding T1)
639
640//===----------------------------------------------------------------------===//
641// Multiply Instructions.
642//
Evan Cheng8de898a2009-06-26 00:19:44 +0000643let isCommutable = 1 in
Evan Chengf49810c2009-06-23 17:48:47 +0000644def t2MUL: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000645 "mul", " $dst, $a, $b",
Evan Chengf49810c2009-06-23 17:48:47 +0000646 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
647
648def t2MLA: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000649 "mla", " $dst, $a, $b, $c",
Evan Chengf49810c2009-06-23 17:48:47 +0000650 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
651
652def t2MLS: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000653 "mls", " $dst, $a, $b, $c",
Evan Chengf49810c2009-06-23 17:48:47 +0000654 [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>;
655
656// FIXME: SMULL, etc.
657
658//===----------------------------------------------------------------------===//
659// Misc. Arithmetic Instructions.
660//
661
Evan Chengf49810c2009-06-23 17:48:47 +0000662def t2CLZ : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000663 "clz", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000664 [(set GPR:$dst, (ctlz GPR:$src))]>;
665
666def t2REV : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000667 "rev", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000668 [(set GPR:$dst, (bswap GPR:$src))]>;
669
670def t2REV16 : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000671 "rev16", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000672 [(set GPR:$dst,
673 (or (and (srl GPR:$src, (i32 8)), 0xFF),
674 (or (and (shl GPR:$src, (i32 8)), 0xFF00),
675 (or (and (srl GPR:$src, (i32 8)), 0xFF0000),
676 (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>;
677
678/////
679/// A8.6.137 REVSH
680/////
681def t2REVSH : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000682 "revsh", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000683 [(set GPR:$dst,
684 (sext_inreg
685 (or (srl (and GPR:$src, 0xFFFF), (i32 8)),
686 (shl GPR:$src, (i32 8))), i16))]>;
687
688// FIXME: PKHxx etc.
689
690//===----------------------------------------------------------------------===//
691// Comparison Instructions...
692//
693
694defm t2CMP : T2I_cmp_is<"cmp",
695 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
David Goodwinc0309b42009-06-29 15:33:01 +0000696defm t2CMPz : T2I_cmp_is<"cmp",
697 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000698
699defm t2CMN : T2I_cmp_is<"cmn",
700 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
David Goodwinc0309b42009-06-29 15:33:01 +0000701defm t2CMNz : T2I_cmp_is<"cmn",
702 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000703
Evan Cheng9cb9e672009-06-27 02:26:13 +0000704def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
705 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000706
David Goodwinc0309b42009-06-29 15:33:01 +0000707def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
Evan Cheng9cb9e672009-06-27 02:26:13 +0000708 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000709
David Goodwinbaeb9112009-06-29 22:49:42 +0000710defm t2TST : T2I_cmp_is<"tst",
711 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>>;
712defm t2TEQ : T2I_cmp_is<"teq",
713 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000714
715// A8.6.27 CBNZ, CBZ - Compare and branch on (non)zero.
716// Short range conditional branch. Looks awesome for loops. Need to figure
717// out how to use this one.
718
719// FIXME: Conditional moves
720
David Goodwin5e47a9a2009-06-30 18:04:13 +0000721//===----------------------------------------------------------------------===//
722// Control-Flow Instructions
723//
724
725let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
726let isPredicable = 1 in
727def t2B : T2XI<(outs), (ins brtarget:$target),
728 "b $target",
729 [(br bb:$target)]>;
730
David Goodwinc9a59b52009-06-30 19:50:22 +0000731let isNotDuplicable = 1, isIndirectBranch = 1 in {
732def t2BR_JTr : T2JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
733 "mov pc, $target \n$jt",
734 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
735
736def t2BR_JTm :
737 T2JTI<(outs),
738 (ins t2addrmode_so_reg:$target, jtblock_operand:$jt, i32imm:$id),
739 "ldr pc, $target \n$jt",
740 [(ARMbrjt (i32 (load t2addrmode_so_reg:$target)), tjumptable:$jt,
741 imm:$id)]>;
742
743def t2BR_JTadd :
744 T2JTI<(outs),
745 (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
746 "add pc, $target, $idx \n$jt",
747 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt, imm:$id)]>;
748} // isNotDuplicate, isIndirectBranch
749} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +0000750
751// FIXME: should be able to write a pattern for ARMBrcond, but can't use
752// a two-value operand where a dag node expects two operands. :(
753let isBranch = 1, isTerminator = 1 in
754def t2Bcc : T2I<(outs), (ins brtarget:$target),
755 "b", " $target",
756 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000757
758//===----------------------------------------------------------------------===//
759// Non-Instruction Patterns
760//
761
Evan Chenga09b9ca2009-06-24 23:47:58 +0000762// ConstantPool, GlobalAddress, and JumpTable
Evan Cheng9cb9e672009-06-27 02:26:13 +0000763def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>;
764def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
765def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
766 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000767
Evan Chengf49810c2009-06-23 17:48:47 +0000768// Large immediate handling.
769
Evan Cheng9cb9e672009-06-27 02:26:13 +0000770def : T2Pat<(i32 imm:$src),
771 (t2MOVTi16 (t2MOVi16 (t2_lo16 imm:$src)), (t2_hi16 imm:$src))>;