blob: 406d8db792af607930c1ac1c895d634e6d04930e [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 +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 Grosbach3efad8f2010-12-16 19:11:16 +0000538 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
539 // the clobber of LR.
Evan Cheng53c67c02009-08-07 05:45:07 +0000540 let Defs = [LR] in
Jim Grosbach3efad8f2010-12-16 19:11:16 +0000541 def tBfar : tPseudoInst<(outs), (ins t_bltarget:$target),
542 Size4Bytes, IIC_Br, []>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000543
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000544 def tBR_JTr : tPseudoInst<(outs),
545 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
Bill Wendlinga519d572010-12-21 01:57:15 +0000546 SizeSpecial, IIC_Br,
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000547 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
548 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000549 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000550}
551
Evan Chengc85e8322007-07-05 07:13:32 +0000552// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000553// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000554let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000555 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000556 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000557 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Jim Grosbachceab5012010-12-04 00:20:40 +0000558 T1Encoding<{1,1,0,1,?,?}> {
559 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000560 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000561 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000562 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000563}
Evan Chenga8e29892007-01-19 07:51:42 +0000564
Evan Chengde17fb62009-10-31 23:46:45 +0000565// Compare and branch on zero / non-zero
566let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000567 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000568 "cbz\t$Rn, $target", []>,
569 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000570 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000571 bits<6> target;
572 bits<3> Rn;
573 let Inst{9} = target{5};
574 let Inst{7-3} = target{4-0};
575 let Inst{2-0} = Rn;
576 }
Evan Chengde17fb62009-10-31 23:46:45 +0000577
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000578 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000579 "cbnz\t$cmp, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000580 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000581 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000582 bits<6> target;
583 bits<3> Rn;
584 let Inst{9} = target{5};
585 let Inst{7-3} = target{4-0};
586 let Inst{2-0} = Rn;
587 }
Evan Chengde17fb62009-10-31 23:46:45 +0000588}
589
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000590// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
591// A8.6.16 B: Encoding T1
592// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000593let isCall = 1, Uses = [SP] in
Bill Wendling6179c312010-11-20 00:53:35 +0000594def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
595 "svc", "\t$imm", []>, Encoding16 {
596 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000597 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000598 let Inst{11-8} = 0b1111;
599 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000600}
601
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000602// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000603let isBarrier = 1, isTerminator = 1 in
Anton Korobeynikov418d1d92010-05-15 17:19:20 +0000604def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000605 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000606 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000607}
608
Evan Chenga8e29892007-01-19 07:51:42 +0000609//===----------------------------------------------------------------------===//
610// Load Store Instructions.
611//
612
Bill Wendlingb6faf652010-12-14 22:10:49 +0000613// Loads: reg/reg and reg/imm5
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000614let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb6faf652010-12-14 22:10:49 +0000615multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
616 Operand AddrMode_r, Operand AddrMode_i,
617 AddrMode am, InstrItinClass itin_r,
618 InstrItinClass itin_i, string asm,
619 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000620 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000621 T1pILdStEncode<reg_opc,
622 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
623 am, itin_r, asm, "\t$Rt, $addr",
624 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000625 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000626 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
627 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
628 am, itin_i, asm, "\t$Rt, $addr",
629 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
630}
631// Stores: reg/reg and reg/imm5
632multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
633 Operand AddrMode_r, Operand AddrMode_i,
634 AddrMode am, InstrItinClass itin_r,
635 InstrItinClass itin_i, string asm,
636 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000637 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000638 T1pILdStEncode<reg_opc,
639 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
640 am, itin_r, asm, "\t$Rt, $addr",
641 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000642 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000643 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
644 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
645 am, itin_i, asm, "\t$Rt, $addr",
646 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
647}
Bill Wendling6179c312010-11-20 00:53:35 +0000648
Bill Wendlingb6faf652010-12-14 22:10:49 +0000649// A8.6.57 & A8.6.60
650defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
651 t_addrmode_is4, AddrModeT1_4,
652 IIC_iLoad_r, IIC_iLoad_i, "ldr",
653 UnOpFrag<(load node:$Src)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000654
Bill Wendlingb6faf652010-12-14 22:10:49 +0000655// A8.6.64 & A8.6.61
656defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
657 t_addrmode_is1, AddrModeT1_1,
658 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
659 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000660
Bill Wendlingb6faf652010-12-14 22:10:49 +0000661// A8.6.76 & A8.6.73
662defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
663 t_addrmode_is2, AddrModeT1_2,
664 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
665 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000666
Evan Cheng2f297df2009-07-11 07:08:13 +0000667let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000668def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000669 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
670 AddrModeT1_1, IIC_iLoad_bh_r,
671 "ldrsb", "\t$dst, $addr",
672 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000673
Evan Cheng2f297df2009-07-11 07:08:13 +0000674let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000675def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000676 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
677 AddrModeT1_2, IIC_iLoad_bh_r,
678 "ldrsh", "\t$dst, $addr",
679 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000680
Dan Gohman15511cf2008-12-03 18:15:48 +0000681let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000682def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000683 "ldr", "\t$Rt, $addr",
684 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000685 T1LdStSP<{1,?,?}> {
686 bits<3> Rt;
687 bits<8> addr;
688 let Inst{10-8} = Rt;
689 let Inst{7-0} = addr;
690}
Evan Cheng012f2d92007-01-24 08:53:17 +0000691
Evan Cheng8e59ea92007-02-07 00:06:56 +0000692// Special instruction for restore. It cannot clobber condition register
693// when it's expanded by eliminateCallFramePseudoInstr().
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000694let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000695// FIXME: Pseudo for tLDRspi
Evan Cheng0e55fd62010-09-30 01:08:25 +0000696def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000697 "ldr", "\t$dst, $addr", []>,
Bill Wendlingdedec2b2010-12-16 00:38:41 +0000698 T1LdStSP<{1,?,?}> {
699 bits<3> Rt;
700 bits<8> addr;
701 let Inst{10-8} = Rt;
702 let Inst{7-0} = addr;
703}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000704
Evan Cheng012f2d92007-01-24 08:53:17 +0000705// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000706// FIXME: Use ldr.n to work around a Darwin assembler bug.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000707let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000708def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000709 "ldr", ".n\t$Rt, $addr",
710 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
711 T1Encoding<{0,1,0,0,1,?}> {
712 // A6.2 & A8.6.59
713 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000714 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000715 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000716 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000717}
Evan Chengfa775d02007-03-19 07:20:03 +0000718
Bill Wendlingb6faf652010-12-14 22:10:49 +0000719// A8.6.194 & A8.6.192
720defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
721 t_addrmode_is4, AddrModeT1_4,
722 IIC_iStore_r, IIC_iStore_i, "str",
723 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000724
Bill Wendlingb6faf652010-12-14 22:10:49 +0000725// A8.6.197 & A8.6.195
726defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
727 t_addrmode_is1, AddrModeT1_1,
728 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
729 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000730
Bill Wendlingb6faf652010-12-14 22:10:49 +0000731// A8.6.207 & A8.6.205
732defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
733 t_addrmode_is2, AddrModeT1_2,
734 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
735 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000736
Evan Chenga8e29892007-01-19 07:51:42 +0000737
Jim Grosbachd967cd02010-12-07 21:50:47 +0000738def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendlingf4caf692010-12-14 03:36:38 +0000739 "str", "\t$Rt, $addr",
740 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000741 T1LdStSP<{0,?,?}> {
742 bits<3> Rt;
743 bits<8> addr;
744 let Inst{10-8} = Rt;
745 let Inst{7-0} = addr;
746}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000747
Bill Wendling3f8c1102010-11-30 23:54:45 +0000748let mayStore = 1, neverHasSideEffects = 1 in
749// Special instruction for spill. It cannot clobber condition register when it's
750// expanded by eliminateCallFramePseudoInstr().
Jim Grosbachd967cd02010-12-07 21:50:47 +0000751// FIXME: Pseudo for tSTRspi
Evan Cheng0e55fd62010-09-30 01:08:25 +0000752def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000753 "str", "\t$src, $addr", []>,
Bill Wendlingdedec2b2010-12-16 00:38:41 +0000754 T1LdStSP<{0,?,?}> {
755 bits<3> Rt;
756 bits<8> addr;
757 let Inst{10-8} = Rt;
758 let Inst{7-0} = addr;
759}
Evan Chenga8e29892007-01-19 07:51:42 +0000760
761//===----------------------------------------------------------------------===//
762// Load / store multiple Instructions.
763//
764
Bill Wendling6c470b82010-11-13 09:09:38 +0000765multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
766 InstrItinClass itin_upd, bits<6> T1Enc,
767 bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000768 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000769 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000770 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000771 T1Encoding<T1Enc> {
772 bits<3> Rn;
773 bits<8> regs;
774 let Inst{10-8} = Rn;
775 let Inst{7-0} = regs;
776 }
Bill Wendling73fe34a2010-11-16 01:16:36 +0000777 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +0000778 T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000779 itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000780 T1Encoding<T1Enc> {
781 bits<3> Rn;
782 bits<8> regs;
783 let Inst{10-8} = Rn;
784 let Inst{7-0} = regs;
785 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000786}
787
Bill Wendling73fe34a2010-11-16 01:16:36 +0000788// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000789let neverHasSideEffects = 1 in {
790
791let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
792defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
793 {1,1,0,0,1,?}, 1>;
794
795let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
796defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
797 {1,1,0,0,0,?}, 0>;
798
799} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000800
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000801let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000802def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000803 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000804 "pop${p}\t$regs", []>,
805 T1Misc<{1,1,0,?,?,?,?}> {
806 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000807 let Inst{8} = regs{15};
808 let Inst{7-0} = regs{7-0};
809}
Evan Cheng4b322e52009-08-11 21:11:32 +0000810
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000811let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000812def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000813 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000814 "push${p}\t$regs", []>,
815 T1Misc<{0,1,0,?,?,?,?}> {
816 bits<16> regs;
817 let Inst{8} = regs{14};
818 let Inst{7-0} = regs{7-0};
819}
Evan Chenga8e29892007-01-19 07:51:42 +0000820
821//===----------------------------------------------------------------------===//
822// Arithmetic Instructions.
823//
824
Bill Wendling1d045ee2010-12-01 02:28:08 +0000825// Helper classes for encoding T1pI patterns:
826class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
827 string opc, string asm, list<dag> pattern>
828 : T1pI<oops, iops, itin, opc, asm, pattern>,
829 T1DataProcessing<opA> {
830 bits<3> Rm;
831 bits<3> Rn;
832 let Inst{5-3} = Rm;
833 let Inst{2-0} = Rn;
834}
835class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
836 string opc, string asm, list<dag> pattern>
837 : T1pI<oops, iops, itin, opc, asm, pattern>,
838 T1Misc<opA> {
839 bits<3> Rm;
840 bits<3> Rd;
841 let Inst{5-3} = Rm;
842 let Inst{2-0} = Rd;
843}
844
Bill Wendling76f4e102010-12-01 01:20:15 +0000845// Helper classes for encoding T1sI patterns:
846class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
847 string opc, string asm, list<dag> pattern>
848 : T1sI<oops, iops, itin, opc, asm, pattern>,
849 T1DataProcessing<opA> {
850 bits<3> Rd;
851 bits<3> Rn;
852 let Inst{5-3} = Rn;
853 let Inst{2-0} = Rd;
854}
855class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
856 string opc, string asm, list<dag> pattern>
857 : T1sI<oops, iops, itin, opc, asm, pattern>,
858 T1General<opA> {
859 bits<3> Rm;
860 bits<3> Rn;
861 bits<3> Rd;
862 let Inst{8-6} = Rm;
863 let Inst{5-3} = Rn;
864 let Inst{2-0} = Rd;
865}
866class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
867 string opc, string asm, list<dag> pattern>
868 : T1sI<oops, iops, itin, opc, asm, pattern>,
869 T1General<opA> {
870 bits<3> Rd;
871 bits<3> Rm;
872 let Inst{5-3} = Rm;
873 let Inst{2-0} = Rd;
874}
875
876// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000877class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
878 string opc, string asm, list<dag> pattern>
879 : T1sIt<oops, iops, itin, opc, asm, pattern>,
880 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000881 bits<3> Rdn;
882 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000883 let Inst{5-3} = Rm;
884 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000885}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000886class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
887 string opc, string asm, list<dag> pattern>
888 : T1sIt<oops, iops, itin, opc, asm, pattern>,
889 T1General<opA> {
890 bits<3> Rdn;
891 bits<8> imm8;
892 let Inst{10-8} = Rdn;
893 let Inst{7-0} = imm8;
894}
895
896// Add with carry register
897let isCommutable = 1, Uses = [CPSR] in
898def tADC : // A8.6.2
899 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
900 "adc", "\t$Rdn, $Rm",
901 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000902
David Goodwinc9ee1182009-06-25 22:49:55 +0000903// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000904def tADDi3 : // A8.6.4 T1
905 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3), IIC_iALUi,
906 "add", "\t$Rd, $Rm, $imm3",
907 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000908 bits<3> imm3;
909 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000910}
Evan Chenga8e29892007-01-19 07:51:42 +0000911
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000912def tADDi8 : // A8.6.4 T2
913 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
914 IIC_iALUi,
915 "add", "\t$Rdn, $imm8",
916 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000917
David Goodwinc9ee1182009-06-25 22:49:55 +0000918// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000919let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000920def tADDrr : // A8.6.6 T1
921 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
922 IIC_iALUr,
923 "add", "\t$Rd, $Rn, $Rm",
924 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000925
Evan Chengcd799b92009-06-12 20:46:18 +0000926let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000927def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
928 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000929 T1Special<{0,0,?,?}> {
930 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000931 bits<4> Rdn;
932 bits<4> Rm;
933 let Inst{7} = Rdn{3};
934 let Inst{6-3} = Rm;
935 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000936}
Evan Chenga8e29892007-01-19 07:51:42 +0000937
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000938// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000939let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000940def tAND : // A8.6.12
941 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
942 IIC_iBITr,
943 "and", "\t$Rdn, $Rm",
944 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000945
David Goodwinc9ee1182009-06-25 22:49:55 +0000946// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000947def tASRri : // A8.6.14
948 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
949 IIC_iMOVsi,
950 "asr", "\t$Rd, $Rm, $imm5",
951 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000952 bits<5> imm5;
953 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000954}
Evan Chenga8e29892007-01-19 07:51:42 +0000955
David Goodwinc9ee1182009-06-25 22:49:55 +0000956// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000957def tASRrr : // A8.6.15
958 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
959 IIC_iMOVsr,
960 "asr", "\t$Rdn, $Rm",
961 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000962
David Goodwinc9ee1182009-06-25 22:49:55 +0000963// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000964def tBIC : // A8.6.20
965 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
966 IIC_iBITr,
967 "bic", "\t$Rdn, $Rm",
968 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000969
David Goodwinc9ee1182009-06-25 22:49:55 +0000970// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000971let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000972//FIXME: Disable CMN, as CCodes are backwards from compare expectations
973// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000974//def tCMN : // A8.6.33
975// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
976// IIC_iCMPr,
977// "cmn", "\t$lhs, $rhs",
978// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000979
980def tCMNz : // A8.6.33
981 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
982 IIC_iCMPr,
983 "cmn", "\t$Rn, $Rm",
984 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
985
986} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000987
David Goodwinc9ee1182009-06-25 22:49:55 +0000988// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000989let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000990def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
991 "cmp", "\t$Rn, $imm8",
992 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
993 T1General<{1,0,1,?,?}> {
994 // A8.6.35
995 bits<3> Rn;
996 bits<8> imm8;
997 let Inst{10-8} = Rn;
998 let Inst{7-0} = imm8;
999}
1000
David Goodwinc9ee1182009-06-25 22:49:55 +00001001// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +00001002def tCMPr : // A8.6.36 T1
1003 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1004 IIC_iCMPr,
1005 "cmp", "\t$Rn, $Rm",
1006 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
1007
Bill Wendling849f2e32010-11-29 00:18:15 +00001008def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1009 "cmp", "\t$Rn, $Rm", []>,
1010 T1Special<{0,1,?,?}> {
1011 // A8.6.36 T2
1012 bits<4> Rm;
1013 bits<4> Rn;
1014 let Inst{7} = Rn{3};
1015 let Inst{6-3} = Rm;
1016 let Inst{2-0} = Rn{2-0};
1017}
Bill Wendling5cc88a22010-11-20 22:52:33 +00001018} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +00001019
Evan Chenga8e29892007-01-19 07:51:42 +00001020
David Goodwinc9ee1182009-06-25 22:49:55 +00001021// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +00001022let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001023def tEOR : // A8.6.45
1024 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1025 IIC_iBITr,
1026 "eor", "\t$Rdn, $Rm",
1027 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001028
David Goodwinc9ee1182009-06-25 22:49:55 +00001029// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001030def tLSLri : // A8.6.88
1031 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1032 IIC_iMOVsi,
1033 "lsl", "\t$Rd, $Rm, $imm5",
1034 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001035 bits<5> imm5;
1036 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001037}
Evan Chenga8e29892007-01-19 07:51:42 +00001038
David Goodwinc9ee1182009-06-25 22:49:55 +00001039// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001040def tLSLrr : // A8.6.89
1041 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1042 IIC_iMOVsr,
1043 "lsl", "\t$Rdn, $Rm",
1044 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001045
David Goodwinc9ee1182009-06-25 22:49:55 +00001046// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001047def tLSRri : // A8.6.90
1048 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1049 IIC_iMOVsi,
1050 "lsr", "\t$Rd, $Rm, $imm5",
1051 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001052 bits<5> imm5;
1053 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001054}
Evan Chenga8e29892007-01-19 07:51:42 +00001055
David Goodwinc9ee1182009-06-25 22:49:55 +00001056// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001057def tLSRrr : // A8.6.91
1058 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1059 IIC_iMOVsr,
1060 "lsr", "\t$Rdn, $Rm",
1061 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001062
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001063// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001064let isMoveImm = 1 in
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001065def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins i32imm:$imm8), IIC_iMOVi,
1066 "mov", "\t$Rd, $imm8",
1067 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1068 T1General<{1,0,0,?,?}> {
1069 // A8.6.96
1070 bits<3> Rd;
1071 bits<8> imm8;
1072 let Inst{10-8} = Rd;
1073 let Inst{7-0} = imm8;
1074}
Evan Chenga8e29892007-01-19 07:51:42 +00001075
1076// TODO: A7-73: MOV(2) - mov setting flag.
1077
Evan Chengcd799b92009-06-12 20:46:18 +00001078let neverHasSideEffects = 1 in {
Evan Cheng446c4282009-07-11 06:43:01 +00001079// FIXME: Make this predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001080def tMOVr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1081 "mov\t$Rd, $Rm", []>,
1082 T1Special<0b1000> {
1083 // A8.6.97
1084 bits<4> Rd;
1085 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001086 // Bits {7-6} are encoded by the T1Special value.
1087 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001088 let Inst{2-0} = Rd{2-0};
1089}
Evan Cheng446c4282009-07-11 06:43:01 +00001090let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001091def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1092 "movs\t$Rd, $Rm", []>, Encoding16 {
1093 // A8.6.97
1094 bits<3> Rd;
1095 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001096 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001097 let Inst{5-3} = Rm;
1098 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001099}
Evan Cheng446c4282009-07-11 06:43:01 +00001100
1101// FIXME: Make these predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001102def tMOVgpr2tgpr : T1I<(outs tGPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1103 "mov\t$Rd, $Rm", []>,
1104 T1Special<{1,0,0,?}> {
1105 // A8.6.97
1106 bits<4> Rd;
1107 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001108 // Bit {7} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001109 let Inst{6-3} = Rm;
1110 let Inst{2-0} = Rd{2-0};
1111}
1112def tMOVtgpr2gpr : T1I<(outs GPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1113 "mov\t$Rd, $Rm", []>,
1114 T1Special<{1,0,?,0}> {
1115 // A8.6.97
1116 bits<4> Rd;
1117 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001118 // Bit {6} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001119 let Inst{7} = Rd{3};
Bill Wendling278b6e82010-12-03 02:02:58 +00001120 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001121 let Inst{2-0} = Rd{2-0};
1122}
1123def tMOVgpr2gpr : T1I<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1124 "mov\t$Rd, $Rm", []>,
1125 T1Special<{1,0,?,?}> {
1126 // A8.6.97
1127 bits<4> Rd;
1128 bits<4> Rm;
1129 let Inst{7} = Rd{3};
1130 let Inst{6-3} = Rm;
1131 let Inst{2-0} = Rd{2-0};
1132}
Evan Chengcd799b92009-06-12 20:46:18 +00001133} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001134
Bill Wendling0480e282010-12-01 02:36:55 +00001135// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001136let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001137def tMUL : // A8.6.105 T1
1138 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1139 IIC_iMUL32,
1140 "mul", "\t$Rdn, $Rm, $Rdn",
1141 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001142
Bill Wendling76f4e102010-12-01 01:20:15 +00001143// Move inverse register
1144def tMVN : // A8.6.107
1145 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1146 "mvn", "\t$Rd, $Rn",
1147 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001148
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001149// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001150let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001151def tORR : // A8.6.114
1152 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1153 IIC_iBITr,
1154 "orr", "\t$Rdn, $Rm",
1155 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001156
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001157// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001158def tREV : // A8.6.134
1159 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1160 IIC_iUNAr,
1161 "rev", "\t$Rd, $Rm",
1162 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1163 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001164
Bill Wendling1d045ee2010-12-01 02:28:08 +00001165def tREV16 : // A8.6.135
1166 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1167 IIC_iUNAr,
1168 "rev16", "\t$Rd, $Rm",
Bill Wendlingd19ac0c2010-11-29 00:42:50 +00001169 [(set tGPR:$Rd,
1170 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF),
1171 (or (and (shl tGPR:$Rm, (i32 8)), 0xFF00),
1172 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF0000),
1173 (and (shl tGPR:$Rm, (i32 8)), 0xFF000000)))))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001174 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001175
Bill Wendling1d045ee2010-12-01 02:28:08 +00001176def tREVSH : // A8.6.136
1177 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1178 IIC_iUNAr,
1179 "revsh", "\t$Rd, $Rm",
1180 [(set tGPR:$Rd,
1181 (sext_inreg
1182 (or (srl (and tGPR:$Rm, 0xFF00), (i32 8)),
1183 (shl tGPR:$Rm, (i32 8))), i16))]>,
1184 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001185
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001186// Rotate right register
1187def tROR : // A8.6.139
1188 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1189 IIC_iMOVsr,
1190 "ror", "\t$Rdn, $Rm",
1191 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001192
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001193// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001194def tRSB : // A8.6.141
1195 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1196 IIC_iALUi,
1197 "rsb", "\t$Rd, $Rn, #0",
1198 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001199
David Goodwinc9ee1182009-06-25 22:49:55 +00001200// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001201let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001202def tSBC : // A8.6.151
1203 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1204 IIC_iALUr,
1205 "sbc", "\t$Rdn, $Rm",
1206 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001207
David Goodwinc9ee1182009-06-25 22:49:55 +00001208// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001209def tSUBi3 : // A8.6.210 T1
1210 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1211 IIC_iALUi,
1212 "sub", "\t$Rd, $Rm, $imm3",
1213 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001214 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001215 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001216}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001217
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001218def tSUBi8 : // A8.6.210 T2
1219 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1220 IIC_iALUi,
1221 "sub", "\t$Rdn, $imm8",
1222 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001223
Bill Wendling76f4e102010-12-01 01:20:15 +00001224// Subtract register
1225def tSUBrr : // A8.6.212
1226 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1227 IIC_iALUr,
1228 "sub", "\t$Rd, $Rn, $Rm",
1229 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001230
1231// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001232
Bill Wendling76f4e102010-12-01 01:20:15 +00001233// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001234def tSXTB : // A8.6.222
1235 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1236 IIC_iUNAr,
1237 "sxtb", "\t$Rd, $Rm",
1238 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1239 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001240
Bill Wendling1d045ee2010-12-01 02:28:08 +00001241// Sign-extend short
1242def tSXTH : // A8.6.224
1243 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1244 IIC_iUNAr,
1245 "sxth", "\t$Rd, $Rm",
1246 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1247 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001248
Bill Wendling1d045ee2010-12-01 02:28:08 +00001249// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001250let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001251def tTST : // A8.6.230
1252 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1253 "tst", "\t$Rn, $Rm",
1254 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001255
Bill Wendling1d045ee2010-12-01 02:28:08 +00001256// Zero-extend byte
1257def tUXTB : // A8.6.262
1258 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1259 IIC_iUNAr,
1260 "uxtb", "\t$Rd, $Rm",
1261 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1262 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001263
Bill Wendling1d045ee2010-12-01 02:28:08 +00001264// Zero-extend short
1265def tUXTH : // A8.6.264
1266 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1267 IIC_iUNAr,
1268 "uxth", "\t$Rd, $Rm",
1269 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1270 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001271
Jim Grosbach80dc1162010-02-16 21:23:02 +00001272// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001273// Expanded after instruction selection into a branch sequence.
1274let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001275 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001276 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001277 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001278 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001279
Evan Cheng007ea272009-08-12 05:17:19 +00001280
1281// 16-bit movcc in IT blocks for Thumb2.
Owen Andersonf523e472010-09-23 23:45:25 +00001282let neverHasSideEffects = 1 in {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001283def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1284 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001285 T1Special<{1,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001286 bits<4> Rdn;
1287 bits<4> Rm;
1288 let Inst{7} = Rdn{3};
1289 let Inst{6-3} = Rm;
1290 let Inst{2-0} = Rdn{2-0};
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001291}
Evan Cheng007ea272009-08-12 05:17:19 +00001292
Evan Chengc4af4632010-11-17 20:13:28 +00001293let isMoveImm = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +00001294def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1295 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001296 T1General<{1,0,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001297 bits<3> Rdn;
1298 bits<8> Rm;
1299 let Inst{10-8} = Rdn;
1300 let Inst{7-0} = Rm;
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001301}
1302
Owen Andersonf523e472010-09-23 23:45:25 +00001303} // neverHasSideEffects
Evan Cheng007ea272009-08-12 05:17:19 +00001304
Evan Chenga8e29892007-01-19 07:51:42 +00001305// tLEApcrel - Load a pc-relative address into a register without offending the
1306// assembler.
Jim Grosbachd40963c2010-12-14 22:28:03 +00001307
1308def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1309 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1310 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling67077412010-11-30 00:18:30 +00001311 bits<3> Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001312 bits<8> addr;
Bill Wendling67077412010-11-30 00:18:30 +00001313 let Inst{10-8} = Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001314 let Inst{7-0} = addr;
Bill Wendling67077412010-11-30 00:18:30 +00001315}
Evan Chenga8e29892007-01-19 07:51:42 +00001316
Jim Grosbachd40963c2010-12-14 22:28:03 +00001317let neverHasSideEffects = 1, isReMaterializable = 1 in
1318def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1319 Size2Bytes, IIC_iALUi, []>;
1320
1321def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1322 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1323 Size2Bytes, IIC_iALUi, []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001324
Evan Chenga8e29892007-01-19 07:51:42 +00001325//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001326// Move between coprocessor and ARM core register -- for disassembly only
1327//
1328
1329class tMovRCopro<string opc, bit direction>
1330 : T1Cop<(outs), (ins p_imm:$cop, i32imm:$opc1,
1331 GPR:$Rt, c_imm:$CRn, c_imm:$CRm, i32imm:$opc2),
1332 !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
1333 [/* For disassembly only; pattern left blank */]> {
1334 let Inst{27-24} = 0b1110;
1335 let Inst{20} = direction;
1336 let Inst{4} = 1;
1337
1338 bits<4> Rt;
1339 bits<4> cop;
1340 bits<3> opc1;
1341 bits<3> opc2;
1342 bits<4> CRm;
1343 bits<4> CRn;
1344
1345 let Inst{15-12} = Rt;
1346 let Inst{11-8} = cop;
1347 let Inst{23-21} = opc1;
1348 let Inst{7-5} = opc2;
1349 let Inst{3-0} = CRm;
1350 let Inst{19-16} = CRn;
1351}
1352
1353def tMCR : tMovRCopro<"mcr", 0 /* from ARM core register to coprocessor */>;
1354def tMRC : tMovRCopro<"mrc", 1 /* from coprocessor to ARM core register */>;
1355
1356class tMovRRCopro<string opc, bit direction>
1357 : T1Cop<(outs), (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
1358 !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"),
1359 [/* For disassembly only; pattern left blank */]> {
1360 let Inst{27-24} = 0b1100;
1361 let Inst{23-21} = 0b010;
1362 let Inst{20} = direction;
1363
1364 bits<4> Rt;
1365 bits<4> Rt2;
1366 bits<4> cop;
1367 bits<4> opc1;
1368 bits<4> CRm;
1369
1370 let Inst{15-12} = Rt;
1371 let Inst{19-16} = Rt2;
1372 let Inst{11-8} = cop;
1373 let Inst{7-4} = opc1;
1374 let Inst{3-0} = CRm;
1375}
1376
1377def tMCRR : tMovRRCopro<"mcrr", 0 /* from ARM core register to coprocessor */>;
1378def tMRRC : tMovRRCopro<"mrrc", 1 /* from coprocessor to ARM core register */>;
1379
1380//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001381// TLS Instructions
1382//
1383
1384// __aeabi_read_tp preserves the registers r1-r3.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001385let isCall = 1, Defs = [R0, LR], Uses = [SP] in
1386def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
1387 "bl\t__aeabi_read_tp",
1388 [(set R0, ARMthread_pointer)]> {
1389 // Encoding is 0xf7fffffe.
1390 let Inst = 0xf7fffffe;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001391}
1392
Bill Wendling0480e282010-12-01 02:36:55 +00001393//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001394// SJLJ Exception handling intrinsics
Bill Wendling0480e282010-12-01 02:36:55 +00001395//
1396
1397// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1398// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1399// from some other function to get here, and we're using the stack frame for the
1400// containing function to save/restore registers, we can't keep anything live in
1401// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1402// tromped upon when we get here from a longjmp(). We force everthing out of
1403// registers except for our own input by listing the relevant registers in
1404// Defs. By doing so, we also cause the prologue/epilogue code to actively
1405// preserve all of the callee-saved resgisters, which is exactly what we want.
1406// $val is a scratch register for our use.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001407let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12 ],
1408 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1409def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1410 AddrModeNone, SizeSpecial, NoItinerary, "","",
1411 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001412
1413// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001414let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001415 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001416def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001417 AddrModeNone, SizeSpecial, IndexModeNone,
1418 Pseudo, NoItinerary, "", "",
1419 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1420 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001421
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001422//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001423// Non-Instruction Patterns
1424//
1425
Jim Grosbach97a884d2010-12-07 20:41:06 +00001426// Comparisons
1427def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1428 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1429def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1430 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1431
Evan Cheng892837a2009-07-10 02:09:04 +00001432// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001433def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1434 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1435def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001436 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001437def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1438 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001439
1440// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001441def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1442 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1443def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1444 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1445def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1446 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001447
Evan Chenga8e29892007-01-19 07:51:42 +00001448// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001449def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1450def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001451
Evan Chengd85ac4d2007-01-27 02:29:45 +00001452// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001453def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1454 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001455
Evan Chenga8e29892007-01-19 07:51:42 +00001456// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001457def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001458 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001459def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001460 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001461
1462def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001463 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001464def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001465 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001466
1467// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001468def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1469 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1470def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1471 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001472
1473// zextload i1 -> zextload i8
Bill Wendlingf4caf692010-12-14 03:36:38 +00001474def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1475 (tLDRBr t_addrmode_rrs1:$addr)>;
1476def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1477 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001478
Evan Chengb60c02e2007-01-26 19:13:16 +00001479// extload -> zextload
Bill Wendlingf4caf692010-12-14 03:36:38 +00001480def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1481def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1482def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1483def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1484def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1485def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001486
Evan Cheng0e87e232009-08-28 00:31:43 +00001487// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001488// ldr{b|h} + sxt{b|h} instead.
Bill Wendling415af342010-12-15 00:58:57 +00001489def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1490 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1491 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001492def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1493 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001494 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling415af342010-12-15 00:58:57 +00001495def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1496 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1497 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001498def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1499 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001500 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001501
Bill Wendlingf4caf692010-12-14 03:36:38 +00001502def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1503 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling415af342010-12-15 00:58:57 +00001504def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1505 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1506def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1507 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1508def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1509 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001510
Evan Chenga8e29892007-01-19 07:51:42 +00001511// Large immediate handling.
1512
1513// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001514def : T1Pat<(i32 thumb_immshifted:$src),
1515 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1516 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001517
Evan Cheng9cb9e672009-06-27 02:26:13 +00001518def : T1Pat<(i32 imm0_255_comp:$src),
1519 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001520
1521// Pseudo instruction that combines ldr from constpool and add pc. This should
1522// be expanded into two instructions late to allow if-conversion and
1523// scheduling.
1524let isReMaterializable = 1 in
1525def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001526 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001527 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1528 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001529 Requires<[IsThumb, IsThumb1Only]>;