blob: 67f7da64ddf713ba83febb52ad799bc8d758bd8f [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 Grosbach662a8162010-12-06 23:57:07 +000077def t_bltarget : Operand<i32> {
78 let EncoderMethod = "getThumbBLTargetOpValue";
79}
80
Bill Wendlingef4a68b2010-11-30 07:44:32 +000081def MemModeThumbAsmOperand : AsmOperandClass {
82 let Name = "MemModeThumb";
83 let SuperClasses = [];
84}
85
Evan Chenga8e29892007-01-19 07:51:42 +000086// t_addrmode_rr := reg + reg
87//
88def t_addrmode_rr : Operand<i32>,
89 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
90 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +000091 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +000092}
93
Evan Chengc38f2bc2007-01-23 22:59:13 +000094// t_addrmode_s4 := reg + reg
95// reg + imm5 * 4
Evan Chenga8e29892007-01-19 07:51:42 +000096//
Evan Chengc38f2bc2007-01-23 22:59:13 +000097def t_addrmode_s4 : Operand<i32>,
98 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
Jim Grosbach0b951ce2010-12-03 19:31:00 +000099 let EncoderMethod = "getAddrModeS4OpValue";
Evan Chengc38f2bc2007-01-23 22:59:13 +0000100 let PrintMethod = "printThumbAddrModeS4Operand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000101 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000102 let ParserMatchClass = MemModeThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000103}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000104
105// t_addrmode_s2 := reg + reg
106// reg + imm5 * 2
107//
108def t_addrmode_s2 : Operand<i32>,
109 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
Jim Grosbach0b951ce2010-12-03 19:31:00 +0000110 let EncoderMethod = "getAddrModeS2OpValue";
Evan Chengc38f2bc2007-01-23 22:59:13 +0000111 let PrintMethod = "printThumbAddrModeS2Operand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000112 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Bill Wendling1fd374e2010-11-30 22:57:21 +0000113 let ParserMatchClass = MemModeThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000114}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000115
116// t_addrmode_s1 := reg + reg
117// reg + imm5
118//
119def t_addrmode_s1 : Operand<i32>,
120 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
Jim Grosbach0b951ce2010-12-03 19:31:00 +0000121 let EncoderMethod = "getAddrModeS1OpValue";
Evan Chengc38f2bc2007-01-23 22:59:13 +0000122 let PrintMethod = "printThumbAddrModeS1Operand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000123 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Bill Wendling1fd374e2010-11-30 22:57:21 +0000124 let ParserMatchClass = MemModeThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000125}
126
127// t_addrmode_sp := sp + imm8 * 4
128//
129def t_addrmode_sp : Operand<i32>,
130 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
131 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000132 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Bill Wendling1fd374e2010-11-30 22:57:21 +0000133 let ParserMatchClass = MemModeThumbAsmOperand;
Evan Chenga8e29892007-01-19 07:51:42 +0000134}
135
136//===----------------------------------------------------------------------===//
137// Miscellaneous Instructions.
138//
139
Jim Grosbach4642ad32010-02-22 23:10:38 +0000140// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
141// from removing one half of the matched pairs. That breaks PEI, which assumes
142// these will always be in pairs, and asserts if it finds otherwise. Better way?
143let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000144def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000145 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
146 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
147 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000148
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000149def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000150 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
151 [(ARMcallseq_start imm:$amt)]>,
152 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000153}
Evan Cheng44bec522007-05-15 01:29:07 +0000154
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000155// T1Disassembly - A simple class to make encoding some disassembly patterns
156// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000157class T1Disassembly<bits<2> op1, bits<8> op2>
158 : T1Encoding<0b101111> {
159 let Inst{9-8} = op1;
160 let Inst{7-0} = op2;
161}
162
Johnny Chenbd2c6232010-02-25 03:28:51 +0000163def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
164 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000165 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000166
Johnny Chend86d2692010-02-25 17:51:03 +0000167def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
168 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000169 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000170
171def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
172 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000173 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000174
175def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
176 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000177 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000178
179def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
180 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000181 T1Disassembly<0b11, 0x40>; // A8.6.157
182
183// The i32imm operand $val can be used by a debugger to store more information
184// about the breakpoint.
185def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
186 [/* For disassembly only; pattern left blank */]>,
187 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
188 // A8.6.22
189 bits<8> val;
190 let Inst{7-0} = val;
191}
Johnny Chend86d2692010-02-25 17:51:03 +0000192
193def tSETENDBE : T1I<(outs), (ins), NoItinerary, "setend\tbe",
194 [/* For disassembly only; pattern left blank */]>,
195 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000196 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000197 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000198 let Inst{4} = 1;
199 let Inst{3} = 1; // Big-Endian
200 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000201}
202
203def tSETENDLE : T1I<(outs), (ins), NoItinerary, "setend\tle",
204 [/* For disassembly only; pattern left blank */]>,
205 T1Encoding<0b101101> {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000206 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000207 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000208 let Inst{4} = 1;
209 let Inst{3} = 0; // Little-Endian
210 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000211}
212
Johnny Chen93042d12010-03-02 18:14:57 +0000213// Change Processor State is a system instruction -- for disassembly only.
214// The singleton $opt operand contains the following information:
Bill Wendling0480e282010-12-01 02:36:55 +0000215//
216// opt{4-0} = mode ==> don't care
217// opt{5} = changemode ==> 0 (false for 16-bit Thumb instr)
218// opt{8-6} = AIF from Inst{2-0}
219// opt{10-9} = 1:imod from Inst{4} with 0b10 as enable and 0b11 as disable
Johnny Chen93042d12010-03-02 18:14:57 +0000220//
221// The opt{4-0} and opt{5} sub-fields are to accommodate 32-bit Thumb and ARM
222// CPS which has more options.
Johnny Chendd0f3cf2010-03-10 18:59:38 +0000223def tCPS : T1I<(outs), (ins cps_opt:$opt), NoItinerary, "cps$opt",
Johnny Chen93042d12010-03-02 18:14:57 +0000224 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000225 T1Misc<0b0110011> {
226 // A8.6.38 & B6.1.1
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000227 let Inst{3} = 0;
228 // FIXME: Finish encoding.
Bill Wendling849f2e32010-11-29 00:18:15 +0000229}
Johnny Chen93042d12010-03-02 18:14:57 +0000230
Evan Cheng35d6c412009-08-04 23:47:55 +0000231// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000232let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000233def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000234 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000235 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000236 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000237 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000238 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000239 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000240}
Evan Chenga8e29892007-01-19 07:51:42 +0000241
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000242// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000243def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000244 "add\t$dst, pc, $rhs", []>,
245 T1Encoding<{1,0,1,0,0,?}> {
246 // A6.2 & A8.6.10
247 bits<3> dst;
248 bits<8> rhs;
249 let Inst{10-8} = dst;
250 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000251}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000252
Bill Wendling0ae28e42010-11-19 22:37:33 +0000253// ADD <Rd>, sp, #<imm8>
254// This is rematerializable, which is particularly useful for taking the
255// address of locals.
256let isReMaterializable = 1 in
257def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
258 "add\t$dst, $sp, $rhs", []>,
259 T1Encoding<{1,0,1,0,1,?}> {
260 // A6.2 & A8.6.8
261 bits<3> dst;
262 bits<8> rhs;
263 let Inst{10-8} = dst;
264 let Inst{7-0} = rhs;
265}
266
267// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000268def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000269 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000270 T1Misc<{0,0,0,0,0,?,?}> {
271 // A6.2.5 & A8.6.8
272 bits<7> rhs;
273 let Inst{6-0} = rhs;
274}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000275
Bill Wendling0ae28e42010-11-19 22:37:33 +0000276// SUB sp, sp, #<imm7>
277// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000278def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000279 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000280 T1Misc<{0,0,0,0,1,?,?}> {
281 // A6.2.5 & A8.6.214
282 bits<7> rhs;
283 let Inst{6-0} = rhs;
284}
Evan Cheng86198642009-08-07 00:34:42 +0000285
Bill Wendling0ae28e42010-11-19 22:37:33 +0000286// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000287def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000288 "add\t$dst, $rhs", []>,
289 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000290 // A8.6.9 Encoding T1
291 bits<4> dst;
292 let Inst{7} = dst{3};
293 let Inst{6-3} = 0b1101;
294 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000295}
Evan Cheng86198642009-08-07 00:34:42 +0000296
Bill Wendling0ae28e42010-11-19 22:37:33 +0000297// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000298def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000299 "add\t$dst, $rhs", []>,
300 T1Special<{0,0,?,?}> {
301 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000302 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000303 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000304 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000305 let Inst{2-0} = 0b101;
306}
Evan Cheng86198642009-08-07 00:34:42 +0000307
Evan Chenga8e29892007-01-19 07:51:42 +0000308//===----------------------------------------------------------------------===//
309// Control Flow Instructions.
310//
311
Jim Grosbachc732adf2009-09-30 01:35:11 +0000312let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Bill Wendling602890d2010-11-19 01:33:10 +0000313 def tBX_RET : TI<(outs), (ins), IIC_Br, "bx\tlr",
314 [(ARMretflag)]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000315 T1Special<{1,1,0,?}> {
316 // A6.2.3 & A8.6.25
Johnny Chend68e1192009-12-15 17:24:14 +0000317 let Inst{6-3} = 0b1110; // Rm = lr
Bill Wendling602890d2010-11-19 01:33:10 +0000318 let Inst{2-0} = 0b000;
Johnny Chend68e1192009-12-15 17:24:14 +0000319 }
Bill Wendling602890d2010-11-19 01:33:10 +0000320
Evan Cheng9d945f72007-02-01 01:49:46 +0000321 // Alternative return instruction used by vararg functions.
Bill Wendling602890d2010-11-19 01:33:10 +0000322 def tBX_RET_vararg : TI<(outs), (ins tGPR:$Rm),
323 IIC_Br, "bx\t$Rm",
324 []>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000325 T1Special<{1,1,0,?}> {
326 // A6.2.3 & A8.6.25
Bill Wendling602890d2010-11-19 01:33:10 +0000327 bits<4> Rm;
328 let Inst{6-3} = Rm;
329 let Inst{2-0} = 0b000;
330 }
Evan Cheng9d945f72007-02-01 01:49:46 +0000331}
Evan Chenga8e29892007-01-19 07:51:42 +0000332
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000333// Indirect branches
334let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Bill Wendling534a5e42010-12-03 01:55:47 +0000335 def tBRIND : TI<(outs), (ins GPR:$Rm),
336 IIC_Br,
337 "mov\tpc, $Rm",
Bill Wendling602890d2010-11-19 01:33:10 +0000338 [(brind GPR:$Rm)]>,
Bill Wendling12280382010-11-19 23:14:32 +0000339 T1Special<{1,0,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000340 // A8.6.97
Bill Wendling602890d2010-11-19 01:33:10 +0000341 bits<4> Rm;
Bill Wendling849f2e32010-11-29 00:18:15 +0000342 let Inst{7} = 1; // <Rd> = Inst{7:2-0} = pc
Bill Wendling602890d2010-11-19 01:33:10 +0000343 let Inst{6-3} = Rm;
Bill Wendling12280382010-11-19 23:14:32 +0000344 let Inst{2-0} = 0b111;
Johnny Chend68e1192009-12-15 17:24:14 +0000345 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000346}
347
Evan Chenga8e29892007-01-19 07:51:42 +0000348// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000349let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
350 hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000351def tPOP_RET : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000352 IIC_iPop_Br,
Bill Wendling602890d2010-11-19 01:33:10 +0000353 "pop${p}\t$regs", []>,
354 T1Misc<{1,1,0,?,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000355 // A8.6.121
Bill Wendling602890d2010-11-19 01:33:10 +0000356 bits<16> regs;
Bill Wendling849f2e32010-11-29 00:18:15 +0000357 let Inst{8} = regs{15}; // registers = P:'0000000':register_list
Bill Wendling602890d2010-11-19 01:33:10 +0000358 let Inst{7-0} = regs{7-0};
359}
Evan Chenga8e29892007-01-19 07:51:42 +0000360
Bill Wendling0480e282010-12-01 02:36:55 +0000361// All calls clobber the non-callee saved registers. SP is marked as a use to
362// prevent stack-pointer assignments that appear immediately before calls from
363// potentially appearing dead.
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000364let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000365 // On non-Darwin platforms R9 is callee-saved.
Evan Cheng756da122009-07-22 06:46:53 +0000366 Defs = [R0, R1, R2, R3, R12, LR,
367 D0, D1, D2, D3, D4, D5, D6, D7,
368 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000369 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
370 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000371 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000372 def tBL : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000373 (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000374 "bl\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000375 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000376 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000377 bits<21> func;
378 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000379 let Inst{13} = 1;
380 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000381 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000382 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000383
Evan Chengb6207242009-08-01 00:16:10 +0000384 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000385 def tBLXi : TIx2<0b11110, 0b11, 0,
Jim Grosbach662a8162010-12-06 23:57:07 +0000386 (outs), (ins t_bltarget:$func, variable_ops), IIC_Br,
Jim Grosbach1d6111c2010-10-06 21:36:43 +0000387 "blx\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000388 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000389 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000390 bits<21> func;
391 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000392 let Inst{13} = 1;
393 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000394 let Inst{10-1} = func{10-1};
395 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000396 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000397
Evan Chengb6207242009-08-01 00:16:10 +0000398 // Also used for Thumb2
Jim Grosbach64171712010-02-16 21:07:46 +0000399 def tBLXr : TI<(outs), (ins GPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000400 "blx\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000401 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000402 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
403 T1Special<{1,1,1,?}>; // A6.2.3 & A8.6.24;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000404
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000405 // ARMv4T
Jim Grosbachd2535452010-12-03 18:37:17 +0000406 // FIXME: Should be a pseudo.
Chris Lattner4d1189f2010-11-01 00:46:16 +0000407 let isCodeGenOnly = 1 in
Johnny Chend68e1192009-12-15 17:24:14 +0000408 def tBX : TIx2<{?,?,?,?,?}, {?,?}, ?,
Jim Grosbach64171712010-02-16 21:07:46 +0000409 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +0000410 "mov\tlr, pc\n\tbx\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000411 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000412 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000413}
414
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000415let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000416 // On Darwin R9 is call-clobbered.
417 // R7 is marked as a use to prevent frame-pointer assignments from being
418 // moved above / below calls.
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000419 Defs = [R0, R1, R2, R3, R9, R12, LR,
420 D0, D1, D2, D3, D4, D5, D6, D7,
421 D16, D17, D18, D19, D20, D21, D22, D23,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000422 D24, D25, D26, D27, D28, D29, D30, D31, CPSR, FPSCR],
423 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000424 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000425 def tBLr9 : TIx2<0b11110, 0b11, 1,
Jim Grosbach662a8162010-12-06 23:57:07 +0000426 (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
427 IIC_Br, "bl${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000428 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000429 Requires<[IsThumb, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000430 bits<21> func;
431 let Inst{25-16} = func{20-11};
432 let Inst{13} = 1;
433 let Inst{11} = 1;
434 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000435 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000436
Evan Chengb6207242009-08-01 00:16:10 +0000437 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000438 def tBLXi_r9 : TIx2<0b11110, 0b11, 0,
Jim Grosbach662a8162010-12-06 23:57:07 +0000439 (outs), (ins pred:$p, t_bltarget:$func, variable_ops),
440 IIC_Br, "blx${p}\t$func",
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000441 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000442 Requires<[IsThumb, HasV5T, IsDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000443 bits<21> func;
444 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000445 let Inst{13} = 1;
446 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000447 let Inst{10-1} = func{10-1};
448 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000449 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000450
Evan Chengb6207242009-08-01 00:16:10 +0000451 // Also used for Thumb2
Bill Wendling849f2e32010-11-29 00:18:15 +0000452 def tBLXr_r9 : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
453 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000454 [(ARMtcall GPR:$func)]>,
455 Requires<[IsThumb, HasV5T, IsDarwin]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000456 T1Special<{1,1,1,?}> {
457 // A6.2.3 & A8.6.24
458 bits<4> func;
459 let Inst{6-3} = func;
460 let Inst{2-0} = 0b000;
461 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000462
463 // ARMv4T
Chris Lattner4d1189f2010-11-01 00:46:16 +0000464 let isCodeGenOnly = 1 in
Jim Grosbachd2535452010-12-03 18:37:17 +0000465 // FIXME: Should be a pseudo.
Johnny Chend68e1192009-12-15 17:24:14 +0000466 def tBXr9 : TIx2<{?,?,?,?,?}, {?,?}, ?,
Jim Grosbach64171712010-02-16 21:07:46 +0000467 (outs), (ins tGPR:$func, variable_ops), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000468 "mov\tlr, pc\n\tbx\t$func",
469 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000470 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000471}
472
Bill Wendling0480e282010-12-01 02:36:55 +0000473let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
474 let isPredicable = 1 in
475 def tB : T1I<(outs), (ins brtarget:$target), IIC_Br,
476 "b\t$target", [(br bb:$target)]>,
477 T1Encoding<{1,1,1,0,0,?}>;
Evan Chenga8e29892007-01-19 07:51:42 +0000478
Evan Cheng225dfe92007-01-30 01:13:37 +0000479 // Far jump
Evan Cheng53c67c02009-08-07 05:45:07 +0000480 let Defs = [LR] in
Jim Grosbach64171712010-02-16 21:07:46 +0000481 def tBfar : TIx2<0b11110, 0b11, 1, (outs), (ins brtarget:$target), IIC_Br,
Jim Grosbach78890f42010-10-01 23:21:38 +0000482 "bl\t$target",[]>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000483
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000484 def tBR_JTr : tPseudoInst<(outs),
485 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
486 Size2Bytes, IIC_Br,
487 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
488 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000489 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000490}
491
Evan Chengc85e8322007-07-05 07:13:32 +0000492// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000493// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000494let isBranch = 1, isTerminator = 1 in
Jim Grosbachceab5012010-12-04 00:20:40 +0000495 def tBcc : T1I<(outs), (ins brtarget:$target, pred:$p), IIC_Br,
496 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000497 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Jim Grosbachceab5012010-12-04 00:20:40 +0000498 T1Encoding<{1,1,0,1,?,?}> {
499 bits<4> p;
500 let Inst{11-8} = p;
501}
Evan Chenga8e29892007-01-19 07:51:42 +0000502
Evan Chengde17fb62009-10-31 23:46:45 +0000503// Compare and branch on zero / non-zero
504let isBranch = 1, isTerminator = 1 in {
Bill Wendling12280382010-11-19 23:14:32 +0000505 def tCBZ : T1I<(outs), (ins tGPR:$Rn, brtarget:$target), IIC_Br,
506 "cbz\t$Rn, $target", []>,
507 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000508 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000509 bits<6> target;
510 bits<3> Rn;
511 let Inst{9} = target{5};
512 let Inst{7-3} = target{4-0};
513 let Inst{2-0} = Rn;
514 }
Evan Chengde17fb62009-10-31 23:46:45 +0000515
516 def tCBNZ : T1I<(outs), (ins tGPR:$cmp, brtarget:$target), IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000517 "cbnz\t$cmp, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000518 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000519 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000520 bits<6> target;
521 bits<3> Rn;
522 let Inst{9} = target{5};
523 let Inst{7-3} = target{4-0};
524 let Inst{2-0} = Rn;
525 }
Evan Chengde17fb62009-10-31 23:46:45 +0000526}
527
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000528// A8.6.218 Supervisor Call (Software Interrupt) -- for disassembly only
529// A8.6.16 B: Encoding T1
530// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng1e0eab12010-11-29 22:43:27 +0000531let isCall = 1, Uses = [SP] in
Bill Wendling6179c312010-11-20 00:53:35 +0000532def tSVC : T1pI<(outs), (ins i32imm:$imm), IIC_Br,
533 "svc", "\t$imm", []>, Encoding16 {
534 bits<8> imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000535 let Inst{15-12} = 0b1101;
Bill Wendling6179c312010-11-20 00:53:35 +0000536 let Inst{11-8} = 0b1111;
537 let Inst{7-0} = imm;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000538}
539
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000540// The assembler uses 0xDEFE for a trap instruction.
Evan Chengfb3611d2010-05-11 07:26:32 +0000541let isBarrier = 1, isTerminator = 1 in
Anton Korobeynikov418d1d92010-05-15 17:19:20 +0000542def tTRAP : TI<(outs), (ins), IIC_Br,
Jim Grosbach2e6ae132010-09-23 18:05:37 +0000543 "trap", [(trap)]>, Encoding16 {
Bill Wendling7d0affd2010-11-21 10:55:23 +0000544 let Inst = 0xdefe;
Johnny Chen4c61cdd2010-02-25 02:21:11 +0000545}
546
Evan Chenga8e29892007-01-19 07:51:42 +0000547//===----------------------------------------------------------------------===//
548// Load Store Instructions.
549//
550
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000551let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000552def tLDR : // A8.6.60
Bill Wendling40062fb2010-12-01 01:38:08 +0000553 T1pILdStEncode<0b100, (outs tGPR:$Rt), (ins t_addrmode_s4:$addr),
554 AddrModeT1_4, IIC_iLoad_r,
555 "ldr", "\t$Rt, $addr",
556 [(set tGPR:$Rt, (load t_addrmode_s4:$addr))]>;
Bill Wendling6179c312010-11-20 00:53:35 +0000557
Bill Wendling1fd374e2010-11-30 22:57:21 +0000558def tLDRi: // A8.6.57
Bill Wendling40062fb2010-12-01 01:38:08 +0000559 T1pILdStEncodeImm<0b0110, 1, (outs tGPR:$Rt), (ins t_addrmode_s4:$addr),
560 AddrModeT1_4, IIC_iLoad_r,
561 "ldr", "\t$Rt, $addr",
562 []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000563
Bill Wendling1fd374e2010-11-30 22:57:21 +0000564def tLDRB : // A8.6.64
Bill Wendling40062fb2010-12-01 01:38:08 +0000565 T1pILdStEncode<0b110, (outs tGPR:$Rt), (ins t_addrmode_s1:$addr),
566 AddrModeT1_1, IIC_iLoad_bh_r,
567 "ldrb", "\t$Rt, $addr",
568 [(set tGPR:$Rt, (zextloadi8 t_addrmode_s1:$addr))]>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000569
570def tLDRBi : // A8.6.61
Bill Wendlingfb62d552010-12-03 23:44:24 +0000571 T1pILdStEncodeImm<0b0111, 1, (outs tGPR:$Rt), (ins t_addrmode_s1:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000572 AddrModeT1_1, IIC_iLoad_bh_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000573 "ldrb", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000574 []>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000575
Bill Wendling1fd374e2010-11-30 22:57:21 +0000576def tLDRH : // A8.6.76
Bill Wendling40062fb2010-12-01 01:38:08 +0000577 T1pILdStEncode<0b101, (outs tGPR:$dst), (ins t_addrmode_s2:$addr),
578 AddrModeT1_2, IIC_iLoad_bh_r,
579 "ldrh", "\t$dst, $addr",
580 [(set tGPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000581
582def tLDRHi: // A8.6.73
Bill Wendlingfb62d552010-12-03 23:44:24 +0000583 T1pILdStEncodeImm<0b1000, 1, (outs tGPR:$Rt), (ins t_addrmode_s2:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000584 AddrModeT1_2, IIC_iLoad_bh_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000585 "ldrh", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000586 []>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000587
Evan Cheng2f297df2009-07-11 07:08:13 +0000588let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000589def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000590 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
591 AddrModeT1_1, IIC_iLoad_bh_r,
592 "ldrsb", "\t$dst, $addr",
593 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000594
Evan Cheng2f297df2009-07-11 07:08:13 +0000595let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000596def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000597 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
598 AddrModeT1_2, IIC_iLoad_bh_r,
599 "ldrsh", "\t$dst, $addr",
600 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000601
Dan Gohman15511cf2008-12-03 18:15:48 +0000602let canFoldAsLoad = 1 in
Evan Cheng0e55fd62010-09-30 01:08:25 +0000603def tLDRspi : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Evan Cheng699beba2009-10-27 00:08:59 +0000604 "ldr", "\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000605 [(set tGPR:$dst, (load t_addrmode_sp:$addr))]>,
606 T1LdStSP<{1,?,?}>;
Evan Cheng012f2d92007-01-24 08:53:17 +0000607
Evan Cheng8e59ea92007-02-07 00:06:56 +0000608// Special instruction for restore. It cannot clobber condition register
609// when it's expanded by eliminateCallFramePseudoInstr().
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000610let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1 in
Evan Cheng0e55fd62010-09-30 01:08:25 +0000611def tRestore : T1pIs<(outs tGPR:$dst), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000612 "ldr", "\t$dst, $addr", []>,
613 T1LdStSP<{1,?,?}>;
Evan Cheng8e59ea92007-02-07 00:06:56 +0000614
Evan Cheng012f2d92007-01-24 08:53:17 +0000615// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000616// FIXME: Use ldr.n to work around a Darwin assembler bug.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000617let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendling3f8c1102010-11-30 23:54:45 +0000618def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins i32imm:$addr), IIC_iLoad_i,
619 "ldr", ".n\t$Rt, $addr",
620 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
621 T1Encoding<{0,1,0,0,1,?}> {
622 // A6.2 & A8.6.59
623 bits<3> Rt;
624 let Inst{10-8} = Rt;
625 // FIXME: Finish for the addr.
626}
Evan Chengfa775d02007-03-19 07:20:03 +0000627
628// Special LDR for loads from non-pc-relative constpools.
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000629let canFoldAsLoad = 1, mayLoad = 1, neverHasSideEffects = 1,
630 isReMaterializable = 1 in
Evan Cheng0e55fd62010-09-30 01:08:25 +0000631def tLDRcp : T1pIs<(outs tGPR:$dst), (ins i32imm:$addr), IIC_iLoad_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000632 "ldr", "\t$dst, $addr", []>,
633 T1LdStSP<{1,?,?}>;
Evan Chenga8e29892007-01-19 07:51:42 +0000634
Bill Wendling1fd374e2010-11-30 22:57:21 +0000635def tSTR : // A8.6.194
Bill Wendling40062fb2010-12-01 01:38:08 +0000636 T1pILdStEncode<0b000, (outs), (ins tGPR:$src, t_addrmode_s4:$addr),
637 AddrModeT1_4, IIC_iStore_r,
638 "str", "\t$src, $addr",
639 [(store tGPR:$src, t_addrmode_s4:$addr)]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000640
Bill Wendling1fd374e2010-11-30 22:57:21 +0000641def tSTRi : // A8.6.192
Bill Wendlingfb62d552010-12-03 23:44:24 +0000642 T1pILdStEncodeImm<0b0110, 0, (outs), (ins tGPR:$Rt, t_addrmode_s4:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000643 AddrModeT1_4, IIC_iStore_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000644 "str", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000645 []>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000646
Bill Wendling1fd374e2010-11-30 22:57:21 +0000647def tSTRB : // A8.6.197
Bill Wendling40062fb2010-12-01 01:38:08 +0000648 T1pILdStEncode<0b010, (outs), (ins tGPR:$src, t_addrmode_s1:$addr),
649 AddrModeT1_1, IIC_iStore_bh_r,
650 "strb", "\t$src, $addr",
651 [(truncstorei8 tGPR:$src, t_addrmode_s1:$addr)]>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000652
653def tSTRBi : // A8.6.195
Bill Wendlingfb62d552010-12-03 23:44:24 +0000654 T1pILdStEncodeImm<0b0111, 0, (outs), (ins tGPR:$Rt, t_addrmode_s1:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000655 AddrModeT1_1, IIC_iStore_bh_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000656 "strb", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000657 []>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000658
659def tSTRH : // A8.6.207
Bill Wendling40062fb2010-12-01 01:38:08 +0000660 T1pILdStEncode<0b001, (outs), (ins tGPR:$src, t_addrmode_s2:$addr),
661 AddrModeT1_2, IIC_iStore_bh_r,
662 "strh", "\t$src, $addr",
663 [(truncstorei16 tGPR:$src, t_addrmode_s2:$addr)]>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000664
665def tSTRHi : // A8.6.205
Bill Wendlingfb62d552010-12-03 23:44:24 +0000666 T1pILdStEncodeImm<0b1000, 0, (outs), (ins tGPR:$Rt, t_addrmode_s2:$addr),
Bill Wendling40062fb2010-12-01 01:38:08 +0000667 AddrModeT1_2, IIC_iStore_bh_r,
Bill Wendlingfb62d552010-12-03 23:44:24 +0000668 "strh", "\t$Rt, $addr",
Bill Wendling40062fb2010-12-01 01:38:08 +0000669 []>;
Evan Chenga8e29892007-01-19 07:51:42 +0000670
Evan Cheng0e55fd62010-09-30 01:08:25 +0000671def tSTRspi : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore_i,
Evan Cheng699beba2009-10-27 00:08:59 +0000672 "str", "\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000673 [(store tGPR:$src, t_addrmode_sp:$addr)]>,
674 T1LdStSP<{0,?,?}>;
Evan Cheng8e59ea92007-02-07 00:06:56 +0000675
Bill Wendling3f8c1102010-11-30 23:54:45 +0000676let mayStore = 1, neverHasSideEffects = 1 in
677// Special instruction for spill. It cannot clobber condition register when it's
678// expanded by eliminateCallFramePseudoInstr().
Evan Cheng0e55fd62010-09-30 01:08:25 +0000679def tSpill : T1pIs<(outs), (ins tGPR:$src, t_addrmode_sp:$addr), IIC_iStore_i,
Johnny Chend68e1192009-12-15 17:24:14 +0000680 "str", "\t$src, $addr", []>,
681 T1LdStSP<{0,?,?}>;
Evan Chenga8e29892007-01-19 07:51:42 +0000682
683//===----------------------------------------------------------------------===//
684// Load / store multiple Instructions.
685//
686
Bill Wendling6c470b82010-11-13 09:09:38 +0000687multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
688 InstrItinClass itin_upd, bits<6> T1Enc,
689 bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000690 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000691 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000692 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000693 T1Encoding<T1Enc> {
694 bits<3> Rn;
695 bits<8> regs;
696 let Inst{10-8} = Rn;
697 let Inst{7-0} = regs;
698 }
Bill Wendling73fe34a2010-11-16 01:16:36 +0000699 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +0000700 T1It<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000701 itin_upd, !strconcat(asm, "ia${p}\t$Rn!, $regs"), "$Rn = $wb", []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000702 T1Encoding<T1Enc> {
703 bits<3> Rn;
704 bits<8> regs;
705 let Inst{10-8} = Rn;
706 let Inst{7-0} = regs;
707 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000708}
709
Bill Wendling73fe34a2010-11-16 01:16:36 +0000710// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000711let neverHasSideEffects = 1 in {
712
713let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
714defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
715 {1,1,0,0,1,?}, 1>;
716
717let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
718defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
719 {1,1,0,0,0,?}, 0>;
720
721} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000722
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000723let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000724def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000725 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000726 "pop${p}\t$regs", []>,
727 T1Misc<{1,1,0,?,?,?,?}> {
728 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000729 let Inst{8} = regs{15};
730 let Inst{7-0} = regs{7-0};
731}
Evan Cheng4b322e52009-08-11 21:11:32 +0000732
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000733let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000734def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000735 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000736 "push${p}\t$regs", []>,
737 T1Misc<{0,1,0,?,?,?,?}> {
738 bits<16> regs;
739 let Inst{8} = regs{14};
740 let Inst{7-0} = regs{7-0};
741}
Evan Chenga8e29892007-01-19 07:51:42 +0000742
743//===----------------------------------------------------------------------===//
744// Arithmetic Instructions.
745//
746
Bill Wendling1d045ee2010-12-01 02:28:08 +0000747// Helper classes for encoding T1pI patterns:
748class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
749 string opc, string asm, list<dag> pattern>
750 : T1pI<oops, iops, itin, opc, asm, pattern>,
751 T1DataProcessing<opA> {
752 bits<3> Rm;
753 bits<3> Rn;
754 let Inst{5-3} = Rm;
755 let Inst{2-0} = Rn;
756}
757class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
758 string opc, string asm, list<dag> pattern>
759 : T1pI<oops, iops, itin, opc, asm, pattern>,
760 T1Misc<opA> {
761 bits<3> Rm;
762 bits<3> Rd;
763 let Inst{5-3} = Rm;
764 let Inst{2-0} = Rd;
765}
766
Bill Wendling76f4e102010-12-01 01:20:15 +0000767// Helper classes for encoding T1sI patterns:
768class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
769 string opc, string asm, list<dag> pattern>
770 : T1sI<oops, iops, itin, opc, asm, pattern>,
771 T1DataProcessing<opA> {
772 bits<3> Rd;
773 bits<3> Rn;
774 let Inst{5-3} = Rn;
775 let Inst{2-0} = Rd;
776}
777class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
778 string opc, string asm, list<dag> pattern>
779 : T1sI<oops, iops, itin, opc, asm, pattern>,
780 T1General<opA> {
781 bits<3> Rm;
782 bits<3> Rn;
783 bits<3> Rd;
784 let Inst{8-6} = Rm;
785 let Inst{5-3} = Rn;
786 let Inst{2-0} = Rd;
787}
788class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
789 string opc, string asm, list<dag> pattern>
790 : T1sI<oops, iops, itin, opc, asm, pattern>,
791 T1General<opA> {
792 bits<3> Rd;
793 bits<3> Rm;
794 let Inst{5-3} = Rm;
795 let Inst{2-0} = Rd;
796}
797
798// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000799class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
800 string opc, string asm, list<dag> pattern>
801 : T1sIt<oops, iops, itin, opc, asm, pattern>,
802 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000803 bits<3> Rdn;
804 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000805 let Inst{5-3} = Rm;
806 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000807}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000808class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
809 string opc, string asm, list<dag> pattern>
810 : T1sIt<oops, iops, itin, opc, asm, pattern>,
811 T1General<opA> {
812 bits<3> Rdn;
813 bits<8> imm8;
814 let Inst{10-8} = Rdn;
815 let Inst{7-0} = imm8;
816}
817
818// Add with carry register
819let isCommutable = 1, Uses = [CPSR] in
820def tADC : // A8.6.2
821 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
822 "adc", "\t$Rdn, $Rm",
823 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000824
David Goodwinc9ee1182009-06-25 22:49:55 +0000825// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000826def tADDi3 : // A8.6.4 T1
827 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3), IIC_iALUi,
828 "add", "\t$Rd, $Rm, $imm3",
829 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000830 bits<3> imm3;
831 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000832}
Evan Chenga8e29892007-01-19 07:51:42 +0000833
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000834def tADDi8 : // A8.6.4 T2
835 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
836 IIC_iALUi,
837 "add", "\t$Rdn, $imm8",
838 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000839
David Goodwinc9ee1182009-06-25 22:49:55 +0000840// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000841let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000842def tADDrr : // A8.6.6 T1
843 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
844 IIC_iALUr,
845 "add", "\t$Rd, $Rn, $Rm",
846 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000847
Evan Chengcd799b92009-06-12 20:46:18 +0000848let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000849def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
850 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000851 T1Special<{0,0,?,?}> {
852 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000853 bits<4> Rdn;
854 bits<4> Rm;
855 let Inst{7} = Rdn{3};
856 let Inst{6-3} = Rm;
857 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000858}
Evan Chenga8e29892007-01-19 07:51:42 +0000859
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000860// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000861let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000862def tAND : // A8.6.12
863 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
864 IIC_iBITr,
865 "and", "\t$Rdn, $Rm",
866 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000867
David Goodwinc9ee1182009-06-25 22:49:55 +0000868// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000869def tASRri : // A8.6.14
870 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
871 IIC_iMOVsi,
872 "asr", "\t$Rd, $Rm, $imm5",
873 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000874 bits<5> imm5;
875 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000876}
Evan Chenga8e29892007-01-19 07:51:42 +0000877
David Goodwinc9ee1182009-06-25 22:49:55 +0000878// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000879def tASRrr : // A8.6.15
880 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
881 IIC_iMOVsr,
882 "asr", "\t$Rdn, $Rm",
883 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000884
David Goodwinc9ee1182009-06-25 22:49:55 +0000885// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000886def tBIC : // A8.6.20
887 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
888 IIC_iBITr,
889 "bic", "\t$Rdn, $Rm",
890 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000891
David Goodwinc9ee1182009-06-25 22:49:55 +0000892// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000893let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000894//FIXME: Disable CMN, as CCodes are backwards from compare expectations
895// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000896//def tCMN : // A8.6.33
897// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
898// IIC_iCMPr,
899// "cmn", "\t$lhs, $rhs",
900// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000901
902def tCMNz : // A8.6.33
903 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
904 IIC_iCMPr,
905 "cmn", "\t$Rn, $Rm",
906 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
907
908} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000909
David Goodwinc9ee1182009-06-25 22:49:55 +0000910// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000911let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000912def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
913 "cmp", "\t$Rn, $imm8",
914 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
915 T1General<{1,0,1,?,?}> {
916 // A8.6.35
917 bits<3> Rn;
918 bits<8> imm8;
919 let Inst{10-8} = Rn;
920 let Inst{7-0} = imm8;
921}
922
923def tCMPzi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
924 "cmp", "\t$Rn, $imm8",
925 [(ARMcmpZ tGPR:$Rn, imm0_255:$imm8)]>,
926 T1General<{1,0,1,?,?}> {
927 // A8.6.35
928 bits<3> Rn;
929 let Inst{10-8} = Rn;
930 let Inst{7-0} = 0x00;
David Goodwinc9ee1182009-06-25 22:49:55 +0000931}
932
933// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +0000934def tCMPr : // A8.6.36 T1
935 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
936 IIC_iCMPr,
937 "cmp", "\t$Rn, $Rm",
938 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
939
940def tCMPzr : // A8.6.36 T1
941 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iCMPr,
942 "cmp", "\t$Rn, $Rm",
943 [(ARMcmpZ tGPR:$Rn, tGPR:$Rm)]>;
Bill Wendling602890d2010-11-19 01:33:10 +0000944
Bill Wendling849f2e32010-11-29 00:18:15 +0000945def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
946 "cmp", "\t$Rn, $Rm", []>,
947 T1Special<{0,1,?,?}> {
948 // A8.6.36 T2
949 bits<4> Rm;
950 bits<4> Rn;
951 let Inst{7} = Rn{3};
952 let Inst{6-3} = Rm;
953 let Inst{2-0} = Rn{2-0};
954}
Jim Grosbach1b555d92010-12-03 23:21:25 +0000955def tCMPzhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
956 "cmp", "\t$Rn, $Rm", []>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000957 T1Special<{0,1,?,?}> {
958 // A8.6.36 T2
959 bits<4> Rm;
960 bits<4> Rn;
961 let Inst{7} = Rn{3};
962 let Inst{6-3} = Rm;
963 let Inst{2-0} = Rn{2-0};
964}
965
Bill Wendling5cc88a22010-11-20 22:52:33 +0000966} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000967
Evan Chenga8e29892007-01-19 07:51:42 +0000968
David Goodwinc9ee1182009-06-25 22:49:55 +0000969// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +0000970let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000971def tEOR : // A8.6.45
972 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
973 IIC_iBITr,
974 "eor", "\t$Rdn, $Rm",
975 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000976
David Goodwinc9ee1182009-06-25 22:49:55 +0000977// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000978def tLSLri : // A8.6.88
979 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
980 IIC_iMOVsi,
981 "lsl", "\t$Rd, $Rm, $imm5",
982 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000983 bits<5> imm5;
984 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000985}
Evan Chenga8e29892007-01-19 07:51:42 +0000986
David Goodwinc9ee1182009-06-25 22:49:55 +0000987// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000988def tLSLrr : // A8.6.89
989 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
990 IIC_iMOVsr,
991 "lsl", "\t$Rdn, $Rm",
992 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000993
David Goodwinc9ee1182009-06-25 22:49:55 +0000994// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000995def tLSRri : // A8.6.90
996 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
997 IIC_iMOVsi,
998 "lsr", "\t$Rd, $Rm, $imm5",
999 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001000 bits<5> imm5;
1001 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001002}
Evan Chenga8e29892007-01-19 07:51:42 +00001003
David Goodwinc9ee1182009-06-25 22:49:55 +00001004// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001005def tLSRrr : // A8.6.91
1006 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1007 IIC_iMOVsr,
1008 "lsr", "\t$Rdn, $Rm",
1009 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001010
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001011// Move register
Evan Chengc4af4632010-11-17 20:13:28 +00001012let isMoveImm = 1 in
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001013def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins i32imm:$imm8), IIC_iMOVi,
1014 "mov", "\t$Rd, $imm8",
1015 [(set tGPR:$Rd, imm0_255:$imm8)]>,
1016 T1General<{1,0,0,?,?}> {
1017 // A8.6.96
1018 bits<3> Rd;
1019 bits<8> imm8;
1020 let Inst{10-8} = Rd;
1021 let Inst{7-0} = imm8;
1022}
Evan Chenga8e29892007-01-19 07:51:42 +00001023
1024// TODO: A7-73: MOV(2) - mov setting flag.
1025
Evan Chengcd799b92009-06-12 20:46:18 +00001026let neverHasSideEffects = 1 in {
Evan Cheng446c4282009-07-11 06:43:01 +00001027// FIXME: Make this predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001028def tMOVr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1029 "mov\t$Rd, $Rm", []>,
1030 T1Special<0b1000> {
1031 // A8.6.97
1032 bits<4> Rd;
1033 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001034 // Bits {7-6} are encoded by the T1Special value.
1035 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001036 let Inst{2-0} = Rd{2-0};
1037}
Evan Cheng446c4282009-07-11 06:43:01 +00001038let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001039def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1040 "movs\t$Rd, $Rm", []>, Encoding16 {
1041 // A8.6.97
1042 bits<3> Rd;
1043 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001044 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001045 let Inst{5-3} = Rm;
1046 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001047}
Evan Cheng446c4282009-07-11 06:43:01 +00001048
1049// FIXME: Make these predicable.
Bill Wendling534a5e42010-12-03 01:55:47 +00001050def tMOVgpr2tgpr : T1I<(outs tGPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1051 "mov\t$Rd, $Rm", []>,
1052 T1Special<{1,0,0,?}> {
1053 // A8.6.97
1054 bits<4> Rd;
1055 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001056 // Bit {7} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001057 let Inst{6-3} = Rm;
1058 let Inst{2-0} = Rd{2-0};
1059}
1060def tMOVtgpr2gpr : T1I<(outs GPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1061 "mov\t$Rd, $Rm", []>,
1062 T1Special<{1,0,?,0}> {
1063 // A8.6.97
1064 bits<4> Rd;
1065 bits<4> Rm;
Bill Wendling278b6e82010-12-03 02:02:58 +00001066 // Bit {6} is encoded by the T1Special value.
Bill Wendling534a5e42010-12-03 01:55:47 +00001067 let Inst{7} = Rd{3};
Bill Wendling278b6e82010-12-03 02:02:58 +00001068 let Inst{5-3} = Rm{2-0};
Bill Wendling534a5e42010-12-03 01:55:47 +00001069 let Inst{2-0} = Rd{2-0};
1070}
1071def tMOVgpr2gpr : T1I<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1072 "mov\t$Rd, $Rm", []>,
1073 T1Special<{1,0,?,?}> {
1074 // A8.6.97
1075 bits<4> Rd;
1076 bits<4> Rm;
1077 let Inst{7} = Rd{3};
1078 let Inst{6-3} = Rm;
1079 let Inst{2-0} = Rd{2-0};
1080}
Evan Chengcd799b92009-06-12 20:46:18 +00001081} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001082
Bill Wendling0480e282010-12-01 02:36:55 +00001083// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001084let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001085def tMUL : // A8.6.105 T1
1086 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1087 IIC_iMUL32,
1088 "mul", "\t$Rdn, $Rm, $Rdn",
1089 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001090
Bill Wendling76f4e102010-12-01 01:20:15 +00001091// Move inverse register
1092def tMVN : // A8.6.107
1093 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1094 "mvn", "\t$Rd, $Rn",
1095 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001096
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001097// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001098let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001099def tORR : // A8.6.114
1100 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1101 IIC_iBITr,
1102 "orr", "\t$Rdn, $Rm",
1103 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001104
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001105// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001106def tREV : // A8.6.134
1107 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1108 IIC_iUNAr,
1109 "rev", "\t$Rd, $Rm",
1110 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1111 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001112
Bill Wendling1d045ee2010-12-01 02:28:08 +00001113def tREV16 : // A8.6.135
1114 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1115 IIC_iUNAr,
1116 "rev16", "\t$Rd, $Rm",
Bill Wendlingd19ac0c2010-11-29 00:42:50 +00001117 [(set tGPR:$Rd,
1118 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF),
1119 (or (and (shl tGPR:$Rm, (i32 8)), 0xFF00),
1120 (or (and (srl tGPR:$Rm, (i32 8)), 0xFF0000),
1121 (and (shl tGPR:$Rm, (i32 8)), 0xFF000000)))))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001122 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001123
Bill Wendling1d045ee2010-12-01 02:28:08 +00001124def tREVSH : // A8.6.136
1125 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1126 IIC_iUNAr,
1127 "revsh", "\t$Rd, $Rm",
1128 [(set tGPR:$Rd,
1129 (sext_inreg
1130 (or (srl (and tGPR:$Rm, 0xFF00), (i32 8)),
1131 (shl tGPR:$Rm, (i32 8))), i16))]>,
1132 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001133
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001134// Rotate right register
1135def tROR : // A8.6.139
1136 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1137 IIC_iMOVsr,
1138 "ror", "\t$Rdn, $Rm",
1139 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001140
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001141// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001142def tRSB : // A8.6.141
1143 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1144 IIC_iALUi,
1145 "rsb", "\t$Rd, $Rn, #0",
1146 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001147
David Goodwinc9ee1182009-06-25 22:49:55 +00001148// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001149let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001150def tSBC : // A8.6.151
1151 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1152 IIC_iALUr,
1153 "sbc", "\t$Rdn, $Rm",
1154 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001155
David Goodwinc9ee1182009-06-25 22:49:55 +00001156// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001157def tSUBi3 : // A8.6.210 T1
1158 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1159 IIC_iALUi,
1160 "sub", "\t$Rd, $Rm, $imm3",
1161 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001162 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001163 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001164}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001165
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001166def tSUBi8 : // A8.6.210 T2
1167 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1168 IIC_iALUi,
1169 "sub", "\t$Rdn, $imm8",
1170 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001171
Bill Wendling76f4e102010-12-01 01:20:15 +00001172// Subtract register
1173def tSUBrr : // A8.6.212
1174 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1175 IIC_iALUr,
1176 "sub", "\t$Rd, $Rn, $Rm",
1177 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001178
1179// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001180
Bill Wendling76f4e102010-12-01 01:20:15 +00001181// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001182def tSXTB : // A8.6.222
1183 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1184 IIC_iUNAr,
1185 "sxtb", "\t$Rd, $Rm",
1186 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1187 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001188
Bill Wendling1d045ee2010-12-01 02:28:08 +00001189// Sign-extend short
1190def tSXTH : // A8.6.224
1191 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1192 IIC_iUNAr,
1193 "sxth", "\t$Rd, $Rm",
1194 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1195 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001196
Bill Wendling1d045ee2010-12-01 02:28:08 +00001197// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001198let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001199def tTST : // A8.6.230
1200 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1201 "tst", "\t$Rn, $Rm",
1202 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001203
Bill Wendling1d045ee2010-12-01 02:28:08 +00001204// Zero-extend byte
1205def tUXTB : // A8.6.262
1206 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1207 IIC_iUNAr,
1208 "uxtb", "\t$Rd, $Rm",
1209 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1210 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001211
Bill Wendling1d045ee2010-12-01 02:28:08 +00001212// Zero-extend short
1213def tUXTH : // A8.6.264
1214 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1215 IIC_iUNAr,
1216 "uxth", "\t$Rd, $Rm",
1217 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1218 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001219
Jim Grosbach80dc1162010-02-16 21:23:02 +00001220// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001221// Expanded after instruction selection into a branch sequence.
1222let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001223 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001224 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001225 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001226 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001227
Evan Cheng007ea272009-08-12 05:17:19 +00001228
1229// 16-bit movcc in IT blocks for Thumb2.
Owen Andersonf523e472010-09-23 23:45:25 +00001230let neverHasSideEffects = 1 in {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001231def tMOVCCr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iCMOVr,
1232 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001233 T1Special<{1,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001234 bits<4> Rdn;
1235 bits<4> Rm;
1236 let Inst{7} = Rdn{3};
1237 let Inst{6-3} = Rm;
1238 let Inst{2-0} = Rdn{2-0};
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001239}
Evan Cheng007ea272009-08-12 05:17:19 +00001240
Evan Chengc4af4632010-11-17 20:13:28 +00001241let isMoveImm = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +00001242def tMOVCCi : T1pIt<(outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$Rm), IIC_iCMOVi,
1243 "mov", "\t$Rdn, $Rm", []>,
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001244 T1General<{1,0,0,?,?}> {
Bill Wendling0b424dc2010-12-01 01:32:02 +00001245 bits<3> Rdn;
1246 bits<8> Rm;
1247 let Inst{10-8} = Rdn;
1248 let Inst{7-0} = Rm;
Bill Wendling9b0e92c2010-11-29 22:37:46 +00001249}
1250
Owen Andersonf523e472010-09-23 23:45:25 +00001251} // neverHasSideEffects
Evan Cheng007ea272009-08-12 05:17:19 +00001252
Evan Chenga8e29892007-01-19 07:51:42 +00001253// tLEApcrel - Load a pc-relative address into a register without offending the
1254// assembler.
Bill Wendling8ca2fd62010-11-30 00:08:20 +00001255let neverHasSideEffects = 1, isReMaterializable = 1 in
Bill Wendling67077412010-11-30 00:18:30 +00001256def tLEApcrel : T1I<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p), IIC_iALUi,
1257 "adr${p}\t$Rd, #$label", []>,
1258 T1Encoding<{1,0,1,0,0,?}> {
1259 // A6.2 & A8.6.10
1260 bits<3> Rd;
1261 let Inst{10-8} = Rd;
1262 // FIXME: Add label encoding/fixup
1263}
Evan Chenga8e29892007-01-19 07:51:42 +00001264
Bill Wendling67077412010-11-30 00:18:30 +00001265def tLEApcrelJT : T1I<(outs tGPR:$Rd),
Bob Wilson4f38b382009-08-21 21:58:55 +00001266 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Bill Wendling67077412010-11-30 00:18:30 +00001267 IIC_iALUi, "adr${p}\t$Rd, #${label}_${id}", []>,
1268 T1Encoding<{1,0,1,0,0,?}> {
1269 // A6.2 & A8.6.10
1270 bits<3> Rd;
1271 let Inst{10-8} = Rd;
1272 // FIXME: Add label encoding/fixup
1273}
Evan Chengd85ac4d2007-01-27 02:29:45 +00001274
Evan Chenga8e29892007-01-19 07:51:42 +00001275//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001276// TLS Instructions
1277//
1278
1279// __aeabi_read_tp preserves the registers r1-r3.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001280let isCall = 1, Defs = [R0, LR], Uses = [SP] in
1281def tTPsoft : TIx2<0b11110, 0b11, 1, (outs), (ins), IIC_Br,
1282 "bl\t__aeabi_read_tp",
1283 [(set R0, ARMthread_pointer)]> {
1284 // Encoding is 0xf7fffffe.
1285 let Inst = 0xf7fffffe;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001286}
1287
Bill Wendling0480e282010-12-01 02:36:55 +00001288//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001289// SJLJ Exception handling intrinsics
Bill Wendling0480e282010-12-01 02:36:55 +00001290//
1291
1292// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1293// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1294// from some other function to get here, and we're using the stack frame for the
1295// containing function to save/restore registers, we can't keep anything live in
1296// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
1297// tromped upon when we get here from a longjmp(). We force everthing out of
1298// registers except for our own input by listing the relevant registers in
1299// Defs. By doing so, we also cause the prologue/epilogue code to actively
1300// preserve all of the callee-saved resgisters, which is exactly what we want.
1301// $val is a scratch register for our use.
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001302let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12 ],
1303 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1304def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
1305 AddrModeNone, SizeSpecial, NoItinerary, "","",
1306 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001307
1308// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001309let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001310 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001311def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001312 AddrModeNone, SizeSpecial, IndexModeNone,
1313 Pseudo, NoItinerary, "", "",
1314 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1315 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001316
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001317//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001318// Non-Instruction Patterns
1319//
1320
Evan Cheng892837a2009-07-10 02:09:04 +00001321// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001322def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1323 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1324def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001325 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001326def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1327 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001328
1329// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001330def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1331 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1332def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1333 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1334def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1335 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001336
Evan Chenga8e29892007-01-19 07:51:42 +00001337// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001338def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1339def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001340
Evan Chengd85ac4d2007-01-27 02:29:45 +00001341// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001342def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1343 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001344
Evan Chenga8e29892007-01-19 07:51:42 +00001345// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001346def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001347 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001348def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001349 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001350
1351def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001352 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001353def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001354 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001355
1356// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001357def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1358 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1359def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1360 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001361
1362// zextload i1 -> zextload i8
Evan Chengf3c21b82009-06-30 02:15:48 +00001363def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
1364 (tLDRB t_addrmode_s1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001365
Evan Chengb60c02e2007-01-26 19:13:16 +00001366// extload -> zextload
Evan Chengf3c21b82009-06-30 02:15:48 +00001367def : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
1368def : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
1369def : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001370
Evan Cheng0e87e232009-08-28 00:31:43 +00001371// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001372// ldr{b|h} + sxt{b|h} instead.
Evan Cheng3ecadc82009-07-21 18:15:26 +00001373def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
Evan Cheng0e87e232009-08-28 00:31:43 +00001374 (tSXTB (tLDRB t_addrmode_s1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001375 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng3ecadc82009-07-21 18:15:26 +00001376def : T1Pat<(sextloadi16 t_addrmode_s2:$addr),
Evan Cheng0e87e232009-08-28 00:31:43 +00001377 (tSXTH (tLDRH t_addrmode_s2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001378 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001379
Evan Cheng0e87e232009-08-28 00:31:43 +00001380def : T1Pat<(sextloadi8 t_addrmode_s1:$addr),
1381 (tASRri (tLSLri (tLDRB t_addrmode_s1:$addr), 24), 24)>;
1382def : T1Pat<(sextloadi16 t_addrmode_s1:$addr),
1383 (tASRri (tLSLri (tLDRH t_addrmode_s1:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001384
Evan Chenga8e29892007-01-19 07:51:42 +00001385// Large immediate handling.
1386
1387// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001388def : T1Pat<(i32 thumb_immshifted:$src),
1389 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1390 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001391
Evan Cheng9cb9e672009-06-27 02:26:13 +00001392def : T1Pat<(i32 imm0_255_comp:$src),
1393 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001394
1395// Pseudo instruction that combines ldr from constpool and add pc. This should
1396// be expanded into two instructions late to allow if-conversion and
1397// scheduling.
1398let isReMaterializable = 1 in
1399def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001400 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001401 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1402 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001403 Requires<[IsThumb, IsThumb1Only]>;