blob: d7e343307e72bb489433b958435fd8897b0dce89 [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
Jim Grosbach46dd4132011-08-17 21:51:27 +000018def imm_sr_XFORM: SDNodeXForm<imm, [{
19 unsigned Imm = N->getZExtValue();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000020 return CurDAG->getTargetConstant((Imm == 32 ? 0 : Imm), SDLoc(N), MVT::i32);
Jim Grosbach46dd4132011-08-17 21:51:27 +000021}]>;
22def ThumbSRImmAsmOperand: AsmOperandClass { let Name = "ImmThumbSR"; }
23def imm_sr : Operand<i32>, PatLeaf<(imm), [{
24 uint64_t Imm = N->getZExtValue();
Owen Andersonc4030382011-08-08 20:42:17 +000025 return Imm > 0 && Imm <= 32;
Jim Grosbach46dd4132011-08-17 21:51:27 +000026}], imm_sr_XFORM> {
27 let PrintMethod = "printThumbSRImm";
28 let ParserMatchClass = ThumbSRImmAsmOperand;
Owen Andersonc4030382011-08-08 20:42:17 +000029}
30
Evan Cheng10043e22007-01-19 07:51:42 +000031def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000032 return (uint32_t)-N->getZExtValue() < 8;
Evan Cheng10043e22007-01-19 07:51:42 +000033}], imm_neg_XFORM>;
34
Evan Cheng10043e22007-01-19 07:51:42 +000035def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000036 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000037}]>;
38
Eric Christophera98cd222011-04-28 05:49:04 +000039def imm8_255 : ImmLeaf<i32, [{
40 return Imm >= 8 && Imm < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000041}]>;
42def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000043 unsigned Val = -N->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +000044 return Val >= 8 && Val < 256;
45}], imm_neg_XFORM>;
46
Bill Wendling9c258942010-12-01 02:36:55 +000047// Break imm's up into two pieces: an immediate + a left shift. This uses
48// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
49// to get the val/shift pieces.
Evan Cheng10043e22007-01-19 07:51:42 +000050def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000051 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Cheng10043e22007-01-19 07:51:42 +000052}]>;
53
54def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000055 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000056 return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000057}]>;
58
59def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000060 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000061 return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000062}]>;
63
James Molloy65b6be12016-06-14 13:33:07 +000064def imm256_510 : ImmLeaf<i32, [{
65 return Imm >= 256 && Imm < 511;
James Molloyb1013832016-06-07 13:10:14 +000066}]>;
67
James Molloy65b6be12016-06-14 13:33:07 +000068def thumb_imm256_510_addend : SDNodeXForm<imm, [{
James Molloyb1013832016-06-07 13:10:14 +000069 return CurDAG->getTargetConstant(N->getZExtValue() - 255, SDLoc(N), MVT::i32);
70}]>;
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
Tim Northover3e036172016-07-11 22:29:37 +0000123
124def thumb_br_target : Operand<OtherVT> {
125 let ParserMatchClass = ThumbBranchTarget;
126 let EncoderMethod = "getThumbBranchTargetOpValue";
127 let OperandType = "OPERAND_PCREL";
Jim Grosbach78485ad2010-12-10 17:13:40 +0000128}
129
Tim Northover3e036172016-07-11 22:29:37 +0000130def thumb_bl_target : Operand<i32> {
131 let ParserMatchClass = ThumbBranchTarget;
Jim Grosbach9e199462010-12-06 23:57:07 +0000132 let EncoderMethod = "getThumbBLTargetOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000133 let DecoderMethod = "DecodeThumbBLTargetOperand";
Jim Grosbach9e199462010-12-06 23:57:07 +0000134}
135
Tim Northover3e036172016-07-11 22:29:37 +0000136// Target for BLX *from* thumb mode.
137def thumb_blx_target : Operand<i32> {
138 let ParserMatchClass = ARMBranchTarget;
Bill Wendling3392bfc2010-12-09 00:39:08 +0000139 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
Tim Northover3e036172016-07-11 22:29:37 +0000143def thumb_bcc_target : Operand<OtherVT> {
144 let ParserMatchClass = ThumbBranchTarget;
145 let EncoderMethod = "getThumbBCCTargetOpValue";
146 let DecoderMethod = "DecodeThumbBCCTargetOperand";
147}
148
149def thumb_cb_target : Operand<OtherVT> {
150 let ParserMatchClass = ThumbBranchTarget;
151 let EncoderMethod = "getThumbCBTargetOpValue";
152 let DecoderMethod = "DecodeThumbCmpBROperand";
153}
154
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000155// t_addrmode_pc := <label> => pc + imm8 * 4
156//
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000157def t_addrmode_pc : MemOperand {
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000158 let EncoderMethod = "getAddrModePCOpValue";
159 let DecoderMethod = "DecodeThumbAddrModePC";
160 let PrintMethod = "printThumbLdrLabelOperand";
161 let ParserMatchClass = ThumbMemPC;
162}
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000163}
Bill Wendling3392bfc2010-12-09 00:39:08 +0000164
Evan Cheng10043e22007-01-19 07:51:42 +0000165// t_addrmode_rr := reg + reg
166//
Jim Grosbachd3595712011-08-03 23:50:40 +0000167def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000168def t_addrmode_rr : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000169 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000170 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Cheng10043e22007-01-19 07:51:42 +0000171 let PrintMethod = "printThumbAddrModeRROperand";
Owen Anderson3157f2e2011-08-15 19:00:06 +0000172 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbach7c4739d2011-08-19 19:17:58 +0000173 let ParserMatchClass = t_addrmode_rr_asm_operand;
Jim Grosbachfde21102009-04-07 20:34:09 +0000174 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000175}
176
Bill Wendling092a7bd2010-12-14 03:36:38 +0000177// t_addrmode_rrs := reg + reg
Evan Cheng10043e22007-01-19 07:51:42 +0000178//
Jim Grosbache9380702011-08-19 16:52:32 +0000179// We use separate scaled versions because the Select* functions need
180// to explicitly check for a matching constant and return false here so that
181// the reg+imm forms will match instead. This is a horrible way to do that,
182// as it forces tight coupling between the methods, but it's how selectiondag
183// currently works.
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000184def t_addrmode_rrs1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000185 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
186 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
187 let PrintMethod = "printThumbAddrModeRROperand";
Owen Andersone0152a72011-08-09 20:55:18 +0000188 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbachd3595712011-08-03 23:50:40 +0000189 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000190 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000191}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000192def t_addrmode_rrs2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000193 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
194 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000195 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000196 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000197 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000198 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000199}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000200def t_addrmode_rrs4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000201 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
202 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000203 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000204 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000205 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000206 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000207}
Evan Chengc0b73662007-01-23 22:59:13 +0000208
Bill Wendling092a7bd2010-12-14 03:36:38 +0000209// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc0b73662007-01-23 22:59:13 +0000210//
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000211def t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000212def t_addrmode_is4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000213 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
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 = "printThumbAddrModeImm5S4Operand";
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000217 let ParserMatchClass = t_addrmode_is4_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_is2 := reg + imm5 * 2
222//
Jim Grosbach26d35872011-08-19 18:55:51 +0000223def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000224def t_addrmode_is2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000225 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
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 = "printThumbAddrModeImm5S2Operand";
Jim Grosbach26d35872011-08-19 18:55:51 +0000229 let ParserMatchClass = t_addrmode_is2_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000230 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000231}
232
233// t_addrmode_is1 := reg + imm5
234//
Jim Grosbacha32c7532011-08-19 18:49:59 +0000235def t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000236def t_addrmode_is1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000237 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
238 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000239 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000240 let PrintMethod = "printThumbAddrModeImm5S1Operand";
Jim Grosbacha32c7532011-08-19 18:49:59 +0000241 let ParserMatchClass = t_addrmode_is1_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000242 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000243}
244
245// t_addrmode_sp := sp + imm8 * 4
246//
Jim Grosbach505be7592011-08-23 18:39:41 +0000247// FIXME: This really shouldn't have an explicit SP operand at all. It should
248// be implicit, just like in the instruction encoding itself.
Jim Grosbach23983d62011-08-19 18:13:48 +0000249def t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000250def t_addrmode_sp : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000251 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000252 let EncoderMethod = "getAddrModeThumbSPOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000253 let DecoderMethod = "DecodeThumbAddrModeSP";
Evan Cheng10043e22007-01-19 07:51:42 +0000254 let PrintMethod = "printThumbAddrModeSPOperand";
Jim Grosbach23983d62011-08-19 18:13:48 +0000255 let ParserMatchClass = t_addrmode_sp_asm_operand;
Jakob Stoklund Olesena94837d2010-01-13 00:43:06 +0000256 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000257}
258
259//===----------------------------------------------------------------------===//
260// Miscellaneous Instructions.
261//
262
Jim Grosbach45fceea2010-02-22 23:10:38 +0000263// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
264// from removing one half of the matched pairs. That breaks PEI, which assumes
265// these will always be in pairs, and asserts if it finds otherwise. Better way?
266let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000267def tADJCALLSTACKUP :
Bill Wendling49a2e232010-11-19 22:02:18 +0000268 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
269 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
270 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000271
Jim Grosbach669f1d02009-03-27 23:06:27 +0000272def tADJCALLSTACKDOWN :
Bill Wendling49a2e232010-11-19 22:02:18 +0000273 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
274 [(ARMcallseq_start imm:$amt)]>,
275 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000276}
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000277
Jim Grosbach23b729e2011-08-17 23:08:57 +0000278class T1SystemEncoding<bits<8> opc>
Bill Wendling5da8cae2010-11-29 22:15:03 +0000279 : T1Encoding<0b101111> {
Jim Grosbach23b729e2011-08-17 23:08:57 +0000280 let Inst{9-8} = 0b11;
281 let Inst{7-0} = opc;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000282}
283
Saleem Abdulrasool7e7c2f92014-04-25 17:24:24 +0000284def tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
285 [(int_arm_hint imm0_15:$imm)]>,
Richard Barton87dacc32013-10-18 14:09:49 +0000286 T1SystemEncoding<0x00>,
287 Requires<[IsThumb, HasV6M]> {
288 bits<4> imm;
289 let Inst{7-4} = imm;
290}
Johnny Chen90adefc2010-02-25 03:28:51 +0000291
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000292// Note: When EmitPriority == 1, the alias will be used for printing
293class tHintAlias<string Asm, dag Result, bit EmitPriority = 0> : tInstAlias<Asm, Result, EmitPriority> {
Richard Barton87dacc32013-10-18 14:09:49 +0000294 let Predicates = [IsThumb, HasV6M];
295}
Johnny Chen74cca5a2010-02-25 17:51:03 +0000296
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000297def : tHintAlias<"nop$p", (tHINT 0, pred:$p), 1>; // A8.6.110
298def : tHintAlias<"yield$p", (tHINT 1, pred:$p), 1>; // A8.6.410
299def : tHintAlias<"wfe$p", (tHINT 2, pred:$p), 1>; // A8.6.408
300def : tHintAlias<"wfi$p", (tHINT 3, pred:$p), 1>; // A8.6.409
301def : tHintAlias<"sev$p", (tHINT 4, pred:$p), 1>; // A8.6.157
302def : tInstAlias<"sevl$p", (tHINT 5, pred:$p), 1> {
Richard Barton87dacc32013-10-18 14:09:49 +0000303 let Predicates = [IsThumb2, HasV8];
304}
Joey Goulyad98f162013-10-01 12:39:11 +0000305
Jim Grosbach23b729e2011-08-17 23:08:57 +0000306// The imm operand $val can be used by a debugger to store more information
Bill Wendling5da8cae2010-11-29 22:15:03 +0000307// about the breakpoint.
Jim Grosbach23b729e2011-08-17 23:08:57 +0000308def tBKPT : T1I<(outs), (ins imm0_255:$val), NoItinerary, "bkpt\t$val",
309 []>,
310 T1Encoding<0b101111> {
311 let Inst{9-8} = 0b10;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000312 // A8.6.22
313 bits<8> val;
314 let Inst{7-0} = val;
315}
Saleem Abdulrasool70187552013-12-23 17:23:58 +0000316// default immediate for breakpoint mnemonic
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000317def : InstAlias<"bkpt", (tBKPT 0), 0>, Requires<[IsThumb]>;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000318
Richard Barton8d519fe2013-09-05 14:14:19 +0000319def tHLT : T1I<(outs), (ins imm0_63:$val), NoItinerary, "hlt\t$val",
320 []>, T1Encoding<0b101110>, Requires<[IsThumb, HasV8]> {
321 let Inst{9-6} = 0b1010;
322 bits<6> val;
323 let Inst{5-0} = val;
324}
325
Jim Grosbach39f93882011-07-22 17:52:23 +0000326def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
Keith Walker10457172014-08-05 15:11:59 +0000327 []>, T1Encoding<0b101101>, Requires<[IsNotMClass]>, Deprecated<HasV8Ops> {
Jim Grosbach39f93882011-07-22 17:52:23 +0000328 bits<1> end;
Bill Wendling3acd0272010-11-21 10:55:23 +0000329 // A8.6.156
Johnny Chen74cca5a2010-02-25 17:51:03 +0000330 let Inst{9-5} = 0b10010;
Bill Wendling49a2e232010-11-19 22:02:18 +0000331 let Inst{4} = 1;
Jim Grosbach39f93882011-07-22 17:52:23 +0000332 let Inst{3} = end;
Bill Wendling49a2e232010-11-19 22:02:18 +0000333 let Inst{2-0} = 0b000;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000334}
335
Johnny Chen44908a52010-03-02 18:14:57 +0000336// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000337def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
Jim Grosbach4da03f02011-09-20 00:00:06 +0000338 NoItinerary, "cps$imod $iflags", []>,
Bill Wendling775899e2010-11-29 00:18:15 +0000339 T1Misc<0b0110011> {
340 // A8.6.38 & B6.1.1
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000341 bit imod;
342 bits<3> iflags;
343
344 let Inst{4} = imod;
345 let Inst{3} = 0;
346 let Inst{2-0} = iflags;
Owen Andersone0152a72011-08-09 20:55:18 +0000347 let DecoderMethod = "DecodeThumbCPS";
Bill Wendling775899e2010-11-29 00:18:15 +0000348}
Johnny Chen44908a52010-03-02 18:14:57 +0000349
Evan Cheng7cc6aca2009-08-04 23:47:55 +0000350// For both thumb1 and thumb2.
Chris Lattner9492c172010-10-31 19:15:18 +0000351let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +0000352def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendlinga82fb712010-11-19 22:37:33 +0000353 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000354 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlingddce9f32010-11-30 00:50:22 +0000355 // A8.6.6
Bill Wendlinga82fb712010-11-19 22:37:33 +0000356 bits<3> dst;
Bill Wendlingddce9f32010-11-30 00:50:22 +0000357 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendlinga82fb712010-11-19 22:37:33 +0000358 let Inst{2-0} = dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000359}
Evan Cheng10043e22007-01-19 07:51:42 +0000360
Bill Wendlinga82fb712010-11-19 22:37:33 +0000361// ADD <Rd>, sp, #<imm8>
Jakob Stoklund Olesendd2b39d2011-10-15 00:57:13 +0000362// FIXME: This should not be marked as having side effects, and it should be
363// rematerializable. Clearing the side effect bit causes miscompilations,
364// probably because the instruction can be moved around.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000365def tADDrSPi : T1pI<(outs tGPR:$dst), (ins GPRsp:$sp, t_imm0_1020s4:$imm),
366 IIC_iALUi, "add", "\t$dst, $sp, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000367 T1Encoding<{1,0,1,0,1,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000368 // A6.2 & A8.6.8
369 bits<3> dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000370 bits<8> imm;
Bill Wendlinga82fb712010-11-19 22:37:33 +0000371 let Inst{10-8} = dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000372 let Inst{7-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000373 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000374}
375
Tim Northover23075cc2014-10-20 21:28:41 +0000376// Thumb1 frame lowering is rather fragile, we hope to be able to use
377// tADDrSPi, but we may need to insert a sequence that clobbers CPSR.
378def tADDframe : PseudoInst<(outs tGPR:$dst), (ins i32imm:$base, i32imm:$offset),
379 NoItinerary, []>,
380 Requires<[IsThumb, IsThumb1Only]> {
381 let Defs = [CPSR];
382}
383
Bill Wendlinga82fb712010-11-19 22:37:33 +0000384// ADD sp, sp, #<imm7>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000385def tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
386 IIC_iALUi, "add", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000387 T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000388 // A6.2.5 & A8.6.8
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000389 bits<7> imm;
390 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000391 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000392}
Evan Chengb566ab72009-06-25 01:05:06 +0000393
Bill Wendlinga82fb712010-11-19 22:37:33 +0000394// SUB sp, sp, #<imm7>
395// FIXME: The encoding and the ASM string don't match up.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000396def tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
397 IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000398 T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000399 // A6.2.5 & A8.6.214
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000400 bits<7> imm;
401 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000402 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000403}
Evan Chengb972e562009-08-07 00:34:42 +0000404
Jim Grosbach930f2f62012-04-05 20:57:13 +0000405def : tInstAlias<"add${p} sp, $imm",
406 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
407def : tInstAlias<"add${p} sp, sp, $imm",
408 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
409
Jim Grosbach4b701af2011-08-24 21:42:27 +0000410// Can optionally specify SP as a three operand instruction.
411def : tInstAlias<"add${p} sp, sp, $imm",
412 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
413def : tInstAlias<"sub${p} sp, sp, $imm",
414 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
415
Bill Wendlinga82fb712010-11-19 22:37:33 +0000416// ADD <Rm>, sp
Jim Grosbachc6f32b32012-04-27 23:51:36 +0000417def tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
418 "add", "\t$Rdn, $sp, $Rn", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000419 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000420 // A8.6.9 Encoding T1
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000421 bits<4> Rdn;
422 let Inst{7} = Rdn{3};
Bill Wendlinga82fb712010-11-19 22:37:33 +0000423 let Inst{6-3} = 0b1101;
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000424 let Inst{2-0} = Rdn{2-0};
Owen Andersone0152a72011-08-09 20:55:18 +0000425 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000426}
Evan Chengb972e562009-08-07 00:34:42 +0000427
Bill Wendlinga82fb712010-11-19 22:37:33 +0000428// ADD sp, <Rm>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000429def tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
430 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000431 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Johnny Chenc28e6292009-12-15 17:24:14 +0000432 // A8.6.9 Encoding T2
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000433 bits<4> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000434 let Inst{7} = 1;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000435 let Inst{6-3} = Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000436 let Inst{2-0} = 0b101;
Owen Andersone0152a72011-08-09 20:55:18 +0000437 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000438}
Evan Chengb972e562009-08-07 00:34:42 +0000439
Evan Cheng10043e22007-01-19 07:51:42 +0000440//===----------------------------------------------------------------------===//
441// Control Flow Instructions.
442//
443
Bob Wilson73789b82009-10-28 18:26:41 +0000444// Indirect branches
445let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000446 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000447 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000448 // A6.2.3 & A8.6.25
449 bits<4> Rm;
450 let Inst{6-3} = Rm;
451 let Inst{2-0} = 0b000;
James Molloyd9ba4fd2012-02-09 10:56:31 +0000452 let Unpredictable{2-0} = 0b111;
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000453 }
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000454 def tBXNS : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bxns${p}\t$Rm", []>,
455 Requires<[IsThumb, Has8MSecExt]>,
456 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
457 bits<4> Rm;
458 let Inst{6-3} = Rm;
459 let Inst{2-0} = 0b100;
460 let Unpredictable{1-0} = 0b11;
461 }
Bob Wilson73789b82009-10-28 18:26:41 +0000462}
463
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000464let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson651b2302011-07-13 23:22:26 +0000465 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000466 [(ARMretflag)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000467
468 // Alternative return instruction used by vararg functions.
Jim Grosbach74719372011-07-08 21:50:04 +0000469 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000470 2, IIC_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000471 (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000472}
473
Bill Wendling9c258942010-12-01 02:36:55 +0000474// All calls clobber the non-callee saved registers. SP is marked as a use to
475// prevent stack-pointer assignments that appear immediately before calls from
476// potentially appearing dead.
Jim Grosbach669f1d02009-03-27 23:06:27 +0000477let isCall = 1,
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000478 Defs = [LR], Uses = [SP] in {
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000479 // Also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000480 def tBL : TIx2<0b11110, 0b11, 1,
Tim Northover3e036172016-07-11 22:29:37 +0000481 (outs), (ins pred:$p, thumb_bl_target:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000482 "bl${p}\t$func",
Tim Northoverb5ece522016-05-10 19:17:47 +0000483 [(ARMcall tglobaladdr:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000484 Requires<[IsThumb]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000485 bits<24> func;
486 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000487 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000488 let Inst{13} = func{22};
489 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000490 let Inst{10-0} = func{10-0};
Bill Wendling4d8ff862010-12-03 01:55:47 +0000491 }
Evan Cheng175bd142009-07-29 21:26:42 +0000492
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000493 // ARMv5T and above, also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000494 def tBLXi : TIx2<0b11110, 0b11, 0,
Tim Northover3e036172016-07-11 22:29:37 +0000495 (outs), (ins pred:$p, thumb_blx_target:$func), IIC_Br,
Tim Northoverb5ece522016-05-10 19:17:47 +0000496 "blx${p}\t$func", []>,
Keith Walker10457172014-08-05 15:11:59 +0000497 Requires<[IsThumb, HasV5T, IsNotMClass]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000498 bits<24> func;
499 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000500 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000501 let Inst{13} = func{22};
502 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000503 let Inst{10-1} = func{10-1};
504 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbache4fee202010-12-03 22:33:42 +0000505 }
Evan Cheng175bd142009-07-29 21:26:42 +0000506
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000507 // Also used for Thumb2
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000508 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000509 "blx${p}\t$func",
Tim Northoverb5ece522016-05-10 19:17:47 +0000510 [(ARMcall GPR:$func)]>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +0000511 Requires<[IsThumb, HasV5T]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000512 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
Owen Andersonb7456232011-05-11 17:00:48 +0000513 bits<4> func;
514 let Inst{6-3} = func;
515 let Inst{2-0} = 0b000;
516 }
Evan Cheng175bd142009-07-29 21:26:42 +0000517
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000518 // ARMv8-M Security Extensions
519 def tBLXNSr : TI<(outs), (ins pred:$p, GPRnopc:$func), IIC_Br,
520 "blxns${p}\t$func", []>,
521 Requires<[IsThumb, Has8MSecExt]>,
522 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> {
523 bits<4> func;
524 let Inst{6-3} = func;
525 let Inst{2-0} = 0b100;
526 let Unpredictable{1-0} = 0b11;
527 }
528
Lauro Ramos Venancio143b0df2007-03-27 16:19:21 +0000529 // ARMv4T
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000530 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
Owen Anderson651b2302011-07-13 23:22:26 +0000531 4, IIC_Br,
Evan Cheng175bd142009-07-29 21:26:42 +0000532 [(ARMcall_nolink tGPR:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000533 Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000534}
535
Bill Wendling9c258942010-12-01 02:36:55 +0000536let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
537 let isPredicable = 1 in
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000538 def tB : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
539 "b", "\t$target", [(br bb:$target)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000540 T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
Jim Grosbache119da12010-12-10 18:21:33 +0000541 bits<11> target;
542 let Inst{10-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000543 let AsmMatchConverter = "cvtThumbBranches";
544 }
Evan Cheng10043e22007-01-19 07:51:42 +0000545
Evan Cheng863736b2007-01-30 01:13:37 +0000546 // Far jump
Jim Grosbachb5743b92010-12-16 19:11:16 +0000547 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
548 // the clobber of LR.
Evan Cheng317bd7a2009-08-07 05:45:07 +0000549 let Defs = [LR] in
Tim Northover3e036172016-07-11 22:29:37 +0000550 def tBfar : tPseudoExpand<(outs), (ins thumb_bl_target:$target, pred:$p),
551 4, IIC_Br, [],
552 (tBL pred:$p, thumb_bl_target:$target)>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000553 Sched<[WriteBrTbl]>;
Evan Cheng863736b2007-01-30 01:13:37 +0000554
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000555 def tBR_JTr : tPseudoInst<(outs),
Tim Northover4998a472015-05-13 20:28:38 +0000556 (ins tGPR:$target, i32imm:$jt),
Owen Anderson651b2302011-07-13 23:22:26 +0000557 0, IIC_Br,
Tim Northover4998a472015-05-13 20:28:38 +0000558 [(ARMbrjt tGPR:$target, tjumptable:$jt)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000559 Sched<[WriteBrTbl]> {
Tim Northovera603c402015-05-31 19:22:07 +0000560 let Size = 2;
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000561 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chen466231a2009-12-16 02:32:54 +0000562 }
Evan Cheng0701c5a2007-01-27 02:29:45 +0000563}
564
Evan Chengaa3b8012007-07-05 07:13:32 +0000565// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach669f1d02009-03-27 23:06:27 +0000566// a two-value operand where a dag node expects two operands. :(
Evan Chengac1591b2007-07-21 00:34:19 +0000567let isBranch = 1, isTerminator = 1 in
Tim Northover3e036172016-07-11 22:29:37 +0000568 def tBcc : T1I<(outs), (ins thumb_bcc_target:$target, pred:$p), IIC_Br,
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000569 "b${p}\t$target",
Johnny Chenc28e6292009-12-15 17:24:14 +0000570 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000571 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000572 bits<4> p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000573 bits<8> target;
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000574 let Inst{11-8} = p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000575 let Inst{7-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000576 let AsmMatchConverter = "cvtThumbBranches";
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000577}
Evan Cheng10043e22007-01-19 07:51:42 +0000578
Mihai Popad36cbaa2013-07-03 09:21:44 +0000579
Jim Grosbach166cd882011-07-08 20:13:35 +0000580// Tail calls
581let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
Evan Cheng68132d82011-12-20 18:26:50 +0000582 // IOS versions.
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000583 let Uses = [SP] in {
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000584 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
Owen Anderson651b2302011-07-13 23:22:26 +0000585 4, IIC_Br, [],
Jim Grosbach204c1282011-07-08 20:39:19 +0000586 (tBX GPR:$dst, (ops 14, zero_reg))>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000587 Requires<[IsThumb]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000588 }
Tim Northoverd6a729b2014-01-06 14:28:05 +0000589 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
590 // on MachO), so it's in ARMInstrThumb2.td.
591 // Non-MachO version:
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000592 let Uses = [SP] in {
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000593 def tTAILJMPdND : tPseudoExpand<(outs),
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000594 (ins t_brtarget:$dst, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000595 4, IIC_Br, [],
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000596 (tB t_brtarget:$dst, pred:$p)>,
Tim Northoverd6a729b2014-01-06 14:28:05 +0000597 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000598 }
599}
600
601
Jim Grosbach5cc338d2011-08-23 19:49:10 +0000602// A8.6.218 Supervisor Call (Software Interrupt)
Johnny Chen57656da2010-02-25 02:21:11 +0000603// A8.6.16 B: Encoding T1
604// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng9a133f62010-11-29 22:43:27 +0000605let isCall = 1, Uses = [SP] in
Jim Grosbachf1637842011-07-26 16:24:27 +0000606def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000607 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000608 bits<8> imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000609 let Inst{15-12} = 0b1101;
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000610 let Inst{11-8} = 0b1111;
611 let Inst{7-0} = imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000612}
613
Bill Wendling811c9362010-11-30 07:44:32 +0000614// The assembler uses 0xDEFE for a trap instruction.
Evan Cheng2fa5a7e2010-05-11 07:26:32 +0000615let isBarrier = 1, isTerminator = 1 in
Owen Andersonb7456232011-05-11 17:00:48 +0000616def tTRAP : TI<(outs), (ins), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000617 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
Bill Wendling3acd0272010-11-21 10:55:23 +0000618 let Inst = 0xdefe;
Johnny Chen57656da2010-02-25 02:21:11 +0000619}
620
Evan Cheng10043e22007-01-19 07:51:42 +0000621//===----------------------------------------------------------------------===//
622// Load Store Instructions.
623//
624
John Brawn68acdcb2015-08-13 10:48:22 +0000625// PC-relative loads need to be matched first as constant pool accesses need to
626// always be PC-relative. We do this using AddedComplexity, as the pattern is
627// simpler than the patterns of the other load instructions.
628let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 10 in
629def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
630 "ldr", "\t$Rt, $addr",
631 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
632 T1Encoding<{0,1,0,0,1,?}> {
633 // A6.2 & A8.6.59
634 bits<3> Rt;
635 bits<8> addr;
636 let Inst{10-8} = Rt;
637 let Inst{7-0} = addr;
638}
639
640// SP-relative loads should be matched before standard immediate-offset loads as
641// it means we avoid having to move SP to another register.
642let canFoldAsLoad = 1 in
643def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
644 "ldr", "\t$Rt, $addr",
645 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
646 T1LdStSP<{1,?,?}> {
647 bits<3> Rt;
648 bits<8> addr;
649 let Inst{10-8} = Rt;
650 let Inst{7-0} = addr;
651}
652
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000653// Loads: reg/reg and reg/imm5
Dan Gohman8c5d6832010-02-27 23:47:46 +0000654let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000655multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
656 Operand AddrMode_r, Operand AddrMode_i,
657 AddrMode am, InstrItinClass itin_r,
658 InstrItinClass itin_i, string asm,
659 PatFrag opnode> {
John Brawn68acdcb2015-08-13 10:48:22 +0000660 // Immediate-offset loads should be matched before register-offset loads as
661 // when the offset is a constant it's simpler to first check if it fits in the
662 // immediate offset field then fall back to register-offset if it doesn't.
Bill Wendling5ab38b52010-12-14 23:42:48 +0000663 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000664 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
665 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
666 am, itin_i, asm, "\t$Rt, $addr",
667 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000668 // Register-offset loads are matched last.
669 def r : // reg/reg
670 T1pILdStEncode<reg_opc,
671 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
672 am, itin_r, asm, "\t$Rt, $addr",
673 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000674}
675// Stores: reg/reg and reg/imm5
676multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
677 Operand AddrMode_r, Operand AddrMode_i,
678 AddrMode am, InstrItinClass itin_r,
679 InstrItinClass itin_i, string asm,
680 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000681 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000682 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
683 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
684 am, itin_i, asm, "\t$Rt, $addr",
685 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000686 def r : // reg/reg
687 T1pILdStEncode<reg_opc,
688 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
689 am, itin_r, asm, "\t$Rt, $addr",
690 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000691}
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000692
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000693// A8.6.57 & A8.6.60
John Brawn68acdcb2015-08-13 10:48:22 +0000694defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000695 t_addrmode_is4, AddrModeT1_4,
696 IIC_iLoad_r, IIC_iLoad_i, "ldr",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000697 load>;
Evan Cheng10043e22007-01-19 07:51:42 +0000698
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000699// A8.6.64 & A8.6.61
John Brawn68acdcb2015-08-13 10:48:22 +0000700defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000701 t_addrmode_is1, AddrModeT1_1,
702 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000703 zextloadi8>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000704
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000705// A8.6.76 & A8.6.73
John Brawn68acdcb2015-08-13 10:48:22 +0000706defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000707 t_addrmode_is2, AddrModeT1_2,
708 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000709 zextloadi16>;
Evan Chengc0b73662007-01-23 22:59:13 +0000710
Evan Cheng0794c6a2009-07-11 07:08:13 +0000711let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000712def tLDRSB : // A8.6.80
Owen Anderson3157f2e2011-08-15 19:00:06 +0000713 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000714 AddrModeT1_1, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000715 "ldrsb", "\t$Rt, $addr",
716 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000717
Evan Cheng0794c6a2009-07-11 07:08:13 +0000718let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000719def tLDRSH : // A8.6.84
Owen Anderson3157f2e2011-08-15 19:00:06 +0000720 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000721 AddrModeT1_2, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000722 "ldrsh", "\t$Rt, $addr",
723 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000724
Evan Cheng10043e22007-01-19 07:51:42 +0000725
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000726def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000727 "str", "\t$Rt, $addr",
728 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000729 T1LdStSP<{0,?,?}> {
730 bits<3> Rt;
731 bits<8> addr;
732 let Inst{10-8} = Rt;
733 let Inst{7-0} = addr;
734}
Evan Chengec13f8262007-02-07 00:06:56 +0000735
John Brawn68acdcb2015-08-13 10:48:22 +0000736// A8.6.194 & A8.6.192
737defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rr,
738 t_addrmode_is4, AddrModeT1_4,
739 IIC_iStore_r, IIC_iStore_i, "str",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000740 store>;
John Brawn68acdcb2015-08-13 10:48:22 +0000741
742// A8.6.197 & A8.6.195
743defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rr,
744 t_addrmode_is1, AddrModeT1_1,
745 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000746 truncstorei8>;
John Brawn68acdcb2015-08-13 10:48:22 +0000747
748// A8.6.207 & A8.6.205
749defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rr,
750 t_addrmode_is2, AddrModeT1_2,
751 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000752 truncstorei16>;
John Brawn68acdcb2015-08-13 10:48:22 +0000753
754
Evan Cheng10043e22007-01-19 07:51:42 +0000755//===----------------------------------------------------------------------===//
756// Load / store multiple Instructions.
757//
758
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000759// These require base address to be written back or one of the loaded regs.
Craig Topperc50d64b2014-11-26 00:46:26 +0000760let hasSideEffects = 0 in {
Bill Wendling705ec772010-11-13 10:57:02 +0000761
762let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000763def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
764 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
765 bits<3> Rn;
766 bits<8> regs;
767 let Inst{10-8} = Rn;
768 let Inst{7-0} = regs;
769}
Bill Wendling705ec772010-11-13 10:57:02 +0000770
Jim Grosbache364ad52011-08-23 17:41:15 +0000771// Writeback version is just a pseudo, as there's no encoding difference.
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +0000772// Writeback happens iff the base register is not in the destination register
Jim Grosbache364ad52011-08-23 17:41:15 +0000773// list.
Scott Douglass953f9082015-10-05 14:49:54 +0000774let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000775def tLDMIA_UPD :
776 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
777 "$Rn = $wb", IIC_iLoad_mu>,
778 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
779 let Size = 2;
780 let OutOperandList = (outs GPR:$wb);
781 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
782 let Pattern = [];
783 let isCodeGenOnly = 1;
784 let isPseudo = 1;
785 list<Predicate> Predicates = [IsThumb];
786}
787
788// There is no non-writeback version of STM for Thumb.
Bill Wendling705ec772010-11-13 10:57:02 +0000789let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
Jim Grosbach6ccd79f2011-08-24 18:19:42 +0000790def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
791 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
792 AddrModeNone, 2, IIC_iStore_mu,
793 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
Jim Grosbache364ad52011-08-23 17:41:15 +0000794 T1Encoding<{1,1,0,0,0,?}> {
795 bits<3> Rn;
796 bits<8> regs;
797 let Inst{10-8} = Rn;
798 let Inst{7-0} = regs;
799}
Owen Andersonb7456232011-05-11 17:00:48 +0000800
Craig Topperc50d64b2014-11-26 00:46:26 +0000801} // hasSideEffects
Evan Chengcc9ca352009-08-11 21:11:32 +0000802
Jim Grosbach90103cc2011-08-18 21:50:53 +0000803def : InstAlias<"ldm${p} $Rn!, $regs",
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000804 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs), 0>,
Jim Grosbach90103cc2011-08-18 21:50:53 +0000805 Requires<[IsThumb, IsThumb1Only]>;
806
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000807let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling945b7762010-11-19 01:33:10 +0000808def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000809 IIC_iPop,
Bill Wendling945b7762010-11-19 01:33:10 +0000810 "pop${p}\t$regs", []>,
811 T1Misc<{1,1,0,?,?,?,?}> {
812 bits<16> regs;
Bill Wendling945b7762010-11-19 01:33:10 +0000813 let Inst{8} = regs{15};
814 let Inst{7-0} = regs{7-0};
815}
Evan Chengcc9ca352009-08-11 21:11:32 +0000816
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000817let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000818def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000819 IIC_iStore_m,
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000820 "push${p}\t$regs", []>,
821 T1Misc<{0,1,0,?,?,?,?}> {
822 bits<16> regs;
823 let Inst{8} = regs{14};
824 let Inst{7-0} = regs{7-0};
825}
Evan Cheng10043e22007-01-19 07:51:42 +0000826
827//===----------------------------------------------------------------------===//
828// Arithmetic Instructions.
829//
830
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000831// Helper classes for encoding T1pI patterns:
832class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
833 string opc, string asm, list<dag> pattern>
834 : T1pI<oops, iops, itin, opc, asm, pattern>,
835 T1DataProcessing<opA> {
836 bits<3> Rm;
837 bits<3> Rn;
838 let Inst{5-3} = Rm;
839 let Inst{2-0} = Rn;
840}
841class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
842 string opc, string asm, list<dag> pattern>
843 : T1pI<oops, iops, itin, opc, asm, pattern>,
844 T1Misc<opA> {
845 bits<3> Rm;
846 bits<3> Rd;
847 let Inst{5-3} = Rm;
848 let Inst{2-0} = Rd;
849}
850
Bill Wendling490240a2010-12-01 01:20:15 +0000851// Helper classes for encoding T1sI patterns:
852class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
853 string opc, string asm, list<dag> pattern>
854 : T1sI<oops, iops, itin, opc, asm, pattern>,
855 T1DataProcessing<opA> {
856 bits<3> Rd;
857 bits<3> Rn;
858 let Inst{5-3} = Rn;
859 let Inst{2-0} = Rd;
860}
861class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
862 string opc, string asm, list<dag> pattern>
863 : T1sI<oops, iops, itin, opc, asm, pattern>,
864 T1General<opA> {
865 bits<3> Rm;
866 bits<3> Rn;
867 bits<3> Rd;
868 let Inst{8-6} = Rm;
869 let Inst{5-3} = Rn;
870 let Inst{2-0} = Rd;
871}
872class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
873 string opc, string asm, list<dag> pattern>
874 : T1sI<oops, iops, itin, opc, asm, pattern>,
875 T1General<opA> {
876 bits<3> Rd;
877 bits<3> Rm;
878 let Inst{5-3} = Rm;
879 let Inst{2-0} = Rd;
880}
881
882// Helper classes for encoding T1sIt patterns:
Bill Wendling4915f562010-12-01 00:48:44 +0000883class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
884 string opc, string asm, list<dag> pattern>
885 : T1sIt<oops, iops, itin, opc, asm, pattern>,
886 T1DataProcessing<opA> {
Bill Wendling05632cb2010-11-30 23:54:45 +0000887 bits<3> Rdn;
888 bits<3> Rm;
Bill Wendling4915f562010-12-01 00:48:44 +0000889 let Inst{5-3} = Rm;
890 let Inst{2-0} = Rdn;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000891}
Bill Wendling4915f562010-12-01 00:48:44 +0000892class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
893 string opc, string asm, list<dag> pattern>
894 : T1sIt<oops, iops, itin, opc, asm, pattern>,
895 T1General<opA> {
896 bits<3> Rdn;
897 bits<8> imm8;
898 let Inst{10-8} = Rdn;
899 let Inst{7-0} = imm8;
900}
901
Sjoerd Meijer724023a2016-09-14 08:20:03 +0000902let isAdd = 1 in {
903 // Add with carry register
904 let isCommutable = 1, Uses = [CPSR] in
905 def tADC : // A8.6.2
906 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
907 "adc", "\t$Rdn, $Rm",
Artyom Skrobov0c93ceb2017-03-10 07:40:27 +0000908 []>, Sched<[WriteALU]>;
Evan Chengf40b9002007-01-27 00:07:15 +0000909
Sjoerd Meijer724023a2016-09-14 08:20:03 +0000910 // Add immediate
911 def tADDi3 : // A8.6.4 T1
912 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
913 IIC_iALUi,
914 "add", "\t$Rd, $Rm, $imm3",
915 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
916 Sched<[WriteALU]> {
917 bits<3> imm3;
918 let Inst{8-6} = imm3;
919 }
Evan Cheng10043e22007-01-19 07:51:42 +0000920
Sjoerd Meijer724023a2016-09-14 08:20:03 +0000921 def tADDi8 : // A8.6.4 T2
922 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
923 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
924 "add", "\t$Rdn, $imm8",
925 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
926 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000927
Sjoerd Meijer724023a2016-09-14 08:20:03 +0000928 // Add register
929 let isCommutable = 1 in
930 def tADDrr : // A8.6.6 T1
931 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
932 IIC_iALUr,
933 "add", "\t$Rd, $Rn, $Rm",
934 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000935
Artyom Skrobov0c93ceb2017-03-10 07:40:27 +0000936 /// Similar to the above except these set the 's' bit so the
937 /// instruction modifies the CPSR register.
938 ///
939 /// These opcodes will be converted to the real non-S opcodes by
940 /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
941 let hasPostISelHook = 1, Defs = [CPSR] in {
942 let isCommutable = 1 in
943 def tADCS : tPseudoInst<(outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
944 2, IIC_iALUr,
945 [(set tGPR:$Rdn, CPSR, (ARMadde tGPR:$Rn, tGPR:$Rm,
946 CPSR))]>,
947 Requires<[IsThumb1Only]>,
948 Sched<[WriteALU]>;
949
950 def tADDSi3 : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
951 2, IIC_iALUi,
952 [(set tGPR:$Rd, CPSR, (ARMaddc tGPR:$Rm,
953 imm0_7:$imm3))]>,
954 Requires<[IsThumb1Only]>,
955 Sched<[WriteALU]>;
956
957 def tADDSi8 : tPseudoInst<(outs tGPR:$Rdn), (ins tGPR:$Rn, imm0_255:$imm8),
958 2, IIC_iALUi,
959 [(set tGPR:$Rdn, CPSR, (ARMaddc tGPR:$Rn,
960 imm8_255:$imm8))]>,
961 Requires<[IsThumb1Only]>,
962 Sched<[WriteALU]>;
963
964 let isCommutable = 1 in
965 def tADDSrr : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
966 2, IIC_iALUr,
967 [(set tGPR:$Rd, CPSR, (ARMaddc tGPR:$Rn,
968 tGPR:$Rm))]>,
969 Requires<[IsThumb1Only]>,
970 Sched<[WriteALU]>;
971 }
972
Sjoerd Meijer724023a2016-09-14 08:20:03 +0000973 let hasSideEffects = 0 in
974 def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
975 "add", "\t$Rdn, $Rm", []>,
976 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
977 // A8.6.6 T2
978 bits<4> Rdn;
979 bits<4> Rm;
980 let Inst{7} = Rdn{3};
981 let Inst{6-3} = Rm;
982 let Inst{2-0} = Rdn{2-0};
983 }
Bill Wendling284326b2010-11-20 01:18:47 +0000984}
Evan Cheng10043e22007-01-19 07:51:42 +0000985
Bill Wendling284326b2010-11-20 01:18:47 +0000986// AND register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000987let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000988def tAND : // A8.6.12
989 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
990 IIC_iBITr,
991 "and", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000992 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000993
David Goodwine85169c2009-06-25 22:49:55 +0000994// ASR immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000995def tASRri : // A8.6.14
Owen Andersonc4030382011-08-08 20:42:17 +0000996 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +0000997 IIC_iMOVsi,
998 "asr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000999 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1000 Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +00001001 bits<5> imm5;
1002 let Inst{10-6} = imm5;
Bill Wendling284326b2010-11-20 01:18:47 +00001003}
Evan Cheng10043e22007-01-19 07:51:42 +00001004
David Goodwine85169c2009-06-25 22:49:55 +00001005// ASR register
Bill Wendling4915f562010-12-01 00:48:44 +00001006def tASRrr : // A8.6.15
1007 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1008 IIC_iMOVsr,
1009 "asr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001010 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001011
David Goodwine85169c2009-06-25 22:49:55 +00001012// BIC register
Bill Wendling4915f562010-12-01 00:48:44 +00001013def tBIC : // A8.6.20
1014 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1015 IIC_iBITr,
1016 "bic", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001017 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
1018 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001019
David Goodwine85169c2009-06-25 22:49:55 +00001020// CMN register
Gabor Greif22f69222010-09-14 22:00:50 +00001021let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach267430f2010-01-22 00:08:13 +00001022//FIXME: Disable CMN, as CCodes are backwards from compare expectations
1023// Compare-to-zero still works out, just not the relationals
Bill Wendling9c258942010-12-01 02:36:55 +00001024//def tCMN : // A8.6.33
1025// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
1026// IIC_iCMPr,
1027// "cmn", "\t$lhs, $rhs",
1028// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001029
1030def tCMNz : // A8.6.33
1031 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1032 IIC_iCMPr,
1033 "cmn", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001034 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001035
1036} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +00001037
David Goodwine85169c2009-06-25 22:49:55 +00001038// CMP immediate
Gabor Greif22f69222010-09-14 22:00:50 +00001039let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach4f240a12011-08-18 18:08:29 +00001040def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
Bill Wendlingc31de252010-11-20 22:52:33 +00001041 "cmp", "\t$Rn, $imm8",
1042 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001043 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendlingc31de252010-11-20 22:52:33 +00001044 // A8.6.35
1045 bits<3> Rn;
1046 bits<8> imm8;
1047 let Inst{10-8} = Rn;
1048 let Inst{7-0} = imm8;
1049}
1050
David Goodwine85169c2009-06-25 22:49:55 +00001051// CMP register
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001052def tCMPr : // A8.6.36 T1
1053 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1054 IIC_iCMPr,
1055 "cmp", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001056 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001057
Bill Wendling775899e2010-11-29 00:18:15 +00001058def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1059 "cmp", "\t$Rn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001060 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendling775899e2010-11-29 00:18:15 +00001061 // A8.6.36 T2
1062 bits<4> Rm;
1063 bits<4> Rn;
1064 let Inst{7} = Rn{3};
1065 let Inst{6-3} = Rm;
1066 let Inst{2-0} = Rn{2-0};
1067}
Bill Wendlingc31de252010-11-20 22:52:33 +00001068} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +00001069
Evan Cheng10043e22007-01-19 07:51:42 +00001070
David Goodwine85169c2009-06-25 22:49:55 +00001071// XOR register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001072let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001073def tEOR : // A8.6.45
1074 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1075 IIC_iBITr,
1076 "eor", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001077 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001078
David Goodwine85169c2009-06-25 22:49:55 +00001079// LSL immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001080def tLSLri : // A8.6.88
Jim Grosbach5503c3a2011-08-19 19:29:25 +00001081 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001082 IIC_iMOVsi,
1083 "lsl", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001084 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
1085 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001086 bits<5> imm5;
1087 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001088}
Evan Cheng10043e22007-01-19 07:51:42 +00001089
David Goodwine85169c2009-06-25 22:49:55 +00001090// LSL register
Bill Wendling4915f562010-12-01 00:48:44 +00001091def tLSLrr : // A8.6.89
1092 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1093 IIC_iMOVsr,
1094 "lsl", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001095 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001096
David Goodwine85169c2009-06-25 22:49:55 +00001097// LSR immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001098def tLSRri : // A8.6.90
Owen Andersonc4030382011-08-08 20:42:17 +00001099 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001100 IIC_iMOVsi,
1101 "lsr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001102 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1103 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001104 bits<5> imm5;
1105 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001106}
Evan Cheng10043e22007-01-19 07:51:42 +00001107
David Goodwine85169c2009-06-25 22:49:55 +00001108// LSR register
Bill Wendling4915f562010-12-01 00:48:44 +00001109def tLSRrr : // A8.6.91
1110 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1111 IIC_iMOVsr,
1112 "lsr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001113 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001114
Bill Wendling22db3132010-11-21 11:49:36 +00001115// Move register
Evan Cheng7f8ab6e2010-11-17 20:13:28 +00001116let isMoveImm = 1 in
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001117def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendling22db3132010-11-21 11:49:36 +00001118 "mov", "\t$Rd, $imm8",
1119 [(set tGPR:$Rd, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001120 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001121 // A8.6.96
1122 bits<3> Rd;
1123 bits<8> imm8;
1124 let Inst{10-8} = Rd;
1125 let Inst{7-0} = imm8;
1126}
Jim Grosbachf86cd372011-08-19 20:46:54 +00001127// Because we have an explicit tMOVSr below, we need an alias to handle
1128// the immediate "movs" form here. Blech.
Jim Grosbach6caa5572011-08-22 18:04:24 +00001129def : tInstAlias <"movs $Rdn, $imm",
1130 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001131
Jim Grosbach4def7042011-07-01 17:14:11 +00001132// A7-73: MOV(2) - mov setting flag.
Evan Cheng10043e22007-01-19 07:51:42 +00001133
Craig Topperc50d64b2014-11-26 00:46:26 +00001134let hasSideEffects = 0 in {
Jim Grosbache9cc9012011-06-30 23:38:17 +00001135def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson651b2302011-07-13 23:22:26 +00001136 2, IIC_iMOVr,
Jim Grosbachb98ab912011-06-30 22:10:46 +00001137 "mov", "\t$Rd, $Rm", "", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001138 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001139 // A8.6.97
1140 bits<4> Rd;
1141 bits<4> Rm;
Jim Grosbache9cc9012011-06-30 23:38:17 +00001142 let Inst{7} = Rd{3};
1143 let Inst{6-3} = Rm;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001144 let Inst{2-0} = Rd{2-0};
1145}
Evan Chengcd4cdd12009-07-11 06:43:01 +00001146let Defs = [CPSR] in
Bill Wendling4d8ff862010-12-03 01:55:47 +00001147def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001148 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001149 // A8.6.97
1150 bits<3> Rd;
1151 bits<3> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +00001152 let Inst{15-6} = 0b0000000000;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001153 let Inst{5-3} = Rm;
1154 let Inst{2-0} = Rd;
Johnny Chenc28e6292009-12-15 17:24:14 +00001155}
Craig Topperc50d64b2014-11-26 00:46:26 +00001156} // hasSideEffects
Evan Cheng10043e22007-01-19 07:51:42 +00001157
Bill Wendling9c258942010-12-01 02:36:55 +00001158// Multiply register
Jim Grosbachbfeb4f72011-08-22 23:25:48 +00001159let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001160def tMUL : // A8.6.105 T1
Jim Grosbach8e048492011-08-19 22:07:46 +00001161 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1162 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1163 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1164 T1DataProcessing<0b1101> {
1165 bits<3> Rd;
1166 bits<3> Rn;
1167 let Inst{5-3} = Rn;
1168 let Inst{2-0} = Rd;
1169 let AsmMatchConverter = "cvtThumbMultiply";
1170}
1171
Jim Grosbach6caa5572011-08-22 18:04:24 +00001172def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1173 pred:$p)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001174
Bill Wendling490240a2010-12-01 01:20:15 +00001175// Move inverse register
1176def tMVN : // A8.6.107
1177 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1178 "mvn", "\t$Rd, $Rn",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001179 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001180
Bill Wendling22db3132010-11-21 11:49:36 +00001181// Bitwise or register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001182let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001183def tORR : // A8.6.114
1184 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1185 IIC_iBITr,
1186 "orr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001187 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001188
Bill Wendling22db3132010-11-21 11:49:36 +00001189// Swaps
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001190def tREV : // A8.6.134
1191 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1192 IIC_iUNAr,
1193 "rev", "\t$Rd, $Rm",
1194 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001195 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001196
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001197def tREV16 : // A8.6.135
1198 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1199 IIC_iUNAr,
1200 "rev16", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001201 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001202 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001203
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001204def tREVSH : // A8.6.136
1205 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1206 IIC_iUNAr,
1207 "revsh", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001208 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001209 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001210
Bill Wendling4915f562010-12-01 00:48:44 +00001211// Rotate right register
1212def tROR : // A8.6.139
1213 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1214 IIC_iMOVsr,
1215 "ror", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001216 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1217 Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001218
Bill Wendling4915f562010-12-01 00:48:44 +00001219// Negate register
Bill Wendling490240a2010-12-01 01:20:15 +00001220def tRSB : // A8.6.141
1221 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1222 IIC_iALUi,
1223 "rsb", "\t$Rd, $Rn, #0",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001224 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001225
David Goodwine85169c2009-06-25 22:49:55 +00001226// Subtract with carry register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001227let Uses = [CPSR] in
Bill Wendling4915f562010-12-01 00:48:44 +00001228def tSBC : // A8.6.151
1229 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1230 IIC_iALUr,
1231 "sbc", "\t$Rdn, $Rm",
Artyom Skrobov0c93ceb2017-03-10 07:40:27 +00001232 []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001233 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001234
David Goodwine85169c2009-06-25 22:49:55 +00001235// Subtract immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001236def tSUBi3 : // A8.6.210 T1
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001237 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Bill Wendling490240a2010-12-01 01:20:15 +00001238 IIC_iALUi,
1239 "sub", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001240 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1241 Sched<[WriteALU]> {
Bill Wendlingccba1a82010-11-29 01:00:43 +00001242 bits<3> imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001243 let Inst{8-6} = imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001244}
Jim Grosbach669f1d02009-03-27 23:06:27 +00001245
Bill Wendling4915f562010-12-01 00:48:44 +00001246def tSUBi8 : // A8.6.210 T2
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001247 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1248 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +00001249 "sub", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001250 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1251 Sched<[WriteALU]>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001252
Bill Wendling490240a2010-12-01 01:20:15 +00001253// Subtract register
1254def tSUBrr : // A8.6.212
1255 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1256 IIC_iALUr,
1257 "sub", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001258 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1259 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001260
Artyom Skrobov0c93ceb2017-03-10 07:40:27 +00001261/// Similar to the above except these set the 's' bit so the
1262/// instruction modifies the CPSR register.
1263///
1264/// These opcodes will be converted to the real non-S opcodes by
1265/// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
1266let hasPostISelHook = 1, Defs = [CPSR] in {
1267 def tSBCS : tPseudoInst<(outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1268 2, IIC_iALUr,
1269 [(set tGPR:$Rdn, CPSR, (ARMsube tGPR:$Rn, tGPR:$Rm,
1270 CPSR))]>,
1271 Requires<[IsThumb1Only]>,
1272 Sched<[WriteALU]>;
1273
1274 def tSUBSi3 : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
1275 2, IIC_iALUi,
1276 [(set tGPR:$Rd, CPSR, (ARMsubc tGPR:$Rm,
1277 imm0_7:$imm3))]>,
1278 Requires<[IsThumb1Only]>,
1279 Sched<[WriteALU]>;
1280
1281 def tSUBSi8 : tPseudoInst<(outs tGPR:$Rdn), (ins tGPR:$Rn, imm0_255:$imm8),
1282 2, IIC_iALUi,
1283 [(set tGPR:$Rdn, CPSR, (ARMsubc tGPR:$Rn,
1284 imm8_255:$imm8))]>,
1285 Requires<[IsThumb1Only]>,
1286 Sched<[WriteALU]>;
1287
1288 def tSUBSrr : tPseudoInst<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1289 2, IIC_iALUr,
1290 [(set tGPR:$Rd, CPSR, (ARMsubc tGPR:$Rn,
1291 tGPR:$Rm))]>,
1292 Requires<[IsThumb1Only]>,
1293 Sched<[WriteALU]>;
1294}
1295
Bill Wendling490240a2010-12-01 01:20:15 +00001296// Sign-extend byte
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001297def tSXTB : // A8.6.222
1298 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1299 IIC_iUNAr,
1300 "sxtb", "\t$Rd, $Rm",
1301 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001302 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1303 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001304
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001305// Sign-extend short
1306def tSXTH : // A8.6.224
1307 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1308 IIC_iUNAr,
1309 "sxth", "\t$Rd, $Rm",
1310 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001311 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1312 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001313
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001314// Test
Gabor Greif2afac8e2010-09-14 20:47:43 +00001315let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001316def tTST : // A8.6.230
1317 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1318 "tst", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001319 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1320 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001321
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001322// A8.8.247 UDF - Undefined (Encoding T1)
Saleem Abdulrasool2bd12622014-05-22 04:46:46 +00001323def tUDF : TI<(outs), (ins imm0_255:$imm8), IIC_Br, "udf\t$imm8",
1324 [(int_arm_undefined imm0_255:$imm8)]>, Encoding16 {
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001325 bits<8> imm8;
1326 let Inst{15-12} = 0b1101;
1327 let Inst{11-8} = 0b1110;
1328 let Inst{7-0} = imm8;
1329}
1330
Saleem Abdulrasool075d2e32016-10-27 16:59:22 +00001331def t__brkdiv0 : TI<(outs), (ins), IIC_Br, "__brkdiv0",
1332 [(int_arm_undefined 249)]>, Encoding16,
1333 Requires<[IsThumb, IsWindows]> {
1334 let Inst = 0xdef9;
1335 let isTerminator = 1;
1336}
1337
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001338// Zero-extend byte
1339def tUXTB : // A8.6.262
1340 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1341 IIC_iUNAr,
1342 "uxtb", "\t$Rd, $Rm",
1343 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001344 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1345 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001346
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001347// Zero-extend short
1348def tUXTH : // A8.6.264
1349 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1350 IIC_iUNAr,
1351 "uxth", "\t$Rd, $Rm",
1352 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001353 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001354
Jim Grosbach3e2cad32010-02-16 21:23:02 +00001355// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman453d64c2009-10-29 18:10:34 +00001356// Expanded after instruction selection into a branch sequence.
1357let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Chengbb2af352009-08-12 05:17:19 +00001358 def tMOVCCr_pseudo :
Tim Northover42180442013-08-22 09:57:11 +00001359 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1360 NoItinerary,
1361 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001362
1363// tLEApcrel - Load a pc-relative address into a register without offending the
1364// assembler.
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001365
1366def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
Jim Grosbache2a04042011-08-17 20:37:40 +00001367 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001368 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
Bill Wendling85a8a722010-11-30 00:18:30 +00001369 bits<3> Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001370 bits<8> addr;
Bill Wendling85a8a722010-11-30 00:18:30 +00001371 let Inst{10-8} = Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001372 let Inst{7-0} = addr;
Owen Andersone0152a72011-08-09 20:55:18 +00001373 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendling85a8a722010-11-30 00:18:30 +00001374}
Evan Cheng10043e22007-01-19 07:51:42 +00001375
Craig Topperc50d64b2014-11-26 00:46:26 +00001376let hasSideEffects = 0, isReMaterializable = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001377def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001378 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001379
Jakob Stoklund Olesen74352492012-08-24 22:46:55 +00001380let hasSideEffects = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001381def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
Tim Northover4998a472015-05-13 20:28:38 +00001382 (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001383 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001384
James Molloy70a3d6d2016-11-01 13:37:41 +00001385// Thumb-1 doesn't have the TBB or TBH instructions, but we can synthesize them
1386// and make use of the same compressed jump table format as Thumb-2.
1387let Size = 2 in {
1388def tTBB_JT : tPseudoInst<(outs),
1389 (ins tGPR:$base, tGPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
1390 Sched<[WriteBr]>;
1391
1392def tTBH_JT : tPseudoInst<(outs),
1393 (ins tGPR:$base, tGPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
1394 Sched<[WriteBr]>;
1395}
1396
Evan Cheng10043e22007-01-19 07:51:42 +00001397//===----------------------------------------------------------------------===//
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001398// TLS Instructions
1399//
1400
1401// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbache4750ef2011-06-30 19:38:01 +00001402// This is a pseudo inst so that we can get the encoding right,
1403// complete with fixup for the aeabi_read_tp function.
1404let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson651b2302011-07-13 23:22:26 +00001405def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001406 [(set R0, ARMthread_pointer)]>,
1407 Sched<[WriteBr]>;
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001408
Bill Wendling9c258942010-12-01 02:36:55 +00001409//===----------------------------------------------------------------------===//
Jim Grosbach36d4dec2009-12-01 18:10:36 +00001410// SJLJ Exception handling intrinsics
Owen Andersonb7456232011-05-11 17:00:48 +00001411//
Bill Wendling9c258942010-12-01 02:36:55 +00001412
1413// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1414// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1415// from some other function to get here, and we're using the stack frame for the
1416// containing function to save/restore registers, we can't keep anything live in
1417// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner0ab5e2c2011-04-15 05:18:47 +00001418// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling9c258942010-12-01 02:36:55 +00001419// registers except for our own input by listing the relevant registers in
1420// Defs. By doing so, we also cause the prologue/epilogue code to actively
1421// preserve all of the callee-saved resgisters, which is exactly what we want.
1422// $val is a scratch register for our use.
Andrew Trick410172b2011-06-07 00:08:49 +00001423let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendlingaa9047d2011-10-17 22:26:23 +00001424 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1425 usesCustomInserter = 1 in
Bill Wendlingddce9f32010-11-30 00:50:22 +00001426def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson651b2302011-07-13 23:22:26 +00001427 AddrModeNone, 0, NoItinerary, "","",
Bill Wendlingddce9f32010-11-30 00:50:22 +00001428 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001429
Evan Cheng68132d82011-12-20 18:26:50 +00001430// FIXME: Non-IOS version(s)
Chris Lattner9492c172010-10-31 19:15:18 +00001431let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001432 Defs = [ R7, LR, SP ] in
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001433def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson651b2302011-07-13 23:22:26 +00001434 AddrModeNone, 0, IndexModeNone,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001435 Pseudo, NoItinerary, "", "",
1436 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
Saleem Abdulrasool1632fe12016-03-10 16:26:37 +00001437 Requires<[IsThumb,IsNotWindows]>;
1438
1439let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1440 Defs = [ R11, LR, SP ] in
1441def tInt_WIN_eh_sjlj_longjmp
1442 : XI<(outs), (ins GPR:$src, GPR:$scratch), AddrModeNone, 0, IndexModeNone,
1443 Pseudo, NoItinerary, "", "", [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1444 Requires<[IsThumb,IsWindows]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001445
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001446//===----------------------------------------------------------------------===//
Evan Cheng10043e22007-01-19 07:51:42 +00001447// Non-Instruction Patterns
1448//
1449
Jim Grosbach327cf8e2010-12-07 20:41:06 +00001450// Comparisons
1451def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1452 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1453def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1454 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1455
Evan Cheng61671c82009-07-10 02:09:04 +00001456// Subtract with carry
Artyom Skrobov0c93ceb2017-03-10 07:40:27 +00001457def : T1Pat<(ARMaddc tGPR:$lhs, imm0_7_neg:$rhs),
1458 (tSUBSi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1459def : T1Pat<(ARMaddc tGPR:$lhs, imm8_255_neg:$rhs),
1460 (tSUBSi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001461
Louis Gerbargefdcf232014-05-12 19:53:52 +00001462// Bswap 16 with load/store
Louis Gerbargefdcf232014-05-12 19:53:52 +00001463def : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
1464 (tREV16 (tLDRHi t_addrmode_is2:$addr))>;
John Brawn68acdcb2015-08-13 10:48:22 +00001465def : T1Pat<(srl (bswap (extloadi16 t_addrmode_rr:$addr)), (i32 16)),
1466 (tREV16 (tLDRHr t_addrmode_rr:$addr))>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001467def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1468 t_addrmode_is2:$addr),
1469 (tSTRHi(tREV16 tGPR:$Rn), t_addrmode_is2:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001470def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1471 t_addrmode_rr:$addr),
1472 (tSTRHr (tREV16 tGPR:$Rn), t_addrmode_rr:$addr)>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001473
Tim Northoverdfe2156c2013-11-25 14:40:57 +00001474// ConstantPool
David Goodwine5b969f2009-07-27 19:59:26 +00001475def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001476
Tim Northover72360d22013-12-02 10:35:41 +00001477// GlobalAddress
Tim Northover1328c1a2014-01-13 14:19:17 +00001478def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
Tim Northover72360d22013-12-02 10:35:41 +00001479 IIC_iLoadiALU,
Tim Northover1328c1a2014-01-13 14:19:17 +00001480 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001481 (ARMWrapperPIC tglobaladdr:$addr))]>,
1482 Requires<[IsThumb, DontUseMovt]>;
1483
Tim Northover1328c1a2014-01-13 14:19:17 +00001484def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1485 IIC_iLoad_i,
1486 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001487 (ARMWrapper tglobaladdr:$src))]>,
1488 Requires<[IsThumb, DontUseMovt]>;
1489
Tim Northoverbd41cf82016-01-07 09:03:03 +00001490// TLS globals
1491def : Pat<(ARMWrapperPIC tglobaltlsaddr:$addr),
1492 (tLDRLIT_ga_pcrel tglobaltlsaddr:$addr)>,
1493 Requires<[IsThumb, DontUseMovt]>;
1494def : Pat<(ARMWrapper tglobaltlsaddr:$addr),
1495 (tLDRLIT_ga_abs tglobaltlsaddr:$addr)>,
1496 Requires<[IsThumb, DontUseMovt]>;
1497
Tim Northover72360d22013-12-02 10:35:41 +00001498
Evan Cheng0701c5a2007-01-27 02:29:45 +00001499// JumpTable
Tim Northover4998a472015-05-13 20:28:38 +00001500def : T1Pat<(ARMWrapperJT tjumptable:$dst),
1501 (tLEApcrelJT tjumptable:$dst)>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001502
Evan Cheng10043e22007-01-19 07:51:42 +00001503// Direct calls
Tim Northoverb5ece522016-05-10 19:17:47 +00001504def : T1Pat<(ARMcall texternalsym:$func), (tBL texternalsym:$func)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001505 Requires<[IsThumb]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001506
Evan Cheng10043e22007-01-19 07:51:42 +00001507// zextload i1 -> zextload i8
Bill Wendling092a7bd2010-12-14 03:36:38 +00001508def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1509 (tLDRBi t_addrmode_is1:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001510def : T1Pat<(zextloadi1 t_addrmode_rr:$addr),
1511 (tLDRBr t_addrmode_rr:$addr)>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001512
Renato Golinb9887ef2015-02-25 14:41:06 +00001513// extload from the stack -> word load from the stack, as it avoids having to
1514// materialize the base in a separate register. This only works when a word
1515// load puts the byte/halfword value in the same place in the register that the
1516// byte/halfword load would, i.e. when little-endian.
1517def : T1Pat<(extloadi1 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1518 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1519def : T1Pat<(extloadi8 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1520 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1521def : T1Pat<(extloadi16 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1522 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1523
Evan Chengd02d75c2007-01-26 19:13:16 +00001524// extload -> zextload
John Brawn68acdcb2015-08-13 10:48:22 +00001525def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1526def : T1Pat<(extloadi1 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1527def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1528def : T1Pat<(extloadi8 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1529def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1530def : T1Pat<(extloadi16 t_addrmode_rr:$addr), (tLDRHr t_addrmode_rr:$addr)>;
Evan Chengd02d75c2007-01-26 19:13:16 +00001531
James Molloyb3326df2016-07-15 08:03:56 +00001532// post-inc loads and stores
1533
1534// post-inc LDR -> LDM r0!, {r1}. The way operands are layed out in LDMs is
1535// different to how ISel expects them for a post-inc load, so use a pseudo
1536// and expand it just after ISel.
Matthias Braun856548a2017-01-20 18:30:28 +00001537let usesCustomInserter = 1, mayLoad =1,
James Molloyb3326df2016-07-15 08:03:56 +00001538 Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in
1539 def tLDR_postidx: tPseudoInst<(outs rGPR:$Rt, rGPR:$Rn_wb),
1540 (ins rGPR:$Rn, pred:$p),
1541 4, IIC_iStore_ru,
1542 []>;
1543
1544// post-inc STR -> STM r0!, {r1}. The layout of this (because it doesn't def
1545// multiple registers) is the same in ISel as MachineInstr, so there's no need
1546// for a pseudo.
1547def : T1Pat<(post_store rGPR:$Rt, rGPR:$Rn, 4),
1548 (tSTMIA_UPD rGPR:$Rn, rGPR:$Rt)>;
1549
Evan Cheng6da267d2009-08-28 00:31:43 +00001550// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng0794c6a2009-07-11 07:08:13 +00001551// ldr{b|h} + sxt{b|h} instead.
Bill Wendling1171e9e2010-12-15 00:58:57 +00001552def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1553 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1554 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001555def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1556 (tSXTB (tLDRBr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001557 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001558def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1559 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1560 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001561def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1562 (tSXTH (tLDRHr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001563 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001564
Bill Wendling1171e9e2010-12-15 00:58:57 +00001565def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1566 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001567def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1568 (tASRri (tLSLri (tLDRBr t_addrmode_rr:$addr), 24), 24)>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001569def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1570 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001571def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1572 (tASRri (tLSLri (tLDRHr t_addrmode_rr:$addr), 16), 16)>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001573
Eli Friedmanba912e02011-09-15 22:18:49 +00001574def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001575 (tLDRBi t_addrmode_is1:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001576def : T1Pat<(atomic_load_8 t_addrmode_rr:$src),
1577 (tLDRBr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001578def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001579 (tLDRHi t_addrmode_is2:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001580def : T1Pat<(atomic_load_16 t_addrmode_rr:$src),
1581 (tLDRHr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001582def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001583 (tLDRi t_addrmode_is4:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001584def : T1Pat<(atomic_load_32 t_addrmode_rr:$src),
1585 (tLDRr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001586def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1587 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001588def : T1Pat<(atomic_store_8 t_addrmode_rr:$ptr, tGPR:$val),
1589 (tSTRBr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001590def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1591 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001592def : T1Pat<(atomic_store_16 t_addrmode_rr:$ptr, tGPR:$val),
1593 (tSTRHr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001594def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1595 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001596def : T1Pat<(atomic_store_32 t_addrmode_rr:$ptr, tGPR:$val),
1597 (tSTRr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001598
Evan Cheng10043e22007-01-19 07:51:42 +00001599// Large immediate handling.
1600
1601// Two piece imms.
Evan Chengeab9ca72009-06-27 02:26:13 +00001602def : T1Pat<(i32 thumb_immshifted:$src),
1603 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1604 (thumb_immshifted_shamt imm:$src))>;
Evan Cheng10043e22007-01-19 07:51:42 +00001605
Evan Chengeab9ca72009-06-27 02:26:13 +00001606def : T1Pat<(i32 imm0_255_comp:$src),
Artyom Skrobov94fb0bb2017-03-10 13:21:12 +00001607 (tMVN (tMOVi8 (imm_not_XFORM imm:$src)))>;
Evan Cheng207b2462009-11-06 23:52:48 +00001608
James Molloy65b6be12016-06-14 13:33:07 +00001609def : T1Pat<(i32 imm256_510:$src),
James Molloyb1013832016-06-07 13:10:14 +00001610 (tADDi8 (tMOVi8 255),
James Molloy65b6be12016-06-14 13:33:07 +00001611 (thumb_imm256_510_addend imm:$src))>;
James Molloyb1013832016-06-07 13:10:14 +00001612
Evan Cheng207b2462009-11-06 23:52:48 +00001613// Pseudo instruction that combines ldr from constpool and add pc. This should
1614// be expanded into two instructions late to allow if-conversion and
1615// scheduling.
1616let isReMaterializable = 1 in
1617def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling9c258942010-12-01 02:36:55 +00001618 NoItinerary,
Evan Cheng207b2462009-11-06 23:52:48 +00001619 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1620 imm:$cp))]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001621 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001622
1623// Pseudo-instruction for merged POP and return.
1624// FIXME: remove when we have a way to marking a MI with these properties.
1625let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1626 hasExtraDefRegAllocReq = 1 in
1627def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +00001628 2, IIC_iPop_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001629 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001630
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001631// Indirect branch using "mov pc, $Rm"
1632let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach39c67b52011-07-08 22:33:49 +00001633 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001634 2, IIC_Br, [(brind GPR:$Rm)],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001635 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001636}
Jim Grosbach25977222011-08-19 23:24:36 +00001637
1638
1639// In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1640// encoding is available on ARMv6K, but we don't differentiate that finely.
Sjoerd Meijer9da258d2016-06-03 13:19:43 +00001641def : InstAlias<"nop", (tMOVr R8, R8, 14, 0), 0>, Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach08a47802011-09-20 00:10:37 +00001642
1643
1644// For round-trip assembly/disassembly, we have to handle a CPS instruction
1645// without any iflags. That's not, strictly speaking, valid syntax, but it's
Benjamin Kramerbde91762012-06-02 10:20:22 +00001646// a useful extension and assembles to defined behaviour (the insn does
Jim Grosbach08a47802011-09-20 00:10:37 +00001647// nothing).
1648def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1649def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
Jim Grosbach561e4e12011-12-13 20:23:22 +00001650
1651// "neg" is and alias for "rsb rd, rn, #0"
1652def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1653 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1654
Jim Grosbachad66de12012-04-11 00:15:16 +00001655
1656// Implied destination operand forms for shifts.
1657def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1658 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1659def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1660 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1661def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1662 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
Renato Golin3f126132016-05-12 21:22:31 +00001663
1664// Pseudo instruction ldr Rt, =immediate
1665def tLDRConstPool
1666 : tAsmPseudo<"ldr${p} $Rt, $immediate",
1667 (ins tGPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;