blob: bd6d1a0c7d9c6a512e7ab862321ca244df4c2382 [file] [log] [blame]
Bill Wendling0480e282010-12-01 02:36:55 +00001//===- ARMInstrThumb.td - Thumb support for ARM ------------*- tablegen -*-===//
Evan Chenga8e29892007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Thumb specific DAG Nodes.
16//
17
18def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
Chris Lattner036609b2010-12-23 18:28:41 +000019 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000020 SDNPVariadic]>;
Evan Chenga8e29892007-01-19 07:51:42 +000021
Evan Chenga8e29892007-01-19 07:51:42 +000022def imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000023 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000024}]>;
25def imm_comp_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000026 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000027}]>;
28
Evan Chenga8e29892007-01-19 07:51:42 +000029def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000030 return (uint32_t)-N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000031}], imm_neg_XFORM>;
32
Evan Chenga8e29892007-01-19 07:51:42 +000033def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000034 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000035}]>;
36
Eric Christopher8f232d32011-04-28 05:49:04 +000037def imm8_255 : ImmLeaf<i32, [{
38 return Imm >= 8 && Imm < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000039}]>;
40def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000041 unsigned Val = -N->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +000042 return Val >= 8 && Val < 256;
43}], imm_neg_XFORM>;
44
Bill Wendling0480e282010-12-01 02:36:55 +000045// Break imm's up into two pieces: an immediate + a left shift. This uses
46// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
47// to get the val/shift pieces.
Evan Chenga8e29892007-01-19 07:51:42 +000048def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000049 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000050}]>;
51
52def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000053 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000054 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000055}]>;
56
57def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000058 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000059 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000060}]>;
61
Jim Grosbachd40963c2010-12-14 22:28:03 +000062// ADR instruction labels.
63def t_adrlabel : Operand<i32> {
64 let EncoderMethod = "getThumbAdrLabelOpValue";
65}
66
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000067// Scaled 4 immediate.
68def t_imm_s4 : Operand<i32> {
69 let PrintMethod = "printThumbS4ImmOperand";
Benjamin Kramer151bd172011-07-14 21:47:24 +000070 let OperandType = "OPERAND_IMMEDIATE";
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000071}
72
Evan Chenga8e29892007-01-19 07:51:42 +000073// Define Thumb specific addressing modes.
74
Benjamin Kramer151bd172011-07-14 21:47:24 +000075let OperandType = "OPERAND_PCREL" in {
Jim Grosbache2467172010-12-10 18:21:33 +000076def t_brtarget : Operand<OtherVT> {
77 let EncoderMethod = "getThumbBRTargetOpValue";
78}
79
Jim Grosbach01086452010-12-10 17:13:40 +000080def t_bcctarget : Operand<i32> {
81 let EncoderMethod = "getThumbBCCTargetOpValue";
82}
83
Jim Grosbachcf6220a2010-12-09 19:01:46 +000084def t_cbtarget : Operand<i32> {
Jim Grosbach027d6e82010-12-09 19:04:53 +000085 let EncoderMethod = "getThumbCBTargetOpValue";
Bill Wendlingdff2f712010-12-08 23:01:43 +000086}
87
Jim Grosbach662a8162010-12-06 23:57:07 +000088def t_bltarget : Operand<i32> {
89 let EncoderMethod = "getThumbBLTargetOpValue";
90}
91
Bill Wendling09aa3f02010-12-09 00:39:08 +000092def t_blxtarget : Operand<i32> {
93 let EncoderMethod = "getThumbBLXTargetOpValue";
94}
Benjamin Kramer151bd172011-07-14 21:47:24 +000095}
Bill Wendling09aa3f02010-12-09 00:39:08 +000096
Bill Wendlingf4caf692010-12-14 03:36:38 +000097def MemModeRegThumbAsmOperand : AsmOperandClass {
98 let Name = "MemModeRegThumb";
99 let SuperClasses = [];
100}
101
102def MemModeImmThumbAsmOperand : AsmOperandClass {
103 let Name = "MemModeImmThumb";
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000104 let SuperClasses = [];
105}
106
Evan Chenga8e29892007-01-19 07:51:42 +0000107// t_addrmode_rr := reg + reg
108//
109def t_addrmode_rr : Operand<i32>,
110 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000111 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000112 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000113 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000114}
115
Bill Wendlingf4caf692010-12-14 03:36:38 +0000116// t_addrmode_rrs := reg + reg
Evan Chenga8e29892007-01-19 07:51:42 +0000117//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000118def t_addrmode_rrs1 : Operand<i32>,
119 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
120 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
121 let PrintMethod = "printThumbAddrModeRROperand";
122 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
123 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000124}
Bill Wendlingf4caf692010-12-14 03:36:38 +0000125def t_addrmode_rrs2 : Operand<i32>,
126 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
127 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
128 let PrintMethod = "printThumbAddrModeRROperand";
129 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
130 let ParserMatchClass = MemModeRegThumbAsmOperand;
131}
132def t_addrmode_rrs4 : Operand<i32>,
133 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
134 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
135 let PrintMethod = "printThumbAddrModeRROperand";
136 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
137 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000138}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000139
Bill Wendlingf4caf692010-12-14 03:36:38 +0000140// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc38f2bc2007-01-23 22:59:13 +0000141//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000142def t_addrmode_is4 : Operand<i32>,
143 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
144 let EncoderMethod = "getAddrModeISOpValue";
145 let PrintMethod = "printThumbAddrModeImm5S4Operand";
146 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
147 let ParserMatchClass = MemModeImmThumbAsmOperand;
148}
149
150// t_addrmode_is2 := reg + imm5 * 2
151//
152def t_addrmode_is2 : Operand<i32>,
153 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
154 let EncoderMethod = "getAddrModeISOpValue";
155 let PrintMethod = "printThumbAddrModeImm5S2Operand";
156 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
157 let ParserMatchClass = MemModeImmThumbAsmOperand;
158}
159
160// t_addrmode_is1 := reg + imm5
161//
162def t_addrmode_is1 : Operand<i32>,
163 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
164 let EncoderMethod = "getAddrModeISOpValue";
165 let PrintMethod = "printThumbAddrModeImm5S1Operand";
166 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
167 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000168}
169
170// t_addrmode_sp := sp + imm8 * 4
171//
172def t_addrmode_sp : Operand<i32>,
173 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbachd967cd02010-12-07 21:50:47 +0000174 let EncoderMethod = "getAddrModeThumbSPOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000175 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000176 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000177 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000178}
179
Bill Wendlingb8958b02010-12-08 01:57:09 +0000180// t_addrmode_pc := <label> => pc + imm8 * 4
181//
182def t_addrmode_pc : Operand<i32> {
183 let EncoderMethod = "getAddrModePCOpValue";
Bill Wendlingf4caf692010-12-14 03:36:38 +0000184 let ParserMatchClass = MemModeImmThumbAsmOperand;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000185}
186
Evan Chenga8e29892007-01-19 07:51:42 +0000187//===----------------------------------------------------------------------===//
188// Miscellaneous Instructions.
189//
190
Jim Grosbach4642ad32010-02-22 23:10:38 +0000191// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
192// from removing one half of the matched pairs. That breaks PEI, which assumes
193// these will always be in pairs, and asserts if it finds otherwise. Better way?
194let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000195def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000196 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
197 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
198 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000199
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000200def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000201 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
202 [(ARMcallseq_start imm:$amt)]>,
203 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000204}
Evan Cheng44bec522007-05-15 01:29:07 +0000205
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000206// T1Disassembly - A simple class to make encoding some disassembly patterns
207// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000208class T1Disassembly<bits<2> op1, bits<8> op2>
209 : T1Encoding<0b101111> {
210 let Inst{9-8} = op1;
211 let Inst{7-0} = op2;
212}
213
Johnny Chenbd2c6232010-02-25 03:28:51 +0000214def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
215 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000216 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000217
Johnny Chend86d2692010-02-25 17:51:03 +0000218def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
219 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000220 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000221
222def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
223 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000224 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000225
226def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
227 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000228 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000229
230def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
231 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000232 T1Disassembly<0b11, 0x40>; // A8.6.157
233
234// The i32imm operand $val can be used by a debugger to store more information
235// about the breakpoint.
236def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
237 [/* For disassembly only; pattern left blank */]>,
238 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
239 // A8.6.22
240 bits<8> val;
241 let Inst{7-0} = val;
242}
Johnny Chend86d2692010-02-25 17:51:03 +0000243
Jim Grosbach06322472011-07-22 17:52:23 +0000244def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
245 []>, T1Encoding<0b101101> {
246 bits<1> end;
Bill Wendling7d0affd2010-11-21 10:55:23 +0000247 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000248 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000249 let Inst{4} = 1;
Jim Grosbach06322472011-07-22 17:52:23 +0000250 let Inst{3} = end;
Bill Wendlinga8981662010-11-19 22:02:18 +0000251 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000252}
253
Johnny Chen93042d12010-03-02 18:14:57 +0000254// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000255def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
256 NoItinerary, "cps$imod $iflags",
257 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000258 T1Misc<0b0110011> {
259 // A8.6.38 & B6.1.1
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000260 bit imod;
261 bits<3> iflags;
262
263 let Inst{4} = imod;
264 let Inst{3} = 0;
265 let Inst{2-0} = iflags;
Bill Wendling849f2e32010-11-29 00:18:15 +0000266}
Johnny Chen93042d12010-03-02 18:14:57 +0000267
Evan Cheng35d6c412009-08-04 23:47:55 +0000268// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000269let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000270def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000271 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000272 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000273 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000274 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000275 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000276 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000277}
Evan Chenga8e29892007-01-19 07:51:42 +0000278
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000279// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000280def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000281 "add\t$dst, pc, $rhs", []>,
282 T1Encoding<{1,0,1,0,0,?}> {
283 // A6.2 & A8.6.10
284 bits<3> dst;
285 bits<8> rhs;
286 let Inst{10-8} = dst;
287 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000288}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000289
Bill Wendling0ae28e42010-11-19 22:37:33 +0000290// ADD <Rd>, sp, #<imm8>
291// This is rematerializable, which is particularly useful for taking the
292// address of locals.
293let isReMaterializable = 1 in
294def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
295 "add\t$dst, $sp, $rhs", []>,
296 T1Encoding<{1,0,1,0,1,?}> {
297 // A6.2 & A8.6.8
298 bits<3> dst;
299 bits<8> rhs;
300 let Inst{10-8} = dst;
301 let Inst{7-0} = rhs;
302}
303
304// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000305def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000306 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000307 T1Misc<{0,0,0,0,0,?,?}> {
308 // A6.2.5 & A8.6.8
309 bits<7> rhs;
310 let Inst{6-0} = rhs;
311}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000312
Bill Wendling0ae28e42010-11-19 22:37:33 +0000313// SUB sp, sp, #<imm7>
314// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000315def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000316 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000317 T1Misc<{0,0,0,0,1,?,?}> {
318 // A6.2.5 & A8.6.214
319 bits<7> rhs;
320 let Inst{6-0} = rhs;
321}
Evan Cheng86198642009-08-07 00:34:42 +0000322
Bill Wendling0ae28e42010-11-19 22:37:33 +0000323// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000324def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000325 "add\t$dst, $rhs", []>,
326 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000327 // A8.6.9 Encoding T1
328 bits<4> dst;
329 let Inst{7} = dst{3};
330 let Inst{6-3} = 0b1101;
331 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000332}
Evan Cheng86198642009-08-07 00:34:42 +0000333
Bill Wendling0ae28e42010-11-19 22:37:33 +0000334// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000335def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000336 "add\t$dst, $rhs", []>,
337 T1Special<{0,0,?,?}> {
338 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000339 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000340 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000341 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000342 let Inst{2-0} = 0b101;
343}
Evan Cheng86198642009-08-07 00:34:42 +0000344
Evan Chenga8e29892007-01-19 07:51:42 +0000345//===----------------------------------------------------------------------===//
346// Control Flow Instructions.
347//
348
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000349// Indirect branches
350let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich421b1062011-05-26 03:41:12 +0000351 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
352 T1Special<{1,1,0,?}> {
353 // A6.2.3 & A8.6.25
354 bits<4> Rm;
355 let Inst{6-3} = Rm;
356 let Inst{2-0} = 0b000;
357 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000358}
359
Jim Grosbachead77cd2011-07-08 21:04:05 +0000360let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson16884412011-07-13 23:22:26 +0000361 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Jim Grosbach25e6d482011-07-08 21:50:04 +0000362 [(ARMretflag)], (tBX LR, pred:$p)>;
Jim Grosbachead77cd2011-07-08 21:04:05 +0000363
364 // Alternative return instruction used by vararg functions.
Jim Grosbach25e6d482011-07-08 21:50:04 +0000365 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +0000366 2, IIC_Br, [],
Jim Grosbach25e6d482011-07-08 21:50:04 +0000367 (tBX GPR:$Rm, pred:$p)>;
Jim Grosbachead77cd2011-07-08 21:04:05 +0000368}
369
Bill Wendling0480e282010-12-01 02:36:55 +0000370// All calls clobber the non-callee saved registers. SP is marked as a use to
371// prevent stack-pointer assignments that appear immediately before calls from
372// potentially appearing dead.
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000373let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000374 // On non-Darwin platforms R9 is callee-saved.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000375 Defs = [R0, R1, R2, R3, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000376 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000377 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000378 def tBL : TIx2<0b11110, 0b11, 1,
Owen Anderson0af0dc82011-07-18 18:50:52 +0000379 (outs), (ins pred:$p, t_bltarget:$func, variable_ops), IIC_Br,
380 "bl${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000381 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000382 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000383 bits<21> func;
384 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000385 let Inst{13} = 1;
386 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000387 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000388 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000389
Evan Chengb6207242009-08-01 00:16:10 +0000390 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000391 def tBLXi : TIx2<0b11110, 0b11, 0,
Owen Anderson0af0dc82011-07-18 18:50:52 +0000392 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops), IIC_Br,
393 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000394 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000395 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000396 bits<21> func;
397 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000398 let Inst{13} = 1;
399 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000400 let Inst{10-1} = func{10-1};
401 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000402 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000403
Evan Chengb6207242009-08-01 00:16:10 +0000404 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000405 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
406 "blx${p}\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000407 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000408 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
Owen Anderson18901d62011-05-11 17:00:48 +0000409 T1Special<{1,1,1,?}> { // A6.2.3 & A8.6.24;
410 bits<4> func;
411 let Inst{6-3} = func;
412 let Inst{2-0} = 0b000;
413 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000414
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000415 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000416 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000417 4, IIC_Br,
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000418 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000419 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000420}
421
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000422let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000423 // On Darwin R9 is call-clobbered.
424 // R7 is marked as a use to prevent frame-pointer assignments from being
425 // moved above / below calls.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000426 Defs = [R0, R1, R2, R3, R9, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000427 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000428 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000429 def tBLr9 : tPseudoExpand<(outs), (ins pred:$p, t_bltarget:$func, variable_ops),
430 4, IIC_Br, [(ARMtcall tglobaladdr:$func)],
431 (tBL pred:$p, t_bltarget:$func)>,
432 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000433
Evan Chengb6207242009-08-01 00:16:10 +0000434 // ARMv5T and above, also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000435 def tBLXi_r9 : tPseudoExpand<(outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
436 4, IIC_Br, [(ARMcall tglobaladdr:$func)],
437 (tBLXi pred:$p, t_blxtarget:$func)>,
438 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000439
Evan Chengb6207242009-08-01 00:16:10 +0000440 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000441 def tBLXr_r9 : tPseudoExpand<(outs), (ins pred:$p, GPR:$func, variable_ops),
442 2, IIC_Br, [(ARMtcall GPR:$func)],
443 (tBLXr pred:$p, GPR:$func)>,
444 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000445
446 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000447 def tBXr9_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000448 4, IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000449 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000450 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000451}
452
Bill Wendling0480e282010-12-01 02:36:55 +0000453let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
454 let isPredicable = 1 in
Jim Grosbache2467172010-12-10 18:21:33 +0000455 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
Bill Wendling0480e282010-12-01 02:36:55 +0000456 "b\t$target", [(br bb:$target)]>,
Jim Grosbache2467172010-12-10 18:21:33 +0000457 T1Encoding<{1,1,1,0,0,?}> {
458 bits<11> target;
459 let Inst{10-0} = target;
460 }
Evan Chenga8e29892007-01-19 07:51:42 +0000461
Evan Cheng225dfe92007-01-30 01:13:37 +0000462 // Far jump
Jim Grosbach3efad8f2010-12-16 19:11:16 +0000463 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
464 // the clobber of LR.
Evan Cheng53c67c02009-08-07 05:45:07 +0000465 let Defs = [LR] in
Owen Anderson0af0dc82011-07-18 18:50:52 +0000466 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
467 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000468
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000469 def tBR_JTr : tPseudoInst<(outs),
470 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
Owen Anderson16884412011-07-13 23:22:26 +0000471 0, IIC_Br,
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000472 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
473 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000474 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000475}
476
Evan Chengc85e8322007-07-05 07:13:32 +0000477// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000478// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000479let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000480 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000481 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000482 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Eric Christopher33281b22011-05-27 03:50:53 +0000483 T1BranchCond<{1,1,0,1}> {
Jim Grosbachceab5012010-12-04 00:20:40 +0000484 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000485 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000486 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000487 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000488}
Evan Chenga8e29892007-01-19 07:51:42 +0000489
Evan Chengde17fb62009-10-31 23:46:45 +0000490// Compare and branch on zero / non-zero
491let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000492 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000493 "cbz\t$Rn, $target", []>,
494 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000495 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000496 bits<6> target;
497 bits<3> Rn;
498 let Inst{9} = target{5};
499 let Inst{7-3} = target{4-0};
500 let Inst{2-0} = Rn;
501 }
Evan Chengde17fb62009-10-31 23:46:45 +0000502
Owen Anderson0bc8bbb2011-08-03 23:21:48 +0000503 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
504 "cbnz\t$Rn, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000505 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000506 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000507 bits<6> target;
508 bits<3> Rn;
509 let Inst{9} = target{5};
510 let Inst{7-3} = target{4-0};
511 let Inst{2-0} = Rn;
512 }
Evan Chengde17fb62009-10-31 23:46:45 +0000513}
514
Jim Grosbache36e21e2011-07-08 20:13:35 +0000515// Tail calls
516let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
517 // Darwin versions.
518 let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
519 Uses = [SP] in {
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000520 // tTAILJMPd: Darwin version uses a Thumb2 branch (no Thumb1 tail calls
521 // on Darwin), so it's in ARMInstrThumb2.td.
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000522 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000523 4, IIC_Br, [],
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000524 (tBX GPR:$dst, (ops 14, zero_reg))>,
525 Requires<[IsThumb, IsDarwin]>;
Jim Grosbache36e21e2011-07-08 20:13:35 +0000526 }
527 // Non-Darwin versions (the difference is R9).
528 let Defs = [R0, R1, R2, R3, R12, QQQQ0, QQQQ2, QQQQ3, PC],
529 Uses = [SP] in {
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000530 def tTAILJMPdND : tPseudoExpand<(outs), (ins t_brtarget:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000531 4, IIC_Br, [],
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000532 (tB t_brtarget:$dst)>,
533 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000534 def tTAILJMPrND : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000535 4, IIC_Br, [],
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000536 (tBX GPR:$dst, (ops 14, zero_reg))>,
537 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbache36e21e2011-07-08 20:13:35 +0000538 }
539}
540
541
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000542// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
543// A8.6.16 B: Encoding T1
544// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000545let isCall = 1, Uses = [SP] in
Jim Grosbached838482011-07-26 16:24:27 +0000546def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Bill Wendling6179c312010-11-20 00:53:35 +0000547 "svc", "\t$imm", []>, Encoding16 {
548 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000549 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000550 let Inst{11-8} = 0b1111;
551 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000552}
553
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000554// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000555let isBarrier = 1, isTerminator = 1 in
Owen Anderson18901d62011-05-11 17:00:48 +0000556def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000557 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000558 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000559}
560
Evan Chenga8e29892007-01-19 07:51:42 +0000561//===----------------------------------------------------------------------===//
562// Load Store Instructions.
563//
564
Bill Wendlingb6faf652010-12-14 22:10:49 +0000565// Loads: reg/reg and reg/imm5
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000566let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb6faf652010-12-14 22:10:49 +0000567multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
568 Operand AddrMode_r, Operand AddrMode_i,
569 AddrMode am, InstrItinClass itin_r,
570 InstrItinClass itin_i, string asm,
571 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000572 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000573 T1pILdStEncode<reg_opc,
574 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
575 am, itin_r, asm, "\t$Rt, $addr",
576 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000577 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000578 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
579 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
580 am, itin_i, asm, "\t$Rt, $addr",
581 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
582}
583// Stores: reg/reg and reg/imm5
584multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
585 Operand AddrMode_r, Operand AddrMode_i,
586 AddrMode am, InstrItinClass itin_r,
587 InstrItinClass itin_i, string asm,
588 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000589 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000590 T1pILdStEncode<reg_opc,
591 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
592 am, itin_r, asm, "\t$Rt, $addr",
593 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000594 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000595 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
596 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
597 am, itin_i, asm, "\t$Rt, $addr",
598 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
599}
Bill Wendling6179c312010-11-20 00:53:35 +0000600
Bill Wendlingb6faf652010-12-14 22:10:49 +0000601// A8.6.57 & A8.6.60
602defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
603 t_addrmode_is4, AddrModeT1_4,
604 IIC_iLoad_r, IIC_iLoad_i, "ldr",
605 UnOpFrag<(load node:$Src)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000606
Bill Wendlingb6faf652010-12-14 22:10:49 +0000607// A8.6.64 & A8.6.61
608defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
609 t_addrmode_is1, AddrModeT1_1,
610 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
611 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000612
Bill Wendlingb6faf652010-12-14 22:10:49 +0000613// A8.6.76 & A8.6.73
614defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
615 t_addrmode_is2, AddrModeT1_2,
616 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
617 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000618
Evan Cheng2f297df2009-07-11 07:08:13 +0000619let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000620def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000621 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
622 AddrModeT1_1, IIC_iLoad_bh_r,
623 "ldrsb", "\t$dst, $addr",
624 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000625
Evan Cheng2f297df2009-07-11 07:08:13 +0000626let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000627def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000628 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
629 AddrModeT1_2, IIC_iLoad_bh_r,
630 "ldrsh", "\t$dst, $addr",
631 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000632
Dan Gohman15511cf2008-12-03 18:15:48 +0000633let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000634def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000635 "ldr", "\t$Rt, $addr",
636 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000637 T1LdStSP<{1,?,?}> {
638 bits<3> Rt;
639 bits<8> addr;
640 let Inst{10-8} = Rt;
641 let Inst{7-0} = addr;
642}
Evan Cheng012f2d92007-01-24 08:53:17 +0000643
644// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000645// FIXME: Use ldr.n to work around a Darwin assembler bug.
Owen Anderson91614ae2011-07-18 22:14:02 +0000646let canFoldAsLoad = 1, isReMaterializable = 1, isCodeGenOnly = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000647def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000648 "ldr", ".n\t$Rt, $addr",
649 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
650 T1Encoding<{0,1,0,0,1,?}> {
651 // A6.2 & A8.6.59
652 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000653 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000654 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000655 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000656}
Evan Chengfa775d02007-03-19 07:20:03 +0000657
Johnny Chen597fa652011-04-22 19:12:43 +0000658// FIXME: Remove this entry when the above ldr.n workaround is fixed.
659// For disassembly use only.
660def tLDRpciDIS : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
661 "ldr", "\t$Rt, $addr",
662 [/* disassembly only */]>,
663 T1Encoding<{0,1,0,0,1,?}> {
664 // A6.2 & A8.6.59
665 bits<3> Rt;
666 bits<8> addr;
667 let Inst{10-8} = Rt;
668 let Inst{7-0} = addr;
669}
670
Bill Wendlingb6faf652010-12-14 22:10:49 +0000671// A8.6.194 & A8.6.192
672defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
673 t_addrmode_is4, AddrModeT1_4,
674 IIC_iStore_r, IIC_iStore_i, "str",
675 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000676
Bill Wendlingb6faf652010-12-14 22:10:49 +0000677// A8.6.197 & A8.6.195
678defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
679 t_addrmode_is1, AddrModeT1_1,
680 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
681 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000682
Bill Wendlingb6faf652010-12-14 22:10:49 +0000683// A8.6.207 & A8.6.205
684defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000685 t_addrmode_is2, AddrModeT1_2,
686 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
687 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000688
Evan Chenga8e29892007-01-19 07:51:42 +0000689
Jim Grosbachd967cd02010-12-07 21:50:47 +0000690def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendlingf4caf692010-12-14 03:36:38 +0000691 "str", "\t$Rt, $addr",
692 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000693 T1LdStSP<{0,?,?}> {
694 bits<3> Rt;
695 bits<8> addr;
696 let Inst{10-8} = Rt;
697 let Inst{7-0} = addr;
698}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000699
Evan Chenga8e29892007-01-19 07:51:42 +0000700//===----------------------------------------------------------------------===//
701// Load / store multiple Instructions.
702//
703
Bill Wendling6c470b82010-11-13 09:09:38 +0000704multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
705 InstrItinClass itin_upd, bits<6> T1Enc,
Owen Anderson565a0362011-07-18 23:25:34 +0000706 bit L_bit, string baseOpc> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000707 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000708 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000709 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000710 T1Encoding<T1Enc> {
711 bits<3> Rn;
712 bits<8> regs;
713 let Inst{10-8} = Rn;
714 let Inst{7-0} = regs;
715 }
Owen Anderson565a0362011-07-18 23:25:34 +0000716
Bill Wendling73fe34a2010-11-16 01:16:36 +0000717 def IA_UPD :
Owen Anderson565a0362011-07-18 23:25:34 +0000718 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
719 "$Rn = $wb", itin_upd>,
720 PseudoInstExpansion<(!cast<Instruction>(!strconcat(baseOpc, "IA"))
721 GPR:$Rn, pred:$p, reglist:$regs)> {
722 let Size = 2;
723 let OutOperandList = (outs GPR:$wb);
724 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
725 let Pattern = [];
726 let isCodeGenOnly = 1;
727 let isPseudo = 1;
728 list<Predicate> Predicates = [IsThumb];
Bill Wendling6179c312010-11-20 00:53:35 +0000729 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000730}
731
Bill Wendling73fe34a2010-11-16 01:16:36 +0000732// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000733let neverHasSideEffects = 1 in {
734
735let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
736defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
Owen Anderson565a0362011-07-18 23:25:34 +0000737 {1,1,0,0,1,?}, 1, "tLDM">;
Bill Wendlingddc918b2010-11-13 10:57:02 +0000738
739let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
740defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
Owen Anderson565a0362011-07-18 23:25:34 +0000741 {1,1,0,0,0,?}, 0, "tSTM">;
Owen Anderson18901d62011-05-11 17:00:48 +0000742
Bill Wendlingddc918b2010-11-13 10:57:02 +0000743} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000744
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000745let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000746def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000747 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000748 "pop${p}\t$regs", []>,
749 T1Misc<{1,1,0,?,?,?,?}> {
750 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000751 let Inst{8} = regs{15};
752 let Inst{7-0} = regs{7-0};
753}
Evan Cheng4b322e52009-08-11 21:11:32 +0000754
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000755let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000756def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000757 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000758 "push${p}\t$regs", []>,
759 T1Misc<{0,1,0,?,?,?,?}> {
760 bits<16> regs;
761 let Inst{8} = regs{14};
762 let Inst{7-0} = regs{7-0};
763}
Evan Chenga8e29892007-01-19 07:51:42 +0000764
765//===----------------------------------------------------------------------===//
766// Arithmetic Instructions.
767//
768
Bill Wendling1d045ee2010-12-01 02:28:08 +0000769// Helper classes for encoding T1pI patterns:
770class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
771 string opc, string asm, list<dag> pattern>
772 : T1pI<oops, iops, itin, opc, asm, pattern>,
773 T1DataProcessing<opA> {
774 bits<3> Rm;
775 bits<3> Rn;
776 let Inst{5-3} = Rm;
777 let Inst{2-0} = Rn;
778}
779class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
780 string opc, string asm, list<dag> pattern>
781 : T1pI<oops, iops, itin, opc, asm, pattern>,
782 T1Misc<opA> {
783 bits<3> Rm;
784 bits<3> Rd;
785 let Inst{5-3} = Rm;
786 let Inst{2-0} = Rd;
787}
788
Bill Wendling76f4e102010-12-01 01:20:15 +0000789// Helper classes for encoding T1sI patterns:
790class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
791 string opc, string asm, list<dag> pattern>
792 : T1sI<oops, iops, itin, opc, asm, pattern>,
793 T1DataProcessing<opA> {
794 bits<3> Rd;
795 bits<3> Rn;
796 let Inst{5-3} = Rn;
797 let Inst{2-0} = Rd;
798}
799class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
800 string opc, string asm, list<dag> pattern>
801 : T1sI<oops, iops, itin, opc, asm, pattern>,
802 T1General<opA> {
803 bits<3> Rm;
804 bits<3> Rn;
805 bits<3> Rd;
806 let Inst{8-6} = Rm;
807 let Inst{5-3} = Rn;
808 let Inst{2-0} = Rd;
809}
810class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
811 string opc, string asm, list<dag> pattern>
812 : T1sI<oops, iops, itin, opc, asm, pattern>,
813 T1General<opA> {
814 bits<3> Rd;
815 bits<3> Rm;
816 let Inst{5-3} = Rm;
817 let Inst{2-0} = Rd;
818}
819
820// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000821class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
822 string opc, string asm, list<dag> pattern>
823 : T1sIt<oops, iops, itin, opc, asm, pattern>,
824 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000825 bits<3> Rdn;
826 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000827 let Inst{5-3} = Rm;
828 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000829}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000830class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
831 string opc, string asm, list<dag> pattern>
832 : T1sIt<oops, iops, itin, opc, asm, pattern>,
833 T1General<opA> {
834 bits<3> Rdn;
835 bits<8> imm8;
836 let Inst{10-8} = Rdn;
837 let Inst{7-0} = imm8;
838}
839
840// Add with carry register
841let isCommutable = 1, Uses = [CPSR] in
842def tADC : // A8.6.2
843 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
844 "adc", "\t$Rdn, $Rm",
845 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000846
David Goodwinc9ee1182009-06-25 22:49:55 +0000847// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000848def tADDi3 : // A8.6.4 T1
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000849 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
850 IIC_iALUi,
Bill Wendling76f4e102010-12-01 01:20:15 +0000851 "add", "\t$Rd, $Rm, $imm3",
852 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000853 bits<3> imm3;
854 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000855}
Evan Chenga8e29892007-01-19 07:51:42 +0000856
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000857def tADDi8 : // A8.6.4 T2
858 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
859 IIC_iALUi,
860 "add", "\t$Rdn, $imm8",
861 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000862
David Goodwinc9ee1182009-06-25 22:49:55 +0000863// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000864let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000865def tADDrr : // A8.6.6 T1
866 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
867 IIC_iALUr,
868 "add", "\t$Rd, $Rn, $Rm",
869 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000870
Evan Chengcd799b92009-06-12 20:46:18 +0000871let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000872def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
873 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000874 T1Special<{0,0,?,?}> {
875 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000876 bits<4> Rdn;
877 bits<4> Rm;
878 let Inst{7} = Rdn{3};
879 let Inst{6-3} = Rm;
880 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000881}
Evan Chenga8e29892007-01-19 07:51:42 +0000882
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000883// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000884let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000885def tAND : // A8.6.12
886 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
887 IIC_iBITr,
888 "and", "\t$Rdn, $Rm",
889 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000890
David Goodwinc9ee1182009-06-25 22:49:55 +0000891// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000892def tASRri : // A8.6.14
893 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
894 IIC_iMOVsi,
895 "asr", "\t$Rd, $Rm, $imm5",
896 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000897 bits<5> imm5;
898 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000899}
Evan Chenga8e29892007-01-19 07:51:42 +0000900
David Goodwinc9ee1182009-06-25 22:49:55 +0000901// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000902def tASRrr : // A8.6.15
903 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
904 IIC_iMOVsr,
905 "asr", "\t$Rdn, $Rm",
906 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000907
David Goodwinc9ee1182009-06-25 22:49:55 +0000908// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000909def tBIC : // A8.6.20
910 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
911 IIC_iBITr,
912 "bic", "\t$Rdn, $Rm",
913 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000914
David Goodwinc9ee1182009-06-25 22:49:55 +0000915// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000916let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000917//FIXME: Disable CMN, as CCodes are backwards from compare expectations
918// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000919//def tCMN : // A8.6.33
920// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
921// IIC_iCMPr,
922// "cmn", "\t$lhs, $rhs",
923// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000924
925def tCMNz : // A8.6.33
926 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
927 IIC_iCMPr,
928 "cmn", "\t$Rn, $Rm",
929 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
930
931} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000932
David Goodwinc9ee1182009-06-25 22:49:55 +0000933// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000934let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000935def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
936 "cmp", "\t$Rn, $imm8",
937 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
938 T1General<{1,0,1,?,?}> {
939 // A8.6.35
940 bits<3> Rn;
941 bits<8> imm8;
942 let Inst{10-8} = Rn;
943 let Inst{7-0} = imm8;
944}
945
David Goodwinc9ee1182009-06-25 22:49:55 +0000946// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +0000947def tCMPr : // A8.6.36 T1
948 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
949 IIC_iCMPr,
950 "cmp", "\t$Rn, $Rm",
951 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
952
Bill Wendling849f2e32010-11-29 00:18:15 +0000953def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
954 "cmp", "\t$Rn, $Rm", []>,
955 T1Special<{0,1,?,?}> {
956 // A8.6.36 T2
957 bits<4> Rm;
958 bits<4> Rn;
959 let Inst{7} = Rn{3};
960 let Inst{6-3} = Rm;
961 let Inst{2-0} = Rn{2-0};
962}
Bill Wendling5cc88a22010-11-20 22:52:33 +0000963} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000964
Evan Chenga8e29892007-01-19 07:51:42 +0000965
David Goodwinc9ee1182009-06-25 22:49:55 +0000966// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +0000967let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000968def tEOR : // A8.6.45
969 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
970 IIC_iBITr,
971 "eor", "\t$Rdn, $Rm",
972 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000973
David Goodwinc9ee1182009-06-25 22:49:55 +0000974// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000975def tLSLri : // A8.6.88
976 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
977 IIC_iMOVsi,
978 "lsl", "\t$Rd, $Rm, $imm5",
979 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000980 bits<5> imm5;
981 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000982}
Evan Chenga8e29892007-01-19 07:51:42 +0000983
David Goodwinc9ee1182009-06-25 22:49:55 +0000984// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000985def tLSLrr : // A8.6.89
986 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
987 IIC_iMOVsr,
988 "lsl", "\t$Rdn, $Rm",
989 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000990
David Goodwinc9ee1182009-06-25 22:49:55 +0000991// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000992def tLSRri : // A8.6.90
993 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
994 IIC_iMOVsi,
995 "lsr", "\t$Rd, $Rm, $imm5",
996 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000997 bits<5> imm5;
998 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000999}
Evan Chenga8e29892007-01-19 07:51:42 +00001000
David Goodwinc9ee1182009-06-25 22:49:55 +00001001// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001002def tLSRrr : // A8.6.91
1003 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1004 IIC_iMOVsr,
1005 "lsr", "\t$Rdn, $Rm",
1006 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001007
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001008// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001009let isMoveImm = 1 in
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00001010def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001011 "mov", "\t$Rd, $imm8",
1012 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1013 T1General<{1,0,0,?,?}> {
1014 // A8.6.96
1015 bits<3> Rd;
1016 bits<8> imm8;
1017 let Inst{10-8} = Rd;
1018 let Inst{7-0} = imm8;
1019}
Evan Chenga8e29892007-01-19 07:51:42 +00001020
Jim Grosbachefeedce2011-07-01 17:14:11 +00001021// A7-73: MOV(2) - mov setting flag.
Evan Chenga8e29892007-01-19 07:51:42 +00001022
Evan Chengcd799b92009-06-12 20:46:18 +00001023let neverHasSideEffects = 1 in {
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001024def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson16884412011-07-13 23:22:26 +00001025 2, IIC_iMOVr,
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001026 "mov", "\t$Rd, $Rm", "", []>,
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001027 T1Special<{1,0,?,?}> {
Bill Wendling534a5e42010-12-03 01:55:47 +00001028 // A8.6.97
1029 bits<4> Rd;
1030 bits<4> Rm;
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001031 let Inst{7} = Rd{3};
1032 let Inst{6-3} = Rm;
Bill Wendling534a5e42010-12-03 01:55:47 +00001033 let Inst{2-0} = Rd{2-0};
1034}
Evan Cheng446c4282009-07-11 06:43:01 +00001035let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001036def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1037 "movs\t$Rd, $Rm", []>, Encoding16 {
1038 // A8.6.97
1039 bits<3> Rd;
1040 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001041 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001042 let Inst{5-3} = Rm;
1043 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001044}
Evan Chengcd799b92009-06-12 20:46:18 +00001045} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001046
Bill Wendling0480e282010-12-01 02:36:55 +00001047// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001048let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001049def tMUL : // A8.6.105 T1
1050 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1051 IIC_iMUL32,
1052 "mul", "\t$Rdn, $Rm, $Rdn",
1053 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001054
Bill Wendling76f4e102010-12-01 01:20:15 +00001055// Move inverse register
1056def tMVN : // A8.6.107
1057 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1058 "mvn", "\t$Rd, $Rn",
1059 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001060
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001061// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001062let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001063def tORR : // A8.6.114
1064 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1065 IIC_iBITr,
1066 "orr", "\t$Rdn, $Rm",
1067 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001068
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001069// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001070def tREV : // A8.6.134
1071 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1072 IIC_iUNAr,
1073 "rev", "\t$Rd, $Rm",
1074 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1075 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001076
Bill Wendling1d045ee2010-12-01 02:28:08 +00001077def tREV16 : // A8.6.135
1078 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1079 IIC_iUNAr,
1080 "rev16", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001081 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001082 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001083
Bill Wendling1d045ee2010-12-01 02:28:08 +00001084def tREVSH : // A8.6.136
1085 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1086 IIC_iUNAr,
1087 "revsh", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001088 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001089 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001090
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001091// Rotate right register
1092def tROR : // A8.6.139
1093 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1094 IIC_iMOVsr,
1095 "ror", "\t$Rdn, $Rm",
1096 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001097
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001098// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001099def tRSB : // A8.6.141
1100 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1101 IIC_iALUi,
1102 "rsb", "\t$Rd, $Rn, #0",
1103 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001104
David Goodwinc9ee1182009-06-25 22:49:55 +00001105// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001106let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001107def tSBC : // A8.6.151
1108 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1109 IIC_iALUr,
1110 "sbc", "\t$Rdn, $Rm",
1111 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001112
David Goodwinc9ee1182009-06-25 22:49:55 +00001113// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001114def tSUBi3 : // A8.6.210 T1
1115 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1116 IIC_iALUi,
1117 "sub", "\t$Rd, $Rm, $imm3",
1118 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001119 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001120 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001121}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001122
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001123def tSUBi8 : // A8.6.210 T2
1124 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1125 IIC_iALUi,
1126 "sub", "\t$Rdn, $imm8",
1127 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001128
Bill Wendling76f4e102010-12-01 01:20:15 +00001129// Subtract register
1130def tSUBrr : // A8.6.212
1131 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1132 IIC_iALUr,
1133 "sub", "\t$Rd, $Rn, $Rm",
1134 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001135
1136// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001137
Bill Wendling76f4e102010-12-01 01:20:15 +00001138// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001139def tSXTB : // A8.6.222
1140 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1141 IIC_iUNAr,
1142 "sxtb", "\t$Rd, $Rm",
1143 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1144 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001145
Bill Wendling1d045ee2010-12-01 02:28:08 +00001146// Sign-extend short
1147def tSXTH : // A8.6.224
1148 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1149 IIC_iUNAr,
1150 "sxth", "\t$Rd, $Rm",
1151 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1152 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001153
Bill Wendling1d045ee2010-12-01 02:28:08 +00001154// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001155let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001156def tTST : // A8.6.230
1157 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1158 "tst", "\t$Rn, $Rm",
1159 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001160
Bill Wendling1d045ee2010-12-01 02:28:08 +00001161// Zero-extend byte
1162def tUXTB : // A8.6.262
1163 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1164 IIC_iUNAr,
1165 "uxtb", "\t$Rd, $Rm",
1166 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1167 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001168
Bill Wendling1d045ee2010-12-01 02:28:08 +00001169// Zero-extend short
1170def tUXTH : // A8.6.264
1171 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1172 IIC_iUNAr,
1173 "uxth", "\t$Rd, $Rm",
1174 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1175 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001176
Jim Grosbach80dc1162010-02-16 21:23:02 +00001177// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001178// Expanded after instruction selection into a branch sequence.
1179let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001180 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001181 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001182 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001183 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001184
1185// tLEApcrel - Load a pc-relative address into a register without offending the
1186// assembler.
Jim Grosbachd40963c2010-12-14 22:28:03 +00001187
1188def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1189 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1190 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling67077412010-11-30 00:18:30 +00001191 bits<3> Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001192 bits<8> addr;
Bill Wendling67077412010-11-30 00:18:30 +00001193 let Inst{10-8} = Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001194 let Inst{7-0} = addr;
Bill Wendling67077412010-11-30 00:18:30 +00001195}
Evan Chenga8e29892007-01-19 07:51:42 +00001196
Jim Grosbachd40963c2010-12-14 22:28:03 +00001197let neverHasSideEffects = 1, isReMaterializable = 1 in
1198def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001199 2, IIC_iALUi, []>;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001200
1201def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1202 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001203 2, IIC_iALUi, []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001204
Evan Chenga8e29892007-01-19 07:51:42 +00001205//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001206// TLS Instructions
1207//
1208
1209// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbachff97eb02011-06-30 19:38:01 +00001210// This is a pseudo inst so that we can get the encoding right,
1211// complete with fixup for the aeabi_read_tp function.
1212let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson16884412011-07-13 23:22:26 +00001213def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Jim Grosbachff97eb02011-06-30 19:38:01 +00001214 [(set R0, ARMthread_pointer)]>;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001215
Bill Wendling0480e282010-12-01 02:36:55 +00001216//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001217// SJLJ Exception handling intrinsics
Owen Anderson18901d62011-05-11 17:00:48 +00001218//
Bill Wendling0480e282010-12-01 02:36:55 +00001219
1220// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1221// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1222// from some other function to get here, and we're using the stack frame for the
1223// containing function to save/restore registers, we can't keep anything live in
1224// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner7a2bdde2011-04-15 05:18:47 +00001225// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling0480e282010-12-01 02:36:55 +00001226// registers except for our own input by listing the relevant registers in
1227// Defs. By doing so, we also cause the prologue/epilogue code to actively
1228// preserve all of the callee-saved resgisters, which is exactly what we want.
1229// $val is a scratch register for our use.
Andrew Tricka1099f12011-06-07 00:08:49 +00001230let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001231 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1232def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson16884412011-07-13 23:22:26 +00001233 AddrModeNone, 0, NoItinerary, "","",
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001234 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001235
1236// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001237let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001238 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001239def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson16884412011-07-13 23:22:26 +00001240 AddrModeNone, 0, IndexModeNone,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001241 Pseudo, NoItinerary, "", "",
1242 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1243 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001244
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001245//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001246// Non-Instruction Patterns
1247//
1248
Jim Grosbach97a884d2010-12-07 20:41:06 +00001249// Comparisons
1250def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1251 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1252def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1253 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1254
Evan Cheng892837a2009-07-10 02:09:04 +00001255// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001256def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1257 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1258def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001259 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001260def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1261 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001262
1263// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001264def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1265 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1266def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1267 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1268def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1269 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001270
Evan Chenga8e29892007-01-19 07:51:42 +00001271// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001272def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1273def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001274
Evan Chengd85ac4d2007-01-27 02:29:45 +00001275// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001276def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1277 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001278
Evan Chenga8e29892007-01-19 07:51:42 +00001279// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001280def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001281 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001282def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001283 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001284
1285def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001286 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001287def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001288 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001289
1290// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001291def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1292 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1293def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1294 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001295
1296// zextload i1 -> zextload i8
Bill Wendlingf4caf692010-12-14 03:36:38 +00001297def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1298 (tLDRBr t_addrmode_rrs1:$addr)>;
1299def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1300 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001301
Evan Chengb60c02e2007-01-26 19:13:16 +00001302// extload -> zextload
Bill Wendlingf4caf692010-12-14 03:36:38 +00001303def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1304def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1305def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1306def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1307def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1308def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001309
Evan Cheng0e87e232009-08-28 00:31:43 +00001310// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001311// ldr{b|h} + sxt{b|h} instead.
Bill Wendling415af342010-12-15 00:58:57 +00001312def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1313 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1314 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001315def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1316 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001317 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling415af342010-12-15 00:58:57 +00001318def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1319 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1320 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001321def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1322 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001323 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001324
Bill Wendlingf4caf692010-12-14 03:36:38 +00001325def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1326 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling415af342010-12-15 00:58:57 +00001327def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1328 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1329def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1330 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1331def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1332 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001333
Evan Chenga8e29892007-01-19 07:51:42 +00001334// Large immediate handling.
1335
1336// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001337def : T1Pat<(i32 thumb_immshifted:$src),
1338 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1339 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001340
Evan Cheng9cb9e672009-06-27 02:26:13 +00001341def : T1Pat<(i32 imm0_255_comp:$src),
1342 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001343
1344// Pseudo instruction that combines ldr from constpool and add pc. This should
1345// be expanded into two instructions late to allow if-conversion and
1346// scheduling.
1347let isReMaterializable = 1 in
1348def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001349 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001350 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1351 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001352 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach53e3fc42011-07-08 17:40:42 +00001353
1354// Pseudo-instruction for merged POP and return.
1355// FIXME: remove when we have a way to marking a MI with these properties.
1356let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1357 hasExtraDefRegAllocReq = 1 in
1358def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +00001359 2, IIC_iPop_Br, [],
Jim Grosbach53e3fc42011-07-08 17:40:42 +00001360 (tPOP pred:$p, reglist:$regs)>;
1361
Jim Grosbachaa8d1b82011-07-08 22:25:23 +00001362// Indirect branch using "mov pc, $Rm"
1363let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach7e61a312011-07-08 22:33:49 +00001364 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001365 2, IIC_Br, [(brind GPR:$Rm)],
Jim Grosbach7e61a312011-07-08 22:33:49 +00001366 (tMOVr PC, GPR:$Rm, pred:$p)>;
Jim Grosbachaa8d1b82011-07-08 22:25:23 +00001367}