blob: c494be470569e37402009f541ba43dab8b033d30 [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";
127 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
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";
136 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
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";
145 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
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 Chengd85ac4d2007-01-27 02:29:45 +0000198 def tBR_JTr : TJTI<(ops GPR:$dst, jtblock_operand:$jt, i32imm:$id),
199 "cpy pc, $dst \n\t.align\t2\n$jt",
200 [(ARMbrjt GPR:$dst, tjumptable:$jt, imm:$id)]>;
201}
202
Evan Chenga8e29892007-01-19 07:51:42 +0000203let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
204 def tBcc : TI<(ops brtarget:$dst, CCOp:$cc), "b$cc $dst",
205 [(ARMbrcond bb:$dst, imm:$cc)]>;
206
207//===----------------------------------------------------------------------===//
208// Load Store Instructions.
209//
210
211let isLoad = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000212def tLDR : TI4<(ops GPR:$dst, t_addrmode_s4:$addr),
213 "ldr $dst, $addr",
214 [(set GPR:$dst, (load t_addrmode_s4:$addr))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000215
Evan Chengc38f2bc2007-01-23 22:59:13 +0000216def tLDRB : TI1<(ops GPR:$dst, t_addrmode_s1:$addr),
217 "ldrb $dst, $addr",
218 [(set GPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
219
220def tLDRH : TI2<(ops GPR:$dst, t_addrmode_s2:$addr),
221 "ldrh $dst, $addr",
222 [(set GPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
223
224def tLDRSB : TI1<(ops GPR:$dst, t_addrmode_rr:$addr),
225 "ldrsb $dst, $addr",
226 [(set GPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
227
228def tLDRSH : TI2<(ops GPR:$dst, t_addrmode_rr:$addr),
229 "ldrsh $dst, $addr",
230 [(set GPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
231
Evan Chenga8e29892007-01-19 07:51:42 +0000232def tLDRspi : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
233 "ldr $dst, $addr",
234 [(set GPR:$dst, (load t_addrmode_sp:$addr))]>;
Evan Cheng012f2d92007-01-24 08:53:17 +0000235
236// Load tconstpool
237def tLDRpci : TIs<(ops GPR:$dst, i32imm:$addr),
238 "ldr $dst, $addr",
239 [(set GPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000240} // isLoad
241
242let isStore = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000243def tSTR : TI4<(ops GPR:$src, t_addrmode_s4:$addr),
244 "str $src, $addr",
245 [(store GPR:$src, t_addrmode_s4:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000246
Evan Chengc38f2bc2007-01-23 22:59:13 +0000247def tSTRB : TI1<(ops GPR:$src, t_addrmode_s1:$addr),
248 "strb $src, $addr",
249 [(truncstorei8 GPR:$src, t_addrmode_s1:$addr)]>;
250
251def tSTRH : TI2<(ops GPR:$src, t_addrmode_s2:$addr),
252 "strh $src, $addr",
253 [(truncstorei16 GPR:$src, t_addrmode_s2:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000254
255def tSTRspi : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
256 "str $src, $addr",
257 [(store GPR:$src, t_addrmode_sp:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000258}
259
260//===----------------------------------------------------------------------===//
261// Load / store multiple Instructions.
262//
263
264// TODO: A7-44: LDMIA - load multiple
265
266let isLoad = 1 in
267def tPOP : TI<(ops reglist:$dst1, variable_ops),
268 "pop $dst1", []>;
269
270let isStore = 1 in
271def tPUSH : TI<(ops reglist:$src1, variable_ops),
272 "push $src1", []>;
273
274//===----------------------------------------------------------------------===//
275// Arithmetic Instructions.
276//
277
Evan Cheng53d7dba2007-01-27 00:07:15 +0000278// Add with carry
279def tADC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
280 "adc $dst, $rhs",
281 [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
282
283def tADDS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
284 "adds $dst, $lhs, $rhs",
285 [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
286
287
Evan Chenga8e29892007-01-19 07:51:42 +0000288def tADDi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
289 "add $dst, $lhs, $rhs",
290 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
291
292def tADDi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
293 "add $dst, $rhs",
294 [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
295
296def tADDrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
297 "add $dst, $lhs, $rhs",
298 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
299
300def tADDhirr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
301 "add $dst, $rhs", []>;
302
303def tADDrPCi : TI<(ops GPR:$dst, i32imm:$rhs),
304 "add $dst, pc, $rhs * 4", []>;
305def tADDrSPi : TI<(ops GPR:$dst, GPR:$sp, i32imm:$rhs),
306 "add $dst, $sp, $rhs * 4", []>;
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000307def tADDspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
308 "add $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000309
Evan Chenga8e29892007-01-19 07:51:42 +0000310def tAND : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
311 "and $dst, $rhs",
312 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
313
314def tASRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
315 "asr $dst, $lhs, $rhs",
316 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
317
318def tASRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
319 "asr $dst, $rhs",
320 [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
321
322def tBIC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
323 "bic $dst, $rhs",
324 [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
325
326
327def tCMN : TI<(ops GPR:$lhs, GPR:$rhs),
328 "cmn $lhs, $rhs",
329 [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
330
331def tCMPi8 : TI<(ops GPR:$lhs, i32imm:$rhs),
332 "cmp $lhs, $rhs",
333 [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
334
335def tCMPr : TI<(ops GPR:$lhs, GPR:$rhs),
336 "cmp $lhs, $rhs",
337 [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
338
339// TODO: A7-37: CMP(3) - cmp hi regs
340
341def tEOR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
342 "eor $dst, $rhs",
343 [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
344
345def tLSLri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
346 "lsl $dst, $lhs, $rhs",
347 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
348
349def tLSLrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
350 "lsl $dst, $rhs",
351 [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
352
353def tLSRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
354 "lsr $dst, $lhs, $rhs",
355 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
356
357def tLSRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
358 "lsr $dst, $rhs",
359 [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
360
361def tMOVri8 : TI<(ops GPR:$dst, i32imm:$src),
362 "mov $dst, $src",
363 [(set GPR:$dst, imm0_255:$src)]>;
364
365// TODO: A7-73: MOV(2) - mov setting flag.
366
367
368// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
369// which is MOV(3). This also supports high registers.
370def tMOVrr : TI<(ops GPR:$dst, GPR:$src),
371 "cpy $dst, $src", []>;
372
373def tMUL : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
374 "mul $dst, $rhs",
375 [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
376
377def tMVN : TI<(ops GPR:$dst, GPR:$src),
378 "mvn $dst, $src",
379 [(set GPR:$dst, (not GPR:$src))]>;
380
381def tNEG : TI<(ops GPR:$dst, GPR:$src),
382 "neg $dst, $src",
383 [(set GPR:$dst, (ineg GPR:$src))]>;
384
385def tORR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
386 "orr $dst, $rhs",
387 [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
388
389
390def tREV : TI<(ops GPR:$dst, GPR:$src),
391 "rev $dst, $src",
392 [(set GPR:$dst, (bswap GPR:$src))]>,
393 Requires<[IsThumb, HasV6]>;
394
395def tREV16 : TI<(ops GPR:$dst, GPR:$src),
396 "rev16 $dst, $src",
397 [(set GPR:$dst,
398 (or (and (srl GPR:$src, 8), 0xFF),
399 (or (and (shl GPR:$src, 8), 0xFF00),
400 (or (and (srl GPR:$src, 8), 0xFF0000),
401 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
402 Requires<[IsThumb, HasV6]>;
403
404def tREVSH : TI<(ops GPR:$dst, GPR:$src),
405 "revsh $dst, $src",
406 [(set GPR:$dst,
407 (sext_inreg
408 (or (srl (and GPR:$src, 0xFFFF), 8),
409 (shl GPR:$src, 8)), i16))]>,
410 Requires<[IsThumb, HasV6]>;
411
412def tROR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
413 "ror $dst, $rhs",
414 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
415
Evan Cheng53d7dba2007-01-27 00:07:15 +0000416
417// Subtract with carry
Evan Chenga8e29892007-01-19 07:51:42 +0000418def tSBC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
419 "sbc $dst, $rhs",
420 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
421
Evan Cheng53d7dba2007-01-27 00:07:15 +0000422def tSUBS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
423 "subs $dst, $lhs, $rhs",
424 [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
425
426
Evan Chenga8e29892007-01-19 07:51:42 +0000427// TODO: A7-96: STMIA - store multiple.
428
429def tSUBi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
430 "sub $dst, $lhs, $rhs",
431 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
432
433def tSUBi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
434 "sub $dst, $rhs",
435 [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
436
437def tSUBrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
438 "sub $dst, $lhs, $rhs",
439 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
440
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000441def tSUBspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
442 "sub $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000443
444def tSXTB : TI<(ops GPR:$dst, GPR:$src),
445 "sxtb $dst, $src",
446 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
447 Requires<[IsThumb, HasV6]>;
448def tSXTH : TI<(ops GPR:$dst, GPR:$src),
449 "sxth $dst, $src",
450 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
451 Requires<[IsThumb, HasV6]>;
452
453// TODO: A7-122: TST - test.
454
455def tUXTB : TI<(ops GPR:$dst, GPR:$src),
456 "uxtb $dst, $src",
457 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
458 Requires<[IsThumb, HasV6]>;
459def tUXTH : TI<(ops GPR:$dst, GPR:$src),
460 "uxth $dst, $src",
461 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>,
462 Requires<[IsThumb, HasV6]>;
463
464
465// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
466// Expanded by the scheduler into a branch sequence.
467let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
468 def tMOVCCr :
469 PseudoInst<(ops GPR:$dst, GPR:$false, GPR:$true, CCOp:$cc),
470 "@ tMOVCCr $cc",
471 [(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))]>;
472
473// tLEApcrel - Load a pc-relative address into a register without offending the
474// assembler.
475def tLEApcrel : TI<(ops GPR:$dst, i32imm:$label),
476 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
477 "${:private}PCRELL${:uid}+4))\n"),
478 !strconcat("${:private}PCRELL${:uid}:\n\t",
479 "add $dst, pc, #PCRELV${:uid}")),
480 []>;
481
482def tLEApcrelCall : TI<(ops GPR:$dst, i32imm:$label),
483 !strconcat(!strconcat(".set PCRELV${:uid}, (${label:call}-(",
484 "${:private}PCRELL${:uid}+4))\n"),
485 !strconcat("${:private}PCRELL${:uid}:\n\t",
486 "add $dst, pc, #PCRELV${:uid}")),
487 []>;
488
Evan Chengd85ac4d2007-01-27 02:29:45 +0000489def tLEApcrelJT : TI<(ops GPR:$dst, i32imm:$label, i32imm:$id),
490 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
491 "${:private}PCRELL${:uid}+4))\n"),
492 !strconcat("${:private}PCRELL${:uid}:\n\t",
493 "add $dst, pc, #PCRELV${:uid}")),
494 []>;
495
Evan Chenga8e29892007-01-19 07:51:42 +0000496//===----------------------------------------------------------------------===//
497// Non-Instruction Patterns
498//
499
500// ConstantPool, GlobalAddress
501def : ThumbPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
502def : ThumbPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
503def : ThumbPat<(ARMWrapperCall tglobaladdr :$dst),
504 (tLEApcrelCall tglobaladdr :$dst)>;
505def : ThumbPat<(ARMWrapperCall texternalsym:$dst),
506 (tLEApcrelCall texternalsym:$dst)>;
507
Evan Chengd85ac4d2007-01-27 02:29:45 +0000508// JumpTable
509def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
510 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
511
Evan Chenga8e29892007-01-19 07:51:42 +0000512// Direct calls
513def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
514def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
515
516// Indirect calls to ARM routines
517def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
518
519// zextload i1 -> zextload i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000520def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
521 (tLDRB t_addrmode_s1:$addr)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000522
Evan Chengb60c02e2007-01-26 19:13:16 +0000523// extload -> zextload
524def : ThumbPat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
525def : ThumbPat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
526def : ThumbPat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
527
Evan Chenga8e29892007-01-19 07:51:42 +0000528// truncstore i1 -> truncstore i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000529def : ThumbPat<(truncstorei1 GPR:$src, t_addrmode_s1:$dst),
530 (tSTRB GPR:$src, t_addrmode_s1:$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000531
532// Large immediate handling.
533
534// Two piece imms.
535def : ThumbPat<(i32 thumb_immshifted:$src),
536 (tLSLri (tMOVri8 (thumb_immshifted_val imm:$src)),
537 (thumb_immshifted_shamt imm:$src))>;
538
539def : ThumbPat<(i32 imm0_255_comp:$src),
540 (tMVN (tMOVri8 (imm_comp_XFORM imm:$src)))>;