blob: f806754fd5a8ee1786e6c97e45e920218c452be3 [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),
161 "\n$cp:\n\tadd $dst, pc",
162 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
163
164//===----------------------------------------------------------------------===//
165// Control Flow Instructions.
166//
167
168let isReturn = 1, isTerminator = 1 in
169 def tBX_RET : TI<(ops), "bx lr", [(ARMretflag)]>;
170
171// FIXME: remove when we have a way to marking a MI with these properties.
172let isLoad = 1, isReturn = 1, isTerminator = 1 in
173def tPOP_RET : TI<(ops reglist:$dst1, variable_ops),
174 "pop $dst1", []>;
175
176let isCall = 1, noResults = 1,
177 Defs = [R0, R1, R2, R3, LR,
178 D0, D1, D2, D3, D4, D5, D6, D7] in {
179 def tBL : TIx2<(ops i32imm:$func, variable_ops),
180 "bl ${func:call}",
181 [(ARMtcall tglobaladdr:$func)]>;
182 // ARMv5T and above
183 def tBLXi : TIx2<(ops i32imm:$func, variable_ops),
184 "blx ${func:call}",
185 [(ARMcall tglobaladdr:$func)]>, Requires<[HasV5T]>;
186 def tBLXr : TI<(ops GPR:$dst, variable_ops),
187 "blx $dst",
188 [(ARMtcall GPR:$dst)]>, Requires<[HasV5T]>;
189 // ARMv4T
190 def tBX : TIx2<(ops GPR:$dst, variable_ops),
191 "cpy lr, pc\n\tbx $dst",
192 [(ARMcall_nolink GPR:$dst)]>;
193}
194
Evan Chengd85ac4d2007-01-27 02:29:45 +0000195let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
Evan Chenga8e29892007-01-19 07:51:42 +0000196 def tB : TI<(ops brtarget:$dst), "b $dst", [(br bb:$dst)]>;
197
Evan Cheng225dfe92007-01-30 01:13:37 +0000198 // Far jump
199 def tBfar : TIx2<(ops brtarget:$dst), "bl $dst\t@ far jump", []>;
200
Evan Chengd85ac4d2007-01-27 02:29:45 +0000201 def tBR_JTr : TJTI<(ops GPR:$dst, jtblock_operand:$jt, i32imm:$id),
202 "cpy pc, $dst \n\t.align\t2\n$jt",
203 [(ARMbrjt GPR:$dst, tjumptable:$jt, imm:$id)]>;
204}
205
Evan Chenga8e29892007-01-19 07:51:42 +0000206let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
207 def tBcc : TI<(ops brtarget:$dst, CCOp:$cc), "b$cc $dst",
208 [(ARMbrcond bb:$dst, imm:$cc)]>;
209
210//===----------------------------------------------------------------------===//
211// Load Store Instructions.
212//
213
214let isLoad = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000215def tLDR : TI4<(ops GPR:$dst, t_addrmode_s4:$addr),
216 "ldr $dst, $addr",
217 [(set GPR:$dst, (load t_addrmode_s4:$addr))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000218
Evan Chengc38f2bc2007-01-23 22:59:13 +0000219def tLDRB : TI1<(ops GPR:$dst, t_addrmode_s1:$addr),
220 "ldrb $dst, $addr",
221 [(set GPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
222
223def tLDRH : TI2<(ops GPR:$dst, t_addrmode_s2:$addr),
224 "ldrh $dst, $addr",
225 [(set GPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
226
227def tLDRSB : TI1<(ops GPR:$dst, t_addrmode_rr:$addr),
228 "ldrsb $dst, $addr",
229 [(set GPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
230
231def tLDRSH : TI2<(ops GPR:$dst, t_addrmode_rr:$addr),
232 "ldrsh $dst, $addr",
233 [(set GPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
234
Evan Chenga8e29892007-01-19 07:51:42 +0000235def tLDRspi : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
236 "ldr $dst, $addr",
237 [(set GPR:$dst, (load t_addrmode_sp:$addr))]>;
Evan Cheng012f2d92007-01-24 08:53:17 +0000238
239// Load tconstpool
240def tLDRpci : TIs<(ops GPR:$dst, i32imm:$addr),
241 "ldr $dst, $addr",
242 [(set GPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000243} // isLoad
244
245let isStore = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000246def tSTR : TI4<(ops GPR:$src, t_addrmode_s4:$addr),
247 "str $src, $addr",
248 [(store GPR:$src, t_addrmode_s4:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000249
Evan Chengc38f2bc2007-01-23 22:59:13 +0000250def tSTRB : TI1<(ops GPR:$src, t_addrmode_s1:$addr),
251 "strb $src, $addr",
252 [(truncstorei8 GPR:$src, t_addrmode_s1:$addr)]>;
253
254def tSTRH : TI2<(ops GPR:$src, t_addrmode_s2:$addr),
255 "strh $src, $addr",
256 [(truncstorei16 GPR:$src, t_addrmode_s2:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000257
258def tSTRspi : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
259 "str $src, $addr",
260 [(store GPR:$src, t_addrmode_sp:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000261}
262
263//===----------------------------------------------------------------------===//
264// Load / store multiple Instructions.
265//
266
267// TODO: A7-44: LDMIA - load multiple
268
269let isLoad = 1 in
270def tPOP : TI<(ops reglist:$dst1, variable_ops),
271 "pop $dst1", []>;
272
273let isStore = 1 in
274def tPUSH : TI<(ops reglist:$src1, variable_ops),
275 "push $src1", []>;
276
277//===----------------------------------------------------------------------===//
278// Arithmetic Instructions.
279//
280
Evan Cheng53d7dba2007-01-27 00:07:15 +0000281// Add with carry
282def tADC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
283 "adc $dst, $rhs",
284 [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
285
286def tADDS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
287 "adds $dst, $lhs, $rhs",
288 [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
289
290
Evan Chenga8e29892007-01-19 07:51:42 +0000291def tADDi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
292 "add $dst, $lhs, $rhs",
293 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
294
295def tADDi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
296 "add $dst, $rhs",
297 [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
298
299def tADDrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
300 "add $dst, $lhs, $rhs",
301 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
302
303def tADDhirr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
304 "add $dst, $rhs", []>;
305
306def tADDrPCi : TI<(ops GPR:$dst, i32imm:$rhs),
307 "add $dst, pc, $rhs * 4", []>;
308def tADDrSPi : TI<(ops GPR:$dst, GPR:$sp, i32imm:$rhs),
309 "add $dst, $sp, $rhs * 4", []>;
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000310def tADDspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
311 "add $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000312
Evan Chenga8e29892007-01-19 07:51:42 +0000313def tAND : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
314 "and $dst, $rhs",
315 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
316
317def tASRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
318 "asr $dst, $lhs, $rhs",
319 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
320
321def tASRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
322 "asr $dst, $rhs",
323 [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
324
325def tBIC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
326 "bic $dst, $rhs",
327 [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
328
329
330def tCMN : TI<(ops GPR:$lhs, GPR:$rhs),
331 "cmn $lhs, $rhs",
332 [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
333
334def tCMPi8 : TI<(ops GPR:$lhs, i32imm:$rhs),
335 "cmp $lhs, $rhs",
336 [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
337
338def tCMPr : TI<(ops GPR:$lhs, GPR:$rhs),
339 "cmp $lhs, $rhs",
340 [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
341
342// TODO: A7-37: CMP(3) - cmp hi regs
343
344def tEOR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
345 "eor $dst, $rhs",
346 [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
347
348def tLSLri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
349 "lsl $dst, $lhs, $rhs",
350 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
351
352def tLSLrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
353 "lsl $dst, $rhs",
354 [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
355
356def tLSRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
357 "lsr $dst, $lhs, $rhs",
358 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
359
360def tLSRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
361 "lsr $dst, $rhs",
362 [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
363
364def tMOVri8 : TI<(ops GPR:$dst, i32imm:$src),
365 "mov $dst, $src",
366 [(set GPR:$dst, imm0_255:$src)]>;
367
368// TODO: A7-73: MOV(2) - mov setting flag.
369
370
371// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
372// which is MOV(3). This also supports high registers.
373def tMOVrr : TI<(ops GPR:$dst, GPR:$src),
374 "cpy $dst, $src", []>;
375
376def tMUL : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
377 "mul $dst, $rhs",
378 [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
379
380def tMVN : TI<(ops GPR:$dst, GPR:$src),
381 "mvn $dst, $src",
382 [(set GPR:$dst, (not GPR:$src))]>;
383
384def tNEG : TI<(ops GPR:$dst, GPR:$src),
385 "neg $dst, $src",
386 [(set GPR:$dst, (ineg GPR:$src))]>;
387
388def tORR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
389 "orr $dst, $rhs",
390 [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
391
392
393def tREV : TI<(ops GPR:$dst, GPR:$src),
394 "rev $dst, $src",
395 [(set GPR:$dst, (bswap GPR:$src))]>,
396 Requires<[IsThumb, HasV6]>;
397
398def tREV16 : TI<(ops GPR:$dst, GPR:$src),
399 "rev16 $dst, $src",
400 [(set GPR:$dst,
401 (or (and (srl GPR:$src, 8), 0xFF),
402 (or (and (shl GPR:$src, 8), 0xFF00),
403 (or (and (srl GPR:$src, 8), 0xFF0000),
404 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
405 Requires<[IsThumb, HasV6]>;
406
407def tREVSH : TI<(ops GPR:$dst, GPR:$src),
408 "revsh $dst, $src",
409 [(set GPR:$dst,
410 (sext_inreg
411 (or (srl (and GPR:$src, 0xFFFF), 8),
412 (shl GPR:$src, 8)), i16))]>,
413 Requires<[IsThumb, HasV6]>;
414
415def tROR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
416 "ror $dst, $rhs",
417 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
418
Evan Cheng53d7dba2007-01-27 00:07:15 +0000419
420// Subtract with carry
Evan Chenga8e29892007-01-19 07:51:42 +0000421def tSBC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
422 "sbc $dst, $rhs",
423 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
424
Evan Cheng53d7dba2007-01-27 00:07:15 +0000425def tSUBS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
426 "subs $dst, $lhs, $rhs",
427 [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
428
429
Evan Chenga8e29892007-01-19 07:51:42 +0000430// TODO: A7-96: STMIA - store multiple.
431
432def tSUBi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
433 "sub $dst, $lhs, $rhs",
434 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
435
436def tSUBi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
437 "sub $dst, $rhs",
438 [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
439
440def tSUBrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
441 "sub $dst, $lhs, $rhs",
442 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
443
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000444def tSUBspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
445 "sub $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000446
447def tSXTB : TI<(ops GPR:$dst, GPR:$src),
448 "sxtb $dst, $src",
449 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
450 Requires<[IsThumb, HasV6]>;
451def tSXTH : TI<(ops GPR:$dst, GPR:$src),
452 "sxth $dst, $src",
453 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
454 Requires<[IsThumb, HasV6]>;
455
456// TODO: A7-122: TST - test.
457
458def tUXTB : TI<(ops GPR:$dst, GPR:$src),
459 "uxtb $dst, $src",
460 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
461 Requires<[IsThumb, HasV6]>;
462def tUXTH : TI<(ops GPR:$dst, GPR:$src),
463 "uxth $dst, $src",
464 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>,
465 Requires<[IsThumb, HasV6]>;
466
467
468// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
469// Expanded by the scheduler into a branch sequence.
470let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
471 def tMOVCCr :
472 PseudoInst<(ops GPR:$dst, GPR:$false, GPR:$true, CCOp:$cc),
473 "@ tMOVCCr $cc",
474 [(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))]>;
475
476// tLEApcrel - Load a pc-relative address into a register without offending the
477// assembler.
478def tLEApcrel : TI<(ops GPR:$dst, i32imm:$label),
479 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
480 "${:private}PCRELL${:uid}+4))\n"),
481 !strconcat("${:private}PCRELL${:uid}:\n\t",
482 "add $dst, pc, #PCRELV${:uid}")),
483 []>;
484
485def tLEApcrelCall : TI<(ops GPR:$dst, i32imm:$label),
486 !strconcat(!strconcat(".set PCRELV${:uid}, (${label:call}-(",
487 "${:private}PCRELL${:uid}+4))\n"),
488 !strconcat("${:private}PCRELL${:uid}:\n\t",
489 "add $dst, pc, #PCRELV${:uid}")),
490 []>;
491
Evan Chengd85ac4d2007-01-27 02:29:45 +0000492def tLEApcrelJT : TI<(ops GPR:$dst, i32imm:$label, i32imm:$id),
493 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
494 "${:private}PCRELL${:uid}+4))\n"),
495 !strconcat("${:private}PCRELL${:uid}:\n\t",
496 "add $dst, pc, #PCRELV${:uid}")),
497 []>;
498
Evan Chenga8e29892007-01-19 07:51:42 +0000499//===----------------------------------------------------------------------===//
500// Non-Instruction Patterns
501//
502
503// ConstantPool, GlobalAddress
504def : ThumbPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
505def : ThumbPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
506def : ThumbPat<(ARMWrapperCall tglobaladdr :$dst),
507 (tLEApcrelCall tglobaladdr :$dst)>;
508def : ThumbPat<(ARMWrapperCall texternalsym:$dst),
509 (tLEApcrelCall texternalsym:$dst)>;
510
Evan Chengd85ac4d2007-01-27 02:29:45 +0000511// JumpTable
512def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
513 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
514
Evan Chenga8e29892007-01-19 07:51:42 +0000515// Direct calls
516def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
517def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
518
519// Indirect calls to ARM routines
520def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
521
522// zextload i1 -> zextload i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000523def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
524 (tLDRB t_addrmode_s1:$addr)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000525
Evan Chengb60c02e2007-01-26 19:13:16 +0000526// extload -> zextload
527def : ThumbPat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
528def : ThumbPat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
529def : ThumbPat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
530
Evan Chenga8e29892007-01-19 07:51:42 +0000531// truncstore i1 -> truncstore i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000532def : ThumbPat<(truncstorei1 GPR:$src, t_addrmode_s1:$dst),
533 (tSTRB GPR:$src, t_addrmode_s1:$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000534
535// Large immediate handling.
536
537// Two piece imms.
538def : ThumbPat<(i32 thumb_immshifted:$src),
539 (tLSLri (tMOVri8 (thumb_immshifted_val imm:$src)),
540 (thumb_immshifted_shamt imm:$src))>;
541
542def : ThumbPat<(i32 imm0_255_comp:$src),
543 (tMVN (tMOVri8 (imm_comp_XFORM imm:$src)))>;