blob: 548c793819b77e877ef9442630fd76ca93341210 [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
Evan Cheng06e16582009-07-10 01:54:42 +000014// IT block predicate field
15def it_pred : Operand<i32> {
16 let PrintMethod = "printPredicateOperand";
17}
18
19// IT block condition mask
20def it_mask : Operand<i32> {
21 let PrintMethod = "printThumbITMask";
22}
23
Anton Korobeynikov52237112009-06-17 18:13:58 +000024// Shifted operands. No register controlled shifts for Thumb2.
25// Note: We do not support rrx shifted operands yet.
26def t2_so_reg : Operand<i32>, // reg imm
Evan Cheng9cb9e672009-06-27 02:26:13 +000027 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
Anton Korobeynikov52237112009-06-17 18:13:58 +000028 [shl,srl,sra,rotr]> {
Evan Cheng9cb9e672009-06-27 02:26:13 +000029 let PrintMethod = "printT2SOOperand";
Anton Korobeynikov52237112009-06-17 18:13:58 +000030 let MIOperandInfo = (ops GPR, i32imm);
31}
32
Evan Chengf49810c2009-06-23 17:48:47 +000033// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
34def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
Evan Chenge7cbe412009-07-08 21:03:57 +000035 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000036}]>;
37
Evan Chengf49810c2009-06-23 17:48:47 +000038// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
39def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
Evan Chenge7cbe412009-07-08 21:03:57 +000040 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
Evan Chengf49810c2009-06-23 17:48:47 +000041}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000042
Evan Chengf49810c2009-06-23 17:48:47 +000043// t2_so_imm - Match a 32-bit immediate operand, which is an
44// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
45// immediate splatted into multiple bytes of the word. t2_so_imm values are
46// represented in the imm field in the same 12-bit form that they are encoded
47// into t2_so_imm instructions: the 8-bit immediate is the least significant bits
48// [bits 0-7], the 4-bit shift/splat amount is the next 4 bits [bits 8-11].
49def t2_so_imm : Operand<i32>,
50 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000051 return ARM_AM::getT2SOImmVal((uint32_t)N->getZExtValue()) != -1;
52}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000053
Evan Chengf49810c2009-06-23 17:48:47 +000054// t2_so_imm_not - Match an immediate that is a complement
55// of a t2_so_imm.
56def t2_so_imm_not : Operand<i32>,
57 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000058 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
59}], t2_so_imm_not_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000060
61// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
62def t2_so_imm_neg : Operand<i32>,
63 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000064 return ARM_AM::getT2SOImmVal(-((int)N->getZExtValue())) != -1;
65}], t2_so_imm_neg_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000066
Evan Chenga67efd12009-06-23 19:39:13 +000067/// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
68def imm1_31 : PatLeaf<(i32 imm), [{
69 return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 32;
70}]>;
71
Evan Chengf49810c2009-06-23 17:48:47 +000072/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
73def imm0_4095 : PatLeaf<(i32 imm), [{
74 return (uint32_t)N->getZExtValue() < 4096;
75}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000076
77def imm0_4095_neg : PatLeaf<(i32 imm), [{
Evan Chengf49810c2009-06-23 17:48:47 +000078 return (uint32_t)(-N->getZExtValue()) < 4096;
Anton Korobeynikov52237112009-06-17 18:13:58 +000079}], imm_neg_XFORM>;
80
Evan Chengf49810c2009-06-23 17:48:47 +000081/// imm0_65535 predicate - True if the 32-bit immediate is in the range
82/// [0.65535].
83def imm0_65535 : PatLeaf<(i32 imm), [{
84 return (uint32_t)N->getZExtValue() < 65536;
Anton Korobeynikov52237112009-06-17 18:13:58 +000085}]>;
86
Evan Chengf49810c2009-06-23 17:48:47 +000087/// Split a 32-bit immediate into two 16 bit parts.
88def t2_lo16 : SDNodeXForm<imm, [{
89 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() & 0xffff,
90 MVT::i32);
91}]>;
92
93def t2_hi16 : SDNodeXForm<imm, [{
94 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
95}]>;
96
97def t2_lo16AllZero : PatLeaf<(i32 imm), [{
98 // Returns true if all low 16-bits are 0.
99 return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
100 }], t2_hi16>;
101
Evan Cheng9cb9e672009-06-27 02:26:13 +0000102
Evan Cheng055b0312009-06-29 07:51:04 +0000103// Define Thumb2 specific addressing modes.
104
105// t2addrmode_imm12 := reg + imm12
106def t2addrmode_imm12 : Operand<i32>,
107 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
108 let PrintMethod = "printT2AddrModeImm12Operand";
109 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
110}
111
David Goodwin5ff58b52009-07-24 00:16:18 +0000112// t2addrmode_imm8 := reg - imm8
Evan Cheng055b0312009-06-29 07:51:04 +0000113def t2addrmode_imm8 : Operand<i32>,
114 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
115 let PrintMethod = "printT2AddrModeImm8Operand";
116 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
117}
118
Evan Cheng6d94f112009-07-03 00:06:39 +0000119def t2am_imm8_offset : Operand<i32>,
120 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset", []>{
Evan Chenge88d5ce2009-07-02 07:28:31 +0000121 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
122}
123
Evan Cheng5c874172009-07-09 22:21:59 +0000124// t2addrmode_imm8s4 := reg +/- (imm8 << 2)
David Goodwin6647cea2009-06-30 22:50:01 +0000125def t2addrmode_imm8s4 : Operand<i32>,
126 ComplexPattern<i32, 2, "SelectT2AddrModeImm8s4", []> {
Evan Cheng5c874172009-07-09 22:21:59 +0000127 let PrintMethod = "printT2AddrModeImm8s4Operand";
David Goodwin6647cea2009-06-30 22:50:01 +0000128 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
129}
130
Evan Chengcba962d2009-07-09 20:40:44 +0000131// t2addrmode_so_reg := reg + (reg << imm2)
Evan Cheng055b0312009-06-29 07:51:04 +0000132def t2addrmode_so_reg : Operand<i32>,
133 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
134 let PrintMethod = "printT2AddrModeSoRegOperand";
135 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
136}
137
138
Anton Korobeynikov52237112009-06-17 18:13:58 +0000139//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000140// Multiclass helpers...
Anton Korobeynikov52237112009-06-17 18:13:58 +0000141//
142
Evan Chenga67efd12009-06-23 19:39:13 +0000143/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000144/// unary operation that produces a value. These are predicable and can be
145/// changed to modify CPSR.
Evan Chenga67efd12009-06-23 19:39:13 +0000146multiclass T2I_un_irs<string opc, PatFrag opnode, bit Cheap = 0, bit ReMat = 0>{
147 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000148 def i : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
149 opc, " $dst, $src",
Evan Chenga67efd12009-06-23 19:39:13 +0000150 [(set GPR:$dst, (opnode t2_so_imm:$src))]> {
151 let isAsCheapAsAMove = Cheap;
152 let isReMaterializable = ReMat;
153 }
154 // register
155 def r : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000156 opc, " $dst, $src",
Evan Chenga67efd12009-06-23 19:39:13 +0000157 [(set GPR:$dst, (opnode GPR:$src))]>;
158 // shifted register
159 def s : T2I<(outs GPR:$dst), (ins t2_so_reg:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000160 opc, " $dst, $src",
161 [(set GPR:$dst, (opnode t2_so_reg:$src))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000162}
163
164/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000165// binary operation that produces a value. These are predicable and can be
166/// changed to modify CPSR.
Evan Cheng8de898a2009-06-26 00:19:44 +0000167multiclass T2I_bin_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000168 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000169 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
170 opc, " $dst, $lhs, $rhs",
171 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000172 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000173 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
174 opc, " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000175 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
176 let isCommutable = Commutable;
177 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000178 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000179 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
180 opc, " $dst, $lhs, $rhs",
181 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000182}
183
Evan Cheng1e249e32009-06-25 20:59:23 +0000184/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
185/// reversed. It doesn't define the 'rr' form since it's handled by its
186/// T2I_bin_irs counterpart.
187multiclass T2I_rbin_is<string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000188 // shifted imm
189 def ri : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000190 opc, " $dst, $rhs, $lhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000191 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
192 // shifted register
193 def rs : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000194 opc, " $dst, $rhs, $lhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000195 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
196}
197
Evan Chenga67efd12009-06-23 19:39:13 +0000198/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000199/// instruction modifies the CPSR register.
200let Defs = [CPSR] in {
Evan Cheng8de898a2009-06-26 00:19:44 +0000201multiclass T2I_bin_s_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000202 // shifted imm
Evan Chengf49810c2009-06-23 17:48:47 +0000203 def ri : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000204 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000205 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000206 // register
207 def rr : T2I<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000208 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000209 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
210 let isCommutable = Commutable;
211 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000212 // shifted register
Evan Chengf49810c2009-06-23 17:48:47 +0000213 def rs : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000214 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000215 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000216}
217}
218
Evan Chenga67efd12009-06-23 19:39:13 +0000219/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
220/// patterns for a binary operation that produces a value.
Evan Cheng8de898a2009-06-26 00:19:44 +0000221multiclass T2I_bin_ii12rs<string opc, PatFrag opnode, bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000222 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000223 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
224 opc, " $dst, $lhs, $rhs",
225 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000226 // 12-bit imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000227 def ri12 : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
228 !strconcat(opc, "w"), " $dst, $lhs, $rhs",
229 [(set GPR:$dst, (opnode GPR:$lhs, imm0_4095:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000230 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000231 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
232 opc, " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000233 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
234 let isCommutable = Commutable;
235 }
Evan Chengf49810c2009-06-23 17:48:47 +0000236 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000237 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
238 opc, " $dst, $lhs, $rhs",
239 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000240}
241
Evan Cheng62674222009-06-25 23:34:10 +0000242/// 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 +0000243/// binary operation that produces a value and use and define the carry bit.
244/// It's not predicable.
Evan Cheng62674222009-06-25 23:34:10 +0000245let Uses = [CPSR] in {
Evan Cheng8de898a2009-06-26 00:19:44 +0000246multiclass T2I_adde_sube_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000247 // shifted imm
Evan Cheng62674222009-06-25 23:34:10 +0000248 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000249 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000250 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000251 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000252 // register
Evan Cheng62674222009-06-25 23:34:10 +0000253 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000254 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000255 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000256 Requires<[IsThumb2, CarryDefIsUnused]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000257 let isCommutable = Commutable;
258 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000259 // shifted register
Evan Cheng62674222009-06-25 23:34:10 +0000260 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000261 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000262 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000263 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Cheng62674222009-06-25 23:34:10 +0000264 // Carry setting variants
265 // shifted imm
266 def Sri : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
267 !strconcat(opc, "s $dst, $lhs, $rhs"),
268 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000269 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000270 let Defs = [CPSR];
271 }
272 // register
273 def Srr : T2XI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
274 !strconcat(opc, "s $dst, $lhs, $rhs"),
275 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000276 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000277 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000278 let isCommutable = Commutable;
279 }
Evan Cheng62674222009-06-25 23:34:10 +0000280 // shifted register
281 def Srs : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
282 !strconcat(opc, "s $dst, $lhs, $rhs"),
283 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000284 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000285 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000286 }
Evan Chengf49810c2009-06-23 17:48:47 +0000287}
288}
289
Evan Cheng62674222009-06-25 23:34:10 +0000290/// T2I_rsc_is - Same as T2I_adde_sube_irs except the order of operands are
Evan Cheng1e249e32009-06-25 20:59:23 +0000291/// reversed. It doesn't define the 'rr' form since it's handled by its
Evan Cheng62674222009-06-25 23:34:10 +0000292/// T2I_adde_sube_irs counterpart.
Evan Cheng1e249e32009-06-25 20:59:23 +0000293let Defs = [CPSR], Uses = [CPSR] in {
Evan Cheng62674222009-06-25 23:34:10 +0000294multiclass T2I_rsc_is<string opc, PatFrag opnode> {
Evan Cheng1e249e32009-06-25 20:59:23 +0000295 // shifted imm
Evan Cheng62674222009-06-25 23:34:10 +0000296 def ri : T2sI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
297 opc, " $dst, $rhs, $lhs",
298 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000299 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Cheng1e249e32009-06-25 20:59:23 +0000300 // shifted register
Evan Cheng62674222009-06-25 23:34:10 +0000301 def rs : T2sI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
302 opc, " $dst, $rhs, $lhs",
303 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000304 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Cheng62674222009-06-25 23:34:10 +0000305 // shifted imm
306 def Sri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
Evan Cheng1e249e32009-06-25 20:59:23 +0000307 !strconcat(opc, "s $dst, $rhs, $lhs"),
Evan Cheng62674222009-06-25 23:34:10 +0000308 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000309 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000310 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000311 }
Evan Cheng62674222009-06-25 23:34:10 +0000312 // shifted register
313 def Srs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
314 !strconcat(opc, "s $dst, $rhs, $lhs"),
315 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000316 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000317 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000318 }
Evan Cheng1e249e32009-06-25 20:59:23 +0000319}
320}
321
322/// T2I_rbin_s_is - Same as T2I_bin_s_irs except the order of operands are
323/// reversed. It doesn't define the 'rr' form since it's handled by its
324/// T2I_bin_s_irs counterpart.
325let Defs = [CPSR] in {
326multiclass T2I_rbin_s_is<string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000327 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000328 def ri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs, cc_out:$s),
329 !strconcat(opc, "${s} $dst, $rhs, $lhs"),
330 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000331 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000332 def rs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs, cc_out:$s),
333 !strconcat(opc, "${s} $dst, $rhs, $lhs"),
334 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000335}
336}
337
Evan Chenga67efd12009-06-23 19:39:13 +0000338/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
339// rotate operation that produces a value.
340multiclass T2I_sh_ir<string opc, PatFrag opnode> {
341 // 5-bit imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000342 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
343 opc, " $dst, $lhs, $rhs",
344 [(set GPR:$dst, (opnode GPR:$lhs, imm1_31:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000345 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000346 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
347 opc, " $dst, $lhs, $rhs",
348 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000349}
Evan Chengf49810c2009-06-23 17:48:47 +0000350
Evan Chenga67efd12009-06-23 19:39:13 +0000351/// T21_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
352/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000353/// a explicit result, only implicitly set CPSR.
David Goodwinc27a4542009-07-20 22:13:31 +0000354let Defs = [CPSR] in {
Evan Chengf49810c2009-06-23 17:48:47 +0000355multiclass T2I_cmp_is<string opc, PatFrag opnode> {
356 // shifted imm
357 def ri : T2I<(outs), (ins GPR:$lhs, t2_so_imm:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000358 opc, " $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000359 [(opnode GPR:$lhs, t2_so_imm:$rhs)]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000360 // register
361 def rr : T2I<(outs), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000362 opc, " $lhs, $rhs",
Evan Chenga67efd12009-06-23 19:39:13 +0000363 [(opnode GPR:$lhs, GPR:$rhs)]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000364 // shifted register
365 def rs : T2I<(outs), (ins GPR:$lhs, t2_so_reg:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000366 opc, " $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000367 [(opnode GPR:$lhs, t2_so_reg:$rhs)]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000368}
369}
370
Evan Chengf3c21b82009-06-30 02:15:48 +0000371/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
372multiclass T2I_ld<string opc, PatFrag opnode> {
373 def i12 : T2Ii12<(outs GPR:$dst), (ins t2addrmode_imm12:$addr),
374 opc, " $dst, $addr",
375 [(set GPR:$dst, (opnode t2addrmode_imm12:$addr))]>;
376 def i8 : T2Ii8 <(outs GPR:$dst), (ins t2addrmode_imm8:$addr),
377 opc, " $dst, $addr",
378 [(set GPR:$dst, (opnode t2addrmode_imm8:$addr))]>;
379 def s : T2Iso <(outs GPR:$dst), (ins t2addrmode_so_reg:$addr),
380 opc, " $dst, $addr",
381 [(set GPR:$dst, (opnode t2addrmode_so_reg:$addr))]>;
382 def pci : T2Ipc <(outs GPR:$dst), (ins i32imm:$addr),
383 opc, " $dst, $addr",
384 [(set GPR:$dst, (opnode (ARMWrapper tconstpool:$addr)))]>;
385}
386
David Goodwin73b8f162009-06-30 22:11:34 +0000387/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
388multiclass T2I_st<string opc, PatFrag opnode> {
389 def i12 : T2Ii12<(outs), (ins GPR:$src, t2addrmode_imm12:$addr),
390 opc, " $src, $addr",
391 [(opnode GPR:$src, t2addrmode_imm12:$addr)]>;
392 def i8 : T2Ii8 <(outs), (ins GPR:$src, t2addrmode_imm8:$addr),
393 opc, " $src, $addr",
394 [(opnode GPR:$src, t2addrmode_imm8:$addr)]>;
395 def s : T2Iso <(outs), (ins GPR:$src, t2addrmode_so_reg:$addr),
396 opc, " $src, $addr",
397 [(opnode GPR:$src, t2addrmode_so_reg:$addr)]>;
398}
399
David Goodwind1fa1202009-07-01 00:01:13 +0000400/// T2I_picld - Defines the PIC load pattern.
401class T2I_picld<string opc, PatFrag opnode> :
402 T2I<(outs GPR:$dst), (ins addrmodepc:$addr),
403 !strconcat("${addr:label}:\n\t", opc), " $dst, $addr",
404 [(set GPR:$dst, (opnode addrmodepc:$addr))]>;
405
406/// T2I_picst - Defines the PIC store pattern.
407class T2I_picst<string opc, PatFrag opnode> :
408 T2I<(outs), (ins GPR:$src, addrmodepc:$addr),
409 !strconcat("${addr:label}:\n\t", opc), " $src, $addr",
410 [(opnode GPR:$src, addrmodepc:$addr)]>;
411
Evan Chengd27c9fc2009-07-03 01:43:10 +0000412
413/// T2I_unary_rrot - A unary operation with two forms: one whose operand is a
414/// register and one whose operand is a register rotated by 8/16/24.
415multiclass T2I_unary_rrot<string opc, PatFrag opnode> {
416 def r : T2I<(outs GPR:$dst), (ins GPR:$Src),
417 opc, " $dst, $Src",
418 [(set GPR:$dst, (opnode GPR:$Src))]>;
419 def r_rot : T2I<(outs GPR:$dst), (ins GPR:$Src, i32imm:$rot),
420 opc, " $dst, $Src, ror $rot",
421 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>;
422}
423
424/// T2I_bin_rrot - A binary operation with two forms: one whose operand is a
425/// register and one whose operand is a register rotated by 8/16/24.
426multiclass T2I_bin_rrot<string opc, PatFrag opnode> {
427 def rr : T2I<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
428 opc, " $dst, $LHS, $RHS",
429 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>;
430 def rr_rot : T2I<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
431 opc, " $dst, $LHS, $RHS, ror $rot",
432 [(set GPR:$dst, (opnode GPR:$LHS,
433 (rotr GPR:$RHS, rot_imm:$rot)))]>;
434}
435
Anton Korobeynikov52237112009-06-17 18:13:58 +0000436//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000437// Instructions
438//===----------------------------------------------------------------------===//
439
440//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +0000441// Miscellaneous Instructions.
442//
443
444let isNotDuplicable = 1 in
David Goodwinf1daf7d2009-07-08 23:10:31 +0000445def t2PICADD : T2XI<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000446 "$cp:\n\tadd $dst, pc",
David Goodwinf1daf7d2009-07-08 23:10:31 +0000447 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000448
449
450// LEApcrel - Load a pc-relative address into a register without offending the
451// assembler.
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000452def t2LEApcrel : T2XI<(outs GPR:$dst), (ins i32imm:$label, pred:$p),
Evan Cheng81c102b2009-07-23 18:26:03 +0000453 "adr$p $dst, #$label", []>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000454
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000455def t2LEApcrelJT : T2XI<(outs GPR:$dst),
Evan Cheng81c102b2009-07-23 18:26:03 +0000456 (ins i32imm:$label, i32imm:$id, pred:$p),
457 "adr$p $dst, #${label}_${id:no_hash}", []>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000458
Evan Chengb6c29d52009-06-25 01:21:30 +0000459// ADD rd, sp, #so_imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000460def t2ADDrSPi : T2XI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
461 "add $dst, $sp, $imm",
462 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000463
464// ADD rd, sp, #imm12
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000465def t2ADDrSPi12 : T2XI<(outs GPR:$dst), (ins GPR:$sp, i32imm:$imm),
466 "addw $dst, $sp, $imm",
467 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000468
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000469def t2ADDrSPs : T2XI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
470 "addw $dst, $sp, $rhs",
471 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000472
473
Evan Chenga09b9ca2009-06-24 23:47:58 +0000474//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000475// Load / store Instructions.
476//
477
Evan Cheng055b0312009-06-29 07:51:04 +0000478// Load
Evan Chengf3c21b82009-06-30 02:15:48 +0000479let canFoldAsLoad = 1 in
480defm t2LDR : T2I_ld<"ldr", UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000481
Evan Chengf3c21b82009-06-30 02:15:48 +0000482// Loads with zero extension
483defm t2LDRH : T2I_ld<"ldrh", UnOpFrag<(zextloadi16 node:$Src)>>;
484defm t2LDRB : T2I_ld<"ldrb", UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000485
Evan Chengf3c21b82009-06-30 02:15:48 +0000486// Loads with sign extension
487defm t2LDRSH : T2I_ld<"ldrsh", UnOpFrag<(sextloadi16 node:$Src)>>;
488defm t2LDRSB : T2I_ld<"ldrsb", UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000489
Evan Chengf3c21b82009-06-30 02:15:48 +0000490let mayLoad = 1 in {
491// Load doubleword
David Goodwin6647cea2009-06-30 22:50:01 +0000492def t2LDRDi8 : T2Ii8s4<(outs GPR:$dst), (ins t2addrmode_imm8s4:$addr),
Evan Chengf3c21b82009-06-30 02:15:48 +0000493 "ldrd", " $dst, $addr", []>;
494def t2LDRDpci : T2Ii8s4<(outs GPR:$dst), (ins i32imm:$addr),
495 "ldrd", " $dst, $addr", []>;
496}
497
498// zextload i1 -> zextload i8
499def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
500 (t2LDRBi12 t2addrmode_imm12:$addr)>;
501def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
502 (t2LDRBi8 t2addrmode_imm8:$addr)>;
503def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
504 (t2LDRBs t2addrmode_so_reg:$addr)>;
505def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
506 (t2LDRBpci tconstpool:$addr)>;
507
508// extload -> zextload
509// FIXME: Reduce the number of patterns by legalizing extload to zextload
510// earlier?
511def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
512 (t2LDRBi12 t2addrmode_imm12:$addr)>;
513def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
514 (t2LDRBi8 t2addrmode_imm8:$addr)>;
515def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
516 (t2LDRBs t2addrmode_so_reg:$addr)>;
517def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
518 (t2LDRBpci tconstpool:$addr)>;
519
520def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
521 (t2LDRBi12 t2addrmode_imm12:$addr)>;
522def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
523 (t2LDRBi8 t2addrmode_imm8:$addr)>;
524def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
525 (t2LDRBs t2addrmode_so_reg:$addr)>;
526def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
527 (t2LDRBpci tconstpool:$addr)>;
528
529def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
530 (t2LDRHi12 t2addrmode_imm12:$addr)>;
531def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
532 (t2LDRHi8 t2addrmode_imm8:$addr)>;
533def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
534 (t2LDRHs t2addrmode_so_reg:$addr)>;
535def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
536 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +0000537
Evan Chenge88d5ce2009-07-02 07:28:31 +0000538// Indexed loads
Evan Cheng78236f82009-07-03 00:08:19 +0000539let mayLoad = 1 in {
Evan Chenge88d5ce2009-07-02 07:28:31 +0000540def t2LDR_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
541 (ins t2addrmode_imm8:$addr),
542 AddrModeT2_i8, IndexModePre,
543 "ldr", " $dst, $addr!", "$addr.base = $base_wb",
544 []>;
545
546def t2LDR_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
547 (ins GPR:$base, t2am_imm8_offset:$offset),
548 AddrModeT2_i8, IndexModePost,
549 "ldr", " $dst, [$base], $offset", "$base = $base_wb",
550 []>;
551
552def t2LDRB_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
553 (ins t2addrmode_imm8:$addr),
554 AddrModeT2_i8, IndexModePre,
555 "ldrb", " $dst, $addr!", "$addr.base = $base_wb",
556 []>;
557def t2LDRB_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
558 (ins GPR:$base, t2am_imm8_offset:$offset),
559 AddrModeT2_i8, IndexModePost,
560 "ldrb", " $dst, [$base], $offset", "$base = $base_wb",
561 []>;
562
563def t2LDRH_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
564 (ins t2addrmode_imm8:$addr),
565 AddrModeT2_i8, IndexModePre,
566 "ldrh", " $dst, $addr!", "$addr.base = $base_wb",
567 []>;
568def t2LDRH_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
569 (ins GPR:$base, t2am_imm8_offset:$offset),
570 AddrModeT2_i8, IndexModePost,
571 "ldrh", " $dst, [$base], $offset", "$base = $base_wb",
572 []>;
573
Evan Cheng4fbb9962009-07-02 23:16:11 +0000574def t2LDRSB_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
575 (ins t2addrmode_imm8:$addr),
576 AddrModeT2_i8, IndexModePre,
577 "ldrsb", " $dst, $addr!", "$addr.base = $base_wb",
578 []>;
579def t2LDRSB_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
580 (ins GPR:$base, t2am_imm8_offset:$offset),
581 AddrModeT2_i8, IndexModePost,
582 "ldrsb", " $dst, [$base], $offset", "$base = $base_wb",
583 []>;
584
585def t2LDRSH_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
586 (ins t2addrmode_imm8:$addr),
587 AddrModeT2_i8, IndexModePre,
588 "ldrsh", " $dst, $addr!", "$addr.base = $base_wb",
589 []>;
590def t2LDRSH_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
591 (ins GPR:$base, t2am_imm8_offset:$offset),
592 AddrModeT2_i8, IndexModePost,
593 "ldrsh", " $dst, [$base], $offset", "$base = $base_wb",
594 []>;
Evan Cheng78236f82009-07-03 00:08:19 +0000595}
Evan Cheng4fbb9962009-07-02 23:16:11 +0000596
David Goodwin73b8f162009-06-30 22:11:34 +0000597// Store
Evan Chenge88d5ce2009-07-02 07:28:31 +0000598defm t2STR : T2I_st<"str", BinOpFrag<(store node:$LHS, node:$RHS)>>;
599defm t2STRB : T2I_st<"strb", BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
600defm t2STRH : T2I_st<"strh", BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
David Goodwin73b8f162009-06-30 22:11:34 +0000601
David Goodwin6647cea2009-06-30 22:50:01 +0000602// Store doubleword
603let mayLoad = 1 in
604def t2STRDi8 : T2Ii8s4<(outs), (ins GPR:$src, t2addrmode_imm8s4:$addr),
605 "strd", " $src, $addr", []>;
606
Evan Cheng6d94f112009-07-03 00:06:39 +0000607// Indexed stores
608def t2STR_PRE : T2Iidxldst<(outs GPR:$base_wb),
609 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
610 AddrModeT2_i8, IndexModePre,
611 "str", " $src, [$base, $offset]!", "$base = $base_wb",
612 [(set GPR:$base_wb,
613 (pre_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
614
615def t2STR_POST : T2Iidxldst<(outs GPR:$base_wb),
616 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
617 AddrModeT2_i8, IndexModePost,
618 "str", " $src, [$base], $offset", "$base = $base_wb",
619 [(set GPR:$base_wb,
620 (post_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
621
622def t2STRH_PRE : T2Iidxldst<(outs GPR:$base_wb),
623 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
624 AddrModeT2_i8, IndexModePre,
625 "strh", " $src, [$base, $offset]!", "$base = $base_wb",
626 [(set GPR:$base_wb,
627 (pre_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
628
629def t2STRH_POST : T2Iidxldst<(outs GPR:$base_wb),
630 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
631 AddrModeT2_i8, IndexModePost,
632 "strh", " $src, [$base], $offset", "$base = $base_wb",
633 [(set GPR:$base_wb,
634 (post_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
635
636def t2STRB_PRE : T2Iidxldst<(outs GPR:$base_wb),
637 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
638 AddrModeT2_i8, IndexModePre,
639 "strb", " $src, [$base, $offset]!", "$base = $base_wb",
640 [(set GPR:$base_wb,
641 (pre_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
642
643def t2STRB_POST : T2Iidxldst<(outs GPR:$base_wb),
644 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
645 AddrModeT2_i8, IndexModePost,
646 "strb", " $src, [$base], $offset", "$base = $base_wb",
647 [(set GPR:$base_wb,
648 (post_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
649
David Goodwind1fa1202009-07-01 00:01:13 +0000650
Evan Cheng5c874172009-07-09 22:21:59 +0000651// FIXME: ldrd / strd pre / post variants
Evan Cheng2889cce2009-07-03 00:18:36 +0000652
653//===----------------------------------------------------------------------===//
654// Load / store multiple Instructions.
655//
656
657let mayLoad = 1 in
658def t2LDM : T2XI<(outs),
659 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Evan Chengc50a1cb2009-07-09 22:58:39 +0000660 "ldm${addr:submode}${p} $addr, $dst1", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +0000661
662let mayStore = 1 in
663def t2STM : T2XI<(outs),
664 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
Evan Chengc50a1cb2009-07-09 22:58:39 +0000665 "stm${addr:submode}${p} $addr, $src1", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +0000666
Evan Cheng9cb9e672009-06-27 02:26:13 +0000667//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000668// Move Instructions.
669//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000670
Evan Chengf49810c2009-06-23 17:48:47 +0000671let neverHasSideEffects = 1 in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000672def t2MOVr : T2sI<(outs GPR:$dst), (ins GPR:$src),
673 "mov", " $dst, $src", []>;
Evan Chengf49810c2009-06-23 17:48:47 +0000674
Evan Chenga67efd12009-06-23 19:39:13 +0000675let isReMaterializable = 1, isAsCheapAsAMove = 1 in
David Goodwin83b35932009-06-26 16:10:07 +0000676def t2MOVi : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
677 "mov", " $dst, $src",
678 [(set GPR:$dst, t2_so_imm:$src)]>;
679
680let isReMaterializable = 1, isAsCheapAsAMove = 1 in
681def t2MOVi16 : T2I<(outs GPR:$dst), (ins i32imm:$src),
682 "movw", " $dst, $src",
683 [(set GPR:$dst, imm0_65535:$src)]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000684
Evan Chengf49810c2009-06-23 17:48:47 +0000685// FIXME: Also available in ARM mode.
Evan Cheng3850a6a2009-06-23 05:23:49 +0000686let Constraints = "$src = $dst" in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000687def t2MOVTi16 : T2sI<(outs GPR:$dst), (ins GPR:$src, i32imm:$imm),
688 "movt", " $dst, $imm",
689 [(set GPR:$dst,
690 (or (and GPR:$src, 0xffff), t2_lo16AllZero:$imm))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000691
692//===----------------------------------------------------------------------===//
Evan Chengd27c9fc2009-07-03 01:43:10 +0000693// Extend Instructions.
694//
695
696// Sign extenders
697
698defm t2SXTB : T2I_unary_rrot<"sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
699defm t2SXTH : T2I_unary_rrot<"sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
700
701defm t2SXTAB : T2I_bin_rrot<"sxtab",
702 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
703defm t2SXTAH : T2I_bin_rrot<"sxtah",
704 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
705
706// TODO: SXT(A){B|H}16
707
708// Zero extenders
709
710let AddedComplexity = 16 in {
711defm t2UXTB : T2I_unary_rrot<"uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
712defm t2UXTH : T2I_unary_rrot<"uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
713defm t2UXTB16 : T2I_unary_rrot<"uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
714
715def : T2Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
716 (t2UXTB16r_rot GPR:$Src, 24)>;
717def : T2Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
718 (t2UXTB16r_rot GPR:$Src, 8)>;
719
720defm t2UXTAB : T2I_bin_rrot<"uxtab",
721 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
722defm t2UXTAH : T2I_bin_rrot<"uxtah",
723 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
724}
725
726//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000727// Arithmetic Instructions.
728//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000729
Evan Cheng8de898a2009-06-26 00:19:44 +0000730defm t2ADD : T2I_bin_ii12rs<"add", BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
Evan Chenga67efd12009-06-23 19:39:13 +0000731defm t2SUB : T2I_bin_ii12rs<"sub", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000732
Evan Chengf49810c2009-06-23 17:48:47 +0000733// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Evan Cheng8de898a2009-06-26 00:19:44 +0000734defm t2ADDS : T2I_bin_s_irs <"add", BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
Evan Cheng1e249e32009-06-25 20:59:23 +0000735defm t2SUBS : T2I_bin_s_irs <"sub", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000736
Evan Cheng8de898a2009-06-26 00:19:44 +0000737defm t2ADC : T2I_adde_sube_irs<"adc",BinOpFrag<(adde node:$LHS, node:$RHS)>,1>;
738defm t2SBC : T2I_adde_sube_irs<"sbc",BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000739
740// RSB, RSC
Evan Cheng1e249e32009-06-25 20:59:23 +0000741defm t2RSB : T2I_rbin_is <"rsb", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
742defm t2RSBS : T2I_rbin_s_is <"rsb", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Evan Cheng62674222009-06-25 23:34:10 +0000743defm t2RSC : T2I_rsc_is <"rsc", BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000744
745// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Evan Cheng9cb9e672009-06-27 02:26:13 +0000746def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
747 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
748def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
749 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000750
751
Evan Chengf49810c2009-06-23 17:48:47 +0000752//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +0000753// Shift and rotate Instructions.
754//
755
756defm t2LSL : T2I_sh_ir<"lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
757defm t2LSR : T2I_sh_ir<"lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
758defm t2ASR : T2I_sh_ir<"asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
759defm t2ROR : T2I_sh_ir<"ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
760
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000761def t2MOVrx : T2sI<(outs GPR:$dst), (ins GPR:$src),
762 "mov", " $dst, $src, rrx",
763 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000764
765//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +0000766// Bitwise Instructions.
767//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000768
Evan Cheng8de898a2009-06-26 00:19:44 +0000769defm t2AND : T2I_bin_irs<"and", BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
770defm t2ORR : T2I_bin_irs<"orr", BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
771defm t2EOR : T2I_bin_irs<"eor", BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +0000772
Evan Chenga67efd12009-06-23 19:39:13 +0000773defm t2BIC : T2I_bin_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000774
Evan Chengf49810c2009-06-23 17:48:47 +0000775let Constraints = "$src = $dst" in
776def t2BFC : T2I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000777 "bfc", " $dst, $imm",
Evan Chengf49810c2009-06-23 17:48:47 +0000778 [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>;
779
780// FIXME: A8.6.18 BFI - Bitfield insert (Encoding T1)
781
Evan Cheng36a0aeb2009-07-06 22:23:46 +0000782defm t2ORN : T2I_bin_irs<"orn", BinOpFrag<(or node:$LHS, (not node:$RHS))>>;
783
784// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
785let AddedComplexity = 1 in
786defm t2MVN : T2I_un_irs <"mvn", UnOpFrag<(not node:$Src)>, 1, 1>;
787
788
789def : T2Pat<(and GPR:$src, t2_so_imm_not:$imm),
790 (t2BICri GPR:$src, t2_so_imm_not:$imm)>;
791
792def : T2Pat<(or GPR:$src, t2_so_imm_not:$imm),
793 (t2ORNri GPR:$src, t2_so_imm_not:$imm)>;
794
795def : T2Pat<(t2_so_imm_not:$src),
796 (t2MVNi t2_so_imm_not:$src)>;
797
Evan Chengf49810c2009-06-23 17:48:47 +0000798//===----------------------------------------------------------------------===//
799// Multiply Instructions.
800//
Evan Cheng8de898a2009-06-26 00:19:44 +0000801let isCommutable = 1 in
Evan Chengf49810c2009-06-23 17:48:47 +0000802def t2MUL: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000803 "mul", " $dst, $a, $b",
Evan Chengf49810c2009-06-23 17:48:47 +0000804 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
805
806def t2MLA: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000807 "mla", " $dst, $a, $b, $c",
Evan Chengf49810c2009-06-23 17:48:47 +0000808 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
809
810def t2MLS: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000811 "mls", " $dst, $a, $b, $c",
Evan Chengf49810c2009-06-23 17:48:47 +0000812 [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>;
813
Evan Cheng5b9fcd12009-07-07 01:17:28 +0000814// Extra precision multiplies with low / high results
815let neverHasSideEffects = 1 in {
816let isCommutable = 1 in {
817def t2SMULL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
818 "smull", " $ldst, $hdst, $a, $b", []>;
819
820def t2UMULL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
821 "umull", " $ldst, $hdst, $a, $b", []>;
822}
823
824// Multiply + accumulate
825def t2SMLAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
826 "smlal", " $ldst, $hdst, $a, $b", []>;
827
828def t2UMLAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
829 "umlal", " $ldst, $hdst, $a, $b", []>;
830
831def t2UMAAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
832 "umaal", " $ldst, $hdst, $a, $b", []>;
833} // neverHasSideEffects
834
835// Most significant word multiply
836def t2SMMUL : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
837 "smmul", " $dst, $a, $b",
838 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>;
839
840def t2SMMLA : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
841 "smmla", " $dst, $a, $b, $c",
842 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>;
843
844
845def t2SMMLS : T2I <(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
846 "smmls", " $dst, $a, $b, $c",
847 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>;
848
849multiclass T2I_smul<string opc, PatFrag opnode> {
850 def BB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
851 !strconcat(opc, "bb"), " $dst, $a, $b",
852 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
853 (sext_inreg GPR:$b, i16)))]>;
854
855 def BT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
856 !strconcat(opc, "bt"), " $dst, $a, $b",
857 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
858 (sra GPR:$b, (i32 16))))]>;
859
860 def TB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
861 !strconcat(opc, "tb"), " $dst, $a, $b",
862 [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
863 (sext_inreg GPR:$b, i16)))]>;
864
865 def TT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
866 !strconcat(opc, "tt"), " $dst, $a, $b",
867 [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
868 (sra GPR:$b, (i32 16))))]>;
869
870 def WB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
871 !strconcat(opc, "wb"), " $dst, $a, $b",
872 [(set GPR:$dst, (sra (opnode GPR:$a,
873 (sext_inreg GPR:$b, i16)), (i32 16)))]>;
874
875 def WT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
876 !strconcat(opc, "wt"), " $dst, $a, $b",
877 [(set GPR:$dst, (sra (opnode GPR:$a,
878 (sra GPR:$b, (i32 16))), (i32 16)))]>;
879}
880
881
882multiclass T2I_smla<string opc, PatFrag opnode> {
883 def BB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
884 !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
885 [(set GPR:$dst, (add GPR:$acc,
886 (opnode (sext_inreg GPR:$a, i16),
887 (sext_inreg GPR:$b, i16))))]>;
888
889 def BT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
890 !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
891 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
892 (sra GPR:$b, (i32 16)))))]>;
893
894 def TB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
895 !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
896 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
897 (sext_inreg GPR:$b, i16))))]>;
898
899 def TT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
900 !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
901 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
902 (sra GPR:$b, (i32 16)))))]>;
903
904 def WB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
905 !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
906 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
907 (sext_inreg GPR:$b, i16)), (i32 16))))]>;
908
909 def WT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
910 !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
911 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
912 (sra GPR:$b, (i32 16))), (i32 16))))]>;
913}
914
915defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
916defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
917
918// TODO: Halfword multiple accumulate long: SMLAL<x><y>
919// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
920
Evan Chengf49810c2009-06-23 17:48:47 +0000921
922//===----------------------------------------------------------------------===//
923// Misc. Arithmetic Instructions.
924//
925
Evan Chengf49810c2009-06-23 17:48:47 +0000926def t2CLZ : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000927 "clz", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000928 [(set GPR:$dst, (ctlz GPR:$src))]>;
929
930def t2REV : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000931 "rev", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000932 [(set GPR:$dst, (bswap GPR:$src))]>;
933
934def t2REV16 : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000935 "rev16", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000936 [(set GPR:$dst,
937 (or (and (srl GPR:$src, (i32 8)), 0xFF),
938 (or (and (shl GPR:$src, (i32 8)), 0xFF00),
939 (or (and (srl GPR:$src, (i32 8)), 0xFF0000),
940 (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>;
941
Evan Chengf49810c2009-06-23 17:48:47 +0000942def t2REVSH : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000943 "revsh", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000944 [(set GPR:$dst,
945 (sext_inreg
946 (or (srl (and GPR:$src, 0xFFFF), (i32 8)),
947 (shl GPR:$src, (i32 8))), i16))]>;
948
Evan Cheng40289b02009-07-07 05:35:52 +0000949def t2PKHBT : T2I<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
950 "pkhbt", " $dst, $src1, $src2, LSL $shamt",
951 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
952 (and (shl GPR:$src2, (i32 imm:$shamt)),
953 0xFFFF0000)))]>;
954
955// Alternate cases for PKHBT where identities eliminate some nodes.
956def : T2Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
957 (t2PKHBT GPR:$src1, GPR:$src2, 0)>;
958def : T2Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
959 (t2PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
960
961def t2PKHTB : T2I<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
962 "pkhtb", " $dst, $src1, $src2, ASR $shamt",
963 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
964 (and (sra GPR:$src2, imm16_31:$shamt),
965 0xFFFF)))]>;
966
967// Alternate cases for PKHTB where identities eliminate some nodes. Note that
968// a shift amount of 0 is *not legal* here, it is PKHBT instead.
969def : T2Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, (i32 16))),
970 (t2PKHTB GPR:$src1, GPR:$src2, 16)>;
971def : T2Pat<(or (and GPR:$src1, 0xFFFF0000),
972 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
973 (t2PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000974
975//===----------------------------------------------------------------------===//
976// Comparison Instructions...
977//
978
979defm t2CMP : T2I_cmp_is<"cmp",
980 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
David Goodwinc0309b42009-06-29 15:33:01 +0000981defm t2CMPz : T2I_cmp_is<"cmp",
982 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000983
984defm t2CMN : T2I_cmp_is<"cmn",
985 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
David Goodwinc0309b42009-06-29 15:33:01 +0000986defm t2CMNz : T2I_cmp_is<"cmn",
987 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000988
Evan Cheng9cb9e672009-06-27 02:26:13 +0000989def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
990 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000991
David Goodwinc0309b42009-06-29 15:33:01 +0000992def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
Evan Cheng9cb9e672009-06-27 02:26:13 +0000993 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000994
David Goodwinbaeb9112009-06-29 22:49:42 +0000995defm t2TST : T2I_cmp_is<"tst",
996 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>>;
997defm t2TEQ : T2I_cmp_is<"teq",
998 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000999
1000// A8.6.27 CBNZ, CBZ - Compare and branch on (non)zero.
1001// Short range conditional branch. Looks awesome for loops. Need to figure
1002// out how to use this one.
1003
Evan Chenge253c952009-07-07 20:39:03 +00001004
1005// Conditional moves
1006// FIXME: should be able to write a pattern for ARMcmov, but can't use
1007// a two-value operand where a dag node expects two operands. :(
1008def t2MOVCCr : T2I<(outs GPR:$dst), (ins GPR:$false, GPR:$true),
1009 "mov", " $dst, $true",
1010 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1011 RegConstraint<"$false = $dst">;
1012
1013def t2MOVCCs : T2I<(outs GPR:$dst), (ins GPR:$false, t2_so_reg:$true),
1014 "mov", " $dst, $true",
1015[/*(set GPR:$dst, (ARMcmov GPR:$false, t2_so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1016 RegConstraint<"$false = $dst">;
1017
1018def t2MOVCCi : T2I<(outs GPR:$dst), (ins GPR:$false, t2_so_imm:$true),
1019 "mov", " $dst, $true",
1020[/*(set GPR:$dst, (ARMcmov GPR:$false, t2_so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1021 RegConstraint<"$false = $dst">;
Evan Chengf49810c2009-06-23 17:48:47 +00001022
David Goodwin5e47a9a2009-06-30 18:04:13 +00001023//===----------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +00001024// TLS Instructions
1025//
1026
1027// __aeabi_read_tp preserves the registers r1-r3.
1028let isCall = 1,
1029 Defs = [R0, R12, LR, CPSR] in {
1030 def t2TPsoft : T2XI<(outs), (ins),
1031 "bl __aeabi_read_tp",
1032 [(set R0, ARMthread_pointer)]>;
1033}
1034
1035//===----------------------------------------------------------------------===//
David Goodwin5e47a9a2009-06-30 18:04:13 +00001036// Control-Flow Instructions
1037//
1038
Evan Chengc50a1cb2009-07-09 22:58:39 +00001039// FIXME: remove when we have a way to marking a MI with these properties.
1040// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
1041// operand list.
1042// FIXME: Should pc be an implicit operand like PICADD, etc?
1043let isReturn = 1, isTerminator = 1, mayLoad = 1 in
1044 def t2LDM_RET : T2XI<(outs),
1045 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
1046 "ldm${addr:submode}${p} $addr, $dst1",
1047 []>;
1048
David Goodwin334c2642009-07-08 16:09:28 +00001049// On non-Darwin platforms R9 is callee-saved.
David Goodwin77521f52009-07-08 20:28:28 +00001050let isCall = 1,
Evan Cheng756da122009-07-22 06:46:53 +00001051 Defs = [R0, R1, R2, R3, R12, LR,
1052 D0, D1, D2, D3, D4, D5, D6, D7,
1053 D16, D17, D18, D19, D20, D21, D22, D23,
1054 D24, D25, D26, D27, D28, D29, D31, D31, CPSR] in {
David Goodwin77521f52009-07-08 20:28:28 +00001055def t2BL : T2XI<(outs), (ins i32imm:$func, variable_ops),
1056 "bl ${func:call}",
1057 [(ARMcall tglobaladdr:$func)]>, Requires<[IsNotDarwin]>;
1058
1059def t2BLX : T2XI<(outs), (ins GPR:$func, variable_ops),
1060 "blx $func",
1061 [(ARMcall GPR:$func)]>, Requires<[IsNotDarwin]>;
1062}
David Goodwin334c2642009-07-08 16:09:28 +00001063
1064// On Darwin R9 is call-clobbered.
David Goodwin77521f52009-07-08 20:28:28 +00001065let isCall = 1,
1066 Defs = [R0, R1, R2, R3, R9, R12, LR,
1067 D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
1068def t2BLr9 : T2XI<(outs), (ins i32imm:$func, variable_ops),
1069 "bl ${func:call}",
1070 [(ARMcall tglobaladdr:$func)]>, Requires<[IsDarwin]>;
1071
1072def t2BLXr9 : T2XI<(outs), (ins GPR:$func, variable_ops),
1073 "blx $func",
1074 [(ARMcall GPR:$func)]>, Requires<[IsDarwin]>;
1075}
David Goodwin334c2642009-07-08 16:09:28 +00001076
David Goodwin5e47a9a2009-06-30 18:04:13 +00001077let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
1078let isPredicable = 1 in
1079def t2B : T2XI<(outs), (ins brtarget:$target),
1080 "b $target",
1081 [(br bb:$target)]>;
1082
David Goodwinc9a59b52009-06-30 19:50:22 +00001083let isNotDuplicable = 1, isIndirectBranch = 1 in {
1084def t2BR_JTr : T2JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
Evan Cheng78947622009-07-24 18:20:44 +00001085 "mov pc, $target \n\t.align\t2\n$jt",
David Goodwinc9a59b52009-06-30 19:50:22 +00001086 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
1087
1088def t2BR_JTm :
1089 T2JTI<(outs),
1090 (ins t2addrmode_so_reg:$target, jtblock_operand:$jt, i32imm:$id),
Evan Cheng78947622009-07-24 18:20:44 +00001091 "ldr pc, $target \n\t.align\t2\n$jt",
David Goodwinc9a59b52009-06-30 19:50:22 +00001092 [(ARMbrjt (i32 (load t2addrmode_so_reg:$target)), tjumptable:$jt,
1093 imm:$id)]>;
1094
1095def t2BR_JTadd :
1096 T2JTI<(outs),
1097 (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
Evan Cheng78947622009-07-24 18:20:44 +00001098 "add pc, $target, $idx \n\t.align\t2\n$jt",
David Goodwinc9a59b52009-06-30 19:50:22 +00001099 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt, imm:$id)]>;
1100} // isNotDuplicate, isIndirectBranch
1101} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +00001102
1103// FIXME: should be able to write a pattern for ARMBrcond, but can't use
1104// a two-value operand where a dag node expects two operands. :(
1105let isBranch = 1, isTerminator = 1 in
1106def t2Bcc : T2I<(outs), (ins brtarget:$target),
1107 "b", " $target",
1108 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Evan Chengf49810c2009-06-23 17:48:47 +00001109
Evan Cheng06e16582009-07-10 01:54:42 +00001110
1111// IT block
1112def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
1113 AddrModeNone, Size2Bytes,
1114 "it$mask $cc", "", []>;
1115
Evan Chengf49810c2009-06-23 17:48:47 +00001116//===----------------------------------------------------------------------===//
1117// Non-Instruction Patterns
1118//
1119
Evan Chenga09b9ca2009-06-24 23:47:58 +00001120// ConstantPool, GlobalAddress, and JumpTable
Evan Cheng9cb9e672009-06-27 02:26:13 +00001121def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>;
1122def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
1123def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1124 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chenga09b9ca2009-06-24 23:47:58 +00001125
Evan Chengf49810c2009-06-23 17:48:47 +00001126// Large immediate handling.
1127
Evan Cheng9cb9e672009-06-27 02:26:13 +00001128def : T2Pat<(i32 imm:$src),
1129 (t2MOVTi16 (t2MOVi16 (t2_lo16 imm:$src)), (t2_hi16 imm:$src))>;