blob: e0c03179200d68e01f527e7fe41e5a4702769412 [file] [log] [blame]
Bill Wendling0480e282010-12-01 02:36:55 +00001//===- ARMInstrThumb.td - Thumb support for ARM ------------*- tablegen -*-===//
Evan Chenga8e29892007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Thumb specific DAG Nodes.
16//
17
18def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
Chris Lattner036609b2010-12-23 18:28:41 +000019 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
Chris Lattner60e9eac2010-03-19 05:33:51 +000020 SDNPVariadic]>;
Evan Chenga8e29892007-01-19 07:51:42 +000021
Evan Chenga8e29892007-01-19 07:51:42 +000022def imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000023 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000024}]>;
25def imm_comp_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000026 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000027}]>;
28
Evan Chenga8e29892007-01-19 07:51:42 +000029def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000030 return (uint32_t)-N->getZExtValue() < 8;
Evan Chenga8e29892007-01-19 07:51:42 +000031}], imm_neg_XFORM>;
32
Evan Chenga8e29892007-01-19 07:51:42 +000033def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000034 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000035}]>;
36
Eric Christopher8f232d32011-04-28 05:49:04 +000037def imm8_255 : ImmLeaf<i32, [{
38 return Imm >= 8 && Imm < 256;
Evan Chenga8e29892007-01-19 07:51:42 +000039}]>;
40def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000041 unsigned Val = -N->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +000042 return Val >= 8 && Val < 256;
43}], imm_neg_XFORM>;
44
Bill Wendling0480e282010-12-01 02:36:55 +000045// Break imm's up into two pieces: an immediate + a left shift. This uses
46// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
47// to get the val/shift pieces.
Evan Chenga8e29892007-01-19 07:51:42 +000048def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000049 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Chenga8e29892007-01-19 07:51:42 +000050}]>;
51
52def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000053 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000054 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000055}]>;
56
57def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000058 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson825b72b2009-08-11 20:47:22 +000059 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +000060}]>;
61
Jim Grosbachd40963c2010-12-14 22:28:03 +000062// ADR instruction labels.
63def t_adrlabel : Operand<i32> {
64 let EncoderMethod = "getThumbAdrLabelOpValue";
65}
66
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000067// Scaled 4 immediate.
68def t_imm_s4 : Operand<i32> {
69 let PrintMethod = "printThumbS4ImmOperand";
Benjamin Kramer151bd172011-07-14 21:47:24 +000070 let OperandType = "OPERAND_IMMEDIATE";
Evan Cheng2ef9c8a2009-11-19 06:57:41 +000071}
72
Evan Chenga8e29892007-01-19 07:51:42 +000073// Define Thumb specific addressing modes.
74
Benjamin Kramer151bd172011-07-14 21:47:24 +000075let OperandType = "OPERAND_PCREL" in {
Jim Grosbache2467172010-12-10 18:21:33 +000076def t_brtarget : Operand<OtherVT> {
77 let EncoderMethod = "getThumbBRTargetOpValue";
78}
79
Jim Grosbach01086452010-12-10 17:13:40 +000080def t_bcctarget : Operand<i32> {
81 let EncoderMethod = "getThumbBCCTargetOpValue";
82}
83
Jim Grosbachcf6220a2010-12-09 19:01:46 +000084def t_cbtarget : Operand<i32> {
Jim Grosbach027d6e82010-12-09 19:04:53 +000085 let EncoderMethod = "getThumbCBTargetOpValue";
Bill Wendlingdff2f712010-12-08 23:01:43 +000086}
87
Jim Grosbach662a8162010-12-06 23:57:07 +000088def t_bltarget : Operand<i32> {
89 let EncoderMethod = "getThumbBLTargetOpValue";
90}
91
Bill Wendling09aa3f02010-12-09 00:39:08 +000092def t_blxtarget : Operand<i32> {
93 let EncoderMethod = "getThumbBLXTargetOpValue";
94}
Benjamin Kramer151bd172011-07-14 21:47:24 +000095}
Bill Wendling09aa3f02010-12-09 00:39:08 +000096
Evan Chenga8e29892007-01-19 07:51:42 +000097// t_addrmode_rr := reg + reg
98//
Jim Grosbach7ce05792011-08-03 23:50:40 +000099def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
Evan Chenga8e29892007-01-19 07:51:42 +0000100def t_addrmode_rr : Operand<i32>,
101 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendlingf4caf692010-12-14 03:36:38 +0000102 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000103 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach30eae3c2009-04-07 20:34:09 +0000104 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000105}
106
Bill Wendlingf4caf692010-12-14 03:36:38 +0000107// t_addrmode_rrs := reg + reg
Evan Chenga8e29892007-01-19 07:51:42 +0000108//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000109def t_addrmode_rrs1 : Operand<i32>,
110 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
111 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
112 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach7ce05792011-08-03 23:50:40 +0000113 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000114 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000115}
Bill Wendlingf4caf692010-12-14 03:36:38 +0000116def t_addrmode_rrs2 : Operand<i32>,
117 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
118 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
119 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach7ce05792011-08-03 23:50:40 +0000120 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000121 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000122}
123def t_addrmode_rrs4 : Operand<i32>,
124 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
125 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
126 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach7ce05792011-08-03 23:50:40 +0000127 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000128 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Chenga8e29892007-01-19 07:51:42 +0000129}
Evan Chengc38f2bc2007-01-23 22:59:13 +0000130
Bill Wendlingf4caf692010-12-14 03:36:38 +0000131// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc38f2bc2007-01-23 22:59:13 +0000132//
Bill Wendlingf4caf692010-12-14 03:36:38 +0000133def t_addrmode_is4 : Operand<i32>,
134 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
135 let EncoderMethod = "getAddrModeISOpValue";
136 let PrintMethod = "printThumbAddrModeImm5S4Operand";
137 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000138}
139
140// t_addrmode_is2 := reg + imm5 * 2
141//
142def t_addrmode_is2 : Operand<i32>,
143 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
144 let EncoderMethod = "getAddrModeISOpValue";
145 let PrintMethod = "printThumbAddrModeImm5S2Operand";
146 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000147}
148
149// t_addrmode_is1 := reg + imm5
150//
151def t_addrmode_is1 : Operand<i32>,
152 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
153 let EncoderMethod = "getAddrModeISOpValue";
154 let PrintMethod = "printThumbAddrModeImm5S1Operand";
155 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Evan Chenga8e29892007-01-19 07:51:42 +0000156}
157
158// t_addrmode_sp := sp + imm8 * 4
159//
160def t_addrmode_sp : Operand<i32>,
161 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbachd967cd02010-12-07 21:50:47 +0000162 let EncoderMethod = "getAddrModeThumbSPOpValue";
Evan Chenga8e29892007-01-19 07:51:42 +0000163 let PrintMethod = "printThumbAddrModeSPOperand";
Jakob Stoklund Olesenc5b7ef12010-01-13 00:43:06 +0000164 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Evan Chenga8e29892007-01-19 07:51:42 +0000165}
166
Bill Wendlingb8958b02010-12-08 01:57:09 +0000167// t_addrmode_pc := <label> => pc + imm8 * 4
168//
169def t_addrmode_pc : Operand<i32> {
170 let EncoderMethod = "getAddrModePCOpValue";
Bill Wendlingb8958b02010-12-08 01:57:09 +0000171}
172
Evan Chenga8e29892007-01-19 07:51:42 +0000173//===----------------------------------------------------------------------===//
174// Miscellaneous Instructions.
175//
176
Jim Grosbach4642ad32010-02-22 23:10:38 +0000177// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
178// from removing one half of the matched pairs. That breaks PEI, which assumes
179// these will always be in pairs, and asserts if it finds otherwise. Better way?
180let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng44bec522007-05-15 01:29:07 +0000181def tADJCALLSTACKUP :
Bill Wendlinga8981662010-11-19 22:02:18 +0000182 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
183 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
184 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng44bec522007-05-15 01:29:07 +0000185
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000186def tADJCALLSTACKDOWN :
Bill Wendlinga8981662010-11-19 22:02:18 +0000187 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
188 [(ARMcallseq_start imm:$amt)]>,
189 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000190}
Evan Cheng44bec522007-05-15 01:29:07 +0000191
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000192// T1Disassembly - A simple class to make encoding some disassembly patterns
193// easier and less verbose.
Bill Wendlinga46a4932010-11-29 22:15:03 +0000194class T1Disassembly<bits<2> op1, bits<8> op2>
195 : T1Encoding<0b101111> {
196 let Inst{9-8} = op1;
197 let Inst{7-0} = op2;
198}
199
Johnny Chenbd2c6232010-02-25 03:28:51 +0000200def tNOP : T1pI<(outs), (ins), NoItinerary, "nop", "",
201 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000202 T1Disassembly<0b11, 0x00>; // A8.6.110
Johnny Chenbd2c6232010-02-25 03:28:51 +0000203
Johnny Chend86d2692010-02-25 17:51:03 +0000204def tYIELD : T1pI<(outs), (ins), NoItinerary, "yield", "",
205 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000206 T1Disassembly<0b11, 0x10>; // A8.6.410
Johnny Chend86d2692010-02-25 17:51:03 +0000207
208def tWFE : T1pI<(outs), (ins), NoItinerary, "wfe", "",
209 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000210 T1Disassembly<0b11, 0x20>; // A8.6.408
Johnny Chend86d2692010-02-25 17:51:03 +0000211
212def tWFI : T1pI<(outs), (ins), NoItinerary, "wfi", "",
213 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000214 T1Disassembly<0b11, 0x30>; // A8.6.409
Johnny Chend86d2692010-02-25 17:51:03 +0000215
216def tSEV : T1pI<(outs), (ins), NoItinerary, "sev", "",
217 [/* For disassembly only; pattern left blank */]>,
Bill Wendlinga46a4932010-11-29 22:15:03 +0000218 T1Disassembly<0b11, 0x40>; // A8.6.157
219
220// The i32imm operand $val can be used by a debugger to store more information
221// about the breakpoint.
222def tBKPT : T1I<(outs), (ins i32imm:$val), NoItinerary, "bkpt\t$val",
223 [/* For disassembly only; pattern left blank */]>,
224 T1Disassembly<0b10, {?,?,?,?,?,?,?,?}> {
225 // A8.6.22
226 bits<8> val;
227 let Inst{7-0} = val;
228}
Johnny Chend86d2692010-02-25 17:51:03 +0000229
Jim Grosbach06322472011-07-22 17:52:23 +0000230def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
231 []>, T1Encoding<0b101101> {
232 bits<1> end;
Bill Wendling7d0affd2010-11-21 10:55:23 +0000233 // A8.6.156
Johnny Chend86d2692010-02-25 17:51:03 +0000234 let Inst{9-5} = 0b10010;
Bill Wendlinga8981662010-11-19 22:02:18 +0000235 let Inst{4} = 1;
Jim Grosbach06322472011-07-22 17:52:23 +0000236 let Inst{3} = end;
Bill Wendlinga8981662010-11-19 22:02:18 +0000237 let Inst{2-0} = 0b000;
Johnny Chend86d2692010-02-25 17:51:03 +0000238}
239
Johnny Chen93042d12010-03-02 18:14:57 +0000240// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000241def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
242 NoItinerary, "cps$imod $iflags",
243 [/* For disassembly only; pattern left blank */]>,
Bill Wendling849f2e32010-11-29 00:18:15 +0000244 T1Misc<0b0110011> {
245 // A8.6.38 & B6.1.1
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000246 bit imod;
247 bits<3> iflags;
248
249 let Inst{4} = imod;
250 let Inst{3} = 0;
251 let Inst{2-0} = iflags;
Bill Wendling849f2e32010-11-29 00:18:15 +0000252}
Johnny Chen93042d12010-03-02 18:14:57 +0000253
Evan Cheng35d6c412009-08-04 23:47:55 +0000254// For both thumb1 and thumb2.
Chris Lattnera4a3a5e2010-10-31 19:15:18 +0000255let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbacha3fbadf2010-09-30 19:53:58 +0000256def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendling0ae28e42010-11-19 22:37:33 +0000257 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000258 T1Special<{0,0,?,?}> {
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000259 // A8.6.6
Bill Wendling0ae28e42010-11-19 22:37:33 +0000260 bits<3> dst;
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000261 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendling0ae28e42010-11-19 22:37:33 +0000262 let Inst{2-0} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000263}
Evan Chenga8e29892007-01-19 07:51:42 +0000264
Bill Wendling0e45a5a2010-11-30 00:50:22 +0000265// PC relative add (ADR).
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000266def tADDrPCi : T1I<(outs tGPR:$dst), (ins t_imm_s4:$rhs), IIC_iALUi,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000267 "add\t$dst, pc, $rhs", []>,
268 T1Encoding<{1,0,1,0,0,?}> {
269 // A6.2 & A8.6.10
270 bits<3> dst;
271 bits<8> rhs;
272 let Inst{10-8} = dst;
273 let Inst{7-0} = rhs;
Jim Grosbach663e3392010-08-30 19:49:58 +0000274}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000275
Bill Wendling0ae28e42010-11-19 22:37:33 +0000276// ADD <Rd>, sp, #<imm8>
277// This is rematerializable, which is particularly useful for taking the
278// address of locals.
279let isReMaterializable = 1 in
280def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, t_imm_s4:$rhs), IIC_iALUi,
281 "add\t$dst, $sp, $rhs", []>,
282 T1Encoding<{1,0,1,0,1,?}> {
283 // A6.2 & A8.6.8
284 bits<3> dst;
285 bits<8> rhs;
286 let Inst{10-8} = dst;
287 let Inst{7-0} = rhs;
288}
289
290// ADD sp, sp, #<imm7>
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000291def tADDspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000292 "add\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000293 T1Misc<{0,0,0,0,0,?,?}> {
294 // A6.2.5 & A8.6.8
295 bits<7> rhs;
296 let Inst{6-0} = rhs;
297}
Evan Cheng7dcf4a82009-06-25 01:05:06 +0000298
Bill Wendling0ae28e42010-11-19 22:37:33 +0000299// SUB sp, sp, #<imm7>
300// FIXME: The encoding and the ASM string don't match up.
Evan Cheng2ef9c8a2009-11-19 06:57:41 +0000301def tSUBspi : TIt<(outs GPR:$dst), (ins GPR:$lhs, t_imm_s4:$rhs), IIC_iALUi,
Johnny Chend68e1192009-12-15 17:24:14 +0000302 "sub\t$dst, $rhs", []>,
Bill Wendling0ae28e42010-11-19 22:37:33 +0000303 T1Misc<{0,0,0,0,1,?,?}> {
304 // A6.2.5 & A8.6.214
305 bits<7> rhs;
306 let Inst{6-0} = rhs;
307}
Evan Cheng86198642009-08-07 00:34:42 +0000308
Bill Wendling0ae28e42010-11-19 22:37:33 +0000309// ADD <Rm>, sp
David Goodwin5d598aa2009-08-19 18:00:44 +0000310def tADDrSP : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000311 "add\t$dst, $rhs", []>,
312 T1Special<{0,0,?,?}> {
Bill Wendling0ae28e42010-11-19 22:37:33 +0000313 // A8.6.9 Encoding T1
314 bits<4> dst;
315 let Inst{7} = dst{3};
316 let Inst{6-3} = 0b1101;
317 let Inst{2-0} = dst{2-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000318}
Evan Cheng86198642009-08-07 00:34:42 +0000319
Bill Wendling0ae28e42010-11-19 22:37:33 +0000320// ADD sp, <Rm>
David Goodwin5d598aa2009-08-19 18:00:44 +0000321def tADDspr : TIt<(outs GPR:$dst), (ins GPR:$lhs, GPR:$rhs), IIC_iALUr,
Johnny Chend68e1192009-12-15 17:24:14 +0000322 "add\t$dst, $rhs", []>,
323 T1Special<{0,0,?,?}> {
324 // A8.6.9 Encoding T2
Bill Wendling0ae28e42010-11-19 22:37:33 +0000325 bits<4> dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000326 let Inst{7} = 1;
Bill Wendling0ae28e42010-11-19 22:37:33 +0000327 let Inst{6-3} = dst;
Johnny Chend68e1192009-12-15 17:24:14 +0000328 let Inst{2-0} = 0b101;
329}
Evan Cheng86198642009-08-07 00:34:42 +0000330
Evan Chenga8e29892007-01-19 07:51:42 +0000331//===----------------------------------------------------------------------===//
332// Control Flow Instructions.
333//
334
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000335// Indirect branches
336let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich421b1062011-05-26 03:41:12 +0000337 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
338 T1Special<{1,1,0,?}> {
339 // A6.2.3 & A8.6.25
340 bits<4> Rm;
341 let Inst{6-3} = Rm;
342 let Inst{2-0} = 0b000;
343 }
Bob Wilson8d4de5a2009-10-28 18:26:41 +0000344}
345
Jim Grosbachead77cd2011-07-08 21:04:05 +0000346let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson16884412011-07-13 23:22:26 +0000347 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Jim Grosbach25e6d482011-07-08 21:50:04 +0000348 [(ARMretflag)], (tBX LR, pred:$p)>;
Jim Grosbachead77cd2011-07-08 21:04:05 +0000349
350 // Alternative return instruction used by vararg functions.
Jim Grosbach25e6d482011-07-08 21:50:04 +0000351 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +0000352 2, IIC_Br, [],
Jim Grosbach25e6d482011-07-08 21:50:04 +0000353 (tBX GPR:$Rm, pred:$p)>;
Jim Grosbachead77cd2011-07-08 21:04:05 +0000354}
355
Bill Wendling0480e282010-12-01 02:36:55 +0000356// All calls clobber the non-callee saved registers. SP is marked as a use to
357// prevent stack-pointer assignments that appear immediately before calls from
358// potentially appearing dead.
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000359let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000360 // On non-Darwin platforms R9 is callee-saved.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000361 Defs = [R0, R1, R2, R3, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000362 Uses = [SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000363 // Also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000364 def tBL : TIx2<0b11110, 0b11, 1,
Owen Anderson0af0dc82011-07-18 18:50:52 +0000365 (outs), (ins pred:$p, t_bltarget:$func, variable_ops), IIC_Br,
366 "bl${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000367 [(ARMtcall tglobaladdr:$func)]>,
Bill Wendling534a5e42010-12-03 01:55:47 +0000368 Requires<[IsThumb, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000369 bits<21> func;
370 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000371 let Inst{13} = 1;
372 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000373 let Inst{10-0} = func{10-0};
Bill Wendling534a5e42010-12-03 01:55:47 +0000374 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000375
Evan Chengb6207242009-08-01 00:16:10 +0000376 // ARMv5T and above, also used for Thumb2
Johnny Chend68e1192009-12-15 17:24:14 +0000377 def tBLXi : TIx2<0b11110, 0b11, 0,
Owen Anderson0af0dc82011-07-18 18:50:52 +0000378 (outs), (ins pred:$p, t_blxtarget:$func, variable_ops), IIC_Br,
379 "blx${p}\t$func",
Johnny Chend68e1192009-12-15 17:24:14 +0000380 [(ARMcall tglobaladdr:$func)]>,
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000381 Requires<[IsThumb, HasV5T, IsNotDarwin]> {
Jim Grosbach662a8162010-12-06 23:57:07 +0000382 bits<21> func;
383 let Inst{25-16} = func{20-11};
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000384 let Inst{13} = 1;
385 let Inst{11} = 1;
Jim Grosbach662a8162010-12-06 23:57:07 +0000386 let Inst{10-1} = func{10-1};
387 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbach4fa102b2010-12-03 22:33:42 +0000388 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000389
Evan Chengb6207242009-08-01 00:16:10 +0000390 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000391 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func, variable_ops), IIC_Br,
392 "blx${p}\t$func",
Evan Chengb6207242009-08-01 00:16:10 +0000393 [(ARMtcall GPR:$func)]>,
Johnny Chend68e1192009-12-15 17:24:14 +0000394 Requires<[IsThumb, HasV5T, IsNotDarwin]>,
Owen Anderson18901d62011-05-11 17:00:48 +0000395 T1Special<{1,1,1,?}> { // A6.2.3 & A8.6.24;
396 bits<4> func;
397 let Inst{6-3} = func;
398 let Inst{2-0} = 0b000;
399 }
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000400
Lauro Ramos Venanciob8a93a42007-03-27 16:19:21 +0000401 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000402 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000403 4, IIC_Br,
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000404 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000405 Requires<[IsThumb, IsThumb1Only, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000406}
407
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000408let isCall = 1,
Evan Cheng1e0eab12010-11-29 22:43:27 +0000409 // On Darwin R9 is call-clobbered.
410 // R7 is marked as a use to prevent frame-pointer assignments from being
411 // moved above / below calls.
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +0000412 Defs = [R0, R1, R2, R3, R9, R12, LR, QQQQ0, QQQQ2, QQQQ3, CPSR, FPSCR],
Evan Cheng1e0eab12010-11-29 22:43:27 +0000413 Uses = [R7, SP] in {
Evan Chengb6207242009-08-01 00:16:10 +0000414 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000415 def tBLr9 : tPseudoExpand<(outs), (ins pred:$p, t_bltarget:$func, variable_ops),
416 4, IIC_Br, [(ARMtcall tglobaladdr:$func)],
417 (tBL pred:$p, t_bltarget:$func)>,
418 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000419
Evan Chengb6207242009-08-01 00:16:10 +0000420 // ARMv5T and above, also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000421 def tBLXi_r9 : tPseudoExpand<(outs), (ins pred:$p, t_blxtarget:$func, variable_ops),
422 4, IIC_Br, [(ARMcall tglobaladdr:$func)],
423 (tBLXi pred:$p, t_blxtarget:$func)>,
424 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000425
Evan Chengb6207242009-08-01 00:16:10 +0000426 // Also used for Thumb2
Owen Anderson0af0dc82011-07-18 18:50:52 +0000427 def tBLXr_r9 : tPseudoExpand<(outs), (ins pred:$p, GPR:$func, variable_ops),
428 2, IIC_Br, [(ARMtcall GPR:$func)],
429 (tBLXr pred:$p, GPR:$func)>,
430 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +0000431
432 // ARMv4T
Cameron Zwarichad70f6d2011-05-25 21:53:50 +0000433 def tBXr9_CALL : tPseudoInst<(outs), (ins tGPR:$func, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000434 4, IIC_Br,
Johnny Chend68e1192009-12-15 17:24:14 +0000435 [(ARMcall_nolink tGPR:$func)]>,
Jim Grosbach6797f892010-11-01 17:08:58 +0000436 Requires<[IsThumb, IsThumb1Only, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000437}
438
Bill Wendling0480e282010-12-01 02:36:55 +0000439let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
440 let isPredicable = 1 in
Jim Grosbache2467172010-12-10 18:21:33 +0000441 def tB : T1I<(outs), (ins t_brtarget:$target), IIC_Br,
Bill Wendling0480e282010-12-01 02:36:55 +0000442 "b\t$target", [(br bb:$target)]>,
Jim Grosbache2467172010-12-10 18:21:33 +0000443 T1Encoding<{1,1,1,0,0,?}> {
444 bits<11> target;
445 let Inst{10-0} = target;
446 }
Evan Chenga8e29892007-01-19 07:51:42 +0000447
Evan Cheng225dfe92007-01-30 01:13:37 +0000448 // Far jump
Jim Grosbach3efad8f2010-12-16 19:11:16 +0000449 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
450 // the clobber of LR.
Evan Cheng53c67c02009-08-07 05:45:07 +0000451 let Defs = [LR] in
Owen Anderson0af0dc82011-07-18 18:50:52 +0000452 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
453 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>;
Evan Cheng225dfe92007-01-30 01:13:37 +0000454
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000455 def tBR_JTr : tPseudoInst<(outs),
456 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
Owen Anderson16884412011-07-13 23:22:26 +0000457 0, IIC_Br,
Jim Grosbachf1aa47d2010-11-29 19:32:47 +0000458 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]> {
459 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chenbbc71b22009-12-16 02:32:54 +0000460 }
Evan Chengd85ac4d2007-01-27 02:29:45 +0000461}
462
Evan Chengc85e8322007-07-05 07:13:32 +0000463// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach0ede14f2009-03-27 23:06:27 +0000464// a two-value operand where a dag node expects two operands. :(
Evan Chengffbacca2007-07-21 00:34:19 +0000465let isBranch = 1, isTerminator = 1 in
Jim Grosbach01086452010-12-10 17:13:40 +0000466 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachceab5012010-12-04 00:20:40 +0000467 "b${p}\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +0000468 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Eric Christopher33281b22011-05-27 03:50:53 +0000469 T1BranchCond<{1,1,0,1}> {
Jim Grosbachceab5012010-12-04 00:20:40 +0000470 bits<4> p;
Jim Grosbach01086452010-12-10 17:13:40 +0000471 bits<8> target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000472 let Inst{11-8} = p;
Jim Grosbach01086452010-12-10 17:13:40 +0000473 let Inst{7-0} = target;
Jim Grosbachceab5012010-12-04 00:20:40 +0000474}
Evan Chenga8e29892007-01-19 07:51:42 +0000475
Evan Chengde17fb62009-10-31 23:46:45 +0000476// Compare and branch on zero / non-zero
477let isBranch = 1, isTerminator = 1 in {
Jim Grosbachcf6220a2010-12-09 19:01:46 +0000478 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
Bill Wendling12280382010-11-19 23:14:32 +0000479 "cbz\t$Rn, $target", []>,
480 T1Misc<{0,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000481 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000482 bits<6> target;
483 bits<3> Rn;
484 let Inst{9} = target{5};
485 let Inst{7-3} = target{4-0};
486 let Inst{2-0} = Rn;
487 }
Evan Chengde17fb62009-10-31 23:46:45 +0000488
Owen Anderson0bc8bbb2011-08-03 23:21:48 +0000489 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
490 "cbnz\t$Rn, $target", []>,
Bill Wendling12280382010-11-19 23:14:32 +0000491 T1Misc<{1,0,?,1,?,?,?}> {
Bill Wendling849f2e32010-11-29 00:18:15 +0000492 // A8.6.27
Bill Wendling12280382010-11-19 23:14:32 +0000493 bits<6> target;
494 bits<3> Rn;
495 let Inst{9} = target{5};
496 let Inst{7-3} = target{4-0};
497 let Inst{2-0} = Rn;
498 }
Evan Chengde17fb62009-10-31 23:46:45 +0000499}
500
Jim Grosbache36e21e2011-07-08 20:13:35 +0000501// Tail calls
502let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
503 // Darwin versions.
504 let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
505 Uses = [SP] in {
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000506 // tTAILJMPd: Darwin version uses a Thumb2 branch (no Thumb1 tail calls
507 // on Darwin), so it's in ARMInstrThumb2.td.
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000508 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000509 4, IIC_Br, [],
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000510 (tBX GPR:$dst, (ops 14, zero_reg))>,
511 Requires<[IsThumb, IsDarwin]>;
Jim Grosbache36e21e2011-07-08 20:13:35 +0000512 }
513 // Non-Darwin versions (the difference is R9).
514 let Defs = [R0, R1, R2, R3, R12, QQQQ0, QQQQ2, QQQQ3, PC],
515 Uses = [SP] in {
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000516 def tTAILJMPdND : tPseudoExpand<(outs), (ins t_brtarget:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000517 4, IIC_Br, [],
Jim Grosbachaf7f2d62011-07-08 20:32:21 +0000518 (tB t_brtarget:$dst)>,
519 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000520 def tTAILJMPrND : tPseudoExpand<(outs), (ins tcGPR:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +0000521 4, IIC_Br, [],
Jim Grosbach0b44aea2011-07-08 20:39:19 +0000522 (tBX GPR:$dst, (ops 14, zero_reg))>,
523 Requires<[IsThumb, IsNotDarwin]>;
Jim Grosbache36e21e2011-07-08 20:13:35 +0000524 }
525}
526
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
Jim Grosbached838482011-07-26 16:24:27 +0000532def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Bill Wendling6179c312010-11-20 00:53:35 +0000533 "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
Owen Anderson18901d62011-05-11 17:00:48 +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
Bill Wendlingb6faf652010-12-14 22:10:49 +0000551// Loads: reg/reg and reg/imm5
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000552let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingb6faf652010-12-14 22:10:49 +0000553multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
554 Operand AddrMode_r, Operand AddrMode_i,
555 AddrMode am, InstrItinClass itin_r,
556 InstrItinClass itin_i, string asm,
557 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000558 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000559 T1pILdStEncode<reg_opc,
560 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
561 am, itin_r, asm, "\t$Rt, $addr",
562 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000563 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000564 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
565 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
566 am, itin_i, asm, "\t$Rt, $addr",
567 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
568}
569// Stores: reg/reg and reg/imm5
570multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
571 Operand AddrMode_r, Operand AddrMode_i,
572 AddrMode am, InstrItinClass itin_r,
573 InstrItinClass itin_i, string asm,
574 PatFrag opnode> {
Bill Wendling345cdb62010-12-14 23:42:48 +0000575 def r : // reg/reg
Bill Wendlingb6faf652010-12-14 22:10:49 +0000576 T1pILdStEncode<reg_opc,
577 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
578 am, itin_r, asm, "\t$Rt, $addr",
579 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling345cdb62010-12-14 23:42:48 +0000580 def i : // reg/imm5
Bill Wendlingb6faf652010-12-14 22:10:49 +0000581 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
582 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
583 am, itin_i, asm, "\t$Rt, $addr",
584 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
585}
Bill Wendling6179c312010-11-20 00:53:35 +0000586
Bill Wendlingb6faf652010-12-14 22:10:49 +0000587// A8.6.57 & A8.6.60
588defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
589 t_addrmode_is4, AddrModeT1_4,
590 IIC_iLoad_r, IIC_iLoad_i, "ldr",
591 UnOpFrag<(load node:$Src)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000592
Bill Wendlingb6faf652010-12-14 22:10:49 +0000593// A8.6.64 & A8.6.61
594defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
595 t_addrmode_is1, AddrModeT1_1,
596 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
597 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000598
Bill Wendlingb6faf652010-12-14 22:10:49 +0000599// A8.6.76 & A8.6.73
600defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
601 t_addrmode_is2, AddrModeT1_2,
602 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
603 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000604
Evan Cheng2f297df2009-07-11 07:08:13 +0000605let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000606def tLDRSB : // A8.6.80
Bill Wendling40062fb2010-12-01 01:38:08 +0000607 T1pILdStEncode<0b011, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
608 AddrModeT1_1, IIC_iLoad_bh_r,
609 "ldrsb", "\t$dst, $addr",
610 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000611
Evan Cheng2f297df2009-07-11 07:08:13 +0000612let AddedComplexity = 10 in
Bill Wendling1fd374e2010-11-30 22:57:21 +0000613def tLDRSH : // A8.6.84
Bill Wendling40062fb2010-12-01 01:38:08 +0000614 T1pILdStEncode<0b111, (outs tGPR:$dst), (ins t_addrmode_rr:$addr),
615 AddrModeT1_2, IIC_iLoad_bh_r,
616 "ldrsh", "\t$dst, $addr",
617 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000618
Dan Gohman15511cf2008-12-03 18:15:48 +0000619let canFoldAsLoad = 1 in
Jim Grosbachd967cd02010-12-07 21:50:47 +0000620def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendlingdc381372010-12-15 23:31:24 +0000621 "ldr", "\t$Rt, $addr",
622 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000623 T1LdStSP<{1,?,?}> {
624 bits<3> Rt;
625 bits<8> addr;
626 let Inst{10-8} = Rt;
627 let Inst{7-0} = addr;
628}
Evan Cheng012f2d92007-01-24 08:53:17 +0000629
630// Load tconstpool
Evan Cheng7883fa92009-11-04 00:00:39 +0000631// FIXME: Use ldr.n to work around a Darwin assembler bug.
Owen Anderson91614ae2011-07-18 22:14:02 +0000632let canFoldAsLoad = 1, isReMaterializable = 1, isCodeGenOnly = 1 in
Bill Wendlingb8958b02010-12-08 01:57:09 +0000633def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Bill Wendling3f8c1102010-11-30 23:54:45 +0000634 "ldr", ".n\t$Rt, $addr",
635 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
636 T1Encoding<{0,1,0,0,1,?}> {
637 // A6.2 & A8.6.59
638 bits<3> Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000639 bits<8> addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000640 let Inst{10-8} = Rt;
Bill Wendlingb8958b02010-12-08 01:57:09 +0000641 let Inst{7-0} = addr;
Bill Wendling3f8c1102010-11-30 23:54:45 +0000642}
Evan Chengfa775d02007-03-19 07:20:03 +0000643
Johnny Chen597fa652011-04-22 19:12:43 +0000644// FIXME: Remove this entry when the above ldr.n workaround is fixed.
645// For disassembly use only.
646def tLDRpciDIS : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
647 "ldr", "\t$Rt, $addr",
648 [/* disassembly only */]>,
649 T1Encoding<{0,1,0,0,1,?}> {
650 // A6.2 & A8.6.59
651 bits<3> Rt;
652 bits<8> addr;
653 let Inst{10-8} = Rt;
654 let Inst{7-0} = addr;
655}
656
Bill Wendlingb6faf652010-12-14 22:10:49 +0000657// A8.6.194 & A8.6.192
658defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
659 t_addrmode_is4, AddrModeT1_4,
660 IIC_iStore_r, IIC_iStore_i, "str",
661 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Chenga8e29892007-01-19 07:51:42 +0000662
Bill Wendlingb6faf652010-12-14 22:10:49 +0000663// A8.6.197 & A8.6.195
664defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
665 t_addrmode_is1, AddrModeT1_1,
666 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
667 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000668
Bill Wendlingb6faf652010-12-14 22:10:49 +0000669// A8.6.207 & A8.6.205
670defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000671 t_addrmode_is2, AddrModeT1_2,
672 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
673 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendling1fd374e2010-11-30 22:57:21 +0000674
Evan Chenga8e29892007-01-19 07:51:42 +0000675
Jim Grosbachd967cd02010-12-07 21:50:47 +0000676def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendlingf4caf692010-12-14 03:36:38 +0000677 "str", "\t$Rt, $addr",
678 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbachd967cd02010-12-07 21:50:47 +0000679 T1LdStSP<{0,?,?}> {
680 bits<3> Rt;
681 bits<8> addr;
682 let Inst{10-8} = Rt;
683 let Inst{7-0} = addr;
684}
Evan Cheng8e59ea92007-02-07 00:06:56 +0000685
Evan Chenga8e29892007-01-19 07:51:42 +0000686//===----------------------------------------------------------------------===//
687// Load / store multiple Instructions.
688//
689
Bill Wendling6c470b82010-11-13 09:09:38 +0000690multiclass thumb_ldst_mult<string asm, InstrItinClass itin,
691 InstrItinClass itin_upd, bits<6> T1Enc,
Owen Anderson565a0362011-07-18 23:25:34 +0000692 bit L_bit, string baseOpc> {
Bill Wendling73fe34a2010-11-16 01:16:36 +0000693 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +0000694 T1I<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +0000695 itin, !strconcat(asm, "ia${p}\t$Rn, $regs"), []>,
Bill Wendling6179c312010-11-20 00:53:35 +0000696 T1Encoding<T1Enc> {
697 bits<3> Rn;
698 bits<8> regs;
699 let Inst{10-8} = Rn;
700 let Inst{7-0} = regs;
701 }
Owen Anderson565a0362011-07-18 23:25:34 +0000702
Bill Wendling73fe34a2010-11-16 01:16:36 +0000703 def IA_UPD :
Owen Anderson565a0362011-07-18 23:25:34 +0000704 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
705 "$Rn = $wb", itin_upd>,
706 PseudoInstExpansion<(!cast<Instruction>(!strconcat(baseOpc, "IA"))
707 GPR:$Rn, pred:$p, reglist:$regs)> {
708 let Size = 2;
709 let OutOperandList = (outs GPR:$wb);
710 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
711 let Pattern = [];
712 let isCodeGenOnly = 1;
713 let isPseudo = 1;
714 list<Predicate> Predicates = [IsThumb];
Bill Wendling6179c312010-11-20 00:53:35 +0000715 }
Bill Wendling6c470b82010-11-13 09:09:38 +0000716}
717
Bill Wendling73fe34a2010-11-16 01:16:36 +0000718// These require base address to be written back or one of the loaded regs.
Bill Wendlingddc918b2010-11-13 10:57:02 +0000719let neverHasSideEffects = 1 in {
720
721let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
722defm tLDM : thumb_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu,
Owen Anderson565a0362011-07-18 23:25:34 +0000723 {1,1,0,0,1,?}, 1, "tLDM">;
Bill Wendlingddc918b2010-11-13 10:57:02 +0000724
725let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
726defm tSTM : thumb_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu,
Owen Anderson565a0362011-07-18 23:25:34 +0000727 {1,1,0,0,0,?}, 0, "tSTM">;
Owen Anderson18901d62011-05-11 17:00:48 +0000728
Bill Wendlingddc918b2010-11-13 10:57:02 +0000729} // neverHasSideEffects
Evan Cheng4b322e52009-08-11 21:11:32 +0000730
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000731let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling602890d2010-11-19 01:33:10 +0000732def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000733 IIC_iPop,
Bill Wendling602890d2010-11-19 01:33:10 +0000734 "pop${p}\t$regs", []>,
735 T1Misc<{1,1,0,?,?,?,?}> {
736 bits<16> regs;
Bill Wendling602890d2010-11-19 01:33:10 +0000737 let Inst{8} = regs{15};
738 let Inst{7-0} = regs{7-0};
739}
Evan Cheng4b322e52009-08-11 21:11:32 +0000740
Evan Cheng0d92f5f2009-10-01 08:22:27 +0000741let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendling6179c312010-11-20 00:53:35 +0000742def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +0000743 IIC_iStore_m,
Bill Wendling6179c312010-11-20 00:53:35 +0000744 "push${p}\t$regs", []>,
745 T1Misc<{0,1,0,?,?,?,?}> {
746 bits<16> regs;
747 let Inst{8} = regs{14};
748 let Inst{7-0} = regs{7-0};
749}
Evan Chenga8e29892007-01-19 07:51:42 +0000750
751//===----------------------------------------------------------------------===//
752// Arithmetic Instructions.
753//
754
Bill Wendling1d045ee2010-12-01 02:28:08 +0000755// Helper classes for encoding T1pI patterns:
756class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
757 string opc, string asm, list<dag> pattern>
758 : T1pI<oops, iops, itin, opc, asm, pattern>,
759 T1DataProcessing<opA> {
760 bits<3> Rm;
761 bits<3> Rn;
762 let Inst{5-3} = Rm;
763 let Inst{2-0} = Rn;
764}
765class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
766 string opc, string asm, list<dag> pattern>
767 : T1pI<oops, iops, itin, opc, asm, pattern>,
768 T1Misc<opA> {
769 bits<3> Rm;
770 bits<3> Rd;
771 let Inst{5-3} = Rm;
772 let Inst{2-0} = Rd;
773}
774
Bill Wendling76f4e102010-12-01 01:20:15 +0000775// Helper classes for encoding T1sI patterns:
776class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
777 string opc, string asm, list<dag> pattern>
778 : T1sI<oops, iops, itin, opc, asm, pattern>,
779 T1DataProcessing<opA> {
780 bits<3> Rd;
781 bits<3> Rn;
782 let Inst{5-3} = Rn;
783 let Inst{2-0} = Rd;
784}
785class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
786 string opc, string asm, list<dag> pattern>
787 : T1sI<oops, iops, itin, opc, asm, pattern>,
788 T1General<opA> {
789 bits<3> Rm;
790 bits<3> Rn;
791 bits<3> Rd;
792 let Inst{8-6} = Rm;
793 let Inst{5-3} = Rn;
794 let Inst{2-0} = Rd;
795}
796class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
797 string opc, string asm, list<dag> pattern>
798 : T1sI<oops, iops, itin, opc, asm, pattern>,
799 T1General<opA> {
800 bits<3> Rd;
801 bits<3> Rm;
802 let Inst{5-3} = Rm;
803 let Inst{2-0} = Rd;
804}
805
806// Helper classes for encoding T1sIt patterns:
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000807class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
808 string opc, string asm, list<dag> pattern>
809 : T1sIt<oops, iops, itin, opc, asm, pattern>,
810 T1DataProcessing<opA> {
Bill Wendling3f8c1102010-11-30 23:54:45 +0000811 bits<3> Rdn;
812 bits<3> Rm;
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000813 let Inst{5-3} = Rm;
814 let Inst{2-0} = Rdn;
Bill Wendling95a6d172010-11-20 01:00:29 +0000815}
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000816class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
817 string opc, string asm, list<dag> pattern>
818 : T1sIt<oops, iops, itin, opc, asm, pattern>,
819 T1General<opA> {
820 bits<3> Rdn;
821 bits<8> imm8;
822 let Inst{10-8} = Rdn;
823 let Inst{7-0} = imm8;
824}
825
826// Add with carry register
827let isCommutable = 1, Uses = [CPSR] in
828def tADC : // A8.6.2
829 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
830 "adc", "\t$Rdn, $Rm",
831 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng53d7dba2007-01-27 00:07:15 +0000832
David Goodwinc9ee1182009-06-25 22:49:55 +0000833// Add immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000834def tADDi3 : // A8.6.4 T1
Jim Grosbachf921c0fe2011-06-13 22:54:22 +0000835 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
836 IIC_iALUi,
Bill Wendling76f4e102010-12-01 01:20:15 +0000837 "add", "\t$Rd, $Rm, $imm3",
838 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]> {
Bill Wendling95a6d172010-11-20 01:00:29 +0000839 bits<3> imm3;
840 let Inst{8-6} = imm3;
Bill Wendling95a6d172010-11-20 01:00:29 +0000841}
Evan Chenga8e29892007-01-19 07:51:42 +0000842
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000843def tADDi8 : // A8.6.4 T2
844 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
845 IIC_iALUi,
846 "add", "\t$Rdn, $imm8",
847 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000848
David Goodwinc9ee1182009-06-25 22:49:55 +0000849// Add register
Evan Cheng446c4282009-07-11 06:43:01 +0000850let isCommutable = 1 in
Bill Wendling76f4e102010-12-01 01:20:15 +0000851def tADDrr : // A8.6.6 T1
852 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
853 IIC_iALUr,
854 "add", "\t$Rd, $Rn, $Rm",
855 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000856
Evan Chengcd799b92009-06-12 20:46:18 +0000857let neverHasSideEffects = 1 in
Bill Wendling0b424dc2010-12-01 01:32:02 +0000858def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
859 "add", "\t$Rdn, $Rm", []>,
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000860 T1Special<{0,0,?,?}> {
861 // A8.6.6 T2
Bill Wendling0b424dc2010-12-01 01:32:02 +0000862 bits<4> Rdn;
863 bits<4> Rm;
864 let Inst{7} = Rdn{3};
865 let Inst{6-3} = Rm;
866 let Inst{2-0} = Rdn{2-0};
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000867}
Evan Chenga8e29892007-01-19 07:51:42 +0000868
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000869// AND register
Evan Cheng446c4282009-07-11 06:43:01 +0000870let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000871def tAND : // A8.6.12
872 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
873 IIC_iBITr,
874 "and", "\t$Rdn, $Rm",
875 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000876
David Goodwinc9ee1182009-06-25 22:49:55 +0000877// ASR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000878def tASRri : // A8.6.14
879 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
880 IIC_iMOVsi,
881 "asr", "\t$Rd, $Rm, $imm5",
882 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000883 bits<5> imm5;
884 let Inst{10-6} = imm5;
Bill Wendlinga09cc2b2010-11-20 01:18:47 +0000885}
Evan Chenga8e29892007-01-19 07:51:42 +0000886
David Goodwinc9ee1182009-06-25 22:49:55 +0000887// ASR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000888def tASRrr : // A8.6.15
889 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
890 IIC_iMOVsr,
891 "asr", "\t$Rdn, $Rm",
892 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000893
David Goodwinc9ee1182009-06-25 22:49:55 +0000894// BIC register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000895def tBIC : // A8.6.20
896 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
897 IIC_iBITr,
898 "bic", "\t$Rdn, $Rm",
899 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000900
David Goodwinc9ee1182009-06-25 22:49:55 +0000901// CMN register
Gabor Greiff7d10f52010-09-14 22:00:50 +0000902let isCompare = 1, Defs = [CPSR] in {
Jim Grosbachd5d2bae2010-01-22 00:08:13 +0000903//FIXME: Disable CMN, as CCodes are backwards from compare expectations
904// Compare-to-zero still works out, just not the relationals
Bill Wendling0480e282010-12-01 02:36:55 +0000905//def tCMN : // A8.6.33
906// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
907// IIC_iCMPr,
908// "cmn", "\t$lhs, $rhs",
909// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling1d045ee2010-12-01 02:28:08 +0000910
911def tCMNz : // A8.6.33
912 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
913 IIC_iCMPr,
914 "cmn", "\t$Rn, $Rm",
915 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>;
916
917} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000918
David Goodwinc9ee1182009-06-25 22:49:55 +0000919// CMP immediate
Gabor Greiff7d10f52010-09-14 22:00:50 +0000920let isCompare = 1, Defs = [CPSR] in {
Bill Wendling5cc88a22010-11-20 22:52:33 +0000921def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, i32imm:$imm8), IIC_iCMPi,
922 "cmp", "\t$Rn, $imm8",
923 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
924 T1General<{1,0,1,?,?}> {
925 // A8.6.35
926 bits<3> Rn;
927 bits<8> imm8;
928 let Inst{10-8} = Rn;
929 let Inst{7-0} = imm8;
930}
931
David Goodwinc9ee1182009-06-25 22:49:55 +0000932// CMP register
Bill Wendling1d045ee2010-12-01 02:28:08 +0000933def tCMPr : // A8.6.36 T1
934 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
935 IIC_iCMPr,
936 "cmp", "\t$Rn, $Rm",
937 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>;
938
Bill Wendling849f2e32010-11-29 00:18:15 +0000939def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
940 "cmp", "\t$Rn, $Rm", []>,
941 T1Special<{0,1,?,?}> {
942 // A8.6.36 T2
943 bits<4> Rm;
944 bits<4> Rn;
945 let Inst{7} = Rn{3};
946 let Inst{6-3} = Rm;
947 let Inst{2-0} = Rn{2-0};
948}
Bill Wendling5cc88a22010-11-20 22:52:33 +0000949} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio99966632007-04-02 01:30:03 +0000950
Evan Chenga8e29892007-01-19 07:51:42 +0000951
David Goodwinc9ee1182009-06-25 22:49:55 +0000952// XOR register
Evan Cheng446c4282009-07-11 06:43:01 +0000953let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000954def tEOR : // A8.6.45
955 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
956 IIC_iBITr,
957 "eor", "\t$Rdn, $Rm",
958 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000959
David Goodwinc9ee1182009-06-25 22:49:55 +0000960// LSL immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000961def tLSLri : // A8.6.88
962 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
963 IIC_iMOVsi,
964 "lsl", "\t$Rd, $Rm, $imm5",
965 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]> {
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000966 bits<5> imm5;
967 let Inst{10-6} = imm5;
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000968}
Evan Chenga8e29892007-01-19 07:51:42 +0000969
David Goodwinc9ee1182009-06-25 22:49:55 +0000970// LSL register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000971def tLSLrr : // A8.6.89
972 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
973 IIC_iMOVsr,
974 "lsl", "\t$Rdn, $Rm",
975 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000976
David Goodwinc9ee1182009-06-25 22:49:55 +0000977// LSR immediate
Bill Wendling76f4e102010-12-01 01:20:15 +0000978def tLSRri : // A8.6.90
979 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm5),
980 IIC_iMOVsi,
981 "lsr", "\t$Rd, $Rm, $imm5",
982 [(set tGPR:$Rd, (srl 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// LSR register
Bill Wendlinga5a42d92010-12-01 00:48:44 +0000988def tLSRrr : // A8.6.91
989 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
990 IIC_iMOVsr,
991 "lsr", "\t$Rdn, $Rm",
992 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +0000993
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000994// Move register
Evan Chengc4af4632010-11-17 20:13:28 +0000995let isMoveImm = 1 in
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000996def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendlingdcf0a472010-11-21 11:49:36 +0000997 "mov", "\t$Rd, $imm8",
998 [(set tGPR:$Rd, imm0_255:$imm8)]>,
999 T1General<{1,0,0,?,?}> {
1000 // A8.6.96
1001 bits<3> Rd;
1002 bits<8> imm8;
1003 let Inst{10-8} = Rd;
1004 let Inst{7-0} = imm8;
1005}
Evan Chenga8e29892007-01-19 07:51:42 +00001006
Jim Grosbachefeedce2011-07-01 17:14:11 +00001007// A7-73: MOV(2) - mov setting flag.
Evan Chenga8e29892007-01-19 07:51:42 +00001008
Evan Chengcd799b92009-06-12 20:46:18 +00001009let neverHasSideEffects = 1 in {
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001010def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson16884412011-07-13 23:22:26 +00001011 2, IIC_iMOVr,
Jim Grosbach63b46fa2011-06-30 22:10:46 +00001012 "mov", "\t$Rd, $Rm", "", []>,
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001013 T1Special<{1,0,?,?}> {
Bill Wendling534a5e42010-12-03 01:55:47 +00001014 // A8.6.97
1015 bits<4> Rd;
1016 bits<4> Rm;
Jim Grosbach2a7b41b2011-06-30 23:38:17 +00001017 let Inst{7} = Rd{3};
1018 let Inst{6-3} = Rm;
Bill Wendling534a5e42010-12-03 01:55:47 +00001019 let Inst{2-0} = Rd{2-0};
1020}
Evan Cheng446c4282009-07-11 06:43:01 +00001021let Defs = [CPSR] in
Bill Wendling534a5e42010-12-03 01:55:47 +00001022def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
1023 "movs\t$Rd, $Rm", []>, Encoding16 {
1024 // A8.6.97
1025 bits<3> Rd;
1026 bits<3> Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00001027 let Inst{15-6} = 0b0000000000;
Bill Wendling534a5e42010-12-03 01:55:47 +00001028 let Inst{5-3} = Rm;
1029 let Inst{2-0} = Rd;
Johnny Chend68e1192009-12-15 17:24:14 +00001030}
Evan Chengcd799b92009-06-12 20:46:18 +00001031} // neverHasSideEffects
Evan Chenga8e29892007-01-19 07:51:42 +00001032
Bill Wendling0480e282010-12-01 02:36:55 +00001033// Multiply register
Evan Cheng446c4282009-07-11 06:43:01 +00001034let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001035def tMUL : // A8.6.105 T1
1036 T1sItDPEncode<0b1101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1037 IIC_iMUL32,
1038 "mul", "\t$Rdn, $Rm, $Rdn",
1039 [(set tGPR:$Rdn, (mul tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001040
Bill Wendling76f4e102010-12-01 01:20:15 +00001041// Move inverse register
1042def tMVN : // A8.6.107
1043 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1044 "mvn", "\t$Rd, $Rn",
1045 [(set tGPR:$Rd, (not tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001046
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001047// Bitwise or register
Evan Cheng446c4282009-07-11 06:43:01 +00001048let isCommutable = 1 in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001049def tORR : // A8.6.114
1050 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1051 IIC_iBITr,
1052 "orr", "\t$Rdn, $Rm",
1053 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001054
Bill Wendlingdcf0a472010-11-21 11:49:36 +00001055// Swaps
Bill Wendling1d045ee2010-12-01 02:28:08 +00001056def tREV : // A8.6.134
1057 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1058 IIC_iUNAr,
1059 "rev", "\t$Rd, $Rm",
1060 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
1061 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001062
Bill Wendling1d045ee2010-12-01 02:28:08 +00001063def tREV16 : // A8.6.135
1064 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1065 IIC_iUNAr,
1066 "rev16", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001067 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001068 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001069
Bill Wendling1d045ee2010-12-01 02:28:08 +00001070def tREVSH : // A8.6.136
1071 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1072 IIC_iUNAr,
1073 "revsh", "\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00001074 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Bill Wendling1d045ee2010-12-01 02:28:08 +00001075 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001076
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001077// Rotate right register
1078def tROR : // A8.6.139
1079 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1080 IIC_iMOVsr,
1081 "ror", "\t$Rdn, $Rm",
1082 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>;
Evan Cheng446c4282009-07-11 06:43:01 +00001083
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001084// Negate register
Bill Wendling76f4e102010-12-01 01:20:15 +00001085def tRSB : // A8.6.141
1086 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1087 IIC_iALUi,
1088 "rsb", "\t$Rd, $Rn, #0",
1089 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001090
David Goodwinc9ee1182009-06-25 22:49:55 +00001091// Subtract with carry register
Evan Cheng446c4282009-07-11 06:43:01 +00001092let Uses = [CPSR] in
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001093def tSBC : // A8.6.151
1094 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1095 IIC_iALUr,
1096 "sbc", "\t$Rdn, $Rm",
1097 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001098
David Goodwinc9ee1182009-06-25 22:49:55 +00001099// Subtract immediate
Bill Wendling76f4e102010-12-01 01:20:15 +00001100def tSUBi3 : // A8.6.210 T1
1101 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, i32imm:$imm3),
1102 IIC_iALUi,
1103 "sub", "\t$Rd, $Rm, $imm3",
1104 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]> {
Bill Wendling5cbbf682010-11-29 01:00:43 +00001105 bits<3> imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001106 let Inst{8-6} = imm3;
Bill Wendling5cbbf682010-11-29 01:00:43 +00001107}
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001108
Bill Wendlinga5a42d92010-12-01 00:48:44 +00001109def tSUBi8 : // A8.6.210 T2
1110 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn), (ins tGPR:$Rn, i32imm:$imm8),
1111 IIC_iALUi,
1112 "sub", "\t$Rdn, $imm8",
1113 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001114
Bill Wendling76f4e102010-12-01 01:20:15 +00001115// Subtract register
1116def tSUBrr : // A8.6.212
1117 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1118 IIC_iALUr,
1119 "sub", "\t$Rd, $Rn, $Rm",
1120 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001121
1122// TODO: A7-96: STMIA - store multiple.
Evan Chenga8e29892007-01-19 07:51:42 +00001123
Bill Wendling76f4e102010-12-01 01:20:15 +00001124// Sign-extend byte
Bill Wendling1d045ee2010-12-01 02:28:08 +00001125def tSXTB : // A8.6.222
1126 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1127 IIC_iUNAr,
1128 "sxtb", "\t$Rd, $Rm",
1129 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
1130 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001131
Bill Wendling1d045ee2010-12-01 02:28:08 +00001132// Sign-extend short
1133def tSXTH : // A8.6.224
1134 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1135 IIC_iUNAr,
1136 "sxth", "\t$Rd, $Rm",
1137 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
1138 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001139
Bill Wendling1d045ee2010-12-01 02:28:08 +00001140// Test
Gabor Greif007248b2010-09-14 20:47:43 +00001141let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling1d045ee2010-12-01 02:28:08 +00001142def tTST : // A8.6.230
1143 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1144 "tst", "\t$Rn, $Rm",
1145 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001146
Bill Wendling1d045ee2010-12-01 02:28:08 +00001147// Zero-extend byte
1148def tUXTB : // A8.6.262
1149 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1150 IIC_iUNAr,
1151 "uxtb", "\t$Rd, $Rm",
1152 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
1153 Requires<[IsThumb, IsThumb1Only, HasV6]>;
David Goodwinc9ee1182009-06-25 22:49:55 +00001154
Bill Wendling1d045ee2010-12-01 02:28:08 +00001155// Zero-extend short
1156def tUXTH : // A8.6.264
1157 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1158 IIC_iUNAr,
1159 "uxth", "\t$Rd, $Rm",
1160 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
1161 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001162
Jim Grosbach80dc1162010-02-16 21:23:02 +00001163// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman533297b2009-10-29 18:10:34 +00001164// Expanded after instruction selection into a branch sequence.
1165let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Cheng007ea272009-08-12 05:17:19 +00001166 def tMOVCCr_pseudo :
Evan Chengc9721652009-08-12 02:03:03 +00001167 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Jim Grosbach99594eb2010-11-18 01:38:26 +00001168 NoItinerary,
Evan Chengc9721652009-08-12 02:03:03 +00001169 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001170
1171// tLEApcrel - Load a pc-relative address into a register without offending the
1172// assembler.
Jim Grosbachd40963c2010-12-14 22:28:03 +00001173
1174def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
1175 IIC_iALUi, "adr{$p}\t$Rd, #$addr", []>,
1176 T1Encoding<{1,0,1,0,0,?}> {
Bill Wendling67077412010-11-30 00:18:30 +00001177 bits<3> Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001178 bits<8> addr;
Bill Wendling67077412010-11-30 00:18:30 +00001179 let Inst{10-8} = Rd;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001180 let Inst{7-0} = addr;
Bill Wendling67077412010-11-30 00:18:30 +00001181}
Evan Chenga8e29892007-01-19 07:51:42 +00001182
Jim Grosbachd40963c2010-12-14 22:28:03 +00001183let neverHasSideEffects = 1, isReMaterializable = 1 in
1184def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001185 2, IIC_iALUi, []>;
Jim Grosbachd40963c2010-12-14 22:28:03 +00001186
1187def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1188 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001189 2, IIC_iALUi, []>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001190
Evan Chenga8e29892007-01-19 07:51:42 +00001191//===----------------------------------------------------------------------===//
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001192// TLS Instructions
1193//
1194
1195// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbachff97eb02011-06-30 19:38:01 +00001196// This is a pseudo inst so that we can get the encoding right,
1197// complete with fixup for the aeabi_read_tp function.
1198let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson16884412011-07-13 23:22:26 +00001199def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Jim Grosbachff97eb02011-06-30 19:38:01 +00001200 [(set R0, ARMthread_pointer)]>;
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001201
Bill Wendling0480e282010-12-01 02:36:55 +00001202//===----------------------------------------------------------------------===//
Jim Grosbachd1228742009-12-01 18:10:36 +00001203// SJLJ Exception handling intrinsics
Owen Anderson18901d62011-05-11 17:00:48 +00001204//
Bill Wendling0480e282010-12-01 02:36:55 +00001205
1206// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1207// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1208// from some other function to get here, and we're using the stack frame for the
1209// containing function to save/restore registers, we can't keep anything live in
1210// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner7a2bdde2011-04-15 05:18:47 +00001211// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling0480e282010-12-01 02:36:55 +00001212// registers except for our own input by listing the relevant registers in
1213// Defs. By doing so, we also cause the prologue/epilogue code to actively
1214// preserve all of the callee-saved resgisters, which is exactly what we want.
1215// $val is a scratch register for our use.
Andrew Tricka1099f12011-06-07 00:08:49 +00001216let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001217 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in
1218def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson16884412011-07-13 23:22:26 +00001219 AddrModeNone, 0, NoItinerary, "","",
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001220 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001221
1222// FIXME: Non-Darwin version(s)
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00001223let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001224 Defs = [ R7, LR, SP ] in
Jim Grosbach5eb19512010-05-22 01:06:18 +00001225def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson16884412011-07-13 23:22:26 +00001226 AddrModeNone, 0, IndexModeNone,
Bill Wendling0e45a5a2010-11-30 00:50:22 +00001227 Pseudo, NoItinerary, "", "",
1228 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1229 Requires<[IsThumb, IsDarwin]>;
Jim Grosbach5eb19512010-05-22 01:06:18 +00001230
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +00001231//===----------------------------------------------------------------------===//
Evan Chenga8e29892007-01-19 07:51:42 +00001232// Non-Instruction Patterns
1233//
1234
Jim Grosbach97a884d2010-12-07 20:41:06 +00001235// Comparisons
1236def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1237 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1238def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1239 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1240
Evan Cheng892837a2009-07-10 02:09:04 +00001241// Add with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001242def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1243 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1244def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng89d177f2009-08-20 17:01:04 +00001245 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwinc9d138f2009-07-27 19:59:26 +00001246def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1247 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001248
1249// Subtract with carry
David Goodwinc9d138f2009-07-27 19:59:26 +00001250def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1251 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1252def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1253 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1254def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1255 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng892837a2009-07-10 02:09:04 +00001256
Evan Chenga8e29892007-01-19 07:51:42 +00001257// ConstantPool, GlobalAddress
David Goodwinc9d138f2009-07-27 19:59:26 +00001258def : T1Pat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
1259def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Chenga8e29892007-01-19 07:51:42 +00001260
Evan Chengd85ac4d2007-01-27 02:29:45 +00001261// JumpTable
David Goodwinc9d138f2009-07-27 19:59:26 +00001262def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1263 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Chengd85ac4d2007-01-27 02:29:45 +00001264
Evan Chenga8e29892007-01-19 07:51:42 +00001265// Direct calls
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001266def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001267 Requires<[IsThumb, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001268def : T1Pat<(ARMtcall texternalsym:$func), (tBLr9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001269 Requires<[IsThumb, IsDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001270
1271def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001272 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
Evan Cheng20a2a0a2009-07-29 21:26:42 +00001273def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi_r9 texternalsym:$func)>,
Evan Chengb6207242009-08-01 00:16:10 +00001274 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001275
1276// Indirect calls to ARM routines
Evan Chengb6207242009-08-01 00:16:10 +00001277def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
1278 Requires<[IsThumb, HasV5T, IsNotDarwin]>;
1279def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr_r9 GPR:$dst)>,
1280 Requires<[IsThumb, HasV5T, IsDarwin]>;
Evan Chenga8e29892007-01-19 07:51:42 +00001281
1282// zextload i1 -> zextload i8
Bill Wendlingf4caf692010-12-14 03:36:38 +00001283def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1284 (tLDRBr t_addrmode_rrs1:$addr)>;
1285def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1286 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach0ede14f2009-03-27 23:06:27 +00001287
Evan Chengb60c02e2007-01-26 19:13:16 +00001288// extload -> zextload
Bill Wendlingf4caf692010-12-14 03:36:38 +00001289def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1290def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1291def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1292def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1293def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1294def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengb60c02e2007-01-26 19:13:16 +00001295
Evan Cheng0e87e232009-08-28 00:31:43 +00001296// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng2f297df2009-07-11 07:08:13 +00001297// ldr{b|h} + sxt{b|h} instead.
Bill Wendling415af342010-12-15 00:58:57 +00001298def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1299 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1300 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001301def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1302 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001303 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling415af342010-12-15 00:58:57 +00001304def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1305 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1306 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001307def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1308 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001309 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001310
Bill Wendlingf4caf692010-12-14 03:36:38 +00001311def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1312 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling415af342010-12-15 00:58:57 +00001313def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1314 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1315def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1316 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1317def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1318 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng2f297df2009-07-11 07:08:13 +00001319
Evan Chenga8e29892007-01-19 07:51:42 +00001320// Large immediate handling.
1321
1322// Two piece imms.
Evan Cheng9cb9e672009-06-27 02:26:13 +00001323def : T1Pat<(i32 thumb_immshifted:$src),
1324 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1325 (thumb_immshifted_shamt imm:$src))>;
Evan Chenga8e29892007-01-19 07:51:42 +00001326
Evan Cheng9cb9e672009-06-27 02:26:13 +00001327def : T1Pat<(i32 imm0_255_comp:$src),
1328 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Chengb9803a82009-11-06 23:52:48 +00001329
1330// Pseudo instruction that combines ldr from constpool and add pc. This should
1331// be expanded into two instructions late to allow if-conversion and
1332// scheduling.
1333let isReMaterializable = 1 in
1334def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling0480e282010-12-01 02:36:55 +00001335 NoItinerary,
Evan Chengb9803a82009-11-06 23:52:48 +00001336 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1337 imm:$cp))]>,
Jim Grosbach6797f892010-11-01 17:08:58 +00001338 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach53e3fc42011-07-08 17:40:42 +00001339
1340// Pseudo-instruction for merged POP and return.
1341// FIXME: remove when we have a way to marking a MI with these properties.
1342let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1343 hasExtraDefRegAllocReq = 1 in
1344def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +00001345 2, IIC_iPop_Br, [],
Jim Grosbach53e3fc42011-07-08 17:40:42 +00001346 (tPOP pred:$p, reglist:$regs)>;
1347
Jim Grosbachaa8d1b82011-07-08 22:25:23 +00001348// Indirect branch using "mov pc, $Rm"
1349let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach7e61a312011-07-08 22:33:49 +00001350 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001351 2, IIC_Br, [(brind GPR:$Rm)],
Jim Grosbach7e61a312011-07-08 22:33:49 +00001352 (tMOVr PC, GPR:$Rm, pred:$p)>;
Jim Grosbachaa8d1b82011-07-08 22:25:23 +00001353}