blob: 6c4a8fc40d06c7abe15dc694b670de85238d4e62 [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
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000070// Scaled 4 immediate.
71def t_imm_s4 : Operand<i32> {
72 let PrintMethod = "printThumbS4ImmOperand";
73}
74
Evan Chenga8e29892007-01-19 07:51:42 +000075// Define Thumb specific addressing modes.
76
Jim Grosbach01086452010-12-10 17:13:40 +000077def t_bcctarget : Operand<i32> {
78 let EncoderMethod = "getThumbBCCTargetOpValue";
79}
80
Jim Grosbachcf6220a2010-12-09 19:01:46 +000081def t_cbtarget : Operand<i32> {
Jim Grosbach027d6e82010-12-09 19:04:53 +000082 let EncoderMethod = "getThumbCBTargetOpValue";
Bill Wendlingdff2f712010-12-08 23:01:43 +000083}
84
Jim Grosbach662a8162010-12-06 23:57:07 +000085def t_bltarget : Operand<i32> {
86 let EncoderMethod = "getThumbBLTargetOpValue";
87}
88
Bill Wendling09aa3f02010-12-09 00:39:08 +000089def t_blxtarget : Operand<i32> {
90 let EncoderMethod = "getThumbBLXTargetOpValue";
91}
92
Bill Wendlingef4a68b2010-11-30 07:44:32 +000093def MemModeThumbAsmOperand : AsmOperandClass {
94 let Name = "MemModeThumb";
95 let SuperClasses = [];
96}
97
Evan Chenga8e29892007-01-19 07:51:42 +000098// t_addrmode_rr := reg + reg
99//
100def t_addrmode_rr : Operand<i32>,
101 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
102 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000103 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000104}
105
Evan Chengc38f2bc2007-01-23 22:59:13 +0000106// t_addrmode_s4 := reg + reg
107// reg + imm5 * 4
Evan Chenga8e29892007-01-19 07:51:42 +0000108//
Evan Chengc38f2bc2007-01-23 22:59:13 +0000109def t_addrmode_s4 : Operand<i32>,
110 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
Bill Wendling272df512010-12-09 21:49:07 +0000111 let EncoderMethod = "getAddrModeSOpValue";
Evan Chengc38f2bc2007-01-23 22:59:13 +0000112 let PrintMethod = "printThumbAddrModeS4Operand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000113 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000114 let ParserMatchClass = MemModeThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000115}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000116
117// t_addrmode_s2 := reg + reg
118// reg + imm5 * 2
119//
120def t_addrmode_s2 : Operand<i32>,
121 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
Bill Wendling272df512010-12-09 21:49:07 +0000122 let EncoderMethod = "getAddrModeSOpValue";
Evan Chengc38f2bc2007-01-23 22:59:13 +0000123 let PrintMethod = "printThumbAddrModeS2Operand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000124 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Bill Wendling1fd374e2010-11-30 22:57:21 +0000125 let ParserMatchClass = MemModeThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000126}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000127
128// t_addrmode_s1 := reg + reg
129// reg + imm5
130//
131def t_addrmode_s1 : Operand<i32>,
132 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
Bill Wendling272df512010-12-09 21:49:07 +0000133 let EncoderMethod = "getAddrModeSOpValue";
Evan Chengc38f2bc2007-01-23 22:59:13 +0000134 let PrintMethod = "printThumbAddrModeS1Operand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000135 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Bill Wendling1fd374e2010-11-30 22:57:21 +0000136 let ParserMatchClass = MemModeThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000137}
138
139// t_addrmode_sp := sp + imm8 * 4
140//
141def t_addrmode_sp : Operand<i32>,
142 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbachd967cd02010-12-07 21:50:47 +0000143 let EncoderMethod = "getAddrModeThumbSPOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000144 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000145 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Bill Wendling1fd374e2010-11-30 22:57:21 +0000146 let ParserMatchClass = MemModeThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000147}
148
Bill Wendlingb8958b02010-12-08 01:57:09 +0000149// t_addrmode_pc := <label> => pc + imm8 * 4
150//
151def t_addrmode_pc : Operand<i32> {
152 let EncoderMethod = "getAddrModePCOpValue";
153 let ParserMatchClass = MemModeThumbAsmOperand;
154}
155
Evan Chenga8e29892007-01-19 07:51:42 +0000156//===----------------------------------------------------------------------===//
157// Miscellaneous Instructions.
158//
159
Jim Grosbach4642ad32010-02-22 23:10:38 +0000160// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
161// from removing one half of the matched pairs. That breaks PEI, which assumes
162// these will always be in pairs, and asserts if it finds otherwise. Better way?
163let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000164def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000165 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
166 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
167 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000168
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000169def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000170 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
171 [(ARMcallseq_start imm:$amt)]>,
172 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000173}
Evan Cheng44bec522007-05-15 01:29:07 +0000174
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000175// T1Disassembly - A simple class to make encoding some disassembly patterns
176// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000177class T1Disassembly<bits<2> op1, bits<8> op2>
178 : T1Encoding<0b101111> {
179 let Inst{9-8} = op1;
180 let Inst{7-0} = op2;
181}
182
Johnny Chenbd2c6232010-02-25 03:28:51 +0000183def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
184 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000185 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000186
Johnny Chend86d2692010-02-25 17:51:03 +0000187def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
188 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000189 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000190
191def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
192 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000193 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000194
195def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
196 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000197 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000198
199def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
200 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000201 T1Disassembly<0b11, 0x40>; // A8.6.157
202
203// The i32imm operand $val can be used by a debugger to store more information
204// about the breakpoint.
205def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
206 [/* For disassembly only; pattern left blank */]>,
207 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
208 // A8.6.22
209 bits<8> val;
210 let Inst{7-0} = val;
211}
Johnny Chend86d2692010-02-25 17:51:03 +0000212
213def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
214 [/* For disassembly only; pattern left blank */]>,
215 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000216 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000217 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000218 let Inst{4} = 1;
219 let Inst{3} = 1; // Big-Endian
220 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000221}
222
223def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
224 [/* For disassembly only; pattern left blank */]>,
225 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000226 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000227 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000228 let Inst{4} = 1;
229 let Inst{3} = 0; // Little-Endian
230 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000231}
232
Johnny Chen93042d12010-03-02 18:14:57 +0000233// Change Processor State is a system instruction -- for disassembly only.
234// The singleton $opt operand contains the following information:
Bill Wendling0480e282010-12-01 02:36:55 +0000235//
236// opt{4-0} = mode ==> don't care
237// opt{5} = changemode ==> 0 (false for 16-bit Thumb instr)
238// opt{8-6} = AIF from Inst{2-0}
239// opt{10-9} = 1:imod from Inst{4} with 0b10 as enable and 0b11 as disable
Johnny Chen93042d12010-03-02 18:14:57 +0000240//
241// The opt{4-0} and opt{5} sub-fields are to accommodate 32-bit Thumb and ARM
242// CPS which has more options.
Johnny Chendd0f3cf2010-03-10 18:59:38 +0000243def tCPS : T1I<(outs), (ins cps_opt:$opt), NoItinerary, "cps$opt",
Johnny Chen93042d12010-03-02 18:14:57 +0000244 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000245 T1Misc<0b0110011> {
246 // A8.6.38 & B6.1.1
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000247 let Inst{3} = 0;
248 // FIXME: Finish encoding.
Bill Wendling849f2e32010-11-29 00:18:15 +0000249}
Johnny Chen93042d12010-03-02 18:14:57 +0000250
Evan Cheng35d6c412009-08-04 23:47:55 +0000251// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000252let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000253def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000254 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000255 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000256 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000257 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000258 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000259 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000260}
Evan Chenga8e29892007-01-19 07:51:42 +0000261
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000262// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000263def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000264 "add\t$dst, pc, $rhs", []>,
265 T1Encoding<{1,0,1,0,0,?}> {
266 // A6.2 & A8.6.10
267 bits<3> dst;
268 bits<8> rhs;
269 let Inst{10-8} = dst;
270 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000271}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000272
Bill Wendling0ae28e42010-11-19 22:37:33 +0000273// ADD <Rd>, sp, #<imm8>
274// This is rematerializable, which is particularly useful for taking the
275// address of locals.
276let isReMaterializable = 1 in
277def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
278 "add\t$dst, $sp, $rhs", []>,
279 T1Encoding<{1,0,1,0,1,?}> {
280 // A6.2 & A8.6.8
281 bits<3> dst;
282 bits<8> rhs;
283 let Inst{10-8} = dst;
284 let Inst{7-0} = rhs;
285}
286
287// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000288def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000289 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000290 T1Misc<{0,0,0,0,0,?,?}> {
291 // A6.2.5 & A8.6.8
292 bits<7> rhs;
293 let Inst{6-0} = rhs;
294}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000295
Bill Wendling0ae28e42010-11-19 22:37:33 +0000296// SUB sp, sp, #<imm7>
297// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000298def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000299 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000300 T1Misc<{0,0,0,0,1,?,?}> {
301 // A6.2.5 & A8.6.214
302 bits<7> rhs;
303 let Inst{6-0} = rhs;
304}
Evan Cheng86198642009-08-07 00:34:42 +0000305
Bill Wendling0ae28e42010-11-19 22:37:33 +0000306// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000307def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000308 "add\t$dst, $rhs", []>,
309 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000310 // A8.6.9 Encoding T1
311 bits<4> dst;
312 let Inst{7} = dst{3};
313 let Inst{6-3} = 0b1101;
314 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000315}
Evan Cheng86198642009-08-07 00:34:42 +0000316
Bill Wendling0ae28e42010-11-19 22:37:33 +0000317// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000318def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000319 "add\t$dst, $rhs", []>,
320 T1Special<{0,0,?,?}> {
321 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000322 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000323 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000324 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000325 let Inst{2-0} = 0b101;
326}
Evan Cheng86198642009-08-07 00:34:42 +0000327
Evan Chenga8e29892007-01-19 07:51:42 +0000328//===----------------------------------------------------------------------===//
329// Control Flow Instructions.
330//
331
Jim Grosbachc732adf2009-09-30 01:35:11 +0000332let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Bill Wendling602890d2010-11-19 01:33:10 +0000333 def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr",
334 [(ARMretflag)]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000335 T1Special<{1,1,0,?}> {
336 // A6.2.3 & A8.6.25
Johnny Chend68e1192009-12-15 17:24:14 +0000337 let Inst{6-3} = 0b1110; // Rm = lr
Bill Wendling602890d2010-11-19 01:33:10 +0000338 let Inst{2-0} = 0b000;
Johnny Chend68e1192009-12-15 17:24:14 +0000339 }
Bill Wendling602890d2010-11-19 01:33:10 +0000340
Evan Cheng9d945f72007-02-01 01:49:46 +0000341 // Alternative return instruction used by vararg functions.
Bill Wendling602890d2010-11-19 01:33:10 +0000342 def tBX_RET_vararg : TI<(outs), (ins tGPR:$Rm),
343 IIC_Br, "bx\t$Rm",
344 []>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000345 T1Special<{1,1,0,?}> {
346 // A6.2.3 & A8.6.25
Bill Wendling602890d2010-11-19 01:33:10 +0000347 bits<4> Rm;
348 let Inst{6-3} = Rm;
349 let Inst{2-0} = 0b000;
350 }
Evan Cheng9d945f72007-02-01 01:49:46 +0000351}
Evan Chenga8e29892007-01-19 07:51:42 +0000352
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000353// Indirect branches
354let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Bill Wendling534a5e42010-12-03 01:55:47 +0000355 def tBRIND : TI<(outs), (ins GPR:$Rm),
356 IIC_Br,
357 "mov\tpc, $Rm",
Bill Wendling602890d2010-11-19 01:33:10 +0000358 [(brind GPR:$Rm)]>,
Bill Wendling12280382010-11-19 23:14:32 +0000359 T1Special<{1,0,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000360 // A8.6.97
Bill Wendling602890d2010-11-19 01:33:10 +0000361 bits<4> Rm;
Bill Wendling849f2e32010-11-29 00:18:15 +0000362 let Inst{7} = 1; // <Rd> = Inst{7:2-0} = pc
Bill Wendling602890d2010-11-19 01:33:10 +0000363 let Inst{6-3} = Rm;
Bill Wendling12280382010-11-19 23:14:32 +0000364 let Inst{2-0} = 0b111;
Johnny Chend68e1192009-12-15 17:24:14 +0000365 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000366}
367
Evan Chenga8e29892007-01-19 07:51:42 +0000368// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000369let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
370 hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000371def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000372 IIC_iPop_Br,
Bill Wendling602890d2010-11-19 01:33:10 +0000373 "pop${p}\t$regs", []>,
374 T1Misc<{1,1,0,?,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000375 // A8.6.121
Bill Wendling602890d2010-11-19 01:33:10 +0000376 bits<16> regs;
Bill Wendling849f2e32010-11-29 00:18:15 +0000377 let Inst{8} = regs{15}; // registers = P:'0000000':register_list
Bill Wendling602890d2010-11-19 01:33:10 +0000378 let Inst{7-0} = regs{7-0};
379}
Evan Chenga8e29892007-01-19 07:51:42 +0000380
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.
Evan Cheng756da122009-07-22 06:46:53 +0000386 Defs = [R0, R1, R2, R3, R12, LR,
387 D0, D1, D2, D3, D4, D5, D6, D7,
388 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000389 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
390 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000391 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000392 def tBL : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000393 (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000394 "bl\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000395 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000396 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000397 bits<21> func;
398 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000399 let Inst{13} = 1;
400 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000401 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000402 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000403
Evan Chengb6207242009-08-01 00:16:10 +0000404 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000405 def tBLXi : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000406 (outs), (ins t_blxtarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000407 "blx\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000408 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000409 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000410 bits<21> func;
411 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000412 let Inst{13} = 1;
413 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000414 let Inst{10-1} = func{10-1};
415 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000416 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000417
Evan Chengb6207242009-08-01 00:16:10 +0000418 // Also used for Thumb2
Jim Grosbach64171712010-02-16 21:07:46 +0000419 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000420 "blx\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000421 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000422 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
423 T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000424
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000425 // ARMv4T
Jim Grosbachd2535452010-12-03 18:37:17 +0000426 // FIXME: Should be a pseudo.
Chris Lattner4d1189f2010-11-01 00:46:16 +0000427 let isCodeGenOnly = 1 in
Johnny Chend68e1192009-12-15 17:24:14 +0000428 def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?,
Jim Grosbach64171712010-02-16 21:07:46 +0000429 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000430 "mov\tlr, pc\n\tbx\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000431 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000432 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000433}
434
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000435let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000436 // On Darwin R9 is call-clobbered.
437 // R7 is marked as a use to prevent frame-pointer assignments from being
438 // moved above / below calls.
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000439 Defs = [R0, R1, R2, R3, R9, R12, LR,
440 D0, D1, D2, D3, D4, D5, D6, D7,
441 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000442 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
443 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000444 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000445 def tBLr9 : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000446 (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
447 IIC_Br, "bl${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000448 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000449 Requires<[IsThumb, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000450 bits<21> func;
451 let Inst{25-16} = func{20-11};
452 let Inst{13} = 1;
453 let Inst{11} = 1;
454 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000455 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000456
Evan Chengb6207242009-08-01 00:16:10 +0000457 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000458 def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
Bill Wendling09aa3f02010-12-09 00:39:08 +0000459 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
Jim Grosbach662a8162010-12-06 23:57:07 +0000460 IIC_Br, "blx${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000461 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000462 Requires<[IsThumb, HasV5T, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000463 bits<21> func;
464 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000465 let Inst{13} = 1;
466 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000467 let Inst{10-1} = func{10-1};
468 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000469 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000470
Evan Chengb6207242009-08-01 00:16:10 +0000471 // Also used for Thumb2
Bill Wendling849f2e32010-11-29 00:18:15 +0000472 def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
473 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000474 [(ARMtcall GPR:$func)]>,
475 Requires<[IsThumb, HasV5T, IsDarwin]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000476 T1Special<{1,1,1,?}> {
477 // A6.2.3 & A8.6.24
478 bits<4> func;
479 let Inst{6-3} = func;
480 let Inst{2-0} = 0b000;
481 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000482
483 // ARMv4T
Chris Lattner4d1189f2010-11-01 00:46:16 +0000484 let isCodeGenOnly = 1 in
Jim Grosbachd2535452010-12-03 18:37:17 +0000485 // FIXME: Should be a pseudo.
Johnny Chend68e1192009-12-15 17:24:14 +0000486 def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?,
Jim Grosbach64171712010-02-16 21:07:46 +0000487 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000488 "mov\tlr, pc\n\tbx\t$func",
489 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000490 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000491}
492
Bill Wendling0480e282010-12-01 02:36:55 +0000493let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
494 let isPredicable = 1 in
495 def tB : T1I<(outs), (ins brtarget:$target), IIC_Br,
496 "b\t$target", [(br bb:$target)]>,
497 T1Encoding<{1,1,1,0,0,?}>;
Evan Chenga8e29892007-01-19 07:51:42 +0000498
Evan Cheng225dfe92007-01-30 01:13:37 +0000499 // Far jump
Evan Cheng53c67c02009-08-07 05:45:07 +0000500 let Defs = [LR] in
Jim Grosbach64171712010-02-16 21:07:46 +0000501 def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
Jim Grosbach78890f42010-10-01 23:21:38 +0000502 "bl\t$target",[]>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000503
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000504 def tBR_JTr : tPseudoInst<(outs),
505 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
506 Size2Bytes, IIC_Br,
507 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
508 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000509 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000510}
511
Evan Chengc85e8322007-07-05 07:13:32 +0000512// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000513// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000514let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000515 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000516 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000517 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Jim Grosbachceab5012010-12-04 00:20:40 +0000518 T1Encoding<{1,1,0,1,?,?}> {
519 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000520 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000521 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000522 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000523}
Evan Chenga8e29892007-01-19 07:51:42 +0000524
Evan Chengde17fb62009-10-31 23:46:45 +0000525// Compare and branch on zero / non-zero
526let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000527 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000528 "cbz\t$Rn, $target", []>,
529 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000530 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000531 bits<6> target;
532 bits<3> Rn;
533 let Inst{9} = target{5};
534 let Inst{7-3} = target{4-0};
535 let Inst{2-0} = Rn;
536 }
Evan Chengde17fb62009-10-31 23:46:45 +0000537
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000538 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, t_cbtarget:$target), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000539 "cbnz\t$cmp, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000540 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000541 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000542 bits<6> target;
543 bits<3> Rn;
544 let Inst{9} = target{5};
545 let Inst{7-3} = target{4-0};
546 let Inst{2-0} = Rn;
547 }
Evan Chengde17fb62009-10-31 23:46:45 +0000548}
549
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000550// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
551// A8.6.16 B: Encoding T1
552// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000553let isCall = 1, Uses = [SP] in
Bill Wendling6179c312010-11-20 00:53:35 +0000554def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
555 "svc", "\t$imm", []>, Encoding16 {
556 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000557 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000558 let Inst{11-8} = 0b1111;
559 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000560}
561
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000562// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000563let isBarrier = 1, isTerminator = 1 in
Anton Korobeynikov418d1d92010-05-15 17:19:20 +0000564def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000565 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000566 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000567}
568
Evan Chenga8e29892007-01-19 07:51:42 +0000569//===----------------------------------------------------------------------===//
570// Load Store Instructions.
571//
572
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000573let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000574def tLDR : // A8.6.60
Bill Wendling40062fb2010-12-01 01:38:08 +0000575 T1pILdStEncode<0b100, (outs tGPR:$Rt), (ins t_addrmode_s4:$addr),
576 AddrModeT1_4, IIC_iLoad_r,
577 "ldr", "\t$Rt, $addr",
578 [(set tGPR:$Rt, (load t_addrmode_s4:$addr))]>;
Bill Wendling6179c312010-11-20 00:53:35 +0000579
Bill Wendlingdff2f712010-12-08 23:01:43 +0000580def tLDRi : // A8.6.57
Bill Wendling40062fb2010-12-01 01:38:08 +0000581 T1pILdStEncodeImm<0b0110, 1, (outs tGPR:$Rt), (ins t_addrmode_s4:$addr),
582 AddrModeT1_4, IIC_iLoad_r,
583 "ldr", "\t$Rt, $addr",
584 []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000585
Bill Wendling1fd374e2010-11-30 22:57:21 +0000586def tLDRB : // A8.6.64
Bill Wendling40062fb2010-12-01 01:38:08 +0000587 T1pILdStEncode<0b110, (outs tGPR:$Rt), (ins t_addrmode_s1:$addr),
588 AddrModeT1_1, IIC_iLoad_bh_r,
589 "ldrb", "\t$Rt, $addr",
590 [(set tGPR:$Rt, (zextloadi8 t_addrmode_s1:$addr))]>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000591
592def tLDRBi : // A8.6.61
Bill Wendlingfb62d552010-12-03 23:44:24 +0000593 T1pILdStEncodeImm<0b0111, 1, (outs tGPR:$Rt), (ins t_addrmode_s1:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000594 AddrModeT1_1, IIC_iLoad_bh_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000595 "ldrb", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000596 []>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000597
Bill Wendling1fd374e2010-11-30 22:57:21 +0000598def tLDRH : // A8.6.76
Bill Wendling40062fb2010-12-01 01:38:08 +0000599 T1pILdStEncode<0b101, (outs tGPR:$dst), (ins t_addrmode_s2:$addr),
600 AddrModeT1_2, IIC_iLoad_bh_r,
601 "ldrh", "\t$dst, $addr",
602 [(set tGPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000603
Bill Wendlingdff2f712010-12-08 23:01:43 +0000604def tLDRHi : // A8.6.73
Bill Wendlingfb62d552010-12-03 23:44:24 +0000605 T1pILdStEncodeImm<0b1000, 1, (outs tGPR:$Rt), (ins t_addrmode_s2:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000606 AddrModeT1_2, IIC_iLoad_bh_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000607 "ldrh", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000608 []>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000609
Evan Cheng2f297df2009-07-11 07:08:13 +0000610let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000611def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000612 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
613 AddrModeT1_1, IIC_iLoad_bh_r,
614 "ldrsb", "\t$dst, $addr",
615 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000616
Evan Cheng2f297df2009-07-11 07:08:13 +0000617let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000618def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000619 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
620 AddrModeT1_2, IIC_iLoad_bh_r,
621 "ldrsh", "\t$dst, $addr",
622 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000623
Dan Gohman15511cf2008-12-03 18:15:48 +0000624let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000625def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
626 "ldr", "\t$Rt, $addr",
627 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
628 T1LdStSP<{1,?,?}> {
629 bits<3> Rt;
630 bits<8> addr;
631 let Inst{10-8} = Rt;
632 let Inst{7-0} = addr;
633}
Evan Cheng012f2d92007-01-24 08:53:17 +0000634
Evan Cheng8e59ea92007-02-07 00:06:56 +0000635// Special instruction for restore. It cannot clobber condition register
636// when it's expanded by eliminateCallFramePseudoInstr().
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000637let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000638// FIXME: Pseudo for tLDRspi
Evan Cheng0e55fd62010-09-30 01:08:25 +0000639def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000640 "ldr", "\t$dst, $addr", []>,
641 T1LdStSP<{1,?,?}>;
Evan Cheng8e59ea92007-02-07 00:06:56 +0000642
Evan Cheng012f2d92007-01-24 08:53:17 +0000643// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000644// FIXME: Use ldr.n to work around a Darwin assembler bug.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000645let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000646def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000647 "ldr", ".n\t$Rt, $addr",
648 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
649 T1Encoding<{0,1,0,0,1,?}> {
650 // A6.2 & A8.6.59
651 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000652 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000653 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000654 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000655}
Evan Chengfa775d02007-03-19 07:20:03 +0000656
657// Special LDR for loads from non-pc-relative constpools.
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000658let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
659 isReMaterializable = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000660def tLDRcp : T1pIs<(outs tGPR:$Rt), (ins i32imm:$addr), IIC_iLoad_i,
661 "ldr", "\t$Rt, $addr", []>,
662 T1LdStSP<{1,?,?}> {
663 // A6.2 & A8.6.57 T2
664 bits<3> Rt;
665 bits<8> addr;
666 let Inst{10-8} = Rt;
667 let Inst{7-0} = addr;
668}
Evan Chenga8e29892007-01-19 07:51:42 +0000669
Bill Wendling1fd374e2010-11-30 22:57:21 +0000670def tSTR : // A8.6.194
Bill Wendling40062fb2010-12-01 01:38:08 +0000671 T1pILdStEncode<0b000, (outs), (ins tGPR:$src, t_addrmode_s4:$addr),
672 AddrModeT1_4, IIC_iStore_r,
673 "str", "\t$src, $addr",
674 [(store tGPR:$src, t_addrmode_s4:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000675
Bill Wendling1fd374e2010-11-30 22:57:21 +0000676def tSTRi : // A8.6.192
Bill Wendlingfb62d552010-12-03 23:44:24 +0000677 T1pILdStEncodeImm<0b0110, 0, (outs), (ins tGPR:$Rt, t_addrmode_s4:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000678 AddrModeT1_4, IIC_iStore_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000679 "str", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000680 []>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000681
Bill Wendling1fd374e2010-11-30 22:57:21 +0000682def tSTRB : // A8.6.197
Bill Wendling40062fb2010-12-01 01:38:08 +0000683 T1pILdStEncode<0b010, (outs), (ins tGPR:$src, t_addrmode_s1:$addr),
684 AddrModeT1_1, IIC_iStore_bh_r,
685 "strb", "\t$src, $addr",
686 [(truncstorei8 tGPR:$src, t_addrmode_s1:$addr)]>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000687
688def tSTRBi : // A8.6.195
Bill Wendlingfb62d552010-12-03 23:44:24 +0000689 T1pILdStEncodeImm<0b0111, 0, (outs), (ins tGPR:$Rt, t_addrmode_s1:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000690 AddrModeT1_1, IIC_iStore_bh_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000691 "strb", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000692 []>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000693
694def tSTRH : // A8.6.207
Bill Wendling40062fb2010-12-01 01:38:08 +0000695 T1pILdStEncode<0b001, (outs), (ins tGPR:$src, t_addrmode_s2:$addr),
696 AddrModeT1_2, IIC_iStore_bh_r,
697 "strh", "\t$src, $addr",
698 [(truncstorei16 tGPR:$src, t_addrmode_s2:$addr)]>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000699
700def tSTRHi : // A8.6.205
Bill Wendlingfb62d552010-12-03 23:44:24 +0000701 T1pILdStEncodeImm<0b1000, 0, (outs), (ins tGPR:$Rt, t_addrmode_s2:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000702 AddrModeT1_2, IIC_iStore_bh_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000703 "strh", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000704 []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000705
Jim Grosbachd967cd02010-12-07 21:50:47 +0000706def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
707 "str", "\t$Rt, $addr",
708 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
709 T1LdStSP<{0,?,?}> {
710 bits<3> Rt;
711 bits<8> addr;
712 let Inst{10-8} = Rt;
713 let Inst{7-0} = addr;
714}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000715
Bill Wendling3f8c1102010-11-30 23:54:45 +0000716let mayStore = 1, neverHasSideEffects = 1 in
717// Special instruction for spill. It cannot clobber condition register when it's
718// expanded by eliminateCallFramePseudoInstr().
Jim Grosbachd967cd02010-12-07 21:50:47 +0000719// FIXME: Pseudo for tSTRspi
Evan Cheng0e55fd62010-09-30 01:08:25 +0000720def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000721 "str", "\t$src, $addr", []>,
722 T1LdStSP<{0,?,?}>;
Evan Chenga8e29892007-01-19 07:51:42 +0000723
724//===----------------------------------------------------------------------===//
725// Load / store multiple Instructions.
726//
727
Bill Wendling6c470b82010-11-13 09:09:38 +0000728multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
729 InstrItinClass itin_upd, bits<6> T1Enc,
730 bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000731 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000732 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000733 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000734 T1Encoding<T1Enc> {
735 bits<3> Rn;
736 bits<8> regs;
737 let Inst{10-8} = Rn;
738 let Inst{7-0} = regs;
739 }
Bill Wendling73fe34a2010-11-16 01:16:36 +0000740 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +0000741 T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000742 itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000743 T1Encoding<T1Enc> {
744 bits<3> Rn;
745 bits<8> regs;
746 let Inst{10-8} = Rn;
747 let Inst{7-0} = regs;
748 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000749}
750
Bill Wendling73fe34a2010-11-16 01:16:36 +0000751// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000752let neverHasSideEffects = 1 in {
753
754let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
755defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
756 {1,1,0,0,1,?}, 1>;
757
758let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
759defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
760 {1,1,0,0,0,?}, 0>;
761
762} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000763
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000764let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000765def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000766 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000767 "pop${p}\t$regs", []>,
768 T1Misc<{1,1,0,?,?,?,?}> {
769 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000770 let Inst{8} = regs{15};
771 let Inst{7-0} = regs{7-0};
772}
Evan Cheng4b322e52009-08-11 21:11:32 +0000773
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000774let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000775def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000776 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000777 "push${p}\t$regs", []>,
778 T1Misc<{0,1,0,?,?,?,?}> {
779 bits<16> regs;
780 let Inst{8} = regs{14};
781 let Inst{7-0} = regs{7-0};
782}
Evan Chenga8e29892007-01-19 07:51:42 +0000783
784//===----------------------------------------------------------------------===//
785// Arithmetic Instructions.
786//
787
Bill Wendling1d045ee2010-12-01 02:28:08 +0000788// Helper classes for encoding T1pI patterns:
789class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
790 string opc, string asm, list<dag> pattern>
791 : T1pI<oops, iops, itin, opc, asm, pattern>,
792 T1DataProcessing<opA> {
793 bits<3> Rm;
794 bits<3> Rn;
795 let Inst{5-3} = Rm;
796 let Inst{2-0} = Rn;
797}
798class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
799 string opc, string asm, list<dag> pattern>
800 : T1pI<oops, iops, itin, opc, asm, pattern>,
801 T1Misc<opA> {
802 bits<3> Rm;
803 bits<3> Rd;
804 let Inst{5-3} = Rm;
805 let Inst{2-0} = Rd;
806}
807
Bill Wendling76f4e102010-12-01 01:20:15 +0000808// Helper classes for encoding T1sI patterns:
809class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
810 string opc, string asm, list<dag> pattern>
811 : T1sI<oops, iops, itin, opc, asm, pattern>,
812 T1DataProcessing<opA> {
813 bits<3> Rd;
814 bits<3> Rn;
815 let Inst{5-3} = Rn;
816 let Inst{2-0} = Rd;
817}
818class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
819 string opc, string asm, list<dag> pattern>
820 : T1sI<oops, iops, itin, opc, asm, pattern>,
821 T1General<opA> {
822 bits<3> Rm;
823 bits<3> Rn;
824 bits<3> Rd;
825 let Inst{8-6} = Rm;
826 let Inst{5-3} = Rn;
827 let Inst{2-0} = Rd;
828}
829class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
830 string opc, string asm, list<dag> pattern>
831 : T1sI<oops, iops, itin, opc, asm, pattern>,
832 T1General<opA> {
833 bits<3> Rd;
834 bits<3> Rm;
835 let Inst{5-3} = Rm;
836 let Inst{2-0} = Rd;
837}
838
839// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000840class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
841 string opc, string asm, list<dag> pattern>
842 : T1sIt<oops, iops, itin, opc, asm, pattern>,
843 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000844 bits<3> Rdn;
845 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000846 let Inst{5-3} = Rm;
847 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000848}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000849class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
850 string opc, string asm, list<dag> pattern>
851 : T1sIt<oops, iops, itin, opc, asm, pattern>,
852 T1General<opA> {
853 bits<3> Rdn;
854 bits<8> imm8;
855 let Inst{10-8} = Rdn;
856 let Inst{7-0} = imm8;
857}
858
859// Add with carry register
860let isCommutable = 1, Uses = [CPSR] in
861def tADC : // A8.6.2
862 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
863 "adc", "\t$Rdn, $Rm",
864 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000865
David Goodwinc9ee1182009-06-25 22:49:55 +0000866// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000867def tADDi3 : // A8.6.4 T1
868 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3), IIC_iALUi,
869 "add", "\t$Rd, $Rm, $imm3",
870 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000871 bits<3> imm3;
872 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000873}
Evan Chenga8e29892007-01-19 07:51:42 +0000874
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000875def tADDi8 : // A8.6.4 T2
876 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
877 IIC_iALUi,
878 "add", "\t$Rdn, $imm8",
879 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000880
David Goodwinc9ee1182009-06-25 22:49:55 +0000881// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000882let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000883def tADDrr : // A8.6.6 T1
884 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
885 IIC_iALUr,
886 "add", "\t$Rd, $Rn, $Rm",
887 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000888
Evan Chengcd799b92009-06-12 20:46:18 +0000889let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000890def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
891 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000892 T1Special<{0,0,?,?}> {
893 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000894 bits<4> Rdn;
895 bits<4> Rm;
896 let Inst{7} = Rdn{3};
897 let Inst{6-3} = Rm;
898 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000899}
Evan Chenga8e29892007-01-19 07:51:42 +0000900
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000901// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000902let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000903def tAND : // A8.6.12
904 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
905 IIC_iBITr,
906 "and", "\t$Rdn, $Rm",
907 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000908
David Goodwinc9ee1182009-06-25 22:49:55 +0000909// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000910def tASRri : // A8.6.14
911 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
912 IIC_iMOVsi,
913 "asr", "\t$Rd, $Rm, $imm5",
914 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000915 bits<5> imm5;
916 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000917}
Evan Chenga8e29892007-01-19 07:51:42 +0000918
David Goodwinc9ee1182009-06-25 22:49:55 +0000919// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000920def tASRrr : // A8.6.15
921 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
922 IIC_iMOVsr,
923 "asr", "\t$Rdn, $Rm",
924 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000925
David Goodwinc9ee1182009-06-25 22:49:55 +0000926// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000927def tBIC : // A8.6.20
928 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
929 IIC_iBITr,
930 "bic", "\t$Rdn, $Rm",
931 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000932
David Goodwinc9ee1182009-06-25 22:49:55 +0000933// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000934let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000935//FIXME: Disable CMN, as CCodes are backwards from compare expectations
936// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000937//def tCMN : // A8.6.33
938// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
939// IIC_iCMPr,
940// "cmn", "\t$lhs, $rhs",
941// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000942
943def tCMNz : // A8.6.33
944 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
945 IIC_iCMPr,
946 "cmn", "\t$Rn, $Rm",
947 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
948
949} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000950
David Goodwinc9ee1182009-06-25 22:49:55 +0000951// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000952let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000953def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
954 "cmp", "\t$Rn, $imm8",
955 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
956 T1General<{1,0,1,?,?}> {
957 // A8.6.35
958 bits<3> Rn;
959 bits<8> imm8;
960 let Inst{10-8} = Rn;
961 let Inst{7-0} = imm8;
962}
963
David Goodwinc9ee1182009-06-25 22:49:55 +0000964// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +0000965def tCMPr : // A8.6.36 T1
966 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
967 IIC_iCMPr,
968 "cmp", "\t$Rn, $Rm",
969 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
970
Bill Wendling849f2e32010-11-29 00:18:15 +0000971def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
972 "cmp", "\t$Rn, $Rm", []>,
973 T1Special<{0,1,?,?}> {
974 // A8.6.36 T2
975 bits<4> Rm;
976 bits<4> Rn;
977 let Inst{7} = Rn{3};
978 let Inst{6-3} = Rm;
979 let Inst{2-0} = Rn{2-0};
980}
Bill Wendling5cc88a22010-11-20 22:52:33 +0000981} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000982
Evan Chenga8e29892007-01-19 07:51:42 +0000983
David Goodwinc9ee1182009-06-25 22:49:55 +0000984// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +0000985let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000986def tEOR : // A8.6.45
987 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
988 IIC_iBITr,
989 "eor", "\t$Rdn, $Rm",
990 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000991
David Goodwinc9ee1182009-06-25 22:49:55 +0000992// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000993def tLSLri : // A8.6.88
994 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
995 IIC_iMOVsi,
996 "lsl", "\t$Rd, $Rm, $imm5",
997 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000998 bits<5> imm5;
999 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001000}
Evan Chenga8e29892007-01-19 07:51:42 +00001001
David Goodwinc9ee1182009-06-25 22:49:55 +00001002// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001003def tLSLrr : // A8.6.89
1004 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1005 IIC_iMOVsr,
1006 "lsl", "\t$Rdn, $Rm",
1007 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001008
David Goodwinc9ee1182009-06-25 22:49:55 +00001009// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001010def tLSRri : // A8.6.90
1011 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
1012 IIC_iMOVsi,
1013 "lsr", "\t$Rd, $Rm, $imm5",
1014 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001015 bits<5> imm5;
1016 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001017}
Evan Chenga8e29892007-01-19 07:51:42 +00001018
David Goodwinc9ee1182009-06-25 22:49:55 +00001019// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001020def tLSRrr : // A8.6.91
1021 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1022 IIC_iMOVsr,
1023 "lsr", "\t$Rdn, $Rm",
1024 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001025
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001026// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001027let isMoveImm = 1 in
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001028def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins i32imm:$imm8), IIC_iMOVi,
1029 "mov", "\t$Rd, $imm8",
1030 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1031 T1General<{1,0,0,?,?}> {
1032 // A8.6.96
1033 bits<3> Rd;
1034 bits<8> imm8;
1035 let Inst{10-8} = Rd;
1036 let Inst{7-0} = imm8;
1037}
Evan Chenga8e29892007-01-19 07:51:42 +00001038
1039// TODO: A7-73: MOV(2) - mov setting flag.
1040
Evan Chengcd799b92009-06-12 20:46:18 +00001041let neverHasSideEffects = 1 in {
Evan Cheng446c4282009-07-11 06:43:01 +00001042// FIXME: Make this predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001043def tMOVr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1044 "mov\t$Rd, $Rm", []>,
1045 T1Special<0b1000> {
1046 // A8.6.97
1047 bits<4> Rd;
1048 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001049 // Bits {7-6} are encoded by the T1Special value.
1050 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001051 let Inst{2-0} = Rd{2-0};
1052}
Evan Cheng446c4282009-07-11 06:43:01 +00001053let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001054def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1055 "movs\t$Rd, $Rm", []>, Encoding16 {
1056 // A8.6.97
1057 bits<3> Rd;
1058 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001059 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001060 let Inst{5-3} = Rm;
1061 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001062}
Evan Cheng446c4282009-07-11 06:43:01 +00001063
1064// FIXME: Make these predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001065def tMOVgpr2tgpr : T1I<(outs tGPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1066 "mov\t$Rd, $Rm", []>,
1067 T1Special<{1,0,0,?}> {
1068 // A8.6.97
1069 bits<4> Rd;
1070 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001071 // Bit {7} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001072 let Inst{6-3} = Rm;
1073 let Inst{2-0} = Rd{2-0};
1074}
1075def tMOVtgpr2gpr : T1I<(outs GPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1076 "mov\t$Rd, $Rm", []>,
1077 T1Special<{1,0,?,0}> {
1078 // A8.6.97
1079 bits<4> Rd;
1080 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001081 // Bit {6} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001082 let Inst{7} = Rd{3};
Bill Wendling278b6e82010-12-03 02:02:58 +00001083 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001084 let Inst{2-0} = Rd{2-0};
1085}
1086def tMOVgpr2gpr : T1I<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1087 "mov\t$Rd, $Rm", []>,
1088 T1Special<{1,0,?,?}> {
1089 // A8.6.97
1090 bits<4> Rd;
1091 bits<4> Rm;
1092 let Inst{7} = Rd{3};
1093 let Inst{6-3} = Rm;
1094 let Inst{2-0} = Rd{2-0};
1095}
Evan Chengcd799b92009-06-12 20:46:18 +00001096} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001097
Bill Wendling0480e282010-12-01 02:36:55 +00001098// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001099let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001100def tMUL : // A8.6.105 T1
1101 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1102 IIC_iMUL32,
1103 "mul", "\t$Rdn, $Rm, $Rdn",
1104 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001105
Bill Wendling76f4e102010-12-01 01:20:15 +00001106// Move inverse register
1107def tMVN : // A8.6.107
1108 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1109 "mvn", "\t$Rd, $Rn",
1110 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001111
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001112// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001113let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001114def tORR : // A8.6.114
1115 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1116 IIC_iBITr,
1117 "orr", "\t$Rdn, $Rm",
1118 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001119
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001120// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001121def tREV : // A8.6.134
1122 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1123 IIC_iUNAr,
1124 "rev", "\t$Rd, $Rm",
1125 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1126 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001127
Bill Wendling1d045ee2010-12-01 02:28:08 +00001128def tREV16 : // A8.6.135
1129 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1130 IIC_iUNAr,
1131 "rev16", "\t$Rd, $Rm",
Bill Wendlingd19ac0c2010-11-29 00:42:50 +00001132 [(set tGPR:$Rd,
1133 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF),
1134 (or (and (shl tGPR:$Rm, (i32 8)), 0xFF00),
1135 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF0000),
1136 (and (shl tGPR:$Rm, (i32 8)), 0xFF000000)))))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001137 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001138
Bill Wendling1d045ee2010-12-01 02:28:08 +00001139def tREVSH : // A8.6.136
1140 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1141 IIC_iUNAr,
1142 "revsh", "\t$Rd, $Rm",
1143 [(set tGPR:$Rd,
1144 (sext_inreg
1145 (or (srl (and tGPR:$Rm, 0xFF00), (i32 8)),
1146 (shl tGPR:$Rm, (i32 8))), i16))]>,
1147 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001148
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001149// Rotate right register
1150def tROR : // A8.6.139
1151 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1152 IIC_iMOVsr,
1153 "ror", "\t$Rdn, $Rm",
1154 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001155
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001156// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001157def tRSB : // A8.6.141
1158 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1159 IIC_iALUi,
1160 "rsb", "\t$Rd, $Rn, #0",
1161 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001162
David Goodwinc9ee1182009-06-25 22:49:55 +00001163// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001164let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001165def tSBC : // A8.6.151
1166 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1167 IIC_iALUr,
1168 "sbc", "\t$Rdn, $Rm",
1169 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001170
David Goodwinc9ee1182009-06-25 22:49:55 +00001171// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001172def tSUBi3 : // A8.6.210 T1
1173 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1174 IIC_iALUi,
1175 "sub", "\t$Rd, $Rm, $imm3",
1176 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001177 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001178 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001179}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001180
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001181def tSUBi8 : // A8.6.210 T2
1182 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1183 IIC_iALUi,
1184 "sub", "\t$Rdn, $imm8",
1185 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001186
Bill Wendling76f4e102010-12-01 01:20:15 +00001187// Subtract register
1188def tSUBrr : // A8.6.212
1189 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1190 IIC_iALUr,
1191 "sub", "\t$Rd, $Rn, $Rm",
1192 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001193
1194// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001195
Bill Wendling76f4e102010-12-01 01:20:15 +00001196// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001197def tSXTB : // A8.6.222
1198 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1199 IIC_iUNAr,
1200 "sxtb", "\t$Rd, $Rm",
1201 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1202 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001203
Bill Wendling1d045ee2010-12-01 02:28:08 +00001204// Sign-extend short
1205def tSXTH : // A8.6.224
1206 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1207 IIC_iUNAr,
1208 "sxth", "\t$Rd, $Rm",
1209 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1210 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001211
Bill Wendling1d045ee2010-12-01 02:28:08 +00001212// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001213let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001214def tTST : // A8.6.230
1215 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1216 "tst", "\t$Rn, $Rm",
1217 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001218
Bill Wendling1d045ee2010-12-01 02:28:08 +00001219// Zero-extend byte
1220def tUXTB : // A8.6.262
1221 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1222 IIC_iUNAr,
1223 "uxtb", "\t$Rd, $Rm",
1224 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1225 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001226
Bill Wendling1d045ee2010-12-01 02:28:08 +00001227// Zero-extend short
1228def tUXTH : // A8.6.264
1229 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1230 IIC_iUNAr,
1231 "uxth", "\t$Rd, $Rm",
1232 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1233 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001234
Jim Grosbach80dc1162010-02-16 21:23:02 +00001235// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001236// Expanded after instruction selection into a branch sequence.
1237let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001238 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001239 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001240 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001241 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001242
Evan Cheng007ea272009-08-12 05:17:19 +00001243
1244// 16-bit movcc in IT blocks for Thumb2.
Owen Andersonf523e472010-09-23 23:45:25 +00001245let neverHasSideEffects = 1 in {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001246def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1247 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001248 T1Special<{1,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001249 bits<4> Rdn;
1250 bits<4> Rm;
1251 let Inst{7} = Rdn{3};
1252 let Inst{6-3} = Rm;
1253 let Inst{2-0} = Rdn{2-0};
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001254}
Evan Cheng007ea272009-08-12 05:17:19 +00001255
Evan Chengc4af4632010-11-17 20:13:28 +00001256let isMoveImm = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +00001257def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1258 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001259 T1General<{1,0,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001260 bits<3> Rdn;
1261 bits<8> Rm;
1262 let Inst{10-8} = Rdn;
1263 let Inst{7-0} = Rm;
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001264}
1265
Owen Andersonf523e472010-09-23 23:45:25 +00001266} // neverHasSideEffects
Evan Cheng007ea272009-08-12 05:17:19 +00001267
Evan Chenga8e29892007-01-19 07:51:42 +00001268// tLEApcrel - Load a pc-relative address into a register without offending the
1269// assembler.
Bill Wendling8ca2fd62010-11-30 00:08:20 +00001270let neverHasSideEffects = 1, isReMaterializable = 1 in
Bill Wendling67077412010-11-30 00:18:30 +00001271def tLEApcrel : T1I<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p), IIC_iALUi,
1272 "adr${p}\t$Rd, #$label", []>,
1273 T1Encoding<{1,0,1,0,0,?}> {
1274 // A6.2 & A8.6.10
1275 bits<3> Rd;
1276 let Inst{10-8} = Rd;
1277 // FIXME: Add label encoding/fixup
1278}
Evan Chenga8e29892007-01-19 07:51:42 +00001279
Bill Wendling67077412010-11-30 00:18:30 +00001280def tLEApcrelJT : T1I<(outs tGPR:$Rd),
Bob Wilson4f38b382009-08-21 21:58:55 +00001281 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Bill Wendling67077412010-11-30 00:18:30 +00001282 IIC_iALUi, "adr${p}\t$Rd, #${label}_${id}", []>,
1283 T1Encoding<{1,0,1,0,0,?}> {
1284 // A6.2 & A8.6.10
1285 bits<3> Rd;
1286 let Inst{10-8} = Rd;
1287 // FIXME: Add label encoding/fixup
1288}
Evan Chengd85ac4d2007-01-27 02:29:45 +00001289
Evan Chenga8e29892007-01-19 07:51:42 +00001290//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001291// TLS Instructions
1292//
1293
1294// __aeabi_read_tp preserves the registers r1-r3.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001295let isCall = 1, Defs = [R0, LR], Uses = [SP] in
1296def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
1297 "bl\t__aeabi_read_tp",
1298 [(set R0, ARMthread_pointer)]> {
1299 // Encoding is 0xf7fffffe.
1300 let Inst = 0xf7fffffe;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001301}
1302
Bill Wendling0480e282010-12-01 02:36:55 +00001303//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001304// SJLJ Exception handling intrinsics
Bill Wendling0480e282010-12-01 02:36:55 +00001305//
1306
1307// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1308// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1309// from some other function to get here, and we're using the stack frame for the
1310// containing function to save/restore registers, we can't keep anything live in
1311// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1312// tromped upon when we get here from a longjmp(). We force everthing out of
1313// registers except for our own input by listing the relevant registers in
1314// Defs. By doing so, we also cause the prologue/epilogue code to actively
1315// preserve all of the callee-saved resgisters, which is exactly what we want.
1316// $val is a scratch register for our use.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001317let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12 ],
1318 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1319def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1320 AddrModeNone, SizeSpecial, NoItinerary, "","",
1321 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001322
1323// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001324let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001325 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001326def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001327 AddrModeNone, SizeSpecial, IndexModeNone,
1328 Pseudo, NoItinerary, "", "",
1329 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1330 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001331
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001332//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001333// Non-Instruction Patterns
1334//
1335
Jim Grosbach97a884d2010-12-07 20:41:06 +00001336// Comparisons
1337def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1338 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1339def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1340 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1341
Evan Cheng892837a2009-07-10 02:09:04 +00001342// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001343def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1344 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1345def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001346 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001347def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1348 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001349
1350// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001351def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1352 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1353def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1354 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1355def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1356 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001357
Evan Chenga8e29892007-01-19 07:51:42 +00001358// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001359def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1360def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001361
Evan Chengd85ac4d2007-01-27 02:29:45 +00001362// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001363def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1364 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001365
Evan Chenga8e29892007-01-19 07:51:42 +00001366// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001367def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001368 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001369def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001370 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001371
1372def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001373 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001374def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001375 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001376
1377// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001378def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1379 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1380def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1381 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001382
1383// zextload i1 -> zextload i8
Evan Chengf3c21b82009-06-30 02:15:48 +00001384def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
1385 (tLDRB t_addrmode_s1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001386
Evan Chengb60c02e2007-01-26 19:13:16 +00001387// extload -> zextload
Evan Chengf3c21b82009-06-30 02:15:48 +00001388def : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
1389def : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
1390def : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001391
Evan Cheng0e87e232009-08-28 00:31:43 +00001392// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001393// ldr{b|h} + sxt{b|h} instead.
Evan Cheng3ecadc82009-07-21 18:15:26 +00001394def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
Evan Cheng0e87e232009-08-28 00:31:43 +00001395 (tSXTB (tLDRB t_addrmode_s1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001396 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng3ecadc82009-07-21 18:15:26 +00001397def : T1Pat<(sextloadi16 t_addrmode_s2:$addr),
Evan Cheng0e87e232009-08-28 00:31:43 +00001398 (tSXTH (tLDRH t_addrmode_s2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001399 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001400
Evan Cheng0e87e232009-08-28 00:31:43 +00001401def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
1402 (tASRri (tLSLri (tLDRB t_addrmode_s1:$addr), 24), 24)>;
1403def : T1Pat<(sextloadi16 t_addrmode_s1:$addr),
1404 (tASRri (tLSLri (tLDRH t_addrmode_s1:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001405
Evan Chenga8e29892007-01-19 07:51:42 +00001406// Large immediate handling.
1407
1408// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001409def : T1Pat<(i32 thumb_immshifted:$src),
1410 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1411 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001412
Evan Cheng9cb9e672009-06-27 02:26:13 +00001413def : T1Pat<(i32 imm0_255_comp:$src),
1414 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001415
1416// Pseudo instruction that combines ldr from constpool and add pc. This should
1417// be expanded into two instructions late to allow if-conversion and
1418// scheduling.
1419let isReMaterializable = 1 in
1420def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001421 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001422 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1423 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001424 Requires<[IsThumb, IsThumb1Only]>;