blob: b2bf344e4201b68b2e2bb2ca8e5d9eedb5b2fcab [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].
Eric Christopher8f232d32011-04-28 05:49:04 +000030def imm0_7 : ImmLeaf<i32, [{
31 return Imm >= 0 && Imm < 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
Jim Grosbach6b8f1e32011-06-27 23:54:06 +000037def imm0_255_asmoperand : AsmOperandClass { let Name = "Imm0_255"; }
38def imm0_255 : Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 256; }]> {
39 let ParserMatchClass = imm0_255_asmoperand;
40}
Evan Chenga8e29892007-01-19 07:51:42 +000041def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000042 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000043}]>;
44
Eric Christopher8f232d32011-04-28 05:49:04 +000045def imm8_255 : ImmLeaf<i32, [{
46 return Imm >= 8 && Imm < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000047}]>;
48def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000049 unsigned Val = -N->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +000050 return Val >= 8 && Val < 256;
51}], imm_neg_XFORM>;
52
Bill Wendling0480e282010-12-01 02:36:55 +000053// Break imm's up into two pieces: an immediate + a left shift. This uses
54// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
55// to get the val/shift pieces.
Evan Chenga8e29892007-01-19 07:51:42 +000056def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000057 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000058}]>;
59
60def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000061 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000062 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000063}]>;
64
65def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000066 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000067 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000068}]>;
69
Jim Grosbachd40963c2010-12-14 22:28:03 +000070// ADR instruction labels.
71def t_adrlabel : Operand<i32> {
72 let EncoderMethod = "getThumbAdrLabelOpValue";
73}
74
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000075// Scaled 4 immediate.
76def t_imm_s4 : Operand<i32> {
77 let PrintMethod = "printThumbS4ImmOperand";
78}
79
Evan Chenga8e29892007-01-19 07:51:42 +000080// Define Thumb specific addressing modes.
81
Jim Grosbache2467172010-12-10 18:21:33 +000082def t_brtarget : Operand<OtherVT> {
83 let EncoderMethod = "getThumbBRTargetOpValue";
84}
85
Jim Grosbach01086452010-12-10 17:13:40 +000086def t_bcctarget : Operand<i32> {
87 let EncoderMethod = "getThumbBCCTargetOpValue";
88}
89
Jim Grosbachcf6220a2010-12-09 19:01:46 +000090def t_cbtarget : Operand<i32> {
Jim Grosbach027d6e82010-12-09 19:04:53 +000091 let EncoderMethod = "getThumbCBTargetOpValue";
Bill Wendlingdff2f712010-12-08 23:01:43 +000092}
93
Jim Grosbach662a8162010-12-06 23:57:07 +000094def t_bltarget : Operand<i32> {
95 let EncoderMethod = "getThumbBLTargetOpValue";
96}
97
Bill Wendling09aa3f02010-12-09 00:39:08 +000098def t_blxtarget : Operand<i32> {
99 let EncoderMethod = "getThumbBLXTargetOpValue";
100}
101
Bill Wendlingf4caf692010-12-14 03:36:38 +0000102def MemModeRegThumbAsmOperand : AsmOperandClass {
103 let Name = "MemModeRegThumb";
104 let SuperClasses = [];
105}
106
107def MemModeImmThumbAsmOperand : AsmOperandClass {
108 let Name = "MemModeImmThumb";
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000109 let SuperClasses = [];
110}
111
Evan Chenga8e29892007-01-19 07:51:42 +0000112// t_addrmode_rr := reg + reg
113//
114def t_addrmode_rr : Operand<i32>,
115 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000116 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000117 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000118 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000119}
120
Bill Wendlingf4caf692010-12-14 03:36:38 +0000121// t_addrmode_rrs := reg + reg
Evan Chenga8e29892007-01-19 07:51:42 +0000122//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000123def t_addrmode_rrs1 : Operand<i32>,
124 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
125 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
126 let PrintMethod = "printThumbAddrModeRROperand";
127 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
128 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000129}
Bill Wendlingf4caf692010-12-14 03:36:38 +0000130def t_addrmode_rrs2 : Operand<i32>,
131 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
132 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
133 let PrintMethod = "printThumbAddrModeRROperand";
134 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
135 let ParserMatchClass = MemModeRegThumbAsmOperand;
136}
137def t_addrmode_rrs4 : Operand<i32>,
138 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
139 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
140 let PrintMethod = "printThumbAddrModeRROperand";
141 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
142 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000143}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000144
Bill Wendlingf4caf692010-12-14 03:36:38 +0000145// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc38f2bc2007-01-23 22:59:13 +0000146//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000147def t_addrmode_is4 : Operand<i32>,
148 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
149 let EncoderMethod = "getAddrModeISOpValue";
150 let PrintMethod = "printThumbAddrModeImm5S4Operand";
151 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
152 let ParserMatchClass = MemModeImmThumbAsmOperand;
153}
154
155// t_addrmode_is2 := reg + imm5 * 2
156//
157def t_addrmode_is2 : Operand<i32>,
158 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
159 let EncoderMethod = "getAddrModeISOpValue";
160 let PrintMethod = "printThumbAddrModeImm5S2Operand";
161 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
162 let ParserMatchClass = MemModeImmThumbAsmOperand;
163}
164
165// t_addrmode_is1 := reg + imm5
166//
167def t_addrmode_is1 : Operand<i32>,
168 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
169 let EncoderMethod = "getAddrModeISOpValue";
170 let PrintMethod = "printThumbAddrModeImm5S1Operand";
171 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
172 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000173}
174
175// t_addrmode_sp := sp + imm8 * 4
176//
177def t_addrmode_sp : Operand<i32>,
178 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbachd967cd02010-12-07 21:50:47 +0000179 let EncoderMethod = "getAddrModeThumbSPOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000180 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000181 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000182 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000183}
184
Bill Wendlingb8958b02010-12-08 01:57:09 +0000185// t_addrmode_pc := <label> => pc + imm8 * 4
186//
187def t_addrmode_pc : Operand<i32> {
188 let EncoderMethod = "getAddrModePCOpValue";
Bill Wendlingf4caf692010-12-14 03:36:38 +0000189 let ParserMatchClass = MemModeImmThumbAsmOperand;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000190}
191
Evan Chenga8e29892007-01-19 07:51:42 +0000192//===----------------------------------------------------------------------===//
193// Miscellaneous Instructions.
194//
195
Jim Grosbach4642ad32010-02-22 23:10:38 +0000196// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
197// from removing one half of the matched pairs. That breaks PEI, which assumes
198// these will always be in pairs, and asserts if it finds otherwise. Better way?
199let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000200def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000201 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
202 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
203 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000204
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000205def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000206 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
207 [(ARMcallseq_start imm:$amt)]>,
208 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000209}
Evan Cheng44bec522007-05-15 01:29:07 +0000210
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000211// T1Disassembly - A simple class to make encoding some disassembly patterns
212// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000213class T1Disassembly<bits<2> op1, bits<8> op2>
214 : T1Encoding<0b101111> {
215 let Inst{9-8} = op1;
216 let Inst{7-0} = op2;
217}
218
Johnny Chenbd2c6232010-02-25 03:28:51 +0000219def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
220 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000221 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000222
Johnny Chend86d2692010-02-25 17:51:03 +0000223def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
224 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000225 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000226
227def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
228 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000229 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000230
231def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
232 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000233 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000234
235def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
236 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000237 T1Disassembly<0b11, 0x40>; // A8.6.157
238
239// The i32imm operand $val can be used by a debugger to store more information
240// about the breakpoint.
241def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
242 [/* For disassembly only; pattern left blank */]>,
243 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
244 // A8.6.22
245 bits<8> val;
246 let Inst{7-0} = val;
247}
Johnny Chend86d2692010-02-25 17:51:03 +0000248
249def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
250 [/* For disassembly only; pattern left blank */]>,
251 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000252 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000253 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000254 let Inst{4} = 1;
255 let Inst{3} = 1; // Big-Endian
256 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000257}
258
259def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
260 [/* For disassembly only; pattern left blank */]>,
261 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000262 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000263 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000264 let Inst{4} = 1;
265 let Inst{3} = 0; // Little-Endian
266 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000267}
268
Johnny Chen93042d12010-03-02 18:14:57 +0000269// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000270def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
271 NoItinerary, "cps$imod $iflags",
272 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000273 T1Misc<0b0110011> {
274 // A8.6.38 & B6.1.1
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000275 bit imod;
276 bits<3> iflags;
277
278 let Inst{4} = imod;
279 let Inst{3} = 0;
280 let Inst{2-0} = iflags;
Bill Wendling849f2e32010-11-29 00:18:15 +0000281}
Johnny Chen93042d12010-03-02 18:14:57 +0000282
Evan Cheng35d6c412009-08-04 23:47:55 +0000283// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000284let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000285def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000286 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000287 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000288 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000289 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000290 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000291 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000292}
Evan Chenga8e29892007-01-19 07:51:42 +0000293
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000294// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000295def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000296 "add\t$dst, pc, $rhs", []>,
297 T1Encoding<{1,0,1,0,0,?}> {
298 // A6.2 & A8.6.10
299 bits<3> dst;
300 bits<8> rhs;
301 let Inst{10-8} = dst;
302 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000303}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000304
Bill Wendling0ae28e42010-11-19 22:37:33 +0000305// ADD <Rd>, sp, #<imm8>
306// This is rematerializable, which is particularly useful for taking the
307// address of locals.
308let isReMaterializable = 1 in
309def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
310 "add\t$dst, $sp, $rhs", []>,
311 T1Encoding<{1,0,1,0,1,?}> {
312 // A6.2 & A8.6.8
313 bits<3> dst;
314 bits<8> rhs;
315 let Inst{10-8} = dst;
316 let Inst{7-0} = rhs;
317}
318
319// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000320def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000321 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000322 T1Misc<{0,0,0,0,0,?,?}> {
323 // A6.2.5 & A8.6.8
324 bits<7> rhs;
325 let Inst{6-0} = rhs;
326}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000327
Bill Wendling0ae28e42010-11-19 22:37:33 +0000328// SUB sp, sp, #<imm7>
329// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000330def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000331 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000332 T1Misc<{0,0,0,0,1,?,?}> {
333 // A6.2.5 & A8.6.214
334 bits<7> rhs;
335 let Inst{6-0} = rhs;
336}
Evan Cheng86198642009-08-07 00:34:42 +0000337
Bill Wendling0ae28e42010-11-19 22:37:33 +0000338// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000339def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000340 "add\t$dst, $rhs", []>,
341 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000342 // A8.6.9 Encoding T1
343 bits<4> dst;
344 let Inst{7} = dst{3};
345 let Inst{6-3} = 0b1101;
346 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000347}
Evan Cheng86198642009-08-07 00:34:42 +0000348
Bill Wendling0ae28e42010-11-19 22:37:33 +0000349// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000350def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000351 "add\t$dst, $rhs", []>,
352 T1Special<{0,0,?,?}> {
353 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000354 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000355 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000356 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000357 let Inst{2-0} = 0b101;
358}
Evan Cheng86198642009-08-07 00:34:42 +0000359
Evan Chenga8e29892007-01-19 07:51:42 +0000360//===----------------------------------------------------------------------===//
361// Control Flow Instructions.
362//
363
Jim Grosbachc732adf2009-09-30 01:35:11 +0000364let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Cameron Zwarich8e9bace2011-05-25 04:45:29 +0000365 def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr",
366 [(ARMretflag)]>,
367 T1Special<{1,1,0,?}> {
368 // A6.2.3 & A8.6.25
369 let Inst{6-3} = 0b1110; // Rm = lr
370 let Inst{2-0} = 0b000;
371 }
372
Evan Cheng9d945f72007-02-01 01:49:46 +0000373 // Alternative return instruction used by vararg functions.
Bill Wendling602890d2010-11-19 01:33:10 +0000374 def tBX_RET_vararg : TI<(outs), (ins tGPR:$Rm),
375 IIC_Br, "bx\t$Rm",
376 []>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000377 T1Special<{1,1,0,?}> {
378 // A6.2.3 & A8.6.25
Bill Wendling602890d2010-11-19 01:33:10 +0000379 bits<4> Rm;
380 let Inst{6-3} = Rm;
381 let Inst{2-0} = 0b000;
382 }
Evan Cheng9d945f72007-02-01 01:49:46 +0000383}
Evan Chenga8e29892007-01-19 07:51:42 +0000384
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000385// Indirect branches
386let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich421b1062011-05-26 03:41:12 +0000387 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
388 T1Special<{1,1,0,?}> {
389 // A6.2.3 & A8.6.25
390 bits<4> Rm;
391 let Inst{6-3} = Rm;
392 let Inst{2-0} = 0b000;
393 }
394
Bill Wendling534a5e42010-12-03 01:55:47 +0000395 def tBRIND : TI<(outs), (ins GPR:$Rm),
396 IIC_Br,
397 "mov\tpc, $Rm",
Bill Wendling602890d2010-11-19 01:33:10 +0000398 [(brind GPR:$Rm)]>,
Bill Wendling12280382010-11-19 23:14:32 +0000399 T1Special<{1,0,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000400 // A8.6.97
Bill Wendling602890d2010-11-19 01:33:10 +0000401 bits<4> Rm;
Bill Wendling849f2e32010-11-29 00:18:15 +0000402 let Inst{7} = 1; // <Rd> = Inst{7:2-0} = pc
Bill Wendling602890d2010-11-19 01:33:10 +0000403 let Inst{6-3} = Rm;
Bill Wendling12280382010-11-19 23:14:32 +0000404 let Inst{2-0} = 0b111;
Johnny Chend68e1192009-12-15 17:24:14 +0000405 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000406}
407
Evan Chenga8e29892007-01-19 07:51:42 +0000408// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000409let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
410 hasExtraDefRegAllocReq = 1 in
Jim Grosbach4629d502011-06-30 17:34:04 +0000411def tPOP_RET : tPseudoInst<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Jim Grosbach63b46fa2011-06-30 22:10:46 +0000412 Size2Bytes, IIC_iPop_Br, []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000413
Bill Wendling0480e282010-12-01 02:36:55 +0000414// All calls clobber the non-callee saved registers. SP is marked as a use to
415// prevent stack-pointer assignments that appear immediately before calls from
416// potentially appearing dead.
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000417let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000418 // On non-Darwin platforms R9 is callee-saved.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000419 Defs = [R0, R1, R2, R3, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000420 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000421 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000422 def tBL : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000423 (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000424 "bl\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000425 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000426 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000427 bits<21> func;
428 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000429 let Inst{13} = 1;
430 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000431 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000432 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000433
Evan Chengb6207242009-08-01 00:16:10 +0000434 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000435 def tBLXi : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000436 (outs), (ins t_blxtarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000437 "blx\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000438 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000439 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000440 bits<21> func;
441 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000442 let Inst{13} = 1;
443 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000444 let Inst{10-1} = func{10-1};
445 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000446 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000447
Evan Chengb6207242009-08-01 00:16:10 +0000448 // Also used for Thumb2
Jim Grosbach64171712010-02-16 21:07:46 +0000449 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000450 "blx\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000451 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000452 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
Owen Anderson18901d62011-05-11 17:00:48 +0000453 T1Special<{1,1,1,?}> { // A6.2.3 & A8.6.24;
454 bits<4> func;
455 let Inst{6-3} = func;
456 let Inst{2-0} = 0b000;
457 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000458
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000459 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000460 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
461 Size4Bytes, IIC_Br,
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000462 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000463 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000464}
465
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000466let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000467 // On Darwin R9 is call-clobbered.
468 // R7 is marked as a use to prevent frame-pointer assignments from being
469 // moved above / below calls.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000470 Defs = [R0, R1, R2, R3, R9, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000471 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000472 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000473 def tBLr9 : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000474 (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
475 IIC_Br, "bl${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000476 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000477 Requires<[IsThumb, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000478 bits<21> func;
479 let Inst{25-16} = func{20-11};
480 let Inst{13} = 1;
481 let Inst{11} = 1;
482 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000483 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000484
Evan Chengb6207242009-08-01 00:16:10 +0000485 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000486 def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000487 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
Jim Grosbach662a8162010-12-06 23:57:07 +0000488 IIC_Br, "blx${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000489 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000490 Requires<[IsThumb, HasV5T, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000491 bits<21> func;
492 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000493 let Inst{13} = 1;
494 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000495 let Inst{10-1} = func{10-1};
496 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000497 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000498
Evan Chengb6207242009-08-01 00:16:10 +0000499 // Also used for Thumb2
Bill Wendling849f2e32010-11-29 00:18:15 +0000500 def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
501 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000502 [(ARMtcall GPR:$func)]>,
503 Requires<[IsThumb, HasV5T, IsDarwin]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000504 T1Special<{1,1,1,?}> {
505 // A6.2.3 & A8.6.24
506 bits<4> func;
507 let Inst{6-3} = func;
508 let Inst{2-0} = 0b000;
509 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000510
511 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000512 def tBXr9_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
513 Size4Bytes, IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000514 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000515 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000516}
517
Bill Wendling0480e282010-12-01 02:36:55 +0000518let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
519 let isPredicable = 1 in
Jim Grosbache2467172010-12-10 18:21:33 +0000520 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
Bill Wendling0480e282010-12-01 02:36:55 +0000521 "b\t$target", [(br bb:$target)]>,
Jim Grosbache2467172010-12-10 18:21:33 +0000522 T1Encoding<{1,1,1,0,0,?}> {
523 bits<11> target;
524 let Inst{10-0} = target;
525 }
Evan Chenga8e29892007-01-19 07:51:42 +0000526
Evan Cheng225dfe92007-01-30 01:13:37 +0000527 // Far jump
Jim Grosbach3efad8f2010-12-16 19:11:16 +0000528 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
529 // the clobber of LR.
Evan Cheng53c67c02009-08-07 05:45:07 +0000530 let Defs = [LR] in
Jim Grosbach3efad8f2010-12-16 19:11:16 +0000531 def tBfar : tPseudoInst<(outs), (ins t_bltarget:$target),
532 Size4Bytes, IIC_Br, []>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000533
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000534 def tBR_JTr : tPseudoInst<(outs),
535 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
Bill Wendlinga519d572010-12-21 01:57:15 +0000536 SizeSpecial, IIC_Br,
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000537 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
538 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000539 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000540}
541
Evan Chengc85e8322007-07-05 07:13:32 +0000542// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000543// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000544let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000545 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000546 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000547 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Eric Christopher33281b22011-05-27 03:50:53 +0000548 T1BranchCond<{1,1,0,1}> {
Jim Grosbachceab5012010-12-04 00:20:40 +0000549 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000550 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000551 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000552 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000553}
Evan Chenga8e29892007-01-19 07:51:42 +0000554
Evan Chengde17fb62009-10-31 23:46:45 +0000555// Compare and branch on zero / non-zero
556let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000557 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000558 "cbz\t$Rn, $target", []>,
559 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000560 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000561 bits<6> target;
562 bits<3> Rn;
563 let Inst{9} = target{5};
564 let Inst{7-3} = target{4-0};
565 let Inst{2-0} = Rn;
566 }
Evan Chengde17fb62009-10-31 23:46:45 +0000567
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000568 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000569 "cbnz\t$cmp, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000570 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000571 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000572 bits<6> target;
573 bits<3> Rn;
574 let Inst{9} = target{5};
575 let Inst{7-3} = target{4-0};
576 let Inst{2-0} = Rn;
577 }
Evan Chengde17fb62009-10-31 23:46:45 +0000578}
579
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000580// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
581// A8.6.16 B: Encoding T1
582// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000583let isCall = 1, Uses = [SP] in
Bill Wendling6179c312010-11-20 00:53:35 +0000584def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
585 "svc", "\t$imm", []>, Encoding16 {
586 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000587 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000588 let Inst{11-8} = 0b1111;
589 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000590}
591
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000592// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000593let isBarrier = 1, isTerminator = 1 in
Owen Anderson18901d62011-05-11 17:00:48 +0000594def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000595 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000596 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000597}
598
Evan Chenga8e29892007-01-19 07:51:42 +0000599//===----------------------------------------------------------------------===//
600// Load Store Instructions.
601//
602
Bill Wendlingb6faf652010-12-14 22:10:49 +0000603// Loads: reg/reg and reg/imm5
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000604let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb6faf652010-12-14 22:10:49 +0000605multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
606 Operand AddrMode_r, Operand AddrMode_i,
607 AddrMode am, InstrItinClass itin_r,
608 InstrItinClass itin_i, string asm,
609 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000610 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000611 T1pILdStEncode<reg_opc,
612 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
613 am, itin_r, asm, "\t$Rt, $addr",
614 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000615 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000616 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
617 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
618 am, itin_i, asm, "\t$Rt, $addr",
619 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
620}
621// Stores: reg/reg and reg/imm5
622multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
623 Operand AddrMode_r, Operand AddrMode_i,
624 AddrMode am, InstrItinClass itin_r,
625 InstrItinClass itin_i, string asm,
626 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000627 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000628 T1pILdStEncode<reg_opc,
629 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
630 am, itin_r, asm, "\t$Rt, $addr",
631 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000632 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000633 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
634 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
635 am, itin_i, asm, "\t$Rt, $addr",
636 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
637}
Bill Wendling6179c312010-11-20 00:53:35 +0000638
Bill Wendlingb6faf652010-12-14 22:10:49 +0000639// A8.6.57 & A8.6.60
640defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
641 t_addrmode_is4, AddrModeT1_4,
642 IIC_iLoad_r, IIC_iLoad_i, "ldr",
643 UnOpFrag<(load node:$Src)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000644
Bill Wendlingb6faf652010-12-14 22:10:49 +0000645// A8.6.64 & A8.6.61
646defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
647 t_addrmode_is1, AddrModeT1_1,
648 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
649 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000650
Bill Wendlingb6faf652010-12-14 22:10:49 +0000651// A8.6.76 & A8.6.73
652defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
653 t_addrmode_is2, AddrModeT1_2,
654 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
655 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000656
Evan Cheng2f297df2009-07-11 07:08:13 +0000657let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000658def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000659 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
660 AddrModeT1_1, IIC_iLoad_bh_r,
661 "ldrsb", "\t$dst, $addr",
662 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000663
Evan Cheng2f297df2009-07-11 07:08:13 +0000664let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000665def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000666 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
667 AddrModeT1_2, IIC_iLoad_bh_r,
668 "ldrsh", "\t$dst, $addr",
669 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000670
Dan Gohman15511cf2008-12-03 18:15:48 +0000671let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000672def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000673 "ldr", "\t$Rt, $addr",
674 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000675 T1LdStSP<{1,?,?}> {
676 bits<3> Rt;
677 bits<8> addr;
678 let Inst{10-8} = Rt;
679 let Inst{7-0} = addr;
680}
Evan Cheng012f2d92007-01-24 08:53:17 +0000681
682// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000683// FIXME: Use ldr.n to work around a Darwin assembler bug.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000684let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000685def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000686 "ldr", ".n\t$Rt, $addr",
687 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
688 T1Encoding<{0,1,0,0,1,?}> {
689 // A6.2 & A8.6.59
690 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000691 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000692 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000693 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000694}
Evan Chengfa775d02007-03-19 07:20:03 +0000695
Johnny Chen597fa652011-04-22 19:12:43 +0000696// FIXME: Remove this entry when the above ldr.n workaround is fixed.
697// For disassembly use only.
698def tLDRpciDIS : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
699 "ldr", "\t$Rt, $addr",
700 [/* disassembly only */]>,
701 T1Encoding<{0,1,0,0,1,?}> {
702 // A6.2 & A8.6.59
703 bits<3> Rt;
704 bits<8> addr;
705 let Inst{10-8} = Rt;
706 let Inst{7-0} = addr;
707}
708
Bill Wendlingb6faf652010-12-14 22:10:49 +0000709// A8.6.194 & A8.6.192
710defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
711 t_addrmode_is4, AddrModeT1_4,
712 IIC_iStore_r, IIC_iStore_i, "str",
713 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000714
Bill Wendlingb6faf652010-12-14 22:10:49 +0000715// A8.6.197 & A8.6.195
716defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
717 t_addrmode_is1, AddrModeT1_1,
718 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
719 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000720
Bill Wendlingb6faf652010-12-14 22:10:49 +0000721// A8.6.207 & A8.6.205
722defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000723 t_addrmode_is2, AddrModeT1_2,
724 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
725 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000726
Evan Chenga8e29892007-01-19 07:51:42 +0000727
Jim Grosbachd967cd02010-12-07 21:50:47 +0000728def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendlingf4caf692010-12-14 03:36:38 +0000729 "str", "\t$Rt, $addr",
730 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000731 T1LdStSP<{0,?,?}> {
732 bits<3> Rt;
733 bits<8> addr;
734 let Inst{10-8} = Rt;
735 let Inst{7-0} = addr;
736}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000737
Evan Chenga8e29892007-01-19 07:51:42 +0000738//===----------------------------------------------------------------------===//
739// Load / store multiple Instructions.
740//
741
Bill Wendling6c470b82010-11-13 09:09:38 +0000742multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
743 InstrItinClass itin_upd, bits<6> T1Enc,
744 bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000745 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000746 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000747 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000748 T1Encoding<T1Enc> {
749 bits<3> Rn;
750 bits<8> regs;
751 let Inst{10-8} = Rn;
752 let Inst{7-0} = regs;
753 }
Bill Wendling73fe34a2010-11-16 01:16:36 +0000754 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +0000755 T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000756 itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000757 T1Encoding<T1Enc> {
758 bits<3> Rn;
759 bits<8> regs;
760 let Inst{10-8} = Rn;
761 let Inst{7-0} = regs;
762 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000763}
764
Bill Wendling73fe34a2010-11-16 01:16:36 +0000765// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000766let neverHasSideEffects = 1 in {
767
768let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
769defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
770 {1,1,0,0,1,?}, 1>;
771
772let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
773defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
774 {1,1,0,0,0,?}, 0>;
Owen Anderson18901d62011-05-11 17:00:48 +0000775
Bill Wendlingddc918b2010-11-13 10:57:02 +0000776} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000777
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000778let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000779def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000780 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000781 "pop${p}\t$regs", []>,
782 T1Misc<{1,1,0,?,?,?,?}> {
783 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000784 let Inst{8} = regs{15};
785 let Inst{7-0} = regs{7-0};
786}
Evan Cheng4b322e52009-08-11 21:11:32 +0000787
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000788let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000789def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000790 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000791 "push${p}\t$regs", []>,
792 T1Misc<{0,1,0,?,?,?,?}> {
793 bits<16> regs;
794 let Inst{8} = regs{14};
795 let Inst{7-0} = regs{7-0};
796}
Evan Chenga8e29892007-01-19 07:51:42 +0000797
798//===----------------------------------------------------------------------===//
799// Arithmetic Instructions.
800//
801
Bill Wendling1d045ee2010-12-01 02:28:08 +0000802// Helper classes for encoding T1pI patterns:
803class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
804 string opc, string asm, list<dag> pattern>
805 : T1pI<oops, iops, itin, opc, asm, pattern>,
806 T1DataProcessing<opA> {
807 bits<3> Rm;
808 bits<3> Rn;
809 let Inst{5-3} = Rm;
810 let Inst{2-0} = Rn;
811}
812class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
813 string opc, string asm, list<dag> pattern>
814 : T1pI<oops, iops, itin, opc, asm, pattern>,
815 T1Misc<opA> {
816 bits<3> Rm;
817 bits<3> Rd;
818 let Inst{5-3} = Rm;
819 let Inst{2-0} = Rd;
820}
821
Bill Wendling76f4e102010-12-01 01:20:15 +0000822// Helper classes for encoding T1sI patterns:
823class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
824 string opc, string asm, list<dag> pattern>
825 : T1sI<oops, iops, itin, opc, asm, pattern>,
826 T1DataProcessing<opA> {
827 bits<3> Rd;
828 bits<3> Rn;
829 let Inst{5-3} = Rn;
830 let Inst{2-0} = Rd;
831}
832class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
833 string opc, string asm, list<dag> pattern>
834 : T1sI<oops, iops, itin, opc, asm, pattern>,
835 T1General<opA> {
836 bits<3> Rm;
837 bits<3> Rn;
838 bits<3> Rd;
839 let Inst{8-6} = Rm;
840 let Inst{5-3} = Rn;
841 let Inst{2-0} = Rd;
842}
843class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
844 string opc, string asm, list<dag> pattern>
845 : T1sI<oops, iops, itin, opc, asm, pattern>,
846 T1General<opA> {
847 bits<3> Rd;
848 bits<3> Rm;
849 let Inst{5-3} = Rm;
850 let Inst{2-0} = Rd;
851}
852
853// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000854class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
855 string opc, string asm, list<dag> pattern>
856 : T1sIt<oops, iops, itin, opc, asm, pattern>,
857 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000858 bits<3> Rdn;
859 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000860 let Inst{5-3} = Rm;
861 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000862}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000863class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
864 string opc, string asm, list<dag> pattern>
865 : T1sIt<oops, iops, itin, opc, asm, pattern>,
866 T1General<opA> {
867 bits<3> Rdn;
868 bits<8> imm8;
869 let Inst{10-8} = Rdn;
870 let Inst{7-0} = imm8;
871}
872
873// Add with carry register
874let isCommutable = 1, Uses = [CPSR] in
875def tADC : // A8.6.2
876 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
877 "adc", "\t$Rdn, $Rm",
878 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000879
David Goodwinc9ee1182009-06-25 22:49:55 +0000880// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000881def tADDi3 : // A8.6.4 T1
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000882 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
883 IIC_iALUi,
Bill Wendling76f4e102010-12-01 01:20:15 +0000884 "add", "\t$Rd, $Rm, $imm3",
885 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000886 bits<3> imm3;
887 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000888}
Evan Chenga8e29892007-01-19 07:51:42 +0000889
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000890def tADDi8 : // A8.6.4 T2
891 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
892 IIC_iALUi,
893 "add", "\t$Rdn, $imm8",
894 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000895
David Goodwinc9ee1182009-06-25 22:49:55 +0000896// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000897let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000898def tADDrr : // A8.6.6 T1
899 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
900 IIC_iALUr,
901 "add", "\t$Rd, $Rn, $Rm",
902 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000903
Evan Chengcd799b92009-06-12 20:46:18 +0000904let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000905def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
906 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000907 T1Special<{0,0,?,?}> {
908 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000909 bits<4> Rdn;
910 bits<4> Rm;
911 let Inst{7} = Rdn{3};
912 let Inst{6-3} = Rm;
913 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000914}
Evan Chenga8e29892007-01-19 07:51:42 +0000915
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000916// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000917let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000918def tAND : // A8.6.12
919 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
920 IIC_iBITr,
921 "and", "\t$Rdn, $Rm",
922 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000923
David Goodwinc9ee1182009-06-25 22:49:55 +0000924// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000925def tASRri : // A8.6.14
926 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
927 IIC_iMOVsi,
928 "asr", "\t$Rd, $Rm, $imm5",
929 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000930 bits<5> imm5;
931 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000932}
Evan Chenga8e29892007-01-19 07:51:42 +0000933
David Goodwinc9ee1182009-06-25 22:49:55 +0000934// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000935def tASRrr : // A8.6.15
936 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
937 IIC_iMOVsr,
938 "asr", "\t$Rdn, $Rm",
939 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000940
David Goodwinc9ee1182009-06-25 22:49:55 +0000941// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000942def tBIC : // A8.6.20
943 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
944 IIC_iBITr,
945 "bic", "\t$Rdn, $Rm",
946 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000947
David Goodwinc9ee1182009-06-25 22:49:55 +0000948// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000949let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000950//FIXME: Disable CMN, as CCodes are backwards from compare expectations
951// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000952//def tCMN : // A8.6.33
953// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
954// IIC_iCMPr,
955// "cmn", "\t$lhs, $rhs",
956// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000957
958def tCMNz : // A8.6.33
959 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
960 IIC_iCMPr,
961 "cmn", "\t$Rn, $Rm",
962 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
963
964} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000965
David Goodwinc9ee1182009-06-25 22:49:55 +0000966// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000967let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000968def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
969 "cmp", "\t$Rn, $imm8",
970 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
971 T1General<{1,0,1,?,?}> {
972 // A8.6.35
973 bits<3> Rn;
974 bits<8> imm8;
975 let Inst{10-8} = Rn;
976 let Inst{7-0} = imm8;
977}
978
David Goodwinc9ee1182009-06-25 22:49:55 +0000979// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +0000980def tCMPr : // A8.6.36 T1
981 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
982 IIC_iCMPr,
983 "cmp", "\t$Rn, $Rm",
984 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
985
Bill Wendling849f2e32010-11-29 00:18:15 +0000986def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
987 "cmp", "\t$Rn, $Rm", []>,
988 T1Special<{0,1,?,?}> {
989 // A8.6.36 T2
990 bits<4> Rm;
991 bits<4> Rn;
992 let Inst{7} = Rn{3};
993 let Inst{6-3} = Rm;
994 let Inst{2-0} = Rn{2-0};
995}
Bill Wendling5cc88a22010-11-20 22:52:33 +0000996} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000997
Evan Chenga8e29892007-01-19 07:51:42 +0000998
David Goodwinc9ee1182009-06-25 22:49:55 +0000999// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +00001000let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001001def tEOR : // A8.6.45
1002 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1003 IIC_iBITr,
1004 "eor", "\t$Rdn, $Rm",
1005 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001006
David Goodwinc9ee1182009-06-25 22:49:55 +00001007// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001008def tLSLri : // A8.6.88
1009 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1010 IIC_iMOVsi,
1011 "lsl", "\t$Rd, $Rm, $imm5",
1012 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001013 bits<5> imm5;
1014 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001015}
Evan Chenga8e29892007-01-19 07:51:42 +00001016
David Goodwinc9ee1182009-06-25 22:49:55 +00001017// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001018def tLSLrr : // A8.6.89
1019 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1020 IIC_iMOVsr,
1021 "lsl", "\t$Rdn, $Rm",
1022 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001023
David Goodwinc9ee1182009-06-25 22:49:55 +00001024// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001025def tLSRri : // A8.6.90
1026 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1027 IIC_iMOVsi,
1028 "lsr", "\t$Rd, $Rm, $imm5",
1029 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001030 bits<5> imm5;
1031 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001032}
Evan Chenga8e29892007-01-19 07:51:42 +00001033
David Goodwinc9ee1182009-06-25 22:49:55 +00001034// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001035def tLSRrr : // A8.6.91
1036 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1037 IIC_iMOVsr,
1038 "lsr", "\t$Rdn, $Rm",
1039 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001040
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001041// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001042let isMoveImm = 1 in
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00001043def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001044 "mov", "\t$Rd, $imm8",
1045 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1046 T1General<{1,0,0,?,?}> {
1047 // A8.6.96
1048 bits<3> Rd;
1049 bits<8> imm8;
1050 let Inst{10-8} = Rd;
1051 let Inst{7-0} = imm8;
1052}
Evan Chenga8e29892007-01-19 07:51:42 +00001053
1054// TODO: A7-73: MOV(2) - mov setting flag.
1055
Evan Chengcd799b92009-06-12 20:46:18 +00001056let neverHasSideEffects = 1 in {
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001057def tMOVr : Thumb1pI<(outs tGPR:$Rd), (ins tGPR:$Rm), AddrModeNone,
1058 Size2Bytes, IIC_iMOVr,
1059 "mov", "\t$Rd, $Rm", "", []>,
Bill Wendling534a5e42010-12-03 01:55:47 +00001060 T1Special<0b1000> {
1061 // A8.6.97
1062 bits<4> Rd;
1063 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001064 // Bits {7-6} are encoded by the T1Special value.
1065 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001066 let Inst{2-0} = Rd{2-0};
1067}
Evan Cheng446c4282009-07-11 06:43:01 +00001068let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001069def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1070 "movs\t$Rd, $Rm", []>, Encoding16 {
1071 // A8.6.97
1072 bits<3> Rd;
1073 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001074 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001075 let Inst{5-3} = Rm;
1076 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001077}
Evan Cheng446c4282009-07-11 06:43:01 +00001078
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001079// FIXME: Do we really need separate instructions for GPR<-->tGPR like this?
1080// They all map to the same instruction (MOV encoding T1).
1081def tMOVgpr2tgpr : Thumb1pI<(outs tGPR:$Rd), (ins GPR:$Rm), AddrModeNone,
1082 Size2Bytes, IIC_iMOVr, "mov", "\t$Rd, $Rm", "", []>,
Bill Wendling534a5e42010-12-03 01:55:47 +00001083 T1Special<{1,0,0,?}> {
1084 // A8.6.97
1085 bits<4> Rd;
1086 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001087 // Bit {7} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001088 let Inst{6-3} = Rm;
1089 let Inst{2-0} = Rd{2-0};
1090}
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001091def tMOVtgpr2gpr : Thumb1pI<(outs GPR:$Rd), (ins tGPR:$Rm), AddrModeNone,
1092 Size2Bytes, IIC_iMOVr, "mov", "\t$Rd, $Rm", "", []>,
Bill Wendling534a5e42010-12-03 01:55:47 +00001093 T1Special<{1,0,?,0}> {
1094 // A8.6.97
1095 bits<4> Rd;
1096 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001097 // Bit {6} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001098 let Inst{7} = Rd{3};
Bill Wendling278b6e82010-12-03 02:02:58 +00001099 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001100 let Inst{2-0} = Rd{2-0};
1101}
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001102def tMOVgpr2gpr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
1103 Size2Bytes, IIC_iMOVr, "mov", "\t$Rd, $Rm", "", []>,
Bill Wendling534a5e42010-12-03 01:55:47 +00001104 T1Special<{1,0,?,?}> {
1105 // A8.6.97
1106 bits<4> Rd;
1107 bits<4> Rm;
1108 let Inst{7} = Rd{3};
1109 let Inst{6-3} = Rm;
1110 let Inst{2-0} = Rd{2-0};
1111}
Evan Chengcd799b92009-06-12 20:46:18 +00001112} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001113
Bill Wendling0480e282010-12-01 02:36:55 +00001114// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001115let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001116def tMUL : // A8.6.105 T1
1117 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1118 IIC_iMUL32,
1119 "mul", "\t$Rdn, $Rm, $Rdn",
1120 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001121
Bill Wendling76f4e102010-12-01 01:20:15 +00001122// Move inverse register
1123def tMVN : // A8.6.107
1124 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1125 "mvn", "\t$Rd, $Rn",
1126 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001127
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001128// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001129let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001130def tORR : // A8.6.114
1131 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1132 IIC_iBITr,
1133 "orr", "\t$Rdn, $Rm",
1134 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001135
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001136// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001137def tREV : // A8.6.134
1138 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1139 IIC_iUNAr,
1140 "rev", "\t$Rd, $Rm",
1141 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1142 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001143
Bill Wendling1d045ee2010-12-01 02:28:08 +00001144def tREV16 : // A8.6.135
1145 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1146 IIC_iUNAr,
1147 "rev16", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001148 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001149 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001150
Bill Wendling1d045ee2010-12-01 02:28:08 +00001151def tREVSH : // A8.6.136
1152 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1153 IIC_iUNAr,
1154 "revsh", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001155 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001156 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001157
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001158// Rotate right register
1159def tROR : // A8.6.139
1160 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1161 IIC_iMOVsr,
1162 "ror", "\t$Rdn, $Rm",
1163 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001164
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001165// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001166def tRSB : // A8.6.141
1167 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1168 IIC_iALUi,
1169 "rsb", "\t$Rd, $Rn, #0",
1170 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001171
David Goodwinc9ee1182009-06-25 22:49:55 +00001172// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001173let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001174def tSBC : // A8.6.151
1175 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1176 IIC_iALUr,
1177 "sbc", "\t$Rdn, $Rm",
1178 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001179
David Goodwinc9ee1182009-06-25 22:49:55 +00001180// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001181def tSUBi3 : // A8.6.210 T1
1182 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1183 IIC_iALUi,
1184 "sub", "\t$Rd, $Rm, $imm3",
1185 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001186 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001187 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001188}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001189
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001190def tSUBi8 : // A8.6.210 T2
1191 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1192 IIC_iALUi,
1193 "sub", "\t$Rdn, $imm8",
1194 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001195
Bill Wendling76f4e102010-12-01 01:20:15 +00001196// Subtract register
1197def tSUBrr : // A8.6.212
1198 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1199 IIC_iALUr,
1200 "sub", "\t$Rd, $Rn, $Rm",
1201 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001202
1203// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001204
Bill Wendling76f4e102010-12-01 01:20:15 +00001205// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001206def tSXTB : // A8.6.222
1207 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1208 IIC_iUNAr,
1209 "sxtb", "\t$Rd, $Rm",
1210 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1211 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001212
Bill Wendling1d045ee2010-12-01 02:28:08 +00001213// Sign-extend short
1214def tSXTH : // A8.6.224
1215 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1216 IIC_iUNAr,
1217 "sxth", "\t$Rd, $Rm",
1218 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1219 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001220
Bill Wendling1d045ee2010-12-01 02:28:08 +00001221// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001222let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001223def tTST : // A8.6.230
1224 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1225 "tst", "\t$Rn, $Rm",
1226 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001227
Bill Wendling1d045ee2010-12-01 02:28:08 +00001228// Zero-extend byte
1229def tUXTB : // A8.6.262
1230 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1231 IIC_iUNAr,
1232 "uxtb", "\t$Rd, $Rm",
1233 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1234 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001235
Bill Wendling1d045ee2010-12-01 02:28:08 +00001236// Zero-extend short
1237def tUXTH : // A8.6.264
1238 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1239 IIC_iUNAr,
1240 "uxth", "\t$Rd, $Rm",
1241 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1242 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001243
Jim Grosbach80dc1162010-02-16 21:23:02 +00001244// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001245// Expanded after instruction selection into a branch sequence.
1246let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001247 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001248 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001249 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001250 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001251
Evan Cheng007ea272009-08-12 05:17:19 +00001252
1253// 16-bit movcc in IT blocks for Thumb2.
Owen Andersonf523e472010-09-23 23:45:25 +00001254let neverHasSideEffects = 1 in {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001255def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1256 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001257 T1Special<{1,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001258 bits<4> Rdn;
1259 bits<4> Rm;
1260 let Inst{7} = Rdn{3};
1261 let Inst{6-3} = Rm;
1262 let Inst{2-0} = Rdn{2-0};
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001263}
Evan Cheng007ea272009-08-12 05:17:19 +00001264
Evan Chengc4af4632010-11-17 20:13:28 +00001265let isMoveImm = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +00001266def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1267 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001268 T1General<{1,0,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001269 bits<3> Rdn;
1270 bits<8> Rm;
1271 let Inst{10-8} = Rdn;
1272 let Inst{7-0} = Rm;
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001273}
1274
Owen Andersonf523e472010-09-23 23:45:25 +00001275} // neverHasSideEffects
Evan Cheng007ea272009-08-12 05:17:19 +00001276
Evan Chenga8e29892007-01-19 07:51:42 +00001277// tLEApcrel - Load a pc-relative address into a register without offending the
1278// assembler.
Jim Grosbachd40963c2010-12-14 22:28:03 +00001279
1280def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1281 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1282 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling67077412010-11-30 00:18:30 +00001283 bits<3> Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001284 bits<8> addr;
Bill Wendling67077412010-11-30 00:18:30 +00001285 let Inst{10-8} = Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001286 let Inst{7-0} = addr;
Bill Wendling67077412010-11-30 00:18:30 +00001287}
Evan Chenga8e29892007-01-19 07:51:42 +00001288
Jim Grosbachd40963c2010-12-14 22:28:03 +00001289let neverHasSideEffects = 1, isReMaterializable = 1 in
1290def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1291 Size2Bytes, IIC_iALUi, []>;
1292
1293def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1294 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1295 Size2Bytes, IIC_iALUi, []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001296
Evan Chenga8e29892007-01-19 07:51:42 +00001297//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001298// Move between coprocessor and ARM core register -- for disassembly only
1299//
1300
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00001301class tMovRCopro<string opc, bit direction, dag oops, dag iops,
1302 list<dag> pattern>
Bruno Cardoso Lopes026a42b2011-03-22 15:06:24 +00001303 : T1Cop<oops, iops, !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00001304 pattern> {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001305 let Inst{27-24} = 0b1110;
1306 let Inst{20} = direction;
1307 let Inst{4} = 1;
1308
1309 bits<4> Rt;
1310 bits<4> cop;
1311 bits<3> opc1;
1312 bits<3> opc2;
1313 bits<4> CRm;
1314 bits<4> CRn;
1315
1316 let Inst{15-12} = Rt;
1317 let Inst{11-8} = cop;
1318 let Inst{23-21} = opc1;
1319 let Inst{7-5} = opc2;
1320 let Inst{3-0} = CRm;
1321 let Inst{19-16} = CRn;
1322}
1323
Bruno Cardoso Lopes026a42b2011-03-22 15:06:24 +00001324def tMCR : tMovRCopro<"mcr", 0 /* from ARM core register to coprocessor */,
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00001325 (outs),
1326 (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, c_imm:$CRn,
1327 c_imm:$CRm, i32imm:$opc2),
1328 [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
1329 imm:$CRm, imm:$opc2)]>;
Bruno Cardoso Lopes026a42b2011-03-22 15:06:24 +00001330def tMRC : tMovRCopro<"mrc", 1 /* from coprocessor to ARM core register */,
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00001331 (outs GPR:$Rt),
1332 (ins p_imm:$cop, i32imm:$opc1, c_imm:$CRn, c_imm:$CRm, i32imm:$opc2),
1333 []>;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001334
Bruno Cardoso Lopes54ad87a2011-05-03 17:29:22 +00001335def : Pat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
1336 (tMRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>,
1337 Requires<[IsThumb, HasV6T2]>;
1338
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00001339class tMovRRCopro<string opc, bit direction,
1340 list<dag> pattern = [/* For disassembly only */]>
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001341 : T1Cop<(outs), (ins p_imm:$cop, i32imm:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00001342 !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001343 let Inst{27-24} = 0b1100;
1344 let Inst{23-21} = 0b010;
1345 let Inst{20} = direction;
1346
1347 bits<4> Rt;
1348 bits<4> Rt2;
1349 bits<4> cop;
1350 bits<4> opc1;
1351 bits<4> CRm;
1352
1353 let Inst{15-12} = Rt;
1354 let Inst{19-16} = Rt2;
1355 let Inst{11-8} = cop;
1356 let Inst{7-4} = opc1;
1357 let Inst{3-0} = CRm;
1358}
1359
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00001360def tMCRR : tMovRRCopro<"mcrr", 0 /* from ARM core register to coprocessor */,
1361 [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
1362 imm:$CRm)]>;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00001363def tMRRC : tMovRRCopro<"mrrc", 1 /* from coprocessor to ARM core register */>;
1364
1365//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00001366// Other Coprocessor Instructions. For disassembly only.
1367//
1368def tCDP : T1Cop<(outs), (ins p_imm:$cop, i32imm:$opc1,
1369 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, i32imm:$opc2),
1370 "cdp\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00001371 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
1372 imm:$CRm, imm:$opc2)]> {
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00001373 let Inst{27-24} = 0b1110;
1374
1375 bits<4> opc1;
1376 bits<4> CRn;
1377 bits<4> CRd;
1378 bits<4> cop;
1379 bits<3> opc2;
1380 bits<4> CRm;
1381
1382 let Inst{3-0} = CRm;
1383 let Inst{4} = 0;
1384 let Inst{7-5} = opc2;
1385 let Inst{11-8} = cop;
1386 let Inst{15-12} = CRd;
1387 let Inst{19-16} = CRn;
1388 let Inst{23-20} = opc1;
1389}
1390
1391//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001392// TLS Instructions
1393//
1394
1395// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbachff97eb02011-06-30 19:38:01 +00001396// This is a pseudo inst so that we can get the encoding right,
1397// complete with fixup for the aeabi_read_tp function.
1398let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
1399def tTPsoft : tPseudoInst<(outs), (ins), Size4Bytes, IIC_Br,
1400 [(set R0, ARMthread_pointer)]>;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001401
Bill Wendling0480e282010-12-01 02:36:55 +00001402//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001403// SJLJ Exception handling intrinsics
Owen Anderson18901d62011-05-11 17:00:48 +00001404//
Bill Wendling0480e282010-12-01 02:36:55 +00001405
1406// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1407// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1408// from some other function to get here, and we're using the stack frame for the
1409// containing function to save/restore registers, we can't keep anything live in
1410// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner7a2bdde2011-04-15 05:18:47 +00001411// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling0480e282010-12-01 02:36:55 +00001412// registers except for our own input by listing the relevant registers in
1413// Defs. By doing so, we also cause the prologue/epilogue code to actively
1414// preserve all of the callee-saved resgisters, which is exactly what we want.
1415// $val is a scratch register for our use.
Andrew Tricka1099f12011-06-07 00:08:49 +00001416let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001417 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1418def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1419 AddrModeNone, SizeSpecial, NoItinerary, "","",
1420 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001421
1422// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001423let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001424 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001425def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001426 AddrModeNone, SizeSpecial, IndexModeNone,
1427 Pseudo, NoItinerary, "", "",
1428 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1429 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001430
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001431//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001432// Non-Instruction Patterns
1433//
1434
Jim Grosbach97a884d2010-12-07 20:41:06 +00001435// Comparisons
1436def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1437 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1438def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1439 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1440
Evan Cheng892837a2009-07-10 02:09:04 +00001441// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001442def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1443 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1444def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001445 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001446def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1447 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001448
1449// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001450def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1451 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1452def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1453 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1454def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1455 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001456
Evan Chenga8e29892007-01-19 07:51:42 +00001457// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001458def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1459def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001460
Evan Chengd85ac4d2007-01-27 02:29:45 +00001461// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001462def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1463 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001464
Evan Chenga8e29892007-01-19 07:51:42 +00001465// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001466def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001467 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001468def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001469 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001470
1471def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001472 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001473def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001474 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001475
1476// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001477def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1478 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1479def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1480 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001481
1482// zextload i1 -> zextload i8
Bill Wendlingf4caf692010-12-14 03:36:38 +00001483def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1484 (tLDRBr t_addrmode_rrs1:$addr)>;
1485def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1486 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001487
Evan Chengb60c02e2007-01-26 19:13:16 +00001488// extload -> zextload
Bill Wendlingf4caf692010-12-14 03:36:38 +00001489def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1490def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1491def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1492def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1493def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1494def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001495
Evan Cheng0e87e232009-08-28 00:31:43 +00001496// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001497// ldr{b|h} + sxt{b|h} instead.
Bill Wendling415af342010-12-15 00:58:57 +00001498def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1499 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1500 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001501def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1502 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001503 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling415af342010-12-15 00:58:57 +00001504def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1505 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1506 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001507def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1508 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001509 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001510
Bill Wendlingf4caf692010-12-14 03:36:38 +00001511def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1512 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling415af342010-12-15 00:58:57 +00001513def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1514 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1515def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1516 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1517def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1518 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001519
Evan Chenga8e29892007-01-19 07:51:42 +00001520// Large immediate handling.
1521
1522// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001523def : T1Pat<(i32 thumb_immshifted:$src),
1524 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1525 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001526
Evan Cheng9cb9e672009-06-27 02:26:13 +00001527def : T1Pat<(i32 imm0_255_comp:$src),
1528 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001529
1530// Pseudo instruction that combines ldr from constpool and add pc. This should
1531// be expanded into two instructions late to allow if-conversion and
1532// scheduling.
1533let isReMaterializable = 1 in
1534def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001535 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001536 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1537 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001538 Requires<[IsThumb, IsThumb1Only]>;