blob: ed72d24a8112f07373524b5be8cf4a20de7f1809 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- ARMInstrThumb.td - Thumb support for ARM -----------*- tablegen -*-===//
Evan Cheng10043e22007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Cheng10043e22007-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 Lattner2a0a3b42010-12-23 18:28:41 +000019 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
Chris Lattner04336992010-03-19 05:33:51 +000020 SDNPVariadic]>;
Evan Cheng10043e22007-01-19 07:51:42 +000021
Jim Grosbach46dd4132011-08-17 21:51:27 +000022def imm_sr_XFORM: SDNodeXForm<imm, [{
23 unsigned Imm = N->getZExtValue();
24 return CurDAG->getTargetConstant((Imm == 32 ? 0 : Imm), MVT::i32);
25}]>;
26def ThumbSRImmAsmOperand: AsmOperandClass { let Name = "ImmThumbSR"; }
27def imm_sr : Operand<i32>, PatLeaf<(imm), [{
28 uint64_t Imm = N->getZExtValue();
Owen Andersonc4030382011-08-08 20:42:17 +000029 return Imm > 0 && Imm <= 32;
Jim Grosbach46dd4132011-08-17 21:51:27 +000030}], imm_sr_XFORM> {
31 let PrintMethod = "printThumbSRImm";
32 let ParserMatchClass = ThumbSRImmAsmOperand;
Owen Andersonc4030382011-08-08 20:42:17 +000033}
34
Evan Cheng10043e22007-01-19 07:51:42 +000035def imm_comp_XFORM : SDNodeXForm<imm, [{
Owen Anderson9f944592009-08-11 20:47:22 +000036 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000037}]>;
38
Evan Cheng10043e22007-01-19 07:51:42 +000039def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000040 return (uint32_t)-N->getZExtValue() < 8;
Evan Cheng10043e22007-01-19 07:51:42 +000041}], imm_neg_XFORM>;
42
Evan Cheng10043e22007-01-19 07:51:42 +000043def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000044 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000045}]>;
46
Eric Christophera98cd222011-04-28 05:49:04 +000047def imm8_255 : ImmLeaf<i32, [{
48 return Imm >= 8 && Imm < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000049}]>;
50def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000051 unsigned Val = -N->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +000052 return Val >= 8 && Val < 256;
53}], imm_neg_XFORM>;
54
Bill Wendling9c258942010-12-01 02:36:55 +000055// Break imm's up into two pieces: an immediate + a left shift. This uses
56// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
57// to get the val/shift pieces.
Evan Cheng10043e22007-01-19 07:51:42 +000058def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000059 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Cheng10043e22007-01-19 07:51:42 +000060}]>;
61
62def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000063 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Owen Anderson9f944592009-08-11 20:47:22 +000064 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000065}]>;
66
67def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000068 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Owen Anderson9f944592009-08-11 20:47:22 +000069 return CurDAG->getTargetConstant(V, MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000070}]>;
71
Evan Chengb1852592009-11-19 06:57:41 +000072// Scaled 4 immediate.
Jim Grosbach0a0b3072011-08-24 21:22:15 +000073def t_imm0_1020s4_asmoperand: AsmOperandClass { let Name = "Imm0_1020s4"; }
74def t_imm0_1020s4 : Operand<i32> {
Evan Chengb1852592009-11-19 06:57:41 +000075 let PrintMethod = "printThumbS4ImmOperand";
Jim Grosbach0a0b3072011-08-24 21:22:15 +000076 let ParserMatchClass = t_imm0_1020s4_asmoperand;
77 let OperandType = "OPERAND_IMMEDIATE";
78}
79
80def t_imm0_508s4_asmoperand: AsmOperandClass { let Name = "Imm0_508s4"; }
81def t_imm0_508s4 : Operand<i32> {
82 let PrintMethod = "printThumbS4ImmOperand";
83 let ParserMatchClass = t_imm0_508s4_asmoperand;
Benjamin Kramer3ceac212011-07-14 21:47:24 +000084 let OperandType = "OPERAND_IMMEDIATE";
Evan Chengb1852592009-11-19 06:57:41 +000085}
Jim Grosbach930f2f62012-04-05 20:57:13 +000086// Alias use only, so no printer is necessary.
87def t_imm0_508s4_neg_asmoperand: AsmOperandClass { let Name = "Imm0_508s4Neg"; }
88def t_imm0_508s4_neg : Operand<i32> {
89 let ParserMatchClass = t_imm0_508s4_neg_asmoperand;
90 let OperandType = "OPERAND_IMMEDIATE";
91}
Evan Chengb1852592009-11-19 06:57:41 +000092
Evan Cheng10043e22007-01-19 07:51:42 +000093// Define Thumb specific addressing modes.
94
Mihai Popad36cbaa2013-07-03 09:21:44 +000095// unsigned 8-bit, 2-scaled memory offset
96class OperandUnsignedOffset_b8s2 : AsmOperandClass {
97 let Name = "UnsignedOffset_b8s2";
98 let PredicateMethod = "isUnsignedOffset<8, 2>";
99}
100
101def UnsignedOffset_b8s2 : OperandUnsignedOffset_b8s2;
102
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000103// thumb style PC relative operand. signed, 8 bits magnitude,
104// two bits shift. can be represented as either [pc, #imm], #imm,
105// or relocatable expression...
106def ThumbMemPC : AsmOperandClass {
107 let Name = "ThumbMemPC";
108}
109
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000110let OperandType = "OPERAND_PCREL" in {
Jim Grosbache119da12010-12-10 18:21:33 +0000111def t_brtarget : Operand<OtherVT> {
112 let EncoderMethod = "getThumbBRTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000113 let DecoderMethod = "DecodeThumbBROperand";
Jim Grosbache119da12010-12-10 18:21:33 +0000114}
115
Mihai Popad36cbaa2013-07-03 09:21:44 +0000116// ADR instruction labels.
117def t_adrlabel : Operand<i32> {
118 let EncoderMethod = "getThumbAdrLabelOpValue";
119 let PrintMethod = "printAdrLabelOperand<2>";
120 let ParserMatchClass = UnsignedOffset_b8s2;
121}
122
Jim Grosbach78485ad2010-12-10 17:13:40 +0000123def t_bcctarget : Operand<i32> {
124 let EncoderMethod = "getThumbBCCTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000125 let DecoderMethod = "DecodeThumbBCCTargetOperand";
Jim Grosbach78485ad2010-12-10 17:13:40 +0000126}
127
Jim Grosbach529c7e82010-12-09 19:01:46 +0000128def t_cbtarget : Operand<i32> {
Jim Grosbach62b68112010-12-09 19:04:53 +0000129 let EncoderMethod = "getThumbCBTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000130 let DecoderMethod = "DecodeThumbCmpBROperand";
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000131}
132
Jim Grosbach9e199462010-12-06 23:57:07 +0000133def t_bltarget : Operand<i32> {
134 let EncoderMethod = "getThumbBLTargetOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000135 let DecoderMethod = "DecodeThumbBLTargetOperand";
Jim Grosbach9e199462010-12-06 23:57:07 +0000136}
137
Bill Wendling3392bfc2010-12-09 00:39:08 +0000138def t_blxtarget : Operand<i32> {
139 let EncoderMethod = "getThumbBLXTargetOpValue";
Owen Andersonc4030382011-08-08 20:42:17 +0000140 let DecoderMethod = "DecodeThumbBLXOffset";
Bill Wendling3392bfc2010-12-09 00:39:08 +0000141}
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000142
143// t_addrmode_pc := <label> => pc + imm8 * 4
144//
145def t_addrmode_pc : Operand<i32> {
146 let EncoderMethod = "getAddrModePCOpValue";
147 let DecoderMethod = "DecodeThumbAddrModePC";
148 let PrintMethod = "printThumbLdrLabelOperand";
149 let ParserMatchClass = ThumbMemPC;
150}
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000151}
Bill Wendling3392bfc2010-12-09 00:39:08 +0000152
Evan Cheng10043e22007-01-19 07:51:42 +0000153// t_addrmode_rr := reg + reg
154//
Jim Grosbachd3595712011-08-03 23:50:40 +0000155def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
Evan Cheng10043e22007-01-19 07:51:42 +0000156def t_addrmode_rr : Operand<i32>,
157 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000158 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Cheng10043e22007-01-19 07:51:42 +0000159 let PrintMethod = "printThumbAddrModeRROperand";
Owen Anderson3157f2e2011-08-15 19:00:06 +0000160 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbach7c4739d2011-08-19 19:17:58 +0000161 let ParserMatchClass = t_addrmode_rr_asm_operand;
Jim Grosbachfde21102009-04-07 20:34:09 +0000162 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000163}
164
Bill Wendling092a7bd2010-12-14 03:36:38 +0000165// t_addrmode_rrs := reg + reg
Evan Cheng10043e22007-01-19 07:51:42 +0000166//
Jim Grosbache9380702011-08-19 16:52:32 +0000167// We use separate scaled versions because the Select* functions need
168// to explicitly check for a matching constant and return false here so that
169// the reg+imm forms will match instead. This is a horrible way to do that,
170// as it forces tight coupling between the methods, but it's how selectiondag
171// currently works.
Bill Wendling092a7bd2010-12-14 03:36:38 +0000172def t_addrmode_rrs1 : Operand<i32>,
173 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
174 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
175 let PrintMethod = "printThumbAddrModeRROperand";
Owen Andersone0152a72011-08-09 20:55:18 +0000176 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbachd3595712011-08-03 23:50:40 +0000177 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000178 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000179}
Bill Wendling092a7bd2010-12-14 03:36:38 +0000180def t_addrmode_rrs2 : Operand<i32>,
181 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
182 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000183 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000184 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000185 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000186 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000187}
188def t_addrmode_rrs4 : Operand<i32>,
189 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
190 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000191 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000192 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000193 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000194 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000195}
Evan Chengc0b73662007-01-23 22:59:13 +0000196
Bill Wendling092a7bd2010-12-14 03:36:38 +0000197// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc0b73662007-01-23 22:59:13 +0000198//
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000199def t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
Bill Wendling092a7bd2010-12-14 03:36:38 +0000200def t_addrmode_is4 : Operand<i32>,
201 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
202 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000203 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000204 let PrintMethod = "printThumbAddrModeImm5S4Operand";
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000205 let ParserMatchClass = t_addrmode_is4_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000206 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000207}
208
209// t_addrmode_is2 := reg + imm5 * 2
210//
Jim Grosbach26d35872011-08-19 18:55:51 +0000211def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
Bill Wendling092a7bd2010-12-14 03:36:38 +0000212def t_addrmode_is2 : Operand<i32>,
213 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
214 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000215 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000216 let PrintMethod = "printThumbAddrModeImm5S2Operand";
Jim Grosbach26d35872011-08-19 18:55:51 +0000217 let ParserMatchClass = t_addrmode_is2_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000218 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000219}
220
221// t_addrmode_is1 := reg + imm5
222//
Jim Grosbacha32c7532011-08-19 18:49:59 +0000223def t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
Bill Wendling092a7bd2010-12-14 03:36:38 +0000224def t_addrmode_is1 : Operand<i32>,
225 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
226 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000227 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000228 let PrintMethod = "printThumbAddrModeImm5S1Operand";
Jim Grosbacha32c7532011-08-19 18:49:59 +0000229 let ParserMatchClass = t_addrmode_is1_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000230 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000231}
232
233// t_addrmode_sp := sp + imm8 * 4
234//
Jim Grosbach505be7592011-08-23 18:39:41 +0000235// FIXME: This really shouldn't have an explicit SP operand at all. It should
236// be implicit, just like in the instruction encoding itself.
Jim Grosbach23983d62011-08-19 18:13:48 +0000237def t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
Evan Cheng10043e22007-01-19 07:51:42 +0000238def t_addrmode_sp : Operand<i32>,
239 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000240 let EncoderMethod = "getAddrModeThumbSPOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000241 let DecoderMethod = "DecodeThumbAddrModeSP";
Evan Cheng10043e22007-01-19 07:51:42 +0000242 let PrintMethod = "printThumbAddrModeSPOperand";
Jim Grosbach23983d62011-08-19 18:13:48 +0000243 let ParserMatchClass = t_addrmode_sp_asm_operand;
Jakob Stoklund Olesena94837d2010-01-13 00:43:06 +0000244 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000245}
246
247//===----------------------------------------------------------------------===//
248// Miscellaneous Instructions.
249//
250
Jim Grosbach45fceea2010-02-22 23:10:38 +0000251// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
252// from removing one half of the matched pairs. That breaks PEI, which assumes
253// these will always be in pairs, and asserts if it finds otherwise. Better way?
254let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000255def tADJCALLSTACKUP :
Bill Wendling49a2e232010-11-19 22:02:18 +0000256 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
257 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
258 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000259
Jim Grosbach669f1d02009-03-27 23:06:27 +0000260def tADJCALLSTACKDOWN :
Bill Wendling49a2e232010-11-19 22:02:18 +0000261 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
262 [(ARMcallseq_start imm:$amt)]>,
263 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000264}
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000265
Jim Grosbach23b729e2011-08-17 23:08:57 +0000266class T1SystemEncoding<bits<8> opc>
Bill Wendling5da8cae2010-11-29 22:15:03 +0000267 : T1Encoding<0b101111> {
Jim Grosbach23b729e2011-08-17 23:08:57 +0000268 let Inst{9-8} = 0b11;
269 let Inst{7-0} = opc;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000270}
271
Saleem Abdulrasool7e7c2f92014-04-25 17:24:24 +0000272def tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
273 [(int_arm_hint imm0_15:$imm)]>,
Richard Barton87dacc32013-10-18 14:09:49 +0000274 T1SystemEncoding<0x00>,
275 Requires<[IsThumb, HasV6M]> {
276 bits<4> imm;
277 let Inst{7-4} = imm;
278}
Johnny Chen90adefc2010-02-25 03:28:51 +0000279
Richard Barton87dacc32013-10-18 14:09:49 +0000280class tHintAlias<string Asm, dag Result> : tInstAlias<Asm, Result> {
281 let Predicates = [IsThumb, HasV6M];
282}
Johnny Chen74cca5a2010-02-25 17:51:03 +0000283
Richard Barton87dacc32013-10-18 14:09:49 +0000284def : tHintAlias<"nop$p", (tHINT 0, pred:$p)>; // A8.6.110
285def : tHintAlias<"yield$p", (tHINT 1, pred:$p)>; // A8.6.410
286def : tHintAlias<"wfe$p", (tHINT 2, pred:$p)>; // A8.6.408
287def : tHintAlias<"wfi$p", (tHINT 3, pred:$p)>; // A8.6.409
288def : tHintAlias<"sev$p", (tHINT 4, pred:$p)>; // A8.6.157
289def : tInstAlias<"sevl$p", (tHINT 5, pred:$p)> {
290 let Predicates = [IsThumb2, HasV8];
291}
292def : T2Pat<(int_arm_sevl), (tHINT 5)>;
Joey Goulyad98f162013-10-01 12:39:11 +0000293
Jim Grosbach23b729e2011-08-17 23:08:57 +0000294// The imm operand $val can be used by a debugger to store more information
Bill Wendling5da8cae2010-11-29 22:15:03 +0000295// about the breakpoint.
Jim Grosbach23b729e2011-08-17 23:08:57 +0000296def tBKPT : T1I<(outs), (ins imm0_255:$val), NoItinerary, "bkpt\t$val",
297 []>,
298 T1Encoding<0b101111> {
299 let Inst{9-8} = 0b10;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000300 // A8.6.22
301 bits<8> val;
302 let Inst{7-0} = val;
303}
Saleem Abdulrasool70187552013-12-23 17:23:58 +0000304// default immediate for breakpoint mnemonic
305def : InstAlias<"bkpt", (tBKPT 0)>, Requires<[IsThumb]>;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000306
Richard Barton8d519fe2013-09-05 14:14:19 +0000307def tHLT : T1I<(outs), (ins imm0_63:$val), NoItinerary, "hlt\t$val",
308 []>, T1Encoding<0b101110>, Requires<[IsThumb, HasV8]> {
309 let Inst{9-6} = 0b1010;
310 bits<6> val;
311 let Inst{5-0} = val;
312}
313
Jim Grosbach39f93882011-07-22 17:52:23 +0000314def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
Amara Emerson52cfb6a2013-10-03 09:31:51 +0000315 []>, T1Encoding<0b101101>, Deprecated<HasV8Ops> {
Jim Grosbach39f93882011-07-22 17:52:23 +0000316 bits<1> end;
Bill Wendling3acd0272010-11-21 10:55:23 +0000317 // A8.6.156
Johnny Chen74cca5a2010-02-25 17:51:03 +0000318 let Inst{9-5} = 0b10010;
Bill Wendling49a2e232010-11-19 22:02:18 +0000319 let Inst{4} = 1;
Jim Grosbach39f93882011-07-22 17:52:23 +0000320 let Inst{3} = end;
Bill Wendling49a2e232010-11-19 22:02:18 +0000321 let Inst{2-0} = 0b000;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000322}
323
Johnny Chen44908a52010-03-02 18:14:57 +0000324// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000325def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
Jim Grosbach4da03f02011-09-20 00:00:06 +0000326 NoItinerary, "cps$imod $iflags", []>,
Bill Wendling775899e2010-11-29 00:18:15 +0000327 T1Misc<0b0110011> {
328 // A8.6.38 & B6.1.1
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000329 bit imod;
330 bits<3> iflags;
331
332 let Inst{4} = imod;
333 let Inst{3} = 0;
334 let Inst{2-0} = iflags;
Owen Andersone0152a72011-08-09 20:55:18 +0000335 let DecoderMethod = "DecodeThumbCPS";
Bill Wendling775899e2010-11-29 00:18:15 +0000336}
Johnny Chen44908a52010-03-02 18:14:57 +0000337
Evan Cheng7cc6aca2009-08-04 23:47:55 +0000338// For both thumb1 and thumb2.
Chris Lattner9492c172010-10-31 19:15:18 +0000339let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +0000340def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendlinga82fb712010-11-19 22:37:33 +0000341 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000342 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlingddce9f32010-11-30 00:50:22 +0000343 // A8.6.6
Bill Wendlinga82fb712010-11-19 22:37:33 +0000344 bits<3> dst;
Bill Wendlingddce9f32010-11-30 00:50:22 +0000345 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendlinga82fb712010-11-19 22:37:33 +0000346 let Inst{2-0} = dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000347}
Evan Cheng10043e22007-01-19 07:51:42 +0000348
Bill Wendlinga82fb712010-11-19 22:37:33 +0000349// ADD <Rd>, sp, #<imm8>
Jakob Stoklund Olesendd2b39d2011-10-15 00:57:13 +0000350// FIXME: This should not be marked as having side effects, and it should be
351// rematerializable. Clearing the side effect bit causes miscompilations,
352// probably because the instruction can be moved around.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000353def tADDrSPi : T1pI<(outs tGPR:$dst), (ins GPRsp:$sp, t_imm0_1020s4:$imm),
354 IIC_iALUi, "add", "\t$dst, $sp, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000355 T1Encoding<{1,0,1,0,1,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000356 // A6.2 & A8.6.8
357 bits<3> dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000358 bits<8> imm;
Bill Wendlinga82fb712010-11-19 22:37:33 +0000359 let Inst{10-8} = dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000360 let Inst{7-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000361 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000362}
363
364// ADD sp, sp, #<imm7>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000365def tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
366 IIC_iALUi, "add", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000367 T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000368 // A6.2.5 & A8.6.8
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000369 bits<7> imm;
370 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000371 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000372}
Evan Chengb566ab72009-06-25 01:05:06 +0000373
Bill Wendlinga82fb712010-11-19 22:37:33 +0000374// SUB sp, sp, #<imm7>
375// FIXME: The encoding and the ASM string don't match up.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000376def tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
377 IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000378 T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000379 // A6.2.5 & A8.6.214
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000380 bits<7> imm;
381 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000382 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000383}
Evan Chengb972e562009-08-07 00:34:42 +0000384
Jim Grosbach930f2f62012-04-05 20:57:13 +0000385def : tInstAlias<"add${p} sp, $imm",
386 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
387def : tInstAlias<"add${p} sp, sp, $imm",
388 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
389
Jim Grosbach4b701af2011-08-24 21:42:27 +0000390// Can optionally specify SP as a three operand instruction.
391def : tInstAlias<"add${p} sp, sp, $imm",
392 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
393def : tInstAlias<"sub${p} sp, sp, $imm",
394 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
395
Bill Wendlinga82fb712010-11-19 22:37:33 +0000396// ADD <Rm>, sp
Jim Grosbachc6f32b32012-04-27 23:51:36 +0000397def tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
398 "add", "\t$Rdn, $sp, $Rn", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000399 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000400 // A8.6.9 Encoding T1
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000401 bits<4> Rdn;
402 let Inst{7} = Rdn{3};
Bill Wendlinga82fb712010-11-19 22:37:33 +0000403 let Inst{6-3} = 0b1101;
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000404 let Inst{2-0} = Rdn{2-0};
Owen Andersone0152a72011-08-09 20:55:18 +0000405 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000406}
Evan Chengb972e562009-08-07 00:34:42 +0000407
Bill Wendlinga82fb712010-11-19 22:37:33 +0000408// ADD sp, <Rm>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000409def tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
410 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000411 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Johnny Chenc28e6292009-12-15 17:24:14 +0000412 // A8.6.9 Encoding T2
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000413 bits<4> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000414 let Inst{7} = 1;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000415 let Inst{6-3} = Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000416 let Inst{2-0} = 0b101;
Owen Andersone0152a72011-08-09 20:55:18 +0000417 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000418}
Evan Chengb972e562009-08-07 00:34:42 +0000419
Evan Cheng10043e22007-01-19 07:51:42 +0000420//===----------------------------------------------------------------------===//
421// Control Flow Instructions.
422//
423
Bob Wilson73789b82009-10-28 18:26:41 +0000424// Indirect branches
425let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000426 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000427 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000428 // A6.2.3 & A8.6.25
429 bits<4> Rm;
430 let Inst{6-3} = Rm;
431 let Inst{2-0} = 0b000;
James Molloyd9ba4fd2012-02-09 10:56:31 +0000432 let Unpredictable{2-0} = 0b111;
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000433 }
Bob Wilson73789b82009-10-28 18:26:41 +0000434}
435
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000436let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson651b2302011-07-13 23:22:26 +0000437 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000438 [(ARMretflag)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000439
440 // Alternative return instruction used by vararg functions.
Jim Grosbach74719372011-07-08 21:50:04 +0000441 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000442 2, IIC_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000443 (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000444}
445
Bill Wendling9c258942010-12-01 02:36:55 +0000446// All calls clobber the non-callee saved registers. SP is marked as a use to
447// prevent stack-pointer assignments that appear immediately before calls from
448// potentially appearing dead.
Jim Grosbach669f1d02009-03-27 23:06:27 +0000449let isCall = 1,
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000450 Defs = [LR], Uses = [SP] in {
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000451 // Also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000452 def tBL : TIx2<0b11110, 0b11, 1,
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000453 (outs), (ins pred:$p, t_bltarget:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000454 "bl${p}\t$func",
Johnny Chenc28e6292009-12-15 17:24:14 +0000455 [(ARMtcall tglobaladdr:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000456 Requires<[IsThumb]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000457 bits<24> func;
458 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000459 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000460 let Inst{13} = func{22};
461 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000462 let Inst{10-0} = func{10-0};
Bill Wendling4d8ff862010-12-03 01:55:47 +0000463 }
Evan Cheng175bd142009-07-29 21:26:42 +0000464
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000465 // ARMv5T and above, also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000466 def tBLXi : TIx2<0b11110, 0b11, 0,
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000467 (outs), (ins pred:$p, t_blxtarget:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000468 "blx${p}\t$func",
Johnny Chenc28e6292009-12-15 17:24:14 +0000469 [(ARMcall tglobaladdr:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000470 Requires<[IsThumb, HasV5T]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000471 bits<24> func;
472 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000473 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000474 let Inst{13} = func{22};
475 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000476 let Inst{10-1} = func{10-1};
477 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbache4fee202010-12-03 22:33:42 +0000478 }
Evan Cheng175bd142009-07-29 21:26:42 +0000479
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000480 // Also used for Thumb2
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000481 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000482 "blx${p}\t$func",
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000483 [(ARMtcall GPR:$func)]>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +0000484 Requires<[IsThumb, HasV5T]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000485 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
Owen Andersonb7456232011-05-11 17:00:48 +0000486 bits<4> func;
487 let Inst{6-3} = func;
488 let Inst{2-0} = 0b000;
489 }
Evan Cheng175bd142009-07-29 21:26:42 +0000490
Lauro Ramos Venancio143b0df2007-03-27 16:19:21 +0000491 // ARMv4T
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000492 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
Owen Anderson651b2302011-07-13 23:22:26 +0000493 4, IIC_Br,
Evan Cheng175bd142009-07-29 21:26:42 +0000494 [(ARMcall_nolink tGPR:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000495 Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000496}
497
Bill Wendling9c258942010-12-01 02:36:55 +0000498let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
499 let isPredicable = 1 in
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000500 def tB : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
501 "b", "\t$target", [(br bb:$target)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000502 T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
Jim Grosbache119da12010-12-10 18:21:33 +0000503 bits<11> target;
504 let Inst{10-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000505 let AsmMatchConverter = "cvtThumbBranches";
506 }
Evan Cheng10043e22007-01-19 07:51:42 +0000507
Evan Cheng863736b2007-01-30 01:13:37 +0000508 // Far jump
Jim Grosbachb5743b92010-12-16 19:11:16 +0000509 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
510 // the clobber of LR.
Evan Cheng317bd7a2009-08-07 05:45:07 +0000511 let Defs = [LR] in
Owen Anderson64d53622011-07-18 18:50:52 +0000512 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000513 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>,
514 Sched<[WriteBrTbl]>;
Evan Cheng863736b2007-01-30 01:13:37 +0000515
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000516 def tBR_JTr : tPseudoInst<(outs),
517 (ins tGPR:$target, i32imm:$jt, i32imm:$id),
Owen Anderson651b2302011-07-13 23:22:26 +0000518 0, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000519 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>,
520 Sched<[WriteBrTbl]> {
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000521 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chen466231a2009-12-16 02:32:54 +0000522 }
Evan Cheng0701c5a2007-01-27 02:29:45 +0000523}
524
Evan Chengaa3b8012007-07-05 07:13:32 +0000525// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach669f1d02009-03-27 23:06:27 +0000526// a two-value operand where a dag node expects two operands. :(
Evan Chengac1591b2007-07-21 00:34:19 +0000527let isBranch = 1, isTerminator = 1 in
Jim Grosbach78485ad2010-12-10 17:13:40 +0000528 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000529 "b${p}\t$target",
Johnny Chenc28e6292009-12-15 17:24:14 +0000530 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000531 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000532 bits<4> p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000533 bits<8> target;
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000534 let Inst{11-8} = p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000535 let Inst{7-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000536 let AsmMatchConverter = "cvtThumbBranches";
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000537}
Evan Cheng10043e22007-01-19 07:51:42 +0000538
Mihai Popad36cbaa2013-07-03 09:21:44 +0000539
Jim Grosbach166cd882011-07-08 20:13:35 +0000540// Tail calls
541let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
Evan Cheng68132d82011-12-20 18:26:50 +0000542 // IOS versions.
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000543 let Uses = [SP] in {
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000544 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
Owen Anderson651b2302011-07-13 23:22:26 +0000545 4, IIC_Br, [],
Jim Grosbach204c1282011-07-08 20:39:19 +0000546 (tBX GPR:$dst, (ops 14, zero_reg))>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000547 Requires<[IsThumb]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000548 }
Tim Northoverd6a729b2014-01-06 14:28:05 +0000549 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
550 // on MachO), so it's in ARMInstrThumb2.td.
551 // Non-MachO version:
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000552 let Uses = [SP] in {
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000553 def tTAILJMPdND : tPseudoExpand<(outs),
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000554 (ins t_brtarget:$dst, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000555 4, IIC_Br, [],
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000556 (tB t_brtarget:$dst, pred:$p)>,
Tim Northoverd6a729b2014-01-06 14:28:05 +0000557 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000558 }
559}
560
561
Jim Grosbach5cc338d2011-08-23 19:49:10 +0000562// A8.6.218 Supervisor Call (Software Interrupt)
Johnny Chen57656da2010-02-25 02:21:11 +0000563// A8.6.16 B: Encoding T1
564// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng9a133f62010-11-29 22:43:27 +0000565let isCall = 1, Uses = [SP] in
Jim Grosbachf1637842011-07-26 16:24:27 +0000566def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000567 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000568 bits<8> imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000569 let Inst{15-12} = 0b1101;
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000570 let Inst{11-8} = 0b1111;
571 let Inst{7-0} = imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000572}
573
Bill Wendling811c9362010-11-30 07:44:32 +0000574// The assembler uses 0xDEFE for a trap instruction.
Evan Cheng2fa5a7e2010-05-11 07:26:32 +0000575let isBarrier = 1, isTerminator = 1 in
Owen Andersonb7456232011-05-11 17:00:48 +0000576def tTRAP : TI<(outs), (ins), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000577 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
Bill Wendling3acd0272010-11-21 10:55:23 +0000578 let Inst = 0xdefe;
Johnny Chen57656da2010-02-25 02:21:11 +0000579}
580
Evan Cheng10043e22007-01-19 07:51:42 +0000581//===----------------------------------------------------------------------===//
582// Load Store Instructions.
583//
584
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000585// Loads: reg/reg and reg/imm5
Dan Gohman8c5d6832010-02-27 23:47:46 +0000586let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000587multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
588 Operand AddrMode_r, Operand AddrMode_i,
589 AddrMode am, InstrItinClass itin_r,
590 InstrItinClass itin_i, string asm,
591 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000592 def r : // reg/reg
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000593 T1pILdStEncode<reg_opc,
594 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
595 am, itin_r, asm, "\t$Rt, $addr",
596 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendling5ab38b52010-12-14 23:42:48 +0000597 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000598 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
599 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
600 am, itin_i, asm, "\t$Rt, $addr",
601 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
602}
603// Stores: reg/reg and reg/imm5
604multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
605 Operand AddrMode_r, Operand AddrMode_i,
606 AddrMode am, InstrItinClass itin_r,
607 InstrItinClass itin_i, string asm,
608 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000609 def r : // reg/reg
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000610 T1pILdStEncode<reg_opc,
611 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
612 am, itin_r, asm, "\t$Rt, $addr",
613 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendling5ab38b52010-12-14 23:42:48 +0000614 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000615 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
616 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
617 am, itin_i, asm, "\t$Rt, $addr",
618 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
619}
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000620
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000621// A8.6.57 & A8.6.60
622defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rrs4,
623 t_addrmode_is4, AddrModeT1_4,
624 IIC_iLoad_r, IIC_iLoad_i, "ldr",
625 UnOpFrag<(load node:$Src)>>;
Evan Cheng10043e22007-01-19 07:51:42 +0000626
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000627// A8.6.64 & A8.6.61
628defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rrs1,
629 t_addrmode_is1, AddrModeT1_1,
630 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
631 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000632
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000633// A8.6.76 & A8.6.73
634defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rrs2,
635 t_addrmode_is2, AddrModeT1_2,
636 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
637 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc0b73662007-01-23 22:59:13 +0000638
Evan Cheng0794c6a2009-07-11 07:08:13 +0000639let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000640def tLDRSB : // A8.6.80
Owen Anderson3157f2e2011-08-15 19:00:06 +0000641 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000642 AddrModeT1_1, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000643 "ldrsb", "\t$Rt, $addr",
644 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000645
Evan Cheng0794c6a2009-07-11 07:08:13 +0000646let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000647def tLDRSH : // A8.6.84
Owen Anderson3157f2e2011-08-15 19:00:06 +0000648 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000649 AddrModeT1_2, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000650 "ldrsh", "\t$Rt, $addr",
651 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000652
Dan Gohman69cc2cb2008-12-03 18:15:48 +0000653let canFoldAsLoad = 1 in
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000654def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
Bill Wendling6217ecd2010-12-15 23:31:24 +0000655 "ldr", "\t$Rt, $addr",
656 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000657 T1LdStSP<{1,?,?}> {
658 bits<3> Rt;
659 bits<8> addr;
660 let Inst{10-8} = Rt;
661 let Inst{7-0} = addr;
662}
Evan Cheng1526ba52007-01-24 08:53:17 +0000663
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000664let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendling8a6449c2010-12-08 01:57:09 +0000665def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000666 "ldr", "\t$Rt, $addr",
Bill Wendling05632cb2010-11-30 23:54:45 +0000667 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
668 T1Encoding<{0,1,0,0,1,?}> {
669 // A6.2 & A8.6.59
670 bits<3> Rt;
Bill Wendling8a6449c2010-12-08 01:57:09 +0000671 bits<8> addr;
Bill Wendling05632cb2010-11-30 23:54:45 +0000672 let Inst{10-8} = Rt;
Bill Wendling8a6449c2010-12-08 01:57:09 +0000673 let Inst{7-0} = addr;
Bill Wendling05632cb2010-11-30 23:54:45 +0000674}
Evan Chengee2763f2007-03-19 07:20:03 +0000675
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000676// A8.6.194 & A8.6.192
677defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rrs4,
678 t_addrmode_is4, AddrModeT1_4,
679 IIC_iStore_r, IIC_iStore_i, "str",
680 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Cheng10043e22007-01-19 07:51:42 +0000681
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000682// A8.6.197 & A8.6.195
683defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rrs1,
684 t_addrmode_is1, AddrModeT1_1,
685 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
686 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Chengc0b73662007-01-23 22:59:13 +0000687
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000688// A8.6.207 & A8.6.205
689defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rrs2,
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000690 t_addrmode_is2, AddrModeT1_2,
691 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
692 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000693
Evan Cheng10043e22007-01-19 07:51:42 +0000694
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000695def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000696 "str", "\t$Rt, $addr",
697 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000698 T1LdStSP<{0,?,?}> {
699 bits<3> Rt;
700 bits<8> addr;
701 let Inst{10-8} = Rt;
702 let Inst{7-0} = addr;
703}
Evan Chengec13f8262007-02-07 00:06:56 +0000704
Evan Cheng10043e22007-01-19 07:51:42 +0000705//===----------------------------------------------------------------------===//
706// Load / store multiple Instructions.
707//
708
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000709// These require base address to be written back or one of the loaded regs.
Bill Wendling705ec772010-11-13 10:57:02 +0000710let neverHasSideEffects = 1 in {
711
712let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000713def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
714 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
715 bits<3> Rn;
716 bits<8> regs;
717 let Inst{10-8} = Rn;
718 let Inst{7-0} = regs;
719}
Bill Wendling705ec772010-11-13 10:57:02 +0000720
Jim Grosbache364ad52011-08-23 17:41:15 +0000721// Writeback version is just a pseudo, as there's no encoding difference.
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +0000722// Writeback happens iff the base register is not in the destination register
Jim Grosbache364ad52011-08-23 17:41:15 +0000723// list.
724def tLDMIA_UPD :
725 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
726 "$Rn = $wb", IIC_iLoad_mu>,
727 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
728 let Size = 2;
729 let OutOperandList = (outs GPR:$wb);
730 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
731 let Pattern = [];
732 let isCodeGenOnly = 1;
733 let isPseudo = 1;
734 list<Predicate> Predicates = [IsThumb];
735}
736
737// There is no non-writeback version of STM for Thumb.
Bill Wendling705ec772010-11-13 10:57:02 +0000738let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
Jim Grosbach6ccd79f2011-08-24 18:19:42 +0000739def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
740 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
741 AddrModeNone, 2, IIC_iStore_mu,
742 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
Jim Grosbache364ad52011-08-23 17:41:15 +0000743 T1Encoding<{1,1,0,0,0,?}> {
744 bits<3> Rn;
745 bits<8> regs;
746 let Inst{10-8} = Rn;
747 let Inst{7-0} = regs;
748}
Owen Andersonb7456232011-05-11 17:00:48 +0000749
Bill Wendling705ec772010-11-13 10:57:02 +0000750} // neverHasSideEffects
Evan Chengcc9ca352009-08-11 21:11:32 +0000751
Jim Grosbach90103cc2011-08-18 21:50:53 +0000752def : InstAlias<"ldm${p} $Rn!, $regs",
753 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)>,
754 Requires<[IsThumb, IsThumb1Only]>;
755
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000756let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling945b7762010-11-19 01:33:10 +0000757def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000758 IIC_iPop,
Bill Wendling945b7762010-11-19 01:33:10 +0000759 "pop${p}\t$regs", []>,
760 T1Misc<{1,1,0,?,?,?,?}> {
761 bits<16> regs;
Bill Wendling945b7762010-11-19 01:33:10 +0000762 let Inst{8} = regs{15};
763 let Inst{7-0} = regs{7-0};
764}
Evan Chengcc9ca352009-08-11 21:11:32 +0000765
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000766let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000767def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000768 IIC_iStore_m,
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000769 "push${p}\t$regs", []>,
770 T1Misc<{0,1,0,?,?,?,?}> {
771 bits<16> regs;
772 let Inst{8} = regs{14};
773 let Inst{7-0} = regs{7-0};
774}
Evan Cheng10043e22007-01-19 07:51:42 +0000775
776//===----------------------------------------------------------------------===//
777// Arithmetic Instructions.
778//
779
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000780// Helper classes for encoding T1pI patterns:
781class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
782 string opc, string asm, list<dag> pattern>
783 : T1pI<oops, iops, itin, opc, asm, pattern>,
784 T1DataProcessing<opA> {
785 bits<3> Rm;
786 bits<3> Rn;
787 let Inst{5-3} = Rm;
788 let Inst{2-0} = Rn;
789}
790class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
791 string opc, string asm, list<dag> pattern>
792 : T1pI<oops, iops, itin, opc, asm, pattern>,
793 T1Misc<opA> {
794 bits<3> Rm;
795 bits<3> Rd;
796 let Inst{5-3} = Rm;
797 let Inst{2-0} = Rd;
798}
799
Bill Wendling490240a2010-12-01 01:20:15 +0000800// Helper classes for encoding T1sI patterns:
801class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
802 string opc, string asm, list<dag> pattern>
803 : T1sI<oops, iops, itin, opc, asm, pattern>,
804 T1DataProcessing<opA> {
805 bits<3> Rd;
806 bits<3> Rn;
807 let Inst{5-3} = Rn;
808 let Inst{2-0} = Rd;
809}
810class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
811 string opc, string asm, list<dag> pattern>
812 : T1sI<oops, iops, itin, opc, asm, pattern>,
813 T1General<opA> {
814 bits<3> Rm;
815 bits<3> Rn;
816 bits<3> Rd;
817 let Inst{8-6} = Rm;
818 let Inst{5-3} = Rn;
819 let Inst{2-0} = Rd;
820}
821class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
822 string opc, string asm, list<dag> pattern>
823 : T1sI<oops, iops, itin, opc, asm, pattern>,
824 T1General<opA> {
825 bits<3> Rd;
826 bits<3> Rm;
827 let Inst{5-3} = Rm;
828 let Inst{2-0} = Rd;
829}
830
831// Helper classes for encoding T1sIt patterns:
Bill Wendling4915f562010-12-01 00:48:44 +0000832class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
833 string opc, string asm, list<dag> pattern>
834 : T1sIt<oops, iops, itin, opc, asm, pattern>,
835 T1DataProcessing<opA> {
Bill Wendling05632cb2010-11-30 23:54:45 +0000836 bits<3> Rdn;
837 bits<3> Rm;
Bill Wendling4915f562010-12-01 00:48:44 +0000838 let Inst{5-3} = Rm;
839 let Inst{2-0} = Rdn;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000840}
Bill Wendling4915f562010-12-01 00:48:44 +0000841class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
842 string opc, string asm, list<dag> pattern>
843 : T1sIt<oops, iops, itin, opc, asm, pattern>,
844 T1General<opA> {
845 bits<3> Rdn;
846 bits<8> imm8;
847 let Inst{10-8} = Rdn;
848 let Inst{7-0} = imm8;
849}
850
851// Add with carry register
852let isCommutable = 1, Uses = [CPSR] in
853def tADC : // A8.6.2
854 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
855 "adc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000856 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Chengf40b9002007-01-27 00:07:15 +0000857
David Goodwine85169c2009-06-25 22:49:55 +0000858// Add immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000859def tADDi3 : // A8.6.4 T1
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000860 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000861 IIC_iALUi,
Bill Wendling490240a2010-12-01 01:20:15 +0000862 "add", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000863 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
864 Sched<[WriteALU]> {
Bill Wendlingfe1de032010-11-20 01:00:29 +0000865 bits<3> imm3;
866 let Inst{8-6} = imm3;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000867}
Evan Cheng10043e22007-01-19 07:51:42 +0000868
Bill Wendling4915f562010-12-01 00:48:44 +0000869def tADDi8 : // A8.6.4 T2
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000870 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
871 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +0000872 "add", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000873 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
874 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000875
David Goodwine85169c2009-06-25 22:49:55 +0000876// Add register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000877let isCommutable = 1 in
Bill Wendling490240a2010-12-01 01:20:15 +0000878def tADDrr : // A8.6.6 T1
879 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
880 IIC_iALUr,
881 "add", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000882 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000883
Evan Chengd93b5b62009-06-12 20:46:18 +0000884let neverHasSideEffects = 1 in
Bill Wendling7c646b92010-12-01 01:32:02 +0000885def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
886 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000887 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000888 // A8.6.6 T2
Bill Wendling7c646b92010-12-01 01:32:02 +0000889 bits<4> Rdn;
890 bits<4> Rm;
891 let Inst{7} = Rdn{3};
892 let Inst{6-3} = Rm;
893 let Inst{2-0} = Rdn{2-0};
Bill Wendling284326b2010-11-20 01:18:47 +0000894}
Evan Cheng10043e22007-01-19 07:51:42 +0000895
Bill Wendling284326b2010-11-20 01:18:47 +0000896// AND register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000897let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000898def tAND : // A8.6.12
899 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
900 IIC_iBITr,
901 "and", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000902 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000903
David Goodwine85169c2009-06-25 22:49:55 +0000904// ASR immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000905def tASRri : // A8.6.14
Owen Andersonc4030382011-08-08 20:42:17 +0000906 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +0000907 IIC_iMOVsi,
908 "asr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000909 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
910 Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000911 bits<5> imm5;
912 let Inst{10-6} = imm5;
Bill Wendling284326b2010-11-20 01:18:47 +0000913}
Evan Cheng10043e22007-01-19 07:51:42 +0000914
David Goodwine85169c2009-06-25 22:49:55 +0000915// ASR register
Bill Wendling4915f562010-12-01 00:48:44 +0000916def tASRrr : // A8.6.15
917 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
918 IIC_iMOVsr,
919 "asr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000920 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000921
David Goodwine85169c2009-06-25 22:49:55 +0000922// BIC register
Bill Wendling4915f562010-12-01 00:48:44 +0000923def tBIC : // A8.6.20
924 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
925 IIC_iBITr,
926 "bic", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000927 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
928 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000929
David Goodwine85169c2009-06-25 22:49:55 +0000930// CMN register
Gabor Greif22f69222010-09-14 22:00:50 +0000931let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach267430f2010-01-22 00:08:13 +0000932//FIXME: Disable CMN, as CCodes are backwards from compare expectations
933// Compare-to-zero still works out, just not the relationals
Bill Wendling9c258942010-12-01 02:36:55 +0000934//def tCMN : // A8.6.33
935// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
936// IIC_iCMPr,
937// "cmn", "\t$lhs, $rhs",
938// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000939
940def tCMNz : // A8.6.33
941 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
942 IIC_iCMPr,
943 "cmn", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000944 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000945
946} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +0000947
David Goodwine85169c2009-06-25 22:49:55 +0000948// CMP immediate
Gabor Greif22f69222010-09-14 22:00:50 +0000949let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach4f240a12011-08-18 18:08:29 +0000950def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
Bill Wendlingc31de252010-11-20 22:52:33 +0000951 "cmp", "\t$Rn, $imm8",
952 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000953 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendlingc31de252010-11-20 22:52:33 +0000954 // A8.6.35
955 bits<3> Rn;
956 bits<8> imm8;
957 let Inst{10-8} = Rn;
958 let Inst{7-0} = imm8;
959}
960
David Goodwine85169c2009-06-25 22:49:55 +0000961// CMP register
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000962def tCMPr : // A8.6.36 T1
963 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
964 IIC_iCMPr,
965 "cmp", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000966 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000967
Bill Wendling775899e2010-11-29 00:18:15 +0000968def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
969 "cmp", "\t$Rn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000970 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendling775899e2010-11-29 00:18:15 +0000971 // A8.6.36 T2
972 bits<4> Rm;
973 bits<4> Rn;
974 let Inst{7} = Rn{3};
975 let Inst{6-3} = Rm;
976 let Inst{2-0} = Rn{2-0};
977}
Bill Wendlingc31de252010-11-20 22:52:33 +0000978} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +0000979
Evan Cheng10043e22007-01-19 07:51:42 +0000980
David Goodwine85169c2009-06-25 22:49:55 +0000981// XOR register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000982let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000983def tEOR : // A8.6.45
984 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
985 IIC_iBITr,
986 "eor", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000987 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000988
David Goodwine85169c2009-06-25 22:49:55 +0000989// LSL immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000990def tLSLri : // A8.6.88
Jim Grosbach5503c3a2011-08-19 19:29:25 +0000991 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +0000992 IIC_iMOVsi,
993 "lsl", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000994 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
995 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +0000996 bits<5> imm5;
997 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +0000998}
Evan Cheng10043e22007-01-19 07:51:42 +0000999
David Goodwine85169c2009-06-25 22:49:55 +00001000// LSL register
Bill Wendling4915f562010-12-01 00:48:44 +00001001def tLSLrr : // A8.6.89
1002 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1003 IIC_iMOVsr,
1004 "lsl", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001005 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001006
David Goodwine85169c2009-06-25 22:49:55 +00001007// LSR immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001008def tLSRri : // A8.6.90
Owen Andersonc4030382011-08-08 20:42:17 +00001009 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001010 IIC_iMOVsi,
1011 "lsr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001012 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1013 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001014 bits<5> imm5;
1015 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001016}
Evan Cheng10043e22007-01-19 07:51:42 +00001017
David Goodwine85169c2009-06-25 22:49:55 +00001018// LSR register
Bill Wendling4915f562010-12-01 00:48:44 +00001019def tLSRrr : // A8.6.91
1020 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1021 IIC_iMOVsr,
1022 "lsr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001023 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001024
Bill Wendling22db3132010-11-21 11:49:36 +00001025// Move register
Evan Cheng7f8ab6e2010-11-17 20:13:28 +00001026let isMoveImm = 1 in
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001027def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendling22db3132010-11-21 11:49:36 +00001028 "mov", "\t$Rd, $imm8",
1029 [(set tGPR:$Rd, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001030 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001031 // A8.6.96
1032 bits<3> Rd;
1033 bits<8> imm8;
1034 let Inst{10-8} = Rd;
1035 let Inst{7-0} = imm8;
1036}
Jim Grosbachf86cd372011-08-19 20:46:54 +00001037// Because we have an explicit tMOVSr below, we need an alias to handle
1038// the immediate "movs" form here. Blech.
Jim Grosbach6caa5572011-08-22 18:04:24 +00001039def : tInstAlias <"movs $Rdn, $imm",
1040 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001041
Jim Grosbach4def7042011-07-01 17:14:11 +00001042// A7-73: MOV(2) - mov setting flag.
Evan Cheng10043e22007-01-19 07:51:42 +00001043
Evan Chengd93b5b62009-06-12 20:46:18 +00001044let neverHasSideEffects = 1 in {
Jim Grosbache9cc9012011-06-30 23:38:17 +00001045def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson651b2302011-07-13 23:22:26 +00001046 2, IIC_iMOVr,
Jim Grosbachb98ab912011-06-30 22:10:46 +00001047 "mov", "\t$Rd, $Rm", "", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001048 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001049 // A8.6.97
1050 bits<4> Rd;
1051 bits<4> Rm;
Jim Grosbache9cc9012011-06-30 23:38:17 +00001052 let Inst{7} = Rd{3};
1053 let Inst{6-3} = Rm;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001054 let Inst{2-0} = Rd{2-0};
1055}
Evan Chengcd4cdd12009-07-11 06:43:01 +00001056let Defs = [CPSR] in
Bill Wendling4d8ff862010-12-03 01:55:47 +00001057def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001058 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001059 // A8.6.97
1060 bits<3> Rd;
1061 bits<3> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +00001062 let Inst{15-6} = 0b0000000000;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001063 let Inst{5-3} = Rm;
1064 let Inst{2-0} = Rd;
Johnny Chenc28e6292009-12-15 17:24:14 +00001065}
Evan Chengd93b5b62009-06-12 20:46:18 +00001066} // neverHasSideEffects
Evan Cheng10043e22007-01-19 07:51:42 +00001067
Bill Wendling9c258942010-12-01 02:36:55 +00001068// Multiply register
Jim Grosbachbfeb4f72011-08-22 23:25:48 +00001069let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001070def tMUL : // A8.6.105 T1
Jim Grosbach8e048492011-08-19 22:07:46 +00001071 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1072 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1073 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1074 T1DataProcessing<0b1101> {
1075 bits<3> Rd;
1076 bits<3> Rn;
1077 let Inst{5-3} = Rn;
1078 let Inst{2-0} = Rd;
1079 let AsmMatchConverter = "cvtThumbMultiply";
1080}
1081
Jim Grosbach6caa5572011-08-22 18:04:24 +00001082def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1083 pred:$p)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001084
Bill Wendling490240a2010-12-01 01:20:15 +00001085// Move inverse register
1086def tMVN : // A8.6.107
1087 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1088 "mvn", "\t$Rd, $Rn",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001089 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001090
Bill Wendling22db3132010-11-21 11:49:36 +00001091// Bitwise or register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001092let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001093def tORR : // A8.6.114
1094 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1095 IIC_iBITr,
1096 "orr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001097 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001098
Bill Wendling22db3132010-11-21 11:49:36 +00001099// Swaps
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001100def tREV : // A8.6.134
1101 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1102 IIC_iUNAr,
1103 "rev", "\t$Rd, $Rm",
1104 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001105 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001106
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001107def tREV16 : // A8.6.135
1108 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1109 IIC_iUNAr,
1110 "rev16", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001111 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001112 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001113
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001114def tREVSH : // A8.6.136
1115 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1116 IIC_iUNAr,
1117 "revsh", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001118 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001119 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001120
Bill Wendling4915f562010-12-01 00:48:44 +00001121// Rotate right register
1122def tROR : // A8.6.139
1123 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1124 IIC_iMOVsr,
1125 "ror", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001126 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1127 Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001128
Bill Wendling4915f562010-12-01 00:48:44 +00001129// Negate register
Bill Wendling490240a2010-12-01 01:20:15 +00001130def tRSB : // A8.6.141
1131 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1132 IIC_iALUi,
1133 "rsb", "\t$Rd, $Rn, #0",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001134 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001135
David Goodwine85169c2009-06-25 22:49:55 +00001136// Subtract with carry register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001137let Uses = [CPSR] in
Bill Wendling4915f562010-12-01 00:48:44 +00001138def tSBC : // A8.6.151
1139 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1140 IIC_iALUr,
1141 "sbc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001142 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>,
1143 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001144
David Goodwine85169c2009-06-25 22:49:55 +00001145// Subtract immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001146def tSUBi3 : // A8.6.210 T1
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001147 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Bill Wendling490240a2010-12-01 01:20:15 +00001148 IIC_iALUi,
1149 "sub", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001150 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1151 Sched<[WriteALU]> {
Bill Wendlingccba1a82010-11-29 01:00:43 +00001152 bits<3> imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001153 let Inst{8-6} = imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001154}
Jim Grosbach669f1d02009-03-27 23:06:27 +00001155
Bill Wendling4915f562010-12-01 00:48:44 +00001156def tSUBi8 : // A8.6.210 T2
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001157 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1158 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +00001159 "sub", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001160 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1161 Sched<[WriteALU]>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001162
Bill Wendling490240a2010-12-01 01:20:15 +00001163// Subtract register
1164def tSUBrr : // A8.6.212
1165 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1166 IIC_iALUr,
1167 "sub", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001168 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1169 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001170
Bill Wendling490240a2010-12-01 01:20:15 +00001171// Sign-extend byte
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001172def tSXTB : // A8.6.222
1173 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1174 IIC_iUNAr,
1175 "sxtb", "\t$Rd, $Rm",
1176 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001177 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1178 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001179
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001180// Sign-extend short
1181def tSXTH : // A8.6.224
1182 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1183 IIC_iUNAr,
1184 "sxth", "\t$Rd, $Rm",
1185 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001186 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1187 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001188
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001189// Test
Gabor Greif2afac8e2010-09-14 20:47:43 +00001190let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001191def tTST : // A8.6.230
1192 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1193 "tst", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001194 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1195 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001196
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001197// Zero-extend byte
1198def tUXTB : // A8.6.262
1199 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1200 IIC_iUNAr,
1201 "uxtb", "\t$Rd, $Rm",
1202 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001203 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1204 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001205
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001206// Zero-extend short
1207def tUXTH : // A8.6.264
1208 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1209 IIC_iUNAr,
1210 "uxth", "\t$Rd, $Rm",
1211 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001212 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001213
Jim Grosbach3e2cad32010-02-16 21:23:02 +00001214// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman453d64c2009-10-29 18:10:34 +00001215// Expanded after instruction selection into a branch sequence.
1216let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Chengbb2af352009-08-12 05:17:19 +00001217 def tMOVCCr_pseudo :
Tim Northover42180442013-08-22 09:57:11 +00001218 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1219 NoItinerary,
1220 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001221
1222// tLEApcrel - Load a pc-relative address into a register without offending the
1223// assembler.
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001224
1225def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
Jim Grosbache2a04042011-08-17 20:37:40 +00001226 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001227 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
Bill Wendling85a8a722010-11-30 00:18:30 +00001228 bits<3> Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001229 bits<8> addr;
Bill Wendling85a8a722010-11-30 00:18:30 +00001230 let Inst{10-8} = Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001231 let Inst{7-0} = addr;
Owen Andersone0152a72011-08-09 20:55:18 +00001232 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendling85a8a722010-11-30 00:18:30 +00001233}
Evan Cheng10043e22007-01-19 07:51:42 +00001234
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001235let neverHasSideEffects = 1, isReMaterializable = 1 in
1236def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001237 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001238
Jakob Stoklund Olesen74352492012-08-24 22:46:55 +00001239let hasSideEffects = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001240def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
1241 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001242 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001243
Evan Cheng10043e22007-01-19 07:51:42 +00001244//===----------------------------------------------------------------------===//
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001245// TLS Instructions
1246//
1247
1248// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbache4750ef2011-06-30 19:38:01 +00001249// This is a pseudo inst so that we can get the encoding right,
1250// complete with fixup for the aeabi_read_tp function.
1251let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson651b2302011-07-13 23:22:26 +00001252def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001253 [(set R0, ARMthread_pointer)]>,
1254 Sched<[WriteBr]>;
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001255
Bill Wendling9c258942010-12-01 02:36:55 +00001256//===----------------------------------------------------------------------===//
Jim Grosbach36d4dec2009-12-01 18:10:36 +00001257// SJLJ Exception handling intrinsics
Owen Andersonb7456232011-05-11 17:00:48 +00001258//
Bill Wendling9c258942010-12-01 02:36:55 +00001259
1260// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1261// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1262// from some other function to get here, and we're using the stack frame for the
1263// containing function to save/restore registers, we can't keep anything live in
1264// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner0ab5e2c2011-04-15 05:18:47 +00001265// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling9c258942010-12-01 02:36:55 +00001266// registers except for our own input by listing the relevant registers in
1267// Defs. By doing so, we also cause the prologue/epilogue code to actively
1268// preserve all of the callee-saved resgisters, which is exactly what we want.
1269// $val is a scratch register for our use.
Andrew Trick410172b2011-06-07 00:08:49 +00001270let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendlingaa9047d2011-10-17 22:26:23 +00001271 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1272 usesCustomInserter = 1 in
Bill Wendlingddce9f32010-11-30 00:50:22 +00001273def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson651b2302011-07-13 23:22:26 +00001274 AddrModeNone, 0, NoItinerary, "","",
Bill Wendlingddce9f32010-11-30 00:50:22 +00001275 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001276
Evan Cheng68132d82011-12-20 18:26:50 +00001277// FIXME: Non-IOS version(s)
Chris Lattner9492c172010-10-31 19:15:18 +00001278let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001279 Defs = [ R7, LR, SP ] in
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001280def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson651b2302011-07-13 23:22:26 +00001281 AddrModeNone, 0, IndexModeNone,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001282 Pseudo, NoItinerary, "", "",
1283 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
Evan Cheng68132d82011-12-20 18:26:50 +00001284 Requires<[IsThumb, IsIOS]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001285
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001286//===----------------------------------------------------------------------===//
Evan Cheng10043e22007-01-19 07:51:42 +00001287// Non-Instruction Patterns
1288//
1289
Jim Grosbach327cf8e2010-12-07 20:41:06 +00001290// Comparisons
1291def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1292 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1293def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1294 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1295
Evan Cheng61671c82009-07-10 02:09:04 +00001296// Add with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001297def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1298 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1299def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng01de9852009-08-20 17:01:04 +00001300 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwine5b969f2009-07-27 19:59:26 +00001301def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1302 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001303
1304// Subtract with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001305def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1306 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1307def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1308 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1309def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1310 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001311
Tim Northoverdfe2156c2013-11-25 14:40:57 +00001312// ConstantPool
David Goodwine5b969f2009-07-27 19:59:26 +00001313def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001314
Tim Northover72360d22013-12-02 10:35:41 +00001315// GlobalAddress
Tim Northover1328c1a2014-01-13 14:19:17 +00001316def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
Tim Northover72360d22013-12-02 10:35:41 +00001317 IIC_iLoadiALU,
Tim Northover1328c1a2014-01-13 14:19:17 +00001318 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001319 (ARMWrapperPIC tglobaladdr:$addr))]>,
1320 Requires<[IsThumb, DontUseMovt]>;
1321
Tim Northover1328c1a2014-01-13 14:19:17 +00001322def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1323 IIC_iLoad_i,
1324 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001325 (ARMWrapper tglobaladdr:$src))]>,
1326 Requires<[IsThumb, DontUseMovt]>;
1327
1328
Evan Cheng0701c5a2007-01-27 02:29:45 +00001329// JumpTable
David Goodwine5b969f2009-07-27 19:59:26 +00001330def : T1Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
1331 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001332
Evan Cheng10043e22007-01-19 07:51:42 +00001333// Direct calls
Evan Cheng175bd142009-07-29 21:26:42 +00001334def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001335 Requires<[IsThumb]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001336
1337def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001338 Requires<[IsThumb, HasV5T]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001339
1340// Indirect calls to ARM routines
Evan Cheng6ab54fd2009-08-01 00:16:10 +00001341def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001342 Requires<[IsThumb, HasV5T]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001343
1344// zextload i1 -> zextload i8
Bill Wendling092a7bd2010-12-14 03:36:38 +00001345def : T1Pat<(zextloadi1 t_addrmode_rrs1:$addr),
1346 (tLDRBr t_addrmode_rrs1:$addr)>;
1347def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1348 (tLDRBi t_addrmode_is1:$addr)>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001349
Evan Chengd02d75c2007-01-26 19:13:16 +00001350// extload -> zextload
Bill Wendling092a7bd2010-12-14 03:36:38 +00001351def : T1Pat<(extloadi1 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1352def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1353def : T1Pat<(extloadi8 t_addrmode_rrs1:$addr), (tLDRBr t_addrmode_rrs1:$addr)>;
1354def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1355def : T1Pat<(extloadi16 t_addrmode_rrs2:$addr), (tLDRHr t_addrmode_rrs2:$addr)>;
1356def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
Evan Chengd02d75c2007-01-26 19:13:16 +00001357
Evan Cheng6da267d2009-08-28 00:31:43 +00001358// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng0794c6a2009-07-11 07:08:13 +00001359// ldr{b|h} + sxt{b|h} instead.
Bill Wendling1171e9e2010-12-15 00:58:57 +00001360def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1361 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1362 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001363def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1364 (tSXTB (tLDRBr t_addrmode_rrs1:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001365 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001366def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1367 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1368 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001369def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1370 (tSXTH (tLDRHr t_addrmode_rrs2:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001371 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001372
Bill Wendling092a7bd2010-12-14 03:36:38 +00001373def : T1Pat<(sextloadi8 t_addrmode_rrs1:$addr),
1374 (tASRri (tLSLri (tLDRBr t_addrmode_rrs1:$addr), 24), 24)>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001375def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1376 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
1377def : T1Pat<(sextloadi16 t_addrmode_rrs2:$addr),
1378 (tASRri (tLSLri (tLDRHr t_addrmode_rrs2:$addr), 16), 16)>;
1379def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1380 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001381
Eli Friedmanba912e02011-09-15 22:18:49 +00001382def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001383 (tLDRBi t_addrmode_is1:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001384def : T1Pat<(atomic_load_8 t_addrmode_rrs1:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001385 (tLDRBr t_addrmode_rrs1:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001386def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001387 (tLDRHi t_addrmode_is2:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001388def : T1Pat<(atomic_load_16 t_addrmode_rrs2:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001389 (tLDRHr t_addrmode_rrs2:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001390def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001391 (tLDRi t_addrmode_is4:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001392def : T1Pat<(atomic_load_32 t_addrmode_rrs4:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001393 (tLDRr t_addrmode_rrs4:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001394def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1395 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
1396def : T1Pat<(atomic_store_8 t_addrmode_rrs1:$ptr, tGPR:$val),
1397 (tSTRBr tGPR:$val, t_addrmode_rrs1:$ptr)>;
1398def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1399 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
1400def : T1Pat<(atomic_store_16 t_addrmode_rrs2:$ptr, tGPR:$val),
1401 (tSTRHr tGPR:$val, t_addrmode_rrs2:$ptr)>;
1402def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1403 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
1404def : T1Pat<(atomic_store_32 t_addrmode_rrs4:$ptr, tGPR:$val),
1405 (tSTRr tGPR:$val, t_addrmode_rrs4:$ptr)>;
1406
Evan Cheng10043e22007-01-19 07:51:42 +00001407// Large immediate handling.
1408
1409// Two piece imms.
Evan Chengeab9ca72009-06-27 02:26:13 +00001410def : T1Pat<(i32 thumb_immshifted:$src),
1411 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1412 (thumb_immshifted_shamt imm:$src))>;
Evan Cheng10043e22007-01-19 07:51:42 +00001413
Evan Chengeab9ca72009-06-27 02:26:13 +00001414def : T1Pat<(i32 imm0_255_comp:$src),
1415 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Cheng207b2462009-11-06 23:52:48 +00001416
1417// Pseudo instruction that combines ldr from constpool and add pc. This should
1418// be expanded into two instructions late to allow if-conversion and
1419// scheduling.
1420let isReMaterializable = 1 in
1421def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling9c258942010-12-01 02:36:55 +00001422 NoItinerary,
Evan Cheng207b2462009-11-06 23:52:48 +00001423 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1424 imm:$cp))]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001425 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001426
1427// Pseudo-instruction for merged POP and return.
1428// FIXME: remove when we have a way to marking a MI with these properties.
1429let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1430 hasExtraDefRegAllocReq = 1 in
1431def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +00001432 2, IIC_iPop_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001433 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001434
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001435// Indirect branch using "mov pc, $Rm"
1436let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach39c67b52011-07-08 22:33:49 +00001437 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001438 2, IIC_Br, [(brind GPR:$Rm)],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001439 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001440}
Jim Grosbach25977222011-08-19 23:24:36 +00001441
1442
1443// In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1444// encoding is available on ARMv6K, but we don't differentiate that finely.
1445def : InstAlias<"nop", (tMOVr R8, R8, 14, 0)>,Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach08a47802011-09-20 00:10:37 +00001446
1447
1448// For round-trip assembly/disassembly, we have to handle a CPS instruction
1449// without any iflags. That's not, strictly speaking, valid syntax, but it's
Benjamin Kramerbde91762012-06-02 10:20:22 +00001450// a useful extension and assembles to defined behaviour (the insn does
Jim Grosbach08a47802011-09-20 00:10:37 +00001451// nothing).
1452def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1453def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
Jim Grosbach561e4e12011-12-13 20:23:22 +00001454
1455// "neg" is and alias for "rsb rd, rn, #0"
1456def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1457 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1458
Jim Grosbachad66de12012-04-11 00:15:16 +00001459
1460// Implied destination operand forms for shifts.
1461def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1462 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1463def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1464 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1465def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1466 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;