blob: 9b54e67bedf6909f09e62bae9094de73fa7c7206 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMInstrThumb.td - Thumb support for ARM ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021def imm_neg_XFORM : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000022 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023}]>;
24def imm_comp_XFORM : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000025 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Gohmanfaeb4a32008-09-12 16:56:44 +000031 return (uint32_t)N->getZExtValue() < 8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000032}]>;
33def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000034 return (uint32_t)-N->getZExtValue() < 8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035}], imm_neg_XFORM>;
36
37def imm0_255 : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000038 return (uint32_t)N->getZExtValue() < 256;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039}]>;
40def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000041 return ~((uint32_t)N->getZExtValue()) < 256;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042}]>;
43
44def imm8_255 : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000045 return (uint32_t)N->getZExtValue() >= 8 && (uint32_t)N->getZExtValue() < 256;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046}]>;
47def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000048 unsigned Val = -N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Gohmanfaeb4a32008-09-12 16:56:44 +000056 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057}]>;
58
59def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000060 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 return CurDAG->getTargetConstant(V, MVT::i32);
62}]>;
63
64def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000065 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Dan Gohmanf17a25c2007-07-18 16:29:46 +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";
Jim Grosbach0e4e9742009-04-07 20:34:09 +000076 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077}
78
79// t_addrmode_s4 := reg + reg
80// reg + imm5 * 4
81//
82def t_addrmode_s4 : Operand<i32>,
83 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
84 let PrintMethod = "printThumbAddrModeS4Operand";
Jim Grosbach0e4e9742009-04-07 20:34:09 +000085 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000086}
87
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";
Jim Grosbach0e4e9742009-04-07 20:34:09 +000094 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095}
96
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";
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000103 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +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";
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000111 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000112}
113
114//===----------------------------------------------------------------------===//
115// Miscellaneous Instructions.
116//
117
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000118let Defs = [SP], Uses = [SP] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000119def tADJCALLSTACKUP :
David Goodwincfd67652009-08-06 16:52:47 +0000120PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
Bill Wendling22f8deb2007-11-13 00:44:25 +0000121 "@ tADJCALLSTACKUP $amt1",
David Goodwin4a897932009-07-08 23:10:31 +0000122 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>, Requires<[IsThumb1Only]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000123
Jim Grosbach7ea52762009-03-27 23:06:27 +0000124def tADJCALLSTACKDOWN :
David Goodwincfd67652009-08-06 16:52:47 +0000125PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000126 "@ tADJCALLSTACKDOWN $amt",
David Goodwin4a897932009-07-08 23:10:31 +0000127 [(ARMcallseq_start imm:$amt)]>, Requires<[IsThumb1Only]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000128}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000129
Evan Chengd16eb2f2009-08-04 23:47:55 +0000130// For both thumb1 and thumb2.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000131let isNotDuplicable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000132def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALU,
Evan Chengd16eb2f2009-08-04 23:47:55 +0000133 "$cp:\n\tadd $dst, pc",
134 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000135
Evan Chengae2ed1f2009-06-25 01:05:06 +0000136// PC relative add.
David Goodwincfd67652009-08-06 16:52:47 +0000137def tADDrPCi : T1I<(outs tGPR:$dst), (ins i32imm:$rhs), IIC_iALU,
Evan Chengae2ed1f2009-06-25 01:05:06 +0000138 "add $dst, pc, $rhs * 4", []>;
139
140// ADD rd, sp, #imm8
David Goodwincfd67652009-08-06 16:52:47 +0000141def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, i32imm:$rhs), IIC_iALU,
Evan Chengae2ed1f2009-06-25 01:05:06 +0000142 "add $dst, $sp, $rhs * 4 @ addrspi", []>;
143
144// ADD sp, sp, #imm7
Evan Cheng815c23a2009-08-07 00:34:42 +0000145def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Chengae2ed1f2009-06-25 01:05:06 +0000146 "add $dst, $rhs * 4", []>;
147
Evan Cheng815c23a2009-08-07 00:34:42 +0000148// SUB sp, sp, #imm7
149def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs), IIC_iALU,
150 "sub $dst, $rhs * 4", []>;
151
Evan Chengae2ed1f2009-06-25 01:05:06 +0000152// ADD rm, sp, rm
Evan Cheng815c23a2009-08-07 00:34:42 +0000153def tADDrSPr : TI<(outs GPR:$dst), (ins GPR:$sp, GPR:$rhs), IIC_iALU,
154 "add $dst, $sp, $rhs", []>;
155
Evan Chengae2ed1f2009-06-25 01:05:06 +0000156// ADD sp, rm
Evan Cheng815c23a2009-08-07 00:34:42 +0000157def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
158 "add $dst, $rhs", []>;
159
160// Pseudo instruction that will expand into a tSUBspi + a copy.
161let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler.
162def tSUBspi_ : PseudoInst<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
163 NoItinerary, "@ sub $dst, $rhs * 4", []>;
164
165def tADDspr_ : PseudoInst<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs),
166 NoItinerary, "@ add $dst, $rhs", []>;
167
168let Defs = [CPSR] in
169def tANDsp : PseudoInst<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
170 NoItinerary, "@ and $dst, $rhs", []>;
171} // usesCustomDAGSchedInserter
Evan Chengae2ed1f2009-06-25 01:05:06 +0000172
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173//===----------------------------------------------------------------------===//
174// Control Flow Instructions.
175//
176
177let isReturn = 1, isTerminator = 1 in {
David Goodwincfd67652009-08-06 16:52:47 +0000178 def tBX_RET : TI<(outs), (ins), IIC_Br, "bx lr", [(ARMretflag)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179 // Alternative return instruction used by vararg functions.
David Goodwincfd67652009-08-06 16:52:47 +0000180 def tBX_RET_vararg : TI<(outs), (ins tGPR:$target), IIC_Br, "bx $target", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000181}
182
183// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng8610a3b2008-01-07 23:56:57 +0000184let isReturn = 1, isTerminator = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000185def tPOP_RET : T1I<(outs reglist:$dst1, variable_ops), (ins), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186 "pop $dst1", []>;
187
Jim Grosbach7ea52762009-03-27 23:06:27 +0000188let isCall = 1,
Evan Cheng27396a62009-07-22 06:46:53 +0000189 Defs = [R0, R1, R2, R3, R12, LR,
190 D0, D1, D2, D3, D4, D5, D6, D7,
191 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng80ab2a82009-07-29 20:10:36 +0000192 D24, D25, D26, D27, D28, D29, D30, D31, CPSR] in {
Evan Cheng68e4b582009-08-01 00:16:10 +0000193 // Also used for Thumb2
David Goodwincfd67652009-08-06 16:52:47 +0000194 def tBL : TIx2<(outs), (ins i32imm:$func, variable_ops), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000195 "bl ${func:call}",
Evan Cheng9e734482009-07-29 21:26:42 +0000196 [(ARMtcall tglobaladdr:$func)]>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000197 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000198
Evan Cheng68e4b582009-08-01 00:16:10 +0000199 // ARMv5T and above, also used for Thumb2
David Goodwincfd67652009-08-06 16:52:47 +0000200 def tBLXi : TIx2<(outs), (ins i32imm:$func, variable_ops), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201 "blx ${func:call}",
Evan Cheng9e734482009-07-29 21:26:42 +0000202 [(ARMcall tglobaladdr:$func)]>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000203 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000204
Evan Cheng68e4b582009-08-01 00:16:10 +0000205 // Also used for Thumb2
David Goodwincfd67652009-08-06 16:52:47 +0000206 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
Evan Chengb783fa32007-07-19 01:14:50 +0000207 "blx $func",
Evan Cheng68e4b582009-08-01 00:16:10 +0000208 [(ARMtcall GPR:$func)]>,
209 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000210
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000211 // ARMv4T
David Goodwincfd67652009-08-06 16:52:47 +0000212 def tBX : TIx2<(outs), (ins tGPR:$func, variable_ops), IIC_Br,
Evan Chengfb1d1472009-07-14 01:49:27 +0000213 "mov lr, pc\n\tbx $func",
Evan Cheng9e734482009-07-29 21:26:42 +0000214 [(ARMcall_nolink tGPR:$func)]>,
215 Requires<[IsThumb1Only, IsNotDarwin]>;
216}
217
218// On Darwin R9 is call-clobbered.
219let isCall = 1,
220 Defs = [R0, R1, R2, R3, R9, R12, LR,
221 D0, D1, D2, D3, D4, D5, D6, D7,
222 D16, D17, D18, D19, D20, D21, D22, D23,
223 D24, D25, D26, D27, D28, D29, D30, D31, CPSR] in {
Evan Cheng68e4b582009-08-01 00:16:10 +0000224 // Also used for Thumb2
David Goodwincfd67652009-08-06 16:52:47 +0000225 def tBLr9 : TIx2<(outs), (ins i32imm:$func, variable_ops), IIC_Br,
Evan Cheng9e734482009-07-29 21:26:42 +0000226 "bl ${func:call}",
227 [(ARMtcall tglobaladdr:$func)]>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000228 Requires<[IsThumb, IsDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000229
Evan Cheng68e4b582009-08-01 00:16:10 +0000230 // ARMv5T and above, also used for Thumb2
David Goodwincfd67652009-08-06 16:52:47 +0000231 def tBLXi_r9 : TIx2<(outs), (ins i32imm:$func, variable_ops), IIC_Br,
Evan Cheng9e734482009-07-29 21:26:42 +0000232 "blx ${func:call}",
233 [(ARMcall tglobaladdr:$func)]>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000234 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000235
Evan Cheng68e4b582009-08-01 00:16:10 +0000236 // Also used for Thumb2
David Goodwincfd67652009-08-06 16:52:47 +0000237 def tBLXr_r9 : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
Evan Cheng9e734482009-07-29 21:26:42 +0000238 "blx $func",
Evan Cheng68e4b582009-08-01 00:16:10 +0000239 [(ARMtcall GPR:$func)]>,
240 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000241
242 // ARMv4T
David Goodwincfd67652009-08-06 16:52:47 +0000243 def tBXr9 : TIx2<(outs), (ins tGPR:$func, variable_ops), IIC_Br,
Evan Cheng9e734482009-07-29 21:26:42 +0000244 "mov lr, pc\n\tbx $func",
245 [(ARMcall_nolink tGPR:$func)]>,
246 Requires<[IsThumb1Only, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247}
248
Evan Cheng37e7c752007-07-21 00:34:19 +0000249let isBranch = 1, isTerminator = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000250 let isBarrier = 1 in {
251 let isPredicable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000252 def tB : T1I<(outs), (ins brtarget:$target), IIC_Br,
253 "b $target", [(br bb:$target)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254
255 // Far jump
David Goodwincfd67652009-08-06 16:52:47 +0000256 def tBfar : TIx2<(outs), (ins brtarget:$target), IIC_Br,
David Goodwinf6154702009-06-30 18:04:13 +0000257 "bl $target\t@ far jump",[]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000258
David Goodwinf6154702009-06-30 18:04:13 +0000259 def tBR_JTr : T1JTI<(outs),
260 (ins tGPR:$target, jtblock_operand:$jt, i32imm:$id),
David Goodwincfd67652009-08-06 16:52:47 +0000261 IIC_Br, "mov pc, $target\n\t.align\t2\n$jt",
David Goodwinf6154702009-06-30 18:04:13 +0000262 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263 }
264}
265
266// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach7ea52762009-03-27 23:06:27 +0000267// a two-value operand where a dag node expects two operands. :(
Evan Cheng37e7c752007-07-21 00:34:19 +0000268let isBranch = 1, isTerminator = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000269 def tBcc : T1I<(outs), (ins brtarget:$target, pred:$cc), IIC_Br,
270 "b$cc $target",
Evan Chengb783fa32007-07-19 01:14:50 +0000271 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272
273//===----------------------------------------------------------------------===//
274// Load Store Instructions.
275//
276
Dan Gohman5574cc72008-12-03 18:15:48 +0000277let canFoldAsLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000278def tLDR : T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000279 "ldr", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000280 [(set tGPR:$dst, (load t_addrmode_s4:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000281
David Goodwincfd67652009-08-06 16:52:47 +0000282def tLDRB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000283 "ldrb", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000284 [(set tGPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285
David Goodwincfd67652009-08-06 16:52:47 +0000286def tLDRH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000287 "ldrh", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000288 [(set tGPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289
Evan Cheng76aeed32009-07-11 07:08:13 +0000290let AddedComplexity = 10 in
David Goodwincfd67652009-08-06 16:52:47 +0000291def tLDRSB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000292 "ldrsb", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000293 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294
Evan Cheng76aeed32009-07-11 07:08:13 +0000295let AddedComplexity = 10 in
David Goodwincfd67652009-08-06 16:52:47 +0000296def tLDRSH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000297 "ldrsh", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000298 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299
Dan Gohman5574cc72008-12-03 18:15:48 +0000300let canFoldAsLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000301def tLDRspi : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000302 "ldr", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000303 [(set tGPR:$dst, (load t_addrmode_sp:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304
305// Special instruction for restore. It cannot clobber condition register
306// when it's expanded by eliminateCallFramePseudoInstr().
Dan Gohman5574cc72008-12-03 18:15:48 +0000307let canFoldAsLoad = 1, mayLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000308def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000309 "ldr", " $dst, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000310
311// Load tconstpool
Dan Gohman5574cc72008-12-03 18:15:48 +0000312let canFoldAsLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000313def tLDRpci : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000314 "ldr", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000315 [(set tGPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316
317// Special LDR for loads from non-pc-relative constpools.
Dan Gohman5574cc72008-12-03 18:15:48 +0000318let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000319def tLDRcp : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000320 "ldr", " $dst, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000321
David Goodwincfd67652009-08-06 16:52:47 +0000322def tSTR : T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000323 "str", " $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000324 [(store tGPR:$src, t_addrmode_s4:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325
David Goodwincfd67652009-08-06 16:52:47 +0000326def tSTRB : T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000327 "strb", " $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000328 [(truncstorei8 tGPR:$src, t_addrmode_s1:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000329
David Goodwincfd67652009-08-06 16:52:47 +0000330def tSTRH : T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000331 "strh", " $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000332 [(truncstorei16 tGPR:$src, t_addrmode_s2:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333
David Goodwincfd67652009-08-06 16:52:47 +0000334def tSTRspi : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000335 "str", " $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000336 [(store tGPR:$src, t_addrmode_sp:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000337
Chris Lattner6887b142008-01-06 08:36:04 +0000338let mayStore = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000339// Special instruction for spill. It cannot clobber condition register
340// when it's expanded by eliminateCallFramePseudoInstr().
David Goodwincfd67652009-08-06 16:52:47 +0000341def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000342 "str", " $src, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343}
344
345//===----------------------------------------------------------------------===//
346// Load / store multiple Instructions.
347//
348
349// TODO: A7-44: LDMIA - load multiple
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000350// TODO: Allow these to be predicated
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000352let mayLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000353def tPOP : T1I<(outs reglist:$dst1, variable_ops), (ins), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354 "pop $dst1", []>;
355
Chris Lattner6887b142008-01-06 08:36:04 +0000356let mayStore = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000357def tPUSH : T1I<(outs), (ins reglist:$src1, variable_ops), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000358 "push $src1", []>;
359
360//===----------------------------------------------------------------------===//
361// Arithmetic Instructions.
362//
363
David Goodwin8768bff2009-06-25 22:49:55 +0000364// Add with carry register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000365let isCommutable = 1, Uses = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000366def tADC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000367 "adc", " $dst, $rhs",
Evan Cheng986e3b72009-07-10 02:09:04 +0000368 [(set tGPR:$dst, (adde tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369
David Goodwin8768bff2009-06-25 22:49:55 +0000370// Add immediate
David Goodwincfd67652009-08-06 16:52:47 +0000371def tADDi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000372 "add", " $dst, $lhs, $rhs",
373 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000374
David Goodwincfd67652009-08-06 16:52:47 +0000375def tADDi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000376 "add", " $dst, $rhs",
377 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000378
David Goodwin8768bff2009-06-25 22:49:55 +0000379// Add register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000380let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000381def tADDrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000382 "add", " $dst, $lhs, $rhs",
383 [(set tGPR:$dst, (add tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384
Evan Chengd97d7142009-06-12 20:46:18 +0000385let neverHasSideEffects = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000386def tADDhirr : T1pIt<(outs tGPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000387 "add", " $dst, $rhs @ addhirr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000388
David Goodwin8768bff2009-06-25 22:49:55 +0000389// And register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000390let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000391def tAND : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000392 "and", " $dst, $rhs",
393 [(set tGPR:$dst, (and tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394
David Goodwin8768bff2009-06-25 22:49:55 +0000395// ASR immediate
David Goodwincfd67652009-08-06 16:52:47 +0000396def tASRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000397 "asr", " $dst, $lhs, $rhs",
398 [(set tGPR:$dst, (sra tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000399
David Goodwin8768bff2009-06-25 22:49:55 +0000400// ASR register
David Goodwincfd67652009-08-06 16:52:47 +0000401def tASRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000402 "asr", " $dst, $rhs",
403 [(set tGPR:$dst, (sra tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000404
David Goodwin8768bff2009-06-25 22:49:55 +0000405// BIC register
David Goodwincfd67652009-08-06 16:52:47 +0000406def tBIC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000407 "bic", " $dst, $rhs",
408 [(set tGPR:$dst, (and tGPR:$lhs, (not tGPR:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409
David Goodwin8768bff2009-06-25 22:49:55 +0000410// CMN register
411let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000412def tCMN : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000413 "cmn", " $lhs, $rhs",
414 [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwincfd67652009-08-06 16:52:47 +0000415def tCMNZ : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000416 "cmn", " $lhs, $rhs",
417 [(ARMcmpZ tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000418}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000419
David Goodwin8768bff2009-06-25 22:49:55 +0000420// CMP immediate
421let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000422def tCMPi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000423 "cmp", " $lhs, $rhs",
424 [(ARMcmp tGPR:$lhs, imm0_255:$rhs)]>;
David Goodwincfd67652009-08-06 16:52:47 +0000425def tCMPZi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000426 "cmp", " $lhs, $rhs",
427 [(ARMcmpZ tGPR:$lhs, imm0_255:$rhs)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428
David Goodwin8768bff2009-06-25 22:49:55 +0000429}
430
431// CMP register
432let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000433def tCMPr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000434 "cmp", " $lhs, $rhs",
435 [(ARMcmp tGPR:$lhs, tGPR:$rhs)]>;
David Goodwincfd67652009-08-06 16:52:47 +0000436def tCMPZr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000437 "cmp", " $lhs, $rhs",
438 [(ARMcmpZ tGPR:$lhs, tGPR:$rhs)]>;
439
440// TODO: Make use of the followings cmp hi regs
David Goodwincfd67652009-08-06 16:52:47 +0000441def tCMPhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000442 "cmp", " $lhs, $rhs", []>;
David Goodwincfd67652009-08-06 16:52:47 +0000443def tCMPZhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000444 "cmp", " $lhs, $rhs", []>;
David Goodwin8768bff2009-06-25 22:49:55 +0000445}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447
David Goodwin8768bff2009-06-25 22:49:55 +0000448// XOR register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000449let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000450def tEOR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000451 "eor", " $dst, $rhs",
452 [(set tGPR:$dst, (xor tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453
David Goodwin8768bff2009-06-25 22:49:55 +0000454// LSL immediate
David Goodwincfd67652009-08-06 16:52:47 +0000455def tLSLri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000456 "lsl", " $dst, $lhs, $rhs",
457 [(set tGPR:$dst, (shl tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458
David Goodwin8768bff2009-06-25 22:49:55 +0000459// LSL register
David Goodwincfd67652009-08-06 16:52:47 +0000460def tLSLrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000461 "lsl", " $dst, $rhs",
462 [(set tGPR:$dst, (shl tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463
David Goodwin8768bff2009-06-25 22:49:55 +0000464// LSR immediate
David Goodwincfd67652009-08-06 16:52:47 +0000465def tLSRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000466 "lsr", " $dst, $lhs, $rhs",
467 [(set tGPR:$dst, (srl tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000468
David Goodwin8768bff2009-06-25 22:49:55 +0000469// LSR register
David Goodwincfd67652009-08-06 16:52:47 +0000470def tLSRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000471 "lsr", " $dst, $rhs",
472 [(set tGPR:$dst, (srl tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473
David Goodwin8768bff2009-06-25 22:49:55 +0000474// move register
David Goodwincfd67652009-08-06 16:52:47 +0000475def tMOVi8 : T1sI<(outs tGPR:$dst), (ins i32imm:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000476 "mov", " $dst, $src",
477 [(set tGPR:$dst, imm0_255:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478
479// TODO: A7-73: MOV(2) - mov setting flag.
480
481
Evan Chengd97d7142009-06-12 20:46:18 +0000482let neverHasSideEffects = 1 in {
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000483// FIXME: Make this predicable.
David Goodwincfd67652009-08-06 16:52:47 +0000484def tMOVr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000485 "mov $dst, $src", []>;
486let Defs = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000487def tMOVSr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000488 "movs $dst, $src", []>;
489
490// FIXME: Make these predicable.
David Goodwincfd67652009-08-06 16:52:47 +0000491def tMOVgpr2tgpr : T1I<(outs tGPR:$dst), (ins GPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000492 "mov $dst, $src\t@ hir2lor", []>;
David Goodwincfd67652009-08-06 16:52:47 +0000493def tMOVtgpr2gpr : T1I<(outs GPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000494 "mov $dst, $src\t@ lor2hir", []>;
David Goodwincfd67652009-08-06 16:52:47 +0000495def tMOVgpr2gpr : T1I<(outs GPR:$dst), (ins GPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000496 "mov $dst, $src\t@ hir2hir", []>;
Evan Chengd97d7142009-06-12 20:46:18 +0000497} // neverHasSideEffects
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498
David Goodwin8768bff2009-06-25 22:49:55 +0000499// multiply register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000500let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000501def tMUL : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000502 "mul", " $dst, $rhs",
503 [(set tGPR:$dst, (mul tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504
David Goodwin8768bff2009-06-25 22:49:55 +0000505// move inverse register
David Goodwincfd67652009-08-06 16:52:47 +0000506def tMVN : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000507 "mvn", " $dst, $src",
508 [(set tGPR:$dst, (not tGPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509
David Goodwin8768bff2009-06-25 22:49:55 +0000510// bitwise or register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000511let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000512def tORR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000513 "orr", " $dst, $rhs",
514 [(set tGPR:$dst, (or tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515
David Goodwin8768bff2009-06-25 22:49:55 +0000516// swaps
David Goodwincfd67652009-08-06 16:52:47 +0000517def tREV : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000518 "rev", " $dst, $src",
519 [(set tGPR:$dst, (bswap tGPR:$src))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000520 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521
David Goodwincfd67652009-08-06 16:52:47 +0000522def tREV16 : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000523 "rev16", " $dst, $src",
524 [(set tGPR:$dst,
525 (or (and (srl tGPR:$src, (i32 8)), 0xFF),
526 (or (and (shl tGPR:$src, (i32 8)), 0xFF00),
527 (or (and (srl tGPR:$src, (i32 8)), 0xFF0000),
528 (and (shl tGPR:$src, (i32 8)), 0xFF000000)))))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000529 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530
David Goodwincfd67652009-08-06 16:52:47 +0000531def tREVSH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000532 "revsh", " $dst, $src",
533 [(set tGPR:$dst,
534 (sext_inreg
535 (or (srl (and tGPR:$src, 0xFFFF), (i32 8)),
536 (shl tGPR:$src, (i32 8))), i16))]>,
537 Requires<[IsThumb1Only, HasV6]>;
538
David Goodwin8768bff2009-06-25 22:49:55 +0000539// rotate right register
David Goodwincfd67652009-08-06 16:52:47 +0000540def tROR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000541 "ror", " $dst, $rhs",
542 [(set tGPR:$dst, (rotr tGPR:$lhs, tGPR:$rhs))]>;
543
544// negate register
David Goodwincfd67652009-08-06 16:52:47 +0000545def tRSB : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000546 "rsb", " $dst, $src, #0",
547 [(set tGPR:$dst, (ineg tGPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548
David Goodwin8768bff2009-06-25 22:49:55 +0000549// Subtract with carry register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000550let Uses = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000551def tSBC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000552 "sbc", " $dst, $rhs",
553 [(set tGPR:$dst, (sube tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000554
David Goodwin8768bff2009-06-25 22:49:55 +0000555// Subtract immediate
David Goodwincfd67652009-08-06 16:52:47 +0000556def tSUBi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000557 "sub", " $dst, $lhs, $rhs",
558 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7_neg:$rhs))]>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000559
David Goodwincfd67652009-08-06 16:52:47 +0000560def tSUBi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000561 "sub", " $dst, $rhs",
562 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255_neg:$rhs))]>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000563
David Goodwin8768bff2009-06-25 22:49:55 +0000564// subtract register
David Goodwincfd67652009-08-06 16:52:47 +0000565def tSUBrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000566 "sub", " $dst, $lhs, $rhs",
567 [(set tGPR:$dst, (sub tGPR:$lhs, tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000568
569// TODO: A7-96: STMIA - store multiple.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570
David Goodwin8768bff2009-06-25 22:49:55 +0000571// sign-extend byte
David Goodwincfd67652009-08-06 16:52:47 +0000572def tSXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000573 "sxtb", " $dst, $src",
574 [(set tGPR:$dst, (sext_inreg tGPR:$src, i8))]>,
575 Requires<[IsThumb1Only, HasV6]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000576
577// sign-extend short
David Goodwincfd67652009-08-06 16:52:47 +0000578def tSXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000579 "sxth", " $dst, $src",
580 [(set tGPR:$dst, (sext_inreg tGPR:$src, i16))]>,
581 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582
David Goodwin8768bff2009-06-25 22:49:55 +0000583// test
Evan Cheng138f60e2009-06-26 00:19:07 +0000584let isCommutable = 1, Defs = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000585def tTST : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000586 "tst", " $lhs, $rhs",
587 [(ARMcmpZ (and tGPR:$lhs, tGPR:$rhs), 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588
David Goodwin8768bff2009-06-25 22:49:55 +0000589// zero-extend byte
David Goodwincfd67652009-08-06 16:52:47 +0000590def tUXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000591 "uxtb", " $dst, $src",
592 [(set tGPR:$dst, (and tGPR:$src, 0xFF))]>,
593 Requires<[IsThumb1Only, HasV6]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000594
595// zero-extend short
David Goodwincfd67652009-08-06 16:52:47 +0000596def tUXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000597 "uxth", " $dst, $src",
598 [(set tGPR:$dst, (and tGPR:$src, 0xFFFF))]>,
599 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000600
601
602// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
603// Expanded by the scheduler into a branch sequence.
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000604// FIXME: Add actual movcc in IT blocks for Thumb2.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000605let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
606 def tMOVCCr :
David Goodwincfd67652009-08-06 16:52:47 +0000607 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc), IIC_iALU,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608 "@ tMOVCCr $cc",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000609 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000610
611// tLEApcrel - Load a pc-relative address into a register without offending the
612// assembler.
David Goodwincfd67652009-08-06 16:52:47 +0000613def tLEApcrel : T1I<(outs tGPR:$dst), (ins i32imm:$label), IIC_iALU,
Evan Cheng6683bb62009-07-23 18:26:03 +0000614 "adr $dst, #$label", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615
David Goodwincfd67652009-08-06 16:52:47 +0000616def tLEApcrelJT : T1I<(outs tGPR:$dst), (ins i32imm:$label, i32imm:$id), IIC_iALU,
Evan Cheng6683bb62009-07-23 18:26:03 +0000617 "adr $dst, #${label}_${id:no_hash}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618
619//===----------------------------------------------------------------------===//
620// TLS Instructions
621//
622
623// __aeabi_read_tp preserves the registers r1-r3.
624let isCall = 1,
625 Defs = [R0, LR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000626 def tTPsoft : TIx2<(outs), (ins), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 "bl __aeabi_read_tp",
628 [(set R0, ARMthread_pointer)]>;
629}
630
631//===----------------------------------------------------------------------===//
632// Non-Instruction Patterns
633//
634
Evan Cheng986e3b72009-07-10 02:09:04 +0000635// Add with carry
David Goodwin27c016b2009-07-27 19:59:26 +0000636def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
637 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
638def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
639 (tADDi3 tGPR:$lhs, imm8_255:$rhs)>;
640def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
641 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng986e3b72009-07-10 02:09:04 +0000642
643// Subtract with carry
David Goodwin27c016b2009-07-27 19:59:26 +0000644def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
645 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
646def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
647 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
648def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
649 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng986e3b72009-07-10 02:09:04 +0000650
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651// ConstantPool, GlobalAddress
David Goodwin27c016b2009-07-27 19:59:26 +0000652def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
653def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654
655// JumpTable
David Goodwin27c016b2009-07-27 19:59:26 +0000656def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
657 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658
659// Direct calls
Evan Cheng9e734482009-07-29 21:26:42 +0000660def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000661 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000662def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000663 Requires<[IsThumb, IsDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000664
665def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000666 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000667def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000668 Requires<[IsThumb, HasV5T, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669
670// Indirect calls to ARM routines
Evan Cheng68e4b582009-08-01 00:16:10 +0000671def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
672 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
673def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
674 Requires<[IsThumb, HasV5T, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000675
676// zextload i1 -> zextload i8
Evan Cheng503be112009-06-30 02:15:48 +0000677def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
678 (tLDRB t_addrmode_s1:$addr)>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000679
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680// extload -> zextload
Evan Cheng503be112009-06-30 02:15:48 +0000681def : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
682def : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
683def : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000684
Evan Cheng76aeed32009-07-11 07:08:13 +0000685// If it's possible to use [r,r] address mode for sextload, select to
686// ldr{b|h} + sxt{b|h} instead.
Evan Cheng58fec0c2009-07-21 18:15:26 +0000687def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
688 (tSXTB (tLDRB t_addrmode_s1:$addr))>;
689def : T1Pat<(sextloadi16 t_addrmode_s2:$addr),
690 (tSXTH (tLDRH t_addrmode_s2:$addr))>;
Evan Cheng76aeed32009-07-11 07:08:13 +0000691
692
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000693// Large immediate handling.
694
695// Two piece imms.
Evan Cheng19bb7c72009-06-27 02:26:13 +0000696def : T1Pat<(i32 thumb_immshifted:$src),
697 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
698 (thumb_immshifted_shamt imm:$src))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000699
Evan Cheng19bb7c72009-06-27 02:26:13 +0000700def : T1Pat<(i32 imm0_255_comp:$src),
701 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;