blob: 11ae0ee75db1ff764f43ebecf5dacdac9292ab96 [file] [log] [blame]
Anton Korobeynikovd4022c32009-05-29 23:41:08 +00001//===- ARMInstrThumb2.td - Thumb2 support for ARM -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb2 instruction set.
11//
12//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +000013
14// Shifted operands. No register controlled shifts for Thumb2.
15// Note: We do not support rrx shifted operands yet.
16def t2_so_reg : Operand<i32>, // reg imm
Evan Cheng9cb9e672009-06-27 02:26:13 +000017 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
Anton Korobeynikov52237112009-06-17 18:13:58 +000018 [shl,srl,sra,rotr]> {
Evan Cheng9cb9e672009-06-27 02:26:13 +000019 let PrintMethod = "printT2SOOperand";
Anton Korobeynikov52237112009-06-17 18:13:58 +000020 let MIOperandInfo = (ops GPR, i32imm);
21}
22
Evan Chengf49810c2009-06-23 17:48:47 +000023// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
24def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
Evan Chenge7cbe412009-07-08 21:03:57 +000025 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000026}]>;
27
Evan Chengf49810c2009-06-23 17:48:47 +000028// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
29def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
Evan Chenge7cbe412009-07-08 21:03:57 +000030 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
Evan Chengf49810c2009-06-23 17:48:47 +000031}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000032
Evan Chengf49810c2009-06-23 17:48:47 +000033// t2_so_imm - Match a 32-bit immediate operand, which is an
34// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
35// immediate splatted into multiple bytes of the word. t2_so_imm values are
36// represented in the imm field in the same 12-bit form that they are encoded
37// into t2_so_imm instructions: the 8-bit immediate is the least significant bits
38// [bits 0-7], the 4-bit shift/splat amount is the next 4 bits [bits 8-11].
39def t2_so_imm : Operand<i32>,
40 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000041 return ARM_AM::getT2SOImmVal((uint32_t)N->getZExtValue()) != -1;
42}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000043
Evan Chengf49810c2009-06-23 17:48:47 +000044// t2_so_imm_not - Match an immediate that is a complement
45// of a t2_so_imm.
46def t2_so_imm_not : Operand<i32>,
47 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000048 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
49}], t2_so_imm_not_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000050
51// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
52def t2_so_imm_neg : Operand<i32>,
53 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000054 return ARM_AM::getT2SOImmVal(-((int)N->getZExtValue())) != -1;
55}], t2_so_imm_neg_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000056
Evan Chenga67efd12009-06-23 19:39:13 +000057/// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
58def imm1_31 : PatLeaf<(i32 imm), [{
59 return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 32;
60}]>;
61
Evan Chengf49810c2009-06-23 17:48:47 +000062/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
63def imm0_4095 : PatLeaf<(i32 imm), [{
64 return (uint32_t)N->getZExtValue() < 4096;
65}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000066
67def imm0_4095_neg : PatLeaf<(i32 imm), [{
Evan Chengf49810c2009-06-23 17:48:47 +000068 return (uint32_t)(-N->getZExtValue()) < 4096;
Anton Korobeynikov52237112009-06-17 18:13:58 +000069}], imm_neg_XFORM>;
70
Evan Chengf49810c2009-06-23 17:48:47 +000071/// imm0_65535 predicate - True if the 32-bit immediate is in the range
72/// [0.65535].
73def imm0_65535 : PatLeaf<(i32 imm), [{
74 return (uint32_t)N->getZExtValue() < 65536;
Anton Korobeynikov52237112009-06-17 18:13:58 +000075}]>;
76
Evan Chengf49810c2009-06-23 17:48:47 +000077/// Split a 32-bit immediate into two 16 bit parts.
78def t2_lo16 : SDNodeXForm<imm, [{
79 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() & 0xffff,
80 MVT::i32);
81}]>;
82
83def t2_hi16 : SDNodeXForm<imm, [{
84 return CurDAG->getTargetConstant((uint32_t)N->getZExtValue() >> 16, MVT::i32);
85}]>;
86
87def t2_lo16AllZero : PatLeaf<(i32 imm), [{
88 // Returns true if all low 16-bits are 0.
89 return (((uint32_t)N->getZExtValue()) & 0xFFFFUL) == 0;
90 }], t2_hi16>;
91
Evan Cheng9cb9e672009-06-27 02:26:13 +000092
Evan Cheng055b0312009-06-29 07:51:04 +000093// Define Thumb2 specific addressing modes.
94
95// t2addrmode_imm12 := reg + imm12
96def t2addrmode_imm12 : Operand<i32>,
97 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
98 let PrintMethod = "printT2AddrModeImm12Operand";
99 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
100}
101
Evan Chenge88d5ce2009-07-02 07:28:31 +0000102// t2addrmode_imm8 := reg - imm8
Evan Cheng055b0312009-06-29 07:51:04 +0000103def t2addrmode_imm8 : Operand<i32>,
104 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
105 let PrintMethod = "printT2AddrModeImm8Operand";
106 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
107}
108
Evan Cheng6d94f112009-07-03 00:06:39 +0000109def t2am_imm8_offset : Operand<i32>,
110 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset", []>{
Evan Chenge88d5ce2009-07-02 07:28:31 +0000111 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
112}
113
David Goodwin6647cea2009-06-30 22:50:01 +0000114// t2addrmode_imm8s4 := reg + (imm8 << 2)
115def t2addrmode_imm8s4 : Operand<i32>,
116 ComplexPattern<i32, 2, "SelectT2AddrModeImm8s4", []> {
117 let PrintMethod = "printT2AddrModeImm8Operand";
118 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
119}
120
Evan Cheng055b0312009-06-29 07:51:04 +0000121// t2addrmode_so_reg := reg + reg << imm2
122def t2addrmode_so_reg : Operand<i32>,
123 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
124 let PrintMethod = "printT2AddrModeSoRegOperand";
125 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
126}
127
128
Anton Korobeynikov52237112009-06-17 18:13:58 +0000129//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000130// Multiclass helpers...
Anton Korobeynikov52237112009-06-17 18:13:58 +0000131//
132
Evan Chenga67efd12009-06-23 19:39:13 +0000133/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000134/// unary operation that produces a value. These are predicable and can be
135/// changed to modify CPSR.
Evan Chenga67efd12009-06-23 19:39:13 +0000136multiclass T2I_un_irs<string opc, PatFrag opnode, bit Cheap = 0, bit ReMat = 0>{
137 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000138 def i : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
139 opc, " $dst, $src",
Evan Chenga67efd12009-06-23 19:39:13 +0000140 [(set GPR:$dst, (opnode t2_so_imm:$src))]> {
141 let isAsCheapAsAMove = Cheap;
142 let isReMaterializable = ReMat;
143 }
144 // register
145 def r : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000146 opc, " $dst, $src",
Evan Chenga67efd12009-06-23 19:39:13 +0000147 [(set GPR:$dst, (opnode GPR:$src))]>;
148 // shifted register
149 def s : T2I<(outs GPR:$dst), (ins t2_so_reg:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000150 opc, " $dst, $src",
151 [(set GPR:$dst, (opnode t2_so_reg:$src))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000152}
153
154/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000155// binary operation that produces a value. These are predicable and can be
156/// changed to modify CPSR.
Evan Cheng8de898a2009-06-26 00:19:44 +0000157multiclass T2I_bin_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000158 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000159 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
160 opc, " $dst, $lhs, $rhs",
161 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000162 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000163 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
164 opc, " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000165 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
166 let isCommutable = Commutable;
167 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000168 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000169 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
170 opc, " $dst, $lhs, $rhs",
171 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000172}
173
Evan Cheng1e249e32009-06-25 20:59:23 +0000174/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
175/// reversed. It doesn't define the 'rr' form since it's handled by its
176/// T2I_bin_irs counterpart.
177multiclass T2I_rbin_is<string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000178 // shifted imm
179 def ri : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000180 opc, " $dst, $rhs, $lhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000181 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
182 // shifted register
183 def rs : T2I<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000184 opc, " $dst, $rhs, $lhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000185 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
186}
187
Evan Chenga67efd12009-06-23 19:39:13 +0000188/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000189/// instruction modifies the CPSR register.
190let Defs = [CPSR] in {
Evan Cheng8de898a2009-06-26 00:19:44 +0000191multiclass T2I_bin_s_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000192 // shifted imm
Evan Chengf49810c2009-06-23 17:48:47 +0000193 def ri : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000194 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000195 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000196 // register
197 def rr : T2I<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000198 !strconcat(opc, "s"), " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000199 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
200 let isCommutable = Commutable;
201 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000202 // shifted register
Evan Chengf49810c2009-06-23 17:48:47 +0000203 def rs : T2I<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$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_reg:$rhs))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000206}
207}
208
Evan Chenga67efd12009-06-23 19:39:13 +0000209/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
210/// patterns for a binary operation that produces a value.
Evan Cheng8de898a2009-06-26 00:19:44 +0000211multiclass T2I_bin_ii12rs<string opc, PatFrag opnode, bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000212 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000213 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
214 opc, " $dst, $lhs, $rhs",
215 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000216 // 12-bit imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000217 def ri12 : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
218 !strconcat(opc, "w"), " $dst, $lhs, $rhs",
219 [(set GPR:$dst, (opnode GPR:$lhs, imm0_4095:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000220 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000221 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
222 opc, " $dst, $lhs, $rhs",
Evan Cheng8de898a2009-06-26 00:19:44 +0000223 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]> {
224 let isCommutable = Commutable;
225 }
Evan Chengf49810c2009-06-23 17:48:47 +0000226 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000227 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
228 opc, " $dst, $lhs, $rhs",
229 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000230}
231
Evan Cheng62674222009-06-25 23:34:10 +0000232/// 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 +0000233/// binary operation that produces a value and use and define the carry bit.
234/// It's not predicable.
Evan Cheng62674222009-06-25 23:34:10 +0000235let Uses = [CPSR] in {
Evan Cheng8de898a2009-06-26 00:19:44 +0000236multiclass T2I_adde_sube_irs<string opc, PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000237 // shifted imm
Evan Cheng62674222009-06-25 23:34:10 +0000238 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000239 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000240 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000241 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000242 // register
Evan Cheng62674222009-06-25 23:34:10 +0000243 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000244 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000245 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000246 Requires<[IsThumb2, CarryDefIsUnused]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000247 let isCommutable = Commutable;
248 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000249 // shifted register
Evan Cheng62674222009-06-25 23:34:10 +0000250 def rs : T2sI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
David Goodwin7ce720b2009-06-26 20:45:56 +0000251 opc, " $dst, $lhs, $rhs",
Evan Cheng62674222009-06-25 23:34:10 +0000252 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000253 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Cheng62674222009-06-25 23:34:10 +0000254 // Carry setting variants
255 // shifted imm
256 def Sri : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs),
257 !strconcat(opc, "s $dst, $lhs, $rhs"),
258 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000259 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000260 let Defs = [CPSR];
261 }
262 // register
263 def Srr : T2XI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
264 !strconcat(opc, "s $dst, $lhs, $rhs"),
265 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000266 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000267 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000268 let isCommutable = Commutable;
269 }
Evan Cheng62674222009-06-25 23:34:10 +0000270 // shifted register
271 def Srs : T2XI<(outs GPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs),
272 !strconcat(opc, "s $dst, $lhs, $rhs"),
273 [(set GPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000274 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000275 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000276 }
Evan Chengf49810c2009-06-23 17:48:47 +0000277}
278}
279
Evan Cheng62674222009-06-25 23:34:10 +0000280/// T2I_rsc_is - Same as T2I_adde_sube_irs except the order of operands are
Evan Cheng1e249e32009-06-25 20:59:23 +0000281/// reversed. It doesn't define the 'rr' form since it's handled by its
Evan Cheng62674222009-06-25 23:34:10 +0000282/// T2I_adde_sube_irs counterpart.
Evan Cheng1e249e32009-06-25 20:59:23 +0000283let Defs = [CPSR], Uses = [CPSR] in {
Evan Cheng62674222009-06-25 23:34:10 +0000284multiclass T2I_rsc_is<string opc, PatFrag opnode> {
Evan Cheng1e249e32009-06-25 20:59:23 +0000285 // shifted imm
Evan Cheng62674222009-06-25 23:34:10 +0000286 def ri : T2sI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
287 opc, " $dst, $rhs, $lhs",
288 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000289 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Cheng1e249e32009-06-25 20:59:23 +0000290 // shifted register
Evan Cheng62674222009-06-25 23:34:10 +0000291 def rs : T2sI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
292 opc, " $dst, $rhs, $lhs",
293 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000294 Requires<[IsThumb2, CarryDefIsUnused]>;
Evan Cheng62674222009-06-25 23:34:10 +0000295 // shifted imm
296 def Sri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs),
Evan Cheng1e249e32009-06-25 20:59:23 +0000297 !strconcat(opc, "s $dst, $rhs, $lhs"),
Evan Cheng62674222009-06-25 23:34:10 +0000298 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$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 Cheng62674222009-06-25 23:34:10 +0000302 // shifted register
303 def Srs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs),
304 !strconcat(opc, "s $dst, $rhs, $lhs"),
305 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>,
Evan Chengd770d9e2009-07-02 06:38:40 +0000306 Requires<[IsThumb2, CarryDefIsUsed]> {
Evan Cheng62674222009-06-25 23:34:10 +0000307 let Defs = [CPSR];
Evan Cheng8de898a2009-06-26 00:19:44 +0000308 }
Evan Cheng1e249e32009-06-25 20:59:23 +0000309}
310}
311
312/// T2I_rbin_s_is - Same as T2I_bin_s_irs except the order of operands are
313/// reversed. It doesn't define the 'rr' form since it's handled by its
314/// T2I_bin_s_irs counterpart.
315let Defs = [CPSR] in {
316multiclass T2I_rbin_s_is<string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000317 // shifted imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000318 def ri : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_imm:$lhs, cc_out:$s),
319 !strconcat(opc, "${s} $dst, $rhs, $lhs"),
320 [(set GPR:$dst, (opnode t2_so_imm:$lhs, GPR:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000321 // shifted register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000322 def rs : T2XI<(outs GPR:$dst), (ins GPR:$rhs, t2_so_reg:$lhs, cc_out:$s),
323 !strconcat(opc, "${s} $dst, $rhs, $lhs"),
324 [(set GPR:$dst, (opnode t2_so_reg:$lhs, GPR:$rhs))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000325}
326}
327
Evan Chenga67efd12009-06-23 19:39:13 +0000328/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
329// rotate operation that produces a value.
330multiclass T2I_sh_ir<string opc, PatFrag opnode> {
331 // 5-bit imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000332 def ri : T2sI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
333 opc, " $dst, $lhs, $rhs",
334 [(set GPR:$dst, (opnode GPR:$lhs, imm1_31:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000335 // register
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000336 def rr : T2sI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
337 opc, " $dst, $lhs, $rhs",
338 [(set GPR:$dst, (opnode GPR:$lhs, GPR:$rhs))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000339}
Evan Chengf49810c2009-06-23 17:48:47 +0000340
Evan Chenga67efd12009-06-23 19:39:13 +0000341/// T21_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
342/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000343/// a explicit result, only implicitly set CPSR.
344let Uses = [CPSR] in {
345multiclass T2I_cmp_is<string opc, PatFrag opnode> {
346 // shifted imm
347 def ri : T2I<(outs), (ins GPR:$lhs, t2_so_imm:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000348 opc, " $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000349 [(opnode GPR:$lhs, t2_so_imm:$rhs)]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000350 // register
351 def rr : T2I<(outs), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000352 opc, " $lhs, $rhs",
Evan Chenga67efd12009-06-23 19:39:13 +0000353 [(opnode GPR:$lhs, GPR:$rhs)]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000354 // shifted register
355 def rs : T2I<(outs), (ins GPR:$lhs, t2_so_reg:$rhs),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000356 opc, " $lhs, $rhs",
Evan Chengf49810c2009-06-23 17:48:47 +0000357 [(opnode GPR:$lhs, t2_so_reg:$rhs)]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000358}
359}
360
Evan Chengf3c21b82009-06-30 02:15:48 +0000361/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
362multiclass T2I_ld<string opc, PatFrag opnode> {
363 def i12 : T2Ii12<(outs GPR:$dst), (ins t2addrmode_imm12:$addr),
364 opc, " $dst, $addr",
365 [(set GPR:$dst, (opnode t2addrmode_imm12:$addr))]>;
366 def i8 : T2Ii8 <(outs GPR:$dst), (ins t2addrmode_imm8:$addr),
367 opc, " $dst, $addr",
368 [(set GPR:$dst, (opnode t2addrmode_imm8:$addr))]>;
369 def s : T2Iso <(outs GPR:$dst), (ins t2addrmode_so_reg:$addr),
370 opc, " $dst, $addr",
371 [(set GPR:$dst, (opnode t2addrmode_so_reg:$addr))]>;
372 def pci : T2Ipc <(outs GPR:$dst), (ins i32imm:$addr),
373 opc, " $dst, $addr",
374 [(set GPR:$dst, (opnode (ARMWrapper tconstpool:$addr)))]>;
375}
376
David Goodwin73b8f162009-06-30 22:11:34 +0000377/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
378multiclass T2I_st<string opc, PatFrag opnode> {
379 def i12 : T2Ii12<(outs), (ins GPR:$src, t2addrmode_imm12:$addr),
380 opc, " $src, $addr",
381 [(opnode GPR:$src, t2addrmode_imm12:$addr)]>;
382 def i8 : T2Ii8 <(outs), (ins GPR:$src, t2addrmode_imm8:$addr),
383 opc, " $src, $addr",
384 [(opnode GPR:$src, t2addrmode_imm8:$addr)]>;
385 def s : T2Iso <(outs), (ins GPR:$src, t2addrmode_so_reg:$addr),
386 opc, " $src, $addr",
387 [(opnode GPR:$src, t2addrmode_so_reg:$addr)]>;
388}
389
David Goodwind1fa1202009-07-01 00:01:13 +0000390/// T2I_picld - Defines the PIC load pattern.
391class T2I_picld<string opc, PatFrag opnode> :
392 T2I<(outs GPR:$dst), (ins addrmodepc:$addr),
393 !strconcat("${addr:label}:\n\t", opc), " $dst, $addr",
394 [(set GPR:$dst, (opnode addrmodepc:$addr))]>;
395
396/// T2I_picst - Defines the PIC store pattern.
397class T2I_picst<string opc, PatFrag opnode> :
398 T2I<(outs), (ins GPR:$src, addrmodepc:$addr),
399 !strconcat("${addr:label}:\n\t", opc), " $src, $addr",
400 [(opnode GPR:$src, addrmodepc:$addr)]>;
401
Evan Chengd27c9fc2009-07-03 01:43:10 +0000402
403/// T2I_unary_rrot - A unary operation with two forms: one whose operand is a
404/// register and one whose operand is a register rotated by 8/16/24.
405multiclass T2I_unary_rrot<string opc, PatFrag opnode> {
406 def r : T2I<(outs GPR:$dst), (ins GPR:$Src),
407 opc, " $dst, $Src",
408 [(set GPR:$dst, (opnode GPR:$Src))]>;
409 def r_rot : T2I<(outs GPR:$dst), (ins GPR:$Src, i32imm:$rot),
410 opc, " $dst, $Src, ror $rot",
411 [(set GPR:$dst, (opnode (rotr GPR:$Src, rot_imm:$rot)))]>;
412}
413
414/// T2I_bin_rrot - A binary operation with two forms: one whose operand is a
415/// register and one whose operand is a register rotated by 8/16/24.
416multiclass T2I_bin_rrot<string opc, PatFrag opnode> {
417 def rr : T2I<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS),
418 opc, " $dst, $LHS, $RHS",
419 [(set GPR:$dst, (opnode GPR:$LHS, GPR:$RHS))]>;
420 def rr_rot : T2I<(outs GPR:$dst), (ins GPR:$LHS, GPR:$RHS, i32imm:$rot),
421 opc, " $dst, $LHS, $RHS, ror $rot",
422 [(set GPR:$dst, (opnode GPR:$LHS,
423 (rotr GPR:$RHS, rot_imm:$rot)))]>;
424}
425
Anton Korobeynikov52237112009-06-17 18:13:58 +0000426//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000427// Instructions
428//===----------------------------------------------------------------------===//
429
430//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +0000431// Miscellaneous Instructions.
432//
433
434let isNotDuplicable = 1 in
David Goodwinf1daf7d2009-07-08 23:10:31 +0000435def t2PICADD : T2XI<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000436 "$cp:\n\tadd $dst, pc",
David Goodwinf1daf7d2009-07-08 23:10:31 +0000437 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
Evan Chenga09b9ca2009-06-24 23:47:58 +0000438
439
440// LEApcrel - Load a pc-relative address into a register without offending the
441// assembler.
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000442def t2LEApcrel : T2XI<(outs GPR:$dst), (ins i32imm:$label, pred:$p),
Evan Chenga09b9ca2009-06-24 23:47:58 +0000443 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
444 "${:private}PCRELL${:uid}+8))\n"),
445 !strconcat("${:private}PCRELL${:uid}:\n\t",
446 "add$p $dst, pc, #PCRELV${:uid}")),
447 []>;
448
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000449def t2LEApcrelJT : T2XI<(outs GPR:$dst),
Evan Chenga09b9ca2009-06-24 23:47:58 +0000450 (ins i32imm:$label, i32imm:$id, pred:$p),
451 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
452 "${:private}PCRELL${:uid}+8))\n"),
453 !strconcat("${:private}PCRELL${:uid}:\n\t",
454 "add$p $dst, pc, #PCRELV${:uid}")),
455 []>;
456
Evan Chengb6c29d52009-06-25 01:21:30 +0000457// ADD rd, sp, #so_imm
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000458def t2ADDrSPi : T2XI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
459 "add $dst, $sp, $imm",
460 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000461
462// ADD rd, sp, #imm12
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000463def t2ADDrSPi12 : T2XI<(outs GPR:$dst), (ins GPR:$sp, i32imm:$imm),
464 "addw $dst, $sp, $imm",
465 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000466
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000467def t2ADDrSPs : T2XI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
468 "addw $dst, $sp, $rhs",
469 []>;
Evan Chengb6c29d52009-06-25 01:21:30 +0000470
471
Evan Chenga09b9ca2009-06-24 23:47:58 +0000472//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000473// Load / store Instructions.
474//
475
Evan Cheng055b0312009-06-29 07:51:04 +0000476// Load
Evan Chengf3c21b82009-06-30 02:15:48 +0000477let canFoldAsLoad = 1 in
478defm t2LDR : T2I_ld<"ldr", UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000479
Evan Chengf3c21b82009-06-30 02:15:48 +0000480// Loads with zero extension
481defm t2LDRH : T2I_ld<"ldrh", UnOpFrag<(zextloadi16 node:$Src)>>;
482defm t2LDRB : T2I_ld<"ldrb", UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000483
Evan Chengf3c21b82009-06-30 02:15:48 +0000484// Loads with sign extension
485defm t2LDRSH : T2I_ld<"ldrsh", UnOpFrag<(sextloadi16 node:$Src)>>;
486defm t2LDRSB : T2I_ld<"ldrsb", UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000487
Evan Chengf3c21b82009-06-30 02:15:48 +0000488let mayLoad = 1 in {
489// Load doubleword
David Goodwin6647cea2009-06-30 22:50:01 +0000490def t2LDRDi8 : T2Ii8s4<(outs GPR:$dst), (ins t2addrmode_imm8s4:$addr),
Evan Chengf3c21b82009-06-30 02:15:48 +0000491 "ldrd", " $dst, $addr", []>;
492def t2LDRDpci : T2Ii8s4<(outs GPR:$dst), (ins i32imm:$addr),
493 "ldrd", " $dst, $addr", []>;
494}
495
496// zextload i1 -> zextload i8
497def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
498 (t2LDRBi12 t2addrmode_imm12:$addr)>;
499def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
500 (t2LDRBi8 t2addrmode_imm8:$addr)>;
501def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
502 (t2LDRBs t2addrmode_so_reg:$addr)>;
503def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
504 (t2LDRBpci tconstpool:$addr)>;
505
506// extload -> zextload
507// FIXME: Reduce the number of patterns by legalizing extload to zextload
508// earlier?
509def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
510 (t2LDRBi12 t2addrmode_imm12:$addr)>;
511def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
512 (t2LDRBi8 t2addrmode_imm8:$addr)>;
513def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
514 (t2LDRBs t2addrmode_so_reg:$addr)>;
515def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
516 (t2LDRBpci tconstpool:$addr)>;
517
518def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
519 (t2LDRBi12 t2addrmode_imm12:$addr)>;
520def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
521 (t2LDRBi8 t2addrmode_imm8:$addr)>;
522def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
523 (t2LDRBs t2addrmode_so_reg:$addr)>;
524def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
525 (t2LDRBpci tconstpool:$addr)>;
526
527def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
528 (t2LDRHi12 t2addrmode_imm12:$addr)>;
529def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
530 (t2LDRHi8 t2addrmode_imm8:$addr)>;
531def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
532 (t2LDRHs t2addrmode_so_reg:$addr)>;
533def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
534 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +0000535
Evan Chenge88d5ce2009-07-02 07:28:31 +0000536// Indexed loads
Evan Cheng78236f82009-07-03 00:08:19 +0000537let mayLoad = 1 in {
Evan Chenge88d5ce2009-07-02 07:28:31 +0000538def t2LDR_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
539 (ins t2addrmode_imm8:$addr),
540 AddrModeT2_i8, IndexModePre,
541 "ldr", " $dst, $addr!", "$addr.base = $base_wb",
542 []>;
543
544def t2LDR_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
545 (ins GPR:$base, t2am_imm8_offset:$offset),
546 AddrModeT2_i8, IndexModePost,
547 "ldr", " $dst, [$base], $offset", "$base = $base_wb",
548 []>;
549
550def t2LDRB_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
551 (ins t2addrmode_imm8:$addr),
552 AddrModeT2_i8, IndexModePre,
553 "ldrb", " $dst, $addr!", "$addr.base = $base_wb",
554 []>;
555def t2LDRB_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
556 (ins GPR:$base, t2am_imm8_offset:$offset),
557 AddrModeT2_i8, IndexModePost,
558 "ldrb", " $dst, [$base], $offset", "$base = $base_wb",
559 []>;
560
561def t2LDRH_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
562 (ins t2addrmode_imm8:$addr),
563 AddrModeT2_i8, IndexModePre,
564 "ldrh", " $dst, $addr!", "$addr.base = $base_wb",
565 []>;
566def t2LDRH_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
567 (ins GPR:$base, t2am_imm8_offset:$offset),
568 AddrModeT2_i8, IndexModePost,
569 "ldrh", " $dst, [$base], $offset", "$base = $base_wb",
570 []>;
571
Evan Cheng4fbb9962009-07-02 23:16:11 +0000572def t2LDRSB_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
573 (ins t2addrmode_imm8:$addr),
574 AddrModeT2_i8, IndexModePre,
575 "ldrsb", " $dst, $addr!", "$addr.base = $base_wb",
576 []>;
577def t2LDRSB_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
578 (ins GPR:$base, t2am_imm8_offset:$offset),
579 AddrModeT2_i8, IndexModePost,
580 "ldrsb", " $dst, [$base], $offset", "$base = $base_wb",
581 []>;
582
583def t2LDRSH_PRE : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
584 (ins t2addrmode_imm8:$addr),
585 AddrModeT2_i8, IndexModePre,
586 "ldrsh", " $dst, $addr!", "$addr.base = $base_wb",
587 []>;
588def t2LDRSH_POST : T2Iidxldst<(outs GPR:$dst, GPR:$base_wb),
589 (ins GPR:$base, t2am_imm8_offset:$offset),
590 AddrModeT2_i8, IndexModePost,
591 "ldrsh", " $dst, [$base], $offset", "$base = $base_wb",
592 []>;
Evan Cheng78236f82009-07-03 00:08:19 +0000593}
Evan Cheng4fbb9962009-07-02 23:16:11 +0000594
David Goodwin73b8f162009-06-30 22:11:34 +0000595// Store
Evan Chenge88d5ce2009-07-02 07:28:31 +0000596defm t2STR : T2I_st<"str", BinOpFrag<(store node:$LHS, node:$RHS)>>;
597defm t2STRB : T2I_st<"strb", BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
598defm t2STRH : T2I_st<"strh", BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
David Goodwin73b8f162009-06-30 22:11:34 +0000599
David Goodwin6647cea2009-06-30 22:50:01 +0000600// Store doubleword
601let mayLoad = 1 in
602def t2STRDi8 : T2Ii8s4<(outs), (ins GPR:$src, t2addrmode_imm8s4:$addr),
603 "strd", " $src, $addr", []>;
604
Evan Cheng6d94f112009-07-03 00:06:39 +0000605// Indexed stores
606def t2STR_PRE : T2Iidxldst<(outs GPR:$base_wb),
607 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
608 AddrModeT2_i8, IndexModePre,
609 "str", " $src, [$base, $offset]!", "$base = $base_wb",
610 [(set GPR:$base_wb,
611 (pre_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
612
613def t2STR_POST : T2Iidxldst<(outs GPR:$base_wb),
614 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
615 AddrModeT2_i8, IndexModePost,
616 "str", " $src, [$base], $offset", "$base = $base_wb",
617 [(set GPR:$base_wb,
618 (post_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
619
620def t2STRH_PRE : T2Iidxldst<(outs GPR:$base_wb),
621 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
622 AddrModeT2_i8, IndexModePre,
623 "strh", " $src, [$base, $offset]!", "$base = $base_wb",
624 [(set GPR:$base_wb,
625 (pre_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
626
627def t2STRH_POST : T2Iidxldst<(outs GPR:$base_wb),
628 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
629 AddrModeT2_i8, IndexModePost,
630 "strh", " $src, [$base], $offset", "$base = $base_wb",
631 [(set GPR:$base_wb,
632 (post_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
633
634def t2STRB_PRE : T2Iidxldst<(outs GPR:$base_wb),
635 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
636 AddrModeT2_i8, IndexModePre,
637 "strb", " $src, [$base, $offset]!", "$base = $base_wb",
638 [(set GPR:$base_wb,
639 (pre_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
640
641def t2STRB_POST : T2Iidxldst<(outs GPR:$base_wb),
642 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
643 AddrModeT2_i8, IndexModePost,
644 "strb", " $src, [$base], $offset", "$base = $base_wb",
645 [(set GPR:$base_wb,
646 (post_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
647
David Goodwind1fa1202009-07-01 00:01:13 +0000648
649// Address computation and loads and stores in PIC mode.
650let isNotDuplicable = 1, AddedComplexity = 10 in {
651let canFoldAsLoad = 1 in
652def t2PICLDR : T2I_picld<"ldr", UnOpFrag<(load node:$Src)>>;
653
654def t2PICLDRH : T2I_picld<"ldrh", UnOpFrag<(zextloadi16 node:$Src)>>;
655def t2PICLDRB : T2I_picld<"ldrb", UnOpFrag<(zextloadi8 node:$Src)>>;
656def t2PICLDRSH : T2I_picld<"ldrsh", UnOpFrag<(sextloadi16 node:$Src)>>;
657def t2PICLDRSB : T2I_picld<"ldrsb", UnOpFrag<(sextloadi8 node:$Src)>>;
658
659def t2PICSTR : T2I_picst<"str", BinOpFrag<(store node:$LHS, node:$RHS)>>;
660def t2PICSTRH : T2I_picst<"strh", BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
661def t2PICSTRB : T2I_picst<"strb", BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
662} // isNotDuplicable = 1, AddedComplexity = 10
663
Evan Cheng2889cce2009-07-03 00:18:36 +0000664
665//===----------------------------------------------------------------------===//
666// Load / store multiple Instructions.
667//
668
669let mayLoad = 1 in
670def t2LDM : T2XI<(outs),
671 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
672 "ldm${p}${addr:submode} $addr, $dst1", []>;
673
674let mayStore = 1 in
675def t2STM : T2XI<(outs),
676 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
677 "stm${p}${addr:submode} $addr, $src1", []>;
678
Evan Cheng9cb9e672009-06-27 02:26:13 +0000679//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000680// Move Instructions.
681//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000682
Evan Chengf49810c2009-06-23 17:48:47 +0000683let neverHasSideEffects = 1 in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000684def t2MOVr : T2sI<(outs GPR:$dst), (ins GPR:$src),
685 "mov", " $dst, $src", []>;
Evan Chengf49810c2009-06-23 17:48:47 +0000686
Evan Chenga67efd12009-06-23 19:39:13 +0000687let isReMaterializable = 1, isAsCheapAsAMove = 1 in
David Goodwin83b35932009-06-26 16:10:07 +0000688def t2MOVi : T2sI<(outs GPR:$dst), (ins t2_so_imm:$src),
689 "mov", " $dst, $src",
690 [(set GPR:$dst, t2_so_imm:$src)]>;
691
692let isReMaterializable = 1, isAsCheapAsAMove = 1 in
693def t2MOVi16 : T2I<(outs GPR:$dst), (ins i32imm:$src),
694 "movw", " $dst, $src",
695 [(set GPR:$dst, imm0_65535:$src)]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000696
Evan Chengf49810c2009-06-23 17:48:47 +0000697// FIXME: Also available in ARM mode.
Evan Cheng3850a6a2009-06-23 05:23:49 +0000698let Constraints = "$src = $dst" in
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000699def t2MOVTi16 : T2sI<(outs GPR:$dst), (ins GPR:$src, i32imm:$imm),
700 "movt", " $dst, $imm",
701 [(set GPR:$dst,
702 (or (and GPR:$src, 0xffff), t2_lo16AllZero:$imm))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000703
704//===----------------------------------------------------------------------===//
Evan Chengd27c9fc2009-07-03 01:43:10 +0000705// Extend Instructions.
706//
707
708// Sign extenders
709
710defm t2SXTB : T2I_unary_rrot<"sxtb", UnOpFrag<(sext_inreg node:$Src, i8)>>;
711defm t2SXTH : T2I_unary_rrot<"sxth", UnOpFrag<(sext_inreg node:$Src, i16)>>;
712
713defm t2SXTAB : T2I_bin_rrot<"sxtab",
714 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
715defm t2SXTAH : T2I_bin_rrot<"sxtah",
716 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
717
718// TODO: SXT(A){B|H}16
719
720// Zero extenders
721
722let AddedComplexity = 16 in {
723defm t2UXTB : T2I_unary_rrot<"uxtb" , UnOpFrag<(and node:$Src, 0x000000FF)>>;
724defm t2UXTH : T2I_unary_rrot<"uxth" , UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
725defm t2UXTB16 : T2I_unary_rrot<"uxtb16", UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
726
727def : T2Pat<(and (shl GPR:$Src, (i32 8)), 0xFF00FF),
728 (t2UXTB16r_rot GPR:$Src, 24)>;
729def : T2Pat<(and (srl GPR:$Src, (i32 8)), 0xFF00FF),
730 (t2UXTB16r_rot GPR:$Src, 8)>;
731
732defm t2UXTAB : T2I_bin_rrot<"uxtab",
733 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
734defm t2UXTAH : T2I_bin_rrot<"uxtah",
735 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
736}
737
738//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000739// Arithmetic Instructions.
740//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000741
Evan Cheng8de898a2009-06-26 00:19:44 +0000742defm t2ADD : T2I_bin_ii12rs<"add", BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
Evan Chenga67efd12009-06-23 19:39:13 +0000743defm t2SUB : T2I_bin_ii12rs<"sub", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000744
Evan Chengf49810c2009-06-23 17:48:47 +0000745// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Evan Cheng8de898a2009-06-26 00:19:44 +0000746defm t2ADDS : T2I_bin_s_irs <"add", BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
Evan Cheng1e249e32009-06-25 20:59:23 +0000747defm t2SUBS : T2I_bin_s_irs <"sub", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000748
Evan Cheng8de898a2009-06-26 00:19:44 +0000749defm t2ADC : T2I_adde_sube_irs<"adc",BinOpFrag<(adde node:$LHS, node:$RHS)>,1>;
750defm t2SBC : T2I_adde_sube_irs<"sbc",BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000751
752// RSB, RSC
Evan Cheng1e249e32009-06-25 20:59:23 +0000753defm t2RSB : T2I_rbin_is <"rsb", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
754defm t2RSBS : T2I_rbin_s_is <"rsb", BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Evan Cheng62674222009-06-25 23:34:10 +0000755defm t2RSC : T2I_rsc_is <"rsc", BinOpFrag<(sube node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000756
757// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Evan Cheng9cb9e672009-06-27 02:26:13 +0000758def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
759 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
760def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
761 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000762
763
Evan Chengf49810c2009-06-23 17:48:47 +0000764//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +0000765// Shift and rotate Instructions.
766//
767
768defm t2LSL : T2I_sh_ir<"lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
769defm t2LSR : T2I_sh_ir<"lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
770defm t2ASR : T2I_sh_ir<"asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
771defm t2ROR : T2I_sh_ir<"ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
772
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000773def t2MOVrx : T2sI<(outs GPR:$dst), (ins GPR:$src),
774 "mov", " $dst, $src, rrx",
775 [(set GPR:$dst, (ARMrrx GPR:$src))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000776
777//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +0000778// Bitwise Instructions.
779//
Anton Korobeynikov52237112009-06-17 18:13:58 +0000780
Evan Cheng8de898a2009-06-26 00:19:44 +0000781defm t2AND : T2I_bin_irs<"and", BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
782defm t2ORR : T2I_bin_irs<"orr", BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
783defm t2EOR : T2I_bin_irs<"eor", BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +0000784
Evan Chenga67efd12009-06-23 19:39:13 +0000785defm t2BIC : T2I_bin_irs<"bic", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000786
Evan Chengf49810c2009-06-23 17:48:47 +0000787let Constraints = "$src = $dst" in
788def t2BFC : T2I<(outs GPR:$dst), (ins GPR:$src, bf_inv_mask_imm:$imm),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000789 "bfc", " $dst, $imm",
Evan Chengf49810c2009-06-23 17:48:47 +0000790 [(set GPR:$dst, (and GPR:$src, bf_inv_mask_imm:$imm))]>;
791
792// FIXME: A8.6.18 BFI - Bitfield insert (Encoding T1)
793
Evan Cheng36a0aeb2009-07-06 22:23:46 +0000794defm t2ORN : T2I_bin_irs<"orn", BinOpFrag<(or node:$LHS, (not node:$RHS))>>;
795
796// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
797let AddedComplexity = 1 in
798defm t2MVN : T2I_un_irs <"mvn", UnOpFrag<(not node:$Src)>, 1, 1>;
799
800
801def : T2Pat<(and GPR:$src, t2_so_imm_not:$imm),
802 (t2BICri GPR:$src, t2_so_imm_not:$imm)>;
803
804def : T2Pat<(or GPR:$src, t2_so_imm_not:$imm),
805 (t2ORNri GPR:$src, t2_so_imm_not:$imm)>;
806
807def : T2Pat<(t2_so_imm_not:$src),
808 (t2MVNi t2_so_imm_not:$src)>;
809
Evan Chengf49810c2009-06-23 17:48:47 +0000810//===----------------------------------------------------------------------===//
811// Multiply Instructions.
812//
Evan Cheng8de898a2009-06-26 00:19:44 +0000813let isCommutable = 1 in
Evan Chengf49810c2009-06-23 17:48:47 +0000814def t2MUL: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000815 "mul", " $dst, $a, $b",
Evan Chengf49810c2009-06-23 17:48:47 +0000816 [(set GPR:$dst, (mul GPR:$a, GPR:$b))]>;
817
818def t2MLA: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000819 "mla", " $dst, $a, $b, $c",
Evan Chengf49810c2009-06-23 17:48:47 +0000820 [(set GPR:$dst, (add (mul GPR:$a, GPR:$b), GPR:$c))]>;
821
822def t2MLS: T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000823 "mls", " $dst, $a, $b, $c",
Evan Chengf49810c2009-06-23 17:48:47 +0000824 [(set GPR:$dst, (sub GPR:$c, (mul GPR:$a, GPR:$b)))]>;
825
Evan Cheng5b9fcd12009-07-07 01:17:28 +0000826// Extra precision multiplies with low / high results
827let neverHasSideEffects = 1 in {
828let isCommutable = 1 in {
829def t2SMULL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
830 "smull", " $ldst, $hdst, $a, $b", []>;
831
832def t2UMULL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
833 "umull", " $ldst, $hdst, $a, $b", []>;
834}
835
836// Multiply + accumulate
837def t2SMLAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
838 "smlal", " $ldst, $hdst, $a, $b", []>;
839
840def t2UMLAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
841 "umlal", " $ldst, $hdst, $a, $b", []>;
842
843def t2UMAAL : T2I<(outs GPR:$ldst, GPR:$hdst), (ins GPR:$a, GPR:$b),
844 "umaal", " $ldst, $hdst, $a, $b", []>;
845} // neverHasSideEffects
846
847// Most significant word multiply
848def t2SMMUL : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
849 "smmul", " $dst, $a, $b",
850 [(set GPR:$dst, (mulhs GPR:$a, GPR:$b))]>;
851
852def t2SMMLA : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
853 "smmla", " $dst, $a, $b, $c",
854 [(set GPR:$dst, (add (mulhs GPR:$a, GPR:$b), GPR:$c))]>;
855
856
857def t2SMMLS : T2I <(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$c),
858 "smmls", " $dst, $a, $b, $c",
859 [(set GPR:$dst, (sub GPR:$c, (mulhs GPR:$a, GPR:$b)))]>;
860
861multiclass T2I_smul<string opc, PatFrag opnode> {
862 def BB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
863 !strconcat(opc, "bb"), " $dst, $a, $b",
864 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
865 (sext_inreg GPR:$b, i16)))]>;
866
867 def BT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
868 !strconcat(opc, "bt"), " $dst, $a, $b",
869 [(set GPR:$dst, (opnode (sext_inreg GPR:$a, i16),
870 (sra GPR:$b, (i32 16))))]>;
871
872 def TB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
873 !strconcat(opc, "tb"), " $dst, $a, $b",
874 [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
875 (sext_inreg GPR:$b, i16)))]>;
876
877 def TT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
878 !strconcat(opc, "tt"), " $dst, $a, $b",
879 [(set GPR:$dst, (opnode (sra GPR:$a, (i32 16)),
880 (sra GPR:$b, (i32 16))))]>;
881
882 def WB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
883 !strconcat(opc, "wb"), " $dst, $a, $b",
884 [(set GPR:$dst, (sra (opnode GPR:$a,
885 (sext_inreg GPR:$b, i16)), (i32 16)))]>;
886
887 def WT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b),
888 !strconcat(opc, "wt"), " $dst, $a, $b",
889 [(set GPR:$dst, (sra (opnode GPR:$a,
890 (sra GPR:$b, (i32 16))), (i32 16)))]>;
891}
892
893
894multiclass T2I_smla<string opc, PatFrag opnode> {
895 def BB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
896 !strconcat(opc, "bb"), " $dst, $a, $b, $acc",
897 [(set GPR:$dst, (add GPR:$acc,
898 (opnode (sext_inreg GPR:$a, i16),
899 (sext_inreg GPR:$b, i16))))]>;
900
901 def BT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
902 !strconcat(opc, "bt"), " $dst, $a, $b, $acc",
903 [(set GPR:$dst, (add GPR:$acc, (opnode (sext_inreg GPR:$a, i16),
904 (sra GPR:$b, (i32 16)))))]>;
905
906 def TB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
907 !strconcat(opc, "tb"), " $dst, $a, $b, $acc",
908 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
909 (sext_inreg GPR:$b, i16))))]>;
910
911 def TT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
912 !strconcat(opc, "tt"), " $dst, $a, $b, $acc",
913 [(set GPR:$dst, (add GPR:$acc, (opnode (sra GPR:$a, (i32 16)),
914 (sra GPR:$b, (i32 16)))))]>;
915
916 def WB : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
917 !strconcat(opc, "wb"), " $dst, $a, $b, $acc",
918 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
919 (sext_inreg GPR:$b, i16)), (i32 16))))]>;
920
921 def WT : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b, GPR:$acc),
922 !strconcat(opc, "wt"), " $dst, $a, $b, $acc",
923 [(set GPR:$dst, (add GPR:$acc, (sra (opnode GPR:$a,
924 (sra GPR:$b, (i32 16))), (i32 16))))]>;
925}
926
927defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
928defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
929
930// TODO: Halfword multiple accumulate long: SMLAL<x><y>
931// TODO: Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
932
Evan Chengf49810c2009-06-23 17:48:47 +0000933
934//===----------------------------------------------------------------------===//
935// Misc. Arithmetic Instructions.
936//
937
Evan Chengf49810c2009-06-23 17:48:47 +0000938def t2CLZ : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000939 "clz", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000940 [(set GPR:$dst, (ctlz GPR:$src))]>;
941
942def t2REV : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000943 "rev", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000944 [(set GPR:$dst, (bswap GPR:$src))]>;
945
946def t2REV16 : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000947 "rev16", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000948 [(set GPR:$dst,
949 (or (and (srl GPR:$src, (i32 8)), 0xFF),
950 (or (and (shl GPR:$src, (i32 8)), 0xFF00),
951 (or (and (srl GPR:$src, (i32 8)), 0xFF0000),
952 (and (shl GPR:$src, (i32 8)), 0xFF000000)))))]>;
953
Evan Chengf49810c2009-06-23 17:48:47 +0000954def t2REVSH : T2I<(outs GPR:$dst), (ins GPR:$src),
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000955 "revsh", " $dst, $src",
Evan Chengf49810c2009-06-23 17:48:47 +0000956 [(set GPR:$dst,
957 (sext_inreg
958 (or (srl (and GPR:$src, 0xFFFF), (i32 8)),
959 (shl GPR:$src, (i32 8))), i16))]>;
960
Evan Cheng40289b02009-07-07 05:35:52 +0000961def t2PKHBT : T2I<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
962 "pkhbt", " $dst, $src1, $src2, LSL $shamt",
963 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF),
964 (and (shl GPR:$src2, (i32 imm:$shamt)),
965 0xFFFF0000)))]>;
966
967// Alternate cases for PKHBT where identities eliminate some nodes.
968def : T2Pat<(or (and GPR:$src1, 0xFFFF), (and GPR:$src2, 0xFFFF0000)),
969 (t2PKHBT GPR:$src1, GPR:$src2, 0)>;
970def : T2Pat<(or (and GPR:$src1, 0xFFFF), (shl GPR:$src2, imm16_31:$shamt)),
971 (t2PKHBT GPR:$src1, GPR:$src2, imm16_31:$shamt)>;
972
973def t2PKHTB : T2I<(outs GPR:$dst), (ins GPR:$src1, GPR:$src2, i32imm:$shamt),
974 "pkhtb", " $dst, $src1, $src2, ASR $shamt",
975 [(set GPR:$dst, (or (and GPR:$src1, 0xFFFF0000),
976 (and (sra GPR:$src2, imm16_31:$shamt),
977 0xFFFF)))]>;
978
979// Alternate cases for PKHTB where identities eliminate some nodes. Note that
980// a shift amount of 0 is *not legal* here, it is PKHBT instead.
981def : T2Pat<(or (and GPR:$src1, 0xFFFF0000), (srl GPR:$src2, (i32 16))),
982 (t2PKHTB GPR:$src1, GPR:$src2, 16)>;
983def : T2Pat<(or (and GPR:$src1, 0xFFFF0000),
984 (and (srl GPR:$src2, imm1_15:$shamt), 0xFFFF)),
985 (t2PKHTB GPR:$src1, GPR:$src2, imm1_15:$shamt)>;
Evan Chengf49810c2009-06-23 17:48:47 +0000986
987//===----------------------------------------------------------------------===//
988// Comparison Instructions...
989//
990
991defm t2CMP : T2I_cmp_is<"cmp",
992 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
David Goodwinc0309b42009-06-29 15:33:01 +0000993defm t2CMPz : T2I_cmp_is<"cmp",
994 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +0000995
996defm t2CMN : T2I_cmp_is<"cmn",
997 BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
David Goodwinc0309b42009-06-29 15:33:01 +0000998defm t2CMNz : T2I_cmp_is<"cmn",
999 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001000
Evan Cheng9cb9e672009-06-27 02:26:13 +00001001def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
1002 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +00001003
David Goodwinc0309b42009-06-29 15:33:01 +00001004def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
Evan Cheng9cb9e672009-06-27 02:26:13 +00001005 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +00001006
David Goodwinbaeb9112009-06-29 22:49:42 +00001007defm t2TST : T2I_cmp_is<"tst",
1008 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>>;
1009defm t2TEQ : T2I_cmp_is<"teq",
1010 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001011
1012// A8.6.27 CBNZ, CBZ - Compare and branch on (non)zero.
1013// Short range conditional branch. Looks awesome for loops. Need to figure
1014// out how to use this one.
1015
Evan Chenge253c952009-07-07 20:39:03 +00001016
1017// Conditional moves
1018// FIXME: should be able to write a pattern for ARMcmov, but can't use
1019// a two-value operand where a dag node expects two operands. :(
1020def t2MOVCCr : T2I<(outs GPR:$dst), (ins GPR:$false, GPR:$true),
1021 "mov", " $dst, $true",
1022 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc, CCR:$ccr))*/]>,
1023 RegConstraint<"$false = $dst">;
1024
1025def t2MOVCCs : T2I<(outs GPR:$dst), (ins GPR:$false, t2_so_reg:$true),
1026 "mov", " $dst, $true",
1027[/*(set GPR:$dst, (ARMcmov GPR:$false, t2_so_reg:$true, imm:$cc, CCR:$ccr))*/]>,
1028 RegConstraint<"$false = $dst">;
1029
1030def t2MOVCCi : T2I<(outs GPR:$dst), (ins GPR:$false, t2_so_imm:$true),
1031 "mov", " $dst, $true",
1032[/*(set GPR:$dst, (ARMcmov GPR:$false, t2_so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
1033 RegConstraint<"$false = $dst">;
Evan Chengf49810c2009-06-23 17:48:47 +00001034
David Goodwin5e47a9a2009-06-30 18:04:13 +00001035//===----------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +00001036// TLS Instructions
1037//
1038
1039// __aeabi_read_tp preserves the registers r1-r3.
1040let isCall = 1,
1041 Defs = [R0, R12, LR, CPSR] in {
1042 def t2TPsoft : T2XI<(outs), (ins),
1043 "bl __aeabi_read_tp",
1044 [(set R0, ARMthread_pointer)]>;
1045}
1046
1047//===----------------------------------------------------------------------===//
David Goodwin5e47a9a2009-06-30 18:04:13 +00001048// Control-Flow Instructions
1049//
1050
David Goodwin77521f52009-07-08 20:28:28 +00001051let isReturn = 1, isTerminator = 1 in
1052 def t2BX_RET : T2XI<(outs), (ins), "bx lr", [(ARMretflag)]>;
1053
David Goodwin334c2642009-07-08 16:09:28 +00001054// On non-Darwin platforms R9 is callee-saved.
David Goodwin77521f52009-07-08 20:28:28 +00001055let isCall = 1,
1056 Defs = [R0, R1, R2, R3, R12, LR,
1057 D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
1058def t2BL : T2XI<(outs), (ins i32imm:$func, variable_ops),
1059 "bl ${func:call}",
1060 [(ARMcall tglobaladdr:$func)]>, Requires<[IsNotDarwin]>;
1061
1062def t2BLX : T2XI<(outs), (ins GPR:$func, variable_ops),
1063 "blx $func",
1064 [(ARMcall GPR:$func)]>, Requires<[IsNotDarwin]>;
1065}
David Goodwin334c2642009-07-08 16:09:28 +00001066
1067// On Darwin R9 is call-clobbered.
David Goodwin77521f52009-07-08 20:28:28 +00001068let isCall = 1,
1069 Defs = [R0, R1, R2, R3, R9, R12, LR,
1070 D0, D1, D2, D3, D4, D5, D6, D7, CPSR] in {
1071def t2BLr9 : T2XI<(outs), (ins i32imm:$func, variable_ops),
1072 "bl ${func:call}",
1073 [(ARMcall tglobaladdr:$func)]>, Requires<[IsDarwin]>;
1074
1075def t2BLXr9 : T2XI<(outs), (ins GPR:$func, variable_ops),
1076 "blx $func",
1077 [(ARMcall GPR:$func)]>, Requires<[IsDarwin]>;
1078}
David Goodwin334c2642009-07-08 16:09:28 +00001079
David Goodwin5e47a9a2009-06-30 18:04:13 +00001080let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
1081let isPredicable = 1 in
1082def t2B : T2XI<(outs), (ins brtarget:$target),
1083 "b $target",
1084 [(br bb:$target)]>;
1085
David Goodwinc9a59b52009-06-30 19:50:22 +00001086let isNotDuplicable = 1, isIndirectBranch = 1 in {
1087def t2BR_JTr : T2JTI<(outs), (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
1088 "mov pc, $target \n$jt",
1089 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
1090
1091def t2BR_JTm :
1092 T2JTI<(outs),
1093 (ins t2addrmode_so_reg:$target, jtblock_operand:$jt, i32imm:$id),
1094 "ldr pc, $target \n$jt",
1095 [(ARMbrjt (i32 (load t2addrmode_so_reg:$target)), tjumptable:$jt,
1096 imm:$id)]>;
1097
1098def t2BR_JTadd :
1099 T2JTI<(outs),
1100 (ins GPR:$target, GPR:$idx, jtblock_operand:$jt, i32imm:$id),
1101 "add pc, $target, $idx \n$jt",
1102 [(ARMbrjt (add GPR:$target, GPR:$idx), tjumptable:$jt, imm:$id)]>;
1103} // isNotDuplicate, isIndirectBranch
1104} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +00001105
1106// FIXME: should be able to write a pattern for ARMBrcond, but can't use
1107// a two-value operand where a dag node expects two operands. :(
1108let isBranch = 1, isTerminator = 1 in
1109def t2Bcc : T2I<(outs), (ins brtarget:$target),
1110 "b", " $target",
1111 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Evan Chengf49810c2009-06-23 17:48:47 +00001112
1113//===----------------------------------------------------------------------===//
1114// Non-Instruction Patterns
1115//
1116
Evan Chenga09b9ca2009-06-24 23:47:58 +00001117// ConstantPool, GlobalAddress, and JumpTable
Evan Cheng9cb9e672009-06-27 02:26:13 +00001118def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>;
1119def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
1120def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1121 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chenga09b9ca2009-06-24 23:47:58 +00001122
Evan Chengf49810c2009-06-23 17:48:47 +00001123// Large immediate handling.
1124
Evan Cheng9cb9e672009-06-27 02:26:13 +00001125def : T2Pat<(i32 imm:$src),
1126 (t2MOVTi16 (t2MOVi16 (t2_lo16 imm:$src)), (t2_hi16 imm:$src))>;