blob: a1f03bd1726a77ce27cebea80913e4bc9bcbad64 [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.
35 : InstARM<0, am, sz, IndexModeNone, ops, asm, cstr> {
36 let Pattern = pattern;
37 list<Predicate> Predicates = [IsThumb];
38}
39
40class TI<dag ops, string asm, list<dag> pattern>
41 : ThumbI<ops, AddrModeNone, Size2Bytes, asm, "", pattern>;
42class TI1<dag ops, string asm, list<dag> pattern>
43 : ThumbI<ops, AddrModeT1, Size2Bytes, asm, "", pattern>;
44class TI2<dag ops, string asm, list<dag> pattern>
45 : ThumbI<ops, AddrModeT2, Size2Bytes, asm, "", pattern>;
46class TI4<dag ops, string asm, list<dag> pattern>
47 : ThumbI<ops, AddrModeT4, Size2Bytes, asm, "", pattern>;
48class TIs<dag ops, string asm, list<dag> pattern>
49 : ThumbI<ops, AddrModeTs, Size2Bytes, asm, "", pattern>;
50
51// Two-address instructions
52class TIt<dag ops, string asm, list<dag> pattern>
53 : ThumbI<ops, AddrModeNone, Size2Bytes, asm, "$lhs = $dst", pattern>;
54
55// BL, BLX(1) are translated by assembler into two instructions
56class TIx2<dag ops, string asm, list<dag> pattern>
57 : ThumbI<ops, AddrModeNone, Size4Bytes, asm, "", pattern>;
58
Evan Chengd85ac4d2007-01-27 02:29:45 +000059// BR_JT instructions
60class TJTI<dag ops, string asm, list<dag> pattern>
61 : ThumbI<ops, AddrModeNone, SizeSpecial, asm, "", pattern>;
62
Evan Chenga8e29892007-01-19 07:51:42 +000063def imm_neg_XFORM : SDNodeXForm<imm, [{
64 return CurDAG->getTargetConstant(-(int)N->getValue(), MVT::i32);
65}]>;
66def imm_comp_XFORM : SDNodeXForm<imm, [{
67 return CurDAG->getTargetConstant(~((uint32_t)N->getValue()), MVT::i32);
68}]>;
69
70
71/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
72def imm0_7 : PatLeaf<(i32 imm), [{
73 return (uint32_t)N->getValue() < 8;
74}]>;
75def imm0_7_neg : PatLeaf<(i32 imm), [{
76 return (uint32_t)-N->getValue() < 8;
77}], imm_neg_XFORM>;
78
79def imm0_255 : PatLeaf<(i32 imm), [{
80 return (uint32_t)N->getValue() < 256;
81}]>;
82def imm0_255_comp : PatLeaf<(i32 imm), [{
83 return ~((uint32_t)N->getValue()) < 256;
84}]>;
85
86def imm8_255 : PatLeaf<(i32 imm), [{
87 return (uint32_t)N->getValue() >= 8 && (uint32_t)N->getValue() < 256;
88}]>;
89def imm8_255_neg : PatLeaf<(i32 imm), [{
90 unsigned Val = -N->getValue();
91 return Val >= 8 && Val < 256;
92}], imm_neg_XFORM>;
93
94// Break imm's up into two pieces: an immediate + a left shift.
95// This uses thumb_immshifted to match and thumb_immshifted_val and
96// thumb_immshifted_shamt to get the val/shift pieces.
97def thumb_immshifted : PatLeaf<(imm), [{
98 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getValue());
99}]>;
100
101def thumb_immshifted_val : SDNodeXForm<imm, [{
102 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getValue());
103 return CurDAG->getTargetConstant(V, MVT::i32);
104}]>;
105
106def thumb_immshifted_shamt : SDNodeXForm<imm, [{
107 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getValue());
108 return CurDAG->getTargetConstant(V, MVT::i32);
109}]>;
110
111// Define Thumb specific addressing modes.
112
113// t_addrmode_rr := reg + reg
114//
115def t_addrmode_rr : Operand<i32>,
116 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
117 let PrintMethod = "printThumbAddrModeRROperand";
118 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg);
119}
120
Evan Chengc38f2bc2007-01-23 22:59:13 +0000121// t_addrmode_s4 := reg + reg
122// reg + imm5 * 4
Evan Chenga8e29892007-01-19 07:51:42 +0000123//
Evan Chengc38f2bc2007-01-23 22:59:13 +0000124def t_addrmode_s4 : Operand<i32>,
125 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
126 let PrintMethod = "printThumbAddrModeS4Operand";
Evan Chengcea117d2007-01-30 02:35:32 +0000127 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000128}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000129
130// t_addrmode_s2 := reg + reg
131// reg + imm5 * 2
132//
133def t_addrmode_s2 : Operand<i32>,
134 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
135 let PrintMethod = "printThumbAddrModeS2Operand";
Evan Chengcea117d2007-01-30 02:35:32 +0000136 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000137}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000138
139// t_addrmode_s1 := reg + reg
140// reg + imm5
141//
142def t_addrmode_s1 : Operand<i32>,
143 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
144 let PrintMethod = "printThumbAddrModeS1Operand";
Evan Chengcea117d2007-01-30 02:35:32 +0000145 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000146}
147
148// t_addrmode_sp := sp + imm8 * 4
149//
150def t_addrmode_sp : Operand<i32>,
151 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
152 let PrintMethod = "printThumbAddrModeSPOperand";
153 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
154}
155
156//===----------------------------------------------------------------------===//
157// Miscellaneous Instructions.
158//
159
160def tPICADD : TIt<(ops GPR:$dst, GPR:$lhs, pclabel:$cp),
Evan Chengc60e76d2007-01-30 20:37:08 +0000161 "$cp:\n\tadd $dst, pc",
Evan Chenga8e29892007-01-19 07:51:42 +0000162 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
163
164//===----------------------------------------------------------------------===//
165// Control Flow Instructions.
166//
167
Evan Cheng9d945f72007-02-01 01:49:46 +0000168let isReturn = 1, isTerminator = 1 in {
Evan Chenga8e29892007-01-19 07:51:42 +0000169 def tBX_RET : TI<(ops), "bx lr", [(ARMretflag)]>;
Evan Cheng9d945f72007-02-01 01:49:46 +0000170 // Alternative return instruction used by vararg functions.
171 def tBX_RET_vararg : TI<(ops GPR:$dst), "bx $dst", []>;
172}
Evan Chenga8e29892007-01-19 07:51:42 +0000173
174// FIXME: remove when we have a way to marking a MI with these properties.
175let isLoad = 1, isReturn = 1, isTerminator = 1 in
176def tPOP_RET : TI<(ops reglist:$dst1, variable_ops),
177 "pop $dst1", []>;
178
179let isCall = 1, noResults = 1,
180 Defs = [R0, R1, R2, R3, LR,
181 D0, D1, D2, D3, D4, D5, D6, D7] in {
182 def tBL : TIx2<(ops i32imm:$func, variable_ops),
183 "bl ${func:call}",
184 [(ARMtcall tglobaladdr:$func)]>;
185 // ARMv5T and above
186 def tBLXi : TIx2<(ops i32imm:$func, variable_ops),
187 "blx ${func:call}",
188 [(ARMcall tglobaladdr:$func)]>, Requires<[HasV5T]>;
189 def tBLXr : TI<(ops GPR:$dst, variable_ops),
190 "blx $dst",
191 [(ARMtcall GPR:$dst)]>, Requires<[HasV5T]>;
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +0000192 let Uses = [LR] in {
193 // ARMv4T
194 def tBX : TI<(ops GPR:$dst, variable_ops),
195 "bx $dst",
Evan Chenga8e29892007-01-19 07:51:42 +0000196 [(ARMcall_nolink GPR:$dst)]>;
Lauro Ramos Venancio64c88d72007-03-20 17:57:23 +0000197 }
Evan Chenga8e29892007-01-19 07:51:42 +0000198}
199
Evan Chengd85ac4d2007-01-27 02:29:45 +0000200let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
Evan Chenga8e29892007-01-19 07:51:42 +0000201 def tB : TI<(ops brtarget:$dst), "b $dst", [(br bb:$dst)]>;
202
Evan Cheng225dfe92007-01-30 01:13:37 +0000203 // Far jump
204 def tBfar : TIx2<(ops brtarget:$dst), "bl $dst\t@ far jump", []>;
205
Evan Chengd85ac4d2007-01-27 02:29:45 +0000206 def tBR_JTr : TJTI<(ops GPR:$dst, jtblock_operand:$jt, i32imm:$id),
207 "cpy pc, $dst \n\t.align\t2\n$jt",
208 [(ARMbrjt GPR:$dst, tjumptable:$jt, imm:$id)]>;
209}
210
Evan Chenga8e29892007-01-19 07:51:42 +0000211let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
212 def tBcc : TI<(ops brtarget:$dst, CCOp:$cc), "b$cc $dst",
213 [(ARMbrcond bb:$dst, imm:$cc)]>;
214
215//===----------------------------------------------------------------------===//
216// Load Store Instructions.
217//
218
219let isLoad = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000220def tLDR : TI4<(ops GPR:$dst, t_addrmode_s4:$addr),
221 "ldr $dst, $addr",
222 [(set GPR:$dst, (load t_addrmode_s4:$addr))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000223
Evan Chengc38f2bc2007-01-23 22:59:13 +0000224def tLDRB : TI1<(ops GPR:$dst, t_addrmode_s1:$addr),
225 "ldrb $dst, $addr",
226 [(set GPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
227
228def tLDRH : TI2<(ops GPR:$dst, t_addrmode_s2:$addr),
229 "ldrh $dst, $addr",
230 [(set GPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
231
232def tLDRSB : TI1<(ops GPR:$dst, t_addrmode_rr:$addr),
233 "ldrsb $dst, $addr",
234 [(set GPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
235
236def tLDRSH : TI2<(ops GPR:$dst, t_addrmode_rr:$addr),
237 "ldrsh $dst, $addr",
238 [(set GPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
239
Evan Chenga8e29892007-01-19 07:51:42 +0000240def tLDRspi : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
241 "ldr $dst, $addr",
242 [(set GPR:$dst, (load t_addrmode_sp:$addr))]>;
Evan Cheng012f2d92007-01-24 08:53:17 +0000243
Evan Cheng8e59ea92007-02-07 00:06:56 +0000244// Special instruction for restore. It cannot clobber condition register
245// when it's expanded by eliminateCallFramePseudoInstr().
246def tRestore : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
247 "ldr $dst, $addr", []>;
248
Evan Cheng012f2d92007-01-24 08:53:17 +0000249// Load tconstpool
250def tLDRpci : TIs<(ops GPR:$dst, i32imm:$addr),
251 "ldr $dst, $addr",
252 [(set GPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Evan Chengfa775d02007-03-19 07:20:03 +0000253
254// Special LDR for loads from non-pc-relative constpools.
255let isReMaterializable = 1 in
256def tLDRcp : TIs<(ops GPR:$dst, i32imm:$addr),
257 "ldr $dst, $addr", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000258} // isLoad
259
260let isStore = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000261def tSTR : TI4<(ops GPR:$src, t_addrmode_s4:$addr),
262 "str $src, $addr",
263 [(store GPR:$src, t_addrmode_s4:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000264
Evan Chengc38f2bc2007-01-23 22:59:13 +0000265def tSTRB : TI1<(ops GPR:$src, t_addrmode_s1:$addr),
266 "strb $src, $addr",
267 [(truncstorei8 GPR:$src, t_addrmode_s1:$addr)]>;
268
269def tSTRH : TI2<(ops GPR:$src, t_addrmode_s2:$addr),
270 "strh $src, $addr",
271 [(truncstorei16 GPR:$src, t_addrmode_s2:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000272
273def tSTRspi : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
274 "str $src, $addr",
275 [(store GPR:$src, t_addrmode_sp:$addr)]>;
Evan Cheng8e59ea92007-02-07 00:06:56 +0000276
277// Special instruction for spill. It cannot clobber condition register
278// when it's expanded by eliminateCallFramePseudoInstr().
279def tSpill : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
280 "str $src, $addr", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000281}
282
283//===----------------------------------------------------------------------===//
284// Load / store multiple Instructions.
285//
286
287// TODO: A7-44: LDMIA - load multiple
288
289let isLoad = 1 in
290def tPOP : TI<(ops reglist:$dst1, variable_ops),
291 "pop $dst1", []>;
292
293let isStore = 1 in
294def tPUSH : TI<(ops reglist:$src1, variable_ops),
295 "push $src1", []>;
296
297//===----------------------------------------------------------------------===//
298// Arithmetic Instructions.
299//
300
Evan Cheng53d7dba2007-01-27 00:07:15 +0000301// Add with carry
302def tADC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
303 "adc $dst, $rhs",
304 [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
305
306def tADDS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
Evan Cheng3471b602007-01-31 20:12:31 +0000307 "add $dst, $lhs, $rhs",
Evan Cheng53d7dba2007-01-27 00:07:15 +0000308 [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
309
310
Evan Chenga8e29892007-01-19 07:51:42 +0000311def tADDi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
312 "add $dst, $lhs, $rhs",
313 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
314
315def tADDi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
316 "add $dst, $rhs",
317 [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
318
319def tADDrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
320 "add $dst, $lhs, $rhs",
321 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
322
323def tADDhirr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
324 "add $dst, $rhs", []>;
325
326def tADDrPCi : TI<(ops GPR:$dst, i32imm:$rhs),
327 "add $dst, pc, $rhs * 4", []>;
328def tADDrSPi : TI<(ops GPR:$dst, GPR:$sp, i32imm:$rhs),
329 "add $dst, $sp, $rhs * 4", []>;
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000330def tADDspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
331 "add $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000332
Evan Chenga8e29892007-01-19 07:51:42 +0000333def tAND : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
334 "and $dst, $rhs",
335 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
336
337def tASRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
338 "asr $dst, $lhs, $rhs",
339 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
340
341def tASRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
342 "asr $dst, $rhs",
343 [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
344
345def tBIC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
346 "bic $dst, $rhs",
347 [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
348
349
350def tCMN : TI<(ops GPR:$lhs, GPR:$rhs),
351 "cmn $lhs, $rhs",
352 [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
353
354def tCMPi8 : TI<(ops GPR:$lhs, i32imm:$rhs),
355 "cmp $lhs, $rhs",
356 [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
357
358def tCMPr : TI<(ops GPR:$lhs, GPR:$rhs),
359 "cmp $lhs, $rhs",
360 [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
361
362// TODO: A7-37: CMP(3) - cmp hi regs
363
364def tEOR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
365 "eor $dst, $rhs",
366 [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
367
368def tLSLri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
369 "lsl $dst, $lhs, $rhs",
370 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
371
372def tLSLrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
373 "lsl $dst, $rhs",
374 [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
375
376def tLSRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
377 "lsr $dst, $lhs, $rhs",
378 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
379
380def tLSRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
381 "lsr $dst, $rhs",
382 [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
383
Evan Chenga2515702007-03-19 07:09:02 +0000384let isReMaterializable = 1 in
Evan Cheng9f6636f2007-03-19 07:48:02 +0000385def tMOVi8 : TI<(ops GPR:$dst, i32imm:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000386 "mov $dst, $src",
387 [(set GPR:$dst, imm0_255:$src)]>;
388
389// TODO: A7-73: MOV(2) - mov setting flag.
390
391
392// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
393// which is MOV(3). This also supports high registers.
Evan Cheng9f6636f2007-03-19 07:48:02 +0000394def tMOVr : TI<(ops GPR:$dst, GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000395 "cpy $dst, $src", []>;
396
397def tMUL : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
398 "mul $dst, $rhs",
399 [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
400
401def tMVN : TI<(ops GPR:$dst, GPR:$src),
402 "mvn $dst, $src",
403 [(set GPR:$dst, (not GPR:$src))]>;
404
405def tNEG : TI<(ops GPR:$dst, GPR:$src),
406 "neg $dst, $src",
407 [(set GPR:$dst, (ineg GPR:$src))]>;
408
409def tORR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
410 "orr $dst, $rhs",
411 [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
412
413
414def tREV : TI<(ops GPR:$dst, GPR:$src),
415 "rev $dst, $src",
416 [(set GPR:$dst, (bswap GPR:$src))]>,
417 Requires<[IsThumb, HasV6]>;
418
419def tREV16 : TI<(ops GPR:$dst, GPR:$src),
420 "rev16 $dst, $src",
421 [(set GPR:$dst,
422 (or (and (srl GPR:$src, 8), 0xFF),
423 (or (and (shl GPR:$src, 8), 0xFF00),
424 (or (and (srl GPR:$src, 8), 0xFF0000),
425 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
426 Requires<[IsThumb, HasV6]>;
427
428def tREVSH : TI<(ops GPR:$dst, GPR:$src),
429 "revsh $dst, $src",
430 [(set GPR:$dst,
431 (sext_inreg
432 (or (srl (and GPR:$src, 0xFFFF), 8),
433 (shl GPR:$src, 8)), i16))]>,
434 Requires<[IsThumb, HasV6]>;
435
436def tROR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
437 "ror $dst, $rhs",
438 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
439
Evan Cheng53d7dba2007-01-27 00:07:15 +0000440
441// Subtract with carry
Evan Chenga8e29892007-01-19 07:51:42 +0000442def tSBC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
443 "sbc $dst, $rhs",
444 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
445
Evan Cheng53d7dba2007-01-27 00:07:15 +0000446def tSUBS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
Evan Cheng3471b602007-01-31 20:12:31 +0000447 "sub $dst, $lhs, $rhs",
Evan Cheng53d7dba2007-01-27 00:07:15 +0000448 [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
449
450
Evan Chenga8e29892007-01-19 07:51:42 +0000451// TODO: A7-96: STMIA - store multiple.
452
453def tSUBi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
454 "sub $dst, $lhs, $rhs",
455 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
456
457def tSUBi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
458 "sub $dst, $rhs",
459 [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
460
461def tSUBrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
462 "sub $dst, $lhs, $rhs",
463 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
464
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000465def tSUBspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
466 "sub $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000467
468def tSXTB : TI<(ops GPR:$dst, GPR:$src),
469 "sxtb $dst, $src",
470 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
471 Requires<[IsThumb, HasV6]>;
472def tSXTH : TI<(ops GPR:$dst, GPR:$src),
473 "sxth $dst, $src",
474 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
475 Requires<[IsThumb, HasV6]>;
476
477// TODO: A7-122: TST - test.
478
479def tUXTB : TI<(ops GPR:$dst, GPR:$src),
480 "uxtb $dst, $src",
481 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
482 Requires<[IsThumb, HasV6]>;
483def tUXTH : TI<(ops GPR:$dst, GPR:$src),
484 "uxth $dst, $src",
485 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>,
486 Requires<[IsThumb, HasV6]>;
487
488
489// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
490// Expanded by the scheduler into a branch sequence.
491let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
492 def tMOVCCr :
493 PseudoInst<(ops GPR:$dst, GPR:$false, GPR:$true, CCOp:$cc),
494 "@ tMOVCCr $cc",
495 [(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))]>;
496
497// tLEApcrel - Load a pc-relative address into a register without offending the
498// assembler.
Evan Chengc60e76d2007-01-30 20:37:08 +0000499def tLEApcrel : TIx2<(ops GPR:$dst, i32imm:$label),
Evan Chenga8e29892007-01-19 07:51:42 +0000500 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
Evan Chenge0c2b6b2007-02-01 03:04:49 +0000501 "${:private}PCRELL${:uid}+6))\n"),
502 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
503 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
Evan Chenga8e29892007-01-19 07:51:42 +0000504 []>;
505
Evan Chengc60e76d2007-01-30 20:37:08 +0000506def tLEApcrelJT : TIx2<(ops GPR:$dst, i32imm:$label, i32imm:$id),
Evan Chengd85ac4d2007-01-27 02:29:45 +0000507 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
508 "${:private}PCRELL${:uid}+4))\n"),
Evan Chenge0c2b6b2007-02-01 03:04:49 +0000509 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
510 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
511 []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +0000512
Evan Chenga8e29892007-01-19 07:51:42 +0000513//===----------------------------------------------------------------------===//
514// Non-Instruction Patterns
515//
516
517// ConstantPool, GlobalAddress
518def : ThumbPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
519def : ThumbPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000520
Evan Chengd85ac4d2007-01-27 02:29:45 +0000521// JumpTable
522def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
523 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
524
Evan Chenga8e29892007-01-19 07:51:42 +0000525// Direct calls
526def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
527def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
528
529// Indirect calls to ARM routines
530def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
531
532// zextload i1 -> zextload i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000533def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
534 (tLDRB t_addrmode_s1:$addr)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000535
Evan Chengb60c02e2007-01-26 19:13:16 +0000536// extload -> zextload
537def : ThumbPat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
538def : ThumbPat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
539def : ThumbPat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
540
Evan Chenga8e29892007-01-19 07:51:42 +0000541// truncstore i1 -> truncstore i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000542def : ThumbPat<(truncstorei1 GPR:$src, t_addrmode_s1:$dst),
543 (tSTRB GPR:$src, t_addrmode_s1:$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000544
545// Large immediate handling.
546
547// Two piece imms.
548def : ThumbPat<(i32 thumb_immshifted:$src),
Evan Cheng9f6636f2007-03-19 07:48:02 +0000549 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
Evan Chenga8e29892007-01-19 07:51:42 +0000550 (thumb_immshifted_shamt imm:$src))>;
551
552def : ThumbPat<(i32 imm0_255_comp:$src),
Evan Cheng9f6636f2007-03-19 07:48:02 +0000553 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;