blob: 52b8939e24ccc6991807842ff60a4f5dfa335d15 [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
59def imm_neg_XFORM : SDNodeXForm<imm, [{
60 return CurDAG->getTargetConstant(-(int)N->getValue(), MVT::i32);
61}]>;
62def imm_comp_XFORM : SDNodeXForm<imm, [{
63 return CurDAG->getTargetConstant(~((uint32_t)N->getValue()), MVT::i32);
64}]>;
65
66
67/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
68def imm0_7 : PatLeaf<(i32 imm), [{
69 return (uint32_t)N->getValue() < 8;
70}]>;
71def imm0_7_neg : PatLeaf<(i32 imm), [{
72 return (uint32_t)-N->getValue() < 8;
73}], imm_neg_XFORM>;
74
75def imm0_255 : PatLeaf<(i32 imm), [{
76 return (uint32_t)N->getValue() < 256;
77}]>;
78def imm0_255_comp : PatLeaf<(i32 imm), [{
79 return ~((uint32_t)N->getValue()) < 256;
80}]>;
81
82def imm8_255 : PatLeaf<(i32 imm), [{
83 return (uint32_t)N->getValue() >= 8 && (uint32_t)N->getValue() < 256;
84}]>;
85def imm8_255_neg : PatLeaf<(i32 imm), [{
86 unsigned Val = -N->getValue();
87 return Val >= 8 && Val < 256;
88}], imm_neg_XFORM>;
89
90// Break imm's up into two pieces: an immediate + a left shift.
91// This uses thumb_immshifted to match and thumb_immshifted_val and
92// thumb_immshifted_shamt to get the val/shift pieces.
93def thumb_immshifted : PatLeaf<(imm), [{
94 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getValue());
95}]>;
96
97def thumb_immshifted_val : SDNodeXForm<imm, [{
98 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getValue());
99 return CurDAG->getTargetConstant(V, MVT::i32);
100}]>;
101
102def thumb_immshifted_shamt : SDNodeXForm<imm, [{
103 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getValue());
104 return CurDAG->getTargetConstant(V, MVT::i32);
105}]>;
106
107// Define Thumb specific addressing modes.
108
109// t_addrmode_rr := reg + reg
110//
111def t_addrmode_rr : Operand<i32>,
112 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
113 let PrintMethod = "printThumbAddrModeRROperand";
114 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg);
115}
116
Evan Chengc38f2bc2007-01-23 22:59:13 +0000117// t_addrmode_s4 := reg + reg
118// reg + imm5 * 4
Evan Chenga8e29892007-01-19 07:51:42 +0000119//
Evan Chengc38f2bc2007-01-23 22:59:13 +0000120def t_addrmode_s4 : Operand<i32>,
121 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
122 let PrintMethod = "printThumbAddrModeS4Operand";
123 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
Evan Chenga8e29892007-01-19 07:51:42 +0000124}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000125
126// t_addrmode_s2 := reg + reg
127// reg + imm5 * 2
128//
129def t_addrmode_s2 : Operand<i32>,
130 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
131 let PrintMethod = "printThumbAddrModeS2Operand";
132 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
Evan Chenga8e29892007-01-19 07:51:42 +0000133}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000134
135// t_addrmode_s1 := reg + reg
136// reg + imm5
137//
138def t_addrmode_s1 : Operand<i32>,
139 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
140 let PrintMethod = "printThumbAddrModeS1Operand";
141 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg, i32imm:$offsimm);
Evan Chenga8e29892007-01-19 07:51:42 +0000142}
143
144// t_addrmode_sp := sp + imm8 * 4
145//
146def t_addrmode_sp : Operand<i32>,
147 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
148 let PrintMethod = "printThumbAddrModeSPOperand";
149 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
150}
151
152//===----------------------------------------------------------------------===//
153// Miscellaneous Instructions.
154//
155
156def tPICADD : TIt<(ops GPR:$dst, GPR:$lhs, pclabel:$cp),
157 "\n$cp:\n\tadd $dst, pc",
158 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
159
160//===----------------------------------------------------------------------===//
161// Control Flow Instructions.
162//
163
164let isReturn = 1, isTerminator = 1 in
165 def tBX_RET : TI<(ops), "bx lr", [(ARMretflag)]>;
166
167// FIXME: remove when we have a way to marking a MI with these properties.
168let isLoad = 1, isReturn = 1, isTerminator = 1 in
169def tPOP_RET : TI<(ops reglist:$dst1, variable_ops),
170 "pop $dst1", []>;
171
172let isCall = 1, noResults = 1,
173 Defs = [R0, R1, R2, R3, LR,
174 D0, D1, D2, D3, D4, D5, D6, D7] in {
175 def tBL : TIx2<(ops i32imm:$func, variable_ops),
176 "bl ${func:call}",
177 [(ARMtcall tglobaladdr:$func)]>;
178 // ARMv5T and above
179 def tBLXi : TIx2<(ops i32imm:$func, variable_ops),
180 "blx ${func:call}",
181 [(ARMcall tglobaladdr:$func)]>, Requires<[HasV5T]>;
182 def tBLXr : TI<(ops GPR:$dst, variable_ops),
183 "blx $dst",
184 [(ARMtcall GPR:$dst)]>, Requires<[HasV5T]>;
185 // ARMv4T
186 def tBX : TIx2<(ops GPR:$dst, variable_ops),
187 "cpy lr, pc\n\tbx $dst",
188 [(ARMcall_nolink GPR:$dst)]>;
189}
190
191let isBranch = 1, isTerminator = 1, isBarrier = 1 in
192 def tB : TI<(ops brtarget:$dst), "b $dst", [(br bb:$dst)]>;
193
194let isBranch = 1, isTerminator = 1, noResults = 1, isBarrier = 1 in
195 def tBcc : TI<(ops brtarget:$dst, CCOp:$cc), "b$cc $dst",
196 [(ARMbrcond bb:$dst, imm:$cc)]>;
197
198//===----------------------------------------------------------------------===//
199// Load Store Instructions.
200//
201
202let isLoad = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000203def tLDR : TI4<(ops GPR:$dst, t_addrmode_s4:$addr),
204 "ldr $dst, $addr",
205 [(set GPR:$dst, (load t_addrmode_s4:$addr))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000206
Evan Chengc38f2bc2007-01-23 22:59:13 +0000207def tLDRB : TI1<(ops GPR:$dst, t_addrmode_s1:$addr),
208 "ldrb $dst, $addr",
209 [(set GPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
210
211def tLDRH : TI2<(ops GPR:$dst, t_addrmode_s2:$addr),
212 "ldrh $dst, $addr",
213 [(set GPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
214
215def tLDRSB : TI1<(ops GPR:$dst, t_addrmode_rr:$addr),
216 "ldrsb $dst, $addr",
217 [(set GPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
218
219def tLDRSH : TI2<(ops GPR:$dst, t_addrmode_rr:$addr),
220 "ldrsh $dst, $addr",
221 [(set GPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
222
Evan Chenga8e29892007-01-19 07:51:42 +0000223def tLDRspi : TIs<(ops GPR:$dst, t_addrmode_sp:$addr),
224 "ldr $dst, $addr",
225 [(set GPR:$dst, (load t_addrmode_sp:$addr))]>;
Evan Cheng012f2d92007-01-24 08:53:17 +0000226
227// Load tconstpool
228def tLDRpci : TIs<(ops GPR:$dst, i32imm:$addr),
229 "ldr $dst, $addr",
230 [(set GPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000231} // isLoad
232
233let isStore = 1 in {
Evan Chengc38f2bc2007-01-23 22:59:13 +0000234def tSTR : TI4<(ops GPR:$src, t_addrmode_s4:$addr),
235 "str $src, $addr",
236 [(store GPR:$src, t_addrmode_s4:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000237
Evan Chengc38f2bc2007-01-23 22:59:13 +0000238def tSTRB : TI1<(ops GPR:$src, t_addrmode_s1:$addr),
239 "strb $src, $addr",
240 [(truncstorei8 GPR:$src, t_addrmode_s1:$addr)]>;
241
242def tSTRH : TI2<(ops GPR:$src, t_addrmode_s2:$addr),
243 "strh $src, $addr",
244 [(truncstorei16 GPR:$src, t_addrmode_s2:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000245
246def tSTRspi : TIs<(ops GPR:$src, t_addrmode_sp:$addr),
247 "str $src, $addr",
248 [(store GPR:$src, t_addrmode_sp:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000249}
250
251//===----------------------------------------------------------------------===//
252// Load / store multiple Instructions.
253//
254
255// TODO: A7-44: LDMIA - load multiple
256
257let isLoad = 1 in
258def tPOP : TI<(ops reglist:$dst1, variable_ops),
259 "pop $dst1", []>;
260
261let isStore = 1 in
262def tPUSH : TI<(ops reglist:$src1, variable_ops),
263 "push $src1", []>;
264
265//===----------------------------------------------------------------------===//
266// Arithmetic Instructions.
267//
268
Evan Cheng53d7dba2007-01-27 00:07:15 +0000269// Add with carry
270def tADC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
271 "adc $dst, $rhs",
272 [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
273
274def tADDS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
275 "adds $dst, $lhs, $rhs",
276 [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
277
278
Evan Chenga8e29892007-01-19 07:51:42 +0000279def tADDi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
280 "add $dst, $lhs, $rhs",
281 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
282
283def tADDi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
284 "add $dst, $rhs",
285 [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
286
287def tADDrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
288 "add $dst, $lhs, $rhs",
289 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
290
291def tADDhirr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
292 "add $dst, $rhs", []>;
293
294def tADDrPCi : TI<(ops GPR:$dst, i32imm:$rhs),
295 "add $dst, pc, $rhs * 4", []>;
296def tADDrSPi : TI<(ops GPR:$dst, GPR:$sp, i32imm:$rhs),
297 "add $dst, $sp, $rhs * 4", []>;
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000298def tADDspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
299 "add $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000300
Evan Chenga8e29892007-01-19 07:51:42 +0000301def tAND : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
302 "and $dst, $rhs",
303 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
304
305def tASRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
306 "asr $dst, $lhs, $rhs",
307 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
308
309def tASRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
310 "asr $dst, $rhs",
311 [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
312
313def tBIC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
314 "bic $dst, $rhs",
315 [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
316
317
318def tCMN : TI<(ops GPR:$lhs, GPR:$rhs),
319 "cmn $lhs, $rhs",
320 [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
321
322def tCMPi8 : TI<(ops GPR:$lhs, i32imm:$rhs),
323 "cmp $lhs, $rhs",
324 [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
325
326def tCMPr : TI<(ops GPR:$lhs, GPR:$rhs),
327 "cmp $lhs, $rhs",
328 [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
329
330// TODO: A7-37: CMP(3) - cmp hi regs
331
332def tEOR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
333 "eor $dst, $rhs",
334 [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
335
336def tLSLri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
337 "lsl $dst, $lhs, $rhs",
338 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
339
340def tLSLrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
341 "lsl $dst, $rhs",
342 [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
343
344def tLSRri : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
345 "lsr $dst, $lhs, $rhs",
346 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
347
348def tLSRrr : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
349 "lsr $dst, $rhs",
350 [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
351
352def tMOVri8 : TI<(ops GPR:$dst, i32imm:$src),
353 "mov $dst, $src",
354 [(set GPR:$dst, imm0_255:$src)]>;
355
356// TODO: A7-73: MOV(2) - mov setting flag.
357
358
359// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
360// which is MOV(3). This also supports high registers.
361def tMOVrr : TI<(ops GPR:$dst, GPR:$src),
362 "cpy $dst, $src", []>;
363
364def tMUL : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
365 "mul $dst, $rhs",
366 [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
367
368def tMVN : TI<(ops GPR:$dst, GPR:$src),
369 "mvn $dst, $src",
370 [(set GPR:$dst, (not GPR:$src))]>;
371
372def tNEG : TI<(ops GPR:$dst, GPR:$src),
373 "neg $dst, $src",
374 [(set GPR:$dst, (ineg GPR:$src))]>;
375
376def tORR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
377 "orr $dst, $rhs",
378 [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
379
380
381def tREV : TI<(ops GPR:$dst, GPR:$src),
382 "rev $dst, $src",
383 [(set GPR:$dst, (bswap GPR:$src))]>,
384 Requires<[IsThumb, HasV6]>;
385
386def tREV16 : TI<(ops GPR:$dst, GPR:$src),
387 "rev16 $dst, $src",
388 [(set GPR:$dst,
389 (or (and (srl GPR:$src, 8), 0xFF),
390 (or (and (shl GPR:$src, 8), 0xFF00),
391 (or (and (srl GPR:$src, 8), 0xFF0000),
392 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
393 Requires<[IsThumb, HasV6]>;
394
395def tREVSH : TI<(ops GPR:$dst, GPR:$src),
396 "revsh $dst, $src",
397 [(set GPR:$dst,
398 (sext_inreg
399 (or (srl (and GPR:$src, 0xFFFF), 8),
400 (shl GPR:$src, 8)), i16))]>,
401 Requires<[IsThumb, HasV6]>;
402
403def tROR : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
404 "ror $dst, $rhs",
405 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
406
Evan Cheng53d7dba2007-01-27 00:07:15 +0000407
408// Subtract with carry
Evan Chenga8e29892007-01-19 07:51:42 +0000409def tSBC : TIt<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
410 "sbc $dst, $rhs",
411 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
412
Evan Cheng53d7dba2007-01-27 00:07:15 +0000413def tSUBS : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
414 "subs $dst, $lhs, $rhs",
415 [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
416
417
Evan Chenga8e29892007-01-19 07:51:42 +0000418// TODO: A7-96: STMIA - store multiple.
419
420def tSUBi3 : TI<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
421 "sub $dst, $lhs, $rhs",
422 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
423
424def tSUBi8 : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
425 "sub $dst, $rhs",
426 [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
427
428def tSUBrr : TI<(ops GPR:$dst, GPR:$lhs, GPR:$rhs),
429 "sub $dst, $lhs, $rhs",
430 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
431
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000432def tSUBspi : TIt<(ops GPR:$dst, GPR:$lhs, i32imm:$rhs),
433 "sub $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000434
435def tSXTB : TI<(ops GPR:$dst, GPR:$src),
436 "sxtb $dst, $src",
437 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
438 Requires<[IsThumb, HasV6]>;
439def tSXTH : TI<(ops GPR:$dst, GPR:$src),
440 "sxth $dst, $src",
441 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
442 Requires<[IsThumb, HasV6]>;
443
444// TODO: A7-122: TST - test.
445
446def tUXTB : TI<(ops GPR:$dst, GPR:$src),
447 "uxtb $dst, $src",
448 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
449 Requires<[IsThumb, HasV6]>;
450def tUXTH : TI<(ops GPR:$dst, GPR:$src),
451 "uxth $dst, $src",
452 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>,
453 Requires<[IsThumb, HasV6]>;
454
455
456// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
457// Expanded by the scheduler into a branch sequence.
458let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
459 def tMOVCCr :
460 PseudoInst<(ops GPR:$dst, GPR:$false, GPR:$true, CCOp:$cc),
461 "@ tMOVCCr $cc",
462 [(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))]>;
463
464// tLEApcrel - Load a pc-relative address into a register without offending the
465// assembler.
466def tLEApcrel : TI<(ops GPR:$dst, i32imm:$label),
467 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
468 "${:private}PCRELL${:uid}+4))\n"),
469 !strconcat("${:private}PCRELL${:uid}:\n\t",
470 "add $dst, pc, #PCRELV${:uid}")),
471 []>;
472
473def tLEApcrelCall : TI<(ops GPR:$dst, i32imm:$label),
474 !strconcat(!strconcat(".set PCRELV${:uid}, (${label:call}-(",
475 "${:private}PCRELL${:uid}+4))\n"),
476 !strconcat("${:private}PCRELL${:uid}:\n\t",
477 "add $dst, pc, #PCRELV${:uid}")),
478 []>;
479
480//===----------------------------------------------------------------------===//
481// Non-Instruction Patterns
482//
483
484// ConstantPool, GlobalAddress
485def : ThumbPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
486def : ThumbPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
487def : ThumbPat<(ARMWrapperCall tglobaladdr :$dst),
488 (tLEApcrelCall tglobaladdr :$dst)>;
489def : ThumbPat<(ARMWrapperCall texternalsym:$dst),
490 (tLEApcrelCall texternalsym:$dst)>;
491
492// Direct calls
493def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
494def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
495
496// Indirect calls to ARM routines
497def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
498
499// zextload i1 -> zextload i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000500def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
501 (tLDRB t_addrmode_s1:$addr)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000502
Evan Chengb60c02e2007-01-26 19:13:16 +0000503// extload -> zextload
504def : ThumbPat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
505def : ThumbPat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
506def : ThumbPat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
507
Evan Chenga8e29892007-01-19 07:51:42 +0000508// truncstore i1 -> truncstore i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000509def : ThumbPat<(truncstorei1 GPR:$src, t_addrmode_s1:$dst),
510 (tSTRB GPR:$src, t_addrmode_s1:$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000511
512// Large immediate handling.
513
514// Two piece imms.
515def : ThumbPat<(i32 thumb_immshifted:$src),
516 (tLSLri (tMOVri8 (thumb_immshifted_val imm:$src)),
517 (thumb_immshifted_shamt imm:$src))>;
518
519def : ThumbPat<(i32 imm0_255_comp:$src),
520 (tMVN (tMOVri8 (imm_comp_XFORM imm:$src)))>;