blob: 7ec4bdef26314e6b8481bfb0fff950a9704e0d79 [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 Goodwin236ccb52009-08-19 18:00:44 +0000132def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr,
Evan Cheng3ab67152009-08-28 06:59:37 +0000133 "\n$cp:\n\tadd $dst, pc",
Evan Chengd16eb2f2009-08-04 23:47:55 +0000134 [(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 Goodwin236ccb52009-08-19 18:00:44 +0000137def tADDrPCi : T1I<(outs tGPR:$dst), (ins i32imm:$rhs), IIC_iALUi,
Evan Chengae2ed1f2009-06-25 01:05:06 +0000138 "add $dst, pc, $rhs * 4", []>;
139
140// ADD rd, sp, #imm8
David Goodwin236ccb52009-08-19 18:00:44 +0000141def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, i32imm:$rhs), IIC_iALUi,
Evan Cheng7b3c2ad2009-09-09 01:38:23 +0000142 "add $dst, $sp, $rhs * 4", []>;
Evan Chengae2ed1f2009-06-25 01:05:06 +0000143
144// ADD sp, sp, #imm7
David Goodwin236ccb52009-08-19 18:00:44 +0000145def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs), IIC_iALUi,
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
David Goodwin236ccb52009-08-19 18:00:44 +0000149def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs), IIC_iALUi,
Evan Cheng815c23a2009-08-07 00:34:42 +0000150 "sub $dst, $rhs * 4", []>;
151
Evan Cheng9deae0b2009-08-11 23:00:31 +0000152// ADD rm, sp
David Goodwin236ccb52009-08-19 18:00:44 +0000153def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Evan Cheng9deae0b2009-08-11 23:00:31 +0000154 "add $dst, $rhs", []>;
Evan Cheng815c23a2009-08-07 00:34:42 +0000155
Evan Chengae2ed1f2009-06-25 01:05:06 +0000156// ADD sp, rm
David Goodwin236ccb52009-08-19 18:00:44 +0000157def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Evan Cheng815c23a2009-08-07 00:34:42 +0000158 "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
Jim Grosbachc6f0c022009-09-30 01:35:11 +0000177let isReturn = 1, isTerminator = 1, isBarrier = 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.
Jim Grosbachc6f0c022009-09-30 01:35:11 +0000184let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1 in
Evan Cheng94958142009-08-11 21:11:32 +0000185def 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,
David Goodwin3d88e912009-09-03 22:12:28 +0000192 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] 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,
David Goodwin3d88e912009-09-03 22:12:28 +0000223 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR] 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,
Evan Cheng08ed20d2009-08-31 20:14:07 +0000253 "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,
Evan Cheng08ed20d2009-08-31 20:14:07 +0000271 "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 Goodwin236ccb52009-08-19 18:00:44 +0000279def tLDR : T1pI4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr), IIC_iLoadr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000283def tLDRB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr), IIC_iLoadr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000287def tLDRH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr), IIC_iLoadr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000292def tLDRSB : T1pI1<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoadr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000297def tLDRSH : T1pI2<(outs tGPR:$dst), (ins t_addrmode_rr:$addr), IIC_iLoadr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000302def tLDRspi : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoadi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000309def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoadi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000314def tLDRpci : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoadi,
Evan Cheng08ed20d2009-08-31 20:14:07 +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 Goodwin236ccb52009-08-19 18:00:44 +0000320def tLDRcp : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoadi,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000321 "ldr", " $dst, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322
David Goodwin236ccb52009-08-19 18:00:44 +0000323def tSTR : T1pI4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr), IIC_iStorer,
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 Goodwin236ccb52009-08-19 18:00:44 +0000327def tSTRB : T1pI1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr), IIC_iStorer,
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 Goodwin236ccb52009-08-19 18:00:44 +0000331def tSTRH : T1pI2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr), IIC_iStorer,
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 Goodwin236ccb52009-08-19 18:00:44 +0000335def tSTRspi : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei,
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 Goodwin236ccb52009-08-19 18:00:44 +0000342def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStorei,
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),
David Goodwin236ccb52009-08-19 18:00:44 +0000354 IIC_iLoadm,
Evan Cheng94958142009-08-11 21:11:32 +0000355 "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),
David Goodwin236ccb52009-08-19 18:00:44 +0000360 IIC_iStorem,
Evan Cheng94958142009-08-11 21:11:32 +0000361 "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 Goodwin236ccb52009-08-19 18:00:44 +0000377def tADC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000382def tADDi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000386def tADDi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000392def tADDrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
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
David Goodwin236ccb52009-08-19 18:00:44 +0000397def tADDhirr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Evan Cheng7b3c2ad2009-09-09 01:38:23 +0000398 "add", " $dst, $rhs", []>;
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 Goodwin236ccb52009-08-19 18:00:44 +0000402def tAND : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000407def tASRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000412def tASRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000417def tBIC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000423def tCMN : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000424 "cmn", " $lhs, $rhs",
425 [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwin236ccb52009-08-19 18:00:44 +0000426def tCMNZ : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000433def tCMPi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMPi,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000434 "cmp", " $lhs, $rhs",
435 [(ARMcmp tGPR:$lhs, imm0_255:$rhs)]>;
David Goodwin236ccb52009-08-19 18:00:44 +0000436def tCMPzi8 : T1pI<(outs), (ins tGPR:$lhs, i32imm:$rhs), IIC_iCMPi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000444def tCMPr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000445 "cmp", " $lhs, $rhs",
446 [(ARMcmp tGPR:$lhs, tGPR:$rhs)]>;
David Goodwin236ccb52009-08-19 18:00:44 +0000447def tCMPzr : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000448 "cmp", " $lhs, $rhs",
449 [(ARMcmpZ tGPR:$lhs, tGPR:$rhs)]>;
450
David Goodwin236ccb52009-08-19 18:00:44 +0000451def tCMPhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iCMPr,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000452 "cmp", " $lhs, $rhs", []>;
David Goodwin236ccb52009-08-19 18:00:44 +0000453def tCMPzhir : T1pI<(outs), (ins GPR:$lhs, GPR:$rhs), IIC_iCMPr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000460def tEOR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000465def tLSLri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000470def tLSLrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000475def tLSRri : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000480def tLSRrr : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000485def tMOVi8 : T1sI<(outs tGPR:$dst), (ins i32imm:$src), IIC_iMOVi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000494def tMOVr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000495 "mov $dst, $src", []>;
496let Defs = [CPSR] in
David Goodwin236ccb52009-08-19 18:00:44 +0000497def tMOVSr : T1I<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000498 "movs $dst, $src", []>;
499
500// FIXME: Make these predicable.
David Goodwin236ccb52009-08-19 18:00:44 +0000501def tMOVgpr2tgpr : T1I<(outs tGPR:$dst), (ins GPR:$src), IIC_iMOVr,
Evan Cheng7b3c2ad2009-09-09 01:38:23 +0000502 "mov $dst, $src", []>;
David Goodwin236ccb52009-08-19 18:00:44 +0000503def tMOVtgpr2gpr : T1I<(outs GPR:$dst), (ins tGPR:$src), IIC_iMOVr,
Evan Cheng7b3c2ad2009-09-09 01:38:23 +0000504 "mov $dst, $src", []>;
David Goodwin236ccb52009-08-19 18:00:44 +0000505def tMOVgpr2gpr : T1I<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVr,
Evan Cheng7b3c2ad2009-09-09 01:38:23 +0000506 "mov $dst, $src", []>;
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 Goodwin236ccb52009-08-19 18:00:44 +0000511def tMUL : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMUL32,
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 Goodwin236ccb52009-08-19 18:00:44 +0000516def tMVN : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iMOVr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000522def tORR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000527def tREV : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000532def tREV16 : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000541def tREVSH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000542 "revsh", " $dst, $src",
543 [(set tGPR:$dst,
544 (sext_inreg
Evan Chengb4c98a32009-08-18 05:43:23 +0000545 (or (srl (and tGPR:$src, 0xFF00), (i32 8)),
Evan Cheng7bd2ad12009-07-11 06:43:01 +0000546 (shl tGPR:$src, (i32 8))), i16))]>,
547 Requires<[IsThumb1Only, HasV6]>;
548
David Goodwin8768bff2009-06-25 22:49:55 +0000549// rotate right register
David Goodwin236ccb52009-08-19 18:00:44 +0000550def tROR : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iMOVsr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000555def tRSB : T1sI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iALUi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000561def tSBC : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000566def tSUBi3 : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000570def tSUBi8 : T1sIt<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs), IIC_iALUi,
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 Goodwin236ccb52009-08-19 18:00:44 +0000575def tSUBrr : T1sI<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs), IIC_iALUr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000582def tSXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000588def tSXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000595def tTST : T1pI<(outs), (ins tGPR:$lhs, tGPR:$rhs), IIC_iCMPr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000600def tUXTB : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
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 Goodwin236ccb52009-08-19 18:00:44 +0000606def tUXTH : T1pI<(outs tGPR:$dst), (ins tGPR:$src), IIC_iUNAr,
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.
614let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
Evan Chengbf4111c2009-08-12 05:17:19 +0000615 def tMOVCCr_pseudo :
Evan Chengb9d5cff2009-08-12 02:03:03 +0000616 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
617 NoItinerary, "@ tMOVCCr $cc",
618 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000619
Evan Chengbf4111c2009-08-12 05:17:19 +0000620
621// 16-bit movcc in IT blocks for Thumb2.
David Goodwin236ccb52009-08-19 18:00:44 +0000622def tMOVCCr : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iCMOVr,
Evan Chengbf4111c2009-08-12 05:17:19 +0000623 "mov", " $dst, $rhs", []>;
624
David Goodwin236ccb52009-08-19 18:00:44 +0000625def tMOVCCi : T1pIt<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs), IIC_iCMOVi,
Evan Chengbf4111c2009-08-12 05:17:19 +0000626 "mov", " $dst, $rhs", []>;
627
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000628// tLEApcrel - Load a pc-relative address into a register without offending the
629// assembler.
David Goodwin236ccb52009-08-19 18:00:44 +0000630def tLEApcrel : T1I<(outs tGPR:$dst), (ins i32imm:$label, pred:$p), IIC_iALUi,
Evan Chengf7b61a12009-08-14 18:31:44 +0000631 "adr$p $dst, #$label", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632
Evan Chenga441c1a2009-08-14 00:32:16 +0000633def tLEApcrelJT : T1I<(outs tGPR:$dst),
Bob Wilson30ff4492009-08-21 21:58:55 +0000634 (ins i32imm:$label, nohash_imm:$id, pred:$p),
David Goodwin236ccb52009-08-19 18:00:44 +0000635 IIC_iALUi, "adr$p $dst, #${label}_${id}", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000636
637//===----------------------------------------------------------------------===//
638// TLS Instructions
639//
640
641// __aeabi_read_tp preserves the registers r1-r3.
642let isCall = 1,
643 Defs = [R0, LR] in {
David Goodwincfd67652009-08-06 16:52:47 +0000644 def tTPsoft : TIx2<(outs), (ins), IIC_Br,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000645 "bl __aeabi_read_tp",
646 [(set R0, ARMthread_pointer)]>;
647}
648
649//===----------------------------------------------------------------------===//
650// Non-Instruction Patterns
651//
652
Evan Cheng986e3b72009-07-10 02:09:04 +0000653// Add with carry
David Goodwin27c016b2009-07-27 19:59:26 +0000654def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
655 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
656def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Chengaf35b282009-08-20 17:01:04 +0000657 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwin27c016b2009-07-27 19:59:26 +0000658def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
659 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng986e3b72009-07-10 02:09:04 +0000660
661// Subtract with carry
David Goodwin27c016b2009-07-27 19:59:26 +0000662def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
663 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
664def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
665 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
666def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
667 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng986e3b72009-07-10 02:09:04 +0000668
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669// ConstantPool, GlobalAddress
David Goodwin27c016b2009-07-27 19:59:26 +0000670def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
671def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000672
673// JumpTable
David Goodwin27c016b2009-07-27 19:59:26 +0000674def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
675 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676
677// Direct calls
Evan Cheng9e734482009-07-29 21:26:42 +0000678def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000679 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000680def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000681 Requires<[IsThumb, IsDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000682
683def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000684 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng9e734482009-07-29 21:26:42 +0000685def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Cheng68e4b582009-08-01 00:16:10 +0000686 Requires<[IsThumb, HasV5T, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000687
688// Indirect calls to ARM routines
Evan Cheng68e4b582009-08-01 00:16:10 +0000689def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
690 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
691def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
692 Requires<[IsThumb, HasV5T, IsDarwin]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000693
694// zextload i1 -> zextload i8
Evan Cheng503be112009-06-30 02:15:48 +0000695def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
696 (tLDRB t_addrmode_s1:$addr)>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000697
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698// extload -> zextload
Evan Cheng503be112009-06-30 02:15:48 +0000699def : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
700def : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
701def : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000702
Evan Cheng5e1d2182009-08-28 00:31:43 +0000703// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng76aeed32009-07-11 07:08:13 +0000704// ldr{b|h} + sxt{b|h} instead.
Evan Cheng58fec0c2009-07-21 18:15:26 +0000705def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
Evan Cheng5e1d2182009-08-28 00:31:43 +0000706 (tSXTB (tLDRB t_addrmode_s1:$addr))>,
707 Requires<[IsThumb1Only, HasV6]>;
Evan Cheng58fec0c2009-07-21 18:15:26 +0000708def : T1Pat<(sextloadi16 t_addrmode_s2:$addr),
Evan Cheng5e1d2182009-08-28 00:31:43 +0000709 (tSXTH (tLDRH t_addrmode_s2:$addr))>,
710 Requires<[IsThumb1Only, HasV6]>;
Evan Cheng76aeed32009-07-11 07:08:13 +0000711
Evan Cheng5e1d2182009-08-28 00:31:43 +0000712def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
713 (tASRri (tLSLri (tLDRB t_addrmode_s1:$addr), 24), 24)>;
714def : T1Pat<(sextloadi16 t_addrmode_s1:$addr),
715 (tASRri (tLSLri (tLDRH t_addrmode_s1:$addr), 16), 16)>;
Evan Cheng76aeed32009-07-11 07:08:13 +0000716
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000717// Large immediate handling.
718
719// Two piece imms.
Evan Cheng19bb7c72009-06-27 02:26:13 +0000720def : T1Pat<(i32 thumb_immshifted:$src),
721 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
722 (thumb_immshifted_shamt imm:$src))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000723
Evan Cheng19bb7c72009-06-27 02:26:13 +0000724def : T1Pat<(i32 imm0_255_comp:$src),
725 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;