blob: 7880c235fccf641211b1af33f4fb6de47ad257e7 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMInstrThumb.td - Thumb support for ARM ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Thumb specific DAG Nodes.
16//
17
18def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
19 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
20
21// TI - Thumb instruction.
22
23// ThumbPat - Same as Pat<>, but requires that the compiler be in Thumb mode.
24class ThumbPat<dag pattern, dag result> : Pat<pattern, result> {
25 list<Predicate> Predicates = [IsThumb];
26}
27
28class ThumbV5Pat<dag pattern, dag result> : Pat<pattern, result> {
29 list<Predicate> Predicates = [IsThumb, HasV5T];
30}
31
Evan Chengb783fa32007-07-19 01:14:50 +000032class ThumbI<dag outs, dag ins, AddrMode am, SizeFlagVal sz,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 string asm, string cstr, list<dag> pattern>
34 // FIXME: Set all opcodes to 0 for now.
Evan Chenga7b3e7c2007-08-07 01:37:15 +000035 : InstARM<0, am, sz, IndexModeNone, ThumbFrm, cstr> {
Evan Chengb783fa32007-07-19 01:14:50 +000036 let OutOperandList = outs;
37 let InOperandList = ins;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038 let AsmString = asm;
39 let Pattern = pattern;
40 list<Predicate> Predicates = [IsThumb];
41}
42
Evan Chengb783fa32007-07-19 01:14:50 +000043class TI<dag outs, dag ins, string asm, list<dag> pattern>
44 : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "", pattern>;
45class TI1<dag outs, dag ins, string asm, list<dag> pattern>
46 : ThumbI<outs, ins, AddrModeT1, Size2Bytes, asm, "", pattern>;
47class TI2<dag outs, dag ins, string asm, list<dag> pattern>
48 : ThumbI<outs, ins, AddrModeT2, Size2Bytes, asm, "", pattern>;
49class TI4<dag outs, dag ins, string asm, list<dag> pattern>
50 : ThumbI<outs, ins, AddrModeT4, Size2Bytes, asm, "", pattern>;
51class TIs<dag outs, dag ins, string asm, list<dag> pattern>
52 : ThumbI<outs, ins, AddrModeTs, Size2Bytes, asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053
54// Two-address instructions
Evan Chengb783fa32007-07-19 01:14:50 +000055class TIt<dag outs, dag ins, string asm, list<dag> pattern>
56 : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "$lhs = $dst", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057
58// BL, BLX(1) are translated by assembler into two instructions
Evan Chengb783fa32007-07-19 01:14:50 +000059class TIx2<dag outs, dag ins, string asm, list<dag> pattern>
60 : ThumbI<outs, ins, AddrModeNone, Size4Bytes, asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061
62// BR_JT instructions
Evan Chengb783fa32007-07-19 01:14:50 +000063class TJTI<dag outs, dag ins, string asm, list<dag> pattern>
64 : ThumbI<outs, ins, AddrModeNone, SizeSpecial, asm, "", pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065
66def imm_neg_XFORM : SDNodeXForm<imm, [{
67 return CurDAG->getTargetConstant(-(int)N->getValue(), MVT::i32);
68}]>;
69def imm_comp_XFORM : SDNodeXForm<imm, [{
70 return CurDAG->getTargetConstant(~((uint32_t)N->getValue()), MVT::i32);
71}]>;
72
73
74/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
75def imm0_7 : PatLeaf<(i32 imm), [{
76 return (uint32_t)N->getValue() < 8;
77}]>;
78def imm0_7_neg : PatLeaf<(i32 imm), [{
79 return (uint32_t)-N->getValue() < 8;
80}], imm_neg_XFORM>;
81
82def imm0_255 : PatLeaf<(i32 imm), [{
83 return (uint32_t)N->getValue() < 256;
84}]>;
85def imm0_255_comp : PatLeaf<(i32 imm), [{
86 return ~((uint32_t)N->getValue()) < 256;
87}]>;
88
89def imm8_255 : PatLeaf<(i32 imm), [{
90 return (uint32_t)N->getValue() >= 8 && (uint32_t)N->getValue() < 256;
91}]>;
92def imm8_255_neg : PatLeaf<(i32 imm), [{
93 unsigned Val = -N->getValue();
94 return Val >= 8 && Val < 256;
95}], imm_neg_XFORM>;
96
97// Break imm's up into two pieces: an immediate + a left shift.
98// This uses thumb_immshifted to match and thumb_immshifted_val and
99// thumb_immshifted_shamt to get the val/shift pieces.
100def thumb_immshifted : PatLeaf<(imm), [{
101 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getValue());
102}]>;
103
104def thumb_immshifted_val : SDNodeXForm<imm, [{
105 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getValue());
106 return CurDAG->getTargetConstant(V, MVT::i32);
107}]>;
108
109def thumb_immshifted_shamt : SDNodeXForm<imm, [{
110 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getValue());
111 return CurDAG->getTargetConstant(V, MVT::i32);
112}]>;
113
114// Define Thumb specific addressing modes.
115
116// t_addrmode_rr := reg + reg
117//
118def t_addrmode_rr : Operand<i32>,
119 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
120 let PrintMethod = "printThumbAddrModeRROperand";
121 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg);
122}
123
124// t_addrmode_s4 := reg + reg
125// reg + imm5 * 4
126//
127def t_addrmode_s4 : Operand<i32>,
128 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
129 let PrintMethod = "printThumbAddrModeS4Operand";
130 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
131}
132
133// t_addrmode_s2 := reg + reg
134// reg + imm5 * 2
135//
136def t_addrmode_s2 : Operand<i32>,
137 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
138 let PrintMethod = "printThumbAddrModeS2Operand";
139 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
140}
141
142// t_addrmode_s1 := reg + reg
143// reg + imm5
144//
145def t_addrmode_s1 : Operand<i32>,
146 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
147 let PrintMethod = "printThumbAddrModeS1Operand";
148 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
149}
150
151// t_addrmode_sp := sp + imm8 * 4
152//
153def t_addrmode_sp : Operand<i32>,
154 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
155 let PrintMethod = "printThumbAddrModeSPOperand";
156 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
157}
158
159//===----------------------------------------------------------------------===//
160// Miscellaneous Instructions.
161//
162
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000163let Defs = [SP], Uses = [SP] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164def tADJCALLSTACKUP :
Bill Wendling22f8deb2007-11-13 00:44:25 +0000165PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2),
166 "@ tADJCALLSTACKUP $amt1",
167 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>, Requires<[IsThumb]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000168
169def tADJCALLSTACKDOWN :
Evan Chengb783fa32007-07-19 01:14:50 +0000170PseudoInst<(outs), (ins i32imm:$amt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171 "@ tADJCALLSTACKDOWN $amt",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000172 [(ARMcallseq_start imm:$amt)]>, Requires<[IsThumb]>;
173}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000174
175let isNotDuplicable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000176def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000177 "$cp:\n\tadd $dst, pc",
178 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
179
180//===----------------------------------------------------------------------===//
181// Control Flow Instructions.
182//
183
184let isReturn = 1, isTerminator = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000185 def tBX_RET : TI<(outs), (ins), "bx lr", [(ARMretflag)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186 // Alternative return instruction used by vararg functions.
Evan Chengb783fa32007-07-19 01:14:50 +0000187 def tBX_RET_vararg : TI<(outs), (ins GPR:$target), "bx $target", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188}
189
190// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng8610a3b2008-01-07 23:56:57 +0000191let isReturn = 1, isTerminator = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000192def tPOP_RET : TI<(outs reglist:$dst1, variable_ops), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193 "pop $dst1", []>;
194
Evan Cheng37e7c752007-07-21 00:34:19 +0000195let isCall = 1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196 Defs = [R0, R1, R2, R3, LR,
197 D0, D1, D2, D3, D4, D5, D6, D7] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000198 def tBL : TIx2<(outs), (ins i32imm:$func, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199 "bl ${func:call}",
200 [(ARMtcall tglobaladdr:$func)]>;
201 // ARMv5T and above
Evan Chengb783fa32007-07-19 01:14:50 +0000202 def tBLXi : TIx2<(outs), (ins i32imm:$func, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203 "blx ${func:call}",
204 [(ARMcall tglobaladdr:$func)]>, Requires<[HasV5T]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000205 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops),
206 "blx $func",
207 [(ARMtcall GPR:$func)]>, Requires<[HasV5T]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208 // ARMv4T
Evan Chengb783fa32007-07-19 01:14:50 +0000209 def tBX : TIx2<(outs), (ins GPR:$func, variable_ops),
210 "cpy lr, pc\n\tbx $func",
211 [(ARMcall_nolink GPR:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000212}
213
Evan Cheng37e7c752007-07-21 00:34:19 +0000214let isBranch = 1, isTerminator = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215 let isBarrier = 1 in {
216 let isPredicable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000217 def tB : TI<(outs), (ins brtarget:$target), "b $target",
218 [(br bb:$target)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219
220 // Far jump
Evan Chengb783fa32007-07-19 01:14:50 +0000221 def tBfar : TIx2<(outs), (ins brtarget:$target), "bl $target\t@ far jump",[]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000222
Evan Chengb783fa32007-07-19 01:14:50 +0000223 def tBR_JTr : TJTI<(outs),
224 (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
225 "cpy pc, $target \n\t.align\t2\n$jt",
226 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000227 }
228}
229
230// FIXME: should be able to write a pattern for ARMBrcond, but can't use
231// a two-value operand where a dag node expects two operands. :(
Evan Cheng37e7c752007-07-21 00:34:19 +0000232let isBranch = 1, isTerminator = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000233 def tBcc : TI<(outs), (ins brtarget:$target, pred:$cc), "b$cc $target",
234 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000235
236//===----------------------------------------------------------------------===//
237// Load Store Instructions.
238//
239
Evan Cheng8610a3b2008-01-07 23:56:57 +0000240let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000241def tLDR : TI4<(outs GPR:$dst), (ins t_addrmode_s4:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 "ldr $dst, $addr",
243 [(set GPR:$dst, (load t_addrmode_s4:$addr))]>;
244
Evan Chengb783fa32007-07-19 01:14:50 +0000245def tLDRB : TI1<(outs GPR:$dst), (ins t_addrmode_s1:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000246 "ldrb $dst, $addr",
247 [(set GPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
248
Evan Chengb783fa32007-07-19 01:14:50 +0000249def tLDRH : TI2<(outs GPR:$dst), (ins t_addrmode_s2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000250 "ldrh $dst, $addr",
251 [(set GPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
252
Evan Chengb783fa32007-07-19 01:14:50 +0000253def tLDRSB : TI1<(outs GPR:$dst), (ins t_addrmode_rr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 "ldrsb $dst, $addr",
255 [(set GPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
256
Evan Chengb783fa32007-07-19 01:14:50 +0000257def tLDRSH : TI2<(outs GPR:$dst), (ins t_addrmode_rr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000258 "ldrsh $dst, $addr",
259 [(set GPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
260
Evan Cheng8610a3b2008-01-07 23:56:57 +0000261let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000262def tLDRspi : TIs<(outs GPR:$dst), (ins t_addrmode_sp:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 "ldr $dst, $addr",
264 [(set GPR:$dst, (load t_addrmode_sp:$addr))]>;
265
266// Special instruction for restore. It cannot clobber condition register
267// when it's expanded by eliminateCallFramePseudoInstr().
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000268let isSimpleLoad = 1, mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000269def tRestore : TIs<(outs GPR:$dst), (ins t_addrmode_sp:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000270 "ldr $dst, $addr", []>;
271
272// Load tconstpool
Evan Cheng8610a3b2008-01-07 23:56:57 +0000273let isSimpleLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000274def tLDRpci : TIs<(outs GPR:$dst), (ins i32imm:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275 "ldr $dst, $addr",
276 [(set GPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
277
278// Special LDR for loads from non-pc-relative constpools.
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000279let isSimpleLoad = 1, mayLoad = 1, isReMaterializable = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000280def tLDRcp : TIs<(outs GPR:$dst), (ins i32imm:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000281 "ldr $dst, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282
Evan Chengb783fa32007-07-19 01:14:50 +0000283def tSTR : TI4<(outs), (ins GPR:$src, t_addrmode_s4:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 "str $src, $addr",
285 [(store GPR:$src, t_addrmode_s4:$addr)]>;
286
Evan Chengb783fa32007-07-19 01:14:50 +0000287def tSTRB : TI1<(outs), (ins GPR:$src, t_addrmode_s1:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 "strb $src, $addr",
289 [(truncstorei8 GPR:$src, t_addrmode_s1:$addr)]>;
290
Evan Chengb783fa32007-07-19 01:14:50 +0000291def tSTRH : TI2<(outs), (ins GPR:$src, t_addrmode_s2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 "strh $src, $addr",
293 [(truncstorei16 GPR:$src, t_addrmode_s2:$addr)]>;
294
Evan Chengb783fa32007-07-19 01:14:50 +0000295def tSTRspi : TIs<(outs), (ins GPR:$src, t_addrmode_sp:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296 "str $src, $addr",
297 [(store GPR:$src, t_addrmode_sp:$addr)]>;
298
Chris Lattner6887b142008-01-06 08:36:04 +0000299let mayStore = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300// Special instruction for spill. It cannot clobber condition register
301// when it's expanded by eliminateCallFramePseudoInstr().
Evan Chengb783fa32007-07-19 01:14:50 +0000302def tSpill : TIs<(outs), (ins GPR:$src, t_addrmode_sp:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303 "str $src, $addr", []>;
304}
305
306//===----------------------------------------------------------------------===//
307// Load / store multiple Instructions.
308//
309
310// TODO: A7-44: LDMIA - load multiple
311
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000312let mayLoad = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000313def tPOP : TI<(outs reglist:$dst1, variable_ops), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314 "pop $dst1", []>;
315
Chris Lattner6887b142008-01-06 08:36:04 +0000316let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000317def tPUSH : TI<(outs), (ins reglist:$src1, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000318 "push $src1", []>;
319
320//===----------------------------------------------------------------------===//
321// Arithmetic Instructions.
322//
323
324// Add with carry
Evan Chengb783fa32007-07-19 01:14:50 +0000325def tADC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326 "adc $dst, $rhs",
327 [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
328
Evan Chengb783fa32007-07-19 01:14:50 +0000329def tADDS : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330 "add $dst, $lhs, $rhs",
331 [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
332
333
Evan Chengb783fa32007-07-19 01:14:50 +0000334def tADDi3 : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 "add $dst, $lhs, $rhs",
336 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
337
Evan Chengb783fa32007-07-19 01:14:50 +0000338def tADDi8 : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000339 "add $dst, $rhs",
340 [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
341
Evan Chengb783fa32007-07-19 01:14:50 +0000342def tADDrr : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343 "add $dst, $lhs, $rhs",
344 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
345
Evan Chengb783fa32007-07-19 01:14:50 +0000346def tADDhirr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000347 "add $dst, $rhs", []>;
348
Evan Chengb783fa32007-07-19 01:14:50 +0000349def tADDrPCi : TI<(outs GPR:$dst), (ins i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000350 "add $dst, pc, $rhs * 4", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000351def tADDrSPi : TI<(outs GPR:$dst), (ins GPR:$sp, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352 "add $dst, $sp, $rhs * 4", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000353def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354 "add $dst, $rhs * 4", []>;
355
Evan Chengb783fa32007-07-19 01:14:50 +0000356def tAND : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357 "and $dst, $rhs",
358 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
359
Evan Chengb783fa32007-07-19 01:14:50 +0000360def tASRri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361 "asr $dst, $lhs, $rhs",
362 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
363
Evan Chengb783fa32007-07-19 01:14:50 +0000364def tASRrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000365 "asr $dst, $rhs",
366 [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
367
Evan Chengb783fa32007-07-19 01:14:50 +0000368def tBIC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369 "bic $dst, $rhs",
370 [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
371
372
Evan Chengb783fa32007-07-19 01:14:50 +0000373def tCMN : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000374 "cmn $lhs, $rhs",
375 [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
376
Evan Chengb783fa32007-07-19 01:14:50 +0000377def tCMPi8 : TI<(outs), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000378 "cmp $lhs, $rhs",
379 [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
380
Evan Chengb783fa32007-07-19 01:14:50 +0000381def tCMPr : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382 "cmp $lhs, $rhs",
383 [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
384
Evan Chengb783fa32007-07-19 01:14:50 +0000385def tTST : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000386 "tst $lhs, $rhs",
387 [(ARMcmpNZ (and GPR:$lhs, GPR:$rhs), 0)]>;
388
Evan Chengb783fa32007-07-19 01:14:50 +0000389def tCMNNZ : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390 "cmn $lhs, $rhs",
391 [(ARMcmpNZ GPR:$lhs, (ineg GPR:$rhs))]>;
392
Evan Chengb783fa32007-07-19 01:14:50 +0000393def tCMPNZi8 : TI<(outs), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394 "cmp $lhs, $rhs",
395 [(ARMcmpNZ GPR:$lhs, imm0_255:$rhs)]>;
396
Evan Chengb783fa32007-07-19 01:14:50 +0000397def tCMPNZr : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398 "cmp $lhs, $rhs",
399 [(ARMcmpNZ GPR:$lhs, GPR:$rhs)]>;
400
401// TODO: A7-37: CMP(3) - cmp hi regs
402
Evan Chengb783fa32007-07-19 01:14:50 +0000403def tEOR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000404 "eor $dst, $rhs",
405 [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
406
Evan Chengb783fa32007-07-19 01:14:50 +0000407def tLSLri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000408 "lsl $dst, $lhs, $rhs",
409 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
410
Evan Chengb783fa32007-07-19 01:14:50 +0000411def tLSLrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000412 "lsl $dst, $rhs",
413 [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
414
Evan Chengb783fa32007-07-19 01:14:50 +0000415def tLSRri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000416 "lsr $dst, $lhs, $rhs",
417 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
418
Evan Chengb783fa32007-07-19 01:14:50 +0000419def tLSRrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420 "lsr $dst, $rhs",
421 [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
422
423// FIXME: This is not rematerializable because mov changes the condition code.
Evan Chengb783fa32007-07-19 01:14:50 +0000424def tMOVi8 : TI<(outs GPR:$dst), (ins i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000425 "mov $dst, $src",
426 [(set GPR:$dst, imm0_255:$src)]>;
427
428// TODO: A7-73: MOV(2) - mov setting flag.
429
430
431// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
432// which is MOV(3). This also supports high registers.
Evan Chengb783fa32007-07-19 01:14:50 +0000433def tMOVr : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434 "cpy $dst, $src", []>;
435
Evan Chengb783fa32007-07-19 01:14:50 +0000436def tMUL : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437 "mul $dst, $rhs",
438 [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
439
Evan Chengb783fa32007-07-19 01:14:50 +0000440def tMVN : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000441 "mvn $dst, $src",
442 [(set GPR:$dst, (not GPR:$src))]>;
443
Evan Chengb783fa32007-07-19 01:14:50 +0000444def tNEG : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000445 "neg $dst, $src",
446 [(set GPR:$dst, (ineg GPR:$src))]>;
447
Evan Chengb783fa32007-07-19 01:14:50 +0000448def tORR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000449 "orr $dst, $rhs",
450 [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
451
452
Evan Chengb783fa32007-07-19 01:14:50 +0000453def tREV : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000454 "rev $dst, $src",
455 [(set GPR:$dst, (bswap GPR:$src))]>,
456 Requires<[IsThumb, HasV6]>;
457
Evan Chengb783fa32007-07-19 01:14:50 +0000458def tREV16 : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459 "rev16 $dst, $src",
460 [(set GPR:$dst,
461 (or (and (srl GPR:$src, 8), 0xFF),
462 (or (and (shl GPR:$src, 8), 0xFF00),
463 (or (and (srl GPR:$src, 8), 0xFF0000),
464 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
465 Requires<[IsThumb, HasV6]>;
466
Evan Chengb783fa32007-07-19 01:14:50 +0000467def tREVSH : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000468 "revsh $dst, $src",
469 [(set GPR:$dst,
470 (sext_inreg
471 (or (srl (and GPR:$src, 0xFFFF), 8),
472 (shl GPR:$src, 8)), i16))]>,
473 Requires<[IsThumb, HasV6]>;
474
Evan Chengb783fa32007-07-19 01:14:50 +0000475def tROR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000476 "ror $dst, $rhs",
477 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
478
479
480// Subtract with carry
Evan Chengb783fa32007-07-19 01:14:50 +0000481def tSBC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482 "sbc $dst, $rhs",
483 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
484
Evan Chengb783fa32007-07-19 01:14:50 +0000485def tSUBS : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486 "sub $dst, $lhs, $rhs",
487 [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
488
489
490// TODO: A7-96: STMIA - store multiple.
491
Evan Chengb783fa32007-07-19 01:14:50 +0000492def tSUBi3 : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000493 "sub $dst, $lhs, $rhs",
494 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
495
Evan Chengb783fa32007-07-19 01:14:50 +0000496def tSUBi8 : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497 "sub $dst, $rhs",
498 [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
499
Evan Chengb783fa32007-07-19 01:14:50 +0000500def tSUBrr : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000501 "sub $dst, $lhs, $rhs",
502 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
503
Evan Chengb783fa32007-07-19 01:14:50 +0000504def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000505 "sub $dst, $rhs * 4", []>;
506
Evan Chengb783fa32007-07-19 01:14:50 +0000507def tSXTB : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508 "sxtb $dst, $src",
509 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
510 Requires<[IsThumb, HasV6]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000511def tSXTH : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512 "sxth $dst, $src",
513 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
514 Requires<[IsThumb, HasV6]>;
515
516
Evan Chengb783fa32007-07-19 01:14:50 +0000517def tUXTB : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518 "uxtb $dst, $src",
519 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
520 Requires<[IsThumb, HasV6]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000521def tUXTH : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522 "uxth $dst, $src",
523 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>,
524 Requires<[IsThumb, HasV6]>;
525
526
527// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
528// Expanded by the scheduler into a branch sequence.
529let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
530 def tMOVCCr :
Evan Chengb783fa32007-07-19 01:14:50 +0000531 PseudoInst<(outs GPR:$dst), (ins GPR:$false, GPR:$true, pred:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532 "@ tMOVCCr $cc",
533 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))*/]>;
534
535// tLEApcrel - Load a pc-relative address into a register without offending the
536// assembler.
Evan Chengb783fa32007-07-19 01:14:50 +0000537def tLEApcrel : TIx2<(outs GPR:$dst), (ins i32imm:$label),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000538 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
539 "${:private}PCRELL${:uid}+4))\n"),
540 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
541 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
542 []>;
543
Evan Chengb783fa32007-07-19 01:14:50 +0000544def tLEApcrelJT : TIx2<(outs GPR:$dst), (ins i32imm:$label, i32imm:$id),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000545 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
546 "${:private}PCRELL${:uid}+4))\n"),
547 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
548 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
549 []>;
550
551//===----------------------------------------------------------------------===//
552// TLS Instructions
553//
554
555// __aeabi_read_tp preserves the registers r1-r3.
556let isCall = 1,
557 Defs = [R0, LR] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000558 def tTPsoft : TIx2<(outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559 "bl __aeabi_read_tp",
560 [(set R0, ARMthread_pointer)]>;
561}
562
563//===----------------------------------------------------------------------===//
564// Non-Instruction Patterns
565//
566
567// ConstantPool, GlobalAddress
568def : ThumbPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
569def : ThumbPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
570
571// JumpTable
572def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
573 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
574
575// Direct calls
576def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
577def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
578
579// Indirect calls to ARM routines
580def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
581
582// zextload i1 -> zextload i8
583def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
584 (tLDRB t_addrmode_s1:$addr)>;
585
586// extload -> zextload
587def : ThumbPat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
588def : ThumbPat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
589def : ThumbPat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
590
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591// Large immediate handling.
592
593// Two piece imms.
594def : ThumbPat<(i32 thumb_immshifted:$src),
595 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
596 (thumb_immshifted_shamt imm:$src))>;
597
598def : ThumbPat<(i32 imm0_255_comp:$src),
599 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;