blob: 8f9bc43c4f65f1e93609038031b344dc0eddf0d2 [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().
Evan Cheng8610a3b2008-01-07 23:56:57 +0000268let isSimpleLoad = 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.
Evan Cheng8610a3b2008-01-07 23:56:57 +0000279let isSimpleLoad = 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
Evan Chengb783fa32007-07-19 01:14:50 +0000312def tPOP : TI<(outs reglist:$dst1, variable_ops), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313 "pop $dst1", []>;
314
Chris Lattner6887b142008-01-06 08:36:04 +0000315let mayStore = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000316def tPUSH : TI<(outs), (ins reglist:$src1, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317 "push $src1", []>;
318
319//===----------------------------------------------------------------------===//
320// Arithmetic Instructions.
321//
322
323// Add with carry
Evan Chengb783fa32007-07-19 01:14:50 +0000324def tADC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325 "adc $dst, $rhs",
326 [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
327
Evan Chengb783fa32007-07-19 01:14:50 +0000328def tADDS : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329 "add $dst, $lhs, $rhs",
330 [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
331
332
Evan Chengb783fa32007-07-19 01:14:50 +0000333def tADDi3 : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334 "add $dst, $lhs, $rhs",
335 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
336
Evan Chengb783fa32007-07-19 01:14:50 +0000337def tADDi8 : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338 "add $dst, $rhs",
339 [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
340
Evan Chengb783fa32007-07-19 01:14:50 +0000341def tADDrr : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342 "add $dst, $lhs, $rhs",
343 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
344
Evan Chengb783fa32007-07-19 01:14:50 +0000345def tADDhirr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000346 "add $dst, $rhs", []>;
347
Evan Chengb783fa32007-07-19 01:14:50 +0000348def tADDrPCi : TI<(outs GPR:$dst), (ins i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349 "add $dst, pc, $rhs * 4", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000350def tADDrSPi : TI<(outs GPR:$dst), (ins GPR:$sp, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351 "add $dst, $sp, $rhs * 4", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000352def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000353 "add $dst, $rhs * 4", []>;
354
Evan Chengb783fa32007-07-19 01:14:50 +0000355def tAND : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356 "and $dst, $rhs",
357 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
358
Evan Chengb783fa32007-07-19 01:14:50 +0000359def tASRri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 "asr $dst, $lhs, $rhs",
361 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
362
Evan Chengb783fa32007-07-19 01:14:50 +0000363def tASRrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364 "asr $dst, $rhs",
365 [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
366
Evan Chengb783fa32007-07-19 01:14:50 +0000367def tBIC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000368 "bic $dst, $rhs",
369 [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
370
371
Evan Chengb783fa32007-07-19 01:14:50 +0000372def tCMN : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000373 "cmn $lhs, $rhs",
374 [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
375
Evan Chengb783fa32007-07-19 01:14:50 +0000376def tCMPi8 : TI<(outs), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000377 "cmp $lhs, $rhs",
378 [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
379
Evan Chengb783fa32007-07-19 01:14:50 +0000380def tCMPr : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000381 "cmp $lhs, $rhs",
382 [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
383
Evan Chengb783fa32007-07-19 01:14:50 +0000384def tTST : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385 "tst $lhs, $rhs",
386 [(ARMcmpNZ (and GPR:$lhs, GPR:$rhs), 0)]>;
387
Evan Chengb783fa32007-07-19 01:14:50 +0000388def tCMNNZ : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389 "cmn $lhs, $rhs",
390 [(ARMcmpNZ GPR:$lhs, (ineg GPR:$rhs))]>;
391
Evan Chengb783fa32007-07-19 01:14:50 +0000392def tCMPNZi8 : TI<(outs), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393 "cmp $lhs, $rhs",
394 [(ARMcmpNZ GPR:$lhs, imm0_255:$rhs)]>;
395
Evan Chengb783fa32007-07-19 01:14:50 +0000396def tCMPNZr : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 "cmp $lhs, $rhs",
398 [(ARMcmpNZ GPR:$lhs, GPR:$rhs)]>;
399
400// TODO: A7-37: CMP(3) - cmp hi regs
401
Evan Chengb783fa32007-07-19 01:14:50 +0000402def tEOR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403 "eor $dst, $rhs",
404 [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
405
Evan Chengb783fa32007-07-19 01:14:50 +0000406def tLSLri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000407 "lsl $dst, $lhs, $rhs",
408 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
409
Evan Chengb783fa32007-07-19 01:14:50 +0000410def tLSLrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411 "lsl $dst, $rhs",
412 [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
413
Evan Chengb783fa32007-07-19 01:14:50 +0000414def tLSRri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415 "lsr $dst, $lhs, $rhs",
416 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
417
Evan Chengb783fa32007-07-19 01:14:50 +0000418def tLSRrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000419 "lsr $dst, $rhs",
420 [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
421
422// FIXME: This is not rematerializable because mov changes the condition code.
Evan Chengb783fa32007-07-19 01:14:50 +0000423def tMOVi8 : TI<(outs GPR:$dst), (ins i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000424 "mov $dst, $src",
425 [(set GPR:$dst, imm0_255:$src)]>;
426
427// TODO: A7-73: MOV(2) - mov setting flag.
428
429
430// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
431// which is MOV(3). This also supports high registers.
Evan Chengb783fa32007-07-19 01:14:50 +0000432def tMOVr : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433 "cpy $dst, $src", []>;
434
Evan Chengb783fa32007-07-19 01:14:50 +0000435def tMUL : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000436 "mul $dst, $rhs",
437 [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
438
Evan Chengb783fa32007-07-19 01:14:50 +0000439def tMVN : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000440 "mvn $dst, $src",
441 [(set GPR:$dst, (not GPR:$src))]>;
442
Evan Chengb783fa32007-07-19 01:14:50 +0000443def tNEG : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444 "neg $dst, $src",
445 [(set GPR:$dst, (ineg GPR:$src))]>;
446
Evan Chengb783fa32007-07-19 01:14:50 +0000447def tORR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448 "orr $dst, $rhs",
449 [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
450
451
Evan Chengb783fa32007-07-19 01:14:50 +0000452def tREV : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453 "rev $dst, $src",
454 [(set GPR:$dst, (bswap GPR:$src))]>,
455 Requires<[IsThumb, HasV6]>;
456
Evan Chengb783fa32007-07-19 01:14:50 +0000457def tREV16 : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458 "rev16 $dst, $src",
459 [(set GPR:$dst,
460 (or (and (srl GPR:$src, 8), 0xFF),
461 (or (and (shl GPR:$src, 8), 0xFF00),
462 (or (and (srl GPR:$src, 8), 0xFF0000),
463 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
464 Requires<[IsThumb, HasV6]>;
465
Evan Chengb783fa32007-07-19 01:14:50 +0000466def tREVSH : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467 "revsh $dst, $src",
468 [(set GPR:$dst,
469 (sext_inreg
470 (or (srl (and GPR:$src, 0xFFFF), 8),
471 (shl GPR:$src, 8)), i16))]>,
472 Requires<[IsThumb, HasV6]>;
473
Evan Chengb783fa32007-07-19 01:14:50 +0000474def tROR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475 "ror $dst, $rhs",
476 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
477
478
479// Subtract with carry
Evan Chengb783fa32007-07-19 01:14:50 +0000480def tSBC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000481 "sbc $dst, $rhs",
482 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
483
Evan Chengb783fa32007-07-19 01:14:50 +0000484def tSUBS : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000485 "sub $dst, $lhs, $rhs",
486 [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
487
488
489// TODO: A7-96: STMIA - store multiple.
490
Evan Chengb783fa32007-07-19 01:14:50 +0000491def tSUBi3 : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492 "sub $dst, $lhs, $rhs",
493 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
494
Evan Chengb783fa32007-07-19 01:14:50 +0000495def tSUBi8 : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496 "sub $dst, $rhs",
497 [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
498
Evan Chengb783fa32007-07-19 01:14:50 +0000499def tSUBrr : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000500 "sub $dst, $lhs, $rhs",
501 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
502
Evan Chengb783fa32007-07-19 01:14:50 +0000503def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504 "sub $dst, $rhs * 4", []>;
505
Evan Chengb783fa32007-07-19 01:14:50 +0000506def tSXTB : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000507 "sxtb $dst, $src",
508 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
509 Requires<[IsThumb, HasV6]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000510def tSXTH : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511 "sxth $dst, $src",
512 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
513 Requires<[IsThumb, HasV6]>;
514
515
Evan Chengb783fa32007-07-19 01:14:50 +0000516def tUXTB : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000517 "uxtb $dst, $src",
518 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
519 Requires<[IsThumb, HasV6]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000520def tUXTH : TI<(outs GPR:$dst), (ins GPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521 "uxth $dst, $src",
522 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>,
523 Requires<[IsThumb, HasV6]>;
524
525
526// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
527// Expanded by the scheduler into a branch sequence.
528let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
529 def tMOVCCr :
Evan Chengb783fa32007-07-19 01:14:50 +0000530 PseudoInst<(outs GPR:$dst), (ins GPR:$false, GPR:$true, pred:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000531 "@ tMOVCCr $cc",
532 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))*/]>;
533
534// tLEApcrel - Load a pc-relative address into a register without offending the
535// assembler.
Evan Chengb783fa32007-07-19 01:14:50 +0000536def tLEApcrel : TIx2<(outs GPR:$dst), (ins i32imm:$label),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
538 "${:private}PCRELL${:uid}+4))\n"),
539 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
540 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
541 []>;
542
Evan Chengb783fa32007-07-19 01:14:50 +0000543def tLEApcrelJT : TIx2<(outs GPR:$dst), (ins i32imm:$label, i32imm:$id),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
545 "${:private}PCRELL${:uid}+4))\n"),
546 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
547 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
548 []>;
549
550//===----------------------------------------------------------------------===//
551// TLS Instructions
552//
553
554// __aeabi_read_tp preserves the registers r1-r3.
555let isCall = 1,
556 Defs = [R0, LR] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000557 def tTPsoft : TIx2<(outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558 "bl __aeabi_read_tp",
559 [(set R0, ARMthread_pointer)]>;
560}
561
562//===----------------------------------------------------------------------===//
563// Non-Instruction Patterns
564//
565
566// ConstantPool, GlobalAddress
567def : ThumbPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
568def : ThumbPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
569
570// JumpTable
571def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
572 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
573
574// Direct calls
575def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
576def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
577
578// Indirect calls to ARM routines
579def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
580
581// zextload i1 -> zextload i8
582def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
583 (tLDRB t_addrmode_s1:$addr)>;
584
585// extload -> zextload
586def : ThumbPat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
587def : ThumbPat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
588def : ThumbPat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
589
590// truncstore i1 -> truncstore i8
591def : ThumbPat<(truncstorei1 GPR:$src, t_addrmode_s1:$dst),
592 (tSTRB GPR:$src, t_addrmode_s1:$dst)>;
593
594// Large immediate handling.
595
596// Two piece imms.
597def : ThumbPat<(i32 thumb_immshifted:$src),
598 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
599 (thumb_immshifted_shamt imm:$src))>;
600
601def : ThumbPat<(i32 imm0_255_comp:$src),
602 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;