blob: 58c20347155b88b388eb800bb5626eb2b89261c0 [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 Lattner60e9eac2010-03-19 05:33:51 +000019 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag,
20 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 +000029/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
30def imm0_7 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000031 return (uint32_t)N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000032}]>;
33def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000034 return (uint32_t)-N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000035}], imm_neg_XFORM>;
36
37def imm0_255 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000038 return (uint32_t)N->getZExtValue() < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000039}]>;
40def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000041 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000042}]>;
43
44def imm8_255 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000045 return (uint32_t)N->getZExtValue() >= 8 && (uint32_t)N->getZExtValue() < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000046}]>;
47def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000048 unsigned Val = -N->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +000049 return Val >= 8 && Val < 256;
50}], imm_neg_XFORM>;
51
Bill Wendling0480e282010-12-01 02:36:55 +000052// Break imm's up into two pieces: an immediate + a left shift. This uses
53// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
54// to get the val/shift pieces.
Evan Chenga8e29892007-01-19 07:51:42 +000055def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000056 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000057}]>;
58
59def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000060 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000061 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000062}]>;
63
64def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000065 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000066 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000067}]>;
68
Jim Grosbachd40963c2010-12-14 22:28:03 +000069// ADR instruction labels.
70def t_adrlabel : Operand<i32> {
71 let EncoderMethod = "getThumbAdrLabelOpValue";
72}
73
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000074// Scaled 4 immediate.
75def t_imm_s4 : Operand<i32> {
76 let PrintMethod = "printThumbS4ImmOperand";
77}
78
Evan Chenga8e29892007-01-19 07:51:42 +000079// Define Thumb specific addressing modes.
80
Jim Grosbache2467172010-12-10 18:21:33 +000081def t_brtarget : Operand<OtherVT> {
82 let EncoderMethod = "getThumbBRTargetOpValue";
83}
84
Jim Grosbach01086452010-12-10 17:13:40 +000085def t_bcctarget : Operand<i32> {
86 let EncoderMethod = "getThumbBCCTargetOpValue";
87}
88
Jim Grosbachcf6220a2010-12-09 19:01:46 +000089def t_cbtarget : Operand<i32> {
Jim Grosbach027d6e82010-12-09 19:04:53 +000090 let EncoderMethod = "getThumbCBTargetOpValue";
Bill Wendlingdff2f712010-12-08 23:01:43 +000091}
92
Jim Grosbach662a8162010-12-06 23:57:07 +000093def t_bltarget : Operand<i32> {
94 let EncoderMethod = "getThumbBLTargetOpValue";
95}
96
Bill Wendling09aa3f02010-12-09 00:39:08 +000097def t_blxtarget : Operand<i32> {
98 let EncoderMethod = "getThumbBLXTargetOpValue";
99}
100
Bill Wendlingf4caf692010-12-14 03:36:38 +0000101def MemModeRegThumbAsmOperand : AsmOperandClass {
102 let Name = "MemModeRegThumb";
103 let SuperClasses = [];
104}
105
106def MemModeImmThumbAsmOperand : AsmOperandClass {
107 let Name = "MemModeImmThumb";
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000108 let SuperClasses = [];
109}
110
Evan Chenga8e29892007-01-19 07:51:42 +0000111// t_addrmode_rr := reg + reg
112//
113def t_addrmode_rr : Operand<i32>,
114 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000115 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000116 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000117 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000118}
119
Bill Wendlingf4caf692010-12-14 03:36:38 +0000120// t_addrmode_rrs := reg + reg
Evan Chenga8e29892007-01-19 07:51:42 +0000121//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000122def t_addrmode_rrs1 : Operand<i32>,
123 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
124 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
125 let PrintMethod = "printThumbAddrModeRROperand";
126 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
127 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000128}
Bill Wendlingf4caf692010-12-14 03:36:38 +0000129def t_addrmode_rrs2 : Operand<i32>,
130 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
131 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
132 let PrintMethod = "printThumbAddrModeRROperand";
133 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
134 let ParserMatchClass = MemModeRegThumbAsmOperand;
135}
136def t_addrmode_rrs4 : Operand<i32>,
137 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
138 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
139 let PrintMethod = "printThumbAddrModeRROperand";
140 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
141 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000142}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000143
Bill Wendlingf4caf692010-12-14 03:36:38 +0000144// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc38f2bc2007-01-23 22:59:13 +0000145//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000146def t_addrmode_is4 : Operand<i32>,
147 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
148 let EncoderMethod = "getAddrModeISOpValue";
149 let PrintMethod = "printThumbAddrModeImm5S4Operand";
150 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
151 let ParserMatchClass = MemModeImmThumbAsmOperand;
152}
153
154// t_addrmode_is2 := reg + imm5 * 2
155//
156def t_addrmode_is2 : Operand<i32>,
157 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
158 let EncoderMethod = "getAddrModeISOpValue";
159 let PrintMethod = "printThumbAddrModeImm5S2Operand";
160 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
161 let ParserMatchClass = MemModeImmThumbAsmOperand;
162}
163
164// t_addrmode_is1 := reg + imm5
165//
166def t_addrmode_is1 : Operand<i32>,
167 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
168 let EncoderMethod = "getAddrModeISOpValue";
169 let PrintMethod = "printThumbAddrModeImm5S1Operand";
170 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
171 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000172}
173
174// t_addrmode_sp := sp + imm8 * 4
175//
176def t_addrmode_sp : Operand<i32>,
177 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbachd967cd02010-12-07 21:50:47 +0000178 let EncoderMethod = "getAddrModeThumbSPOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000179 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000180 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000181 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000182}
183
Bill Wendlingb8958b02010-12-08 01:57:09 +0000184// t_addrmode_pc := <label> => pc + imm8 * 4
185//
186def t_addrmode_pc : Operand<i32> {
187 let EncoderMethod = "getAddrModePCOpValue";
Bill Wendlingf4caf692010-12-14 03:36:38 +0000188 let ParserMatchClass = MemModeImmThumbAsmOperand;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000189}
190
Evan Chenga8e29892007-01-19 07:51:42 +0000191//===----------------------------------------------------------------------===//
192// Miscellaneous Instructions.
193//
194
Jim Grosbach4642ad32010-02-22 23:10:38 +0000195// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
196// from removing one half of the matched pairs. That breaks PEI, which assumes
197// these will always be in pairs, and asserts if it finds otherwise. Better way?
198let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000199def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000200 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
201 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
202 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000203
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000204def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000205 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
206 [(ARMcallseq_start imm:$amt)]>,
207 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000208}
Evan Cheng44bec522007-05-15 01:29:07 +0000209
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000210// T1Disassembly - A simple class to make encoding some disassembly patterns
211// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000212class T1Disassembly<bits<2> op1, bits<8> op2>
213 : T1Encoding<0b101111> {
214 let Inst{9-8} = op1;
215 let Inst{7-0} = op2;
216}
217
Johnny Chenbd2c6232010-02-25 03:28:51 +0000218def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
219 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000220 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000221
Johnny Chend86d2692010-02-25 17:51:03 +0000222def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
223 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000224 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000225
226def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
227 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000228 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000229
230def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
231 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000232 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000233
234def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
235 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000236 T1Disassembly<0b11, 0x40>; // A8.6.157
237
238// The i32imm operand $val can be used by a debugger to store more information
239// about the breakpoint.
240def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
241 [/* For disassembly only; pattern left blank */]>,
242 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
243 // A8.6.22
244 bits<8> val;
245 let Inst{7-0} = val;
246}
Johnny Chend86d2692010-02-25 17:51:03 +0000247
248def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
249 [/* For disassembly only; pattern left blank */]>,
250 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000251 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000252 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000253 let Inst{4} = 1;
254 let Inst{3} = 1; // Big-Endian
255 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000256}
257
258def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
259 [/* For disassembly only; pattern left blank */]>,
260 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000261 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000262 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000263 let Inst{4} = 1;
264 let Inst{3} = 0; // Little-Endian
265 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000266}
267
Johnny Chen93042d12010-03-02 18:14:57 +0000268// Change Processor State is a system instruction -- for disassembly only.
269// The singleton $opt operand contains the following information:
Bill Wendling0480e282010-12-01 02:36:55 +0000270//
271// opt{4-0} = mode ==> don't care
272// opt{5} = changemode ==> 0 (false for 16-bit Thumb instr)
273// opt{8-6} = AIF from Inst{2-0}
274// opt{10-9} = 1:imod from Inst{4} with 0b10 as enable and 0b11 as disable
Johnny Chen93042d12010-03-02 18:14:57 +0000275//
276// The opt{4-0} and opt{5} sub-fields are to accommodate 32-bit Thumb and ARM
277// CPS which has more options.
Johnny Chendd0f3cf2010-03-10 18:59:38 +0000278def tCPS : T1I<(outs), (ins cps_opt:$opt), NoItinerary, "cps$opt",
Johnny Chen93042d12010-03-02 18:14:57 +0000279 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000280 T1Misc<0b0110011> {
281 // A8.6.38 & B6.1.1
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000282 let Inst{3} = 0;
283 // FIXME: Finish encoding.
Bill Wendling849f2e32010-11-29 00:18:15 +0000284}
Johnny Chen93042d12010-03-02 18:14:57 +0000285
Evan Cheng35d6c412009-08-04 23:47:55 +0000286// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000287let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000288def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000289 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000290 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000291 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000292 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000293 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000294 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000295}
Evan Chenga8e29892007-01-19 07:51:42 +0000296
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000297// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000298def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000299 "add\t$dst, pc, $rhs", []>,
300 T1Encoding<{1,0,1,0,0,?}> {
301 // A6.2 & A8.6.10
302 bits<3> dst;
303 bits<8> rhs;
304 let Inst{10-8} = dst;
305 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000306}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000307
Bill Wendling0ae28e42010-11-19 22:37:33 +0000308// ADD <Rd>, sp, #<imm8>
309// This is rematerializable, which is particularly useful for taking the
310// address of locals.
311let isReMaterializable = 1 in
312def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
313 "add\t$dst, $sp, $rhs", []>,
314 T1Encoding<{1,0,1,0,1,?}> {
315 // A6.2 & A8.6.8
316 bits<3> dst;
317 bits<8> rhs;
318 let Inst{10-8} = dst;
319 let Inst{7-0} = rhs;
320}
321
322// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000323def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000324 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000325 T1Misc<{0,0,0,0,0,?,?}> {
326 // A6.2.5 & A8.6.8
327 bits<7> rhs;
328 let Inst{6-0} = rhs;
329}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000330
Bill Wendling0ae28e42010-11-19 22:37:33 +0000331// SUB sp, sp, #<imm7>
332// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000333def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000334 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000335 T1Misc<{0,0,0,0,1,?,?}> {
336 // A6.2.5 & A8.6.214
337 bits<7> rhs;
338 let Inst{6-0} = rhs;
339}
Evan Cheng86198642009-08-07 00:34:42 +0000340
Bill Wendling0ae28e42010-11-19 22:37:33 +0000341// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000342def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000343 "add\t$dst, $rhs", []>,
344 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000345 // A8.6.9 Encoding T1
346 bits<4> dst;
347 let Inst{7} = dst{3};
348 let Inst{6-3} = 0b1101;
349 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000350}
Evan Cheng86198642009-08-07 00:34:42 +0000351
Bill Wendling0ae28e42010-11-19 22:37:33 +0000352// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000353def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000354 "add\t$dst, $rhs", []>,
355 T1Special<{0,0,?,?}> {
356 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000357 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000358 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000359 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000360 let Inst{2-0} = 0b101;
361}
Evan Cheng86198642009-08-07 00:34:42 +0000362
Evan Chenga8e29892007-01-19 07:51:42 +0000363//===----------------------------------------------------------------------===//
364// Control Flow Instructions.
365//
366
Jim Grosbachc732adf2009-09-30 01:35:11 +0000367let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Bill Wendling602890d2010-11-19 01:33:10 +0000368 def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr",
369 [(ARMretflag)]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000370 T1Special<{1,1,0,?}> {
371 // A6.2.3 & A8.6.25
Johnny Chend68e1192009-12-15 17:24:14 +0000372 let Inst{6-3} = 0b1110; // Rm = lr
Bill Wendling602890d2010-11-19 01:33:10 +0000373 let Inst{2-0} = 0b000;
Johnny Chend68e1192009-12-15 17:24:14 +0000374 }
Bill Wendling602890d2010-11-19 01:33:10 +0000375
Evan Cheng9d945f72007-02-01 01:49:46 +0000376 // Alternative return instruction used by vararg functions.
Bill Wendling602890d2010-11-19 01:33:10 +0000377 def tBX_RET_vararg : TI<(outs), (ins tGPR:$Rm),
378 IIC_Br, "bx\t$Rm",
379 []>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000380 T1Special<{1,1,0,?}> {
381 // A6.2.3 & A8.6.25
Bill Wendling602890d2010-11-19 01:33:10 +0000382 bits<4> Rm;
383 let Inst{6-3} = Rm;
384 let Inst{2-0} = 0b000;
385 }
Evan Cheng9d945f72007-02-01 01:49:46 +0000386}
Evan Chenga8e29892007-01-19 07:51:42 +0000387
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000388// Indirect branches
389let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Bill Wendling534a5e42010-12-03 01:55:47 +0000390 def tBRIND : TI<(outs), (ins GPR:$Rm),
391 IIC_Br,
392 "mov\tpc, $Rm",
Bill Wendling602890d2010-11-19 01:33:10 +0000393 [(brind GPR:$Rm)]>,
Bill Wendling12280382010-11-19 23:14:32 +0000394 T1Special<{1,0,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000395 // A8.6.97
Bill Wendling602890d2010-11-19 01:33:10 +0000396 bits<4> Rm;
Bill Wendling849f2e32010-11-29 00:18:15 +0000397 let Inst{7} = 1; // <Rd> = Inst{7:2-0} = pc
Bill Wendling602890d2010-11-19 01:33:10 +0000398 let Inst{6-3} = Rm;
Bill Wendling12280382010-11-19 23:14:32 +0000399 let Inst{2-0} = 0b111;
Johnny Chend68e1192009-12-15 17:24:14 +0000400 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000401}
402
Evan Chenga8e29892007-01-19 07:51:42 +0000403// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000404let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
405 hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000406def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000407 IIC_iPop_Br,
Bill Wendling602890d2010-11-19 01:33:10 +0000408 "pop${p}\t$regs", []>,
409 T1Misc<{1,1,0,?,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000410 // A8.6.121
Bill Wendling602890d2010-11-19 01:33:10 +0000411 bits<16> regs;
Bill Wendling849f2e32010-11-29 00:18:15 +0000412 let Inst{8} = regs{15}; // registers = P:'0000000':register_list
Bill Wendling602890d2010-11-19 01:33:10 +0000413 let Inst{7-0} = regs{7-0};
414}
Evan Chenga8e29892007-01-19 07:51:42 +0000415
Bill Wendling0480e282010-12-01 02:36:55 +0000416// All calls clobber the non-callee saved registers. SP is marked as a use to
417// prevent stack-pointer assignments that appear immediately before calls from
418// potentially appearing dead.
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000419let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000420 // On non-Darwin platforms R9 is callee-saved.
Evan Cheng756da122009-07-22 06:46:53 +0000421 Defs = [R0, R1, R2, R3, R12, LR,
422 D0, D1, D2, D3, D4, D5, D6, D7,
423 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000424 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
425 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000426 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000427 def tBL : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000428 (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000429 "bl\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000430 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000431 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000432 bits<21> func;
433 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000434 let Inst{13} = 1;
435 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000436 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000437 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000438
Evan Chengb6207242009-08-01 00:16:10 +0000439 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000440 def tBLXi : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000441 (outs), (ins t_blxtarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000442 "blx\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000443 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000444 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000445 bits<21> func;
446 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000447 let Inst{13} = 1;
448 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000449 let Inst{10-1} = func{10-1};
450 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000451 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000452
Evan Chengb6207242009-08-01 00:16:10 +0000453 // Also used for Thumb2
Jim Grosbach64171712010-02-16 21:07:46 +0000454 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000455 "blx\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000456 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000457 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
458 T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000459
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000460 // ARMv4T
Jim Grosbachd2535452010-12-03 18:37:17 +0000461 // FIXME: Should be a pseudo.
Chris Lattner4d1189f2010-11-01 00:46:16 +0000462 let isCodeGenOnly = 1 in
Johnny Chend68e1192009-12-15 17:24:14 +0000463 def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?,
Jim Grosbach64171712010-02-16 21:07:46 +0000464 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000465 "mov\tlr, pc\n\tbx\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000466 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000467 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000468}
469
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000470let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000471 // On Darwin R9 is call-clobbered.
472 // R7 is marked as a use to prevent frame-pointer assignments from being
473 // moved above / below calls.
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000474 Defs = [R0, R1, R2, R3, R9, R12, LR,
475 D0, D1, D2, D3, D4, D5, D6, D7,
476 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000477 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
478 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000479 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000480 def tBLr9 : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000481 (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
482 IIC_Br, "bl${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000483 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000484 Requires<[IsThumb, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000485 bits<21> func;
486 let Inst{25-16} = func{20-11};
487 let Inst{13} = 1;
488 let Inst{11} = 1;
489 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000490 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000491
Evan Chengb6207242009-08-01 00:16:10 +0000492 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000493 def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000494 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
Jim Grosbach662a8162010-12-06 23:57:07 +0000495 IIC_Br, "blx${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000496 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000497 Requires<[IsThumb, HasV5T, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000498 bits<21> func;
499 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000500 let Inst{13} = 1;
501 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000502 let Inst{10-1} = func{10-1};
503 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000504 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000505
Evan Chengb6207242009-08-01 00:16:10 +0000506 // Also used for Thumb2
Bill Wendling849f2e32010-11-29 00:18:15 +0000507 def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
508 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000509 [(ARMtcall GPR:$func)]>,
510 Requires<[IsThumb, HasV5T, IsDarwin]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000511 T1Special<{1,1,1,?}> {
512 // A6.2.3 & A8.6.24
513 bits<4> func;
514 let Inst{6-3} = func;
515 let Inst{2-0} = 0b000;
516 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000517
518 // ARMv4T
Chris Lattner4d1189f2010-11-01 00:46:16 +0000519 let isCodeGenOnly = 1 in
Jim Grosbachd2535452010-12-03 18:37:17 +0000520 // FIXME: Should be a pseudo.
Johnny Chend68e1192009-12-15 17:24:14 +0000521 def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?,
Jim Grosbach64171712010-02-16 21:07:46 +0000522 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000523 "mov\tlr, pc\n\tbx\t$func",
524 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000525 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000526}
527
Bill Wendling0480e282010-12-01 02:36:55 +0000528let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
529 let isPredicable = 1 in
Jim Grosbache2467172010-12-10 18:21:33 +0000530 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
Bill Wendling0480e282010-12-01 02:36:55 +0000531 "b\t$target", [(br bb:$target)]>,
Jim Grosbache2467172010-12-10 18:21:33 +0000532 T1Encoding<{1,1,1,0,0,?}> {
533 bits<11> target;
534 let Inst{10-0} = target;
535 }
Evan Chenga8e29892007-01-19 07:51:42 +0000536
Evan Cheng225dfe92007-01-30 01:13:37 +0000537 // Far jump
Jim Grosbache2467172010-12-10 18:21:33 +0000538 // FIXME: Encoding. This should probably be a pseudo for tBL
Evan Cheng53c67c02009-08-07 05:45:07 +0000539 let Defs = [LR] in
Jim Grosbach64171712010-02-16 21:07:46 +0000540 def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
Jim Grosbach78890f42010-10-01 23:21:38 +0000541 "bl\t$target",[]>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000542
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000543 def tBR_JTr : tPseudoInst<(outs),
544 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
545 Size2Bytes, IIC_Br,
546 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
547 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000548 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000549}
550
Evan Chengc85e8322007-07-05 07:13:32 +0000551// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000552// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000553let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000554 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000555 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000556 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Jim Grosbachceab5012010-12-04 00:20:40 +0000557 T1Encoding<{1,1,0,1,?,?}> {
558 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000559 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000560 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000561 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000562}
Evan Chenga8e29892007-01-19 07:51:42 +0000563
Evan Chengde17fb62009-10-31 23:46:45 +0000564// Compare and branch on zero / non-zero
565let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000566 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000567 "cbz\t$Rn, $target", []>,
568 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000569 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000570 bits<6> target;
571 bits<3> Rn;
572 let Inst{9} = target{5};
573 let Inst{7-3} = target{4-0};
574 let Inst{2-0} = Rn;
575 }
Evan Chengde17fb62009-10-31 23:46:45 +0000576
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000577 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000578 "cbnz\t$cmp, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000579 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000580 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000581 bits<6> target;
582 bits<3> Rn;
583 let Inst{9} = target{5};
584 let Inst{7-3} = target{4-0};
585 let Inst{2-0} = Rn;
586 }
Evan Chengde17fb62009-10-31 23:46:45 +0000587}
588
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000589// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
590// A8.6.16 B: Encoding T1
591// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000592let isCall = 1, Uses = [SP] in
Bill Wendling6179c312010-11-20 00:53:35 +0000593def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
594 "svc", "\t$imm", []>, Encoding16 {
595 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000596 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000597 let Inst{11-8} = 0b1111;
598 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000599}
600
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000601// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000602let isBarrier = 1, isTerminator = 1 in
Anton Korobeynikov418d1d92010-05-15 17:19:20 +0000603def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000604 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000605 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000606}
607
Evan Chenga8e29892007-01-19 07:51:42 +0000608//===----------------------------------------------------------------------===//
609// Load Store Instructions.
610//
611
Bill Wendlingb6faf652010-12-14 22:10:49 +0000612// Loads: reg/reg and reg/imm5
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000613let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb6faf652010-12-14 22:10:49 +0000614multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
615 Operand AddrMode_r, Operand AddrMode_i,
616 AddrMode am, InstrItinClass itin_r,
617 InstrItinClass itin_i, string asm,
618 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000619 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000620 T1pILdStEncode<reg_opc,
621 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
622 am, itin_r, asm, "\t$Rt, $addr",
623 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000624 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000625 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
626 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
627 am, itin_i, asm, "\t$Rt, $addr",
628 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
629}
630// Stores: reg/reg and reg/imm5
631multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
632 Operand AddrMode_r, Operand AddrMode_i,
633 AddrMode am, InstrItinClass itin_r,
634 InstrItinClass itin_i, string asm,
635 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000636 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000637 T1pILdStEncode<reg_opc,
638 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
639 am, itin_r, asm, "\t$Rt, $addr",
640 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000641 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000642 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
643 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
644 am, itin_i, asm, "\t$Rt, $addr",
645 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
646}
Bill Wendling6179c312010-11-20 00:53:35 +0000647
Bill Wendlingb6faf652010-12-14 22:10:49 +0000648// A8.6.57 & A8.6.60
649defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
650 t_addrmode_is4, AddrModeT1_4,
651 IIC_iLoad_r, IIC_iLoad_i, "ldr",
652 UnOpFrag<(load node:$Src)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000653
Bill Wendlingb6faf652010-12-14 22:10:49 +0000654// A8.6.64 & A8.6.61
655defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
656 t_addrmode_is1, AddrModeT1_1,
657 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
658 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000659
Bill Wendlingb6faf652010-12-14 22:10:49 +0000660// A8.6.76 & A8.6.73
661defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
662 t_addrmode_is2, AddrModeT1_2,
663 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
664 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000665
Evan Cheng2f297df2009-07-11 07:08:13 +0000666let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000667def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000668 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
669 AddrModeT1_1, IIC_iLoad_bh_r,
670 "ldrsb", "\t$dst, $addr",
671 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000672
Evan Cheng2f297df2009-07-11 07:08:13 +0000673let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000674def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000675 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
676 AddrModeT1_2, IIC_iLoad_bh_r,
677 "ldrsh", "\t$dst, $addr",
678 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000679
Dan Gohman15511cf2008-12-03 18:15:48 +0000680let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000681def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000682 "ldr", "\t$Rt, $addr",
683 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000684 T1LdStSP<{1,?,?}> {
685 bits<3> Rt;
686 bits<8> addr;
687 let Inst{10-8} = Rt;
688 let Inst{7-0} = addr;
689}
Evan Cheng012f2d92007-01-24 08:53:17 +0000690
Evan Cheng8e59ea92007-02-07 00:06:56 +0000691// Special instruction for restore. It cannot clobber condition register
692// when it's expanded by eliminateCallFramePseudoInstr().
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000693let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000694// FIXME: Pseudo for tLDRspi
Evan Cheng0e55fd62010-09-30 01:08:25 +0000695def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000696 "ldr", "\t$dst, $addr", []>,
Johnny Chend68e1192009-12-15 17:24:14 +0000697 T1LdStSP<{1,?,?}>;
Evan Cheng8e59ea92007-02-07 00:06:56 +0000698
Evan Cheng012f2d92007-01-24 08:53:17 +0000699// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000700// FIXME: Use ldr.n to work around a Darwin assembler bug.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000701let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000702def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000703 "ldr", ".n\t$Rt, $addr",
704 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
705 T1Encoding<{0,1,0,0,1,?}> {
706 // A6.2 & A8.6.59
707 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000708 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000709 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000710 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000711}
Evan Chengfa775d02007-03-19 07:20:03 +0000712
713// Special LDR for loads from non-pc-relative constpools.
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000714let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
715 isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000716def tLDRcp : T1pIs<(outs tGPR:$Rt), (ins i32imm:$addr), IIC_iLoad_i,
717 "ldr", "\t$Rt, $addr", []>,
718 T1LdStSP<{1,?,?}> {
719 // A6.2 & A8.6.57 T2
720 bits<3> Rt;
721 bits<8> addr;
722 let Inst{10-8} = Rt;
723 let Inst{7-0} = addr;
724}
Evan Chenga8e29892007-01-19 07:51:42 +0000725
Bill Wendlingb6faf652010-12-14 22:10:49 +0000726// A8.6.194 & A8.6.192
727defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
728 t_addrmode_is4, AddrModeT1_4,
729 IIC_iStore_r, IIC_iStore_i, "str",
730 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000731
Bill Wendlingb6faf652010-12-14 22:10:49 +0000732// A8.6.197 & A8.6.195
733defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
734 t_addrmode_is1, AddrModeT1_1,
735 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
736 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000737
Bill Wendlingb6faf652010-12-14 22:10:49 +0000738// A8.6.207 & A8.6.205
739defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
740 t_addrmode_is2, AddrModeT1_2,
741 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
742 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000743
Evan Chenga8e29892007-01-19 07:51:42 +0000744
Jim Grosbachd967cd02010-12-07 21:50:47 +0000745def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendlingf4caf692010-12-14 03:36:38 +0000746 "str", "\t$Rt, $addr",
747 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000748 T1LdStSP<{0,?,?}> {
749 bits<3> Rt;
750 bits<8> addr;
751 let Inst{10-8} = Rt;
752 let Inst{7-0} = addr;
753}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000754
Bill Wendling3f8c1102010-11-30 23:54:45 +0000755let mayStore = 1, neverHasSideEffects = 1 in
756// Special instruction for spill. It cannot clobber condition register when it's
757// expanded by eliminateCallFramePseudoInstr().
Jim Grosbachd967cd02010-12-07 21:50:47 +0000758// FIXME: Pseudo for tSTRspi
Evan Cheng0e55fd62010-09-30 01:08:25 +0000759def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000760 "str", "\t$src, $addr", []>,
761 T1LdStSP<{0,?,?}>;
Evan Chenga8e29892007-01-19 07:51:42 +0000762
763//===----------------------------------------------------------------------===//
764// Load / store multiple Instructions.
765//
766
Bill Wendling6c470b82010-11-13 09:09:38 +0000767multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
768 InstrItinClass itin_upd, bits<6> T1Enc,
769 bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000770 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000771 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000772 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000773 T1Encoding<T1Enc> {
774 bits<3> Rn;
775 bits<8> regs;
776 let Inst{10-8} = Rn;
777 let Inst{7-0} = regs;
778 }
Bill Wendling73fe34a2010-11-16 01:16:36 +0000779 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +0000780 T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000781 itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000782 T1Encoding<T1Enc> {
783 bits<3> Rn;
784 bits<8> regs;
785 let Inst{10-8} = Rn;
786 let Inst{7-0} = regs;
787 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000788}
789
Bill Wendling73fe34a2010-11-16 01:16:36 +0000790// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000791let neverHasSideEffects = 1 in {
792
793let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
794defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
795 {1,1,0,0,1,?}, 1>;
796
797let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
798defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
799 {1,1,0,0,0,?}, 0>;
800
801} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000802
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000803let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000804def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000805 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000806 "pop${p}\t$regs", []>,
807 T1Misc<{1,1,0,?,?,?,?}> {
808 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000809 let Inst{8} = regs{15};
810 let Inst{7-0} = regs{7-0};
811}
Evan Cheng4b322e52009-08-11 21:11:32 +0000812
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000813let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000814def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000815 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000816 "push${p}\t$regs", []>,
817 T1Misc<{0,1,0,?,?,?,?}> {
818 bits<16> regs;
819 let Inst{8} = regs{14};
820 let Inst{7-0} = regs{7-0};
821}
Evan Chenga8e29892007-01-19 07:51:42 +0000822
823//===----------------------------------------------------------------------===//
824// Arithmetic Instructions.
825//
826
Bill Wendling1d045ee2010-12-01 02:28:08 +0000827// Helper classes for encoding T1pI patterns:
828class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
829 string opc, string asm, list<dag> pattern>
830 : T1pI<oops, iops, itin, opc, asm, pattern>,
831 T1DataProcessing<opA> {
832 bits<3> Rm;
833 bits<3> Rn;
834 let Inst{5-3} = Rm;
835 let Inst{2-0} = Rn;
836}
837class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
838 string opc, string asm, list<dag> pattern>
839 : T1pI<oops, iops, itin, opc, asm, pattern>,
840 T1Misc<opA> {
841 bits<3> Rm;
842 bits<3> Rd;
843 let Inst{5-3} = Rm;
844 let Inst{2-0} = Rd;
845}
846
Bill Wendling76f4e102010-12-01 01:20:15 +0000847// Helper classes for encoding T1sI patterns:
848class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
849 string opc, string asm, list<dag> pattern>
850 : T1sI<oops, iops, itin, opc, asm, pattern>,
851 T1DataProcessing<opA> {
852 bits<3> Rd;
853 bits<3> Rn;
854 let Inst{5-3} = Rn;
855 let Inst{2-0} = Rd;
856}
857class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
858 string opc, string asm, list<dag> pattern>
859 : T1sI<oops, iops, itin, opc, asm, pattern>,
860 T1General<opA> {
861 bits<3> Rm;
862 bits<3> Rn;
863 bits<3> Rd;
864 let Inst{8-6} = Rm;
865 let Inst{5-3} = Rn;
866 let Inst{2-0} = Rd;
867}
868class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
869 string opc, string asm, list<dag> pattern>
870 : T1sI<oops, iops, itin, opc, asm, pattern>,
871 T1General<opA> {
872 bits<3> Rd;
873 bits<3> Rm;
874 let Inst{5-3} = Rm;
875 let Inst{2-0} = Rd;
876}
877
878// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000879class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
880 string opc, string asm, list<dag> pattern>
881 : T1sIt<oops, iops, itin, opc, asm, pattern>,
882 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000883 bits<3> Rdn;
884 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000885 let Inst{5-3} = Rm;
886 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000887}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000888class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
889 string opc, string asm, list<dag> pattern>
890 : T1sIt<oops, iops, itin, opc, asm, pattern>,
891 T1General<opA> {
892 bits<3> Rdn;
893 bits<8> imm8;
894 let Inst{10-8} = Rdn;
895 let Inst{7-0} = imm8;
896}
897
898// Add with carry register
899let isCommutable = 1, Uses = [CPSR] in
900def tADC : // A8.6.2
901 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
902 "adc", "\t$Rdn, $Rm",
903 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000904
David Goodwinc9ee1182009-06-25 22:49:55 +0000905// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000906def tADDi3 : // A8.6.4 T1
907 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3), IIC_iALUi,
908 "add", "\t$Rd, $Rm, $imm3",
909 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000910 bits<3> imm3;
911 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000912}
Evan Chenga8e29892007-01-19 07:51:42 +0000913
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000914def tADDi8 : // A8.6.4 T2
915 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
916 IIC_iALUi,
917 "add", "\t$Rdn, $imm8",
918 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000919
David Goodwinc9ee1182009-06-25 22:49:55 +0000920// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000921let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000922def tADDrr : // A8.6.6 T1
923 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
924 IIC_iALUr,
925 "add", "\t$Rd, $Rn, $Rm",
926 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000927
Evan Chengcd799b92009-06-12 20:46:18 +0000928let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000929def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
930 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000931 T1Special<{0,0,?,?}> {
932 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000933 bits<4> Rdn;
934 bits<4> Rm;
935 let Inst{7} = Rdn{3};
936 let Inst{6-3} = Rm;
937 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000938}
Evan Chenga8e29892007-01-19 07:51:42 +0000939
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000940// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000941let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000942def tAND : // A8.6.12
943 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
944 IIC_iBITr,
945 "and", "\t$Rdn, $Rm",
946 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000947
David Goodwinc9ee1182009-06-25 22:49:55 +0000948// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000949def tASRri : // A8.6.14
950 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
951 IIC_iMOVsi,
952 "asr", "\t$Rd, $Rm, $imm5",
953 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000954 bits<5> imm5;
955 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000956}
Evan Chenga8e29892007-01-19 07:51:42 +0000957
David Goodwinc9ee1182009-06-25 22:49:55 +0000958// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000959def tASRrr : // A8.6.15
960 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
961 IIC_iMOVsr,
962 "asr", "\t$Rdn, $Rm",
963 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000964
David Goodwinc9ee1182009-06-25 22:49:55 +0000965// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000966def tBIC : // A8.6.20
967 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
968 IIC_iBITr,
969 "bic", "\t$Rdn, $Rm",
970 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000971
David Goodwinc9ee1182009-06-25 22:49:55 +0000972// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000973let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000974//FIXME: Disable CMN, as CCodes are backwards from compare expectations
975// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000976//def tCMN : // A8.6.33
977// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
978// IIC_iCMPr,
979// "cmn", "\t$lhs, $rhs",
980// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000981
982def tCMNz : // A8.6.33
983 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
984 IIC_iCMPr,
985 "cmn", "\t$Rn, $Rm",
986 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
987
988} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000989
David Goodwinc9ee1182009-06-25 22:49:55 +0000990// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000991let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000992def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
993 "cmp", "\t$Rn, $imm8",
994 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
995 T1General<{1,0,1,?,?}> {
996 // A8.6.35
997 bits<3> Rn;
998 bits<8> imm8;
999 let Inst{10-8} = Rn;
1000 let Inst{7-0} = imm8;
1001}
1002
David Goodwinc9ee1182009-06-25 22:49:55 +00001003// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +00001004def tCMPr : // A8.6.36 T1
1005 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1006 IIC_iCMPr,
1007 "cmp", "\t$Rn, $Rm",
1008 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
1009
Bill Wendling849f2e32010-11-29 00:18:15 +00001010def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1011 "cmp", "\t$Rn, $Rm", []>,
1012 T1Special<{0,1,?,?}> {
1013 // A8.6.36 T2
1014 bits<4> Rm;
1015 bits<4> Rn;
1016 let Inst{7} = Rn{3};
1017 let Inst{6-3} = Rm;
1018 let Inst{2-0} = Rn{2-0};
1019}
Bill Wendling5cc88a22010-11-20 22:52:33 +00001020} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +00001021
Evan Chenga8e29892007-01-19 07:51:42 +00001022
David Goodwinc9ee1182009-06-25 22:49:55 +00001023// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +00001024let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001025def tEOR : // A8.6.45
1026 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1027 IIC_iBITr,
1028 "eor", "\t$Rdn, $Rm",
1029 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001030
David Goodwinc9ee1182009-06-25 22:49:55 +00001031// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001032def tLSLri : // A8.6.88
1033 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1034 IIC_iMOVsi,
1035 "lsl", "\t$Rd, $Rm, $imm5",
1036 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001037 bits<5> imm5;
1038 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001039}
Evan Chenga8e29892007-01-19 07:51:42 +00001040
David Goodwinc9ee1182009-06-25 22:49:55 +00001041// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001042def tLSLrr : // A8.6.89
1043 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1044 IIC_iMOVsr,
1045 "lsl", "\t$Rdn, $Rm",
1046 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001047
David Goodwinc9ee1182009-06-25 22:49:55 +00001048// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001049def tLSRri : // A8.6.90
1050 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1051 IIC_iMOVsi,
1052 "lsr", "\t$Rd, $Rm, $imm5",
1053 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001054 bits<5> imm5;
1055 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001056}
Evan Chenga8e29892007-01-19 07:51:42 +00001057
David Goodwinc9ee1182009-06-25 22:49:55 +00001058// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001059def tLSRrr : // A8.6.91
1060 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1061 IIC_iMOVsr,
1062 "lsr", "\t$Rdn, $Rm",
1063 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001064
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001065// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001066let isMoveImm = 1 in
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001067def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins i32imm:$imm8), IIC_iMOVi,
1068 "mov", "\t$Rd, $imm8",
1069 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1070 T1General<{1,0,0,?,?}> {
1071 // A8.6.96
1072 bits<3> Rd;
1073 bits<8> imm8;
1074 let Inst{10-8} = Rd;
1075 let Inst{7-0} = imm8;
1076}
Evan Chenga8e29892007-01-19 07:51:42 +00001077
1078// TODO: A7-73: MOV(2) - mov setting flag.
1079
Evan Chengcd799b92009-06-12 20:46:18 +00001080let neverHasSideEffects = 1 in {
Evan Cheng446c4282009-07-11 06:43:01 +00001081// FIXME: Make this predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001082def tMOVr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1083 "mov\t$Rd, $Rm", []>,
1084 T1Special<0b1000> {
1085 // A8.6.97
1086 bits<4> Rd;
1087 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001088 // Bits {7-6} are encoded by the T1Special value.
1089 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001090 let Inst{2-0} = Rd{2-0};
1091}
Evan Cheng446c4282009-07-11 06:43:01 +00001092let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001093def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1094 "movs\t$Rd, $Rm", []>, Encoding16 {
1095 // A8.6.97
1096 bits<3> Rd;
1097 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001098 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001099 let Inst{5-3} = Rm;
1100 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001101}
Evan Cheng446c4282009-07-11 06:43:01 +00001102
1103// FIXME: Make these predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001104def tMOVgpr2tgpr : T1I<(outs tGPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1105 "mov\t$Rd, $Rm", []>,
1106 T1Special<{1,0,0,?}> {
1107 // A8.6.97
1108 bits<4> Rd;
1109 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001110 // Bit {7} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001111 let Inst{6-3} = Rm;
1112 let Inst{2-0} = Rd{2-0};
1113}
1114def tMOVtgpr2gpr : T1I<(outs GPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1115 "mov\t$Rd, $Rm", []>,
1116 T1Special<{1,0,?,0}> {
1117 // A8.6.97
1118 bits<4> Rd;
1119 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001120 // Bit {6} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001121 let Inst{7} = Rd{3};
Bill Wendling278b6e82010-12-03 02:02:58 +00001122 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001123 let Inst{2-0} = Rd{2-0};
1124}
1125def tMOVgpr2gpr : T1I<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1126 "mov\t$Rd, $Rm", []>,
1127 T1Special<{1,0,?,?}> {
1128 // A8.6.97
1129 bits<4> Rd;
1130 bits<4> Rm;
1131 let Inst{7} = Rd{3};
1132 let Inst{6-3} = Rm;
1133 let Inst{2-0} = Rd{2-0};
1134}
Evan Chengcd799b92009-06-12 20:46:18 +00001135} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001136
Bill Wendling0480e282010-12-01 02:36:55 +00001137// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001138let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001139def tMUL : // A8.6.105 T1
1140 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1141 IIC_iMUL32,
1142 "mul", "\t$Rdn, $Rm, $Rdn",
1143 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001144
Bill Wendling76f4e102010-12-01 01:20:15 +00001145// Move inverse register
1146def tMVN : // A8.6.107
1147 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1148 "mvn", "\t$Rd, $Rn",
1149 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001150
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001151// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001152let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001153def tORR : // A8.6.114
1154 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1155 IIC_iBITr,
1156 "orr", "\t$Rdn, $Rm",
1157 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001158
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001159// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001160def tREV : // A8.6.134
1161 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1162 IIC_iUNAr,
1163 "rev", "\t$Rd, $Rm",
1164 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1165 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001166
Bill Wendling1d045ee2010-12-01 02:28:08 +00001167def tREV16 : // A8.6.135
1168 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1169 IIC_iUNAr,
1170 "rev16", "\t$Rd, $Rm",
Bill Wendlingd19ac0c2010-11-29 00:42:50 +00001171 [(set tGPR:$Rd,
1172 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF),
1173 (or (and (shl tGPR:$Rm, (i32 8)), 0xFF00),
1174 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF0000),
1175 (and (shl tGPR:$Rm, (i32 8)), 0xFF000000)))))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001176 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001177
Bill Wendling1d045ee2010-12-01 02:28:08 +00001178def tREVSH : // A8.6.136
1179 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1180 IIC_iUNAr,
1181 "revsh", "\t$Rd, $Rm",
1182 [(set tGPR:$Rd,
1183 (sext_inreg
1184 (or (srl (and tGPR:$Rm, 0xFF00), (i32 8)),
1185 (shl tGPR:$Rm, (i32 8))), i16))]>,
1186 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001187
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001188// Rotate right register
1189def tROR : // A8.6.139
1190 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1191 IIC_iMOVsr,
1192 "ror", "\t$Rdn, $Rm",
1193 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001194
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001195// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001196def tRSB : // A8.6.141
1197 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1198 IIC_iALUi,
1199 "rsb", "\t$Rd, $Rn, #0",
1200 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001201
David Goodwinc9ee1182009-06-25 22:49:55 +00001202// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001203let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001204def tSBC : // A8.6.151
1205 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1206 IIC_iALUr,
1207 "sbc", "\t$Rdn, $Rm",
1208 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001209
David Goodwinc9ee1182009-06-25 22:49:55 +00001210// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001211def tSUBi3 : // A8.6.210 T1
1212 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1213 IIC_iALUi,
1214 "sub", "\t$Rd, $Rm, $imm3",
1215 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001216 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001217 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001218}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001219
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001220def tSUBi8 : // A8.6.210 T2
1221 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1222 IIC_iALUi,
1223 "sub", "\t$Rdn, $imm8",
1224 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001225
Bill Wendling76f4e102010-12-01 01:20:15 +00001226// Subtract register
1227def tSUBrr : // A8.6.212
1228 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1229 IIC_iALUr,
1230 "sub", "\t$Rd, $Rn, $Rm",
1231 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001232
1233// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001234
Bill Wendling76f4e102010-12-01 01:20:15 +00001235// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001236def tSXTB : // A8.6.222
1237 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1238 IIC_iUNAr,
1239 "sxtb", "\t$Rd, $Rm",
1240 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1241 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001242
Bill Wendling1d045ee2010-12-01 02:28:08 +00001243// Sign-extend short
1244def tSXTH : // A8.6.224
1245 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1246 IIC_iUNAr,
1247 "sxth", "\t$Rd, $Rm",
1248 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1249 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001250
Bill Wendling1d045ee2010-12-01 02:28:08 +00001251// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001252let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001253def tTST : // A8.6.230
1254 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1255 "tst", "\t$Rn, $Rm",
1256 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001257
Bill Wendling1d045ee2010-12-01 02:28:08 +00001258// Zero-extend byte
1259def tUXTB : // A8.6.262
1260 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1261 IIC_iUNAr,
1262 "uxtb", "\t$Rd, $Rm",
1263 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1264 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001265
Bill Wendling1d045ee2010-12-01 02:28:08 +00001266// Zero-extend short
1267def tUXTH : // A8.6.264
1268 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1269 IIC_iUNAr,
1270 "uxth", "\t$Rd, $Rm",
1271 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1272 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001273
Jim Grosbach80dc1162010-02-16 21:23:02 +00001274// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001275// Expanded after instruction selection into a branch sequence.
1276let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001277 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001278 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001279 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001280 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001281
Evan Cheng007ea272009-08-12 05:17:19 +00001282
1283// 16-bit movcc in IT blocks for Thumb2.
Owen Andersonf523e472010-09-23 23:45:25 +00001284let neverHasSideEffects = 1 in {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001285def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1286 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001287 T1Special<{1,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001288 bits<4> Rdn;
1289 bits<4> Rm;
1290 let Inst{7} = Rdn{3};
1291 let Inst{6-3} = Rm;
1292 let Inst{2-0} = Rdn{2-0};
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001293}
Evan Cheng007ea272009-08-12 05:17:19 +00001294
Evan Chengc4af4632010-11-17 20:13:28 +00001295let isMoveImm = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +00001296def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1297 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001298 T1General<{1,0,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001299 bits<3> Rdn;
1300 bits<8> Rm;
1301 let Inst{10-8} = Rdn;
1302 let Inst{7-0} = Rm;
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001303}
1304
Owen Andersonf523e472010-09-23 23:45:25 +00001305} // neverHasSideEffects
Evan Cheng007ea272009-08-12 05:17:19 +00001306
Evan Chenga8e29892007-01-19 07:51:42 +00001307// tLEApcrel - Load a pc-relative address into a register without offending the
1308// assembler.
Jim Grosbachd40963c2010-12-14 22:28:03 +00001309
1310def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1311 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1312 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling67077412010-11-30 00:18:30 +00001313 bits<3> Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001314 bits<8> addr;
Bill Wendling67077412010-11-30 00:18:30 +00001315 let Inst{10-8} = Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001316 let Inst{7-0} = addr;
Bill Wendling67077412010-11-30 00:18:30 +00001317}
Evan Chenga8e29892007-01-19 07:51:42 +00001318
Jim Grosbachd40963c2010-12-14 22:28:03 +00001319let neverHasSideEffects = 1, isReMaterializable = 1 in
1320def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1321 Size2Bytes, IIC_iALUi, []>;
1322
1323def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1324 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1325 Size2Bytes, IIC_iALUi, []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001326
Evan Chenga8e29892007-01-19 07:51:42 +00001327//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001328// TLS Instructions
1329//
1330
1331// __aeabi_read_tp preserves the registers r1-r3.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001332let isCall = 1, Defs = [R0, LR], Uses = [SP] in
1333def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
1334 "bl\t__aeabi_read_tp",
1335 [(set R0, ARMthread_pointer)]> {
1336 // Encoding is 0xf7fffffe.
1337 let Inst = 0xf7fffffe;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001338}
1339
Bill Wendling0480e282010-12-01 02:36:55 +00001340//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001341// SJLJ Exception handling intrinsics
Bill Wendling0480e282010-12-01 02:36:55 +00001342//
1343
1344// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1345// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1346// from some other function to get here, and we're using the stack frame for the
1347// containing function to save/restore registers, we can't keep anything live in
1348// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1349// tromped upon when we get here from a longjmp(). We force everthing out of
1350// registers except for our own input by listing the relevant registers in
1351// Defs. By doing so, we also cause the prologue/epilogue code to actively
1352// preserve all of the callee-saved resgisters, which is exactly what we want.
1353// $val is a scratch register for our use.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001354let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12 ],
1355 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1356def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1357 AddrModeNone, SizeSpecial, NoItinerary, "","",
1358 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001359
1360// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001361let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001362 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001363def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001364 AddrModeNone, SizeSpecial, IndexModeNone,
1365 Pseudo, NoItinerary, "", "",
1366 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1367 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001368
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001369//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001370// Non-Instruction Patterns
1371//
1372
Jim Grosbach97a884d2010-12-07 20:41:06 +00001373// Comparisons
1374def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1375 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1376def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1377 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1378
Evan Cheng892837a2009-07-10 02:09:04 +00001379// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001380def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1381 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1382def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001383 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001384def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1385 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001386
1387// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001388def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1389 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1390def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1391 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1392def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1393 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001394
Evan Chenga8e29892007-01-19 07:51:42 +00001395// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001396def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1397def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001398
Evan Chengd85ac4d2007-01-27 02:29:45 +00001399// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001400def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1401 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001402
Evan Chenga8e29892007-01-19 07:51:42 +00001403// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001404def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001405 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001406def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001407 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001408
1409def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001410 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001411def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001412 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001413
1414// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001415def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1416 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1417def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1418 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001419
1420// zextload i1 -> zextload i8
Bill Wendlingf4caf692010-12-14 03:36:38 +00001421def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1422 (tLDRBr t_addrmode_rrs1:$addr)>;
1423def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1424 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001425
Evan Chengb60c02e2007-01-26 19:13:16 +00001426// extload -> zextload
Bill Wendlingf4caf692010-12-14 03:36:38 +00001427def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1428def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1429def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1430def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1431def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1432def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001433
Evan Cheng0e87e232009-08-28 00:31:43 +00001434// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001435// ldr{b|h} + sxt{b|h} instead.
Bill Wendling415af342010-12-15 00:58:57 +00001436def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1437 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1438 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001439def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1440 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001441 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling415af342010-12-15 00:58:57 +00001442def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1443 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1444 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001445def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1446 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001447 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001448
Bill Wendlingf4caf692010-12-14 03:36:38 +00001449def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1450 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling415af342010-12-15 00:58:57 +00001451def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1452 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1453def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1454 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1455def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1456 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001457
Evan Chenga8e29892007-01-19 07:51:42 +00001458// Large immediate handling.
1459
1460// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001461def : T1Pat<(i32 thumb_immshifted:$src),
1462 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1463 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001464
Evan Cheng9cb9e672009-06-27 02:26:13 +00001465def : T1Pat<(i32 imm0_255_comp:$src),
1466 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001467
1468// Pseudo instruction that combines ldr from constpool and add pc. This should
1469// be expanded into two instructions late to allow if-conversion and
1470// scheduling.
1471let isReMaterializable = 1 in
1472def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001473 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001474 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1475 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001476 Requires<[IsThumb, IsThumb1Only]>;