blob: 7dcb1d7ec3d538547d3e87297c5ea16cf17d8d54 [file] [log] [blame]
Bill Wendling0480e282010-12-01 02:36:55 +00001//===- ARMInstrThumb.td - Thumb support for ARM ------------*- tablegen -*-===//
Evan Chenga8e29892007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Thumb specific DAG Nodes.
16//
17
18def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
Chris Lattner60e9eac2010-03-19 05:33:51 +000019 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag,
20 SDNPVariadic]>;
Evan Chenga8e29892007-01-19 07:51:42 +000021
Evan Chenga8e29892007-01-19 07:51:42 +000022def imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000023 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000024}]>;
25def imm_comp_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000026 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000027}]>;
28
29
30/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
31def imm0_7 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000032 return (uint32_t)N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000033}]>;
34def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000035 return (uint32_t)-N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000036}], imm_neg_XFORM>;
37
38def imm0_255 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000039 return (uint32_t)N->getZExtValue() < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000040}]>;
41def 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
45def imm8_255 : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000046 return (uint32_t)N->getZExtValue() >= 8 && (uint32_t)N->getZExtValue() < 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}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000130
Bill Wendlingf4caf692010-12-14 03:36:38 +0000131def t_addrmode_rrs2 : Operand<i32>,
132 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
133 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
134 let PrintMethod = "printThumbAddrModeRROperand";
135 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
136 let ParserMatchClass = MemModeRegThumbAsmOperand;
137}
138def t_addrmode_rrs4 : Operand<i32>,
139 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
140 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
141 let PrintMethod = "printThumbAddrModeRROperand";
142 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
143 let ParserMatchClass = MemModeRegThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000144}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000145
Bill Wendlingf4caf692010-12-14 03:36:38 +0000146// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc38f2bc2007-01-23 22:59:13 +0000147//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000148def t_addrmode_is4 : Operand<i32>,
149 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
150 let EncoderMethod = "getAddrModeISOpValue";
151 let PrintMethod = "printThumbAddrModeImm5S4Operand";
152 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
153 let ParserMatchClass = MemModeImmThumbAsmOperand;
154}
155
156// t_addrmode_is2 := reg + imm5 * 2
157//
158def t_addrmode_is2 : Operand<i32>,
159 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
160 let EncoderMethod = "getAddrModeISOpValue";
161 let PrintMethod = "printThumbAddrModeImm5S2Operand";
162 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
163 let ParserMatchClass = MemModeImmThumbAsmOperand;
164}
165
166// t_addrmode_is1 := reg + imm5
167//
168def t_addrmode_is1 : Operand<i32>,
169 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
170 let EncoderMethod = "getAddrModeISOpValue";
171 let PrintMethod = "printThumbAddrModeImm5S1Operand";
172 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
173 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000174}
175
176// t_addrmode_sp := sp + imm8 * 4
177//
178def t_addrmode_sp : Operand<i32>,
179 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbachd967cd02010-12-07 21:50:47 +0000180 let EncoderMethod = "getAddrModeThumbSPOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000181 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000182 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000183 let ParserMatchClass = MemModeImmThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000184}
185
Bill Wendlingb8958b02010-12-08 01:57:09 +0000186// t_addrmode_pc := <label> => pc + imm8 * 4
187//
188def t_addrmode_pc : Operand<i32> {
189 let EncoderMethod = "getAddrModePCOpValue";
Bill Wendlingf4caf692010-12-14 03:36:38 +0000190 let ParserMatchClass = MemModeImmThumbAsmOperand;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000191}
192
Evan Chenga8e29892007-01-19 07:51:42 +0000193//===----------------------------------------------------------------------===//
194// Miscellaneous Instructions.
195//
196
Jim Grosbach4642ad32010-02-22 23:10:38 +0000197// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
198// from removing one half of the matched pairs. That breaks PEI, which assumes
199// these will always be in pairs, and asserts if it finds otherwise. Better way?
200let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000201def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000202 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
203 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
204 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000205
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000206def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000207 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
208 [(ARMcallseq_start imm:$amt)]>,
209 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000210}
Evan Cheng44bec522007-05-15 01:29:07 +0000211
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000212// T1Disassembly - A simple class to make encoding some disassembly patterns
213// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000214class T1Disassembly<bits<2> op1, bits<8> op2>
215 : T1Encoding<0b101111> {
216 let Inst{9-8} = op1;
217 let Inst{7-0} = op2;
218}
219
Johnny Chenbd2c6232010-02-25 03:28:51 +0000220def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
221 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000222 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000223
Johnny Chend86d2692010-02-25 17:51:03 +0000224def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
225 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000226 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000227
228def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
229 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000230 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000231
232def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
233 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000234 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000235
236def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
237 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000238 T1Disassembly<0b11, 0x40>; // A8.6.157
239
240// The i32imm operand $val can be used by a debugger to store more information
241// about the breakpoint.
242def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
243 [/* For disassembly only; pattern left blank */]>,
244 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
245 // A8.6.22
246 bits<8> val;
247 let Inst{7-0} = val;
248}
Johnny Chend86d2692010-02-25 17:51:03 +0000249
250def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
251 [/* For disassembly only; pattern left blank */]>,
252 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000253 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000254 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000255 let Inst{4} = 1;
256 let Inst{3} = 1; // Big-Endian
257 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000258}
259
260def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
261 [/* For disassembly only; pattern left blank */]>,
262 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000263 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000264 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000265 let Inst{4} = 1;
266 let Inst{3} = 0; // Little-Endian
267 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000268}
269
Johnny Chen93042d12010-03-02 18:14:57 +0000270// Change Processor State is a system instruction -- for disassembly only.
271// The singleton $opt operand contains the following information:
Bill Wendling0480e282010-12-01 02:36:55 +0000272//
273// opt{4-0} = mode ==> don't care
274// opt{5} = changemode ==> 0 (false for 16-bit Thumb instr)
275// opt{8-6} = AIF from Inst{2-0}
276// opt{10-9} = 1:imod from Inst{4} with 0b10 as enable and 0b11 as disable
Johnny Chen93042d12010-03-02 18:14:57 +0000277//
278// The opt{4-0} and opt{5} sub-fields are to accommodate 32-bit Thumb and ARM
279// CPS which has more options.
Johnny Chendd0f3cf2010-03-10 18:59:38 +0000280def tCPS : T1I<(outs), (ins cps_opt:$opt), NoItinerary, "cps$opt",
Johnny Chen93042d12010-03-02 18:14:57 +0000281 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000282 T1Misc<0b0110011> {
283 // A8.6.38 & B6.1.1
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000284 let Inst{3} = 0;
285 // FIXME: Finish encoding.
Bill Wendling849f2e32010-11-29 00:18:15 +0000286}
Johnny Chen93042d12010-03-02 18:14:57 +0000287
Evan Cheng35d6c412009-08-04 23:47:55 +0000288// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000289let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000290def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000291 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000292 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000293 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000294 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000295 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000296 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000297}
Evan Chenga8e29892007-01-19 07:51:42 +0000298
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000299// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000300def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000301 "add\t$dst, pc, $rhs", []>,
302 T1Encoding<{1,0,1,0,0,?}> {
303 // A6.2 & A8.6.10
304 bits<3> dst;
305 bits<8> rhs;
306 let Inst{10-8} = dst;
307 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000308}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000309
Bill Wendling0ae28e42010-11-19 22:37:33 +0000310// ADD <Rd>, sp, #<imm8>
311// This is rematerializable, which is particularly useful for taking the
312// address of locals.
313let isReMaterializable = 1 in
314def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
315 "add\t$dst, $sp, $rhs", []>,
316 T1Encoding<{1,0,1,0,1,?}> {
317 // A6.2 & A8.6.8
318 bits<3> dst;
319 bits<8> rhs;
320 let Inst{10-8} = dst;
321 let Inst{7-0} = rhs;
322}
323
324// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000325def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000326 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000327 T1Misc<{0,0,0,0,0,?,?}> {
328 // A6.2.5 & A8.6.8
329 bits<7> rhs;
330 let Inst{6-0} = rhs;
331}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000332
Bill Wendling0ae28e42010-11-19 22:37:33 +0000333// SUB sp, sp, #<imm7>
334// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000335def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000336 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000337 T1Misc<{0,0,0,0,1,?,?}> {
338 // A6.2.5 & A8.6.214
339 bits<7> rhs;
340 let Inst{6-0} = rhs;
341}
Evan Cheng86198642009-08-07 00:34:42 +0000342
Bill Wendling0ae28e42010-11-19 22:37:33 +0000343// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000344def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000345 "add\t$dst, $rhs", []>,
346 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000347 // A8.6.9 Encoding T1
348 bits<4> dst;
349 let Inst{7} = dst{3};
350 let Inst{6-3} = 0b1101;
351 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000352}
Evan Cheng86198642009-08-07 00:34:42 +0000353
Bill Wendling0ae28e42010-11-19 22:37:33 +0000354// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000355def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000356 "add\t$dst, $rhs", []>,
357 T1Special<{0,0,?,?}> {
358 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000359 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000360 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000361 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000362 let Inst{2-0} = 0b101;
363}
Evan Cheng86198642009-08-07 00:34:42 +0000364
Evan Chenga8e29892007-01-19 07:51:42 +0000365//===----------------------------------------------------------------------===//
366// Control Flow Instructions.
367//
368
Jim Grosbachc732adf2009-09-30 01:35:11 +0000369let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Bill Wendling602890d2010-11-19 01:33:10 +0000370 def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr",
371 [(ARMretflag)]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000372 T1Special<{1,1,0,?}> {
373 // A6.2.3 & A8.6.25
Johnny Chend68e1192009-12-15 17:24:14 +0000374 let Inst{6-3} = 0b1110; // Rm = lr
Bill Wendling602890d2010-11-19 01:33:10 +0000375 let Inst{2-0} = 0b000;
Johnny Chend68e1192009-12-15 17:24:14 +0000376 }
Bill Wendling602890d2010-11-19 01:33:10 +0000377
Evan Cheng9d945f72007-02-01 01:49:46 +0000378 // Alternative return instruction used by vararg functions.
Bill Wendling602890d2010-11-19 01:33:10 +0000379 def tBX_RET_vararg : TI<(outs), (ins tGPR:$Rm),
380 IIC_Br, "bx\t$Rm",
381 []>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000382 T1Special<{1,1,0,?}> {
383 // A6.2.3 & A8.6.25
Bill Wendling602890d2010-11-19 01:33:10 +0000384 bits<4> Rm;
385 let Inst{6-3} = Rm;
386 let Inst{2-0} = 0b000;
387 }
Evan Cheng9d945f72007-02-01 01:49:46 +0000388}
Evan Chenga8e29892007-01-19 07:51:42 +0000389
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000390// Indirect branches
391let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Bill Wendling534a5e42010-12-03 01:55:47 +0000392 def tBRIND : TI<(outs), (ins GPR:$Rm),
393 IIC_Br,
394 "mov\tpc, $Rm",
Bill Wendling602890d2010-11-19 01:33:10 +0000395 [(brind GPR:$Rm)]>,
Bill Wendling12280382010-11-19 23:14:32 +0000396 T1Special<{1,0,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000397 // A8.6.97
Bill Wendling602890d2010-11-19 01:33:10 +0000398 bits<4> Rm;
Bill Wendling849f2e32010-11-29 00:18:15 +0000399 let Inst{7} = 1; // <Rd> = Inst{7:2-0} = pc
Bill Wendling602890d2010-11-19 01:33:10 +0000400 let Inst{6-3} = Rm;
Bill Wendling12280382010-11-19 23:14:32 +0000401 let Inst{2-0} = 0b111;
Johnny Chend68e1192009-12-15 17:24:14 +0000402 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000403}
404
Evan Chenga8e29892007-01-19 07:51:42 +0000405// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000406let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
407 hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000408def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000409 IIC_iPop_Br,
Bill Wendling602890d2010-11-19 01:33:10 +0000410 "pop${p}\t$regs", []>,
411 T1Misc<{1,1,0,?,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000412 // A8.6.121
Bill Wendling602890d2010-11-19 01:33:10 +0000413 bits<16> regs;
Bill Wendling849f2e32010-11-29 00:18:15 +0000414 let Inst{8} = regs{15}; // registers = P:'0000000':register_list
Bill Wendling602890d2010-11-19 01:33:10 +0000415 let Inst{7-0} = regs{7-0};
416}
Evan Chenga8e29892007-01-19 07:51:42 +0000417
Bill Wendling0480e282010-12-01 02:36:55 +0000418// All calls clobber the non-callee saved registers. SP is marked as a use to
419// prevent stack-pointer assignments that appear immediately before calls from
420// potentially appearing dead.
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000421let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000422 // On non-Darwin platforms R9 is callee-saved.
Evan Cheng756da122009-07-22 06:46:53 +0000423 Defs = [R0, R1, R2, R3, R12, LR,
424 D0, D1, D2, D3, D4, D5, D6, D7,
425 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000426 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
427 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000428 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000429 def tBL : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000430 (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000431 "bl\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000432 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000433 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000434 bits<21> func;
435 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000436 let Inst{13} = 1;
437 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000438 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000439 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000440
Evan Chengb6207242009-08-01 00:16:10 +0000441 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000442 def tBLXi : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000443 (outs), (ins t_blxtarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000444 "blx\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000445 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000446 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000447 bits<21> func;
448 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000449 let Inst{13} = 1;
450 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000451 let Inst{10-1} = func{10-1};
452 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000453 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000454
Evan Chengb6207242009-08-01 00:16:10 +0000455 // Also used for Thumb2
Jim Grosbach64171712010-02-16 21:07:46 +0000456 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000457 "blx\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000458 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000459 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
460 T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000461
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000462 // ARMv4T
Jim Grosbachd2535452010-12-03 18:37:17 +0000463 // FIXME: Should be a pseudo.
Chris Lattner4d1189f2010-11-01 00:46:16 +0000464 let isCodeGenOnly = 1 in
Johnny Chend68e1192009-12-15 17:24:14 +0000465 def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?,
Jim Grosbach64171712010-02-16 21:07:46 +0000466 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000467 "mov\tlr, pc\n\tbx\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000468 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000469 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000470}
471
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000472let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000473 // On Darwin R9 is call-clobbered.
474 // R7 is marked as a use to prevent frame-pointer assignments from being
475 // moved above / below calls.
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000476 Defs = [R0, R1, R2, R3, R9, R12, LR,
477 D0, D1, D2, D3, D4, D5, D6, D7,
478 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000479 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
480 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000481 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000482 def tBLr9 : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000483 (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
484 IIC_Br, "bl${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000485 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000486 Requires<[IsThumb, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000487 bits<21> func;
488 let Inst{25-16} = func{20-11};
489 let Inst{13} = 1;
490 let Inst{11} = 1;
491 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000492 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000493
Evan Chengb6207242009-08-01 00:16:10 +0000494 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000495 def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000496 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
Jim Grosbach662a8162010-12-06 23:57:07 +0000497 IIC_Br, "blx${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000498 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000499 Requires<[IsThumb, HasV5T, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000500 bits<21> func;
501 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000502 let Inst{13} = 1;
503 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000504 let Inst{10-1} = func{10-1};
505 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000506 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000507
Evan Chengb6207242009-08-01 00:16:10 +0000508 // Also used for Thumb2
Bill Wendling849f2e32010-11-29 00:18:15 +0000509 def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
510 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000511 [(ARMtcall GPR:$func)]>,
512 Requires<[IsThumb, HasV5T, IsDarwin]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000513 T1Special<{1,1,1,?}> {
514 // A6.2.3 & A8.6.24
515 bits<4> func;
516 let Inst{6-3} = func;
517 let Inst{2-0} = 0b000;
518 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000519
520 // ARMv4T
Chris Lattner4d1189f2010-11-01 00:46:16 +0000521 let isCodeGenOnly = 1 in
Jim Grosbachd2535452010-12-03 18:37:17 +0000522 // FIXME: Should be a pseudo.
Johnny Chend68e1192009-12-15 17:24:14 +0000523 def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?,
Jim Grosbach64171712010-02-16 21:07:46 +0000524 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000525 "mov\tlr, pc\n\tbx\t$func",
526 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000527 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000528}
529
Bill Wendling0480e282010-12-01 02:36:55 +0000530let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
531 let isPredicable = 1 in
Jim Grosbache2467172010-12-10 18:21:33 +0000532 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
Bill Wendling0480e282010-12-01 02:36:55 +0000533 "b\t$target", [(br bb:$target)]>,
Jim Grosbache2467172010-12-10 18:21:33 +0000534 T1Encoding<{1,1,1,0,0,?}> {
535 bits<11> target;
536 let Inst{10-0} = target;
537 }
Evan Chenga8e29892007-01-19 07:51:42 +0000538
Evan Cheng225dfe92007-01-30 01:13:37 +0000539 // Far jump
Jim Grosbache2467172010-12-10 18:21:33 +0000540 // FIXME: Encoding. This should probably be a pseudo for tBL
Evan Cheng53c67c02009-08-07 05:45:07 +0000541 let Defs = [LR] in
Jim Grosbach64171712010-02-16 21:07:46 +0000542 def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
Jim Grosbach78890f42010-10-01 23:21:38 +0000543 "bl\t$target",[]>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000544
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000545 def tBR_JTr : tPseudoInst<(outs),
546 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
547 Size2Bytes, IIC_Br,
548 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
549 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000550 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000551}
552
Evan Chengc85e8322007-07-05 07:13:32 +0000553// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000554// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000555let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000556 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000557 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000558 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Jim Grosbachceab5012010-12-04 00:20:40 +0000559 T1Encoding<{1,1,0,1,?,?}> {
560 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000561 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000562 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000563 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000564}
Evan Chenga8e29892007-01-19 07:51:42 +0000565
Evan Chengde17fb62009-10-31 23:46:45 +0000566// Compare and branch on zero / non-zero
567let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000568 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000569 "cbz\t$Rn, $target", []>,
570 T1Misc<{0,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
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000579 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000580 "cbnz\t$cmp, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000581 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000582 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000583 bits<6> target;
584 bits<3> Rn;
585 let Inst{9} = target{5};
586 let Inst{7-3} = target{4-0};
587 let Inst{2-0} = Rn;
588 }
Evan Chengde17fb62009-10-31 23:46:45 +0000589}
590
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000591// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
592// A8.6.16 B: Encoding T1
593// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000594let isCall = 1, Uses = [SP] in
Bill Wendling6179c312010-11-20 00:53:35 +0000595def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
596 "svc", "\t$imm", []>, Encoding16 {
597 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000598 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000599 let Inst{11-8} = 0b1111;
600 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000601}
602
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000603// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000604let isBarrier = 1, isTerminator = 1 in
Anton Korobeynikov418d1d92010-05-15 17:19:20 +0000605def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000606 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000607 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000608}
609
Evan Chenga8e29892007-01-19 07:51:42 +0000610//===----------------------------------------------------------------------===//
611// Load Store Instructions.
612//
613
Bill Wendlingb6faf652010-12-14 22:10:49 +0000614// Loads: reg/reg and reg/imm5
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000615let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb6faf652010-12-14 22:10:49 +0000616multiclass thumb_ld_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> {
621 def r :
622 T1pILdStEncode<reg_opc,
623 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
624 am, itin_r, asm, "\t$Rt, $addr",
625 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
626 def i :
627 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
628 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
629 am, itin_i, asm, "\t$Rt, $addr",
630 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
631}
632// Stores: reg/reg and reg/imm5
633multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
634 Operand AddrMode_r, Operand AddrMode_i,
635 AddrMode am, InstrItinClass itin_r,
636 InstrItinClass itin_i, string asm,
637 PatFrag opnode> {
638 def r :
639 T1pILdStEncode<reg_opc,
640 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
641 am, itin_r, asm, "\t$Rt, $addr",
642 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
643 def i :
644 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
645 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
646 am, itin_i, asm, "\t$Rt, $addr",
647 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
648}
Bill Wendling6179c312010-11-20 00:53:35 +0000649
Bill Wendlingb6faf652010-12-14 22:10:49 +0000650// A8.6.57 & A8.6.60
651defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
652 t_addrmode_is4, AddrModeT1_4,
653 IIC_iLoad_r, IIC_iLoad_i, "ldr",
654 UnOpFrag<(load node:$Src)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000655
Bill Wendlingb6faf652010-12-14 22:10:49 +0000656// A8.6.64 & A8.6.61
657defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
658 t_addrmode_is1, AddrModeT1_1,
659 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
660 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000661
Bill Wendlingb6faf652010-12-14 22:10:49 +0000662// A8.6.76 & A8.6.73
663defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
664 t_addrmode_is2, AddrModeT1_2,
665 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
666 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000667
Evan Cheng2f297df2009-07-11 07:08:13 +0000668let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000669def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000670 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
671 AddrModeT1_1, IIC_iLoad_bh_r,
672 "ldrsb", "\t$dst, $addr",
673 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000674
Evan Cheng2f297df2009-07-11 07:08:13 +0000675let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000676def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000677 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
678 AddrModeT1_2, IIC_iLoad_bh_r,
679 "ldrsh", "\t$dst, $addr",
680 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000681
Dan Gohman15511cf2008-12-03 18:15:48 +0000682let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000683def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
684 "ldr", "\t$Rt, $addr",
685 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
686 T1LdStSP<{1,?,?}> {
687 bits<3> Rt;
688 bits<8> addr;
689 let Inst{10-8} = Rt;
690 let Inst{7-0} = addr;
691}
Evan Cheng012f2d92007-01-24 08:53:17 +0000692
Evan Cheng8e59ea92007-02-07 00:06:56 +0000693// Special instruction for restore. It cannot clobber condition register
694// when it's expanded by eliminateCallFramePseudoInstr().
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000695let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000696// FIXME: Pseudo for tLDRspi
Evan Cheng0e55fd62010-09-30 01:08:25 +0000697def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000698 "ldr", "\t$dst, $addr", []>,
699 T1LdStSP<{1,?,?}>;
Evan Cheng8e59ea92007-02-07 00:06:56 +0000700
Evan Cheng012f2d92007-01-24 08:53:17 +0000701// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000702// FIXME: Use ldr.n to work around a Darwin assembler bug.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000703let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000704def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000705 "ldr", ".n\t$Rt, $addr",
706 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
707 T1Encoding<{0,1,0,0,1,?}> {
708 // A6.2 & A8.6.59
709 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000710 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000711 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000712 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000713}
Evan Chengfa775d02007-03-19 07:20:03 +0000714
715// Special LDR for loads from non-pc-relative constpools.
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000716let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
717 isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000718def tLDRcp : T1pIs<(outs tGPR:$Rt), (ins i32imm:$addr), IIC_iLoad_i,
719 "ldr", "\t$Rt, $addr", []>,
720 T1LdStSP<{1,?,?}> {
721 // A6.2 & A8.6.57 T2
722 bits<3> Rt;
723 bits<8> addr;
724 let Inst{10-8} = Rt;
725 let Inst{7-0} = addr;
726}
Evan Chenga8e29892007-01-19 07:51:42 +0000727
Bill Wendlingb6faf652010-12-14 22:10:49 +0000728// A8.6.194 & A8.6.192
729defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
730 t_addrmode_is4, AddrModeT1_4,
731 IIC_iStore_r, IIC_iStore_i, "str",
732 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000733
Bill Wendlingb6faf652010-12-14 22:10:49 +0000734// A8.6.197 & A8.6.195
735defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
736 t_addrmode_is1, AddrModeT1_1,
737 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
738 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000739
Bill Wendlingb6faf652010-12-14 22:10:49 +0000740// A8.6.207 & A8.6.205
741defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
742 t_addrmode_is2, AddrModeT1_2,
743 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
744 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000745
Evan Chenga8e29892007-01-19 07:51:42 +0000746
Jim Grosbachd967cd02010-12-07 21:50:47 +0000747def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendlingf4caf692010-12-14 03:36:38 +0000748 "str", "\t$Rt, $addr",
749 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000750 T1LdStSP<{0,?,?}> {
751 bits<3> Rt;
752 bits<8> addr;
753 let Inst{10-8} = Rt;
754 let Inst{7-0} = addr;
755}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000756
Bill Wendling3f8c1102010-11-30 23:54:45 +0000757let mayStore = 1, neverHasSideEffects = 1 in
758// Special instruction for spill. It cannot clobber condition register when it's
759// expanded by eliminateCallFramePseudoInstr().
Jim Grosbachd967cd02010-12-07 21:50:47 +0000760// FIXME: Pseudo for tSTRspi
Evan Cheng0e55fd62010-09-30 01:08:25 +0000761def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000762 "str", "\t$src, $addr", []>,
763 T1LdStSP<{0,?,?}>;
Evan Chenga8e29892007-01-19 07:51:42 +0000764
765//===----------------------------------------------------------------------===//
766// Load / store multiple Instructions.
767//
768
Bill Wendling6c470b82010-11-13 09:09:38 +0000769multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
770 InstrItinClass itin_upd, bits<6> T1Enc,
771 bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000772 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000773 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000774 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000775 T1Encoding<T1Enc> {
776 bits<3> Rn;
777 bits<8> regs;
778 let Inst{10-8} = Rn;
779 let Inst{7-0} = regs;
780 }
Bill Wendling73fe34a2010-11-16 01:16:36 +0000781 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +0000782 T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000783 itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000784 T1Encoding<T1Enc> {
785 bits<3> Rn;
786 bits<8> regs;
787 let Inst{10-8} = Rn;
788 let Inst{7-0} = regs;
789 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000790}
791
Bill Wendling73fe34a2010-11-16 01:16:36 +0000792// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000793let neverHasSideEffects = 1 in {
794
795let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
796defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
797 {1,1,0,0,1,?}, 1>;
798
799let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
800defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
801 {1,1,0,0,0,?}, 0>;
802
803} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000804
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000805let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000806def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000807 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000808 "pop${p}\t$regs", []>,
809 T1Misc<{1,1,0,?,?,?,?}> {
810 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000811 let Inst{8} = regs{15};
812 let Inst{7-0} = regs{7-0};
813}
Evan Cheng4b322e52009-08-11 21:11:32 +0000814
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000815let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000816def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000817 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000818 "push${p}\t$regs", []>,
819 T1Misc<{0,1,0,?,?,?,?}> {
820 bits<16> regs;
821 let Inst{8} = regs{14};
822 let Inst{7-0} = regs{7-0};
823}
Evan Chenga8e29892007-01-19 07:51:42 +0000824
825//===----------------------------------------------------------------------===//
826// Arithmetic Instructions.
827//
828
Bill Wendling1d045ee2010-12-01 02:28:08 +0000829// Helper classes for encoding T1pI patterns:
830class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
831 string opc, string asm, list<dag> pattern>
832 : T1pI<oops, iops, itin, opc, asm, pattern>,
833 T1DataProcessing<opA> {
834 bits<3> Rm;
835 bits<3> Rn;
836 let Inst{5-3} = Rm;
837 let Inst{2-0} = Rn;
838}
839class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
840 string opc, string asm, list<dag> pattern>
841 : T1pI<oops, iops, itin, opc, asm, pattern>,
842 T1Misc<opA> {
843 bits<3> Rm;
844 bits<3> Rd;
845 let Inst{5-3} = Rm;
846 let Inst{2-0} = Rd;
847}
848
Bill Wendling76f4e102010-12-01 01:20:15 +0000849// Helper classes for encoding T1sI patterns:
850class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
851 string opc, string asm, list<dag> pattern>
852 : T1sI<oops, iops, itin, opc, asm, pattern>,
853 T1DataProcessing<opA> {
854 bits<3> Rd;
855 bits<3> Rn;
856 let Inst{5-3} = Rn;
857 let Inst{2-0} = Rd;
858}
859class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
860 string opc, string asm, list<dag> pattern>
861 : T1sI<oops, iops, itin, opc, asm, pattern>,
862 T1General<opA> {
863 bits<3> Rm;
864 bits<3> Rn;
865 bits<3> Rd;
866 let Inst{8-6} = Rm;
867 let Inst{5-3} = Rn;
868 let Inst{2-0} = Rd;
869}
870class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
871 string opc, string asm, list<dag> pattern>
872 : T1sI<oops, iops, itin, opc, asm, pattern>,
873 T1General<opA> {
874 bits<3> Rd;
875 bits<3> Rm;
876 let Inst{5-3} = Rm;
877 let Inst{2-0} = Rd;
878}
879
880// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000881class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
882 string opc, string asm, list<dag> pattern>
883 : T1sIt<oops, iops, itin, opc, asm, pattern>,
884 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000885 bits<3> Rdn;
886 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000887 let Inst{5-3} = Rm;
888 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000889}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000890class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
891 string opc, string asm, list<dag> pattern>
892 : T1sIt<oops, iops, itin, opc, asm, pattern>,
893 T1General<opA> {
894 bits<3> Rdn;
895 bits<8> imm8;
896 let Inst{10-8} = Rdn;
897 let Inst{7-0} = imm8;
898}
899
900// Add with carry register
901let isCommutable = 1, Uses = [CPSR] in
902def tADC : // A8.6.2
903 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
904 "adc", "\t$Rdn, $Rm",
905 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000906
David Goodwinc9ee1182009-06-25 22:49:55 +0000907// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000908def tADDi3 : // A8.6.4 T1
909 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3), IIC_iALUi,
910 "add", "\t$Rd, $Rm, $imm3",
911 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000912 bits<3> imm3;
913 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000914}
Evan Chenga8e29892007-01-19 07:51:42 +0000915
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000916def tADDi8 : // A8.6.4 T2
917 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
918 IIC_iALUi,
919 "add", "\t$Rdn, $imm8",
920 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000921
David Goodwinc9ee1182009-06-25 22:49:55 +0000922// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000923let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000924def tADDrr : // A8.6.6 T1
925 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
926 IIC_iALUr,
927 "add", "\t$Rd, $Rn, $Rm",
928 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000929
Evan Chengcd799b92009-06-12 20:46:18 +0000930let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000931def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
932 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000933 T1Special<{0,0,?,?}> {
934 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000935 bits<4> Rdn;
936 bits<4> Rm;
937 let Inst{7} = Rdn{3};
938 let Inst{6-3} = Rm;
939 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000940}
Evan Chenga8e29892007-01-19 07:51:42 +0000941
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000942// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000943let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000944def tAND : // A8.6.12
945 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
946 IIC_iBITr,
947 "and", "\t$Rdn, $Rm",
948 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000949
David Goodwinc9ee1182009-06-25 22:49:55 +0000950// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000951def tASRri : // A8.6.14
952 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
953 IIC_iMOVsi,
954 "asr", "\t$Rd, $Rm, $imm5",
955 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000956 bits<5> imm5;
957 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000958}
Evan Chenga8e29892007-01-19 07:51:42 +0000959
David Goodwinc9ee1182009-06-25 22:49:55 +0000960// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000961def tASRrr : // A8.6.15
962 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
963 IIC_iMOVsr,
964 "asr", "\t$Rdn, $Rm",
965 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000966
David Goodwinc9ee1182009-06-25 22:49:55 +0000967// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000968def tBIC : // A8.6.20
969 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
970 IIC_iBITr,
971 "bic", "\t$Rdn, $Rm",
972 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000973
David Goodwinc9ee1182009-06-25 22:49:55 +0000974// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000975let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000976//FIXME: Disable CMN, as CCodes are backwards from compare expectations
977// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000978//def tCMN : // A8.6.33
979// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
980// IIC_iCMPr,
981// "cmn", "\t$lhs, $rhs",
982// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000983
984def tCMNz : // A8.6.33
985 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
986 IIC_iCMPr,
987 "cmn", "\t$Rn, $Rm",
988 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
989
990} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000991
David Goodwinc9ee1182009-06-25 22:49:55 +0000992// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000993let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000994def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
995 "cmp", "\t$Rn, $imm8",
996 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
997 T1General<{1,0,1,?,?}> {
998 // A8.6.35
999 bits<3> Rn;
1000 bits<8> imm8;
1001 let Inst{10-8} = Rn;
1002 let Inst{7-0} = imm8;
1003}
1004
David Goodwinc9ee1182009-06-25 22:49:55 +00001005// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +00001006def tCMPr : // A8.6.36 T1
1007 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1008 IIC_iCMPr,
1009 "cmp", "\t$Rn, $Rm",
1010 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
1011
Bill Wendling849f2e32010-11-29 00:18:15 +00001012def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1013 "cmp", "\t$Rn, $Rm", []>,
1014 T1Special<{0,1,?,?}> {
1015 // A8.6.36 T2
1016 bits<4> Rm;
1017 bits<4> Rn;
1018 let Inst{7} = Rn{3};
1019 let Inst{6-3} = Rm;
1020 let Inst{2-0} = Rn{2-0};
1021}
Bill Wendling5cc88a22010-11-20 22:52:33 +00001022} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +00001023
Evan Chenga8e29892007-01-19 07:51:42 +00001024
David Goodwinc9ee1182009-06-25 22:49:55 +00001025// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +00001026let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001027def tEOR : // A8.6.45
1028 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1029 IIC_iBITr,
1030 "eor", "\t$Rdn, $Rm",
1031 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001032
David Goodwinc9ee1182009-06-25 22:49:55 +00001033// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001034def tLSLri : // A8.6.88
1035 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1036 IIC_iMOVsi,
1037 "lsl", "\t$Rd, $Rm, $imm5",
1038 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001039 bits<5> imm5;
1040 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001041}
Evan Chenga8e29892007-01-19 07:51:42 +00001042
David Goodwinc9ee1182009-06-25 22:49:55 +00001043// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001044def tLSLrr : // A8.6.89
1045 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1046 IIC_iMOVsr,
1047 "lsl", "\t$Rdn, $Rm",
1048 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001049
David Goodwinc9ee1182009-06-25 22:49:55 +00001050// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001051def tLSRri : // A8.6.90
1052 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1053 IIC_iMOVsi,
1054 "lsr", "\t$Rd, $Rm, $imm5",
1055 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001056 bits<5> imm5;
1057 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001058}
Evan Chenga8e29892007-01-19 07:51:42 +00001059
David Goodwinc9ee1182009-06-25 22:49:55 +00001060// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001061def tLSRrr : // A8.6.91
1062 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1063 IIC_iMOVsr,
1064 "lsr", "\t$Rdn, $Rm",
1065 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001066
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001067// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001068let isMoveImm = 1 in
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001069def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins i32imm:$imm8), IIC_iMOVi,
1070 "mov", "\t$Rd, $imm8",
1071 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1072 T1General<{1,0,0,?,?}> {
1073 // A8.6.96
1074 bits<3> Rd;
1075 bits<8> imm8;
1076 let Inst{10-8} = Rd;
1077 let Inst{7-0} = imm8;
1078}
Evan Chenga8e29892007-01-19 07:51:42 +00001079
1080// TODO: A7-73: MOV(2) - mov setting flag.
1081
Evan Chengcd799b92009-06-12 20:46:18 +00001082let neverHasSideEffects = 1 in {
Evan Cheng446c4282009-07-11 06:43:01 +00001083// FIXME: Make this predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001084def tMOVr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1085 "mov\t$Rd, $Rm", []>,
1086 T1Special<0b1000> {
1087 // A8.6.97
1088 bits<4> Rd;
1089 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001090 // Bits {7-6} are encoded by the T1Special value.
1091 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001092 let Inst{2-0} = Rd{2-0};
1093}
Evan Cheng446c4282009-07-11 06:43:01 +00001094let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001095def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1096 "movs\t$Rd, $Rm", []>, Encoding16 {
1097 // A8.6.97
1098 bits<3> Rd;
1099 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001100 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001101 let Inst{5-3} = Rm;
1102 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001103}
Evan Cheng446c4282009-07-11 06:43:01 +00001104
1105// FIXME: Make these predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001106def tMOVgpr2tgpr : T1I<(outs tGPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1107 "mov\t$Rd, $Rm", []>,
1108 T1Special<{1,0,0,?}> {
1109 // A8.6.97
1110 bits<4> Rd;
1111 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001112 // Bit {7} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001113 let Inst{6-3} = Rm;
1114 let Inst{2-0} = Rd{2-0};
1115}
1116def tMOVtgpr2gpr : T1I<(outs GPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1117 "mov\t$Rd, $Rm", []>,
1118 T1Special<{1,0,?,0}> {
1119 // A8.6.97
1120 bits<4> Rd;
1121 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001122 // Bit {6} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001123 let Inst{7} = Rd{3};
Bill Wendling278b6e82010-12-03 02:02:58 +00001124 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001125 let Inst{2-0} = Rd{2-0};
1126}
1127def tMOVgpr2gpr : T1I<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1128 "mov\t$Rd, $Rm", []>,
1129 T1Special<{1,0,?,?}> {
1130 // A8.6.97
1131 bits<4> Rd;
1132 bits<4> Rm;
1133 let Inst{7} = Rd{3};
1134 let Inst{6-3} = Rm;
1135 let Inst{2-0} = Rd{2-0};
1136}
Evan Chengcd799b92009-06-12 20:46:18 +00001137} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001138
Bill Wendling0480e282010-12-01 02:36:55 +00001139// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001140let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001141def tMUL : // A8.6.105 T1
1142 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1143 IIC_iMUL32,
1144 "mul", "\t$Rdn, $Rm, $Rdn",
1145 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001146
Bill Wendling76f4e102010-12-01 01:20:15 +00001147// Move inverse register
1148def tMVN : // A8.6.107
1149 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1150 "mvn", "\t$Rd, $Rn",
1151 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001152
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001153// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001154let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001155def tORR : // A8.6.114
1156 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1157 IIC_iBITr,
1158 "orr", "\t$Rdn, $Rm",
1159 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001160
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001161// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001162def tREV : // A8.6.134
1163 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1164 IIC_iUNAr,
1165 "rev", "\t$Rd, $Rm",
1166 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1167 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001168
Bill Wendling1d045ee2010-12-01 02:28:08 +00001169def tREV16 : // A8.6.135
1170 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1171 IIC_iUNAr,
1172 "rev16", "\t$Rd, $Rm",
Bill Wendlingd19ac0c2010-11-29 00:42:50 +00001173 [(set tGPR:$Rd,
1174 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF),
1175 (or (and (shl tGPR:$Rm, (i32 8)), 0xFF00),
1176 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF0000),
1177 (and (shl tGPR:$Rm, (i32 8)), 0xFF000000)))))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001178 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001179
Bill Wendling1d045ee2010-12-01 02:28:08 +00001180def tREVSH : // A8.6.136
1181 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1182 IIC_iUNAr,
1183 "revsh", "\t$Rd, $Rm",
1184 [(set tGPR:$Rd,
1185 (sext_inreg
1186 (or (srl (and tGPR:$Rm, 0xFF00), (i32 8)),
1187 (shl tGPR:$Rm, (i32 8))), i16))]>,
1188 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001189
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001190// Rotate right register
1191def tROR : // A8.6.139
1192 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1193 IIC_iMOVsr,
1194 "ror", "\t$Rdn, $Rm",
1195 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001196
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001197// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001198def tRSB : // A8.6.141
1199 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1200 IIC_iALUi,
1201 "rsb", "\t$Rd, $Rn, #0",
1202 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001203
David Goodwinc9ee1182009-06-25 22:49:55 +00001204// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001205let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001206def tSBC : // A8.6.151
1207 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1208 IIC_iALUr,
1209 "sbc", "\t$Rdn, $Rm",
1210 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001211
David Goodwinc9ee1182009-06-25 22:49:55 +00001212// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001213def tSUBi3 : // A8.6.210 T1
1214 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1215 IIC_iALUi,
1216 "sub", "\t$Rd, $Rm, $imm3",
1217 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001218 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001219 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001220}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001221
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001222def tSUBi8 : // A8.6.210 T2
1223 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1224 IIC_iALUi,
1225 "sub", "\t$Rdn, $imm8",
1226 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001227
Bill Wendling76f4e102010-12-01 01:20:15 +00001228// Subtract register
1229def tSUBrr : // A8.6.212
1230 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1231 IIC_iALUr,
1232 "sub", "\t$Rd, $Rn, $Rm",
1233 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001234
1235// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001236
Bill Wendling76f4e102010-12-01 01:20:15 +00001237// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001238def tSXTB : // A8.6.222
1239 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1240 IIC_iUNAr,
1241 "sxtb", "\t$Rd, $Rm",
1242 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1243 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001244
Bill Wendling1d045ee2010-12-01 02:28:08 +00001245// Sign-extend short
1246def tSXTH : // A8.6.224
1247 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1248 IIC_iUNAr,
1249 "sxth", "\t$Rd, $Rm",
1250 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1251 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001252
Bill Wendling1d045ee2010-12-01 02:28:08 +00001253// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001254let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001255def tTST : // A8.6.230
1256 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1257 "tst", "\t$Rn, $Rm",
1258 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001259
Bill Wendling1d045ee2010-12-01 02:28:08 +00001260// Zero-extend byte
1261def tUXTB : // A8.6.262
1262 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1263 IIC_iUNAr,
1264 "uxtb", "\t$Rd, $Rm",
1265 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1266 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001267
Bill Wendling1d045ee2010-12-01 02:28:08 +00001268// Zero-extend short
1269def tUXTH : // A8.6.264
1270 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1271 IIC_iUNAr,
1272 "uxth", "\t$Rd, $Rm",
1273 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1274 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001275
Jim Grosbach80dc1162010-02-16 21:23:02 +00001276// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001277// Expanded after instruction selection into a branch sequence.
1278let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001279 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001280 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001281 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001282 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001283
Evan Cheng007ea272009-08-12 05:17:19 +00001284
1285// 16-bit movcc in IT blocks for Thumb2.
Owen Andersonf523e472010-09-23 23:45:25 +00001286let neverHasSideEffects = 1 in {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001287def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1288 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001289 T1Special<{1,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001290 bits<4> Rdn;
1291 bits<4> Rm;
1292 let Inst{7} = Rdn{3};
1293 let Inst{6-3} = Rm;
1294 let Inst{2-0} = Rdn{2-0};
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001295}
Evan Cheng007ea272009-08-12 05:17:19 +00001296
Evan Chengc4af4632010-11-17 20:13:28 +00001297let isMoveImm = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +00001298def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1299 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001300 T1General<{1,0,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001301 bits<3> Rdn;
1302 bits<8> Rm;
1303 let Inst{10-8} = Rdn;
1304 let Inst{7-0} = Rm;
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001305}
1306
Owen Andersonf523e472010-09-23 23:45:25 +00001307} // neverHasSideEffects
Evan Cheng007ea272009-08-12 05:17:19 +00001308
Evan Chenga8e29892007-01-19 07:51:42 +00001309// tLEApcrel - Load a pc-relative address into a register without offending the
1310// assembler.
Jim Grosbachd40963c2010-12-14 22:28:03 +00001311
1312def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1313 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1314 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling67077412010-11-30 00:18:30 +00001315 bits<3> Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001316 bits<8> addr;
Bill Wendling67077412010-11-30 00:18:30 +00001317 let Inst{10-8} = Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001318 let Inst{7-0} = addr;
Bill Wendling67077412010-11-30 00:18:30 +00001319}
Evan Chenga8e29892007-01-19 07:51:42 +00001320
Jim Grosbachd40963c2010-12-14 22:28:03 +00001321let neverHasSideEffects = 1, isReMaterializable = 1 in
1322def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
1323 Size2Bytes, IIC_iALUi, []>;
1324
1325def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1326 (ins i32imm:$label, nohash_imm:$id, pred:$p),
1327 Size2Bytes, IIC_iALUi, []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001328
Evan Chenga8e29892007-01-19 07:51:42 +00001329//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001330// TLS Instructions
1331//
1332
1333// __aeabi_read_tp preserves the registers r1-r3.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001334let isCall = 1, Defs = [R0, LR], Uses = [SP] in
1335def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
1336 "bl\t__aeabi_read_tp",
1337 [(set R0, ARMthread_pointer)]> {
1338 // Encoding is 0xf7fffffe.
1339 let Inst = 0xf7fffffe;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001340}
1341
Bill Wendling0480e282010-12-01 02:36:55 +00001342//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001343// SJLJ Exception handling intrinsics
Bill Wendling0480e282010-12-01 02:36:55 +00001344//
1345
1346// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1347// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1348// from some other function to get here, and we're using the stack frame for the
1349// containing function to save/restore registers, we can't keep anything live in
1350// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1351// tromped upon when we get here from a longjmp(). We force everthing out of
1352// registers except for our own input by listing the relevant registers in
1353// Defs. By doing so, we also cause the prologue/epilogue code to actively
1354// preserve all of the callee-saved resgisters, which is exactly what we want.
1355// $val is a scratch register for our use.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001356let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12 ],
1357 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1358def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1359 AddrModeNone, SizeSpecial, NoItinerary, "","",
1360 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001361
1362// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001363let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001364 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001365def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001366 AddrModeNone, SizeSpecial, IndexModeNone,
1367 Pseudo, NoItinerary, "", "",
1368 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1369 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001370
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001371//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001372// Non-Instruction Patterns
1373//
1374
Jim Grosbach97a884d2010-12-07 20:41:06 +00001375// Comparisons
1376def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1377 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1378def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1379 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1380
Evan Cheng892837a2009-07-10 02:09:04 +00001381// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001382def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1383 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1384def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001385 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001386def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1387 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001388
1389// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001390def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1391 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1392def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1393 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1394def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1395 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001396
Evan Chenga8e29892007-01-19 07:51:42 +00001397// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001398def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1399def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001400
Evan Chengd85ac4d2007-01-27 02:29:45 +00001401// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001402def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1403 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001404
Evan Chenga8e29892007-01-19 07:51:42 +00001405// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001406def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001407 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001408def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001409 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001410
1411def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001412 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001413def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001414 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001415
1416// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001417def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1418 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1419def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1420 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001421
1422// zextload i1 -> zextload i8
Bill Wendlingf4caf692010-12-14 03:36:38 +00001423def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1424 (tLDRBr t_addrmode_rrs1:$addr)>;
1425def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1426 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001427
Evan Chengb60c02e2007-01-26 19:13:16 +00001428// extload -> zextload
Bill Wendlingf4caf692010-12-14 03:36:38 +00001429def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1430def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1431def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1432def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1433def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1434def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001435
Evan Cheng0e87e232009-08-28 00:31:43 +00001436// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001437// ldr{b|h} + sxt{b|h} instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +00001438def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1439 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001440 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001441def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1442 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001443 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001444
Bill Wendlingf4caf692010-12-14 03:36:38 +00001445def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1446 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
1447def : T1Pat<(sextloadi16 t_addrmode_rrs1:$addr),
1448 (tASRri (tLSLri (tLDRHr t_addrmode_rrs1:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001449
Evan Chenga8e29892007-01-19 07:51:42 +00001450// Large immediate handling.
1451
1452// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001453def : T1Pat<(i32 thumb_immshifted:$src),
1454 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1455 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001456
Evan Cheng9cb9e672009-06-27 02:26:13 +00001457def : T1Pat<(i32 imm0_255_comp:$src),
1458 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001459
1460// Pseudo instruction that combines ldr from constpool and add pc. This should
1461// be expanded into two instructions late to allow if-conversion and
1462// scheduling.
1463let isReMaterializable = 1 in
1464def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001465 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001466 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1467 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001468 Requires<[IsThumb, IsThumb1Only]>;