blob: f8772476f876661173ce4f9f8b9af2234f58dde2 [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, [{
Owen Anderson36e3a6e2009-08-11 20:47:22 +000022 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023}]>;
24def imm_comp_XFORM : SDNodeXForm<imm, [{
Owen Anderson36e3a6e2009-08-11 20:47:22 +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());
Owen Anderson36e3a6e2009-08-11 20:47:22 +000061 return CurDAG->getTargetConstant(V, MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062}]>;
63
64def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000065 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson36e3a6e2009-08-11 20:47:22 +000066 return CurDAG->getTargetConstant(V, MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067}]>;
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 Cheng94958142009-08-11 21:11:32 +0000184let isReturn = 1, isTerminator = 1, mayLoad = 1 in
185def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$dst1, variable_ops), IIC_Br,
186 "pop${p} $dst1", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187
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
Evan Cheng94958142009-08-11 21:11:32 +0000350// These requires base address to be written back or one of the loaded regs.
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000351let mayLoad = 1 in
Evan Cheng94958142009-08-11 21:11:32 +0000352def tLDM : T1I<(outs),
353 (ins addrmode4:$addr, pred:$p, reglist:$dst1, variable_ops),
354 IIC_iLoad,
355 "ldm${addr:submode}${p} $addr, $dst1", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356
Chris Lattner6887b142008-01-06 08:36:04 +0000357let mayStore = 1 in
Evan Cheng94958142009-08-11 21:11:32 +0000358def tSTM : T1I<(outs),
359 (ins addrmode4:$addr, pred:$p, reglist:$src1, variable_ops),
360 IIC_iStore,
361 "stm${addr:submode}${p} $addr, $src1", []>;
362
363let mayLoad = 1, Uses = [SP], Defs = [SP] in
364def tPOP : T1I<(outs), (ins pred:$p, reglist:$dst1, variable_ops), IIC_Br,
365 "pop${p} $dst1", []>;
366
367let mayStore = 1, Uses = [SP], Defs = [SP] in
368def tPUSH : T1I<(outs), (ins pred:$p, reglist:$src1, variable_ops), IIC_Br,
369 "push${p} $src1", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370
371//===----------------------------------------------------------------------===//
372// Arithmetic Instructions.
373//
374
David Goodwin8768bff2009-06-25 22:49:55 +0000375// Add with carry register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000376let isCommutable = 1, Uses = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000377def tADC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000378 "adc", " $dst, $rhs",
Evan Cheng986e3b72009-07-10 02:09:04 +0000379 [(set tGPR:$dst, (adde tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380
David Goodwin8768bff2009-06-25 22:49:55 +0000381// Add immediate
David Goodwincfd67652009-08-06 16:52:47 +0000382def tADDi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000383 "add", " $dst, $lhs, $rhs",
384 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385
David Goodwincfd67652009-08-06 16:52:47 +0000386def tADDi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000387 "add", " $dst, $rhs",
388 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389
David Goodwin8768bff2009-06-25 22:49:55 +0000390// Add register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000391let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000392def tADDrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000393 "add", " $dst, $lhs, $rhs",
394 [(set tGPR:$dst, (add tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395
Evan Chengd97d7142009-06-12 20:46:18 +0000396let neverHasSideEffects = 1 in
Evan Chenga42214a2009-08-08 03:19:44 +0000397def tADDhirr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000398 "add", " $dst, $rhs @ addhirr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000399
David Goodwin8768bff2009-06-25 22:49:55 +0000400// And register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000401let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000402def tAND : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000403 "and", " $dst, $rhs",
404 [(set tGPR:$dst, (and tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405
David Goodwin8768bff2009-06-25 22:49:55 +0000406// ASR immediate
David Goodwincfd67652009-08-06 16:52:47 +0000407def tASRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000408 "asr", " $dst, $lhs, $rhs",
409 [(set tGPR:$dst, (sra tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410
David Goodwin8768bff2009-06-25 22:49:55 +0000411// ASR register
David Goodwincfd67652009-08-06 16:52:47 +0000412def tASRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000413 "asr", " $dst, $rhs",
414 [(set tGPR:$dst, (sra tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415
David Goodwin8768bff2009-06-25 22:49:55 +0000416// BIC register
David Goodwincfd67652009-08-06 16:52:47 +0000417def tBIC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000418 "bic", " $dst, $rhs",
419 [(set tGPR:$dst, (and tGPR:$lhs, (not tGPR:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420
David Goodwin8768bff2009-06-25 22:49:55 +0000421// CMN register
422let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000423def tCMN : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000424 "cmn", " $lhs, $rhs",
425 [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwincfd67652009-08-06 16:52:47 +0000426def tCMNZ : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000427 "cmn", " $lhs, $rhs",
428 [(ARMcmpZ tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000429}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000430
David Goodwin8768bff2009-06-25 22:49:55 +0000431// CMP immediate
432let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000433def tCMPi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000434 "cmp", " $lhs, $rhs",
435 [(ARMcmp tGPR:$lhs, imm0_255:$rhs)]>;
Evan Cheng6dadbee2009-08-10 02:37:24 +0000436def tCMPzi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000437 "cmp", " $lhs, $rhs",
438 [(ARMcmpZ tGPR:$lhs, imm0_255:$rhs)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439
David Goodwin8768bff2009-06-25 22:49:55 +0000440}
441
442// CMP register
443let Defs = [CPSR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000444def tCMPr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000445 "cmp", " $lhs, $rhs",
446 [(ARMcmp tGPR:$lhs, tGPR:$rhs)]>;
Evan Cheng6dadbee2009-08-10 02:37:24 +0000447def tCMPzr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000448 "cmp", " $lhs, $rhs",
449 [(ARMcmpZ tGPR:$lhs, tGPR:$rhs)]>;
450
David Goodwincfd67652009-08-06 16:52:47 +0000451def tCMPhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000452 "cmp", " $lhs, $rhs", []>;
Evan Cheng6dadbee2009-08-10 02:37:24 +0000453def tCMPzhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000454 "cmp", " $lhs, $rhs", []>;
David Goodwin8768bff2009-06-25 22:49:55 +0000455}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457
David Goodwin8768bff2009-06-25 22:49:55 +0000458// XOR register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000459let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000460def tEOR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000461 "eor", " $dst, $rhs",
462 [(set tGPR:$dst, (xor tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463
David Goodwin8768bff2009-06-25 22:49:55 +0000464// LSL immediate
David Goodwincfd67652009-08-06 16:52:47 +0000465def tLSLri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000466 "lsl", " $dst, $lhs, $rhs",
467 [(set tGPR:$dst, (shl tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000468
David Goodwin8768bff2009-06-25 22:49:55 +0000469// LSL register
David Goodwincfd67652009-08-06 16:52:47 +0000470def tLSLrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000471 "lsl", " $dst, $rhs",
472 [(set tGPR:$dst, (shl tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473
David Goodwin8768bff2009-06-25 22:49:55 +0000474// LSR immediate
David Goodwincfd67652009-08-06 16:52:47 +0000475def tLSRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000476 "lsr", " $dst, $lhs, $rhs",
477 [(set tGPR:$dst, (srl tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478
David Goodwin8768bff2009-06-25 22:49:55 +0000479// LSR register
David Goodwincfd67652009-08-06 16:52:47 +0000480def tLSRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000481 "lsr", " $dst, $rhs",
482 [(set tGPR:$dst, (srl tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483
David Goodwin8768bff2009-06-25 22:49:55 +0000484// move register
David Goodwincfd67652009-08-06 16:52:47 +0000485def tMOVi8 : T1sI<(outs tGPR:$dst), (ins i32imm:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000486 "mov", " $dst, $src",
487 [(set tGPR:$dst, imm0_255:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000488
489// TODO: A7-73: MOV(2) - mov setting flag.
490
491
Evan Chengd97d7142009-06-12 20:46:18 +0000492let neverHasSideEffects = 1 in {
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000493// FIXME: Make this predicable.
David Goodwincfd67652009-08-06 16:52:47 +0000494def tMOVr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000495 "mov $dst, $src", []>;
496let Defs = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000497def tMOVSr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000498 "movs $dst, $src", []>;
499
500// FIXME: Make these predicable.
David Goodwincfd67652009-08-06 16:52:47 +0000501def tMOVgpr2tgpr : T1I<(outs tGPR:$dst), (ins GPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000502 "mov $dst, $src\t@ hir2lor", []>;
David Goodwincfd67652009-08-06 16:52:47 +0000503def tMOVtgpr2gpr : T1I<(outs GPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000504 "mov $dst, $src\t@ lor2hir", []>;
David Goodwincfd67652009-08-06 16:52:47 +0000505def tMOVgpr2gpr : T1I<(outs GPR:$dst), (ins GPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000506 "mov $dst, $src\t@ hir2hir", []>;
Evan Chengd97d7142009-06-12 20:46:18 +0000507} // neverHasSideEffects
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508
David Goodwin8768bff2009-06-25 22:49:55 +0000509// multiply register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000510let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000511def tMUL : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000512 "mul", " $dst, $rhs",
513 [(set tGPR:$dst, (mul tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000514
David Goodwin8768bff2009-06-25 22:49:55 +0000515// move inverse register
David Goodwincfd67652009-08-06 16:52:47 +0000516def tMVN : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000517 "mvn", " $dst, $src",
518 [(set tGPR:$dst, (not tGPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000519
David Goodwin8768bff2009-06-25 22:49:55 +0000520// bitwise or register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000521let isCommutable = 1 in
David Goodwincfd67652009-08-06 16:52:47 +0000522def tORR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000523 "orr", " $dst, $rhs",
524 [(set tGPR:$dst, (or tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000525
David Goodwin8768bff2009-06-25 22:49:55 +0000526// swaps
David Goodwincfd67652009-08-06 16:52:47 +0000527def tREV : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000528 "rev", " $dst, $src",
529 [(set tGPR:$dst, (bswap tGPR:$src))]>,
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 tREV16 : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000533 "rev16", " $dst, $src",
534 [(set tGPR:$dst,
535 (or (and (srl tGPR:$src, (i32 8)), 0xFF),
536 (or (and (shl tGPR:$src, (i32 8)), 0xFF00),
537 (or (and (srl tGPR:$src, (i32 8)), 0xFF0000),
538 (and (shl tGPR:$src, (i32 8)), 0xFF000000)))))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000539 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000540
David Goodwincfd67652009-08-06 16:52:47 +0000541def tREVSH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000542 "revsh", " $dst, $src",
543 [(set tGPR:$dst,
544 (sext_inreg
545 (or (srl (and tGPR:$src, 0xFFFF), (i32 8)),
546 (shl tGPR:$src, (i32 8))), i16))]>,
547 Requires<[IsThumb1Only, HasV6]>;
548
David Goodwin8768bff2009-06-25 22:49:55 +0000549// rotate right register
David Goodwincfd67652009-08-06 16:52:47 +0000550def tROR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000551 "ror", " $dst, $rhs",
552 [(set tGPR:$dst, (rotr tGPR:$lhs, tGPR:$rhs))]>;
553
554// negate register
David Goodwincfd67652009-08-06 16:52:47 +0000555def tRSB : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000556 "rsb", " $dst, $src, #0",
557 [(set tGPR:$dst, (ineg tGPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558
David Goodwin8768bff2009-06-25 22:49:55 +0000559// Subtract with carry register
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000560let Uses = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000561def tSBC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000562 "sbc", " $dst, $rhs",
563 [(set tGPR:$dst, (sube tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564
David Goodwin8768bff2009-06-25 22:49:55 +0000565// Subtract immediate
David Goodwincfd67652009-08-06 16:52:47 +0000566def tSUBi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000567 "sub", " $dst, $lhs, $rhs",
568 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7_neg:$rhs))]>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000569
David Goodwincfd67652009-08-06 16:52:47 +0000570def tSUBi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000571 "sub", " $dst, $rhs",
572 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255_neg:$rhs))]>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000573
David Goodwin8768bff2009-06-25 22:49:55 +0000574// subtract register
David Goodwincfd67652009-08-06 16:52:47 +0000575def tSUBrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000576 "sub", " $dst, $lhs, $rhs",
577 [(set tGPR:$dst, (sub tGPR:$lhs, tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000578
579// TODO: A7-96: STMIA - store multiple.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000580
David Goodwin8768bff2009-06-25 22:49:55 +0000581// sign-extend byte
David Goodwincfd67652009-08-06 16:52:47 +0000582def tSXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000583 "sxtb", " $dst, $src",
584 [(set tGPR:$dst, (sext_inreg tGPR:$src, i8))]>,
585 Requires<[IsThumb1Only, HasV6]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000586
587// sign-extend short
David Goodwincfd67652009-08-06 16:52:47 +0000588def tSXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000589 "sxth", " $dst, $src",
590 [(set tGPR:$dst, (sext_inreg tGPR:$src, i16))]>,
591 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592
David Goodwin8768bff2009-06-25 22:49:55 +0000593// test
Evan Cheng138f60e2009-06-26 00:19:07 +0000594let isCommutable = 1, Defs = [CPSR] in
David Goodwincfd67652009-08-06 16:52:47 +0000595def tTST : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000596 "tst", " $lhs, $rhs",
597 [(ARMcmpZ (and tGPR:$lhs, tGPR:$rhs), 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598
David Goodwin8768bff2009-06-25 22:49:55 +0000599// zero-extend byte
David Goodwincfd67652009-08-06 16:52:47 +0000600def tUXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000601 "uxtb", " $dst, $src",
602 [(set tGPR:$dst, (and tGPR:$src, 0xFF))]>,
603 Requires<[IsThumb1Only, HasV6]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000604
605// zero-extend short
David Goodwincfd67652009-08-06 16:52:47 +0000606def tUXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALU,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000607 "uxth", " $dst, $src",
608 [(set tGPR:$dst, (and tGPR:$src, 0xFFFF))]>,
609 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000610
611
612// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
613// Expanded by the scheduler into a branch sequence.
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000614// FIXME: Add actual movcc in IT blocks for Thumb2.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
616 def tMOVCCr :
David Goodwincfd67652009-08-06 16:52:47 +0000617 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc), IIC_iALU,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618 "@ tMOVCCr $cc",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000619 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620
621// tLEApcrel - Load a pc-relative address into a register without offending the
622// assembler.
David Goodwincfd67652009-08-06 16:52:47 +0000623def tLEApcrel : T1I<(outs tGPR:$dst), (ins i32imm:$label), IIC_iALU,
Evan Cheng6683bb62009-07-23 18:26:03 +0000624 "adr $dst, #$label", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000625
Anton Korobeynikove2be3382009-08-08 23:10:41 +0000626def tLEApcrelJT : T1I<(outs tGPR:$dst), (ins i32imm:$label, lane_cst:$id), IIC_iALU,
627 "adr $dst, #${label}_${id}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000628
629//===----------------------------------------------------------------------===//
630// TLS Instructions
631//
632
633// __aeabi_read_tp preserves the registers r1-r3.
634let isCall = 1,
635 Defs = [R0, LR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000636 def tTPsoft : TIx2<(outs), (ins), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000637 "bl __aeabi_read_tp",
638 [(set R0, ARMthread_pointer)]>;
639}
640
641//===----------------------------------------------------------------------===//
642// Non-Instruction Patterns
643//
644
Evan Cheng986e3b72009-07-10 02:09:04 +0000645// Add with carry
David Goodwin27c016b2009-07-27 19:59:26 +0000646def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
647 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
648def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
649 (tADDi3 tGPR:$lhs, imm8_255:$rhs)>;
650def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
651 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng986e3b72009-07-10 02:09:04 +0000652
653// Subtract with carry
David Goodwin27c016b2009-07-27 19:59:26 +0000654def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
655 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
656def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
657 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
658def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
659 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng986e3b72009-07-10 02:09:04 +0000660
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000661// ConstantPool, GlobalAddress
David Goodwin27c016b2009-07-27 19:59:26 +0000662def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
663def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000664
665// JumpTable
David Goodwin27c016b2009-07-27 19:59:26 +0000666def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
667 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000668
669// Direct calls
Evan Cheng9e734482009-07-29 21:26:42 +0000670def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000671 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000672def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000673 Requires<[IsThumb, IsDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000674
675def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000676 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000677def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000678 Requires<[IsThumb, HasV5T, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000679
680// Indirect calls to ARM routines
Evan Cheng68e4b582009-08-01 00:16:10 +0000681def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
682 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
683def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
684 Requires<[IsThumb, HasV5T, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000685
686// zextload i1 -> zextload i8
Evan Cheng503be112009-06-30 02:15:48 +0000687def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
688 (tLDRB t_addrmode_s1:$addr)>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000689
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690// extload -> zextload
Evan Cheng503be112009-06-30 02:15:48 +0000691def : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
692def : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
693def : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694
Evan Cheng76aeed32009-07-11 07:08:13 +0000695// If it's possible to use [r,r] address mode for sextload, select to
696// ldr{b|h} + sxt{b|h} instead.
Evan Cheng58fec0c2009-07-21 18:15:26 +0000697def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
698 (tSXTB (tLDRB t_addrmode_s1:$addr))>;
699def : T1Pat<(sextloadi16 t_addrmode_s2:$addr),
700 (tSXTH (tLDRH t_addrmode_s2:$addr))>;
Evan Cheng76aeed32009-07-11 07:08:13 +0000701
702
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000703// Large immediate handling.
704
705// Two piece imms.
Evan Cheng19bb7c72009-06-27 02:26:13 +0000706def : T1Pat<(i32 thumb_immshifted:$src),
707 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
708 (thumb_immshifted_shamt imm:$src))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000709
Evan Cheng19bb7c72009-06-27 02:26:13 +0000710def : T1Pat<(i32 imm0_255_comp:$src),
711 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;