blob: d2c1db6c959e4b1458033166407292b547b0d510 [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===- ARMInstrThumb.td - Thumb support for ARM ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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
32class ThumbI<dag ops, AddrMode am, SizeFlagVal sz,
33 string asm, string cstr, list<dag> pattern>
34 // FIXME: Set all opcodes to 0 for now.
Evan Cheng44bec522007-05-15 01:29:07 +000035 : InstARM<0, am, sz, IndexModeNone, cstr> {
36 let OperandList = ops;
37 let AsmString = asm;
Evan Chenga8e29892007-01-19 07:51:42 +000038 let Pattern = pattern;
39 list<Predicate> Predicates = [IsThumb];
40}
41
42class TI<dag ops, string asm, list<dag> pattern>
43 : ThumbI<ops, AddrModeNone, Size2Bytes, asm, "", pattern>;
44class TI1<dag ops, string asm, list<dag> pattern>
45 : ThumbI<ops, AddrModeT1, Size2Bytes, asm, "", pattern>;
46class TI2<dag ops, string asm, list<dag> pattern>
47 : ThumbI<ops, AddrModeT2, Size2Bytes, asm, "", pattern>;
48class TI4<dag ops, string asm, list<dag> pattern>
49 : ThumbI<ops, AddrModeT4, Size2Bytes, asm, "", pattern>;
50class TIs<dag ops, string asm, list<dag> pattern>
51 : ThumbI<ops, AddrModeTs, Size2Bytes, asm, "", pattern>;
52
53// Two-address instructions
54class TIt<dag ops, string asm, list<dag> pattern>
55 : ThumbI<ops, AddrModeNone, Size2Bytes, asm, "$lhs = $dst", pattern>;
56
57// BL, BLX(1) are translated by assembler into two instructions
58class TIx2<dag ops, string asm, list<dag> pattern>
59 : ThumbI<ops, AddrModeNone, Size4Bytes, asm, "", pattern>;
60
Evan Chengd85ac4d2007-01-27 02:29:45 +000061// BR_JT instructions
62class TJTI<dag ops, string asm, list<dag> pattern>
63 : ThumbI<ops, AddrModeNone, SizeSpecial, asm, "", pattern>;
64
Evan Chenga8e29892007-01-19 07:51:42 +000065def imm_neg_XFORM : SDNodeXForm<imm, [{
66 return CurDAG->getTargetConstant(-(int)N->getValue(), MVT::i32);
67}]>;
68def imm_comp_XFORM : SDNodeXForm<imm, [{
69 return CurDAG->getTargetConstant(~((uint32_t)N->getValue()), MVT::i32);
70}]>;
71
72
73/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
74def imm0_7 : PatLeaf<(i32 imm), [{
75 return (uint32_t)N->getValue() < 8;
76}]>;
77def imm0_7_neg : PatLeaf<(i32 imm), [{
78 return (uint32_t)-N->getValue() < 8;
79}], imm_neg_XFORM>;
80
81def imm0_255 : PatLeaf<(i32 imm), [{
82 return (uint32_t)N->getValue() < 256;
83}]>;
84def imm0_255_comp : PatLeaf<(i32 imm), [{
85 return ~((uint32_t)N->getValue()) < 256;
86}]>;
87
88def imm8_255 : PatLeaf<(i32 imm), [{
89 return (uint32_t)N->getValue() >= 8 && (uint32_t)N->getValue() < 256;
90}]>;
91def imm8_255_neg : PatLeaf<(i32 imm), [{
92 unsigned Val = -N->getValue();
93 return Val >= 8 && Val < 256;
94}], imm_neg_XFORM>;
95
96// Break imm's up into two pieces: an immediate + a left shift.
97// This uses thumb_immshifted to match and thumb_immshifted_val and
98// thumb_immshifted_shamt to get the val/shift pieces.
99def thumb_immshifted : PatLeaf<(imm), [{
100 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getValue());
101}]>;
102
103def thumb_immshifted_val : SDNodeXForm<imm, [{
104 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getValue());
105 return CurDAG->getTargetConstant(V, MVT::i32);
106}]>;
107
108def thumb_immshifted_shamt : SDNodeXForm<imm, [{
109 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getValue());
110 return CurDAG->getTargetConstant(V, MVT::i32);
111}]>;
112
113// Define Thumb specific addressing modes.
114
115// t_addrmode_rr := reg + reg
116//
117def t_addrmode_rr : Operand<i32>,
118 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
119 let PrintMethod = "printThumbAddrModeRROperand";
120 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg);
121}
122
Evan Chengc38f2bc2007-01-23 22:59:13 +0000123// t_addrmode_s4 := reg + reg
124// reg + imm5 * 4
Evan Chenga8e29892007-01-19 07:51:42 +0000125//
Evan Chengc38f2bc2007-01-23 22:59:13 +0000126def t_addrmode_s4 : Operand<i32>,
127 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
128 let PrintMethod = "printThumbAddrModeS4Operand";
Evan Chengcea117d2007-01-30 02:35:32 +0000129 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000130}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000131
132// t_addrmode_s2 := reg + reg
133// reg + imm5 * 2
134//
135def t_addrmode_s2 : Operand<i32>,
136 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
137 let PrintMethod = "printThumbAddrModeS2Operand";
Evan Chengcea117d2007-01-30 02:35:32 +0000138 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000139}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000140
141// t_addrmode_s1 := reg + reg
142// reg + imm5
143//
144def t_addrmode_s1 : Operand<i32>,
145 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
146 let PrintMethod = "printThumbAddrModeS1Operand";
Evan Chengcea117d2007-01-30 02:35:32 +0000147 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000148}
149
150// t_addrmode_sp := sp + imm8 * 4
151//
152def t_addrmode_sp : Operand<i32>,
153 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
154 let PrintMethod = "printThumbAddrModeSPOperand";
155 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
156}
157
158//===----------------------------------------------------------------------===//
159// Miscellaneous Instructions.
160//
161
Evan Cheng44bec522007-05-15 01:29:07 +0000162def tADJCALLSTACKUP :
163PseudoInst<(ops i32imm:$amt),
164 "@ tADJCALLSTACKUP $amt",
165 [(ARMcallseq_end imm:$amt)]>, Imp<[SP],[SP]>, Requires<[IsThumb]>;
166
167def tADJCALLSTACKDOWN :
168PseudoInst<(ops i32imm:$amt),
169 "@ tADJCALLSTACKDOWN $amt",
170 [(ARMcallseq_start imm:$amt)]>, Imp<[SP],[SP]>, Requires<[IsThumb]>;
171
Evan Chenga8e29892007-01-19 07:51:42 +0000172def tPICADD : TIt<(ops GPR:$dst, GPR:$lhs, pclabel:$cp),
Evan Chengc60e76d2007-01-30 20:37:08 +0000173 "$cp:\n\tadd $dst, pc",
Evan Chenga8e29892007-01-19 07:51:42 +0000174 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
175
176//===----------------------------------------------------------------------===//
177// Control Flow Instructions.
178//
179
Evan Cheng9d945f72007-02-01 01:49:46 +0000180let isReturn = 1, isTerminator = 1 in {
Evan Chenga8e29892007-01-19 07:51:42 +0000181 def tBX_RET : TI<(ops), "bx lr", [(ARMretflag)]>;
Evan Cheng9d945f72007-02-01 01:49:46 +0000182 // Alternative return instruction used by vararg functions.
183 def tBX_RET_vararg : TI<(ops GPR:$dst), "bx $dst", []>;
184}
Evan Chenga8e29892007-01-19 07:51:42 +0000185
186// FIXME: remove when we have a way to marking a MI with these properties.
187let isLoad = 1, isReturn = 1, isTerminator = 1 in
188def tPOP_RET : TI<(ops reglist:$dst1, variable_ops),
189 "pop $dst1", []>;
190
191let isCall = 1, noResults = 1,
192 Defs = [R0, R1, R2, R3, LR,
193 D0, D1, D2, D3, D4, D5, D6, D7] in {
194 def tBL : TIx2<(ops i32imm:$func, variable_ops),
195 "bl ${func:call}",
196 [(ARMtcall tglobaladdr:$func)]>;
197 // ARMv5T and above
198 def tBLXi : TIx2<(ops i32imm:$func, variable_ops),
199 "blx ${func:call}",
200 [(ARMcall tglobaladdr:$func)]>, Requires<[HasV5T]>;
201 def tBLXr : TI<(ops GPR:$dst, variable_ops),
202 "blx $dst",
203 [(ARMtcall GPR:$dst)]>, Requires<[HasV5T]>;
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000204 // ARMv4T
205 def tBX : TIx2<(ops GPR:$dst, variable_ops),
206 "cpy lr, pc\n\tbx $dst",
Evan Chenga8e29892007-01-19 07:51:42 +0000207 [(ARMcall_nolink GPR:$dst)]>;
208}
209
Evan Cheng3f8602c2007-05-16 21:53:43 +0000210let isBranch = 1, isTerminator = 1, noResults = 1 in {
211 let isBarrier = 1 in {
212 let isPredicable = 1 in
213 def tB : TI<(ops brtarget:$dst), "b $dst", [(br bb:$dst)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000214
Evan Cheng225dfe92007-01-30 01:13:37 +0000215 // Far jump
216 def tBfar : TIx2<(ops brtarget:$dst), "bl $dst\t@ far jump", []>;
217
Evan Chengd85ac4d2007-01-27 02:29:45 +0000218 def tBR_JTr : TJTI<(ops GPR:$dst, jtblock_operand:$jt, i32imm:$id),
219 "cpy pc, $dst \n\t.align\t2\n$jt",
220 [(ARMbrjt GPR:$dst, tjumptable:$jt, imm:$id)]>;
Evan Cheng3f8602c2007-05-16 21:53:43 +0000221 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000222}
223
Evan Chenga8e29892007-01-19 07:51:42 +0000224let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
Evan Cheng42d712b2007-05-08 21:08:43 +0000225 def tBcc : TI<(ops brtarget:$dst, ccop:$cc), "b$cc $dst",
Evan Chenga8e29892007-01-19 07:51:42 +0000226 [(ARMbrcond bb:$dst, imm:$cc)]>;
227
228//===----------------------------------------------------------------------===//
229// Load Store Instructions.
230//
231
232let isLoad = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000233def tLDR : TI4<(ops GPR:$dst, t_addrmode_s4:$addr),
234 "ldr $dst, $addr",
235 [(set GPR:$dst, (load t_addrmode_s4:$addr))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000236
Evan Chengc38f2bc2007-01-23 22:59:13 +0000237def tLDRB : TI1<(ops GPR:$dst, t_addrmode_s1:$addr),
238 "ldrb $dst, $addr",
239 [(set GPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
240
241def tLDRH : TI2<(ops GPR:$dst, t_addrmode_s2:$addr),
242 "ldrh $dst, $addr",
243 [(set GPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
244
245def tLDRSB : TI1<(ops GPR:$dst, t_addrmode_rr:$addr),
246 "ldrsb $dst, $addr",
247 [(set GPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
248
249def tLDRSH : TI2<(ops GPR:$dst, t_addrmode_rr:$addr),
250 "ldrsh $dst, $addr",
251 [(set GPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
252
Evan Chenga8e29892007-01-19 07:51:42 +0000253def tLDRspi : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
254 "ldr $dst, $addr",
255 [(set GPR:$dst, (load t_addrmode_sp:$addr))]>;
Evan Cheng012f2d92007-01-24 08:53:17 +0000256
Evan Cheng8e59ea92007-02-07 00:06:56 +0000257// Special instruction for restore. It cannot clobber condition register
258// when it's expanded by eliminateCallFramePseudoInstr().
259def tRestore : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
260 "ldr $dst, $addr", []>;
261
Evan Cheng012f2d92007-01-24 08:53:17 +0000262// Load tconstpool
263def tLDRpci : TIs<(ops GPR:$dst, i32imm:$addr),
264 "ldr $dst, $addr",
265 [(set GPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Evan Chengfa775d02007-03-19 07:20:03 +0000266
267// Special LDR for loads from non-pc-relative constpools.
268let isReMaterializable = 1 in
269def tLDRcp : TIs<(ops GPR:$dst, i32imm:$addr),
270 "ldr $dst, $addr", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000271} // isLoad
272
273let isStore = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000274def tSTR : TI4<(ops GPR:$src, t_addrmode_s4:$addr),
275 "str $src, $addr",
276 [(store GPR:$src, t_addrmode_s4:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000277
Evan Chengc38f2bc2007-01-23 22:59:13 +0000278def tSTRB : TI1<(ops GPR:$src, t_addrmode_s1:$addr),
279 "strb $src, $addr",
280 [(truncstorei8 GPR:$src, t_addrmode_s1:$addr)]>;
281
282def tSTRH : TI2<(ops GPR:$src, t_addrmode_s2:$addr),
283 "strh $src, $addr",
284 [(truncstorei16 GPR:$src, t_addrmode_s2:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000285
286def tSTRspi : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
287 "str $src, $addr",
288 [(store GPR:$src, t_addrmode_sp:$addr)]>;
Evan Cheng8e59ea92007-02-07 00:06:56 +0000289
290// Special instruction for spill. It cannot clobber condition register
291// when it's expanded by eliminateCallFramePseudoInstr().
292def tSpill : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
293 "str $src, $addr", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000294}
295
296//===----------------------------------------------------------------------===//
297// Load / store multiple Instructions.
298//
299
300// TODO: A7-44: LDMIA - load multiple
301
302let isLoad = 1 in
303def tPOP : TI<(ops reglist:$dst1, variable_ops),
304 "pop $dst1", []>;
305
306let isStore = 1 in
307def tPUSH : TI<(ops reglist:$src1, variable_ops),
308 "push $src1", []>;
309
310//===----------------------------------------------------------------------===//
311// Arithmetic Instructions.
312//
313
Evan Cheng53d7dba2007-01-27 00:07:15 +0000314// Add with carry
315def tADC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
316 "adc $dst, $rhs",
317 [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
318
319def tADDS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
Evan Cheng3471b602007-01-31 20:12:31 +0000320 "add $dst, $lhs, $rhs",
Evan Cheng53d7dba2007-01-27 00:07:15 +0000321 [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
322
323
Evan Chenga8e29892007-01-19 07:51:42 +0000324def tADDi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
325 "add $dst, $lhs, $rhs",
326 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
327
328def tADDi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
329 "add $dst, $rhs",
330 [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
331
332def tADDrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
333 "add $dst, $lhs, $rhs",
334 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
335
336def tADDhirr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
337 "add $dst, $rhs", []>;
338
339def tADDrPCi : TI<(ops GPR:$dst, i32imm:$rhs),
340 "add $dst, pc, $rhs * 4", []>;
341def tADDrSPi : TI<(ops GPR:$dst, GPR:$sp, i32imm:$rhs),
342 "add $dst, $sp, $rhs * 4", []>;
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000343def tADDspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
344 "add $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000345
Evan Chenga8e29892007-01-19 07:51:42 +0000346def tAND : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
347 "and $dst, $rhs",
348 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
349
350def tASRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
351 "asr $dst, $lhs, $rhs",
352 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
353
354def tASRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
355 "asr $dst, $rhs",
356 [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
357
358def tBIC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
359 "bic $dst, $rhs",
360 [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
361
362
363def tCMN : TI<(ops GPR:$lhs, GPR:$rhs),
364 "cmn $lhs, $rhs",
365 [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
366
367def tCMPi8 : TI<(ops GPR:$lhs, i32imm:$rhs),
368 "cmp $lhs, $rhs",
369 [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
370
371def tCMPr : TI<(ops GPR:$lhs, GPR:$rhs),
372 "cmp $lhs, $rhs",
373 [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000374
375def tTST : TI<(ops GPR:$lhs, GPR:$rhs),
376 "tst $lhs, $rhs",
377 [(ARMcmpNZ (and GPR:$lhs, GPR:$rhs), 0)]>;
378
379def tCMNNZ : TI<(ops GPR:$lhs, GPR:$rhs),
380 "cmn $lhs, $rhs",
381 [(ARMcmpNZ GPR:$lhs, (ineg GPR:$rhs))]>;
382
383def tCMPNZi8 : TI<(ops GPR:$lhs, i32imm:$rhs),
384 "cmp $lhs, $rhs",
385 [(ARMcmpNZ GPR:$lhs, imm0_255:$rhs)]>;
386
387def tCMPNZr : TI<(ops GPR:$lhs, GPR:$rhs),
388 "cmp $lhs, $rhs",
389 [(ARMcmpNZ GPR:$lhs, GPR:$rhs)]>;
390
Evan Chenga8e29892007-01-19 07:51:42 +0000391// TODO: A7-37: CMP(3) - cmp hi regs
392
393def tEOR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
394 "eor $dst, $rhs",
395 [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
396
397def tLSLri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
398 "lsl $dst, $lhs, $rhs",
399 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
400
401def tLSLrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
402 "lsl $dst, $rhs",
403 [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
404
405def tLSRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
406 "lsr $dst, $lhs, $rhs",
407 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
408
409def tLSRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
410 "lsr $dst, $rhs",
411 [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
412
Evan Cheng5e3c2032007-03-29 21:38:31 +0000413// FIXME: This is not rematerializable because mov changes the condition code.
Evan Cheng9f6636f2007-03-19 07:48:02 +0000414def tMOVi8 : TI<(ops GPR:$dst, i32imm:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000415 "mov $dst, $src",
416 [(set GPR:$dst, imm0_255:$src)]>;
417
418// TODO: A7-73: MOV(2) - mov setting flag.
419
420
421// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
422// which is MOV(3). This also supports high registers.
Evan Cheng9f6636f2007-03-19 07:48:02 +0000423def tMOVr : TI<(ops GPR:$dst, GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000424 "cpy $dst, $src", []>;
425
426def tMUL : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
427 "mul $dst, $rhs",
428 [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
429
430def tMVN : TI<(ops GPR:$dst, GPR:$src),
431 "mvn $dst, $src",
432 [(set GPR:$dst, (not GPR:$src))]>;
433
434def tNEG : TI<(ops GPR:$dst, GPR:$src),
435 "neg $dst, $src",
436 [(set GPR:$dst, (ineg GPR:$src))]>;
437
438def tORR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
439 "orr $dst, $rhs",
440 [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
441
442
443def tREV : TI<(ops GPR:$dst, GPR:$src),
444 "rev $dst, $src",
445 [(set GPR:$dst, (bswap GPR:$src))]>,
446 Requires<[IsThumb, HasV6]>;
447
448def tREV16 : TI<(ops GPR:$dst, GPR:$src),
449 "rev16 $dst, $src",
450 [(set GPR:$dst,
451 (or (and (srl GPR:$src, 8), 0xFF),
452 (or (and (shl GPR:$src, 8), 0xFF00),
453 (or (and (srl GPR:$src, 8), 0xFF0000),
454 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
455 Requires<[IsThumb, HasV6]>;
456
457def tREVSH : TI<(ops GPR:$dst, GPR:$src),
458 "revsh $dst, $src",
459 [(set GPR:$dst,
460 (sext_inreg
461 (or (srl (and GPR:$src, 0xFFFF), 8),
462 (shl GPR:$src, 8)), i16))]>,
463 Requires<[IsThumb, HasV6]>;
464
465def tROR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
466 "ror $dst, $rhs",
467 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
468
Evan Cheng53d7dba2007-01-27 00:07:15 +0000469
470// Subtract with carry
Evan Chenga8e29892007-01-19 07:51:42 +0000471def tSBC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
472 "sbc $dst, $rhs",
473 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
474
Evan Cheng53d7dba2007-01-27 00:07:15 +0000475def tSUBS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
Evan Cheng3471b602007-01-31 20:12:31 +0000476 "sub $dst, $lhs, $rhs",
Evan Cheng53d7dba2007-01-27 00:07:15 +0000477 [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
478
479
Evan Chenga8e29892007-01-19 07:51:42 +0000480// TODO: A7-96: STMIA - store multiple.
481
482def tSUBi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
483 "sub $dst, $lhs, $rhs",
484 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
485
486def tSUBi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
487 "sub $dst, $rhs",
488 [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
489
490def tSUBrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
491 "sub $dst, $lhs, $rhs",
492 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
493
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000494def tSUBspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
495 "sub $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000496
497def tSXTB : TI<(ops GPR:$dst, GPR:$src),
498 "sxtb $dst, $src",
499 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
500 Requires<[IsThumb, HasV6]>;
501def tSXTH : TI<(ops GPR:$dst, GPR:$src),
502 "sxth $dst, $src",
503 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
504 Requires<[IsThumb, HasV6]>;
505
Evan Chenga8e29892007-01-19 07:51:42 +0000506
507def tUXTB : TI<(ops GPR:$dst, GPR:$src),
508 "uxtb $dst, $src",
509 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
510 Requires<[IsThumb, HasV6]>;
511def tUXTH : TI<(ops GPR:$dst, GPR:$src),
512 "uxth $dst, $src",
513 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>,
514 Requires<[IsThumb, HasV6]>;
515
516
517// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
518// Expanded by the scheduler into a branch sequence.
519let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
520 def tMOVCCr :
Evan Cheng42d712b2007-05-08 21:08:43 +0000521 PseudoInst<(ops GPR:$dst, GPR:$false, GPR:$true, ccop:$cc),
Evan Chenga8e29892007-01-19 07:51:42 +0000522 "@ tMOVCCr $cc",
523 [(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))]>;
524
525// tLEApcrel - Load a pc-relative address into a register without offending the
526// assembler.
Evan Chengeec041a2007-04-27 07:50:02 +0000527def tLEApcrel : TIx2<(ops GPR:$dst, i32imm:$label),
Evan Chenga8e29892007-01-19 07:51:42 +0000528 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
Evan Cheng1b201682007-05-01 20:27:19 +0000529 "${:private}PCRELL${:uid}+4))\n"),
Evan Chenge0c2b6b2007-02-01 03:04:49 +0000530 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
531 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
Evan Chenga8e29892007-01-19 07:51:42 +0000532 []>;
533
Evan Chengeec041a2007-04-27 07:50:02 +0000534def tLEApcrelJT : TIx2<(ops GPR:$dst, i32imm:$label, i32imm:$id),
Evan Chengd85ac4d2007-01-27 02:29:45 +0000535 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
536 "${:private}PCRELL${:uid}+4))\n"),
Evan Chenge0c2b6b2007-02-01 03:04:49 +0000537 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
538 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
539 []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +0000540
Evan Chenga8e29892007-01-19 07:51:42 +0000541//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000542// TLS Instructions
543//
544
545// __aeabi_read_tp preserves the registers r1-r3.
546let isCall = 1,
547 Defs = [R0, LR] in {
548 def tTPsoft : TIx2<(ops),
549 "bl __aeabi_read_tp",
550 [(set R0, ARMthread_pointer)]>;
551}
552
553//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +0000554// Non-Instruction Patterns
555//
556
557// ConstantPool, GlobalAddress
558def : ThumbPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
559def : ThumbPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000560
Evan Chengd85ac4d2007-01-27 02:29:45 +0000561// JumpTable
562def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
563 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
564
Evan Chenga8e29892007-01-19 07:51:42 +0000565// Direct calls
566def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
567def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
568
569// Indirect calls to ARM routines
570def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
571
572// zextload i1 -> zextload i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000573def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
574 (tLDRB t_addrmode_s1:$addr)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000575
Evan Chengb60c02e2007-01-26 19:13:16 +0000576// extload -> zextload
577def : ThumbPat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
578def : ThumbPat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
579def : ThumbPat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
580
Evan Chenga8e29892007-01-19 07:51:42 +0000581// truncstore i1 -> truncstore i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000582def : ThumbPat<(truncstorei1 GPR:$src, t_addrmode_s1:$dst),
583 (tSTRB GPR:$src, t_addrmode_s1:$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000584
585// Large immediate handling.
586
587// Two piece imms.
588def : ThumbPat<(i32 thumb_immshifted:$src),
Evan Cheng9f6636f2007-03-19 07:48:02 +0000589 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
Evan Chenga8e29892007-01-19 07:51:42 +0000590 (thumb_immshifted_shamt imm:$src))>;
591
592def : ThumbPat<(i32 imm0_255_comp:$src),
Evan Cheng9f6636f2007-03-19 07:48:02 +0000593 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;