blob: 8903d99128c09c17ba0dcc22de1780c9e65ac3af [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 imm_comp_XFORM : SDNodeXForm<imm, [{
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000032 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), SDLoc(N),
33 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000034}]>;
35
Evan Cheng10043e22007-01-19 07:51:42 +000036def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000037 return (uint32_t)-N->getZExtValue() < 8;
Evan Cheng10043e22007-01-19 07:51:42 +000038}], imm_neg_XFORM>;
39
Evan Cheng10043e22007-01-19 07:51:42 +000040def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000041 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000042}]>;
43
Eric Christophera98cd222011-04-28 05:49:04 +000044def imm8_255 : ImmLeaf<i32, [{
45 return Imm >= 8 && Imm < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000046}]>;
47def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000048 unsigned Val = -N->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +000049 return Val >= 8 && Val < 256;
50}], imm_neg_XFORM>;
51
Bill Wendling9c258942010-12-01 02:36:55 +000052// Break imm's up into two pieces: an immediate + a left shift. This uses
53// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
54// to get the val/shift pieces.
Evan Cheng10043e22007-01-19 07:51:42 +000055def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000056 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Cheng10043e22007-01-19 07:51:42 +000057}]>;
58
59def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000060 unsigned V = ARM_AM::getThumbImmNonShiftedVal((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
64def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000065 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000066 return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000067}]>;
68
Evan Chengb1852592009-11-19 06:57:41 +000069// Scaled 4 immediate.
Jim Grosbach0a0b3072011-08-24 21:22:15 +000070def t_imm0_1020s4_asmoperand: AsmOperandClass { let Name = "Imm0_1020s4"; }
71def t_imm0_1020s4 : Operand<i32> {
Evan Chengb1852592009-11-19 06:57:41 +000072 let PrintMethod = "printThumbS4ImmOperand";
Jim Grosbach0a0b3072011-08-24 21:22:15 +000073 let ParserMatchClass = t_imm0_1020s4_asmoperand;
74 let OperandType = "OPERAND_IMMEDIATE";
75}
76
77def t_imm0_508s4_asmoperand: AsmOperandClass { let Name = "Imm0_508s4"; }
78def t_imm0_508s4 : Operand<i32> {
79 let PrintMethod = "printThumbS4ImmOperand";
80 let ParserMatchClass = t_imm0_508s4_asmoperand;
Benjamin Kramer3ceac212011-07-14 21:47:24 +000081 let OperandType = "OPERAND_IMMEDIATE";
Evan Chengb1852592009-11-19 06:57:41 +000082}
Jim Grosbach930f2f62012-04-05 20:57:13 +000083// Alias use only, so no printer is necessary.
84def t_imm0_508s4_neg_asmoperand: AsmOperandClass { let Name = "Imm0_508s4Neg"; }
85def t_imm0_508s4_neg : Operand<i32> {
86 let ParserMatchClass = t_imm0_508s4_neg_asmoperand;
87 let OperandType = "OPERAND_IMMEDIATE";
88}
Evan Chengb1852592009-11-19 06:57:41 +000089
Evan Cheng10043e22007-01-19 07:51:42 +000090// Define Thumb specific addressing modes.
91
Mihai Popad36cbaa2013-07-03 09:21:44 +000092// unsigned 8-bit, 2-scaled memory offset
93class OperandUnsignedOffset_b8s2 : AsmOperandClass {
94 let Name = "UnsignedOffset_b8s2";
95 let PredicateMethod = "isUnsignedOffset<8, 2>";
96}
97
98def UnsignedOffset_b8s2 : OperandUnsignedOffset_b8s2;
99
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000100// thumb style PC relative operand. signed, 8 bits magnitude,
101// two bits shift. can be represented as either [pc, #imm], #imm,
102// or relocatable expression...
103def ThumbMemPC : AsmOperandClass {
104 let Name = "ThumbMemPC";
105}
106
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000107let OperandType = "OPERAND_PCREL" in {
Jim Grosbache119da12010-12-10 18:21:33 +0000108def t_brtarget : Operand<OtherVT> {
109 let EncoderMethod = "getThumbBRTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000110 let DecoderMethod = "DecodeThumbBROperand";
Jim Grosbache119da12010-12-10 18:21:33 +0000111}
112
Mihai Popad36cbaa2013-07-03 09:21:44 +0000113// ADR instruction labels.
114def t_adrlabel : Operand<i32> {
115 let EncoderMethod = "getThumbAdrLabelOpValue";
116 let PrintMethod = "printAdrLabelOperand<2>";
117 let ParserMatchClass = UnsignedOffset_b8s2;
118}
119
Jim Grosbach78485ad2010-12-10 17:13:40 +0000120def t_bcctarget : Operand<i32> {
121 let EncoderMethod = "getThumbBCCTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000122 let DecoderMethod = "DecodeThumbBCCTargetOperand";
Jim Grosbach78485ad2010-12-10 17:13:40 +0000123}
124
Jim Grosbach529c7e82010-12-09 19:01:46 +0000125def t_cbtarget : Operand<i32> {
Jim Grosbach62b68112010-12-09 19:04:53 +0000126 let EncoderMethod = "getThumbCBTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000127 let DecoderMethod = "DecodeThumbCmpBROperand";
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000128}
129
Jim Grosbach9e199462010-12-06 23:57:07 +0000130def t_bltarget : Operand<i32> {
131 let EncoderMethod = "getThumbBLTargetOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000132 let DecoderMethod = "DecodeThumbBLTargetOperand";
Jim Grosbach9e199462010-12-06 23:57:07 +0000133}
134
Bill Wendling3392bfc2010-12-09 00:39:08 +0000135def t_blxtarget : Operand<i32> {
136 let EncoderMethod = "getThumbBLXTargetOpValue";
Owen Andersonc4030382011-08-08 20:42:17 +0000137 let DecoderMethod = "DecodeThumbBLXOffset";
Bill Wendling3392bfc2010-12-09 00:39:08 +0000138}
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000139
140// t_addrmode_pc := <label> => pc + imm8 * 4
141//
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000142def t_addrmode_pc : MemOperand {
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000143 let EncoderMethod = "getAddrModePCOpValue";
144 let DecoderMethod = "DecodeThumbAddrModePC";
145 let PrintMethod = "printThumbLdrLabelOperand";
146 let ParserMatchClass = ThumbMemPC;
147}
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000148}
Bill Wendling3392bfc2010-12-09 00:39:08 +0000149
Evan Cheng10043e22007-01-19 07:51:42 +0000150// t_addrmode_rr := reg + reg
151//
Jim Grosbachd3595712011-08-03 23:50:40 +0000152def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000153def t_addrmode_rr : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000154 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000155 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Cheng10043e22007-01-19 07:51:42 +0000156 let PrintMethod = "printThumbAddrModeRROperand";
Owen Anderson3157f2e2011-08-15 19:00:06 +0000157 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbach7c4739d2011-08-19 19:17:58 +0000158 let ParserMatchClass = t_addrmode_rr_asm_operand;
Jim Grosbachfde21102009-04-07 20:34:09 +0000159 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000160}
161
Bill Wendling092a7bd2010-12-14 03:36:38 +0000162// t_addrmode_rrs := reg + reg
Evan Cheng10043e22007-01-19 07:51:42 +0000163//
Jim Grosbache9380702011-08-19 16:52:32 +0000164// We use separate scaled versions because the Select* functions need
165// to explicitly check for a matching constant and return false here so that
166// the reg+imm forms will match instead. This is a horrible way to do that,
167// as it forces tight coupling between the methods, but it's how selectiondag
168// currently works.
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000169def t_addrmode_rrs1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000170 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
171 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
172 let PrintMethod = "printThumbAddrModeRROperand";
Owen Andersone0152a72011-08-09 20:55:18 +0000173 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbachd3595712011-08-03 23:50:40 +0000174 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000175 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000176}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000177def t_addrmode_rrs2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000178 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
179 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000180 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000181 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000182 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000183 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000184}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000185def t_addrmode_rrs4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000186 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
187 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000188 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000189 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000190 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000191 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000192}
Evan Chengc0b73662007-01-23 22:59:13 +0000193
Bill Wendling092a7bd2010-12-14 03:36:38 +0000194// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc0b73662007-01-23 22:59:13 +0000195//
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000196def t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000197def t_addrmode_is4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000198 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
199 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000200 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000201 let PrintMethod = "printThumbAddrModeImm5S4Operand";
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000202 let ParserMatchClass = t_addrmode_is4_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000203 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000204}
205
206// t_addrmode_is2 := reg + imm5 * 2
207//
Jim Grosbach26d35872011-08-19 18:55:51 +0000208def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000209def t_addrmode_is2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000210 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
211 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000212 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000213 let PrintMethod = "printThumbAddrModeImm5S2Operand";
Jim Grosbach26d35872011-08-19 18:55:51 +0000214 let ParserMatchClass = t_addrmode_is2_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000215 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000216}
217
218// t_addrmode_is1 := reg + imm5
219//
Jim Grosbacha32c7532011-08-19 18:49:59 +0000220def t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000221def t_addrmode_is1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000222 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
223 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000224 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000225 let PrintMethod = "printThumbAddrModeImm5S1Operand";
Jim Grosbacha32c7532011-08-19 18:49:59 +0000226 let ParserMatchClass = t_addrmode_is1_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000227 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000228}
229
230// t_addrmode_sp := sp + imm8 * 4
231//
Jim Grosbach505be7592011-08-23 18:39:41 +0000232// FIXME: This really shouldn't have an explicit SP operand at all. It should
233// be implicit, just like in the instruction encoding itself.
Jim Grosbach23983d62011-08-19 18:13:48 +0000234def t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000235def t_addrmode_sp : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000236 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000237 let EncoderMethod = "getAddrModeThumbSPOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000238 let DecoderMethod = "DecodeThumbAddrModeSP";
Evan Cheng10043e22007-01-19 07:51:42 +0000239 let PrintMethod = "printThumbAddrModeSPOperand";
Jim Grosbach23983d62011-08-19 18:13:48 +0000240 let ParserMatchClass = t_addrmode_sp_asm_operand;
Jakob Stoklund Olesena94837d2010-01-13 00:43:06 +0000241 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000242}
243
244//===----------------------------------------------------------------------===//
245// Miscellaneous Instructions.
246//
247
Jim Grosbach45fceea2010-02-22 23:10:38 +0000248// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
249// from removing one half of the matched pairs. That breaks PEI, which assumes
250// these will always be in pairs, and asserts if it finds otherwise. Better way?
251let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000252def tADJCALLSTACKUP :
Bill Wendling49a2e232010-11-19 22:02:18 +0000253 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
254 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
255 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000256
Jim Grosbach669f1d02009-03-27 23:06:27 +0000257def tADJCALLSTACKDOWN :
Bill Wendling49a2e232010-11-19 22:02:18 +0000258 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
259 [(ARMcallseq_start imm:$amt)]>,
260 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000261}
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000262
Jim Grosbach23b729e2011-08-17 23:08:57 +0000263class T1SystemEncoding<bits<8> opc>
Bill Wendling5da8cae2010-11-29 22:15:03 +0000264 : T1Encoding<0b101111> {
Jim Grosbach23b729e2011-08-17 23:08:57 +0000265 let Inst{9-8} = 0b11;
266 let Inst{7-0} = opc;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000267}
268
Saleem Abdulrasool7e7c2f92014-04-25 17:24:24 +0000269def tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
270 [(int_arm_hint imm0_15:$imm)]>,
Richard Barton87dacc32013-10-18 14:09:49 +0000271 T1SystemEncoding<0x00>,
272 Requires<[IsThumb, HasV6M]> {
273 bits<4> imm;
274 let Inst{7-4} = imm;
275}
Johnny Chen90adefc2010-02-25 03:28:51 +0000276
Richard Barton87dacc32013-10-18 14:09:49 +0000277class tHintAlias<string Asm, dag Result> : tInstAlias<Asm, Result> {
278 let Predicates = [IsThumb, HasV6M];
279}
Johnny Chen74cca5a2010-02-25 17:51:03 +0000280
Richard Barton87dacc32013-10-18 14:09:49 +0000281def : tHintAlias<"nop$p", (tHINT 0, pred:$p)>; // A8.6.110
282def : tHintAlias<"yield$p", (tHINT 1, pred:$p)>; // A8.6.410
283def : tHintAlias<"wfe$p", (tHINT 2, pred:$p)>; // A8.6.408
284def : tHintAlias<"wfi$p", (tHINT 3, pred:$p)>; // A8.6.409
285def : tHintAlias<"sev$p", (tHINT 4, pred:$p)>; // A8.6.157
286def : tInstAlias<"sevl$p", (tHINT 5, pred:$p)> {
287 let Predicates = [IsThumb2, HasV8];
288}
Joey Goulyad98f162013-10-01 12:39:11 +0000289
Jim Grosbach23b729e2011-08-17 23:08:57 +0000290// The imm operand $val can be used by a debugger to store more information
Bill Wendling5da8cae2010-11-29 22:15:03 +0000291// about the breakpoint.
Jim Grosbach23b729e2011-08-17 23:08:57 +0000292def tBKPT : T1I<(outs), (ins imm0_255:$val), NoItinerary, "bkpt\t$val",
293 []>,
294 T1Encoding<0b101111> {
295 let Inst{9-8} = 0b10;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000296 // A8.6.22
297 bits<8> val;
298 let Inst{7-0} = val;
299}
Saleem Abdulrasool70187552013-12-23 17:23:58 +0000300// default immediate for breakpoint mnemonic
301def : InstAlias<"bkpt", (tBKPT 0)>, Requires<[IsThumb]>;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000302
Richard Barton8d519fe2013-09-05 14:14:19 +0000303def tHLT : T1I<(outs), (ins imm0_63:$val), NoItinerary, "hlt\t$val",
304 []>, T1Encoding<0b101110>, Requires<[IsThumb, HasV8]> {
305 let Inst{9-6} = 0b1010;
306 bits<6> val;
307 let Inst{5-0} = val;
308}
309
Jim Grosbach39f93882011-07-22 17:52:23 +0000310def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
Keith Walker10457172014-08-05 15:11:59 +0000311 []>, T1Encoding<0b101101>, Requires<[IsNotMClass]>, Deprecated<HasV8Ops> {
Jim Grosbach39f93882011-07-22 17:52:23 +0000312 bits<1> end;
Bill Wendling3acd0272010-11-21 10:55:23 +0000313 // A8.6.156
Johnny Chen74cca5a2010-02-25 17:51:03 +0000314 let Inst{9-5} = 0b10010;
Bill Wendling49a2e232010-11-19 22:02:18 +0000315 let Inst{4} = 1;
Jim Grosbach39f93882011-07-22 17:52:23 +0000316 let Inst{3} = end;
Bill Wendling49a2e232010-11-19 22:02:18 +0000317 let Inst{2-0} = 0b000;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000318}
319
Johnny Chen44908a52010-03-02 18:14:57 +0000320// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000321def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
Jim Grosbach4da03f02011-09-20 00:00:06 +0000322 NoItinerary, "cps$imod $iflags", []>,
Bill Wendling775899e2010-11-29 00:18:15 +0000323 T1Misc<0b0110011> {
324 // A8.6.38 & B6.1.1
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000325 bit imod;
326 bits<3> iflags;
327
328 let Inst{4} = imod;
329 let Inst{3} = 0;
330 let Inst{2-0} = iflags;
Owen Andersone0152a72011-08-09 20:55:18 +0000331 let DecoderMethod = "DecodeThumbCPS";
Bill Wendling775899e2010-11-29 00:18:15 +0000332}
Johnny Chen44908a52010-03-02 18:14:57 +0000333
Evan Cheng7cc6aca2009-08-04 23:47:55 +0000334// For both thumb1 and thumb2.
Chris Lattner9492c172010-10-31 19:15:18 +0000335let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +0000336def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendlinga82fb712010-11-19 22:37:33 +0000337 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000338 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlingddce9f32010-11-30 00:50:22 +0000339 // A8.6.6
Bill Wendlinga82fb712010-11-19 22:37:33 +0000340 bits<3> dst;
Bill Wendlingddce9f32010-11-30 00:50:22 +0000341 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendlinga82fb712010-11-19 22:37:33 +0000342 let Inst{2-0} = dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000343}
Evan Cheng10043e22007-01-19 07:51:42 +0000344
Bill Wendlinga82fb712010-11-19 22:37:33 +0000345// ADD <Rd>, sp, #<imm8>
Jakob Stoklund Olesendd2b39d2011-10-15 00:57:13 +0000346// FIXME: This should not be marked as having side effects, and it should be
347// rematerializable. Clearing the side effect bit causes miscompilations,
348// probably because the instruction can be moved around.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000349def tADDrSPi : T1pI<(outs tGPR:$dst), (ins GPRsp:$sp, t_imm0_1020s4:$imm),
350 IIC_iALUi, "add", "\t$dst, $sp, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000351 T1Encoding<{1,0,1,0,1,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000352 // A6.2 & A8.6.8
353 bits<3> dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000354 bits<8> imm;
Bill Wendlinga82fb712010-11-19 22:37:33 +0000355 let Inst{10-8} = dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000356 let Inst{7-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000357 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000358}
359
Tim Northover23075cc2014-10-20 21:28:41 +0000360// Thumb1 frame lowering is rather fragile, we hope to be able to use
361// tADDrSPi, but we may need to insert a sequence that clobbers CPSR.
362def tADDframe : PseudoInst<(outs tGPR:$dst), (ins i32imm:$base, i32imm:$offset),
363 NoItinerary, []>,
364 Requires<[IsThumb, IsThumb1Only]> {
365 let Defs = [CPSR];
366}
367
Bill Wendlinga82fb712010-11-19 22:37:33 +0000368// ADD sp, sp, #<imm7>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000369def tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
370 IIC_iALUi, "add", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000371 T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000372 // A6.2.5 & A8.6.8
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000373 bits<7> imm;
374 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000375 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000376}
Evan Chengb566ab72009-06-25 01:05:06 +0000377
Bill Wendlinga82fb712010-11-19 22:37:33 +0000378// SUB sp, sp, #<imm7>
379// FIXME: The encoding and the ASM string don't match up.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000380def tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
381 IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000382 T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000383 // A6.2.5 & A8.6.214
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000384 bits<7> imm;
385 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000386 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000387}
Evan Chengb972e562009-08-07 00:34:42 +0000388
Jim Grosbach930f2f62012-04-05 20:57:13 +0000389def : tInstAlias<"add${p} sp, $imm",
390 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
391def : tInstAlias<"add${p} sp, sp, $imm",
392 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
393
Jim Grosbach4b701af2011-08-24 21:42:27 +0000394// Can optionally specify SP as a three operand instruction.
395def : tInstAlias<"add${p} sp, sp, $imm",
396 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
397def : tInstAlias<"sub${p} sp, sp, $imm",
398 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
399
Bill Wendlinga82fb712010-11-19 22:37:33 +0000400// ADD <Rm>, sp
Jim Grosbachc6f32b32012-04-27 23:51:36 +0000401def tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
402 "add", "\t$Rdn, $sp, $Rn", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000403 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000404 // A8.6.9 Encoding T1
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000405 bits<4> Rdn;
406 let Inst{7} = Rdn{3};
Bill Wendlinga82fb712010-11-19 22:37:33 +0000407 let Inst{6-3} = 0b1101;
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000408 let Inst{2-0} = Rdn{2-0};
Owen Andersone0152a72011-08-09 20:55:18 +0000409 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000410}
Evan Chengb972e562009-08-07 00:34:42 +0000411
Bill Wendlinga82fb712010-11-19 22:37:33 +0000412// ADD sp, <Rm>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000413def tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
414 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000415 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Johnny Chenc28e6292009-12-15 17:24:14 +0000416 // A8.6.9 Encoding T2
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000417 bits<4> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000418 let Inst{7} = 1;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000419 let Inst{6-3} = Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000420 let Inst{2-0} = 0b101;
Owen Andersone0152a72011-08-09 20:55:18 +0000421 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000422}
Evan Chengb972e562009-08-07 00:34:42 +0000423
Evan Cheng10043e22007-01-19 07:51:42 +0000424//===----------------------------------------------------------------------===//
425// Control Flow Instructions.
426//
427
Bob Wilson73789b82009-10-28 18:26:41 +0000428// Indirect branches
429let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000430 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000431 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000432 // A6.2.3 & A8.6.25
433 bits<4> Rm;
434 let Inst{6-3} = Rm;
435 let Inst{2-0} = 0b000;
James Molloyd9ba4fd2012-02-09 10:56:31 +0000436 let Unpredictable{2-0} = 0b111;
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000437 }
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000438 def tBXNS : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bxns${p}\t$Rm", []>,
439 Requires<[IsThumb, Has8MSecExt]>,
440 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
441 bits<4> Rm;
442 let Inst{6-3} = Rm;
443 let Inst{2-0} = 0b100;
444 let Unpredictable{1-0} = 0b11;
445 }
Bob Wilson73789b82009-10-28 18:26:41 +0000446}
447
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000448let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson651b2302011-07-13 23:22:26 +0000449 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000450 [(ARMretflag)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000451
452 // Alternative return instruction used by vararg functions.
Jim Grosbach74719372011-07-08 21:50:04 +0000453 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000454 2, IIC_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000455 (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000456}
457
Bill Wendling9c258942010-12-01 02:36:55 +0000458// All calls clobber the non-callee saved registers. SP is marked as a use to
459// prevent stack-pointer assignments that appear immediately before calls from
460// potentially appearing dead.
Jim Grosbach669f1d02009-03-27 23:06:27 +0000461let isCall = 1,
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000462 Defs = [LR], Uses = [SP] in {
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000463 // Also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000464 def tBL : TIx2<0b11110, 0b11, 1,
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000465 (outs), (ins pred:$p, t_bltarget:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000466 "bl${p}\t$func",
Tim Northoverb5ece522016-05-10 19:17:47 +0000467 [(ARMcall tglobaladdr:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000468 Requires<[IsThumb]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000469 bits<24> func;
470 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000471 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000472 let Inst{13} = func{22};
473 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000474 let Inst{10-0} = func{10-0};
Bill Wendling4d8ff862010-12-03 01:55:47 +0000475 }
Evan Cheng175bd142009-07-29 21:26:42 +0000476
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000477 // ARMv5T and above, also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000478 def tBLXi : TIx2<0b11110, 0b11, 0,
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000479 (outs), (ins pred:$p, t_blxtarget:$func), IIC_Br,
Tim Northoverb5ece522016-05-10 19:17:47 +0000480 "blx${p}\t$func", []>,
Keith Walker10457172014-08-05 15:11:59 +0000481 Requires<[IsThumb, HasV5T, IsNotMClass]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000482 bits<24> func;
483 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000484 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000485 let Inst{13} = func{22};
486 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000487 let Inst{10-1} = func{10-1};
488 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbache4fee202010-12-03 22:33:42 +0000489 }
Evan Cheng175bd142009-07-29 21:26:42 +0000490
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000491 // Also used for Thumb2
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000492 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000493 "blx${p}\t$func",
Tim Northoverb5ece522016-05-10 19:17:47 +0000494 [(ARMcall GPR:$func)]>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +0000495 Requires<[IsThumb, HasV5T]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000496 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
Owen Andersonb7456232011-05-11 17:00:48 +0000497 bits<4> func;
498 let Inst{6-3} = func;
499 let Inst{2-0} = 0b000;
500 }
Evan Cheng175bd142009-07-29 21:26:42 +0000501
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000502 // ARMv8-M Security Extensions
503 def tBLXNSr : TI<(outs), (ins pred:$p, GPRnopc:$func), IIC_Br,
504 "blxns${p}\t$func", []>,
505 Requires<[IsThumb, Has8MSecExt]>,
506 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> {
507 bits<4> func;
508 let Inst{6-3} = func;
509 let Inst{2-0} = 0b100;
510 let Unpredictable{1-0} = 0b11;
511 }
512
Lauro Ramos Venancio143b0df2007-03-27 16:19:21 +0000513 // ARMv4T
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000514 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
Owen Anderson651b2302011-07-13 23:22:26 +0000515 4, IIC_Br,
Evan Cheng175bd142009-07-29 21:26:42 +0000516 [(ARMcall_nolink tGPR:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000517 Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000518}
519
Bill Wendling9c258942010-12-01 02:36:55 +0000520let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
521 let isPredicable = 1 in
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000522 def tB : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
523 "b", "\t$target", [(br bb:$target)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000524 T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
Jim Grosbache119da12010-12-10 18:21:33 +0000525 bits<11> target;
526 let Inst{10-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000527 let AsmMatchConverter = "cvtThumbBranches";
528 }
Evan Cheng10043e22007-01-19 07:51:42 +0000529
Evan Cheng863736b2007-01-30 01:13:37 +0000530 // Far jump
Jim Grosbachb5743b92010-12-16 19:11:16 +0000531 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
532 // the clobber of LR.
Evan Cheng317bd7a2009-08-07 05:45:07 +0000533 let Defs = [LR] in
Owen Anderson64d53622011-07-18 18:50:52 +0000534 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000535 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>,
536 Sched<[WriteBrTbl]>;
Evan Cheng863736b2007-01-30 01:13:37 +0000537
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000538 def tBR_JTr : tPseudoInst<(outs),
Tim Northover4998a472015-05-13 20:28:38 +0000539 (ins tGPR:$target, i32imm:$jt),
Owen Anderson651b2302011-07-13 23:22:26 +0000540 0, IIC_Br,
Tim Northover4998a472015-05-13 20:28:38 +0000541 [(ARMbrjt tGPR:$target, tjumptable:$jt)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000542 Sched<[WriteBrTbl]> {
Tim Northovera603c402015-05-31 19:22:07 +0000543 let Size = 2;
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000544 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chen466231a2009-12-16 02:32:54 +0000545 }
Evan Cheng0701c5a2007-01-27 02:29:45 +0000546}
547
Evan Chengaa3b8012007-07-05 07:13:32 +0000548// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach669f1d02009-03-27 23:06:27 +0000549// a two-value operand where a dag node expects two operands. :(
Evan Chengac1591b2007-07-21 00:34:19 +0000550let isBranch = 1, isTerminator = 1 in
Jim Grosbach78485ad2010-12-10 17:13:40 +0000551 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000552 "b${p}\t$target",
Johnny Chenc28e6292009-12-15 17:24:14 +0000553 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000554 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000555 bits<4> p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000556 bits<8> target;
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000557 let Inst{11-8} = p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000558 let Inst{7-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000559 let AsmMatchConverter = "cvtThumbBranches";
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000560}
Evan Cheng10043e22007-01-19 07:51:42 +0000561
Mihai Popad36cbaa2013-07-03 09:21:44 +0000562
Jim Grosbach166cd882011-07-08 20:13:35 +0000563// Tail calls
564let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
Evan Cheng68132d82011-12-20 18:26:50 +0000565 // IOS versions.
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000566 let Uses = [SP] in {
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000567 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
Owen Anderson651b2302011-07-13 23:22:26 +0000568 4, IIC_Br, [],
Jim Grosbach204c1282011-07-08 20:39:19 +0000569 (tBX GPR:$dst, (ops 14, zero_reg))>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000570 Requires<[IsThumb]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000571 }
Tim Northoverd6a729b2014-01-06 14:28:05 +0000572 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
573 // on MachO), so it's in ARMInstrThumb2.td.
574 // Non-MachO version:
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000575 let Uses = [SP] in {
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000576 def tTAILJMPdND : tPseudoExpand<(outs),
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000577 (ins t_brtarget:$dst, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000578 4, IIC_Br, [],
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000579 (tB t_brtarget:$dst, pred:$p)>,
Tim Northoverd6a729b2014-01-06 14:28:05 +0000580 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000581 }
582}
583
584
Jim Grosbach5cc338d2011-08-23 19:49:10 +0000585// A8.6.218 Supervisor Call (Software Interrupt)
Johnny Chen57656da2010-02-25 02:21:11 +0000586// A8.6.16 B: Encoding T1
587// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng9a133f62010-11-29 22:43:27 +0000588let isCall = 1, Uses = [SP] in
Jim Grosbachf1637842011-07-26 16:24:27 +0000589def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000590 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000591 bits<8> imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000592 let Inst{15-12} = 0b1101;
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000593 let Inst{11-8} = 0b1111;
594 let Inst{7-0} = imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000595}
596
Bill Wendling811c9362010-11-30 07:44:32 +0000597// The assembler uses 0xDEFE for a trap instruction.
Evan Cheng2fa5a7e2010-05-11 07:26:32 +0000598let isBarrier = 1, isTerminator = 1 in
Owen Andersonb7456232011-05-11 17:00:48 +0000599def tTRAP : TI<(outs), (ins), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000600 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
Bill Wendling3acd0272010-11-21 10:55:23 +0000601 let Inst = 0xdefe;
Johnny Chen57656da2010-02-25 02:21:11 +0000602}
603
Evan Cheng10043e22007-01-19 07:51:42 +0000604//===----------------------------------------------------------------------===//
605// Load Store Instructions.
606//
607
John Brawn68acdcb2015-08-13 10:48:22 +0000608// PC-relative loads need to be matched first as constant pool accesses need to
609// always be PC-relative. We do this using AddedComplexity, as the pattern is
610// simpler than the patterns of the other load instructions.
611let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 10 in
612def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
613 "ldr", "\t$Rt, $addr",
614 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
615 T1Encoding<{0,1,0,0,1,?}> {
616 // A6.2 & A8.6.59
617 bits<3> Rt;
618 bits<8> addr;
619 let Inst{10-8} = Rt;
620 let Inst{7-0} = addr;
621}
622
623// SP-relative loads should be matched before standard immediate-offset loads as
624// it means we avoid having to move SP to another register.
625let canFoldAsLoad = 1 in
626def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
627 "ldr", "\t$Rt, $addr",
628 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
629 T1LdStSP<{1,?,?}> {
630 bits<3> Rt;
631 bits<8> addr;
632 let Inst{10-8} = Rt;
633 let Inst{7-0} = addr;
634}
635
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000636// Loads: reg/reg and reg/imm5
Dan Gohman8c5d6832010-02-27 23:47:46 +0000637let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000638multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
639 Operand AddrMode_r, Operand AddrMode_i,
640 AddrMode am, InstrItinClass itin_r,
641 InstrItinClass itin_i, string asm,
642 PatFrag opnode> {
John Brawn68acdcb2015-08-13 10:48:22 +0000643 // Immediate-offset loads should be matched before register-offset loads as
644 // when the offset is a constant it's simpler to first check if it fits in the
645 // immediate offset field then fall back to register-offset if it doesn't.
Bill Wendling5ab38b52010-12-14 23:42:48 +0000646 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000647 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
648 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
649 am, itin_i, asm, "\t$Rt, $addr",
650 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000651 // Register-offset loads are matched last.
652 def r : // reg/reg
653 T1pILdStEncode<reg_opc,
654 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
655 am, itin_r, asm, "\t$Rt, $addr",
656 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000657}
658// Stores: reg/reg and reg/imm5
659multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
660 Operand AddrMode_r, Operand AddrMode_i,
661 AddrMode am, InstrItinClass itin_r,
662 InstrItinClass itin_i, string asm,
663 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000664 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000665 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
666 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
667 am, itin_i, asm, "\t$Rt, $addr",
668 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000669 def r : // reg/reg
670 T1pILdStEncode<reg_opc,
671 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
672 am, itin_r, asm, "\t$Rt, $addr",
673 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000674}
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000675
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000676// A8.6.57 & A8.6.60
John Brawn68acdcb2015-08-13 10:48:22 +0000677defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000678 t_addrmode_is4, AddrModeT1_4,
679 IIC_iLoad_r, IIC_iLoad_i, "ldr",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000680 load>;
Evan Cheng10043e22007-01-19 07:51:42 +0000681
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000682// A8.6.64 & A8.6.61
John Brawn68acdcb2015-08-13 10:48:22 +0000683defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000684 t_addrmode_is1, AddrModeT1_1,
685 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000686 zextloadi8>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000687
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000688// A8.6.76 & A8.6.73
John Brawn68acdcb2015-08-13 10:48:22 +0000689defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000690 t_addrmode_is2, AddrModeT1_2,
691 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000692 zextloadi16>;
Evan Chengc0b73662007-01-23 22:59:13 +0000693
Evan Cheng0794c6a2009-07-11 07:08:13 +0000694let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000695def tLDRSB : // A8.6.80
Owen Anderson3157f2e2011-08-15 19:00:06 +0000696 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000697 AddrModeT1_1, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000698 "ldrsb", "\t$Rt, $addr",
699 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000700
Evan Cheng0794c6a2009-07-11 07:08:13 +0000701let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000702def tLDRSH : // A8.6.84
Owen Anderson3157f2e2011-08-15 19:00:06 +0000703 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000704 AddrModeT1_2, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000705 "ldrsh", "\t$Rt, $addr",
706 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000707
Evan Cheng10043e22007-01-19 07:51:42 +0000708
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000709def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000710 "str", "\t$Rt, $addr",
711 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000712 T1LdStSP<{0,?,?}> {
713 bits<3> Rt;
714 bits<8> addr;
715 let Inst{10-8} = Rt;
716 let Inst{7-0} = addr;
717}
Evan Chengec13f8262007-02-07 00:06:56 +0000718
John Brawn68acdcb2015-08-13 10:48:22 +0000719// A8.6.194 & A8.6.192
720defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rr,
721 t_addrmode_is4, AddrModeT1_4,
722 IIC_iStore_r, IIC_iStore_i, "str",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000723 store>;
John Brawn68acdcb2015-08-13 10:48:22 +0000724
725// A8.6.197 & A8.6.195
726defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rr,
727 t_addrmode_is1, AddrModeT1_1,
728 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000729 truncstorei8>;
John Brawn68acdcb2015-08-13 10:48:22 +0000730
731// A8.6.207 & A8.6.205
732defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rr,
733 t_addrmode_is2, AddrModeT1_2,
734 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000735 truncstorei16>;
John Brawn68acdcb2015-08-13 10:48:22 +0000736
737
Evan Cheng10043e22007-01-19 07:51:42 +0000738//===----------------------------------------------------------------------===//
739// Load / store multiple Instructions.
740//
741
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000742// These require base address to be written back or one of the loaded regs.
Craig Topperc50d64b2014-11-26 00:46:26 +0000743let hasSideEffects = 0 in {
Bill Wendling705ec772010-11-13 10:57:02 +0000744
745let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000746def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
747 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
748 bits<3> Rn;
749 bits<8> regs;
750 let Inst{10-8} = Rn;
751 let Inst{7-0} = regs;
752}
Bill Wendling705ec772010-11-13 10:57:02 +0000753
Jim Grosbache364ad52011-08-23 17:41:15 +0000754// Writeback version is just a pseudo, as there's no encoding difference.
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +0000755// Writeback happens iff the base register is not in the destination register
Jim Grosbache364ad52011-08-23 17:41:15 +0000756// list.
Scott Douglass953f9082015-10-05 14:49:54 +0000757let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000758def tLDMIA_UPD :
759 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
760 "$Rn = $wb", IIC_iLoad_mu>,
761 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
762 let Size = 2;
763 let OutOperandList = (outs GPR:$wb);
764 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
765 let Pattern = [];
766 let isCodeGenOnly = 1;
767 let isPseudo = 1;
768 list<Predicate> Predicates = [IsThumb];
769}
770
771// There is no non-writeback version of STM for Thumb.
Bill Wendling705ec772010-11-13 10:57:02 +0000772let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
Jim Grosbach6ccd79f2011-08-24 18:19:42 +0000773def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
774 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
775 AddrModeNone, 2, IIC_iStore_mu,
776 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
Jim Grosbache364ad52011-08-23 17:41:15 +0000777 T1Encoding<{1,1,0,0,0,?}> {
778 bits<3> Rn;
779 bits<8> regs;
780 let Inst{10-8} = Rn;
781 let Inst{7-0} = regs;
782}
Owen Andersonb7456232011-05-11 17:00:48 +0000783
Craig Topperc50d64b2014-11-26 00:46:26 +0000784} // hasSideEffects
Evan Chengcc9ca352009-08-11 21:11:32 +0000785
Jim Grosbach90103cc2011-08-18 21:50:53 +0000786def : InstAlias<"ldm${p} $Rn!, $regs",
787 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)>,
788 Requires<[IsThumb, IsThumb1Only]>;
789
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000790let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling945b7762010-11-19 01:33:10 +0000791def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000792 IIC_iPop,
Bill Wendling945b7762010-11-19 01:33:10 +0000793 "pop${p}\t$regs", []>,
794 T1Misc<{1,1,0,?,?,?,?}> {
795 bits<16> regs;
Bill Wendling945b7762010-11-19 01:33:10 +0000796 let Inst{8} = regs{15};
797 let Inst{7-0} = regs{7-0};
798}
Evan Chengcc9ca352009-08-11 21:11:32 +0000799
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000800let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000801def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000802 IIC_iStore_m,
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000803 "push${p}\t$regs", []>,
804 T1Misc<{0,1,0,?,?,?,?}> {
805 bits<16> regs;
806 let Inst{8} = regs{14};
807 let Inst{7-0} = regs{7-0};
808}
Evan Cheng10043e22007-01-19 07:51:42 +0000809
810//===----------------------------------------------------------------------===//
811// Arithmetic Instructions.
812//
813
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000814// Helper classes for encoding T1pI patterns:
815class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
816 string opc, string asm, list<dag> pattern>
817 : T1pI<oops, iops, itin, opc, asm, pattern>,
818 T1DataProcessing<opA> {
819 bits<3> Rm;
820 bits<3> Rn;
821 let Inst{5-3} = Rm;
822 let Inst{2-0} = Rn;
823}
824class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
825 string opc, string asm, list<dag> pattern>
826 : T1pI<oops, iops, itin, opc, asm, pattern>,
827 T1Misc<opA> {
828 bits<3> Rm;
829 bits<3> Rd;
830 let Inst{5-3} = Rm;
831 let Inst{2-0} = Rd;
832}
833
Bill Wendling490240a2010-12-01 01:20:15 +0000834// Helper classes for encoding T1sI patterns:
835class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
836 string opc, string asm, list<dag> pattern>
837 : T1sI<oops, iops, itin, opc, asm, pattern>,
838 T1DataProcessing<opA> {
839 bits<3> Rd;
840 bits<3> Rn;
841 let Inst{5-3} = Rn;
842 let Inst{2-0} = Rd;
843}
844class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
845 string opc, string asm, list<dag> pattern>
846 : T1sI<oops, iops, itin, opc, asm, pattern>,
847 T1General<opA> {
848 bits<3> Rm;
849 bits<3> Rn;
850 bits<3> Rd;
851 let Inst{8-6} = Rm;
852 let Inst{5-3} = Rn;
853 let Inst{2-0} = Rd;
854}
855class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
856 string opc, string asm, list<dag> pattern>
857 : T1sI<oops, iops, itin, opc, asm, pattern>,
858 T1General<opA> {
859 bits<3> Rd;
860 bits<3> Rm;
861 let Inst{5-3} = Rm;
862 let Inst{2-0} = Rd;
863}
864
865// Helper classes for encoding T1sIt patterns:
Bill Wendling4915f562010-12-01 00:48:44 +0000866class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
867 string opc, string asm, list<dag> pattern>
868 : T1sIt<oops, iops, itin, opc, asm, pattern>,
869 T1DataProcessing<opA> {
Bill Wendling05632cb2010-11-30 23:54:45 +0000870 bits<3> Rdn;
871 bits<3> Rm;
Bill Wendling4915f562010-12-01 00:48:44 +0000872 let Inst{5-3} = Rm;
873 let Inst{2-0} = Rdn;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000874}
Bill Wendling4915f562010-12-01 00:48:44 +0000875class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
876 string opc, string asm, list<dag> pattern>
877 : T1sIt<oops, iops, itin, opc, asm, pattern>,
878 T1General<opA> {
879 bits<3> Rdn;
880 bits<8> imm8;
881 let Inst{10-8} = Rdn;
882 let Inst{7-0} = imm8;
883}
884
885// Add with carry register
886let isCommutable = 1, Uses = [CPSR] in
887def tADC : // A8.6.2
888 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
889 "adc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000890 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Chengf40b9002007-01-27 00:07:15 +0000891
David Goodwine85169c2009-06-25 22:49:55 +0000892// Add immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000893def tADDi3 : // A8.6.4 T1
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000894 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000895 IIC_iALUi,
Bill Wendling490240a2010-12-01 01:20:15 +0000896 "add", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000897 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
898 Sched<[WriteALU]> {
Bill Wendlingfe1de032010-11-20 01:00:29 +0000899 bits<3> imm3;
900 let Inst{8-6} = imm3;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000901}
Evan Cheng10043e22007-01-19 07:51:42 +0000902
Bill Wendling4915f562010-12-01 00:48:44 +0000903def tADDi8 : // A8.6.4 T2
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000904 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
905 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +0000906 "add", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000907 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
908 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000909
David Goodwine85169c2009-06-25 22:49:55 +0000910// Add register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000911let isCommutable = 1 in
Bill Wendling490240a2010-12-01 01:20:15 +0000912def tADDrr : // A8.6.6 T1
913 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
914 IIC_iALUr,
915 "add", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000916 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000917
Craig Topperc50d64b2014-11-26 00:46:26 +0000918let hasSideEffects = 0 in
Bill Wendling7c646b92010-12-01 01:32:02 +0000919def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
920 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000921 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000922 // A8.6.6 T2
Bill Wendling7c646b92010-12-01 01:32:02 +0000923 bits<4> Rdn;
924 bits<4> Rm;
925 let Inst{7} = Rdn{3};
926 let Inst{6-3} = Rm;
927 let Inst{2-0} = Rdn{2-0};
Bill Wendling284326b2010-11-20 01:18:47 +0000928}
Evan Cheng10043e22007-01-19 07:51:42 +0000929
Bill Wendling284326b2010-11-20 01:18:47 +0000930// AND register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000931let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000932def tAND : // A8.6.12
933 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
934 IIC_iBITr,
935 "and", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000936 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000937
David Goodwine85169c2009-06-25 22:49:55 +0000938// ASR immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000939def tASRri : // A8.6.14
Owen Andersonc4030382011-08-08 20:42:17 +0000940 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +0000941 IIC_iMOVsi,
942 "asr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000943 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
944 Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000945 bits<5> imm5;
946 let Inst{10-6} = imm5;
Bill Wendling284326b2010-11-20 01:18:47 +0000947}
Evan Cheng10043e22007-01-19 07:51:42 +0000948
David Goodwine85169c2009-06-25 22:49:55 +0000949// ASR register
Bill Wendling4915f562010-12-01 00:48:44 +0000950def tASRrr : // A8.6.15
951 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
952 IIC_iMOVsr,
953 "asr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000954 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000955
David Goodwine85169c2009-06-25 22:49:55 +0000956// BIC register
Bill Wendling4915f562010-12-01 00:48:44 +0000957def tBIC : // A8.6.20
958 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
959 IIC_iBITr,
960 "bic", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000961 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
962 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000963
David Goodwine85169c2009-06-25 22:49:55 +0000964// CMN register
Gabor Greif22f69222010-09-14 22:00:50 +0000965let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach267430f2010-01-22 00:08:13 +0000966//FIXME: Disable CMN, as CCodes are backwards from compare expectations
967// Compare-to-zero still works out, just not the relationals
Bill Wendling9c258942010-12-01 02:36:55 +0000968//def tCMN : // A8.6.33
969// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
970// IIC_iCMPr,
971// "cmn", "\t$lhs, $rhs",
972// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000973
974def tCMNz : // A8.6.33
975 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
976 IIC_iCMPr,
977 "cmn", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000978 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000979
980} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +0000981
David Goodwine85169c2009-06-25 22:49:55 +0000982// CMP immediate
Gabor Greif22f69222010-09-14 22:00:50 +0000983let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach4f240a12011-08-18 18:08:29 +0000984def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
Bill Wendlingc31de252010-11-20 22:52:33 +0000985 "cmp", "\t$Rn, $imm8",
986 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000987 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendlingc31de252010-11-20 22:52:33 +0000988 // A8.6.35
989 bits<3> Rn;
990 bits<8> imm8;
991 let Inst{10-8} = Rn;
992 let Inst{7-0} = imm8;
993}
994
David Goodwine85169c2009-06-25 22:49:55 +0000995// CMP register
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000996def tCMPr : // A8.6.36 T1
997 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
998 IIC_iCMPr,
999 "cmp", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001000 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001001
Bill Wendling775899e2010-11-29 00:18:15 +00001002def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1003 "cmp", "\t$Rn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001004 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendling775899e2010-11-29 00:18:15 +00001005 // A8.6.36 T2
1006 bits<4> Rm;
1007 bits<4> Rn;
1008 let Inst{7} = Rn{3};
1009 let Inst{6-3} = Rm;
1010 let Inst{2-0} = Rn{2-0};
1011}
Bill Wendlingc31de252010-11-20 22:52:33 +00001012} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +00001013
Evan Cheng10043e22007-01-19 07:51:42 +00001014
David Goodwine85169c2009-06-25 22:49:55 +00001015// XOR register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001016let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001017def tEOR : // A8.6.45
1018 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1019 IIC_iBITr,
1020 "eor", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001021 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001022
David Goodwine85169c2009-06-25 22:49:55 +00001023// LSL immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001024def tLSLri : // A8.6.88
Jim Grosbach5503c3a2011-08-19 19:29:25 +00001025 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001026 IIC_iMOVsi,
1027 "lsl", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001028 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
1029 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001030 bits<5> imm5;
1031 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001032}
Evan Cheng10043e22007-01-19 07:51:42 +00001033
David Goodwine85169c2009-06-25 22:49:55 +00001034// LSL register
Bill Wendling4915f562010-12-01 00:48:44 +00001035def tLSLrr : // A8.6.89
1036 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1037 IIC_iMOVsr,
1038 "lsl", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001039 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001040
David Goodwine85169c2009-06-25 22:49:55 +00001041// LSR immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001042def tLSRri : // A8.6.90
Owen Andersonc4030382011-08-08 20:42:17 +00001043 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001044 IIC_iMOVsi,
1045 "lsr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001046 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1047 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001048 bits<5> imm5;
1049 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001050}
Evan Cheng10043e22007-01-19 07:51:42 +00001051
David Goodwine85169c2009-06-25 22:49:55 +00001052// LSR register
Bill Wendling4915f562010-12-01 00:48:44 +00001053def tLSRrr : // A8.6.91
1054 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1055 IIC_iMOVsr,
1056 "lsr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001057 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001058
Bill Wendling22db3132010-11-21 11:49:36 +00001059// Move register
Evan Cheng7f8ab6e2010-11-17 20:13:28 +00001060let isMoveImm = 1 in
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001061def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendling22db3132010-11-21 11:49:36 +00001062 "mov", "\t$Rd, $imm8",
1063 [(set tGPR:$Rd, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001064 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001065 // A8.6.96
1066 bits<3> Rd;
1067 bits<8> imm8;
1068 let Inst{10-8} = Rd;
1069 let Inst{7-0} = imm8;
1070}
Jim Grosbachf86cd372011-08-19 20:46:54 +00001071// Because we have an explicit tMOVSr below, we need an alias to handle
1072// the immediate "movs" form here. Blech.
Jim Grosbach6caa5572011-08-22 18:04:24 +00001073def : tInstAlias <"movs $Rdn, $imm",
1074 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001075
Jim Grosbach4def7042011-07-01 17:14:11 +00001076// A7-73: MOV(2) - mov setting flag.
Evan Cheng10043e22007-01-19 07:51:42 +00001077
Craig Topperc50d64b2014-11-26 00:46:26 +00001078let hasSideEffects = 0 in {
Jim Grosbache9cc9012011-06-30 23:38:17 +00001079def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson651b2302011-07-13 23:22:26 +00001080 2, IIC_iMOVr,
Jim Grosbachb98ab912011-06-30 22:10:46 +00001081 "mov", "\t$Rd, $Rm", "", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001082 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001083 // A8.6.97
1084 bits<4> Rd;
1085 bits<4> Rm;
Jim Grosbache9cc9012011-06-30 23:38:17 +00001086 let Inst{7} = Rd{3};
1087 let Inst{6-3} = Rm;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001088 let Inst{2-0} = Rd{2-0};
1089}
Evan Chengcd4cdd12009-07-11 06:43:01 +00001090let Defs = [CPSR] in
Bill Wendling4d8ff862010-12-03 01:55:47 +00001091def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001092 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001093 // A8.6.97
1094 bits<3> Rd;
1095 bits<3> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +00001096 let Inst{15-6} = 0b0000000000;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001097 let Inst{5-3} = Rm;
1098 let Inst{2-0} = Rd;
Johnny Chenc28e6292009-12-15 17:24:14 +00001099}
Craig Topperc50d64b2014-11-26 00:46:26 +00001100} // hasSideEffects
Evan Cheng10043e22007-01-19 07:51:42 +00001101
Bill Wendling9c258942010-12-01 02:36:55 +00001102// Multiply register
Jim Grosbachbfeb4f72011-08-22 23:25:48 +00001103let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001104def tMUL : // A8.6.105 T1
Jim Grosbach8e048492011-08-19 22:07:46 +00001105 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1106 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1107 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1108 T1DataProcessing<0b1101> {
1109 bits<3> Rd;
1110 bits<3> Rn;
1111 let Inst{5-3} = Rn;
1112 let Inst{2-0} = Rd;
1113 let AsmMatchConverter = "cvtThumbMultiply";
1114}
1115
Jim Grosbach6caa5572011-08-22 18:04:24 +00001116def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1117 pred:$p)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001118
Bill Wendling490240a2010-12-01 01:20:15 +00001119// Move inverse register
1120def tMVN : // A8.6.107
1121 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1122 "mvn", "\t$Rd, $Rn",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001123 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001124
Bill Wendling22db3132010-11-21 11:49:36 +00001125// Bitwise or register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001126let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001127def tORR : // A8.6.114
1128 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1129 IIC_iBITr,
1130 "orr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001131 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001132
Bill Wendling22db3132010-11-21 11:49:36 +00001133// Swaps
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001134def tREV : // A8.6.134
1135 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1136 IIC_iUNAr,
1137 "rev", "\t$Rd, $Rm",
1138 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001139 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001140
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001141def tREV16 : // A8.6.135
1142 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1143 IIC_iUNAr,
1144 "rev16", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001145 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001146 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001147
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001148def tREVSH : // A8.6.136
1149 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1150 IIC_iUNAr,
1151 "revsh", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001152 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001153 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001154
Bill Wendling4915f562010-12-01 00:48:44 +00001155// Rotate right register
1156def tROR : // A8.6.139
1157 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1158 IIC_iMOVsr,
1159 "ror", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001160 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1161 Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001162
Bill Wendling4915f562010-12-01 00:48:44 +00001163// Negate register
Bill Wendling490240a2010-12-01 01:20:15 +00001164def tRSB : // A8.6.141
1165 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1166 IIC_iALUi,
1167 "rsb", "\t$Rd, $Rn, #0",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001168 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001169
David Goodwine85169c2009-06-25 22:49:55 +00001170// Subtract with carry register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001171let Uses = [CPSR] in
Bill Wendling4915f562010-12-01 00:48:44 +00001172def tSBC : // A8.6.151
1173 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1174 IIC_iALUr,
1175 "sbc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001176 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>,
1177 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001178
David Goodwine85169c2009-06-25 22:49:55 +00001179// Subtract immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001180def tSUBi3 : // A8.6.210 T1
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001181 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Bill Wendling490240a2010-12-01 01:20:15 +00001182 IIC_iALUi,
1183 "sub", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001184 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1185 Sched<[WriteALU]> {
Bill Wendlingccba1a82010-11-29 01:00:43 +00001186 bits<3> imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001187 let Inst{8-6} = imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001188}
Jim Grosbach669f1d02009-03-27 23:06:27 +00001189
Bill Wendling4915f562010-12-01 00:48:44 +00001190def tSUBi8 : // A8.6.210 T2
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001191 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1192 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +00001193 "sub", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001194 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1195 Sched<[WriteALU]>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001196
Bill Wendling490240a2010-12-01 01:20:15 +00001197// Subtract register
1198def tSUBrr : // A8.6.212
1199 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1200 IIC_iALUr,
1201 "sub", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001202 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1203 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001204
Bill Wendling490240a2010-12-01 01:20:15 +00001205// Sign-extend byte
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001206def tSXTB : // A8.6.222
1207 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1208 IIC_iUNAr,
1209 "sxtb", "\t$Rd, $Rm",
1210 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001211 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1212 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001213
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001214// Sign-extend short
1215def tSXTH : // A8.6.224
1216 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1217 IIC_iUNAr,
1218 "sxth", "\t$Rd, $Rm",
1219 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001220 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1221 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001222
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001223// Test
Gabor Greif2afac8e2010-09-14 20:47:43 +00001224let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001225def tTST : // A8.6.230
1226 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1227 "tst", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001228 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1229 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001230
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001231// A8.8.247 UDF - Undefined (Encoding T1)
Saleem Abdulrasool2bd12622014-05-22 04:46:46 +00001232def tUDF : TI<(outs), (ins imm0_255:$imm8), IIC_Br, "udf\t$imm8",
1233 [(int_arm_undefined imm0_255:$imm8)]>, Encoding16 {
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001234 bits<8> imm8;
1235 let Inst{15-12} = 0b1101;
1236 let Inst{11-8} = 0b1110;
1237 let Inst{7-0} = imm8;
1238}
1239
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001240// Zero-extend byte
1241def tUXTB : // A8.6.262
1242 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1243 IIC_iUNAr,
1244 "uxtb", "\t$Rd, $Rm",
1245 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001246 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1247 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001248
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001249// Zero-extend short
1250def tUXTH : // A8.6.264
1251 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1252 IIC_iUNAr,
1253 "uxth", "\t$Rd, $Rm",
1254 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001255 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001256
Jim Grosbach3e2cad32010-02-16 21:23:02 +00001257// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman453d64c2009-10-29 18:10:34 +00001258// Expanded after instruction selection into a branch sequence.
1259let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Chengbb2af352009-08-12 05:17:19 +00001260 def tMOVCCr_pseudo :
Tim Northover42180442013-08-22 09:57:11 +00001261 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1262 NoItinerary,
1263 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001264
1265// tLEApcrel - Load a pc-relative address into a register without offending the
1266// assembler.
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001267
1268def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
Jim Grosbache2a04042011-08-17 20:37:40 +00001269 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001270 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
Bill Wendling85a8a722010-11-30 00:18:30 +00001271 bits<3> Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001272 bits<8> addr;
Bill Wendling85a8a722010-11-30 00:18:30 +00001273 let Inst{10-8} = Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001274 let Inst{7-0} = addr;
Owen Andersone0152a72011-08-09 20:55:18 +00001275 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendling85a8a722010-11-30 00:18:30 +00001276}
Evan Cheng10043e22007-01-19 07:51:42 +00001277
Craig Topperc50d64b2014-11-26 00:46:26 +00001278let hasSideEffects = 0, isReMaterializable = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001279def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001280 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001281
Jakob Stoklund Olesen74352492012-08-24 22:46:55 +00001282let hasSideEffects = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001283def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
Tim Northover4998a472015-05-13 20:28:38 +00001284 (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001285 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001286
Evan Cheng10043e22007-01-19 07:51:42 +00001287//===----------------------------------------------------------------------===//
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001288// TLS Instructions
1289//
1290
1291// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbache4750ef2011-06-30 19:38:01 +00001292// This is a pseudo inst so that we can get the encoding right,
1293// complete with fixup for the aeabi_read_tp function.
1294let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson651b2302011-07-13 23:22:26 +00001295def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001296 [(set R0, ARMthread_pointer)]>,
1297 Sched<[WriteBr]>;
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001298
Bill Wendling9c258942010-12-01 02:36:55 +00001299//===----------------------------------------------------------------------===//
Jim Grosbach36d4dec2009-12-01 18:10:36 +00001300// SJLJ Exception handling intrinsics
Owen Andersonb7456232011-05-11 17:00:48 +00001301//
Bill Wendling9c258942010-12-01 02:36:55 +00001302
1303// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1304// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1305// from some other function to get here, and we're using the stack frame for the
1306// containing function to save/restore registers, we can't keep anything live in
1307// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner0ab5e2c2011-04-15 05:18:47 +00001308// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling9c258942010-12-01 02:36:55 +00001309// registers except for our own input by listing the relevant registers in
1310// Defs. By doing so, we also cause the prologue/epilogue code to actively
1311// preserve all of the callee-saved resgisters, which is exactly what we want.
1312// $val is a scratch register for our use.
Andrew Trick410172b2011-06-07 00:08:49 +00001313let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendlingaa9047d2011-10-17 22:26:23 +00001314 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1315 usesCustomInserter = 1 in
Bill Wendlingddce9f32010-11-30 00:50:22 +00001316def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson651b2302011-07-13 23:22:26 +00001317 AddrModeNone, 0, NoItinerary, "","",
Bill Wendlingddce9f32010-11-30 00:50:22 +00001318 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001319
Evan Cheng68132d82011-12-20 18:26:50 +00001320// FIXME: Non-IOS version(s)
Chris Lattner9492c172010-10-31 19:15:18 +00001321let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001322 Defs = [ R7, LR, SP ] in
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001323def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson651b2302011-07-13 23:22:26 +00001324 AddrModeNone, 0, IndexModeNone,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001325 Pseudo, NoItinerary, "", "",
1326 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
Saleem Abdulrasool1632fe12016-03-10 16:26:37 +00001327 Requires<[IsThumb,IsNotWindows]>;
1328
1329let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1330 Defs = [ R11, LR, SP ] in
1331def tInt_WIN_eh_sjlj_longjmp
1332 : XI<(outs), (ins GPR:$src, GPR:$scratch), AddrModeNone, 0, IndexModeNone,
1333 Pseudo, NoItinerary, "", "", [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1334 Requires<[IsThumb,IsWindows]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001335
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001336//===----------------------------------------------------------------------===//
Evan Cheng10043e22007-01-19 07:51:42 +00001337// Non-Instruction Patterns
1338//
1339
Jim Grosbach327cf8e2010-12-07 20:41:06 +00001340// Comparisons
1341def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1342 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1343def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1344 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1345
Evan Cheng61671c82009-07-10 02:09:04 +00001346// Add with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001347def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1348 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1349def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng01de9852009-08-20 17:01:04 +00001350 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwine5b969f2009-07-27 19:59:26 +00001351def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1352 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001353
1354// Subtract with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001355def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1356 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1357def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1358 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1359def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1360 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001361
Louis Gerbargefdcf232014-05-12 19:53:52 +00001362// Bswap 16 with load/store
Louis Gerbargefdcf232014-05-12 19:53:52 +00001363def : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
1364 (tREV16 (tLDRHi t_addrmode_is2:$addr))>;
John Brawn68acdcb2015-08-13 10:48:22 +00001365def : T1Pat<(srl (bswap (extloadi16 t_addrmode_rr:$addr)), (i32 16)),
1366 (tREV16 (tLDRHr t_addrmode_rr:$addr))>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001367def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1368 t_addrmode_is2:$addr),
1369 (tSTRHi(tREV16 tGPR:$Rn), t_addrmode_is2:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001370def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1371 t_addrmode_rr:$addr),
1372 (tSTRHr (tREV16 tGPR:$Rn), t_addrmode_rr:$addr)>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001373
Tim Northoverdfe2156c2013-11-25 14:40:57 +00001374// ConstantPool
David Goodwine5b969f2009-07-27 19:59:26 +00001375def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001376
Tim Northover72360d22013-12-02 10:35:41 +00001377// GlobalAddress
Tim Northover1328c1a2014-01-13 14:19:17 +00001378def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
Tim Northover72360d22013-12-02 10:35:41 +00001379 IIC_iLoadiALU,
Tim Northover1328c1a2014-01-13 14:19:17 +00001380 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001381 (ARMWrapperPIC tglobaladdr:$addr))]>,
1382 Requires<[IsThumb, DontUseMovt]>;
1383
Tim Northover1328c1a2014-01-13 14:19:17 +00001384def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1385 IIC_iLoad_i,
1386 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001387 (ARMWrapper tglobaladdr:$src))]>,
1388 Requires<[IsThumb, DontUseMovt]>;
1389
Tim Northoverbd41cf82016-01-07 09:03:03 +00001390// TLS globals
1391def : Pat<(ARMWrapperPIC tglobaltlsaddr:$addr),
1392 (tLDRLIT_ga_pcrel tglobaltlsaddr:$addr)>,
1393 Requires<[IsThumb, DontUseMovt]>;
1394def : Pat<(ARMWrapper tglobaltlsaddr:$addr),
1395 (tLDRLIT_ga_abs tglobaltlsaddr:$addr)>,
1396 Requires<[IsThumb, DontUseMovt]>;
1397
Tim Northover72360d22013-12-02 10:35:41 +00001398
Evan Cheng0701c5a2007-01-27 02:29:45 +00001399// JumpTable
Tim Northover4998a472015-05-13 20:28:38 +00001400def : T1Pat<(ARMWrapperJT tjumptable:$dst),
1401 (tLEApcrelJT tjumptable:$dst)>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001402
Evan Cheng10043e22007-01-19 07:51:42 +00001403// Direct calls
Tim Northoverb5ece522016-05-10 19:17:47 +00001404def : T1Pat<(ARMcall texternalsym:$func), (tBL texternalsym:$func)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001405 Requires<[IsThumb]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001406
Evan Cheng10043e22007-01-19 07:51:42 +00001407
1408// Indirect calls to ARM routines
Evan Cheng6ab54fd2009-08-01 00:16:10 +00001409def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001410 Requires<[IsThumb, HasV5T]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001411
1412// zextload i1 -> zextload i8
Bill Wendling092a7bd2010-12-14 03:36:38 +00001413def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1414 (tLDRBi t_addrmode_is1:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001415def : T1Pat<(zextloadi1 t_addrmode_rr:$addr),
1416 (tLDRBr t_addrmode_rr:$addr)>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001417
Renato Golinb9887ef2015-02-25 14:41:06 +00001418// extload from the stack -> word load from the stack, as it avoids having to
1419// materialize the base in a separate register. This only works when a word
1420// load puts the byte/halfword value in the same place in the register that the
1421// byte/halfword load would, i.e. when little-endian.
1422def : T1Pat<(extloadi1 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1423 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1424def : T1Pat<(extloadi8 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1425 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1426def : T1Pat<(extloadi16 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1427 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1428
Evan Chengd02d75c2007-01-26 19:13:16 +00001429// extload -> zextload
John Brawn68acdcb2015-08-13 10:48:22 +00001430def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1431def : T1Pat<(extloadi1 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1432def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1433def : T1Pat<(extloadi8 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1434def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1435def : T1Pat<(extloadi16 t_addrmode_rr:$addr), (tLDRHr t_addrmode_rr:$addr)>;
Evan Chengd02d75c2007-01-26 19:13:16 +00001436
Evan Cheng6da267d2009-08-28 00:31:43 +00001437// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng0794c6a2009-07-11 07:08:13 +00001438// ldr{b|h} + sxt{b|h} instead.
Bill Wendling1171e9e2010-12-15 00:58:57 +00001439def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1440 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1441 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001442def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1443 (tSXTB (tLDRBr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001444 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001445def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1446 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1447 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001448def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1449 (tSXTH (tLDRHr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001450 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001451
Bill Wendling1171e9e2010-12-15 00:58:57 +00001452def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1453 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001454def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1455 (tASRri (tLSLri (tLDRBr t_addrmode_rr:$addr), 24), 24)>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001456def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1457 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001458def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1459 (tASRri (tLSLri (tLDRHr t_addrmode_rr:$addr), 16), 16)>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001460
Eli Friedmanba912e02011-09-15 22:18:49 +00001461def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001462 (tLDRBi t_addrmode_is1:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001463def : T1Pat<(atomic_load_8 t_addrmode_rr:$src),
1464 (tLDRBr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001465def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001466 (tLDRHi t_addrmode_is2:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001467def : T1Pat<(atomic_load_16 t_addrmode_rr:$src),
1468 (tLDRHr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001469def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001470 (tLDRi t_addrmode_is4:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001471def : T1Pat<(atomic_load_32 t_addrmode_rr:$src),
1472 (tLDRr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001473def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1474 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001475def : T1Pat<(atomic_store_8 t_addrmode_rr:$ptr, tGPR:$val),
1476 (tSTRBr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001477def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1478 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001479def : T1Pat<(atomic_store_16 t_addrmode_rr:$ptr, tGPR:$val),
1480 (tSTRHr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001481def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1482 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001483def : T1Pat<(atomic_store_32 t_addrmode_rr:$ptr, tGPR:$val),
1484 (tSTRr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001485
Evan Cheng10043e22007-01-19 07:51:42 +00001486// Large immediate handling.
1487
1488// Two piece imms.
Evan Chengeab9ca72009-06-27 02:26:13 +00001489def : T1Pat<(i32 thumb_immshifted:$src),
1490 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1491 (thumb_immshifted_shamt imm:$src))>;
Evan Cheng10043e22007-01-19 07:51:42 +00001492
Evan Chengeab9ca72009-06-27 02:26:13 +00001493def : T1Pat<(i32 imm0_255_comp:$src),
1494 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Cheng207b2462009-11-06 23:52:48 +00001495
1496// Pseudo instruction that combines ldr from constpool and add pc. This should
1497// be expanded into two instructions late to allow if-conversion and
1498// scheduling.
1499let isReMaterializable = 1 in
1500def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling9c258942010-12-01 02:36:55 +00001501 NoItinerary,
Evan Cheng207b2462009-11-06 23:52:48 +00001502 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1503 imm:$cp))]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001504 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001505
1506// Pseudo-instruction for merged POP and return.
1507// FIXME: remove when we have a way to marking a MI with these properties.
1508let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1509 hasExtraDefRegAllocReq = 1 in
1510def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +00001511 2, IIC_iPop_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001512 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001513
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001514// Indirect branch using "mov pc, $Rm"
1515let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach39c67b52011-07-08 22:33:49 +00001516 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001517 2, IIC_Br, [(brind GPR:$Rm)],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001518 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001519}
Jim Grosbach25977222011-08-19 23:24:36 +00001520
1521
1522// In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1523// encoding is available on ARMv6K, but we don't differentiate that finely.
1524def : InstAlias<"nop", (tMOVr R8, R8, 14, 0)>,Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach08a47802011-09-20 00:10:37 +00001525
1526
1527// For round-trip assembly/disassembly, we have to handle a CPS instruction
1528// without any iflags. That's not, strictly speaking, valid syntax, but it's
Benjamin Kramerbde91762012-06-02 10:20:22 +00001529// a useful extension and assembles to defined behaviour (the insn does
Jim Grosbach08a47802011-09-20 00:10:37 +00001530// nothing).
1531def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1532def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
Jim Grosbach561e4e12011-12-13 20:23:22 +00001533
1534// "neg" is and alias for "rsb rd, rn, #0"
1535def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1536 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1537
Jim Grosbachad66de12012-04-11 00:15:16 +00001538
1539// Implied destination operand forms for shifts.
1540def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1541 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1542def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1543 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1544def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1545 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
Renato Golin3f126132016-05-12 21:22:31 +00001546
1547// Pseudo instruction ldr Rt, =immediate
1548def tLDRConstPool
1549 : tAsmPseudo<"ldr${p} $Rt, $immediate",
1550 (ins tGPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;