blob: 5870f58baa37b4effc8ab7cb13bc767d386a298f [file] [log] [blame]
Bill Wendling0480e282010-12-01 02:36:55 +00001//===- ARMInstrThumb.td - Thumb support for ARM ------------*- tablegen -*-===//
Evan Chenga8e29892007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Thumb specific DAG Nodes.
16//
17
18def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
Chris Lattner036609b2010-12-23 18:28:41 +000019 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000020 SDNPVariadic]>;
Evan Chenga8e29892007-01-19 07:51:42 +000021
Evan Chenga8e29892007-01-19 07:51:42 +000022def imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000023 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000024}]>;
25def imm_comp_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000026 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000027}]>;
28
Evan Chenga8e29892007-01-19 07:51:42 +000029def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000030 return (uint32_t)-N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000031}], imm_neg_XFORM>;
32
Jim Grosbach6b8f1e32011-06-27 23:54:06 +000033def imm0_255_asmoperand : AsmOperandClass { let Name = "Imm0_255"; }
34def imm0_255 : Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 256; }]> {
35 let ParserMatchClass = imm0_255_asmoperand;
36}
Evan Chenga8e29892007-01-19 07:51:42 +000037def imm0_255_comp : 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}]>;
40
Eric Christopher8f232d32011-04-28 05:49:04 +000041def imm8_255 : ImmLeaf<i32, [{
42 return Imm >= 8 && Imm < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000043}]>;
44def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000045 unsigned Val = -N->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +000046 return Val >= 8 && Val < 256;
47}], imm_neg_XFORM>;
48
Bill Wendling0480e282010-12-01 02:36:55 +000049// Break imm's up into two pieces: an immediate + a left shift. This uses
50// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
51// to get the val/shift pieces.
Evan Chenga8e29892007-01-19 07:51:42 +000052def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000053 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000054}]>;
55
56def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000057 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000058 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000059}]>;
60
61def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000062 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000063 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000064}]>;
65
Jim Grosbachd40963c2010-12-14 22:28:03 +000066// ADR instruction labels.
67def t_adrlabel : Operand<i32> {
68 let EncoderMethod = "getThumbAdrLabelOpValue";
69}
70
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000071// Scaled 4 immediate.
72def t_imm_s4 : Operand<i32> {
73 let PrintMethod = "printThumbS4ImmOperand";
74}
75
Evan Chenga8e29892007-01-19 07:51:42 +000076// Define Thumb specific addressing modes.
77
Jim Grosbache2467172010-12-10 18:21:33 +000078def t_brtarget : Operand<OtherVT> {
79 let EncoderMethod = "getThumbBRTargetOpValue";
80}
81
Jim Grosbach01086452010-12-10 17:13:40 +000082def t_bcctarget : Operand<i32> {
83 let EncoderMethod = "getThumbBCCTargetOpValue";
84}
85
Jim Grosbachcf6220a2010-12-09 19:01:46 +000086def t_cbtarget : Operand<i32> {
Jim Grosbach027d6e82010-12-09 19:04:53 +000087 let EncoderMethod = "getThumbCBTargetOpValue";
Bill Wendlingdff2f712010-12-08 23:01:43 +000088}
89
Jim Grosbach662a8162010-12-06 23:57:07 +000090def t_bltarget : Operand<i32> {
91 let EncoderMethod = "getThumbBLTargetOpValue";
92}
93
Bill Wendling09aa3f02010-12-09 00:39:08 +000094def t_blxtarget : Operand<i32> {
95 let EncoderMethod = "getThumbBLXTargetOpValue";
96}
97
Bill Wendlingf4caf692010-12-14 03:36:38 +000098def MemModeRegThumbAsmOperand : AsmOperandClass {
99 let Name = "MemModeRegThumb";
100 let SuperClasses = [];
101}
102
103def MemModeImmThumbAsmOperand : AsmOperandClass {
104 let Name = "MemModeImmThumb";
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000105 let SuperClasses = [];
106}
107
Evan Chenga8e29892007-01-19 07:51:42 +0000108// t_addrmode_rr := reg + reg
109//
110def t_addrmode_rr : Operand<i32>,
111 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000112 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000113 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000114 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000115}
116
Bill Wendlingf4caf692010-12-14 03:36:38 +0000117// t_addrmode_rrs := reg + reg
Evan Chenga8e29892007-01-19 07:51:42 +0000118//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000119def t_addrmode_rrs1 : Operand<i32>,
120 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
121 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
122 let PrintMethod = "printThumbAddrModeRROperand";
123 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
124 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000125}
Bill Wendlingf4caf692010-12-14 03:36:38 +0000126def t_addrmode_rrs2 : Operand<i32>,
127 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
128 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
129 let PrintMethod = "printThumbAddrModeRROperand";
130 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
131 let ParserMatchClass = MemModeRegThumbAsmOperand;
132}
133def t_addrmode_rrs4 : Operand<i32>,
134 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
135 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
136 let PrintMethod = "printThumbAddrModeRROperand";
137 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
138 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000139}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000140
Bill Wendlingf4caf692010-12-14 03:36:38 +0000141// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc38f2bc2007-01-23 22:59:13 +0000142//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000143def t_addrmode_is4 : Operand<i32>,
144 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
145 let EncoderMethod = "getAddrModeISOpValue";
146 let PrintMethod = "printThumbAddrModeImm5S4Operand";
147 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
148 let ParserMatchClass = MemModeImmThumbAsmOperand;
149}
150
151// t_addrmode_is2 := reg + imm5 * 2
152//
153def t_addrmode_is2 : Operand<i32>,
154 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
155 let EncoderMethod = "getAddrModeISOpValue";
156 let PrintMethod = "printThumbAddrModeImm5S2Operand";
157 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
158 let ParserMatchClass = MemModeImmThumbAsmOperand;
159}
160
161// t_addrmode_is1 := reg + imm5
162//
163def t_addrmode_is1 : Operand<i32>,
164 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
165 let EncoderMethod = "getAddrModeISOpValue";
166 let PrintMethod = "printThumbAddrModeImm5S1Operand";
167 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
168 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000169}
170
171// t_addrmode_sp := sp + imm8 * 4
172//
173def t_addrmode_sp : Operand<i32>,
174 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbachd967cd02010-12-07 21:50:47 +0000175 let EncoderMethod = "getAddrModeThumbSPOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000176 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000177 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000178 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000179}
180
Bill Wendlingb8958b02010-12-08 01:57:09 +0000181// t_addrmode_pc := <label> => pc + imm8 * 4
182//
183def t_addrmode_pc : Operand<i32> {
184 let EncoderMethod = "getAddrModePCOpValue";
Bill Wendlingf4caf692010-12-14 03:36:38 +0000185 let ParserMatchClass = MemModeImmThumbAsmOperand;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000186}
187
Evan Chenga8e29892007-01-19 07:51:42 +0000188//===----------------------------------------------------------------------===//
189// Miscellaneous Instructions.
190//
191
Jim Grosbach4642ad32010-02-22 23:10:38 +0000192// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
193// from removing one half of the matched pairs. That breaks PEI, which assumes
194// these will always be in pairs, and asserts if it finds otherwise. Better way?
195let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000196def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000197 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
198 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
199 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000200
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000201def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000202 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
203 [(ARMcallseq_start imm:$amt)]>,
204 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000205}
Evan Cheng44bec522007-05-15 01:29:07 +0000206
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000207// T1Disassembly - A simple class to make encoding some disassembly patterns
208// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000209class T1Disassembly<bits<2> op1, bits<8> op2>
210 : T1Encoding<0b101111> {
211 let Inst{9-8} = op1;
212 let Inst{7-0} = op2;
213}
214
Johnny Chenbd2c6232010-02-25 03:28:51 +0000215def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
216 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000217 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000218
Johnny Chend86d2692010-02-25 17:51:03 +0000219def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
220 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000221 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000222
223def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
224 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000225 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000226
227def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
228 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000229 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000230
231def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
232 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000233 T1Disassembly<0b11, 0x40>; // A8.6.157
234
235// The i32imm operand $val can be used by a debugger to store more information
236// about the breakpoint.
237def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
238 [/* For disassembly only; pattern left blank */]>,
239 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
240 // A8.6.22
241 bits<8> val;
242 let Inst{7-0} = val;
243}
Johnny Chend86d2692010-02-25 17:51:03 +0000244
245def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
246 [/* For disassembly only; pattern left blank */]>,
247 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000248 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000249 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000250 let Inst{4} = 1;
251 let Inst{3} = 1; // Big-Endian
252 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000253}
254
255def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
256 [/* For disassembly only; pattern left blank */]>,
257 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000258 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000259 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000260 let Inst{4} = 1;
261 let Inst{3} = 0; // Little-Endian
262 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000263}
264
Johnny Chen93042d12010-03-02 18:14:57 +0000265// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000266def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
267 NoItinerary, "cps$imod $iflags",
268 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000269 T1Misc<0b0110011> {
270 // A8.6.38 & B6.1.1
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000271 bit imod;
272 bits<3> iflags;
273
274 let Inst{4} = imod;
275 let Inst{3} = 0;
276 let Inst{2-0} = iflags;
Bill Wendling849f2e32010-11-29 00:18:15 +0000277}
Johnny Chen93042d12010-03-02 18:14:57 +0000278
Evan Cheng35d6c412009-08-04 23:47:55 +0000279// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000280let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000281def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000282 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000283 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000284 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000285 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000286 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000287 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000288}
Evan Chenga8e29892007-01-19 07:51:42 +0000289
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000290// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000291def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000292 "add\t$dst, pc, $rhs", []>,
293 T1Encoding<{1,0,1,0,0,?}> {
294 // A6.2 & A8.6.10
295 bits<3> dst;
296 bits<8> rhs;
297 let Inst{10-8} = dst;
298 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000299}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000300
Bill Wendling0ae28e42010-11-19 22:37:33 +0000301// ADD <Rd>, sp, #<imm8>
302// This is rematerializable, which is particularly useful for taking the
303// address of locals.
304let isReMaterializable = 1 in
305def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
306 "add\t$dst, $sp, $rhs", []>,
307 T1Encoding<{1,0,1,0,1,?}> {
308 // A6.2 & A8.6.8
309 bits<3> dst;
310 bits<8> rhs;
311 let Inst{10-8} = dst;
312 let Inst{7-0} = rhs;
313}
314
315// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000316def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000317 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000318 T1Misc<{0,0,0,0,0,?,?}> {
319 // A6.2.5 & A8.6.8
320 bits<7> rhs;
321 let Inst{6-0} = rhs;
322}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000323
Bill Wendling0ae28e42010-11-19 22:37:33 +0000324// SUB sp, sp, #<imm7>
325// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000326def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000327 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000328 T1Misc<{0,0,0,0,1,?,?}> {
329 // A6.2.5 & A8.6.214
330 bits<7> rhs;
331 let Inst{6-0} = rhs;
332}
Evan Cheng86198642009-08-07 00:34:42 +0000333
Bill Wendling0ae28e42010-11-19 22:37:33 +0000334// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000335def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000336 "add\t$dst, $rhs", []>,
337 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000338 // A8.6.9 Encoding T1
339 bits<4> dst;
340 let Inst{7} = dst{3};
341 let Inst{6-3} = 0b1101;
342 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000343}
Evan Cheng86198642009-08-07 00:34:42 +0000344
Bill Wendling0ae28e42010-11-19 22:37:33 +0000345// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000346def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000347 "add\t$dst, $rhs", []>,
348 T1Special<{0,0,?,?}> {
349 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000350 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000351 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000352 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000353 let Inst{2-0} = 0b101;
354}
Evan Cheng86198642009-08-07 00:34:42 +0000355
Evan Chenga8e29892007-01-19 07:51:42 +0000356//===----------------------------------------------------------------------===//
357// Control Flow Instructions.
358//
359
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000360// Indirect branches
361let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich421b1062011-05-26 03:41:12 +0000362 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
363 T1Special<{1,1,0,?}> {
364 // A6.2.3 & A8.6.25
365 bits<4> Rm;
366 let Inst{6-3} = Rm;
367 let Inst{2-0} = 0b000;
368 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000369}
370
Jim Grosbachead77cd2011-07-08 21:04:05 +0000371let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson16884412011-07-13 23:22:26 +0000372 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Jim Grosbach25e6d482011-07-08 21:50:04 +0000373 [(ARMretflag)], (tBX LR, pred:$p)>;
Jim Grosbachead77cd2011-07-08 21:04:05 +0000374
375 // Alternative return instruction used by vararg functions.
Jim Grosbach25e6d482011-07-08 21:50:04 +0000376 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +0000377 2, IIC_Br, [],
Jim Grosbach25e6d482011-07-08 21:50:04 +0000378 (tBX GPR:$Rm, pred:$p)>;
Jim Grosbachead77cd2011-07-08 21:04:05 +0000379}
380
Bill Wendling0480e282010-12-01 02:36:55 +0000381// All calls clobber the non-callee saved registers. SP is marked as a use to
382// prevent stack-pointer assignments that appear immediately before calls from
383// potentially appearing dead.
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000384let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000385 // On non-Darwin platforms R9 is callee-saved.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000386 Defs = [R0, R1, R2, R3, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000387 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000388 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000389 def tBL : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000390 (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000391 "bl\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000392 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000393 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000394 bits<21> func;
395 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000396 let Inst{13} = 1;
397 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000398 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000399 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000400
Evan Chengb6207242009-08-01 00:16:10 +0000401 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000402 def tBLXi : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000403 (outs), (ins t_blxtarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000404 "blx\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000405 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000406 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000407 bits<21> func;
408 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000409 let Inst{13} = 1;
410 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000411 let Inst{10-1} = func{10-1};
412 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000413 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000414
Evan Chengb6207242009-08-01 00:16:10 +0000415 // Also used for Thumb2
Jim Grosbach64171712010-02-16 21:07:46 +0000416 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000417 "blx\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000418 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000419 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
Owen Anderson18901d62011-05-11 17:00:48 +0000420 T1Special<{1,1,1,?}> { // A6.2.3 & A8.6.24;
421 bits<4> func;
422 let Inst{6-3} = func;
423 let Inst{2-0} = 0b000;
424 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000425
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000426 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000427 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000428 4, IIC_Br,
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000429 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000430 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000431}
432
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000433let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000434 // On Darwin R9 is call-clobbered.
435 // R7 is marked as a use to prevent frame-pointer assignments from being
436 // moved above / below calls.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000437 Defs = [R0, R1, R2, R3, R9, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000438 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000439 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000440 def tBLr9 : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000441 (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
442 IIC_Br, "bl${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000443 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000444 Requires<[IsThumb, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000445 bits<21> func;
446 let Inst{25-16} = func{20-11};
447 let Inst{13} = 1;
448 let Inst{11} = 1;
449 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000450 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000451
Evan Chengb6207242009-08-01 00:16:10 +0000452 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000453 def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000454 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
Jim Grosbach662a8162010-12-06 23:57:07 +0000455 IIC_Br, "blx${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000456 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000457 Requires<[IsThumb, HasV5T, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000458 bits<21> func;
459 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000460 let Inst{13} = 1;
461 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000462 let Inst{10-1} = func{10-1};
463 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000464 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000465
Evan Chengb6207242009-08-01 00:16:10 +0000466 // Also used for Thumb2
Bill Wendling849f2e32010-11-29 00:18:15 +0000467 def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
468 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000469 [(ARMtcall GPR:$func)]>,
470 Requires<[IsThumb, HasV5T, IsDarwin]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000471 T1Special<{1,1,1,?}> {
472 // A6.2.3 & A8.6.24
473 bits<4> func;
474 let Inst{6-3} = func;
475 let Inst{2-0} = 0b000;
476 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000477
478 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000479 def tBXr9_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000480 4, IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000481 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000482 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000483}
484
Bill Wendling0480e282010-12-01 02:36:55 +0000485let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
486 let isPredicable = 1 in
Jim Grosbache2467172010-12-10 18:21:33 +0000487 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
Bill Wendling0480e282010-12-01 02:36:55 +0000488 "b\t$target", [(br bb:$target)]>,
Jim Grosbache2467172010-12-10 18:21:33 +0000489 T1Encoding<{1,1,1,0,0,?}> {
490 bits<11> target;
491 let Inst{10-0} = target;
492 }
Evan Chenga8e29892007-01-19 07:51:42 +0000493
Evan Cheng225dfe92007-01-30 01:13:37 +0000494 // Far jump
Jim Grosbach3efad8f2010-12-16 19:11:16 +0000495 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
496 // the clobber of LR.
Evan Cheng53c67c02009-08-07 05:45:07 +0000497 let Defs = [LR] in
Jim Grosbach53e3fc42011-07-08 17:40:42 +0000498 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target),
Owen Anderson16884412011-07-13 23:22:26 +0000499 4, IIC_Br, [], (tBL t_bltarget:$target)>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000500
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000501 def tBR_JTr : tPseudoInst<(outs),
502 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
Owen Anderson16884412011-07-13 23:22:26 +0000503 0, IIC_Br,
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000504 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
505 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000506 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000507}
508
Evan Chengc85e8322007-07-05 07:13:32 +0000509// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000510// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000511let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000512 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000513 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000514 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Eric Christopher33281b22011-05-27 03:50:53 +0000515 T1BranchCond<{1,1,0,1}> {
Jim Grosbachceab5012010-12-04 00:20:40 +0000516 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000517 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000518 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000519 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000520}
Evan Chenga8e29892007-01-19 07:51:42 +0000521
Evan Chengde17fb62009-10-31 23:46:45 +0000522// Compare and branch on zero / non-zero
523let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000524 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000525 "cbz\t$Rn, $target", []>,
526 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000527 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000528 bits<6> target;
529 bits<3> Rn;
530 let Inst{9} = target{5};
531 let Inst{7-3} = target{4-0};
532 let Inst{2-0} = Rn;
533 }
Evan Chengde17fb62009-10-31 23:46:45 +0000534
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000535 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000536 "cbnz\t$cmp, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000537 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000538 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000539 bits<6> target;
540 bits<3> Rn;
541 let Inst{9} = target{5};
542 let Inst{7-3} = target{4-0};
543 let Inst{2-0} = Rn;
544 }
Evan Chengde17fb62009-10-31 23:46:45 +0000545}
546
Jim Grosbache36e21e2011-07-08 20:13:35 +0000547// Tail calls
548let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
549 // Darwin versions.
550 let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
551 Uses = [SP] in {
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000552 // tTAILJMPd: Darwin version uses a Thumb2 branch (no Thumb1 tail calls
553 // on Darwin), so it's in ARMInstrThumb2.td.
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000554 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000555 4, IIC_Br, [],
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000556 (tBX GPR:$dst, (ops 14, zero_reg))>,
557 Requires<[IsThumb, IsDarwin]>;
Jim Grosbache36e21e2011-07-08 20:13:35 +0000558 }
559 // Non-Darwin versions (the difference is R9).
560 let Defs = [R0, R1, R2, R3, R12, QQQQ0, QQQQ2, QQQQ3, PC],
561 Uses = [SP] in {
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000562 def tTAILJMPdND : tPseudoExpand<(outs), (ins t_brtarget:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000563 4, IIC_Br, [],
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000564 (tB t_brtarget:$dst)>,
565 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000566 def tTAILJMPrND : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000567 4, IIC_Br, [],
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000568 (tBX GPR:$dst, (ops 14, zero_reg))>,
569 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbache36e21e2011-07-08 20:13:35 +0000570 }
571}
572
573
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000574// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
575// A8.6.16 B: Encoding T1
576// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000577let isCall = 1, Uses = [SP] in
Bill Wendling6179c312010-11-20 00:53:35 +0000578def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
579 "svc", "\t$imm", []>, Encoding16 {
580 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000581 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000582 let Inst{11-8} = 0b1111;
583 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000584}
585
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000586// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000587let isBarrier = 1, isTerminator = 1 in
Owen Anderson18901d62011-05-11 17:00:48 +0000588def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000589 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000590 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000591}
592
Evan Chenga8e29892007-01-19 07:51:42 +0000593//===----------------------------------------------------------------------===//
594// Load Store Instructions.
595//
596
Bill Wendlingb6faf652010-12-14 22:10:49 +0000597// Loads: reg/reg and reg/imm5
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000598let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb6faf652010-12-14 22:10:49 +0000599multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
600 Operand AddrMode_r, Operand AddrMode_i,
601 AddrMode am, InstrItinClass itin_r,
602 InstrItinClass itin_i, string asm,
603 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000604 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000605 T1pILdStEncode<reg_opc,
606 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
607 am, itin_r, asm, "\t$Rt, $addr",
608 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000609 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000610 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
611 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
612 am, itin_i, asm, "\t$Rt, $addr",
613 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
614}
615// Stores: reg/reg and reg/imm5
616multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
617 Operand AddrMode_r, Operand AddrMode_i,
618 AddrMode am, InstrItinClass itin_r,
619 InstrItinClass itin_i, string asm,
620 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000621 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000622 T1pILdStEncode<reg_opc,
623 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
624 am, itin_r, asm, "\t$Rt, $addr",
625 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000626 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000627 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
628 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
629 am, itin_i, asm, "\t$Rt, $addr",
630 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
631}
Bill Wendling6179c312010-11-20 00:53:35 +0000632
Bill Wendlingb6faf652010-12-14 22:10:49 +0000633// A8.6.57 & A8.6.60
634defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
635 t_addrmode_is4, AddrModeT1_4,
636 IIC_iLoad_r, IIC_iLoad_i, "ldr",
637 UnOpFrag<(load node:$Src)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000638
Bill Wendlingb6faf652010-12-14 22:10:49 +0000639// A8.6.64 & A8.6.61
640defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
641 t_addrmode_is1, AddrModeT1_1,
642 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
643 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000644
Bill Wendlingb6faf652010-12-14 22:10:49 +0000645// A8.6.76 & A8.6.73
646defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
647 t_addrmode_is2, AddrModeT1_2,
648 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
649 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000650
Evan Cheng2f297df2009-07-11 07:08:13 +0000651let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000652def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000653 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
654 AddrModeT1_1, IIC_iLoad_bh_r,
655 "ldrsb", "\t$dst, $addr",
656 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000657
Evan Cheng2f297df2009-07-11 07:08:13 +0000658let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000659def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000660 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
661 AddrModeT1_2, IIC_iLoad_bh_r,
662 "ldrsh", "\t$dst, $addr",
663 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000664
Dan Gohman15511cf2008-12-03 18:15:48 +0000665let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000666def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000667 "ldr", "\t$Rt, $addr",
668 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000669 T1LdStSP<{1,?,?}> {
670 bits<3> Rt;
671 bits<8> addr;
672 let Inst{10-8} = Rt;
673 let Inst{7-0} = addr;
674}
Evan Cheng012f2d92007-01-24 08:53:17 +0000675
676// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000677// FIXME: Use ldr.n to work around a Darwin assembler bug.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000678let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000679def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000680 "ldr", ".n\t$Rt, $addr",
681 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
682 T1Encoding<{0,1,0,0,1,?}> {
683 // A6.2 & A8.6.59
684 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000685 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000686 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000687 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000688}
Evan Chengfa775d02007-03-19 07:20:03 +0000689
Johnny Chen597fa652011-04-22 19:12:43 +0000690// FIXME: Remove this entry when the above ldr.n workaround is fixed.
691// For disassembly use only.
692def tLDRpciDIS : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
693 "ldr", "\t$Rt, $addr",
694 [/* disassembly only */]>,
695 T1Encoding<{0,1,0,0,1,?}> {
696 // A6.2 & A8.6.59
697 bits<3> Rt;
698 bits<8> addr;
699 let Inst{10-8} = Rt;
700 let Inst{7-0} = addr;
701}
702
Bill Wendlingb6faf652010-12-14 22:10:49 +0000703// A8.6.194 & A8.6.192
704defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
705 t_addrmode_is4, AddrModeT1_4,
706 IIC_iStore_r, IIC_iStore_i, "str",
707 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000708
Bill Wendlingb6faf652010-12-14 22:10:49 +0000709// A8.6.197 & A8.6.195
710defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
711 t_addrmode_is1, AddrModeT1_1,
712 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
713 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000714
Bill Wendlingb6faf652010-12-14 22:10:49 +0000715// A8.6.207 & A8.6.205
716defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000717 t_addrmode_is2, AddrModeT1_2,
718 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
719 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000720
Evan Chenga8e29892007-01-19 07:51:42 +0000721
Jim Grosbachd967cd02010-12-07 21:50:47 +0000722def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendlingf4caf692010-12-14 03:36:38 +0000723 "str", "\t$Rt, $addr",
724 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000725 T1LdStSP<{0,?,?}> {
726 bits<3> Rt;
727 bits<8> addr;
728 let Inst{10-8} = Rt;
729 let Inst{7-0} = addr;
730}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000731
Evan Chenga8e29892007-01-19 07:51:42 +0000732//===----------------------------------------------------------------------===//
733// Load / store multiple Instructions.
734//
735
Bill Wendling6c470b82010-11-13 09:09:38 +0000736multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
737 InstrItinClass itin_upd, bits<6> T1Enc,
738 bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000739 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000740 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000741 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000742 T1Encoding<T1Enc> {
743 bits<3> Rn;
744 bits<8> regs;
745 let Inst{10-8} = Rn;
746 let Inst{7-0} = regs;
747 }
Bill Wendling73fe34a2010-11-16 01:16:36 +0000748 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +0000749 T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000750 itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000751 T1Encoding<T1Enc> {
752 bits<3> Rn;
753 bits<8> regs;
754 let Inst{10-8} = Rn;
755 let Inst{7-0} = regs;
756 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000757}
758
Bill Wendling73fe34a2010-11-16 01:16:36 +0000759// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000760let neverHasSideEffects = 1 in {
761
762let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
763defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
764 {1,1,0,0,1,?}, 1>;
765
766let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
767defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
768 {1,1,0,0,0,?}, 0>;
Owen Anderson18901d62011-05-11 17:00:48 +0000769
Bill Wendlingddc918b2010-11-13 10:57:02 +0000770} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000771
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000772let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000773def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000774 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000775 "pop${p}\t$regs", []>,
776 T1Misc<{1,1,0,?,?,?,?}> {
777 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000778 let Inst{8} = regs{15};
779 let Inst{7-0} = regs{7-0};
780}
Evan Cheng4b322e52009-08-11 21:11:32 +0000781
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000782let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000783def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000784 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000785 "push${p}\t$regs", []>,
786 T1Misc<{0,1,0,?,?,?,?}> {
787 bits<16> regs;
788 let Inst{8} = regs{14};
789 let Inst{7-0} = regs{7-0};
790}
Evan Chenga8e29892007-01-19 07:51:42 +0000791
792//===----------------------------------------------------------------------===//
793// Arithmetic Instructions.
794//
795
Bill Wendling1d045ee2010-12-01 02:28:08 +0000796// Helper classes for encoding T1pI patterns:
797class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
798 string opc, string asm, list<dag> pattern>
799 : T1pI<oops, iops, itin, opc, asm, pattern>,
800 T1DataProcessing<opA> {
801 bits<3> Rm;
802 bits<3> Rn;
803 let Inst{5-3} = Rm;
804 let Inst{2-0} = Rn;
805}
806class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
807 string opc, string asm, list<dag> pattern>
808 : T1pI<oops, iops, itin, opc, asm, pattern>,
809 T1Misc<opA> {
810 bits<3> Rm;
811 bits<3> Rd;
812 let Inst{5-3} = Rm;
813 let Inst{2-0} = Rd;
814}
815
Bill Wendling76f4e102010-12-01 01:20:15 +0000816// Helper classes for encoding T1sI patterns:
817class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
818 string opc, string asm, list<dag> pattern>
819 : T1sI<oops, iops, itin, opc, asm, pattern>,
820 T1DataProcessing<opA> {
821 bits<3> Rd;
822 bits<3> Rn;
823 let Inst{5-3} = Rn;
824 let Inst{2-0} = Rd;
825}
826class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
827 string opc, string asm, list<dag> pattern>
828 : T1sI<oops, iops, itin, opc, asm, pattern>,
829 T1General<opA> {
830 bits<3> Rm;
831 bits<3> Rn;
832 bits<3> Rd;
833 let Inst{8-6} = Rm;
834 let Inst{5-3} = Rn;
835 let Inst{2-0} = Rd;
836}
837class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
838 string opc, string asm, list<dag> pattern>
839 : T1sI<oops, iops, itin, opc, asm, pattern>,
840 T1General<opA> {
841 bits<3> Rd;
842 bits<3> Rm;
843 let Inst{5-3} = Rm;
844 let Inst{2-0} = Rd;
845}
846
847// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000848class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
849 string opc, string asm, list<dag> pattern>
850 : T1sIt<oops, iops, itin, opc, asm, pattern>,
851 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000852 bits<3> Rdn;
853 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000854 let Inst{5-3} = Rm;
855 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000856}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000857class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
858 string opc, string asm, list<dag> pattern>
859 : T1sIt<oops, iops, itin, opc, asm, pattern>,
860 T1General<opA> {
861 bits<3> Rdn;
862 bits<8> imm8;
863 let Inst{10-8} = Rdn;
864 let Inst{7-0} = imm8;
865}
866
867// Add with carry register
868let isCommutable = 1, Uses = [CPSR] in
869def tADC : // A8.6.2
870 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
871 "adc", "\t$Rdn, $Rm",
872 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000873
David Goodwinc9ee1182009-06-25 22:49:55 +0000874// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000875def tADDi3 : // A8.6.4 T1
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000876 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
877 IIC_iALUi,
Bill Wendling76f4e102010-12-01 01:20:15 +0000878 "add", "\t$Rd, $Rm, $imm3",
879 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000880 bits<3> imm3;
881 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000882}
Evan Chenga8e29892007-01-19 07:51:42 +0000883
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000884def tADDi8 : // A8.6.4 T2
885 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
886 IIC_iALUi,
887 "add", "\t$Rdn, $imm8",
888 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000889
David Goodwinc9ee1182009-06-25 22:49:55 +0000890// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000891let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000892def tADDrr : // A8.6.6 T1
893 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
894 IIC_iALUr,
895 "add", "\t$Rd, $Rn, $Rm",
896 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000897
Evan Chengcd799b92009-06-12 20:46:18 +0000898let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000899def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
900 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000901 T1Special<{0,0,?,?}> {
902 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000903 bits<4> Rdn;
904 bits<4> Rm;
905 let Inst{7} = Rdn{3};
906 let Inst{6-3} = Rm;
907 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000908}
Evan Chenga8e29892007-01-19 07:51:42 +0000909
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000910// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000911let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000912def tAND : // A8.6.12
913 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
914 IIC_iBITr,
915 "and", "\t$Rdn, $Rm",
916 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000917
David Goodwinc9ee1182009-06-25 22:49:55 +0000918// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000919def tASRri : // A8.6.14
920 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
921 IIC_iMOVsi,
922 "asr", "\t$Rd, $Rm, $imm5",
923 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000924 bits<5> imm5;
925 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000926}
Evan Chenga8e29892007-01-19 07:51:42 +0000927
David Goodwinc9ee1182009-06-25 22:49:55 +0000928// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000929def tASRrr : // A8.6.15
930 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
931 IIC_iMOVsr,
932 "asr", "\t$Rdn, $Rm",
933 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000934
David Goodwinc9ee1182009-06-25 22:49:55 +0000935// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000936def tBIC : // A8.6.20
937 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
938 IIC_iBITr,
939 "bic", "\t$Rdn, $Rm",
940 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000941
David Goodwinc9ee1182009-06-25 22:49:55 +0000942// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000943let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000944//FIXME: Disable CMN, as CCodes are backwards from compare expectations
945// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000946//def tCMN : // A8.6.33
947// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
948// IIC_iCMPr,
949// "cmn", "\t$lhs, $rhs",
950// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000951
952def tCMNz : // A8.6.33
953 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
954 IIC_iCMPr,
955 "cmn", "\t$Rn, $Rm",
956 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
957
958} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000959
David Goodwinc9ee1182009-06-25 22:49:55 +0000960// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000961let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000962def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
963 "cmp", "\t$Rn, $imm8",
964 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
965 T1General<{1,0,1,?,?}> {
966 // A8.6.35
967 bits<3> Rn;
968 bits<8> imm8;
969 let Inst{10-8} = Rn;
970 let Inst{7-0} = imm8;
971}
972
David Goodwinc9ee1182009-06-25 22:49:55 +0000973// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +0000974def tCMPr : // A8.6.36 T1
975 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
976 IIC_iCMPr,
977 "cmp", "\t$Rn, $Rm",
978 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
979
Bill Wendling849f2e32010-11-29 00:18:15 +0000980def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
981 "cmp", "\t$Rn, $Rm", []>,
982 T1Special<{0,1,?,?}> {
983 // A8.6.36 T2
984 bits<4> Rm;
985 bits<4> Rn;
986 let Inst{7} = Rn{3};
987 let Inst{6-3} = Rm;
988 let Inst{2-0} = Rn{2-0};
989}
Bill Wendling5cc88a22010-11-20 22:52:33 +0000990} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000991
Evan Chenga8e29892007-01-19 07:51:42 +0000992
David Goodwinc9ee1182009-06-25 22:49:55 +0000993// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +0000994let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000995def tEOR : // A8.6.45
996 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
997 IIC_iBITr,
998 "eor", "\t$Rdn, $Rm",
999 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001000
David Goodwinc9ee1182009-06-25 22:49:55 +00001001// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001002def tLSLri : // A8.6.88
1003 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1004 IIC_iMOVsi,
1005 "lsl", "\t$Rd, $Rm, $imm5",
1006 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001007 bits<5> imm5;
1008 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001009}
Evan Chenga8e29892007-01-19 07:51:42 +00001010
David Goodwinc9ee1182009-06-25 22:49:55 +00001011// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001012def tLSLrr : // A8.6.89
1013 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1014 IIC_iMOVsr,
1015 "lsl", "\t$Rdn, $Rm",
1016 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001017
David Goodwinc9ee1182009-06-25 22:49:55 +00001018// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001019def tLSRri : // A8.6.90
1020 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1021 IIC_iMOVsi,
1022 "lsr", "\t$Rd, $Rm, $imm5",
1023 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001024 bits<5> imm5;
1025 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001026}
Evan Chenga8e29892007-01-19 07:51:42 +00001027
David Goodwinc9ee1182009-06-25 22:49:55 +00001028// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001029def tLSRrr : // A8.6.91
1030 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1031 IIC_iMOVsr,
1032 "lsr", "\t$Rdn, $Rm",
1033 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001034
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001035// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001036let isMoveImm = 1 in
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00001037def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001038 "mov", "\t$Rd, $imm8",
1039 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1040 T1General<{1,0,0,?,?}> {
1041 // A8.6.96
1042 bits<3> Rd;
1043 bits<8> imm8;
1044 let Inst{10-8} = Rd;
1045 let Inst{7-0} = imm8;
1046}
Evan Chenga8e29892007-01-19 07:51:42 +00001047
Jim Grosbachefeedce2011-07-01 17:14:11 +00001048// A7-73: MOV(2) - mov setting flag.
Evan Chenga8e29892007-01-19 07:51:42 +00001049
Evan Chengcd799b92009-06-12 20:46:18 +00001050let neverHasSideEffects = 1 in {
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001051def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson16884412011-07-13 23:22:26 +00001052 2, IIC_iMOVr,
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001053 "mov", "\t$Rd, $Rm", "", []>,
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001054 T1Special<{1,0,?,?}> {
Bill Wendling534a5e42010-12-03 01:55:47 +00001055 // A8.6.97
1056 bits<4> Rd;
1057 bits<4> Rm;
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001058 let Inst{7} = Rd{3};
1059 let Inst{6-3} = Rm;
Bill Wendling534a5e42010-12-03 01:55:47 +00001060 let Inst{2-0} = Rd{2-0};
1061}
Evan Cheng446c4282009-07-11 06:43:01 +00001062let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001063def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1064 "movs\t$Rd, $Rm", []>, Encoding16 {
1065 // A8.6.97
1066 bits<3> Rd;
1067 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001068 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001069 let Inst{5-3} = Rm;
1070 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001071}
Evan Chengcd799b92009-06-12 20:46:18 +00001072} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001073
Bill Wendling0480e282010-12-01 02:36:55 +00001074// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001075let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001076def tMUL : // A8.6.105 T1
1077 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1078 IIC_iMUL32,
1079 "mul", "\t$Rdn, $Rm, $Rdn",
1080 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001081
Bill Wendling76f4e102010-12-01 01:20:15 +00001082// Move inverse register
1083def tMVN : // A8.6.107
1084 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1085 "mvn", "\t$Rd, $Rn",
1086 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001087
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001088// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001089let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001090def tORR : // A8.6.114
1091 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1092 IIC_iBITr,
1093 "orr", "\t$Rdn, $Rm",
1094 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001095
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001096// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001097def tREV : // A8.6.134
1098 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1099 IIC_iUNAr,
1100 "rev", "\t$Rd, $Rm",
1101 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1102 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001103
Bill Wendling1d045ee2010-12-01 02:28:08 +00001104def tREV16 : // A8.6.135
1105 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1106 IIC_iUNAr,
1107 "rev16", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001108 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001109 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001110
Bill Wendling1d045ee2010-12-01 02:28:08 +00001111def tREVSH : // A8.6.136
1112 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1113 IIC_iUNAr,
1114 "revsh", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001115 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001116 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001117
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001118// Rotate right register
1119def tROR : // A8.6.139
1120 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1121 IIC_iMOVsr,
1122 "ror", "\t$Rdn, $Rm",
1123 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001124
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001125// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001126def tRSB : // A8.6.141
1127 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1128 IIC_iALUi,
1129 "rsb", "\t$Rd, $Rn, #0",
1130 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001131
David Goodwinc9ee1182009-06-25 22:49:55 +00001132// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001133let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001134def tSBC : // A8.6.151
1135 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1136 IIC_iALUr,
1137 "sbc", "\t$Rdn, $Rm",
1138 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001139
David Goodwinc9ee1182009-06-25 22:49:55 +00001140// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001141def tSUBi3 : // A8.6.210 T1
1142 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1143 IIC_iALUi,
1144 "sub", "\t$Rd, $Rm, $imm3",
1145 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001146 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001147 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001148}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001149
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001150def tSUBi8 : // A8.6.210 T2
1151 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1152 IIC_iALUi,
1153 "sub", "\t$Rdn, $imm8",
1154 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001155
Bill Wendling76f4e102010-12-01 01:20:15 +00001156// Subtract register
1157def tSUBrr : // A8.6.212
1158 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1159 IIC_iALUr,
1160 "sub", "\t$Rd, $Rn, $Rm",
1161 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001162
1163// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001164
Bill Wendling76f4e102010-12-01 01:20:15 +00001165// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001166def tSXTB : // A8.6.222
1167 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1168 IIC_iUNAr,
1169 "sxtb", "\t$Rd, $Rm",
1170 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1171 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001172
Bill Wendling1d045ee2010-12-01 02:28:08 +00001173// Sign-extend short
1174def tSXTH : // A8.6.224
1175 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1176 IIC_iUNAr,
1177 "sxth", "\t$Rd, $Rm",
1178 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1179 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001180
Bill Wendling1d045ee2010-12-01 02:28:08 +00001181// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001182let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001183def tTST : // A8.6.230
1184 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1185 "tst", "\t$Rn, $Rm",
1186 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001187
Bill Wendling1d045ee2010-12-01 02:28:08 +00001188// Zero-extend byte
1189def tUXTB : // A8.6.262
1190 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1191 IIC_iUNAr,
1192 "uxtb", "\t$Rd, $Rm",
1193 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1194 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001195
Bill Wendling1d045ee2010-12-01 02:28:08 +00001196// Zero-extend short
1197def tUXTH : // A8.6.264
1198 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1199 IIC_iUNAr,
1200 "uxth", "\t$Rd, $Rm",
1201 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1202 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001203
Jim Grosbach80dc1162010-02-16 21:23:02 +00001204// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001205// Expanded after instruction selection into a branch sequence.
1206let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001207 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001208 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001209 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001210 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001211
1212// tLEApcrel - Load a pc-relative address into a register without offending the
1213// assembler.
Jim Grosbachd40963c2010-12-14 22:28:03 +00001214
1215def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1216 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1217 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling67077412010-11-30 00:18:30 +00001218 bits<3> Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001219 bits<8> addr;
Bill Wendling67077412010-11-30 00:18:30 +00001220 let Inst{10-8} = Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001221 let Inst{7-0} = addr;
Bill Wendling67077412010-11-30 00:18:30 +00001222}
Evan Chenga8e29892007-01-19 07:51:42 +00001223
Jim Grosbachd40963c2010-12-14 22:28:03 +00001224let neverHasSideEffects = 1, isReMaterializable = 1 in
1225def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001226 2, IIC_iALUi, []>;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001227
1228def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1229 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001230 2, IIC_iALUi, []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001231
Evan Chenga8e29892007-01-19 07:51:42 +00001232//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001233// TLS Instructions
1234//
1235
1236// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbachff97eb02011-06-30 19:38:01 +00001237// This is a pseudo inst so that we can get the encoding right,
1238// complete with fixup for the aeabi_read_tp function.
1239let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson16884412011-07-13 23:22:26 +00001240def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Jim Grosbachff97eb02011-06-30 19:38:01 +00001241 [(set R0, ARMthread_pointer)]>;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001242
Bill Wendling0480e282010-12-01 02:36:55 +00001243//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001244// SJLJ Exception handling intrinsics
Owen Anderson18901d62011-05-11 17:00:48 +00001245//
Bill Wendling0480e282010-12-01 02:36:55 +00001246
1247// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1248// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1249// from some other function to get here, and we're using the stack frame for the
1250// containing function to save/restore registers, we can't keep anything live in
1251// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner7a2bdde2011-04-15 05:18:47 +00001252// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling0480e282010-12-01 02:36:55 +00001253// registers except for our own input by listing the relevant registers in
1254// Defs. By doing so, we also cause the prologue/epilogue code to actively
1255// preserve all of the callee-saved resgisters, which is exactly what we want.
1256// $val is a scratch register for our use.
Andrew Tricka1099f12011-06-07 00:08:49 +00001257let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001258 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1259def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson16884412011-07-13 23:22:26 +00001260 AddrModeNone, 0, NoItinerary, "","",
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001261 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001262
1263// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001264let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001265 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001266def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson16884412011-07-13 23:22:26 +00001267 AddrModeNone, 0, IndexModeNone,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001268 Pseudo, NoItinerary, "", "",
1269 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1270 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001271
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001272//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001273// Non-Instruction Patterns
1274//
1275
Jim Grosbach97a884d2010-12-07 20:41:06 +00001276// Comparisons
1277def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1278 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1279def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1280 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1281
Evan Cheng892837a2009-07-10 02:09:04 +00001282// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001283def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1284 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1285def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001286 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001287def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1288 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001289
1290// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001291def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1292 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1293def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1294 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1295def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1296 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001297
Evan Chenga8e29892007-01-19 07:51:42 +00001298// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001299def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1300def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001301
Evan Chengd85ac4d2007-01-27 02:29:45 +00001302// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001303def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1304 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001305
Evan Chenga8e29892007-01-19 07:51:42 +00001306// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001307def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001308 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001309def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001310 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001311
1312def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001313 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001314def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001315 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001316
1317// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001318def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1319 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1320def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1321 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001322
1323// zextload i1 -> zextload i8
Bill Wendlingf4caf692010-12-14 03:36:38 +00001324def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1325 (tLDRBr t_addrmode_rrs1:$addr)>;
1326def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1327 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001328
Evan Chengb60c02e2007-01-26 19:13:16 +00001329// extload -> zextload
Bill Wendlingf4caf692010-12-14 03:36:38 +00001330def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1331def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1332def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1333def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1334def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1335def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001336
Evan Cheng0e87e232009-08-28 00:31:43 +00001337// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001338// ldr{b|h} + sxt{b|h} instead.
Bill Wendling415af342010-12-15 00:58:57 +00001339def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1340 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1341 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001342def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1343 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001344 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling415af342010-12-15 00:58:57 +00001345def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1346 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1347 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001348def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1349 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001350 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001351
Bill Wendlingf4caf692010-12-14 03:36:38 +00001352def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1353 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling415af342010-12-15 00:58:57 +00001354def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1355 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1356def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1357 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1358def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1359 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001360
Evan Chenga8e29892007-01-19 07:51:42 +00001361// Large immediate handling.
1362
1363// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001364def : T1Pat<(i32 thumb_immshifted:$src),
1365 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1366 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001367
Evan Cheng9cb9e672009-06-27 02:26:13 +00001368def : T1Pat<(i32 imm0_255_comp:$src),
1369 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001370
1371// Pseudo instruction that combines ldr from constpool and add pc. This should
1372// be expanded into two instructions late to allow if-conversion and
1373// scheduling.
1374let isReMaterializable = 1 in
1375def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001376 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001377 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1378 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001379 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach53e3fc42011-07-08 17:40:42 +00001380
1381// Pseudo-instruction for merged POP and return.
1382// FIXME: remove when we have a way to marking a MI with these properties.
1383let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1384 hasExtraDefRegAllocReq = 1 in
1385def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +00001386 2, IIC_iPop_Br, [],
Jim Grosbach53e3fc42011-07-08 17:40:42 +00001387 (tPOP pred:$p, reglist:$regs)>;
1388
Jim Grosbachaa8d1b82011-07-08 22:25:23 +00001389// Indirect branch using "mov pc, $Rm"
1390let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach7e61a312011-07-08 22:33:49 +00001391 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001392 2, IIC_Br, [(brind GPR:$Rm)],
Jim Grosbach7e61a312011-07-08 22:33:49 +00001393 (tMOVr PC, GPR:$Rm, pred:$p)>;
Jim Grosbachaa8d1b82011-07-08 22:25:23 +00001394}