blob: c6c02ea6a9e941070993baf1180aca3cc4b1cf2d [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
Evan Chengd6053af2009-08-07 05:45:07 +0000256 let Defs = [LR] in
David Goodwincfd67652009-08-06 16:52:47 +0000257 def tBfar : TIx2<(outs), (ins brtarget:$target), IIC_Br,
David Goodwinf6154702009-06-30 18:04:13 +0000258 "bl $target\t@ far jump",[]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259
David Goodwinf6154702009-06-30 18:04:13 +0000260 def tBR_JTr : T1JTI<(outs),
261 (ins tGPR:$target, jtblock_operand:$jt, i32imm:$id),
David Goodwincfd67652009-08-06 16:52:47 +0000262 IIC_Br, "mov pc, $target\n\t.align\t2\n$jt",
David Goodwinf6154702009-06-30 18:04:13 +0000263 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264 }
265}
266
267// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach7ea52762009-03-27 23:06:27 +0000268// a two-value operand where a dag node expects two operands. :(
Evan Cheng37e7c752007-07-21 00:34:19 +0000269let isBranch = 1, isTerminator = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000270 def tBcc : T1I<(outs), (ins brtarget:$target, pred:$cc), IIC_Br,
271 "b$cc $target",
Evan Chengb783fa32007-07-19 01:14:50 +0000272 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273
274//===----------------------------------------------------------------------===//
275// Load Store Instructions.
276//
277
Dan Gohman5574cc72008-12-03 18:15:48 +0000278let canFoldAsLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000279def tLDR : T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000280 "ldr", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000281 [(set tGPR:$dst, (load t_addrmode_s4:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282
David Goodwincfd67652009-08-06 16:52:47 +0000283def tLDRB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000284 "ldrb", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000285 [(set tGPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286
David Goodwincfd67652009-08-06 16:52:47 +0000287def tLDRH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000288 "ldrh", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000289 [(set tGPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000290
Evan Cheng76aeed32009-07-11 07:08:13 +0000291let AddedComplexity = 10 in
David Goodwincfd67652009-08-06 16:52:47 +0000292def tLDRSB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000293 "ldrsb", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000294 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000295
Evan Cheng76aeed32009-07-11 07:08:13 +0000296let AddedComplexity = 10 in
David Goodwincfd67652009-08-06 16:52:47 +0000297def tLDRSH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000298 "ldrsh", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000299 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300
Dan Gohman5574cc72008-12-03 18:15:48 +0000301let canFoldAsLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000302def tLDRspi : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000303 "ldr", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000304 [(set tGPR:$dst, (load t_addrmode_sp:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000305
306// Special instruction for restore. It cannot clobber condition register
307// when it's expanded by eliminateCallFramePseudoInstr().
Dan Gohman5574cc72008-12-03 18:15:48 +0000308let canFoldAsLoad = 1, mayLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000309def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000310 "ldr", " $dst, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311
312// Load tconstpool
Dan Gohman5574cc72008-12-03 18:15:48 +0000313let canFoldAsLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000314def tLDRpci : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000315 "ldr", " $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000316 [(set tGPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317
318// Special LDR for loads from non-pc-relative constpools.
Dan Gohman5574cc72008-12-03 18:15:48 +0000319let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000320def tLDRcp : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoad,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000321 "ldr", " $dst, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322
David Goodwincfd67652009-08-06 16:52:47 +0000323def tSTR : T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000324 "str", " $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000325 [(store tGPR:$src, t_addrmode_s4:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326
David Goodwincfd67652009-08-06 16:52:47 +0000327def tSTRB : T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000328 "strb", " $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000329 [(truncstorei8 tGPR:$src, t_addrmode_s1:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330
David Goodwincfd67652009-08-06 16:52:47 +0000331def tSTRH : T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000332 "strh", " $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000333 [(truncstorei16 tGPR:$src, t_addrmode_s2:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334
David Goodwincfd67652009-08-06 16:52:47 +0000335def tSTRspi : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000336 "str", " $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000337 [(store tGPR:$src, t_addrmode_sp:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338
Chris Lattner6887b142008-01-06 08:36:04 +0000339let mayStore = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340// Special instruction for spill. It cannot clobber condition register
341// when it's expanded by eliminateCallFramePseudoInstr().
David Goodwincfd67652009-08-06 16:52:47 +0000342def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000343 "str", " $src, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000344}
345
346//===----------------------------------------------------------------------===//
347// Load / store multiple Instructions.
348//
349
350// TODO: A7-44: LDMIA - load multiple
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000351// TODO: Allow these to be predicated
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000353let mayLoad = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000354def tPOP : T1I<(outs reglist:$dst1, variable_ops), (ins), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000355 "pop $dst1", []>;
356
Chris Lattner6887b142008-01-06 08:36:04 +0000357let mayStore = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000358def tPUSH : T1I<(outs), (ins reglist:$src1, variable_ops), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359 "push $src1", []>;
360
361//===----------------------------------------------------------------------===//
362// Arithmetic Instructions.
363//
364
David Goodwin8768bff2009-06-25 22:49:55 +0000365// Add with carry register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000366let isCommutable = 1, Uses = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000367def tADC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000368 "adc", " $dst, $rhs",
Evan Cheng986e3b72009-07-10 02:09:04 +0000369 [(set tGPR:$dst, (adde tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370
David Goodwin8768bff2009-06-25 22:49:55 +0000371// Add immediate
David Goodwincfd67652009-08-06 16:52:47 +0000372def tADDi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000373 "add", " $dst, $lhs, $rhs",
374 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000375
David Goodwincfd67652009-08-06 16:52:47 +0000376def tADDi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000377 "add", " $dst, $rhs",
378 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379
David Goodwin8768bff2009-06-25 22:49:55 +0000380// Add register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000381let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000382def tADDrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000383 "add", " $dst, $lhs, $rhs",
384 [(set tGPR:$dst, (add tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385
Evan Chengd97d7142009-06-12 20:46:18 +0000386let neverHasSideEffects = 1 in
Evan Chenga42214a2009-08-08 03:19:44 +0000387def tADDhirr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000388 "add", " $dst, $rhs @ addhirr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389
David Goodwin8768bff2009-06-25 22:49:55 +0000390// And register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000391let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000392def tAND : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000393 "and", " $dst, $rhs",
394 [(set tGPR:$dst, (and tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395
David Goodwin8768bff2009-06-25 22:49:55 +0000396// ASR immediate
David Goodwincfd67652009-08-06 16:52:47 +0000397def tASRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000398 "asr", " $dst, $lhs, $rhs",
399 [(set tGPR:$dst, (sra tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400
David Goodwin8768bff2009-06-25 22:49:55 +0000401// ASR register
David Goodwincfd67652009-08-06 16:52:47 +0000402def tASRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000403 "asr", " $dst, $rhs",
404 [(set tGPR:$dst, (sra tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405
David Goodwin8768bff2009-06-25 22:49:55 +0000406// BIC register
David Goodwincfd67652009-08-06 16:52:47 +0000407def tBIC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000408 "bic", " $dst, $rhs",
409 [(set tGPR:$dst, (and tGPR:$lhs, (not tGPR:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410
David Goodwin8768bff2009-06-25 22:49:55 +0000411// CMN register
412let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000413def tCMN : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000414 "cmn", " $lhs, $rhs",
415 [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwincfd67652009-08-06 16:52:47 +0000416def tCMNZ : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000417 "cmn", " $lhs, $rhs",
418 [(ARMcmpZ tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000419}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420
David Goodwin8768bff2009-06-25 22:49:55 +0000421// CMP immediate
422let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000423def tCMPi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000424 "cmp", " $lhs, $rhs",
425 [(ARMcmp tGPR:$lhs, imm0_255:$rhs)]>;
David Goodwincfd67652009-08-06 16:52:47 +0000426def tCMPZi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000427 "cmp", " $lhs, $rhs",
428 [(ARMcmpZ tGPR:$lhs, imm0_255:$rhs)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429
David Goodwin8768bff2009-06-25 22:49:55 +0000430}
431
432// CMP register
433let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000434def tCMPr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000435 "cmp", " $lhs, $rhs",
436 [(ARMcmp tGPR:$lhs, tGPR:$rhs)]>;
David Goodwincfd67652009-08-06 16:52:47 +0000437def tCMPZr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000438 "cmp", " $lhs, $rhs",
439 [(ARMcmpZ tGPR:$lhs, tGPR:$rhs)]>;
440
441// TODO: Make use of the followings cmp hi regs
David Goodwincfd67652009-08-06 16:52:47 +0000442def tCMPhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000443 "cmp", " $lhs, $rhs", []>;
David Goodwincfd67652009-08-06 16:52:47 +0000444def tCMPZhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000445 "cmp", " $lhs, $rhs", []>;
David Goodwin8768bff2009-06-25 22:49:55 +0000446}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448
David Goodwin8768bff2009-06-25 22:49:55 +0000449// XOR register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000450let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000451def tEOR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000452 "eor", " $dst, $rhs",
453 [(set tGPR:$dst, (xor tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000454
David Goodwin8768bff2009-06-25 22:49:55 +0000455// LSL immediate
David Goodwincfd67652009-08-06 16:52:47 +0000456def tLSLri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000457 "lsl", " $dst, $lhs, $rhs",
458 [(set tGPR:$dst, (shl tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000459
David Goodwin8768bff2009-06-25 22:49:55 +0000460// LSL register
David Goodwincfd67652009-08-06 16:52:47 +0000461def tLSLrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000462 "lsl", " $dst, $rhs",
463 [(set tGPR:$dst, (shl tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000464
David Goodwin8768bff2009-06-25 22:49:55 +0000465// LSR immediate
David Goodwincfd67652009-08-06 16:52:47 +0000466def tLSRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000467 "lsr", " $dst, $lhs, $rhs",
468 [(set tGPR:$dst, (srl tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469
David Goodwin8768bff2009-06-25 22:49:55 +0000470// LSR register
David Goodwincfd67652009-08-06 16:52:47 +0000471def tLSRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000472 "lsr", " $dst, $rhs",
473 [(set tGPR:$dst, (srl tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474
David Goodwin8768bff2009-06-25 22:49:55 +0000475// move register
David Goodwincfd67652009-08-06 16:52:47 +0000476def tMOVi8 : T1sI<(outs tGPR:$dst), (ins i32imm:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000477 "mov", " $dst, $src",
478 [(set tGPR:$dst, imm0_255:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000479
480// TODO: A7-73: MOV(2) - mov setting flag.
481
482
Evan Chengd97d7142009-06-12 20:46:18 +0000483let neverHasSideEffects = 1 in {
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000484// FIXME: Make this predicable.
David Goodwincfd67652009-08-06 16:52:47 +0000485def tMOVr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000486 "mov $dst, $src", []>;
487let Defs = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000488def tMOVSr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000489 "movs $dst, $src", []>;
490
491// FIXME: Make these predicable.
David Goodwincfd67652009-08-06 16:52:47 +0000492def tMOVgpr2tgpr : T1I<(outs tGPR:$dst), (ins GPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000493 "mov $dst, $src\t@ hir2lor", []>;
David Goodwincfd67652009-08-06 16:52:47 +0000494def tMOVtgpr2gpr : T1I<(outs GPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000495 "mov $dst, $src\t@ lor2hir", []>;
David Goodwincfd67652009-08-06 16:52:47 +0000496def tMOVgpr2gpr : T1I<(outs GPR:$dst), (ins GPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000497 "mov $dst, $src\t@ hir2hir", []>;
Evan Chengd97d7142009-06-12 20:46:18 +0000498} // neverHasSideEffects
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499
David Goodwin8768bff2009-06-25 22:49:55 +0000500// multiply register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000501let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000502def tMUL : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000503 "mul", " $dst, $rhs",
504 [(set tGPR:$dst, (mul tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000505
David Goodwin8768bff2009-06-25 22:49:55 +0000506// move inverse register
David Goodwincfd67652009-08-06 16:52:47 +0000507def tMVN : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000508 "mvn", " $dst, $src",
509 [(set tGPR:$dst, (not tGPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000510
David Goodwin8768bff2009-06-25 22:49:55 +0000511// bitwise or register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000512let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000513def tORR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000514 "orr", " $dst, $rhs",
515 [(set tGPR:$dst, (or tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000516
David Goodwin8768bff2009-06-25 22:49:55 +0000517// swaps
David Goodwincfd67652009-08-06 16:52:47 +0000518def tREV : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000519 "rev", " $dst, $src",
520 [(set tGPR:$dst, (bswap tGPR:$src))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000521 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522
David Goodwincfd67652009-08-06 16:52:47 +0000523def tREV16 : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000524 "rev16", " $dst, $src",
525 [(set tGPR:$dst,
526 (or (and (srl tGPR:$src, (i32 8)), 0xFF),
527 (or (and (shl tGPR:$src, (i32 8)), 0xFF00),
528 (or (and (srl tGPR:$src, (i32 8)), 0xFF0000),
529 (and (shl tGPR:$src, (i32 8)), 0xFF000000)))))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000530 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000531
David Goodwincfd67652009-08-06 16:52:47 +0000532def tREVSH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000533 "revsh", " $dst, $src",
534 [(set tGPR:$dst,
535 (sext_inreg
536 (or (srl (and tGPR:$src, 0xFFFF), (i32 8)),
537 (shl tGPR:$src, (i32 8))), i16))]>,
538 Requires<[IsThumb1Only, HasV6]>;
539
David Goodwin8768bff2009-06-25 22:49:55 +0000540// rotate right register
David Goodwincfd67652009-08-06 16:52:47 +0000541def tROR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000542 "ror", " $dst, $rhs",
543 [(set tGPR:$dst, (rotr tGPR:$lhs, tGPR:$rhs))]>;
544
545// negate register
David Goodwincfd67652009-08-06 16:52:47 +0000546def tRSB : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000547 "rsb", " $dst, $src, #0",
548 [(set tGPR:$dst, (ineg tGPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000549
David Goodwin8768bff2009-06-25 22:49:55 +0000550// Subtract with carry register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000551let Uses = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000552def tSBC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000553 "sbc", " $dst, $rhs",
554 [(set tGPR:$dst, (sube tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555
David Goodwin8768bff2009-06-25 22:49:55 +0000556// Subtract immediate
David Goodwincfd67652009-08-06 16:52:47 +0000557def tSUBi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000558 "sub", " $dst, $lhs, $rhs",
559 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7_neg:$rhs))]>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000560
David Goodwincfd67652009-08-06 16:52:47 +0000561def tSUBi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000562 "sub", " $dst, $rhs",
563 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255_neg:$rhs))]>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000564
David Goodwin8768bff2009-06-25 22:49:55 +0000565// subtract register
David Goodwincfd67652009-08-06 16:52:47 +0000566def tSUBrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000567 "sub", " $dst, $lhs, $rhs",
568 [(set tGPR:$dst, (sub tGPR:$lhs, tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000569
570// TODO: A7-96: STMIA - store multiple.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571
David Goodwin8768bff2009-06-25 22:49:55 +0000572// sign-extend byte
David Goodwincfd67652009-08-06 16:52:47 +0000573def tSXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000574 "sxtb", " $dst, $src",
575 [(set tGPR:$dst, (sext_inreg tGPR:$src, i8))]>,
576 Requires<[IsThumb1Only, HasV6]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000577
578// sign-extend short
David Goodwincfd67652009-08-06 16:52:47 +0000579def tSXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000580 "sxth", " $dst, $src",
581 [(set tGPR:$dst, (sext_inreg tGPR:$src, i16))]>,
582 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000583
David Goodwin8768bff2009-06-25 22:49:55 +0000584// test
Evan Cheng138f60e2009-06-26 00:19:07 +0000585let isCommutable = 1, Defs = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000586def tTST : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000587 "tst", " $lhs, $rhs",
588 [(ARMcmpZ (and tGPR:$lhs, tGPR:$rhs), 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589
David Goodwin8768bff2009-06-25 22:49:55 +0000590// zero-extend byte
David Goodwincfd67652009-08-06 16:52:47 +0000591def tUXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000592 "uxtb", " $dst, $src",
593 [(set tGPR:$dst, (and tGPR:$src, 0xFF))]>,
594 Requires<[IsThumb1Only, HasV6]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000595
596// zero-extend short
David Goodwincfd67652009-08-06 16:52:47 +0000597def tUXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000598 "uxth", " $dst, $src",
599 [(set tGPR:$dst, (and tGPR:$src, 0xFFFF))]>,
600 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601
602
603// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
604// Expanded by the scheduler into a branch sequence.
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000605// FIXME: Add actual movcc in IT blocks for Thumb2.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000606let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
607 def tMOVCCr :
David Goodwincfd67652009-08-06 16:52:47 +0000608 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc), IIC_iALU,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609 "@ tMOVCCr $cc",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000610 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611
612// tLEApcrel - Load a pc-relative address into a register without offending the
613// assembler.
David Goodwincfd67652009-08-06 16:52:47 +0000614def tLEApcrel : T1I<(outs tGPR:$dst), (ins i32imm:$label), IIC_iALU,
Evan Cheng6683bb62009-07-23 18:26:03 +0000615 "adr $dst, #$label", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616
David Goodwincfd67652009-08-06 16:52:47 +0000617def tLEApcrelJT : T1I<(outs tGPR:$dst), (ins i32imm:$label, i32imm:$id), IIC_iALU,
Evan Cheng6683bb62009-07-23 18:26:03 +0000618 "adr $dst, #${label}_${id:no_hash}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000619
620//===----------------------------------------------------------------------===//
621// TLS Instructions
622//
623
624// __aeabi_read_tp preserves the registers r1-r3.
625let isCall = 1,
626 Defs = [R0, LR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000627 def tTPsoft : TIx2<(outs), (ins), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000628 "bl __aeabi_read_tp",
629 [(set R0, ARMthread_pointer)]>;
630}
631
632//===----------------------------------------------------------------------===//
633// Non-Instruction Patterns
634//
635
Evan Cheng986e3b72009-07-10 02:09:04 +0000636// Add with carry
David Goodwin27c016b2009-07-27 19:59:26 +0000637def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
638 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
639def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
640 (tADDi3 tGPR:$lhs, imm8_255:$rhs)>;
641def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
642 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng986e3b72009-07-10 02:09:04 +0000643
644// Subtract with carry
David Goodwin27c016b2009-07-27 19:59:26 +0000645def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
646 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
647def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
648 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
649def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
650 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng986e3b72009-07-10 02:09:04 +0000651
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000652// ConstantPool, GlobalAddress
David Goodwin27c016b2009-07-27 19:59:26 +0000653def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
654def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000655
656// JumpTable
David Goodwin27c016b2009-07-27 19:59:26 +0000657def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
658 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000659
660// Direct calls
Evan Cheng9e734482009-07-29 21:26:42 +0000661def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000662 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000663def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000664 Requires<[IsThumb, IsDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000665
666def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000667 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000668def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000669 Requires<[IsThumb, HasV5T, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000670
671// Indirect calls to ARM routines
Evan Cheng68e4b582009-08-01 00:16:10 +0000672def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
673 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
674def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
675 Requires<[IsThumb, HasV5T, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676
677// zextload i1 -> zextload i8
Evan Cheng503be112009-06-30 02:15:48 +0000678def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
679 (tLDRB t_addrmode_s1:$addr)>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000680
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000681// extload -> zextload
Evan Cheng503be112009-06-30 02:15:48 +0000682def : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
683def : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
684def : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685
Evan Cheng76aeed32009-07-11 07:08:13 +0000686// If it's possible to use [r,r] address mode for sextload, select to
687// ldr{b|h} + sxt{b|h} instead.
Evan Cheng58fec0c2009-07-21 18:15:26 +0000688def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
689 (tSXTB (tLDRB t_addrmode_s1:$addr))>;
690def : T1Pat<(sextloadi16 t_addrmode_s2:$addr),
691 (tSXTH (tLDRH t_addrmode_s2:$addr))>;
Evan Cheng76aeed32009-07-11 07:08:13 +0000692
693
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694// Large immediate handling.
695
696// Two piece imms.
Evan Cheng19bb7c72009-06-27 02:26:13 +0000697def : T1Pat<(i32 thumb_immshifted:$src),
698 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
699 (thumb_immshifted_shamt imm:$src))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000700
Evan Cheng19bb7c72009-06-27 02:26:13 +0000701def : T1Pat<(i32 imm0_255_comp:$src),
702 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;