blob: faa7dd5475d8cababaec3978e3bdaeed9519379e [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
Evan Cheng5657c012009-07-29 02:18:14 +000024// Table branch address
25def tb_addrmode : Operand<i32> {
26 let PrintMethod = "printTBAddrMode";
27}
28
Anton Korobeynikov52237112009-06-17 18:13:58 +000029// Shifted operands. No register controlled shifts for Thumb2.
30// Note: We do not support rrx shifted operands yet.
31def t2_so_reg : Operand<i32>, // reg imm
Evan Cheng9cb9e672009-06-27 02:26:13 +000032 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
Anton Korobeynikov52237112009-06-17 18:13:58 +000033 [shl,srl,sra,rotr]> {
Evan Cheng9cb9e672009-06-27 02:26:13 +000034 let PrintMethod = "printT2SOOperand";
Anton Korobeynikov52237112009-06-17 18:13:58 +000035 let MIOperandInfo = (ops GPR, i32imm);
36}
37
Evan Chengf49810c2009-06-23 17:48:47 +000038// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
39def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
Evan Chenge7cbe412009-07-08 21:03:57 +000040 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000041}]>;
42
Evan Chengf49810c2009-06-23 17:48:47 +000043// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
44def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
Evan Chenge7cbe412009-07-08 21:03:57 +000045 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
Evan Chengf49810c2009-06-23 17:48:47 +000046}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000047
Evan Chengf49810c2009-06-23 17:48:47 +000048// t2_so_imm - Match a 32-bit immediate operand, which is an
49// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
50// immediate splatted into multiple bytes of the word. t2_so_imm values are
51// represented in the imm field in the same 12-bit form that they are encoded
52// into t2_so_imm instructions: the 8-bit immediate is the least significant bits
53// [bits 0-7], the 4-bit shift/splat amount is the next 4 bits [bits 8-11].
54def t2_so_imm : Operand<i32>,
55 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000056 return ARM_AM::getT2SOImmVal((uint32_t)N->getZExtValue()) != -1;
57}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000058
Evan Chengf49810c2009-06-23 17:48:47 +000059// t2_so_imm_not - Match an immediate that is a complement
60// of a t2_so_imm.
61def t2_so_imm_not : Operand<i32>,
62 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000063 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
64}], t2_so_imm_not_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000065
66// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
67def t2_so_imm_neg : Operand<i32>,
68 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000069 return ARM_AM::getT2SOImmVal(-((int)N->getZExtValue())) != -1;
70}], t2_so_imm_neg_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000071
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 Chengfa2ea1a2009-08-04 01:41:15 +000086def imm0_255_neg : PatLeaf<(i32 imm), [{
87 return (uint32_t)(-N->getZExtValue()) < 255;
88}], imm_neg_XFORM>;
89
Evan Chengf49810c2009-06-23 17:48:47 +000090/// imm0_65535 predicate - True if the 32-bit immediate is in the range
91/// [0.65535].
92def imm0_65535 : PatLeaf<(i32 imm), [{
93 return (uint32_t)N->getZExtValue() < 65536;
Anton Korobeynikov52237112009-06-17 18:13:58 +000094}]>;
95
Evan Chengf49810c2009-06-23 17:48:47 +000096/// Split a 32-bit immediate into two 16 bit parts.
97def t2_lo16 : SDNodeXForm<imm, [{
98 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() & 0xffff,
99 MVT::i32);
100}]>;
101
102def t2_hi16 : SDNodeXForm<imm, [{
103 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
104}]>;
105
106def t2_lo16AllZero : PatLeaf<(i32 imm), [{
107 // Returns true if all low 16-bits are 0.
108 return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
109 }], t2_hi16>;
110
Evan Cheng9cb9e672009-06-27 02:26:13 +0000111
Evan Cheng055b0312009-06-29 07:51:04 +0000112// Define Thumb2 specific addressing modes.
113
114// t2addrmode_imm12 := reg + imm12
115def t2addrmode_imm12 : Operand<i32>,
116 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
117 let PrintMethod = "printT2AddrModeImm12Operand";
118 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
119}
120
David Goodwin5ff58b52009-07-24 00:16:18 +0000121// t2addrmode_imm8 := reg - imm8
Evan Cheng055b0312009-06-29 07:51:04 +0000122def t2addrmode_imm8 : Operand<i32>,
123 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
124 let PrintMethod = "printT2AddrModeImm8Operand";
125 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
126}
127
Evan Cheng6d94f112009-07-03 00:06:39 +0000128def t2am_imm8_offset : Operand<i32>,
129 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset", []>{
Evan Chenge88d5ce2009-07-02 07:28:31 +0000130 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
131}
132
Evan Cheng5c874172009-07-09 22:21:59 +0000133// t2addrmode_imm8s4 := reg +/- (imm8 << 2)
David Goodwin6647cea2009-06-30 22:50:01 +0000134def t2addrmode_imm8s4 : Operand<i32>,
135 ComplexPattern<i32, 2, "SelectT2AddrModeImm8s4", []> {
Evan Cheng5c874172009-07-09 22:21:59 +0000136 let PrintMethod = "printT2AddrModeImm8s4Operand";
David Goodwin6647cea2009-06-30 22:50:01 +0000137 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
138}
139
Evan Chengcba962d2009-07-09 20:40:44 +0000140// t2addrmode_so_reg := reg + (reg << imm2)
Evan Cheng055b0312009-06-29 07:51:04 +0000141def t2addrmode_so_reg : Operand<i32>,
142 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
143 let PrintMethod = "printT2AddrModeSoRegOperand";
144 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
145}
146
147
Anton Korobeynikov52237112009-06-17 18:13:58 +0000148//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000149// Multiclass helpers...
Anton Korobeynikov52237112009-06-17 18:13:58 +0000150//
151
Evan Chenga67efd12009-06-23 19:39:13 +0000152/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000153/// unary operation that produces a value. These are predicable and can be
154/// changed to modify CPSR.
Evan Chenga67efd12009-06-23 19:39:13 +0000155multiclass T2I_un_irs<string opc, PatFrag opnode, bit Cheap = 0, bit ReMat = 0>{
156 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000157 def i : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
158 opc, " $dst, $src",
Evan Chenga67efd12009-06-23 19:39:13 +0000159 [(set GPR:$dst, (opnode t2_so_imm:$src))]> {
160 let isAsCheapAsAMove = Cheap;
161 let isReMaterializable = ReMat;
162 }
163 // register
164 def r : T2I<(outs GPR:$dst), (ins GPR:$src),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000165 opc, ".w $dst, $src",
Evan Chenga67efd12009-06-23 19:39:13 +0000166 [(set GPR:$dst, (opnode GPR:$src))]>;
167 // shifted register
168 def s : T2I<(outs GPR:$dst), (ins t2_so_reg:$src),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000169 opc, ".w $dst, $src",
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000170 [(set GPR:$dst, (opnode t2_so_reg:$src))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000171}
172
173/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000174// binary operation that produces a value. These are predicable and can be
175/// changed to modify CPSR.
David Goodwin1f096272009-07-27 23:34:12 +0000176multiclass T2I_bin_irs<string opc, PatFrag opnode,
177 bit Commutable = 0, string wide =""> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000178 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000179 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
180 opc, " $dst, $lhs, $rhs",
181 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000182 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000183 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwin1f096272009-07-27 23:34:12 +0000184 opc, !strconcat(wide, " $dst, $lhs, $rhs"),
Evan Cheng8de898a2009-06-26 00:19:44 +0000185 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
186 let isCommutable = Commutable;
187 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000188 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000189 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwin1f096272009-07-27 23:34:12 +0000190 opc, !strconcat(wide, " $dst, $lhs, $rhs"),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000191 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000192}
193
David Goodwin1f096272009-07-27 23:34:12 +0000194/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
195// the ".w" prefix to indicate that they are wide.
196multiclass T2I_bin_w_irs<string opc, PatFrag opnode, bit Commutable = 0> :
197 T2I_bin_irs<opc, opnode, Commutable, ".w">;
198
Evan Cheng1e249e32009-06-25 20:59:23 +0000199/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
200/// reversed. It doesn't define the 'rr' form since it's handled by its
201/// T2I_bin_irs counterpart.
202multiclass T2I_rbin_is<string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000203 // shifted imm
204 def ri : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000205 opc, ".w $dst, $rhs, $lhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000206 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
207 // shifted register
208 def rs : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000209 opc, " $dst, $rhs, $lhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000210 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
211}
212
Evan Chenga67efd12009-06-23 19:39:13 +0000213/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000214/// instruction modifies the CPSR register.
215let Defs = [CPSR] in {
Evan Cheng8de898a2009-06-26 00:19:44 +0000216multiclass T2I_bin_s_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000217 // shifted imm
Evan Chengf49810c2009-06-23 17:48:47 +0000218 def ri : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000219 !strconcat(opc, "s"), ".w $dst, $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000220 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000221 // register
222 def rr : T2I<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000223 !strconcat(opc, "s"), ".w $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000224 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
225 let isCommutable = Commutable;
226 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000227 // shifted register
Evan Chengf49810c2009-06-23 17:48:47 +0000228 def rs : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000229 !strconcat(opc, "s"), ".w $dst, $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000230 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000231}
232}
233
Evan Chenga67efd12009-06-23 19:39:13 +0000234/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
235/// patterns for a binary operation that produces a value.
Evan Cheng8de898a2009-06-26 00:19:44 +0000236multiclass T2I_bin_ii12rs<string opc, PatFrag opnode, bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000237 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000238 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000239 opc, ".w $dst, $lhs, $rhs",
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000240 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000241 // 12-bit imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000242 def ri12 : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
243 !strconcat(opc, "w"), " $dst, $lhs, $rhs",
244 [(set GPR:$dst, (opnode GPR:$lhs, imm0_4095:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000245 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000246 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000247 opc, ".w $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000248 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
249 let isCommutable = Commutable;
250 }
Evan Chengf49810c2009-06-23 17:48:47 +0000251 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000252 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000253 opc, ".w $dst, $lhs, $rhs",
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000254 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000255}
256
Evan Cheng62674222009-06-25 23:34:10 +0000257/// 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 +0000258/// binary operation that produces a value and use and define the carry bit.
259/// It's not predicable.
Evan Cheng62674222009-06-25 23:34:10 +0000260let Uses = [CPSR] in {
Evan Cheng8de898a2009-06-26 00:19:44 +0000261multiclass T2I_adde_sube_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000262 // shifted imm
Evan Cheng62674222009-06-25 23:34:10 +0000263 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000264 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000265 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000266 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000267 // register
Evan Cheng62674222009-06-25 23:34:10 +0000268 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000269 opc, ".w $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000270 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000271 Requires<[IsThumb2, CarryDefIsUnused]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000272 let isCommutable = Commutable;
273 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000274 // shifted register
Evan Cheng62674222009-06-25 23:34:10 +0000275 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000276 opc, ".w $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000277 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000278 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Cheng62674222009-06-25 23:34:10 +0000279 // Carry setting variants
280 // shifted imm
281 def Sri : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
282 !strconcat(opc, "s $dst, $lhs, $rhs"),
283 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000284 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000285 let Defs = [CPSR];
286 }
287 // register
288 def Srr : T2XI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000289 !strconcat(opc, "s.w $dst, $lhs, $rhs"),
Evan Cheng62674222009-06-25 23:34:10 +0000290 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000291 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000292 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000293 let isCommutable = Commutable;
294 }
Evan Cheng62674222009-06-25 23:34:10 +0000295 // shifted register
296 def Srs : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000297 !strconcat(opc, "s.w $dst, $lhs, $rhs"),
Evan Cheng62674222009-06-25 23:34:10 +0000298 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000299 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000300 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000301 }
Evan Chengf49810c2009-06-23 17:48:47 +0000302}
303}
304
David Goodwinaf0d08d2009-07-27 16:31:55 +0000305/// T2I_rbin_s_is - Same as T2I_rbin_is except sets 's' bit.
Evan Cheng1e249e32009-06-25 20:59:23 +0000306let Defs = [CPSR] in {
307multiclass T2I_rbin_s_is<string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000308 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000309 def ri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs, cc_out:$s),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000310 !strconcat(opc, "${s}.w $dst, $rhs, $lhs"),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000311 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000312 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000313 def rs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs, cc_out:$s),
314 !strconcat(opc, "${s} $dst, $rhs, $lhs"),
315 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000316}
317}
318
Evan Chenga67efd12009-06-23 19:39:13 +0000319/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
320// rotate operation that produces a value.
321multiclass T2I_sh_ir<string opc, PatFrag opnode> {
322 // 5-bit imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000323 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000324 opc, ".w $dst, $lhs, $rhs",
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000325 [(set GPR:$dst, (opnode GPR:$lhs, imm1_31:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000326 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000327 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000328 opc, ".w $dst, $lhs, $rhs",
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000329 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000330}
Evan Chengf49810c2009-06-23 17:48:47 +0000331
Evan Chenga67efd12009-06-23 19:39:13 +0000332/// T21_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
333/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000334/// a explicit result, only implicitly set CPSR.
David Goodwinc27a4542009-07-20 22:13:31 +0000335let Defs = [CPSR] in {
Evan Chengf49810c2009-06-23 17:48:47 +0000336multiclass T2I_cmp_is<string opc, PatFrag opnode> {
337 // shifted imm
338 def ri : T2I<(outs), (ins GPR:$lhs, t2_so_imm:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000339 opc, ".w $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000340 [(opnode GPR:$lhs, t2_so_imm:$rhs)]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000341 // register
342 def rr : T2I<(outs), (ins GPR:$lhs, GPR:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000343 opc, ".w $lhs, $rhs",
Evan Chenga67efd12009-06-23 19:39:13 +0000344 [(opnode GPR:$lhs, GPR:$rhs)]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000345 // shifted register
346 def rs : T2I<(outs), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000347 opc, ".w $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000348 [(opnode GPR:$lhs, t2_so_reg:$rhs)]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000349}
350}
351
Evan Chengf3c21b82009-06-30 02:15:48 +0000352/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
353multiclass T2I_ld<string opc, PatFrag opnode> {
354 def i12 : T2Ii12<(outs GPR:$dst), (ins t2addrmode_imm12:$addr),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000355 opc, ".w $dst, $addr",
Evan Chengf3c21b82009-06-30 02:15:48 +0000356 [(set GPR:$dst, (opnode t2addrmode_imm12:$addr))]>;
357 def i8 : T2Ii8 <(outs GPR:$dst), (ins t2addrmode_imm8:$addr),
358 opc, " $dst, $addr",
359 [(set GPR:$dst, (opnode t2addrmode_imm8:$addr))]>;
360 def s : T2Iso <(outs GPR:$dst), (ins t2addrmode_so_reg:$addr),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000361 opc, ".w $dst, $addr",
Evan Chengf3c21b82009-06-30 02:15:48 +0000362 [(set GPR:$dst, (opnode t2addrmode_so_reg:$addr))]>;
363 def pci : T2Ipc <(outs GPR:$dst), (ins i32imm:$addr),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000364 opc, ".w $dst, $addr",
Evan Chengf3c21b82009-06-30 02:15:48 +0000365 [(set GPR:$dst, (opnode (ARMWrapper tconstpool:$addr)))]>;
366}
367
David Goodwin73b8f162009-06-30 22:11:34 +0000368/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
369multiclass T2I_st<string opc, PatFrag opnode> {
370 def i12 : T2Ii12<(outs), (ins GPR:$src, t2addrmode_imm12:$addr),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000371 opc, ".w $src, $addr",
David Goodwin73b8f162009-06-30 22:11:34 +0000372 [(opnode GPR:$src, t2addrmode_imm12:$addr)]>;
373 def i8 : T2Ii8 <(outs), (ins GPR:$src, t2addrmode_imm8:$addr),
374 opc, " $src, $addr",
375 [(opnode GPR:$src, t2addrmode_imm8:$addr)]>;
376 def s : T2Iso <(outs), (ins GPR:$src, t2addrmode_so_reg:$addr),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000377 opc, ".w $src, $addr",
David Goodwin73b8f162009-06-30 22:11:34 +0000378 [(opnode GPR:$src, t2addrmode_so_reg:$addr)]>;
379}
380
David Goodwind1fa1202009-07-01 00:01:13 +0000381/// T2I_picld - Defines the PIC load pattern.
382class T2I_picld<string opc, PatFrag opnode> :
383 T2I<(outs GPR:$dst), (ins addrmodepc:$addr),
384 !strconcat("${addr:label}:\n\t", opc), " $dst, $addr",
385 [(set GPR:$dst, (opnode addrmodepc:$addr))]>;
386
387/// T2I_picst - Defines the PIC store pattern.
388class T2I_picst<string opc, PatFrag opnode> :
389 T2I<(outs), (ins GPR:$src, addrmodepc:$addr),
390 !strconcat("${addr:label}:\n\t", opc), " $src, $addr",
391 [(opnode GPR:$src, addrmodepc:$addr)]>;
392
Evan Chengd27c9fc2009-07-03 01:43:10 +0000393
394/// T2I_unary_rrot - A unary operation with two forms: one whose operand is a
395/// register and one whose operand is a register rotated by 8/16/24.
396multiclass T2I_unary_rrot<string opc, PatFrag opnode> {
397 def r : T2I<(outs GPR:$dst), (ins GPR:$Src),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000398 opc, ".w $dst, $Src",
Evan Chengd27c9fc2009-07-03 01:43:10 +0000399 [(set GPR:$dst, (opnode GPR:$Src))]>;
400 def r_rot : T2I<(outs GPR:$dst), (ins GPR:$Src, i32imm:$rot),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000401 opc, ".w $dst, $Src, ror $rot",
Evan Chengd27c9fc2009-07-03 01:43:10 +0000402 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>;
403}
404
405/// T2I_bin_rrot - A binary operation with two forms: one whose operand is a
406/// register and one whose operand is a register rotated by 8/16/24.
407multiclass T2I_bin_rrot<string opc, PatFrag opnode> {
408 def rr : T2I<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
409 opc, " $dst, $LHS, $RHS",
410 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>;
411 def rr_rot : T2I<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
412 opc, " $dst, $LHS, $RHS, ror $rot",
413 [(set GPR:$dst, (opnode GPR:$LHS,
414 (rotr GPR:$RHS, rot_imm:$rot)))]>;
415}
416
Anton Korobeynikov52237112009-06-17 18:13:58 +0000417//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000418// Instructions
419//===----------------------------------------------------------------------===//
420
421//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +0000422// Miscellaneous Instructions.
423//
424
425let isNotDuplicable = 1 in
David Goodwinf1daf7d2009-07-08 23:10:31 +0000426def t2PICADD : T2XI<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000427 "$cp:\n\tadd.w $dst, $lhs, pc",
David Goodwinf1daf7d2009-07-08 23:10:31 +0000428 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000429
430
431// LEApcrel - Load a pc-relative address into a register without offending the
432// assembler.
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000433def t2LEApcrel : T2XI<(outs GPR:$dst), (ins i32imm:$label, pred:$p),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000434 "adr$p.w $dst, #$label", []>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000435
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000436def t2LEApcrelJT : T2XI<(outs GPR:$dst),
Evan Cheng81c102b2009-07-23 18:26:03 +0000437 (ins i32imm:$label, i32imm:$id, pred:$p),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000438 "adr$p.w $dst, #${label}_${id:no_hash}", []>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000439
440//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000441// Load / store Instructions.
442//
443
Evan Cheng055b0312009-06-29 07:51:04 +0000444// Load
Evan Chengf3c21b82009-06-30 02:15:48 +0000445let canFoldAsLoad = 1 in
446defm t2LDR : T2I_ld<"ldr", UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000447
Evan Chengf3c21b82009-06-30 02:15:48 +0000448// Loads with zero extension
449defm t2LDRH : T2I_ld<"ldrh", UnOpFrag<(zextloadi16 node:$Src)>>;
450defm t2LDRB : T2I_ld<"ldrb", UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000451
Evan Chengf3c21b82009-06-30 02:15:48 +0000452// Loads with sign extension
453defm t2LDRSH : T2I_ld<"ldrsh", UnOpFrag<(sextloadi16 node:$Src)>>;
454defm t2LDRSB : T2I_ld<"ldrsb", UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000455
Evan Chengf3c21b82009-06-30 02:15:48 +0000456let mayLoad = 1 in {
457// Load doubleword
David Goodwin6647cea2009-06-30 22:50:01 +0000458def t2LDRDi8 : T2Ii8s4<(outs GPR:$dst), (ins t2addrmode_imm8s4:$addr),
Evan Chengf3c21b82009-06-30 02:15:48 +0000459 "ldrd", " $dst, $addr", []>;
460def t2LDRDpci : T2Ii8s4<(outs GPR:$dst), (ins i32imm:$addr),
461 "ldrd", " $dst, $addr", []>;
462}
463
464// zextload i1 -> zextload i8
465def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
466 (t2LDRBi12 t2addrmode_imm12:$addr)>;
467def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
468 (t2LDRBi8 t2addrmode_imm8:$addr)>;
469def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
470 (t2LDRBs t2addrmode_so_reg:$addr)>;
471def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
472 (t2LDRBpci tconstpool:$addr)>;
473
474// extload -> zextload
475// FIXME: Reduce the number of patterns by legalizing extload to zextload
476// earlier?
477def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
478 (t2LDRBi12 t2addrmode_imm12:$addr)>;
479def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
480 (t2LDRBi8 t2addrmode_imm8:$addr)>;
481def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
482 (t2LDRBs t2addrmode_so_reg:$addr)>;
483def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
484 (t2LDRBpci tconstpool:$addr)>;
485
486def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
487 (t2LDRBi12 t2addrmode_imm12:$addr)>;
488def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
489 (t2LDRBi8 t2addrmode_imm8:$addr)>;
490def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
491 (t2LDRBs t2addrmode_so_reg:$addr)>;
492def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
493 (t2LDRBpci tconstpool:$addr)>;
494
495def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
496 (t2LDRHi12 t2addrmode_imm12:$addr)>;
497def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
498 (t2LDRHi8 t2addrmode_imm8:$addr)>;
499def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
500 (t2LDRHs t2addrmode_so_reg:$addr)>;
501def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
502 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +0000503
Evan Chenge88d5ce2009-07-02 07:28:31 +0000504// Indexed loads
Evan Cheng78236f82009-07-03 00:08:19 +0000505let mayLoad = 1 in {
Evan Chenge88d5ce2009-07-02 07:28:31 +0000506def t2LDR_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
507 (ins t2addrmode_imm8:$addr),
508 AddrModeT2_i8, IndexModePre,
509 "ldr", " $dst, $addr!", "$addr.base = $base_wb",
510 []>;
511
512def t2LDR_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
513 (ins GPR:$base, t2am_imm8_offset:$offset),
514 AddrModeT2_i8, IndexModePost,
515 "ldr", " $dst, [$base], $offset", "$base = $base_wb",
516 []>;
517
518def t2LDRB_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
519 (ins t2addrmode_imm8:$addr),
520 AddrModeT2_i8, IndexModePre,
521 "ldrb", " $dst, $addr!", "$addr.base = $base_wb",
522 []>;
523def t2LDRB_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
524 (ins GPR:$base, t2am_imm8_offset:$offset),
525 AddrModeT2_i8, IndexModePost,
526 "ldrb", " $dst, [$base], $offset", "$base = $base_wb",
527 []>;
528
529def t2LDRH_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
530 (ins t2addrmode_imm8:$addr),
531 AddrModeT2_i8, IndexModePre,
532 "ldrh", " $dst, $addr!", "$addr.base = $base_wb",
533 []>;
534def t2LDRH_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
535 (ins GPR:$base, t2am_imm8_offset:$offset),
536 AddrModeT2_i8, IndexModePost,
537 "ldrh", " $dst, [$base], $offset", "$base = $base_wb",
538 []>;
539
Evan Cheng4fbb9962009-07-02 23:16:11 +0000540def t2LDRSB_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
541 (ins t2addrmode_imm8:$addr),
542 AddrModeT2_i8, IndexModePre,
543 "ldrsb", " $dst, $addr!", "$addr.base = $base_wb",
544 []>;
545def t2LDRSB_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
546 (ins GPR:$base, t2am_imm8_offset:$offset),
547 AddrModeT2_i8, IndexModePost,
548 "ldrsb", " $dst, [$base], $offset", "$base = $base_wb",
549 []>;
550
551def t2LDRSH_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
552 (ins t2addrmode_imm8:$addr),
553 AddrModeT2_i8, IndexModePre,
554 "ldrsh", " $dst, $addr!", "$addr.base = $base_wb",
555 []>;
556def t2LDRSH_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
557 (ins GPR:$base, t2am_imm8_offset:$offset),
558 AddrModeT2_i8, IndexModePost,
559 "ldrsh", " $dst, [$base], $offset", "$base = $base_wb",
560 []>;
Evan Cheng78236f82009-07-03 00:08:19 +0000561}
Evan Cheng4fbb9962009-07-02 23:16:11 +0000562
David Goodwin73b8f162009-06-30 22:11:34 +0000563// Store
Evan Chenge88d5ce2009-07-02 07:28:31 +0000564defm t2STR : T2I_st<"str", BinOpFrag<(store node:$LHS, node:$RHS)>>;
565defm t2STRB : T2I_st<"strb", BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
566defm t2STRH : T2I_st<"strh", BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
David Goodwin73b8f162009-06-30 22:11:34 +0000567
David Goodwin6647cea2009-06-30 22:50:01 +0000568// Store doubleword
569let mayLoad = 1 in
570def t2STRDi8 : T2Ii8s4<(outs), (ins GPR:$src, t2addrmode_imm8s4:$addr),
571 "strd", " $src, $addr", []>;
572
Evan Cheng6d94f112009-07-03 00:06:39 +0000573// Indexed stores
574def t2STR_PRE : T2Iidxldst<(outs GPR:$base_wb),
575 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
576 AddrModeT2_i8, IndexModePre,
577 "str", " $src, [$base, $offset]!", "$base = $base_wb",
578 [(set GPR:$base_wb,
579 (pre_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
580
581def t2STR_POST : T2Iidxldst<(outs GPR:$base_wb),
582 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
583 AddrModeT2_i8, IndexModePost,
584 "str", " $src, [$base], $offset", "$base = $base_wb",
585 [(set GPR:$base_wb,
586 (post_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
587
588def t2STRH_PRE : T2Iidxldst<(outs GPR:$base_wb),
589 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
590 AddrModeT2_i8, IndexModePre,
591 "strh", " $src, [$base, $offset]!", "$base = $base_wb",
592 [(set GPR:$base_wb,
593 (pre_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
594
595def t2STRH_POST : T2Iidxldst<(outs GPR:$base_wb),
596 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
597 AddrModeT2_i8, IndexModePost,
598 "strh", " $src, [$base], $offset", "$base = $base_wb",
599 [(set GPR:$base_wb,
600 (post_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
601
602def t2STRB_PRE : T2Iidxldst<(outs GPR:$base_wb),
603 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
604 AddrModeT2_i8, IndexModePre,
605 "strb", " $src, [$base, $offset]!", "$base = $base_wb",
606 [(set GPR:$base_wb,
607 (pre_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
608
609def t2STRB_POST : T2Iidxldst<(outs GPR:$base_wb),
610 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
611 AddrModeT2_i8, IndexModePost,
612 "strb", " $src, [$base], $offset", "$base = $base_wb",
613 [(set GPR:$base_wb,
614 (post_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
615
David Goodwind1fa1202009-07-01 00:01:13 +0000616
Evan Cheng5c874172009-07-09 22:21:59 +0000617// FIXME: ldrd / strd pre / post variants
Evan Cheng2889cce2009-07-03 00:18:36 +0000618
619//===----------------------------------------------------------------------===//
620// Load / store multiple Instructions.
621//
622
623let mayLoad = 1 in
624def t2LDM : T2XI<(outs),
625 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000626 "ldm${addr:submode}${p} $addr, $dst1", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +0000627
628let mayStore = 1 in
629def t2STM : T2XI<(outs),
630 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000631 "stm${addr:submode}${p} $addr, $src1", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +0000632
Evan Cheng9cb9e672009-06-27 02:26:13 +0000633//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000634// Move Instructions.
635//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000636
Evan Chengf49810c2009-06-23 17:48:47 +0000637let neverHasSideEffects = 1 in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000638def t2MOVr : T2sI<(outs GPR:$dst), (ins GPR:$src),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000639 "mov", ".w $dst, $src", []>;
Evan Chengf49810c2009-06-23 17:48:47 +0000640
Evan Chenga67efd12009-06-23 19:39:13 +0000641let isReMaterializable = 1, isAsCheapAsAMove = 1 in
David Goodwin83b35932009-06-26 16:10:07 +0000642def t2MOVi : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000643 "mov", ".w $dst, $src",
David Goodwin83b35932009-06-26 16:10:07 +0000644 [(set GPR:$dst, t2_so_imm:$src)]>;
645
646let isReMaterializable = 1, isAsCheapAsAMove = 1 in
647def t2MOVi16 : T2I<(outs GPR:$dst), (ins i32imm:$src),
648 "movw", " $dst, $src",
649 [(set GPR:$dst, imm0_65535:$src)]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000650
Evan Chengf49810c2009-06-23 17:48:47 +0000651// FIXME: Also available in ARM mode.
Evan Cheng3850a6a2009-06-23 05:23:49 +0000652let Constraints = "$src = $dst" in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000653def t2MOVTi16 : T2sI<(outs GPR:$dst), (ins GPR:$src, i32imm:$imm),
654 "movt", " $dst, $imm",
655 [(set GPR:$dst,
656 (or (and GPR:$src, 0xffff), t2_lo16AllZero:$imm))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000657
658//===----------------------------------------------------------------------===//
Evan Chengd27c9fc2009-07-03 01:43:10 +0000659// Extend Instructions.
660//
661
662// Sign extenders
663
664defm t2SXTB : T2I_unary_rrot<"sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
665defm t2SXTH : T2I_unary_rrot<"sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
666
667defm t2SXTAB : T2I_bin_rrot<"sxtab",
668 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
669defm t2SXTAH : T2I_bin_rrot<"sxtah",
670 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
671
672// TODO: SXT(A){B|H}16
673
674// Zero extenders
675
676let AddedComplexity = 16 in {
677defm t2UXTB : T2I_unary_rrot<"uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
678defm t2UXTH : T2I_unary_rrot<"uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
679defm t2UXTB16 : T2I_unary_rrot<"uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
680
681def : T2Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
682 (t2UXTB16r_rot GPR:$Src, 24)>;
683def : T2Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
684 (t2UXTB16r_rot GPR:$Src, 8)>;
685
686defm t2UXTAB : T2I_bin_rrot<"uxtab",
687 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
688defm t2UXTAH : T2I_bin_rrot<"uxtah",
689 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
690}
691
692//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000693// Arithmetic Instructions.
694//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000695
Evan Cheng8de898a2009-06-26 00:19:44 +0000696defm t2ADD : T2I_bin_ii12rs<"add", BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
Evan Chenga67efd12009-06-23 19:39:13 +0000697defm t2SUB : T2I_bin_ii12rs<"sub", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000698
Evan Chengf49810c2009-06-23 17:48:47 +0000699// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Evan Cheng8de898a2009-06-26 00:19:44 +0000700defm t2ADDS : T2I_bin_s_irs <"add", BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
Evan Cheng1e249e32009-06-25 20:59:23 +0000701defm t2SUBS : T2I_bin_s_irs <"sub", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000702
Evan Cheng8de898a2009-06-26 00:19:44 +0000703defm t2ADC : T2I_adde_sube_irs<"adc",BinOpFrag<(adde node:$LHS, node:$RHS)>,1>;
704defm t2SBC : T2I_adde_sube_irs<"sbc",BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000705
David Goodwin752aa7d2009-07-27 16:39:05 +0000706// RSB
Evan Cheng1e249e32009-06-25 20:59:23 +0000707defm t2RSB : T2I_rbin_is <"rsb", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
708defm t2RSBS : T2I_rbin_s_is <"rsb", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000709
710// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000711let AddedComplexity = 1 in
712def : T2Pat<(add GPR:$src, imm0_255_neg:$imm),
713 (t2SUBri GPR:$src, imm0_255_neg:$imm)>;
Evan Cheng9cb9e672009-06-27 02:26:13 +0000714def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
715 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
716def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
717 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000718
719
Evan Chengf49810c2009-06-23 17:48:47 +0000720//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +0000721// Shift and rotate Instructions.
722//
723
724defm t2LSL : T2I_sh_ir<"lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
725defm t2LSR : T2I_sh_ir<"lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
726defm t2ASR : T2I_sh_ir<"asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
727defm t2ROR : T2I_sh_ir<"ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
728
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000729def t2MOVrx : T2sI<(outs GPR:$dst), (ins GPR:$src),
David Goodwin7c92f3a2009-07-30 21:38:40 +0000730 "rrx", ".w $dst, $src",
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000731 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000732
David Goodwin3583df72009-07-28 17:06:49 +0000733let Defs = [CPSR] in {
734def t2MOVsrl_flag : T2XI<(outs GPR:$dst), (ins GPR:$src),
735 "lsrs.w $dst, $src, #1",
736 [(set GPR:$dst, (ARMsrl_flag GPR:$src))]>;
737def t2MOVsra_flag : T2XI<(outs GPR:$dst), (ins GPR:$src),
738 "asrs.w $dst, $src, #1",
739 [(set GPR:$dst, (ARMsra_flag GPR:$src))]>;
740}
741
Evan Chenga67efd12009-06-23 19:39:13 +0000742//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +0000743// Bitwise Instructions.
744//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000745
David Goodwin1f096272009-07-27 23:34:12 +0000746defm t2AND : T2I_bin_w_irs<"and", BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
747defm t2ORR : T2I_bin_w_irs<"orr", BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
748defm t2EOR : T2I_bin_w_irs<"eor", BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +0000749
David Goodwin1f096272009-07-27 23:34:12 +0000750defm t2BIC : T2I_bin_w_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000751
Evan Chengf49810c2009-06-23 17:48:47 +0000752let Constraints = "$src = $dst" in
753def t2BFC : T2I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000754 "bfc", " $dst, $imm",
Evan Chengf49810c2009-06-23 17:48:47 +0000755 [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>;
756
757// FIXME: A8.6.18 BFI - Bitfield insert (Encoding T1)
758
Evan Cheng25f7cfc2009-08-01 06:13:52 +0000759/*
David Goodwin8f652532009-07-30 21:51:41 +0000760defm t2ORN : T2I_bin_irs<"orn", BinOpFrag<(or node:$LHS, (not node:$RHS))>>;
Evan Cheng25f7cfc2009-08-01 06:13:52 +0000761*/
762// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
763def t2ORNri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
764 "orn", " $dst, $lhs, $rhs",
765 [(set GPR:$dst, (or GPR:$lhs, (not t2_so_imm:$rhs)))]>,
766 Requires<[IsThumb2, IsNotDarwin]>;
767
768def t2ORNrr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
769 "orn", " $dst, $lhs, $rhs",
770 [(set GPR:$dst, (or GPR:$lhs, (not GPR:$rhs)))]>;
771def t2ORNrs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
772 "orn", " $dst, $lhs, $rhs",
773 [(set GPR:$dst, (or GPR:$lhs, (not t2_so_reg:$rhs)))]>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +0000774
775// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
776let AddedComplexity = 1 in
777defm t2MVN : T2I_un_irs <"mvn", UnOpFrag<(not node:$Src)>, 1, 1>;
778
779
780def : T2Pat<(and GPR:$src, t2_so_imm_not:$imm),
781 (t2BICri GPR:$src, t2_so_imm_not:$imm)>;
782
Evan Cheng25f7cfc2009-08-01 06:13:52 +0000783// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
David Goodwin8f652532009-07-30 21:51:41 +0000784def : T2Pat<(or GPR:$src, t2_so_imm_not:$imm),
Evan Cheng25f7cfc2009-08-01 06:13:52 +0000785 (t2ORNri GPR:$src, t2_so_imm_not:$imm)>,
786 Requires<[IsThumb2, IsNotDarwin]>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +0000787
788def : T2Pat<(t2_so_imm_not:$src),
789 (t2MVNi t2_so_imm_not:$src)>;
790
Evan Chengf49810c2009-06-23 17:48:47 +0000791//===----------------------------------------------------------------------===//
792// Multiply Instructions.
793//
Evan Cheng8de898a2009-06-26 00:19:44 +0000794let isCommutable = 1 in
Evan Chengf49810c2009-06-23 17:48:47 +0000795def t2MUL: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000796 "mul", " $dst, $a, $b",
Evan Chengf49810c2009-06-23 17:48:47 +0000797 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
798
799def t2MLA: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000800 "mla", " $dst, $a, $b, $c",
Evan Chengf49810c2009-06-23 17:48:47 +0000801 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
802
803def t2MLS: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000804 "mls", " $dst, $a, $b, $c",
Evan Chengf49810c2009-06-23 17:48:47 +0000805 [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>;
806
Evan Cheng5b9fcd12009-07-07 01:17:28 +0000807// Extra precision multiplies with low / high results
808let neverHasSideEffects = 1 in {
809let isCommutable = 1 in {
810def t2SMULL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
811 "smull", " $ldst, $hdst, $a, $b", []>;
812
813def t2UMULL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
814 "umull", " $ldst, $hdst, $a, $b", []>;
815}
816
817// Multiply + accumulate
818def t2SMLAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
819 "smlal", " $ldst, $hdst, $a, $b", []>;
820
821def t2UMLAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
822 "umlal", " $ldst, $hdst, $a, $b", []>;
823
824def t2UMAAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
825 "umaal", " $ldst, $hdst, $a, $b", []>;
826} // neverHasSideEffects
827
828// Most significant word multiply
829def t2SMMUL : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
830 "smmul", " $dst, $a, $b",
831 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>;
832
833def t2SMMLA : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
834 "smmla", " $dst, $a, $b, $c",
835 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>;
836
837
838def t2SMMLS : T2I <(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
839 "smmls", " $dst, $a, $b, $c",
840 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>;
841
842multiclass T2I_smul<string opc, PatFrag opnode> {
843 def BB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
844 !strconcat(opc, "bb"), " $dst, $a, $b",
845 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
846 (sext_inreg GPR:$b, i16)))]>;
847
848 def BT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
849 !strconcat(opc, "bt"), " $dst, $a, $b",
850 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
851 (sra GPR:$b, (i32 16))))]>;
852
853 def TB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
854 !strconcat(opc, "tb"), " $dst, $a, $b",
855 [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
856 (sext_inreg GPR:$b, i16)))]>;
857
858 def TT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
859 !strconcat(opc, "tt"), " $dst, $a, $b",
860 [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
861 (sra GPR:$b, (i32 16))))]>;
862
863 def WB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
864 !strconcat(opc, "wb"), " $dst, $a, $b",
865 [(set GPR:$dst, (sra (opnode GPR:$a,
866 (sext_inreg GPR:$b, i16)), (i32 16)))]>;
867
868 def WT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
869 !strconcat(opc, "wt"), " $dst, $a, $b",
870 [(set GPR:$dst, (sra (opnode GPR:$a,
871 (sra GPR:$b, (i32 16))), (i32 16)))]>;
872}
873
874
875multiclass T2I_smla<string opc, PatFrag opnode> {
876 def BB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
877 !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
878 [(set GPR:$dst, (add GPR:$acc,
879 (opnode (sext_inreg GPR:$a, i16),
880 (sext_inreg GPR:$b, i16))))]>;
881
882 def BT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
883 !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
884 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
885 (sra GPR:$b, (i32 16)))))]>;
886
887 def TB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
888 !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
889 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
890 (sext_inreg GPR:$b, i16))))]>;
891
892 def TT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
893 !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
894 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
895 (sra GPR:$b, (i32 16)))))]>;
896
897 def WB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
898 !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
899 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
900 (sext_inreg GPR:$b, i16)), (i32 16))))]>;
901
902 def WT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
903 !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
904 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
905 (sra GPR:$b, (i32 16))), (i32 16))))]>;
906}
907
908defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
909defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
910
911// TODO: Halfword multiple accumulate long: SMLAL<x><y>
912// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
913
Evan Chengf49810c2009-06-23 17:48:47 +0000914
915//===----------------------------------------------------------------------===//
916// Misc. Arithmetic Instructions.
917//
918
Evan Chengf49810c2009-06-23 17:48:47 +0000919def t2CLZ : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000920 "clz", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000921 [(set GPR:$dst, (ctlz GPR:$src))]>;
922
923def t2REV : T2I<(outs GPR:$dst), (ins GPR:$src),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000924 "rev", ".w $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000925 [(set GPR:$dst, (bswap GPR:$src))]>;
926
927def t2REV16 : T2I<(outs GPR:$dst), (ins GPR:$src),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000928 "rev16", ".w $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000929 [(set GPR:$dst,
930 (or (and (srl GPR:$src, (i32 8)), 0xFF),
931 (or (and (shl GPR:$src, (i32 8)), 0xFF00),
932 (or (and (srl GPR:$src, (i32 8)), 0xFF0000),
933 (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>;
934
Evan Chengf49810c2009-06-23 17:48:47 +0000935def t2REVSH : T2I<(outs GPR:$dst), (ins GPR:$src),
David Goodwinaf0d08d2009-07-27 16:31:55 +0000936 "revsh", ".w $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000937 [(set GPR:$dst,
938 (sext_inreg
939 (or (srl (and GPR:$src, 0xFFFF), (i32 8)),
940 (shl GPR:$src, (i32 8))), i16))]>;
941
Evan Cheng40289b02009-07-07 05:35:52 +0000942def t2PKHBT : T2I<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
943 "pkhbt", " $dst, $src1, $src2, LSL $shamt",
944 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
945 (and (shl GPR:$src2, (i32 imm:$shamt)),
946 0xFFFF0000)))]>;
947
948// Alternate cases for PKHBT where identities eliminate some nodes.
949def : T2Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
950 (t2PKHBT GPR:$src1, GPR:$src2, 0)>;
951def : T2Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
952 (t2PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
953
954def t2PKHTB : T2I<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
955 "pkhtb", " $dst, $src1, $src2, ASR $shamt",
956 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
957 (and (sra GPR:$src2, imm16_31:$shamt),
958 0xFFFF)))]>;
959
960// Alternate cases for PKHTB where identities eliminate some nodes. Note that
961// a shift amount of 0 is *not legal* here, it is PKHBT instead.
962def : T2Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, (i32 16))),
963 (t2PKHTB GPR:$src1, GPR:$src2, 16)>;
964def : T2Pat<(or (and GPR:$src1, 0xFFFF0000),
965 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
966 (t2PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000967
968//===----------------------------------------------------------------------===//
969// Comparison Instructions...
970//
971
972defm t2CMP : T2I_cmp_is<"cmp",
973 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
David Goodwinc0309b42009-06-29 15:33:01 +0000974defm t2CMPz : T2I_cmp_is<"cmp",
975 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000976
977defm t2CMN : T2I_cmp_is<"cmn",
978 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
David Goodwinc0309b42009-06-29 15:33:01 +0000979defm t2CMNz : T2I_cmp_is<"cmn",
980 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000981
Evan Cheng9cb9e672009-06-27 02:26:13 +0000982def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
983 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000984
David Goodwinc0309b42009-06-29 15:33:01 +0000985def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
Evan Cheng9cb9e672009-06-27 02:26:13 +0000986 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000987
David Goodwinbaeb9112009-06-29 22:49:42 +0000988defm t2TST : T2I_cmp_is<"tst",
989 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>>;
990defm t2TEQ : T2I_cmp_is<"teq",
991 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000992
993// A8.6.27 CBNZ, CBZ - Compare and branch on (non)zero.
994// Short range conditional branch. Looks awesome for loops. Need to figure
995// out how to use this one.
996
Evan Chenge253c952009-07-07 20:39:03 +0000997
998// Conditional moves
999// FIXME: should be able to write a pattern for ARMcmov, but can't use
1000// a two-value operand where a dag node expects two operands. :(
1001def t2MOVCCr : T2I<(outs GPR:$dst), (ins GPR:$false, GPR:$true),
Evan Cheng11197762009-07-31 22:21:55 +00001002 "mov", ".w $dst, $true",
Evan Chenge253c952009-07-07 20:39:03 +00001003 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1004 RegConstraint<"$false = $dst">;
1005
Evan Chenge253c952009-07-07 20:39:03 +00001006def t2MOVCCi : T2I<(outs GPR:$dst), (ins GPR:$false, t2_so_imm:$true),
Evan Cheng11197762009-07-31 22:21:55 +00001007 "mov", ".w $dst, $true",
Evan Chenge253c952009-07-07 20:39:03 +00001008[/*(set GPR:$dst, (ARMcmov GPR:$false, t2_so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1009 RegConstraint<"$false = $dst">;
Evan Chengf49810c2009-06-23 17:48:47 +00001010
Evan Cheng13f8b362009-08-01 01:43:45 +00001011def t2MOVCClsl : T2I<(outs GPR:$dst), (ins GPR:$false, GPR:$true, i32imm:$rhs),
1012 "lsl", ".w $dst, $true, $rhs", []>,
1013 RegConstraint<"$false = $dst">;
1014def t2MOVCClsr : T2I<(outs GPR:$dst), (ins GPR:$false, GPR:$true, i32imm:$rhs),
1015 "lsr", ".w $dst, $true, $rhs", []>,
1016 RegConstraint<"$false = $dst">;
1017def t2MOVCCasr : T2I<(outs GPR:$dst), (ins GPR:$false, GPR:$true, i32imm:$rhs),
1018 "asr", ".w $dst, $true, $rhs", []>,
1019 RegConstraint<"$false = $dst">;
1020def t2MOVCCror : T2I<(outs GPR:$dst), (ins GPR:$false, GPR:$true, i32imm:$rhs),
1021 "ror", ".w $dst, $true, $rhs", []>,
1022 RegConstraint<"$false = $dst">;
1023
David Goodwin5e47a9a2009-06-30 18:04:13 +00001024//===----------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +00001025// TLS Instructions
1026//
1027
1028// __aeabi_read_tp preserves the registers r1-r3.
1029let isCall = 1,
1030 Defs = [R0, R12, LR, CPSR] in {
1031 def t2TPsoft : T2XI<(outs), (ins),
1032 "bl __aeabi_read_tp",
1033 [(set R0, ARMthread_pointer)]>;
1034}
1035
1036//===----------------------------------------------------------------------===//
David Goodwin5e47a9a2009-06-30 18:04:13 +00001037// Control-Flow Instructions
1038//
1039
Evan Chengc50a1cb2009-07-09 22:58:39 +00001040// FIXME: remove when we have a way to marking a MI with these properties.
1041// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
1042// operand list.
1043// FIXME: Should pc be an implicit operand like PICADD, etc?
1044let isReturn = 1, isTerminator = 1, mayLoad = 1 in
1045 def t2LDM_RET : T2XI<(outs),
1046 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
1047 "ldm${addr:submode}${p} $addr, $dst1",
1048 []>;
1049
David Goodwin5e47a9a2009-06-30 18:04:13 +00001050let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
1051let isPredicable = 1 in
1052def t2B : T2XI<(outs), (ins brtarget:$target),
David Goodwinaf0d08d2009-07-27 16:31:55 +00001053 "b.w $target",
David Goodwin5e47a9a2009-06-30 18:04:13 +00001054 [(br bb:$target)]>;
1055
Evan Cheng5657c012009-07-29 02:18:14 +00001056let isNotDuplicable = 1, isIndirectBranch = 1 in {
Evan Cheng66ac5312009-07-25 00:33:29 +00001057def t2BR_JT :
Evan Cheng5657c012009-07-29 02:18:14 +00001058 T2JTI<(outs),
1059 (ins GPR:$target, GPR:$index, jt2block_operand:$jt, i32imm:$id),
Evan Chenge7c329b2009-07-28 20:53:24 +00001060 "mov pc, $target\n$jt",
Evan Cheng5657c012009-07-29 02:18:14 +00001061 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>;
1062
Evan Cheng25f7cfc2009-08-01 06:13:52 +00001063// FIXME: Add a non-pc based case that can be predicated.
Evan Cheng5657c012009-07-29 02:18:14 +00001064def t2TBB :
Evan Cheng25f7cfc2009-08-01 06:13:52 +00001065 T2JTI<(outs),
Evan Cheng5657c012009-07-29 02:18:14 +00001066 (ins tb_addrmode:$index, jt2block_operand:$jt, i32imm:$id),
Evan Cheng25f7cfc2009-08-01 06:13:52 +00001067 "tbb $index\n$jt", []>;
Evan Cheng5657c012009-07-29 02:18:14 +00001068
1069def t2TBH :
Evan Cheng25f7cfc2009-08-01 06:13:52 +00001070 T2JTI<(outs),
Evan Cheng5657c012009-07-29 02:18:14 +00001071 (ins tb_addrmode:$index, jt2block_operand:$jt, i32imm:$id),
Evan Cheng25f7cfc2009-08-01 06:13:52 +00001072 "tbh $index\n$jt", []>;
Evan Cheng5657c012009-07-29 02:18:14 +00001073} // isNotDuplicable, isIndirectBranch
1074
David Goodwinc9a59b52009-06-30 19:50:22 +00001075} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +00001076
1077// FIXME: should be able to write a pattern for ARMBrcond, but can't use
1078// a two-value operand where a dag node expects two operands. :(
1079let isBranch = 1, isTerminator = 1 in
1080def t2Bcc : T2I<(outs), (ins brtarget:$target),
David Goodwinaf0d08d2009-07-27 16:31:55 +00001081 "b", ".w $target",
David Goodwin5e47a9a2009-06-30 18:04:13 +00001082 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Evan Chengf49810c2009-06-23 17:48:47 +00001083
Evan Cheng06e16582009-07-10 01:54:42 +00001084
1085// IT block
1086def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
1087 AddrModeNone, Size2Bytes,
1088 "it$mask $cc", "", []>;
1089
Evan Chengf49810c2009-06-23 17:48:47 +00001090//===----------------------------------------------------------------------===//
1091// Non-Instruction Patterns
1092//
1093
Evan Chenga09b9ca2009-06-24 23:47:58 +00001094// ConstantPool, GlobalAddress, and JumpTable
Evan Cheng9cb9e672009-06-27 02:26:13 +00001095def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>;
1096def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
1097def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1098 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chenga09b9ca2009-06-24 23:47:58 +00001099
Evan Chengf49810c2009-06-23 17:48:47 +00001100// Large immediate handling.
1101
Evan Cheng9cb9e672009-06-27 02:26:13 +00001102def : T2Pat<(i32 imm:$src),
1103 (t2MOVTi16 (t2MOVi16 (t2_lo16 imm:$src)), (t2_hi16 imm:$src))>;