blob: 2577555246fb7b9332b82db691d99e3333127f73 [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===- ARMInstrThumb.td - Thumb support for ARM ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
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
Evan Chenga8e29892007-01-19 07:51:42 +000021def imm_neg_XFORM : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000022 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000023}]>;
24def imm_comp_XFORM : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000025 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000026}]>;
27
28
29/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
30def imm0_7 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000031 return (uint32_t)N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000032}]>;
33def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000034 return (uint32_t)-N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000035}], imm_neg_XFORM>;
36
37def imm0_255 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000038 return (uint32_t)N->getZExtValue() < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000039}]>;
40def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000041 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000042}]>;
43
44def imm8_255 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000045 return (uint32_t)N->getZExtValue() >= 8 && (uint32_t)N->getZExtValue() < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000046}]>;
47def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000048 unsigned Val = -N->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +000049 return Val >= 8 && Val < 256;
50}], imm_neg_XFORM>;
51
52// Break imm's up into two pieces: an immediate + a left shift.
53// This uses thumb_immshifted to match and thumb_immshifted_val and
54// thumb_immshifted_shamt to get the val/shift pieces.
55def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000056 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000057}]>;
58
59def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000060 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000061 return CurDAG->getTargetConstant(V, MVT::i32);
62}]>;
63
64def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000065 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000066 return CurDAG->getTargetConstant(V, MVT::i32);
67}]>;
68
69// Define Thumb specific addressing modes.
70
71// t_addrmode_rr := reg + reg
72//
73def t_addrmode_rr : Operand<i32>,
74 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
75 let PrintMethod = "printThumbAddrModeRROperand";
76 let MIOperandInfo = (ops GPR:$base, GPR:$offsreg);
77}
78
Evan Chengc38f2bc2007-01-23 22:59:13 +000079// t_addrmode_s4 := reg + reg
80// reg + imm5 * 4
Evan Chenga8e29892007-01-19 07:51:42 +000081//
Evan Chengc38f2bc2007-01-23 22:59:13 +000082def t_addrmode_s4 : Operand<i32>,
83 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
84 let PrintMethod = "printThumbAddrModeS4Operand";
Evan Chengcea117d2007-01-30 02:35:32 +000085 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +000086}
Evan Chengc38f2bc2007-01-23 22:59:13 +000087
88// t_addrmode_s2 := reg + reg
89// reg + imm5 * 2
90//
91def t_addrmode_s2 : Operand<i32>,
92 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
93 let PrintMethod = "printThumbAddrModeS2Operand";
Evan Chengcea117d2007-01-30 02:35:32 +000094 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +000095}
Evan Chengc38f2bc2007-01-23 22:59:13 +000096
97// t_addrmode_s1 := reg + reg
98// reg + imm5
99//
100def t_addrmode_s1 : Operand<i32>,
101 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
102 let PrintMethod = "printThumbAddrModeS1Operand";
Evan Chengcea117d2007-01-30 02:35:32 +0000103 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm, GPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000104}
105
106// t_addrmode_sp := sp + imm8 * 4
107//
108def t_addrmode_sp : Operand<i32>,
109 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
110 let PrintMethod = "printThumbAddrModeSPOperand";
111 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
112}
113
114//===----------------------------------------------------------------------===//
115// Miscellaneous Instructions.
116//
117
Evan Cheng071a2792007-09-11 19:55:27 +0000118let Defs = [SP], Uses = [SP] in {
Evan Cheng44bec522007-05-15 01:29:07 +0000119def tADJCALLSTACKUP :
Bill Wendling0f8d9c02007-11-13 00:44:25 +0000120PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2),
121 "@ tADJCALLSTACKUP $amt1",
122 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>, Requires<[IsThumb]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000123
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000124def tADJCALLSTACKDOWN :
Evan Cheng64d80e32007-07-19 01:14:50 +0000125PseudoInst<(outs), (ins i32imm:$amt),
Evan Cheng44bec522007-05-15 01:29:07 +0000126 "@ tADJCALLSTACKDOWN $amt",
Evan Cheng071a2792007-09-11 19:55:27 +0000127 [(ARMcallseq_start imm:$amt)]>, Requires<[IsThumb]>;
128}
Evan Cheng44bec522007-05-15 01:29:07 +0000129
Evan Chengeaa91b02007-06-19 01:26:51 +0000130let isNotDuplicable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000131def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp),
Evan Chengc60e76d2007-01-30 20:37:08 +0000132 "$cp:\n\tadd $dst, pc",
Evan Chenga8e29892007-01-19 07:51:42 +0000133 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
134
135//===----------------------------------------------------------------------===//
136// Control Flow Instructions.
137//
138
Evan Cheng9d945f72007-02-01 01:49:46 +0000139let isReturn = 1, isTerminator = 1 in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000140 def tBX_RET : TI<(outs), (ins), "bx lr", [(ARMretflag)]>;
Evan Cheng9d945f72007-02-01 01:49:46 +0000141 // Alternative return instruction used by vararg functions.
Evan Cheng64d80e32007-07-19 01:14:50 +0000142 def tBX_RET_vararg : TI<(outs), (ins GPR:$target), "bx $target", []>;
Evan Cheng9d945f72007-02-01 01:49:46 +0000143}
Evan Chenga8e29892007-01-19 07:51:42 +0000144
145// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng325474e2008-01-07 23:56:57 +0000146let isReturn = 1, isTerminator = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000147def tPOP_RET : TI<(outs reglist:$dst1, variable_ops), (ins),
Evan Chenga8e29892007-01-19 07:51:42 +0000148 "pop $dst1", []>;
149
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000150let isCall = 1,
Evan Chenga8e29892007-01-19 07:51:42 +0000151 Defs = [R0, R1, R2, R3, LR,
152 D0, D1, D2, D3, D4, D5, D6, D7] in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000153 def tBL : TIx2<(outs), (ins i32imm:$func, variable_ops),
Evan Chenga8e29892007-01-19 07:51:42 +0000154 "bl ${func:call}",
155 [(ARMtcall tglobaladdr:$func)]>;
156 // ARMv5T and above
Evan Cheng64d80e32007-07-19 01:14:50 +0000157 def tBLXi : TIx2<(outs), (ins i32imm:$func, variable_ops),
Evan Chenga8e29892007-01-19 07:51:42 +0000158 "blx ${func:call}",
159 [(ARMcall tglobaladdr:$func)]>, Requires<[HasV5T]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000160 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops),
161 "blx $func",
162 [(ARMtcall GPR:$func)]>, Requires<[HasV5T]>;
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000163 // ARMv4T
Evan Cheng64d80e32007-07-19 01:14:50 +0000164 def tBX : TIx2<(outs), (ins GPR:$func, variable_ops),
165 "cpy lr, pc\n\tbx $func",
166 [(ARMcall_nolink GPR:$func)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000167}
168
Evan Chengffbacca2007-07-21 00:34:19 +0000169let isBranch = 1, isTerminator = 1 in {
Evan Cheng3f8602c2007-05-16 21:53:43 +0000170 let isBarrier = 1 in {
171 let isPredicable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000172 def tB : TI<(outs), (ins brtarget:$target), "b $target",
173 [(br bb:$target)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000174
Evan Cheng225dfe92007-01-30 01:13:37 +0000175 // Far jump
Evan Cheng64d80e32007-07-19 01:14:50 +0000176 def tBfar : TIx2<(outs), (ins brtarget:$target), "bl $target\t@ far jump",[]>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000177
Evan Cheng64d80e32007-07-19 01:14:50 +0000178 def tBR_JTr : TJTI<(outs),
179 (ins GPR:$target, jtblock_operand:$jt, i32imm:$id),
180 "cpy pc, $target \n\t.align\t2\n$jt",
181 [(ARMbrjt GPR:$target, tjumptable:$jt, imm:$id)]>;
Evan Cheng3f8602c2007-05-16 21:53:43 +0000182 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000183}
184
Evan Chengc85e8322007-07-05 07:13:32 +0000185// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000186// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000187let isBranch = 1, isTerminator = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000188 def tBcc : TI<(outs), (ins brtarget:$target, pred:$cc), "b$cc $target",
189 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000190
191//===----------------------------------------------------------------------===//
192// Load Store Instructions.
193//
194
Dan Gohman15511cf2008-12-03 18:15:48 +0000195let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000196def tLDR : TI4<(outs GPR:$dst), (ins t_addrmode_s4:$addr),
Evan Chengc38f2bc2007-01-23 22:59:13 +0000197 "ldr $dst, $addr",
198 [(set GPR:$dst, (load t_addrmode_s4:$addr))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000199
Evan Cheng64d80e32007-07-19 01:14:50 +0000200def tLDRB : TI1<(outs GPR:$dst), (ins t_addrmode_s1:$addr),
Evan Chengc38f2bc2007-01-23 22:59:13 +0000201 "ldrb $dst, $addr",
202 [(set GPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
203
Evan Cheng64d80e32007-07-19 01:14:50 +0000204def tLDRH : TI2<(outs GPR:$dst), (ins t_addrmode_s2:$addr),
Evan Chengc38f2bc2007-01-23 22:59:13 +0000205 "ldrh $dst, $addr",
206 [(set GPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
207
Evan Cheng64d80e32007-07-19 01:14:50 +0000208def tLDRSB : TI1<(outs GPR:$dst), (ins t_addrmode_rr:$addr),
Evan Chengc38f2bc2007-01-23 22:59:13 +0000209 "ldrsb $dst, $addr",
210 [(set GPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
211
Evan Cheng64d80e32007-07-19 01:14:50 +0000212def tLDRSH : TI2<(outs GPR:$dst), (ins t_addrmode_rr:$addr),
Evan Chengc38f2bc2007-01-23 22:59:13 +0000213 "ldrsh $dst, $addr",
214 [(set GPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
215
Dan Gohman15511cf2008-12-03 18:15:48 +0000216let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000217def tLDRspi : TIs<(outs GPR:$dst), (ins t_addrmode_sp:$addr),
Evan Chenga8e29892007-01-19 07:51:42 +0000218 "ldr $dst, $addr",
219 [(set GPR:$dst, (load t_addrmode_sp:$addr))]>;
Evan Cheng012f2d92007-01-24 08:53:17 +0000220
Evan Cheng8e59ea92007-02-07 00:06:56 +0000221// Special instruction for restore. It cannot clobber condition register
222// when it's expanded by eliminateCallFramePseudoInstr().
Dan Gohman15511cf2008-12-03 18:15:48 +0000223let canFoldAsLoad = 1, mayLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000224def tRestore : TIs<(outs GPR:$dst), (ins t_addrmode_sp:$addr),
Evan Cheng8e59ea92007-02-07 00:06:56 +0000225 "ldr $dst, $addr", []>;
226
Evan Cheng012f2d92007-01-24 08:53:17 +0000227// Load tconstpool
Dan Gohman15511cf2008-12-03 18:15:48 +0000228let canFoldAsLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000229def tLDRpci : TIs<(outs GPR:$dst), (ins i32imm:$addr),
Evan Cheng012f2d92007-01-24 08:53:17 +0000230 "ldr $dst, $addr",
231 [(set GPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Evan Chengfa775d02007-03-19 07:20:03 +0000232
233// Special LDR for loads from non-pc-relative constpools.
Dan Gohman15511cf2008-12-03 18:15:48 +0000234let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000235def tLDRcp : TIs<(outs GPR:$dst), (ins i32imm:$addr),
Evan Chengfa775d02007-03-19 07:20:03 +0000236 "ldr $dst, $addr", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000237
Evan Cheng64d80e32007-07-19 01:14:50 +0000238def tSTR : TI4<(outs), (ins GPR:$src, t_addrmode_s4:$addr),
Evan Chengc38f2bc2007-01-23 22:59:13 +0000239 "str $src, $addr",
240 [(store GPR:$src, t_addrmode_s4:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000241
Evan Cheng64d80e32007-07-19 01:14:50 +0000242def tSTRB : TI1<(outs), (ins GPR:$src, t_addrmode_s1:$addr),
Evan Chengc38f2bc2007-01-23 22:59:13 +0000243 "strb $src, $addr",
244 [(truncstorei8 GPR:$src, t_addrmode_s1:$addr)]>;
245
Evan Cheng64d80e32007-07-19 01:14:50 +0000246def tSTRH : TI2<(outs), (ins GPR:$src, t_addrmode_s2:$addr),
Evan Chengc38f2bc2007-01-23 22:59:13 +0000247 "strh $src, $addr",
248 [(truncstorei16 GPR:$src, t_addrmode_s2:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000249
Evan Cheng64d80e32007-07-19 01:14:50 +0000250def tSTRspi : TIs<(outs), (ins GPR:$src, t_addrmode_sp:$addr),
Evan Chenga8e29892007-01-19 07:51:42 +0000251 "str $src, $addr",
252 [(store GPR:$src, t_addrmode_sp:$addr)]>;
Evan Cheng8e59ea92007-02-07 00:06:56 +0000253
Chris Lattner2e48a702008-01-06 08:36:04 +0000254let mayStore = 1 in {
Evan Cheng8e59ea92007-02-07 00:06:56 +0000255// Special instruction for spill. It cannot clobber condition register
256// when it's expanded by eliminateCallFramePseudoInstr().
Evan Cheng64d80e32007-07-19 01:14:50 +0000257def tSpill : TIs<(outs), (ins GPR:$src, t_addrmode_sp:$addr),
Evan Cheng8e59ea92007-02-07 00:06:56 +0000258 "str $src, $addr", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000259}
260
261//===----------------------------------------------------------------------===//
262// Load / store multiple Instructions.
263//
264
265// TODO: A7-44: LDMIA - load multiple
266
Chris Lattner9b37aaf2008-01-10 05:12:37 +0000267let mayLoad = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000268def tPOP : TI<(outs reglist:$dst1, variable_ops), (ins),
Evan Chenga8e29892007-01-19 07:51:42 +0000269 "pop $dst1", []>;
270
Chris Lattner2e48a702008-01-06 08:36:04 +0000271let mayStore = 1 in
Evan Cheng64d80e32007-07-19 01:14:50 +0000272def tPUSH : TI<(outs), (ins reglist:$src1, variable_ops),
Evan Chenga8e29892007-01-19 07:51:42 +0000273 "push $src1", []>;
274
275//===----------------------------------------------------------------------===//
276// Arithmetic Instructions.
277//
278
Evan Cheng53d7dba2007-01-27 00:07:15 +0000279// Add with carry
Evan Cheng64d80e32007-07-19 01:14:50 +0000280def tADC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng53d7dba2007-01-27 00:07:15 +0000281 "adc $dst, $rhs",
282 [(set GPR:$dst, (adde GPR:$lhs, GPR:$rhs))]>;
283
Evan Cheng64d80e32007-07-19 01:14:50 +0000284def tADDS : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng3471b602007-01-31 20:12:31 +0000285 "add $dst, $lhs, $rhs",
Evan Cheng53d7dba2007-01-27 00:07:15 +0000286 [(set GPR:$dst, (addc GPR:$lhs, GPR:$rhs))]>;
287
288
Evan Cheng64d80e32007-07-19 01:14:50 +0000289def tADDi3 : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000290 "add $dst, $lhs, $rhs",
291 [(set GPR:$dst, (add GPR:$lhs, imm0_7:$rhs))]>;
292
Evan Cheng64d80e32007-07-19 01:14:50 +0000293def tADDi8 : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000294 "add $dst, $rhs",
295 [(set GPR:$dst, (add GPR:$lhs, imm8_255:$rhs))]>;
296
Evan Cheng64d80e32007-07-19 01:14:50 +0000297def tADDrr : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000298 "add $dst, $lhs, $rhs",
299 [(set GPR:$dst, (add GPR:$lhs, GPR:$rhs))]>;
300
Evan Cheng64d80e32007-07-19 01:14:50 +0000301def tADDhirr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000302 "add $dst, $rhs", []>;
303
Evan Cheng64d80e32007-07-19 01:14:50 +0000304def tADDrPCi : TI<(outs GPR:$dst), (ins i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000305 "add $dst, pc, $rhs * 4", []>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000306def tADDrSPi : TI<(outs GPR:$dst), (ins GPR:$sp, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000307 "add $dst, $sp, $rhs * 4", []>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000308def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000309 "add $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000310
Evan Cheng64d80e32007-07-19 01:14:50 +0000311def tAND : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000312 "and $dst, $rhs",
313 [(set GPR:$dst, (and GPR:$lhs, GPR:$rhs))]>;
314
Evan Cheng64d80e32007-07-19 01:14:50 +0000315def tASRri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000316 "asr $dst, $lhs, $rhs",
317 [(set GPR:$dst, (sra GPR:$lhs, imm:$rhs))]>;
318
Evan Cheng64d80e32007-07-19 01:14:50 +0000319def tASRrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000320 "asr $dst, $rhs",
321 [(set GPR:$dst, (sra GPR:$lhs, GPR:$rhs))]>;
322
Evan Cheng64d80e32007-07-19 01:14:50 +0000323def tBIC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000324 "bic $dst, $rhs",
325 [(set GPR:$dst, (and GPR:$lhs, (not GPR:$rhs)))]>;
326
327
Evan Cheng64d80e32007-07-19 01:14:50 +0000328def tCMN : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000329 "cmn $lhs, $rhs",
330 [(ARMcmp GPR:$lhs, (ineg GPR:$rhs))]>;
331
Evan Cheng64d80e32007-07-19 01:14:50 +0000332def tCMPi8 : TI<(outs), (ins GPR:$lhs, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000333 "cmp $lhs, $rhs",
334 [(ARMcmp GPR:$lhs, imm0_255:$rhs)]>;
335
Evan Cheng64d80e32007-07-19 01:14:50 +0000336def tCMPr : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000337 "cmp $lhs, $rhs",
338 [(ARMcmp GPR:$lhs, GPR:$rhs)]>;
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000339
Evan Cheng64d80e32007-07-19 01:14:50 +0000340def tTST : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000341 "tst $lhs, $rhs",
342 [(ARMcmpNZ (and GPR:$lhs, GPR:$rhs), 0)]>;
343
Evan Cheng64d80e32007-07-19 01:14:50 +0000344def tCMNNZ : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000345 "cmn $lhs, $rhs",
346 [(ARMcmpNZ GPR:$lhs, (ineg GPR:$rhs))]>;
347
Evan Cheng64d80e32007-07-19 01:14:50 +0000348def tCMPNZi8 : TI<(outs), (ins GPR:$lhs, i32imm:$rhs),
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000349 "cmp $lhs, $rhs",
350 [(ARMcmpNZ GPR:$lhs, imm0_255:$rhs)]>;
351
Evan Cheng64d80e32007-07-19 01:14:50 +0000352def tCMPNZr : TI<(outs), (ins GPR:$lhs, GPR:$rhs),
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000353 "cmp $lhs, $rhs",
354 [(ARMcmpNZ GPR:$lhs, GPR:$rhs)]>;
355
Evan Chenga8e29892007-01-19 07:51:42 +0000356// TODO: A7-37: CMP(3) - cmp hi regs
357
Evan Cheng64d80e32007-07-19 01:14:50 +0000358def tEOR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000359 "eor $dst, $rhs",
360 [(set GPR:$dst, (xor GPR:$lhs, GPR:$rhs))]>;
361
Evan Cheng64d80e32007-07-19 01:14:50 +0000362def tLSLri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000363 "lsl $dst, $lhs, $rhs",
364 [(set GPR:$dst, (shl GPR:$lhs, imm:$rhs))]>;
365
Evan Cheng64d80e32007-07-19 01:14:50 +0000366def tLSLrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000367 "lsl $dst, $rhs",
368 [(set GPR:$dst, (shl GPR:$lhs, GPR:$rhs))]>;
369
Evan Cheng64d80e32007-07-19 01:14:50 +0000370def tLSRri : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000371 "lsr $dst, $lhs, $rhs",
372 [(set GPR:$dst, (srl GPR:$lhs, imm:$rhs))]>;
373
Evan Cheng64d80e32007-07-19 01:14:50 +0000374def tLSRrr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000375 "lsr $dst, $rhs",
376 [(set GPR:$dst, (srl GPR:$lhs, GPR:$rhs))]>;
377
Evan Cheng5e3c2032007-03-29 21:38:31 +0000378// FIXME: This is not rematerializable because mov changes the condition code.
Evan Cheng64d80e32007-07-19 01:14:50 +0000379def tMOVi8 : TI<(outs GPR:$dst), (ins i32imm:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000380 "mov $dst, $src",
381 [(set GPR:$dst, imm0_255:$src)]>;
382
383// TODO: A7-73: MOV(2) - mov setting flag.
384
385
386// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
387// which is MOV(3). This also supports high registers.
Evan Cheng64d80e32007-07-19 01:14:50 +0000388def tMOVr : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000389 "cpy $dst, $src", []>;
390
Evan Cheng64d80e32007-07-19 01:14:50 +0000391def tMUL : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000392 "mul $dst, $rhs",
393 [(set GPR:$dst, (mul GPR:$lhs, GPR:$rhs))]>;
394
Evan Cheng64d80e32007-07-19 01:14:50 +0000395def tMVN : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000396 "mvn $dst, $src",
397 [(set GPR:$dst, (not GPR:$src))]>;
398
Evan Cheng64d80e32007-07-19 01:14:50 +0000399def tNEG : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000400 "neg $dst, $src",
401 [(set GPR:$dst, (ineg GPR:$src))]>;
402
Evan Cheng64d80e32007-07-19 01:14:50 +0000403def tORR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000404 "orr $dst, $rhs",
405 [(set GPR:$dst, (or GPR:$lhs, GPR:$rhs))]>;
406
407
Evan Cheng64d80e32007-07-19 01:14:50 +0000408def tREV : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000409 "rev $dst, $src",
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000410 [(set GPR:$dst, (bswap GPR:$src))]>,
Evan Chenga8e29892007-01-19 07:51:42 +0000411 Requires<[IsThumb, HasV6]>;
412
Evan Cheng64d80e32007-07-19 01:14:50 +0000413def tREV16 : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000414 "rev16 $dst, $src",
415 [(set GPR:$dst,
416 (or (and (srl GPR:$src, 8), 0xFF),
417 (or (and (shl GPR:$src, 8), 0xFF00),
418 (or (and (srl GPR:$src, 8), 0xFF0000),
419 (and (shl GPR:$src, 8), 0xFF000000)))))]>,
420 Requires<[IsThumb, HasV6]>;
421
Evan Cheng64d80e32007-07-19 01:14:50 +0000422def tREVSH : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000423 "revsh $dst, $src",
424 [(set GPR:$dst,
425 (sext_inreg
426 (or (srl (and GPR:$src, 0xFFFF), 8),
427 (shl GPR:$src, 8)), i16))]>,
428 Requires<[IsThumb, HasV6]>;
429
Evan Cheng64d80e32007-07-19 01:14:50 +0000430def tROR : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000431 "ror $dst, $rhs",
432 [(set GPR:$dst, (rotr GPR:$lhs, GPR:$rhs))]>;
433
Evan Cheng53d7dba2007-01-27 00:07:15 +0000434
435// Subtract with carry
Evan Cheng64d80e32007-07-19 01:14:50 +0000436def tSBC : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000437 "sbc $dst, $rhs",
438 [(set GPR:$dst, (sube GPR:$lhs, GPR:$rhs))]>;
439
Evan Cheng64d80e32007-07-19 01:14:50 +0000440def tSUBS : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Cheng3471b602007-01-31 20:12:31 +0000441 "sub $dst, $lhs, $rhs",
Evan Cheng53d7dba2007-01-27 00:07:15 +0000442 [(set GPR:$dst, (subc GPR:$lhs, GPR:$rhs))]>;
443
444
Evan Chenga8e29892007-01-19 07:51:42 +0000445// TODO: A7-96: STMIA - store multiple.
446
Evan Cheng64d80e32007-07-19 01:14:50 +0000447def tSUBi3 : TI<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000448 "sub $dst, $lhs, $rhs",
449 [(set GPR:$dst, (add GPR:$lhs, imm0_7_neg:$rhs))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000450
Evan Cheng64d80e32007-07-19 01:14:50 +0000451def tSUBi8 : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000452 "sub $dst, $rhs",
453 [(set GPR:$dst, (add GPR:$lhs, imm8_255_neg:$rhs))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000454
Evan Cheng64d80e32007-07-19 01:14:50 +0000455def tSUBrr : TI<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Evan Chenga8e29892007-01-19 07:51:42 +0000456 "sub $dst, $lhs, $rhs",
457 [(set GPR:$dst, (sub GPR:$lhs, GPR:$rhs))]>;
458
Evan Cheng64d80e32007-07-19 01:14:50 +0000459def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
Evan Cheng3fdadfc2007-01-26 21:33:19 +0000460 "sub $dst, $rhs * 4", []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000461
Evan Cheng64d80e32007-07-19 01:14:50 +0000462def tSXTB : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000463 "sxtb $dst, $src",
464 [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>,
465 Requires<[IsThumb, HasV6]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000466def tSXTH : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000467 "sxth $dst, $src",
468 [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>,
469 Requires<[IsThumb, HasV6]>;
470
Evan Chenga8e29892007-01-19 07:51:42 +0000471
Evan Cheng64d80e32007-07-19 01:14:50 +0000472def tUXTB : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000473 "uxtb $dst, $src",
474 [(set GPR:$dst, (and GPR:$src, 0xFF))]>,
475 Requires<[IsThumb, HasV6]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000476def tUXTH : TI<(outs GPR:$dst), (ins GPR:$src),
Evan Chenga8e29892007-01-19 07:51:42 +0000477 "uxth $dst, $src",
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000478 [(set GPR:$dst, (and GPR:$src, 0xFFFF))]>,
Evan Chenga8e29892007-01-19 07:51:42 +0000479 Requires<[IsThumb, HasV6]>;
480
481
482// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
483// Expanded by the scheduler into a branch sequence.
484let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
485 def tMOVCCr :
Evan Cheng64d80e32007-07-19 01:14:50 +0000486 PseudoInst<(outs GPR:$dst), (ins GPR:$false, GPR:$true, pred:$cc),
Evan Chenga8e29892007-01-19 07:51:42 +0000487 "@ tMOVCCr $cc",
Evan Chengc85e8322007-07-05 07:13:32 +0000488 [/*(set GPR:$dst, (ARMcmov GPR:$false, GPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000489
490// tLEApcrel - Load a pc-relative address into a register without offending the
491// assembler.
Evan Cheng64d80e32007-07-19 01:14:50 +0000492def tLEApcrel : TIx2<(outs GPR:$dst), (ins i32imm:$label),
Evan Chenga8e29892007-01-19 07:51:42 +0000493 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
Evan Cheng1b201682007-05-01 20:27:19 +0000494 "${:private}PCRELL${:uid}+4))\n"),
Evan Chenge0c2b6b2007-02-01 03:04:49 +0000495 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
496 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
Evan Chenga8e29892007-01-19 07:51:42 +0000497 []>;
498
Evan Cheng64d80e32007-07-19 01:14:50 +0000499def tLEApcrelJT : TIx2<(outs GPR:$dst), (ins i32imm:$label, i32imm:$id),
Evan Chengd85ac4d2007-01-27 02:29:45 +0000500 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
501 "${:private}PCRELL${:uid}+4))\n"),
Evan Chenge0c2b6b2007-02-01 03:04:49 +0000502 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
503 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
504 []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +0000505
Evan Chenga8e29892007-01-19 07:51:42 +0000506//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000507// TLS Instructions
508//
509
510// __aeabi_read_tp preserves the registers r1-r3.
511let isCall = 1,
512 Defs = [R0, LR] in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000513 def tTPsoft : TIx2<(outs), (ins),
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +0000514 "bl __aeabi_read_tp",
515 [(set R0, ARMthread_pointer)]>;
516}
517
518//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +0000519// Non-Instruction Patterns
520//
521
522// ConstantPool, GlobalAddress
523def : ThumbPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
524def : ThumbPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +0000525
Evan Chengd85ac4d2007-01-27 02:29:45 +0000526// JumpTable
527def : ThumbPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
528 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
529
Evan Chenga8e29892007-01-19 07:51:42 +0000530// Direct calls
531def : ThumbPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
532def : ThumbV5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
533
534// Indirect calls to ARM routines
535def : ThumbV5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>;
536
537// zextload i1 -> zextload i8
Evan Chengc38f2bc2007-01-23 22:59:13 +0000538def : ThumbPat<(zextloadi1 t_addrmode_s1:$addr),
539 (tLDRB t_addrmode_s1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000540
Evan Chengb60c02e2007-01-26 19:13:16 +0000541// extload -> zextload
542def : ThumbPat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
543def : ThumbPat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
544def : ThumbPat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
545
Evan Chenga8e29892007-01-19 07:51:42 +0000546// Large immediate handling.
547
548// Two piece imms.
549def : ThumbPat<(i32 thumb_immshifted:$src),
Evan Cheng9f6636f2007-03-19 07:48:02 +0000550 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
Evan Chenga8e29892007-01-19 07:51:42 +0000551 (thumb_immshifted_shamt imm:$src))>;
552
553def : ThumbPat<(i32 imm0_255_comp:$src),
Evan Cheng9f6636f2007-03-19 07:48:02 +0000554 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;