blob: 5d4698f6a8badd237e6a1e590ec1676f2454c889 [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
James Molloy65b6be12016-06-14 13:33:07 +000069def imm256_510 : ImmLeaf<i32, [{
70 return Imm >= 256 && Imm < 511;
James Molloyb1013832016-06-07 13:10:14 +000071}]>;
72
James Molloy65b6be12016-06-14 13:33:07 +000073def thumb_imm256_510_addend : SDNodeXForm<imm, [{
James Molloyb1013832016-06-07 13:10:14 +000074 return CurDAG->getTargetConstant(N->getZExtValue() - 255, SDLoc(N), MVT::i32);
75}]>;
76
Evan Chengb1852592009-11-19 06:57:41 +000077// Scaled 4 immediate.
Jim Grosbach0a0b3072011-08-24 21:22:15 +000078def t_imm0_1020s4_asmoperand: AsmOperandClass { let Name = "Imm0_1020s4"; }
79def t_imm0_1020s4 : Operand<i32> {
Evan Chengb1852592009-11-19 06:57:41 +000080 let PrintMethod = "printThumbS4ImmOperand";
Jim Grosbach0a0b3072011-08-24 21:22:15 +000081 let ParserMatchClass = t_imm0_1020s4_asmoperand;
82 let OperandType = "OPERAND_IMMEDIATE";
83}
84
85def t_imm0_508s4_asmoperand: AsmOperandClass { let Name = "Imm0_508s4"; }
86def t_imm0_508s4 : Operand<i32> {
87 let PrintMethod = "printThumbS4ImmOperand";
88 let ParserMatchClass = t_imm0_508s4_asmoperand;
Benjamin Kramer3ceac212011-07-14 21:47:24 +000089 let OperandType = "OPERAND_IMMEDIATE";
Evan Chengb1852592009-11-19 06:57:41 +000090}
Jim Grosbach930f2f62012-04-05 20:57:13 +000091// Alias use only, so no printer is necessary.
92def t_imm0_508s4_neg_asmoperand: AsmOperandClass { let Name = "Imm0_508s4Neg"; }
93def t_imm0_508s4_neg : Operand<i32> {
94 let ParserMatchClass = t_imm0_508s4_neg_asmoperand;
95 let OperandType = "OPERAND_IMMEDIATE";
96}
Evan Chengb1852592009-11-19 06:57:41 +000097
Evan Cheng10043e22007-01-19 07:51:42 +000098// Define Thumb specific addressing modes.
99
Mihai Popad36cbaa2013-07-03 09:21:44 +0000100// unsigned 8-bit, 2-scaled memory offset
101class OperandUnsignedOffset_b8s2 : AsmOperandClass {
102 let Name = "UnsignedOffset_b8s2";
103 let PredicateMethod = "isUnsignedOffset<8, 2>";
104}
105
106def UnsignedOffset_b8s2 : OperandUnsignedOffset_b8s2;
107
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000108// thumb style PC relative operand. signed, 8 bits magnitude,
109// two bits shift. can be represented as either [pc, #imm], #imm,
110// or relocatable expression...
111def ThumbMemPC : AsmOperandClass {
112 let Name = "ThumbMemPC";
113}
114
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000115let OperandType = "OPERAND_PCREL" in {
Jim Grosbache119da12010-12-10 18:21:33 +0000116def t_brtarget : Operand<OtherVT> {
117 let EncoderMethod = "getThumbBRTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000118 let DecoderMethod = "DecodeThumbBROperand";
Jim Grosbache119da12010-12-10 18:21:33 +0000119}
120
Mihai Popad36cbaa2013-07-03 09:21:44 +0000121// ADR instruction labels.
122def t_adrlabel : Operand<i32> {
123 let EncoderMethod = "getThumbAdrLabelOpValue";
124 let PrintMethod = "printAdrLabelOperand<2>";
125 let ParserMatchClass = UnsignedOffset_b8s2;
126}
127
Jim Grosbach78485ad2010-12-10 17:13:40 +0000128def t_bcctarget : Operand<i32> {
129 let EncoderMethod = "getThumbBCCTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000130 let DecoderMethod = "DecodeThumbBCCTargetOperand";
Jim Grosbach78485ad2010-12-10 17:13:40 +0000131}
132
Jim Grosbach529c7e82010-12-09 19:01:46 +0000133def t_cbtarget : Operand<i32> {
Jim Grosbach62b68112010-12-09 19:04:53 +0000134 let EncoderMethod = "getThumbCBTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000135 let DecoderMethod = "DecodeThumbCmpBROperand";
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000136}
137
Jim Grosbach9e199462010-12-06 23:57:07 +0000138def t_bltarget : Operand<i32> {
139 let EncoderMethod = "getThumbBLTargetOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000140 let DecoderMethod = "DecodeThumbBLTargetOperand";
Jim Grosbach9e199462010-12-06 23:57:07 +0000141}
142
Bill Wendling3392bfc2010-12-09 00:39:08 +0000143def t_blxtarget : Operand<i32> {
144 let EncoderMethod = "getThumbBLXTargetOpValue";
Owen Andersonc4030382011-08-08 20:42:17 +0000145 let DecoderMethod = "DecodeThumbBLXOffset";
Bill Wendling3392bfc2010-12-09 00:39:08 +0000146}
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000147
148// t_addrmode_pc := <label> => pc + imm8 * 4
149//
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000150def t_addrmode_pc : MemOperand {
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000151 let EncoderMethod = "getAddrModePCOpValue";
152 let DecoderMethod = "DecodeThumbAddrModePC";
153 let PrintMethod = "printThumbLdrLabelOperand";
154 let ParserMatchClass = ThumbMemPC;
155}
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000156}
Bill Wendling3392bfc2010-12-09 00:39:08 +0000157
Evan Cheng10043e22007-01-19 07:51:42 +0000158// t_addrmode_rr := reg + reg
159//
Jim Grosbachd3595712011-08-03 23:50:40 +0000160def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000161def t_addrmode_rr : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000162 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000163 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Cheng10043e22007-01-19 07:51:42 +0000164 let PrintMethod = "printThumbAddrModeRROperand";
Owen Anderson3157f2e2011-08-15 19:00:06 +0000165 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbach7c4739d2011-08-19 19:17:58 +0000166 let ParserMatchClass = t_addrmode_rr_asm_operand;
Jim Grosbachfde21102009-04-07 20:34:09 +0000167 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000168}
169
Bill Wendling092a7bd2010-12-14 03:36:38 +0000170// t_addrmode_rrs := reg + reg
Evan Cheng10043e22007-01-19 07:51:42 +0000171//
Jim Grosbache9380702011-08-19 16:52:32 +0000172// We use separate scaled versions because the Select* functions need
173// to explicitly check for a matching constant and return false here so that
174// the reg+imm forms will match instead. This is a horrible way to do that,
175// as it forces tight coupling between the methods, but it's how selectiondag
176// currently works.
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000177def t_addrmode_rrs1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000178 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
179 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
180 let PrintMethod = "printThumbAddrModeRROperand";
Owen Andersone0152a72011-08-09 20:55:18 +0000181 let DecoderMethod = "DecodeThumbAddrModeRR";
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);
Evan Cheng10043e22007-01-19 07:51:42 +0000184}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000185def t_addrmode_rrs2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000186 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
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);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000192}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000193def t_addrmode_rrs4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000194 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
195 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000196 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000197 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000198 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000199 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000200}
Evan Chengc0b73662007-01-23 22:59:13 +0000201
Bill Wendling092a7bd2010-12-14 03:36:38 +0000202// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc0b73662007-01-23 22:59:13 +0000203//
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000204def t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000205def t_addrmode_is4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000206 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
207 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000208 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000209 let PrintMethod = "printThumbAddrModeImm5S4Operand";
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000210 let ParserMatchClass = t_addrmode_is4_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000211 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000212}
213
214// t_addrmode_is2 := reg + imm5 * 2
215//
Jim Grosbach26d35872011-08-19 18:55:51 +0000216def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000217def t_addrmode_is2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000218 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
219 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000220 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000221 let PrintMethod = "printThumbAddrModeImm5S2Operand";
Jim Grosbach26d35872011-08-19 18:55:51 +0000222 let ParserMatchClass = t_addrmode_is2_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000223 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000224}
225
226// t_addrmode_is1 := reg + imm5
227//
Jim Grosbacha32c7532011-08-19 18:49:59 +0000228def t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000229def t_addrmode_is1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000230 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
231 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000232 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000233 let PrintMethod = "printThumbAddrModeImm5S1Operand";
Jim Grosbacha32c7532011-08-19 18:49:59 +0000234 let ParserMatchClass = t_addrmode_is1_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000235 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000236}
237
238// t_addrmode_sp := sp + imm8 * 4
239//
Jim Grosbach505be7592011-08-23 18:39:41 +0000240// FIXME: This really shouldn't have an explicit SP operand at all. It should
241// be implicit, just like in the instruction encoding itself.
Jim Grosbach23983d62011-08-19 18:13:48 +0000242def t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000243def t_addrmode_sp : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000244 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000245 let EncoderMethod = "getAddrModeThumbSPOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000246 let DecoderMethod = "DecodeThumbAddrModeSP";
Evan Cheng10043e22007-01-19 07:51:42 +0000247 let PrintMethod = "printThumbAddrModeSPOperand";
Jim Grosbach23983d62011-08-19 18:13:48 +0000248 let ParserMatchClass = t_addrmode_sp_asm_operand;
Jakob Stoklund Olesena94837d2010-01-13 00:43:06 +0000249 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000250}
251
252//===----------------------------------------------------------------------===//
253// Miscellaneous Instructions.
254//
255
Jim Grosbach45fceea2010-02-22 23:10:38 +0000256// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
257// from removing one half of the matched pairs. That breaks PEI, which assumes
258// these will always be in pairs, and asserts if it finds otherwise. Better way?
259let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000260def tADJCALLSTACKUP :
Bill Wendling49a2e232010-11-19 22:02:18 +0000261 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
262 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
263 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000264
Jim Grosbach669f1d02009-03-27 23:06:27 +0000265def tADJCALLSTACKDOWN :
Bill Wendling49a2e232010-11-19 22:02:18 +0000266 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
267 [(ARMcallseq_start imm:$amt)]>,
268 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000269}
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000270
Jim Grosbach23b729e2011-08-17 23:08:57 +0000271class T1SystemEncoding<bits<8> opc>
Bill Wendling5da8cae2010-11-29 22:15:03 +0000272 : T1Encoding<0b101111> {
Jim Grosbach23b729e2011-08-17 23:08:57 +0000273 let Inst{9-8} = 0b11;
274 let Inst{7-0} = opc;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000275}
276
Saleem Abdulrasool7e7c2f92014-04-25 17:24:24 +0000277def tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
278 [(int_arm_hint imm0_15:$imm)]>,
Richard Barton87dacc32013-10-18 14:09:49 +0000279 T1SystemEncoding<0x00>,
280 Requires<[IsThumb, HasV6M]> {
281 bits<4> imm;
282 let Inst{7-4} = imm;
283}
Johnny Chen90adefc2010-02-25 03:28:51 +0000284
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000285// Note: When EmitPriority == 1, the alias will be used for printing
286class tHintAlias<string Asm, dag Result, bit EmitPriority = 0> : tInstAlias<Asm, Result, EmitPriority> {
Richard Barton87dacc32013-10-18 14:09:49 +0000287 let Predicates = [IsThumb, HasV6M];
288}
Johnny Chen74cca5a2010-02-25 17:51:03 +0000289
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000290def : tHintAlias<"nop$p", (tHINT 0, pred:$p), 1>; // A8.6.110
291def : tHintAlias<"yield$p", (tHINT 1, pred:$p), 1>; // A8.6.410
292def : tHintAlias<"wfe$p", (tHINT 2, pred:$p), 1>; // A8.6.408
293def : tHintAlias<"wfi$p", (tHINT 3, pred:$p), 1>; // A8.6.409
294def : tHintAlias<"sev$p", (tHINT 4, pred:$p), 1>; // A8.6.157
295def : tInstAlias<"sevl$p", (tHINT 5, pred:$p), 1> {
Richard Barton87dacc32013-10-18 14:09:49 +0000296 let Predicates = [IsThumb2, HasV8];
297}
Joey Goulyad98f162013-10-01 12:39:11 +0000298
Jim Grosbach23b729e2011-08-17 23:08:57 +0000299// The imm operand $val can be used by a debugger to store more information
Bill Wendling5da8cae2010-11-29 22:15:03 +0000300// about the breakpoint.
Jim Grosbach23b729e2011-08-17 23:08:57 +0000301def tBKPT : T1I<(outs), (ins imm0_255:$val), NoItinerary, "bkpt\t$val",
302 []>,
303 T1Encoding<0b101111> {
304 let Inst{9-8} = 0b10;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000305 // A8.6.22
306 bits<8> val;
307 let Inst{7-0} = val;
308}
Saleem Abdulrasool70187552013-12-23 17:23:58 +0000309// default immediate for breakpoint mnemonic
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000310def : InstAlias<"bkpt", (tBKPT 0), 0>, Requires<[IsThumb]>;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000311
Richard Barton8d519fe2013-09-05 14:14:19 +0000312def tHLT : T1I<(outs), (ins imm0_63:$val), NoItinerary, "hlt\t$val",
313 []>, T1Encoding<0b101110>, Requires<[IsThumb, HasV8]> {
314 let Inst{9-6} = 0b1010;
315 bits<6> val;
316 let Inst{5-0} = val;
317}
318
Jim Grosbach39f93882011-07-22 17:52:23 +0000319def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
Keith Walker10457172014-08-05 15:11:59 +0000320 []>, T1Encoding<0b101101>, Requires<[IsNotMClass]>, Deprecated<HasV8Ops> {
Jim Grosbach39f93882011-07-22 17:52:23 +0000321 bits<1> end;
Bill Wendling3acd0272010-11-21 10:55:23 +0000322 // A8.6.156
Johnny Chen74cca5a2010-02-25 17:51:03 +0000323 let Inst{9-5} = 0b10010;
Bill Wendling49a2e232010-11-19 22:02:18 +0000324 let Inst{4} = 1;
Jim Grosbach39f93882011-07-22 17:52:23 +0000325 let Inst{3} = end;
Bill Wendling49a2e232010-11-19 22:02:18 +0000326 let Inst{2-0} = 0b000;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000327}
328
Johnny Chen44908a52010-03-02 18:14:57 +0000329// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000330def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
Jim Grosbach4da03f02011-09-20 00:00:06 +0000331 NoItinerary, "cps$imod $iflags", []>,
Bill Wendling775899e2010-11-29 00:18:15 +0000332 T1Misc<0b0110011> {
333 // A8.6.38 & B6.1.1
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000334 bit imod;
335 bits<3> iflags;
336
337 let Inst{4} = imod;
338 let Inst{3} = 0;
339 let Inst{2-0} = iflags;
Owen Andersone0152a72011-08-09 20:55:18 +0000340 let DecoderMethod = "DecodeThumbCPS";
Bill Wendling775899e2010-11-29 00:18:15 +0000341}
Johnny Chen44908a52010-03-02 18:14:57 +0000342
Evan Cheng7cc6aca2009-08-04 23:47:55 +0000343// For both thumb1 and thumb2.
Chris Lattner9492c172010-10-31 19:15:18 +0000344let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +0000345def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendlinga82fb712010-11-19 22:37:33 +0000346 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000347 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlingddce9f32010-11-30 00:50:22 +0000348 // A8.6.6
Bill Wendlinga82fb712010-11-19 22:37:33 +0000349 bits<3> dst;
Bill Wendlingddce9f32010-11-30 00:50:22 +0000350 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendlinga82fb712010-11-19 22:37:33 +0000351 let Inst{2-0} = dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000352}
Evan Cheng10043e22007-01-19 07:51:42 +0000353
Bill Wendlinga82fb712010-11-19 22:37:33 +0000354// ADD <Rd>, sp, #<imm8>
Jakob Stoklund Olesendd2b39d2011-10-15 00:57:13 +0000355// FIXME: This should not be marked as having side effects, and it should be
356// rematerializable. Clearing the side effect bit causes miscompilations,
357// probably because the instruction can be moved around.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000358def tADDrSPi : T1pI<(outs tGPR:$dst), (ins GPRsp:$sp, t_imm0_1020s4:$imm),
359 IIC_iALUi, "add", "\t$dst, $sp, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000360 T1Encoding<{1,0,1,0,1,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000361 // A6.2 & A8.6.8
362 bits<3> dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000363 bits<8> imm;
Bill Wendlinga82fb712010-11-19 22:37:33 +0000364 let Inst{10-8} = dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000365 let Inst{7-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000366 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000367}
368
Tim Northover23075cc2014-10-20 21:28:41 +0000369// Thumb1 frame lowering is rather fragile, we hope to be able to use
370// tADDrSPi, but we may need to insert a sequence that clobbers CPSR.
371def tADDframe : PseudoInst<(outs tGPR:$dst), (ins i32imm:$base, i32imm:$offset),
372 NoItinerary, []>,
373 Requires<[IsThumb, IsThumb1Only]> {
374 let Defs = [CPSR];
375}
376
Bill Wendlinga82fb712010-11-19 22:37:33 +0000377// ADD sp, sp, #<imm7>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000378def tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
379 IIC_iALUi, "add", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000380 T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000381 // A6.2.5 & A8.6.8
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000382 bits<7> imm;
383 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000384 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000385}
Evan Chengb566ab72009-06-25 01:05:06 +0000386
Bill Wendlinga82fb712010-11-19 22:37:33 +0000387// SUB sp, sp, #<imm7>
388// FIXME: The encoding and the ASM string don't match up.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000389def tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
390 IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000391 T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000392 // A6.2.5 & A8.6.214
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000393 bits<7> imm;
394 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000395 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000396}
Evan Chengb972e562009-08-07 00:34:42 +0000397
Jim Grosbach930f2f62012-04-05 20:57:13 +0000398def : tInstAlias<"add${p} sp, $imm",
399 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
400def : tInstAlias<"add${p} sp, sp, $imm",
401 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
402
Jim Grosbach4b701af2011-08-24 21:42:27 +0000403// Can optionally specify SP as a three operand instruction.
404def : tInstAlias<"add${p} sp, sp, $imm",
405 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
406def : tInstAlias<"sub${p} sp, sp, $imm",
407 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
408
Bill Wendlinga82fb712010-11-19 22:37:33 +0000409// ADD <Rm>, sp
Jim Grosbachc6f32b32012-04-27 23:51:36 +0000410def tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
411 "add", "\t$Rdn, $sp, $Rn", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000412 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000413 // A8.6.9 Encoding T1
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000414 bits<4> Rdn;
415 let Inst{7} = Rdn{3};
Bill Wendlinga82fb712010-11-19 22:37:33 +0000416 let Inst{6-3} = 0b1101;
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000417 let Inst{2-0} = Rdn{2-0};
Owen Andersone0152a72011-08-09 20:55:18 +0000418 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000419}
Evan Chengb972e562009-08-07 00:34:42 +0000420
Bill Wendlinga82fb712010-11-19 22:37:33 +0000421// ADD sp, <Rm>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000422def tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
423 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000424 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Johnny Chenc28e6292009-12-15 17:24:14 +0000425 // A8.6.9 Encoding T2
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000426 bits<4> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000427 let Inst{7} = 1;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000428 let Inst{6-3} = Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000429 let Inst{2-0} = 0b101;
Owen Andersone0152a72011-08-09 20:55:18 +0000430 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000431}
Evan Chengb972e562009-08-07 00:34:42 +0000432
Evan Cheng10043e22007-01-19 07:51:42 +0000433//===----------------------------------------------------------------------===//
434// Control Flow Instructions.
435//
436
Bob Wilson73789b82009-10-28 18:26:41 +0000437// Indirect branches
438let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000439 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000440 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000441 // A6.2.3 & A8.6.25
442 bits<4> Rm;
443 let Inst{6-3} = Rm;
444 let Inst{2-0} = 0b000;
James Molloyd9ba4fd2012-02-09 10:56:31 +0000445 let Unpredictable{2-0} = 0b111;
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000446 }
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000447 def tBXNS : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bxns${p}\t$Rm", []>,
448 Requires<[IsThumb, Has8MSecExt]>,
449 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
450 bits<4> Rm;
451 let Inst{6-3} = Rm;
452 let Inst{2-0} = 0b100;
453 let Unpredictable{1-0} = 0b11;
454 }
Bob Wilson73789b82009-10-28 18:26:41 +0000455}
456
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000457let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson651b2302011-07-13 23:22:26 +0000458 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000459 [(ARMretflag)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000460
461 // Alternative return instruction used by vararg functions.
Jim Grosbach74719372011-07-08 21:50:04 +0000462 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000463 2, IIC_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000464 (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000465}
466
Bill Wendling9c258942010-12-01 02:36:55 +0000467// All calls clobber the non-callee saved registers. SP is marked as a use to
468// prevent stack-pointer assignments that appear immediately before calls from
469// potentially appearing dead.
Jim Grosbach669f1d02009-03-27 23:06:27 +0000470let isCall = 1,
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000471 Defs = [LR], Uses = [SP] in {
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000472 // Also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000473 def tBL : TIx2<0b11110, 0b11, 1,
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000474 (outs), (ins pred:$p, t_bltarget:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000475 "bl${p}\t$func",
Tim Northoverb5ece522016-05-10 19:17:47 +0000476 [(ARMcall tglobaladdr:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000477 Requires<[IsThumb]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000478 bits<24> func;
479 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000480 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000481 let Inst{13} = func{22};
482 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000483 let Inst{10-0} = func{10-0};
Bill Wendling4d8ff862010-12-03 01:55:47 +0000484 }
Evan Cheng175bd142009-07-29 21:26:42 +0000485
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000486 // ARMv5T and above, also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000487 def tBLXi : TIx2<0b11110, 0b11, 0,
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000488 (outs), (ins pred:$p, t_blxtarget:$func), IIC_Br,
Tim Northoverb5ece522016-05-10 19:17:47 +0000489 "blx${p}\t$func", []>,
Keith Walker10457172014-08-05 15:11:59 +0000490 Requires<[IsThumb, HasV5T, IsNotMClass]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000491 bits<24> func;
492 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000493 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000494 let Inst{13} = func{22};
495 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000496 let Inst{10-1} = func{10-1};
497 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbache4fee202010-12-03 22:33:42 +0000498 }
Evan Cheng175bd142009-07-29 21:26:42 +0000499
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000500 // Also used for Thumb2
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000501 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000502 "blx${p}\t$func",
Tim Northoverb5ece522016-05-10 19:17:47 +0000503 [(ARMcall GPR:$func)]>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +0000504 Requires<[IsThumb, HasV5T]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000505 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
Owen Andersonb7456232011-05-11 17:00:48 +0000506 bits<4> func;
507 let Inst{6-3} = func;
508 let Inst{2-0} = 0b000;
509 }
Evan Cheng175bd142009-07-29 21:26:42 +0000510
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000511 // ARMv8-M Security Extensions
512 def tBLXNSr : TI<(outs), (ins pred:$p, GPRnopc:$func), IIC_Br,
513 "blxns${p}\t$func", []>,
514 Requires<[IsThumb, Has8MSecExt]>,
515 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> {
516 bits<4> func;
517 let Inst{6-3} = func;
518 let Inst{2-0} = 0b100;
519 let Unpredictable{1-0} = 0b11;
520 }
521
Lauro Ramos Venancio143b0df2007-03-27 16:19:21 +0000522 // ARMv4T
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000523 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
Owen Anderson651b2302011-07-13 23:22:26 +0000524 4, IIC_Br,
Evan Cheng175bd142009-07-29 21:26:42 +0000525 [(ARMcall_nolink tGPR:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000526 Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000527}
528
Bill Wendling9c258942010-12-01 02:36:55 +0000529let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
530 let isPredicable = 1 in
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000531 def tB : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
532 "b", "\t$target", [(br bb:$target)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000533 T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
Jim Grosbache119da12010-12-10 18:21:33 +0000534 bits<11> target;
535 let Inst{10-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000536 let AsmMatchConverter = "cvtThumbBranches";
537 }
Evan Cheng10043e22007-01-19 07:51:42 +0000538
Evan Cheng863736b2007-01-30 01:13:37 +0000539 // Far jump
Jim Grosbachb5743b92010-12-16 19:11:16 +0000540 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
541 // the clobber of LR.
Evan Cheng317bd7a2009-08-07 05:45:07 +0000542 let Defs = [LR] in
Owen Anderson64d53622011-07-18 18:50:52 +0000543 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000544 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>,
545 Sched<[WriteBrTbl]>;
Evan Cheng863736b2007-01-30 01:13:37 +0000546
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000547 def tBR_JTr : tPseudoInst<(outs),
Tim Northover4998a472015-05-13 20:28:38 +0000548 (ins tGPR:$target, i32imm:$jt),
Owen Anderson651b2302011-07-13 23:22:26 +0000549 0, IIC_Br,
Tim Northover4998a472015-05-13 20:28:38 +0000550 [(ARMbrjt tGPR:$target, tjumptable:$jt)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000551 Sched<[WriteBrTbl]> {
Tim Northovera603c402015-05-31 19:22:07 +0000552 let Size = 2;
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000553 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chen466231a2009-12-16 02:32:54 +0000554 }
Evan Cheng0701c5a2007-01-27 02:29:45 +0000555}
556
Evan Chengaa3b8012007-07-05 07:13:32 +0000557// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach669f1d02009-03-27 23:06:27 +0000558// a two-value operand where a dag node expects two operands. :(
Evan Chengac1591b2007-07-21 00:34:19 +0000559let isBranch = 1, isTerminator = 1 in
Jim Grosbach78485ad2010-12-10 17:13:40 +0000560 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000561 "b${p}\t$target",
Johnny Chenc28e6292009-12-15 17:24:14 +0000562 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000563 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000564 bits<4> p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000565 bits<8> target;
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000566 let Inst{11-8} = p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000567 let Inst{7-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000568 let AsmMatchConverter = "cvtThumbBranches";
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000569}
Evan Cheng10043e22007-01-19 07:51:42 +0000570
Mihai Popad36cbaa2013-07-03 09:21:44 +0000571
Jim Grosbach166cd882011-07-08 20:13:35 +0000572// Tail calls
573let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
Evan Cheng68132d82011-12-20 18:26:50 +0000574 // IOS versions.
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000575 let Uses = [SP] in {
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000576 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
Owen Anderson651b2302011-07-13 23:22:26 +0000577 4, IIC_Br, [],
Jim Grosbach204c1282011-07-08 20:39:19 +0000578 (tBX GPR:$dst, (ops 14, zero_reg))>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000579 Requires<[IsThumb]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000580 }
Tim Northoverd6a729b2014-01-06 14:28:05 +0000581 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
582 // on MachO), so it's in ARMInstrThumb2.td.
583 // Non-MachO version:
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000584 let Uses = [SP] in {
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000585 def tTAILJMPdND : tPseudoExpand<(outs),
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000586 (ins t_brtarget:$dst, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000587 4, IIC_Br, [],
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000588 (tB t_brtarget:$dst, pred:$p)>,
Tim Northoverd6a729b2014-01-06 14:28:05 +0000589 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000590 }
591}
592
593
Jim Grosbach5cc338d2011-08-23 19:49:10 +0000594// A8.6.218 Supervisor Call (Software Interrupt)
Johnny Chen57656da2010-02-25 02:21:11 +0000595// A8.6.16 B: Encoding T1
596// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng9a133f62010-11-29 22:43:27 +0000597let isCall = 1, Uses = [SP] in
Jim Grosbachf1637842011-07-26 16:24:27 +0000598def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000599 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000600 bits<8> imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000601 let Inst{15-12} = 0b1101;
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000602 let Inst{11-8} = 0b1111;
603 let Inst{7-0} = imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000604}
605
Bill Wendling811c9362010-11-30 07:44:32 +0000606// The assembler uses 0xDEFE for a trap instruction.
Evan Cheng2fa5a7e2010-05-11 07:26:32 +0000607let isBarrier = 1, isTerminator = 1 in
Owen Andersonb7456232011-05-11 17:00:48 +0000608def tTRAP : TI<(outs), (ins), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000609 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
Bill Wendling3acd0272010-11-21 10:55:23 +0000610 let Inst = 0xdefe;
Johnny Chen57656da2010-02-25 02:21:11 +0000611}
612
Evan Cheng10043e22007-01-19 07:51:42 +0000613//===----------------------------------------------------------------------===//
614// Load Store Instructions.
615//
616
John Brawn68acdcb2015-08-13 10:48:22 +0000617// PC-relative loads need to be matched first as constant pool accesses need to
618// always be PC-relative. We do this using AddedComplexity, as the pattern is
619// simpler than the patterns of the other load instructions.
620let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 10 in
621def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
622 "ldr", "\t$Rt, $addr",
623 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
624 T1Encoding<{0,1,0,0,1,?}> {
625 // A6.2 & A8.6.59
626 bits<3> Rt;
627 bits<8> addr;
628 let Inst{10-8} = Rt;
629 let Inst{7-0} = addr;
630}
631
632// SP-relative loads should be matched before standard immediate-offset loads as
633// it means we avoid having to move SP to another register.
634let canFoldAsLoad = 1 in
635def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
636 "ldr", "\t$Rt, $addr",
637 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
638 T1LdStSP<{1,?,?}> {
639 bits<3> Rt;
640 bits<8> addr;
641 let Inst{10-8} = Rt;
642 let Inst{7-0} = addr;
643}
644
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000645// Loads: reg/reg and reg/imm5
Dan Gohman8c5d6832010-02-27 23:47:46 +0000646let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000647multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
648 Operand AddrMode_r, Operand AddrMode_i,
649 AddrMode am, InstrItinClass itin_r,
650 InstrItinClass itin_i, string asm,
651 PatFrag opnode> {
John Brawn68acdcb2015-08-13 10:48:22 +0000652 // Immediate-offset loads should be matched before register-offset loads as
653 // when the offset is a constant it's simpler to first check if it fits in the
654 // immediate offset field then fall back to register-offset if it doesn't.
Bill Wendling5ab38b52010-12-14 23:42:48 +0000655 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000656 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
657 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
658 am, itin_i, asm, "\t$Rt, $addr",
659 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000660 // Register-offset loads are matched last.
661 def r : // reg/reg
662 T1pILdStEncode<reg_opc,
663 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
664 am, itin_r, asm, "\t$Rt, $addr",
665 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000666}
667// Stores: reg/reg and reg/imm5
668multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
669 Operand AddrMode_r, Operand AddrMode_i,
670 AddrMode am, InstrItinClass itin_r,
671 InstrItinClass itin_i, string asm,
672 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000673 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000674 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
675 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
676 am, itin_i, asm, "\t$Rt, $addr",
677 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000678 def r : // reg/reg
679 T1pILdStEncode<reg_opc,
680 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
681 am, itin_r, asm, "\t$Rt, $addr",
682 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000683}
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000684
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000685// A8.6.57 & A8.6.60
John Brawn68acdcb2015-08-13 10:48:22 +0000686defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000687 t_addrmode_is4, AddrModeT1_4,
688 IIC_iLoad_r, IIC_iLoad_i, "ldr",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000689 load>;
Evan Cheng10043e22007-01-19 07:51:42 +0000690
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000691// A8.6.64 & A8.6.61
John Brawn68acdcb2015-08-13 10:48:22 +0000692defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000693 t_addrmode_is1, AddrModeT1_1,
694 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000695 zextloadi8>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000696
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000697// A8.6.76 & A8.6.73
John Brawn68acdcb2015-08-13 10:48:22 +0000698defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000699 t_addrmode_is2, AddrModeT1_2,
700 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000701 zextloadi16>;
Evan Chengc0b73662007-01-23 22:59:13 +0000702
Evan Cheng0794c6a2009-07-11 07:08:13 +0000703let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000704def tLDRSB : // A8.6.80
Owen Anderson3157f2e2011-08-15 19:00:06 +0000705 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000706 AddrModeT1_1, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000707 "ldrsb", "\t$Rt, $addr",
708 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000709
Evan Cheng0794c6a2009-07-11 07:08:13 +0000710let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000711def tLDRSH : // A8.6.84
Owen Anderson3157f2e2011-08-15 19:00:06 +0000712 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000713 AddrModeT1_2, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000714 "ldrsh", "\t$Rt, $addr",
715 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000716
Evan Cheng10043e22007-01-19 07:51:42 +0000717
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000718def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000719 "str", "\t$Rt, $addr",
720 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000721 T1LdStSP<{0,?,?}> {
722 bits<3> Rt;
723 bits<8> addr;
724 let Inst{10-8} = Rt;
725 let Inst{7-0} = addr;
726}
Evan Chengec13f8262007-02-07 00:06:56 +0000727
John Brawn68acdcb2015-08-13 10:48:22 +0000728// A8.6.194 & A8.6.192
729defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rr,
730 t_addrmode_is4, AddrModeT1_4,
731 IIC_iStore_r, IIC_iStore_i, "str",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000732 store>;
John Brawn68acdcb2015-08-13 10:48:22 +0000733
734// A8.6.197 & A8.6.195
735defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rr,
736 t_addrmode_is1, AddrModeT1_1,
737 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000738 truncstorei8>;
John Brawn68acdcb2015-08-13 10:48:22 +0000739
740// A8.6.207 & A8.6.205
741defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rr,
742 t_addrmode_is2, AddrModeT1_2,
743 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000744 truncstorei16>;
John Brawn68acdcb2015-08-13 10:48:22 +0000745
746
Evan Cheng10043e22007-01-19 07:51:42 +0000747//===----------------------------------------------------------------------===//
748// Load / store multiple Instructions.
749//
750
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000751// These require base address to be written back or one of the loaded regs.
Craig Topperc50d64b2014-11-26 00:46:26 +0000752let hasSideEffects = 0 in {
Bill Wendling705ec772010-11-13 10:57:02 +0000753
754let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000755def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
756 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
757 bits<3> Rn;
758 bits<8> regs;
759 let Inst{10-8} = Rn;
760 let Inst{7-0} = regs;
761}
Bill Wendling705ec772010-11-13 10:57:02 +0000762
Jim Grosbache364ad52011-08-23 17:41:15 +0000763// Writeback version is just a pseudo, as there's no encoding difference.
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +0000764// Writeback happens iff the base register is not in the destination register
Jim Grosbache364ad52011-08-23 17:41:15 +0000765// list.
Scott Douglass953f9082015-10-05 14:49:54 +0000766let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000767def tLDMIA_UPD :
768 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
769 "$Rn = $wb", IIC_iLoad_mu>,
770 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
771 let Size = 2;
772 let OutOperandList = (outs GPR:$wb);
773 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
774 let Pattern = [];
775 let isCodeGenOnly = 1;
776 let isPseudo = 1;
777 list<Predicate> Predicates = [IsThumb];
778}
779
780// There is no non-writeback version of STM for Thumb.
Bill Wendling705ec772010-11-13 10:57:02 +0000781let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
Jim Grosbach6ccd79f2011-08-24 18:19:42 +0000782def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
783 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
784 AddrModeNone, 2, IIC_iStore_mu,
785 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
Jim Grosbache364ad52011-08-23 17:41:15 +0000786 T1Encoding<{1,1,0,0,0,?}> {
787 bits<3> Rn;
788 bits<8> regs;
789 let Inst{10-8} = Rn;
790 let Inst{7-0} = regs;
791}
Owen Andersonb7456232011-05-11 17:00:48 +0000792
Craig Topperc50d64b2014-11-26 00:46:26 +0000793} // hasSideEffects
Evan Chengcc9ca352009-08-11 21:11:32 +0000794
Jim Grosbach90103cc2011-08-18 21:50:53 +0000795def : InstAlias<"ldm${p} $Rn!, $regs",
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000796 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs), 0>,
Jim Grosbach90103cc2011-08-18 21:50:53 +0000797 Requires<[IsThumb, IsThumb1Only]>;
798
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000799let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling945b7762010-11-19 01:33:10 +0000800def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000801 IIC_iPop,
Bill Wendling945b7762010-11-19 01:33:10 +0000802 "pop${p}\t$regs", []>,
803 T1Misc<{1,1,0,?,?,?,?}> {
804 bits<16> regs;
Bill Wendling945b7762010-11-19 01:33:10 +0000805 let Inst{8} = regs{15};
806 let Inst{7-0} = regs{7-0};
807}
Evan Chengcc9ca352009-08-11 21:11:32 +0000808
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000809let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000810def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000811 IIC_iStore_m,
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000812 "push${p}\t$regs", []>,
813 T1Misc<{0,1,0,?,?,?,?}> {
814 bits<16> regs;
815 let Inst{8} = regs{14};
816 let Inst{7-0} = regs{7-0};
817}
Evan Cheng10043e22007-01-19 07:51:42 +0000818
819//===----------------------------------------------------------------------===//
820// Arithmetic Instructions.
821//
822
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000823// Helper classes for encoding T1pI patterns:
824class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
825 string opc, string asm, list<dag> pattern>
826 : T1pI<oops, iops, itin, opc, asm, pattern>,
827 T1DataProcessing<opA> {
828 bits<3> Rm;
829 bits<3> Rn;
830 let Inst{5-3} = Rm;
831 let Inst{2-0} = Rn;
832}
833class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
834 string opc, string asm, list<dag> pattern>
835 : T1pI<oops, iops, itin, opc, asm, pattern>,
836 T1Misc<opA> {
837 bits<3> Rm;
838 bits<3> Rd;
839 let Inst{5-3} = Rm;
840 let Inst{2-0} = Rd;
841}
842
Bill Wendling490240a2010-12-01 01:20:15 +0000843// Helper classes for encoding T1sI patterns:
844class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
845 string opc, string asm, list<dag> pattern>
846 : T1sI<oops, iops, itin, opc, asm, pattern>,
847 T1DataProcessing<opA> {
848 bits<3> Rd;
849 bits<3> Rn;
850 let Inst{5-3} = Rn;
851 let Inst{2-0} = Rd;
852}
853class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
854 string opc, string asm, list<dag> pattern>
855 : T1sI<oops, iops, itin, opc, asm, pattern>,
856 T1General<opA> {
857 bits<3> Rm;
858 bits<3> Rn;
859 bits<3> Rd;
860 let Inst{8-6} = Rm;
861 let Inst{5-3} = Rn;
862 let Inst{2-0} = Rd;
863}
864class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
865 string opc, string asm, list<dag> pattern>
866 : T1sI<oops, iops, itin, opc, asm, pattern>,
867 T1General<opA> {
868 bits<3> Rd;
869 bits<3> Rm;
870 let Inst{5-3} = Rm;
871 let Inst{2-0} = Rd;
872}
873
874// Helper classes for encoding T1sIt patterns:
Bill Wendling4915f562010-12-01 00:48:44 +0000875class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
876 string opc, string asm, list<dag> pattern>
877 : T1sIt<oops, iops, itin, opc, asm, pattern>,
878 T1DataProcessing<opA> {
Bill Wendling05632cb2010-11-30 23:54:45 +0000879 bits<3> Rdn;
880 bits<3> Rm;
Bill Wendling4915f562010-12-01 00:48:44 +0000881 let Inst{5-3} = Rm;
882 let Inst{2-0} = Rdn;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000883}
Bill Wendling4915f562010-12-01 00:48:44 +0000884class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
885 string opc, string asm, list<dag> pattern>
886 : T1sIt<oops, iops, itin, opc, asm, pattern>,
887 T1General<opA> {
888 bits<3> Rdn;
889 bits<8> imm8;
890 let Inst{10-8} = Rdn;
891 let Inst{7-0} = imm8;
892}
893
894// Add with carry register
895let isCommutable = 1, Uses = [CPSR] in
896def tADC : // A8.6.2
897 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
898 "adc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000899 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Chengf40b9002007-01-27 00:07:15 +0000900
David Goodwine85169c2009-06-25 22:49:55 +0000901// Add immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000902def tADDi3 : // A8.6.4 T1
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000903 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000904 IIC_iALUi,
Bill Wendling490240a2010-12-01 01:20:15 +0000905 "add", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000906 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
907 Sched<[WriteALU]> {
Bill Wendlingfe1de032010-11-20 01:00:29 +0000908 bits<3> imm3;
909 let Inst{8-6} = imm3;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000910}
Evan Cheng10043e22007-01-19 07:51:42 +0000911
Bill Wendling4915f562010-12-01 00:48:44 +0000912def tADDi8 : // A8.6.4 T2
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000913 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
914 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +0000915 "add", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000916 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
917 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000918
David Goodwine85169c2009-06-25 22:49:55 +0000919// Add register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000920let isCommutable = 1 in
Bill Wendling490240a2010-12-01 01:20:15 +0000921def tADDrr : // A8.6.6 T1
922 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
923 IIC_iALUr,
924 "add", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000925 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000926
Craig Topperc50d64b2014-11-26 00:46:26 +0000927let hasSideEffects = 0 in
Bill Wendling7c646b92010-12-01 01:32:02 +0000928def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
929 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000930 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000931 // A8.6.6 T2
Bill Wendling7c646b92010-12-01 01:32:02 +0000932 bits<4> Rdn;
933 bits<4> Rm;
934 let Inst{7} = Rdn{3};
935 let Inst{6-3} = Rm;
936 let Inst{2-0} = Rdn{2-0};
Bill Wendling284326b2010-11-20 01:18:47 +0000937}
Evan Cheng10043e22007-01-19 07:51:42 +0000938
Bill Wendling284326b2010-11-20 01:18:47 +0000939// AND register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000940let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000941def tAND : // A8.6.12
942 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
943 IIC_iBITr,
944 "and", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000945 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000946
David Goodwine85169c2009-06-25 22:49:55 +0000947// ASR immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000948def tASRri : // A8.6.14
Owen Andersonc4030382011-08-08 20:42:17 +0000949 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +0000950 IIC_iMOVsi,
951 "asr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000952 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
953 Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000954 bits<5> imm5;
955 let Inst{10-6} = imm5;
Bill Wendling284326b2010-11-20 01:18:47 +0000956}
Evan Cheng10043e22007-01-19 07:51:42 +0000957
David Goodwine85169c2009-06-25 22:49:55 +0000958// ASR register
Bill Wendling4915f562010-12-01 00:48:44 +0000959def tASRrr : // A8.6.15
960 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
961 IIC_iMOVsr,
962 "asr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000963 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000964
David Goodwine85169c2009-06-25 22:49:55 +0000965// BIC register
Bill Wendling4915f562010-12-01 00:48:44 +0000966def tBIC : // A8.6.20
967 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
968 IIC_iBITr,
969 "bic", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000970 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
971 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000972
David Goodwine85169c2009-06-25 22:49:55 +0000973// CMN register
Gabor Greif22f69222010-09-14 22:00:50 +0000974let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach267430f2010-01-22 00:08:13 +0000975//FIXME: Disable CMN, as CCodes are backwards from compare expectations
976// Compare-to-zero still works out, just not the relationals
Bill Wendling9c258942010-12-01 02:36:55 +0000977//def tCMN : // A8.6.33
978// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
979// IIC_iCMPr,
980// "cmn", "\t$lhs, $rhs",
981// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000982
983def tCMNz : // A8.6.33
984 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
985 IIC_iCMPr,
986 "cmn", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000987 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000988
989} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +0000990
David Goodwine85169c2009-06-25 22:49:55 +0000991// CMP immediate
Gabor Greif22f69222010-09-14 22:00:50 +0000992let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach4f240a12011-08-18 18:08:29 +0000993def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
Bill Wendlingc31de252010-11-20 22:52:33 +0000994 "cmp", "\t$Rn, $imm8",
995 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000996 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendlingc31de252010-11-20 22:52:33 +0000997 // A8.6.35
998 bits<3> Rn;
999 bits<8> imm8;
1000 let Inst{10-8} = Rn;
1001 let Inst{7-0} = imm8;
1002}
1003
David Goodwine85169c2009-06-25 22:49:55 +00001004// CMP register
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001005def tCMPr : // A8.6.36 T1
1006 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1007 IIC_iCMPr,
1008 "cmp", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001009 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001010
Bill Wendling775899e2010-11-29 00:18:15 +00001011def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1012 "cmp", "\t$Rn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001013 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendling775899e2010-11-29 00:18:15 +00001014 // A8.6.36 T2
1015 bits<4> Rm;
1016 bits<4> Rn;
1017 let Inst{7} = Rn{3};
1018 let Inst{6-3} = Rm;
1019 let Inst{2-0} = Rn{2-0};
1020}
Bill Wendlingc31de252010-11-20 22:52:33 +00001021} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +00001022
Evan Cheng10043e22007-01-19 07:51:42 +00001023
David Goodwine85169c2009-06-25 22:49:55 +00001024// XOR register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001025let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001026def tEOR : // A8.6.45
1027 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1028 IIC_iBITr,
1029 "eor", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001030 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001031
David Goodwine85169c2009-06-25 22:49:55 +00001032// LSL immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001033def tLSLri : // A8.6.88
Jim Grosbach5503c3a2011-08-19 19:29:25 +00001034 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001035 IIC_iMOVsi,
1036 "lsl", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001037 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
1038 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001039 bits<5> imm5;
1040 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001041}
Evan Cheng10043e22007-01-19 07:51:42 +00001042
David Goodwine85169c2009-06-25 22:49:55 +00001043// LSL register
Bill Wendling4915f562010-12-01 00:48:44 +00001044def tLSLrr : // A8.6.89
1045 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1046 IIC_iMOVsr,
1047 "lsl", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001048 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001049
David Goodwine85169c2009-06-25 22:49:55 +00001050// LSR immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001051def tLSRri : // A8.6.90
Owen Andersonc4030382011-08-08 20:42:17 +00001052 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001053 IIC_iMOVsi,
1054 "lsr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001055 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1056 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001057 bits<5> imm5;
1058 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001059}
Evan Cheng10043e22007-01-19 07:51:42 +00001060
David Goodwine85169c2009-06-25 22:49:55 +00001061// LSR register
Bill Wendling4915f562010-12-01 00:48:44 +00001062def tLSRrr : // A8.6.91
1063 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1064 IIC_iMOVsr,
1065 "lsr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001066 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001067
Bill Wendling22db3132010-11-21 11:49:36 +00001068// Move register
Evan Cheng7f8ab6e2010-11-17 20:13:28 +00001069let isMoveImm = 1 in
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001070def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendling22db3132010-11-21 11:49:36 +00001071 "mov", "\t$Rd, $imm8",
1072 [(set tGPR:$Rd, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001073 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001074 // A8.6.96
1075 bits<3> Rd;
1076 bits<8> imm8;
1077 let Inst{10-8} = Rd;
1078 let Inst{7-0} = imm8;
1079}
Jim Grosbachf86cd372011-08-19 20:46:54 +00001080// Because we have an explicit tMOVSr below, we need an alias to handle
1081// the immediate "movs" form here. Blech.
Jim Grosbach6caa5572011-08-22 18:04:24 +00001082def : tInstAlias <"movs $Rdn, $imm",
1083 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001084
Jim Grosbach4def7042011-07-01 17:14:11 +00001085// A7-73: MOV(2) - mov setting flag.
Evan Cheng10043e22007-01-19 07:51:42 +00001086
Craig Topperc50d64b2014-11-26 00:46:26 +00001087let hasSideEffects = 0 in {
Jim Grosbache9cc9012011-06-30 23:38:17 +00001088def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson651b2302011-07-13 23:22:26 +00001089 2, IIC_iMOVr,
Jim Grosbachb98ab912011-06-30 22:10:46 +00001090 "mov", "\t$Rd, $Rm", "", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001091 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001092 // A8.6.97
1093 bits<4> Rd;
1094 bits<4> Rm;
Jim Grosbache9cc9012011-06-30 23:38:17 +00001095 let Inst{7} = Rd{3};
1096 let Inst{6-3} = Rm;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001097 let Inst{2-0} = Rd{2-0};
1098}
Evan Chengcd4cdd12009-07-11 06:43:01 +00001099let Defs = [CPSR] in
Bill Wendling4d8ff862010-12-03 01:55:47 +00001100def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001101 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001102 // A8.6.97
1103 bits<3> Rd;
1104 bits<3> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +00001105 let Inst{15-6} = 0b0000000000;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001106 let Inst{5-3} = Rm;
1107 let Inst{2-0} = Rd;
Johnny Chenc28e6292009-12-15 17:24:14 +00001108}
Craig Topperc50d64b2014-11-26 00:46:26 +00001109} // hasSideEffects
Evan Cheng10043e22007-01-19 07:51:42 +00001110
Bill Wendling9c258942010-12-01 02:36:55 +00001111// Multiply register
Jim Grosbachbfeb4f72011-08-22 23:25:48 +00001112let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001113def tMUL : // A8.6.105 T1
Jim Grosbach8e048492011-08-19 22:07:46 +00001114 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1115 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1116 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1117 T1DataProcessing<0b1101> {
1118 bits<3> Rd;
1119 bits<3> Rn;
1120 let Inst{5-3} = Rn;
1121 let Inst{2-0} = Rd;
1122 let AsmMatchConverter = "cvtThumbMultiply";
1123}
1124
Jim Grosbach6caa5572011-08-22 18:04:24 +00001125def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1126 pred:$p)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001127
Bill Wendling490240a2010-12-01 01:20:15 +00001128// Move inverse register
1129def tMVN : // A8.6.107
1130 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1131 "mvn", "\t$Rd, $Rn",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001132 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001133
Bill Wendling22db3132010-11-21 11:49:36 +00001134// Bitwise or register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001135let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001136def tORR : // A8.6.114
1137 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1138 IIC_iBITr,
1139 "orr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001140 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001141
Bill Wendling22db3132010-11-21 11:49:36 +00001142// Swaps
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001143def tREV : // A8.6.134
1144 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1145 IIC_iUNAr,
1146 "rev", "\t$Rd, $Rm",
1147 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001148 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001149
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001150def tREV16 : // A8.6.135
1151 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1152 IIC_iUNAr,
1153 "rev16", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001154 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001155 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001156
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001157def tREVSH : // A8.6.136
1158 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1159 IIC_iUNAr,
1160 "revsh", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001161 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001162 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001163
Bill Wendling4915f562010-12-01 00:48:44 +00001164// Rotate right register
1165def tROR : // A8.6.139
1166 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1167 IIC_iMOVsr,
1168 "ror", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001169 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1170 Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001171
Bill Wendling4915f562010-12-01 00:48:44 +00001172// Negate register
Bill Wendling490240a2010-12-01 01:20:15 +00001173def tRSB : // A8.6.141
1174 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1175 IIC_iALUi,
1176 "rsb", "\t$Rd, $Rn, #0",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001177 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001178
David Goodwine85169c2009-06-25 22:49:55 +00001179// Subtract with carry register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001180let Uses = [CPSR] in
Bill Wendling4915f562010-12-01 00:48:44 +00001181def tSBC : // A8.6.151
1182 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1183 IIC_iALUr,
1184 "sbc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001185 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>,
1186 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001187
David Goodwine85169c2009-06-25 22:49:55 +00001188// Subtract immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001189def tSUBi3 : // A8.6.210 T1
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001190 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Bill Wendling490240a2010-12-01 01:20:15 +00001191 IIC_iALUi,
1192 "sub", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001193 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1194 Sched<[WriteALU]> {
Bill Wendlingccba1a82010-11-29 01:00:43 +00001195 bits<3> imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001196 let Inst{8-6} = imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001197}
Jim Grosbach669f1d02009-03-27 23:06:27 +00001198
Bill Wendling4915f562010-12-01 00:48:44 +00001199def tSUBi8 : // A8.6.210 T2
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001200 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1201 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +00001202 "sub", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001203 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1204 Sched<[WriteALU]>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001205
Bill Wendling490240a2010-12-01 01:20:15 +00001206// Subtract register
1207def tSUBrr : // A8.6.212
1208 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1209 IIC_iALUr,
1210 "sub", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001211 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1212 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001213
Bill Wendling490240a2010-12-01 01:20:15 +00001214// Sign-extend byte
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001215def tSXTB : // A8.6.222
1216 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1217 IIC_iUNAr,
1218 "sxtb", "\t$Rd, $Rm",
1219 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001220 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1221 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001222
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001223// Sign-extend short
1224def tSXTH : // A8.6.224
1225 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1226 IIC_iUNAr,
1227 "sxth", "\t$Rd, $Rm",
1228 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001229 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1230 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001231
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001232// Test
Gabor Greif2afac8e2010-09-14 20:47:43 +00001233let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001234def tTST : // A8.6.230
1235 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1236 "tst", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001237 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1238 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001239
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001240// A8.8.247 UDF - Undefined (Encoding T1)
Saleem Abdulrasool2bd12622014-05-22 04:46:46 +00001241def tUDF : TI<(outs), (ins imm0_255:$imm8), IIC_Br, "udf\t$imm8",
1242 [(int_arm_undefined imm0_255:$imm8)]>, Encoding16 {
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001243 bits<8> imm8;
1244 let Inst{15-12} = 0b1101;
1245 let Inst{11-8} = 0b1110;
1246 let Inst{7-0} = imm8;
1247}
1248
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001249// Zero-extend byte
1250def tUXTB : // A8.6.262
1251 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1252 IIC_iUNAr,
1253 "uxtb", "\t$Rd, $Rm",
1254 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001255 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1256 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001257
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001258// Zero-extend short
1259def tUXTH : // A8.6.264
1260 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1261 IIC_iUNAr,
1262 "uxth", "\t$Rd, $Rm",
1263 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001264 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001265
Jim Grosbach3e2cad32010-02-16 21:23:02 +00001266// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman453d64c2009-10-29 18:10:34 +00001267// Expanded after instruction selection into a branch sequence.
1268let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Chengbb2af352009-08-12 05:17:19 +00001269 def tMOVCCr_pseudo :
Tim Northover42180442013-08-22 09:57:11 +00001270 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1271 NoItinerary,
1272 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001273
1274// tLEApcrel - Load a pc-relative address into a register without offending the
1275// assembler.
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001276
1277def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
Jim Grosbache2a04042011-08-17 20:37:40 +00001278 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001279 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
Bill Wendling85a8a722010-11-30 00:18:30 +00001280 bits<3> Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001281 bits<8> addr;
Bill Wendling85a8a722010-11-30 00:18:30 +00001282 let Inst{10-8} = Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001283 let Inst{7-0} = addr;
Owen Andersone0152a72011-08-09 20:55:18 +00001284 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendling85a8a722010-11-30 00:18:30 +00001285}
Evan Cheng10043e22007-01-19 07:51:42 +00001286
Craig Topperc50d64b2014-11-26 00:46:26 +00001287let hasSideEffects = 0, isReMaterializable = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001288def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001289 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001290
Jakob Stoklund Olesen74352492012-08-24 22:46:55 +00001291let hasSideEffects = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001292def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
Tim Northover4998a472015-05-13 20:28:38 +00001293 (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001294 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001295
Evan Cheng10043e22007-01-19 07:51:42 +00001296//===----------------------------------------------------------------------===//
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001297// TLS Instructions
1298//
1299
1300// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbache4750ef2011-06-30 19:38:01 +00001301// This is a pseudo inst so that we can get the encoding right,
1302// complete with fixup for the aeabi_read_tp function.
1303let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson651b2302011-07-13 23:22:26 +00001304def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001305 [(set R0, ARMthread_pointer)]>,
1306 Sched<[WriteBr]>;
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001307
Bill Wendling9c258942010-12-01 02:36:55 +00001308//===----------------------------------------------------------------------===//
Jim Grosbach36d4dec2009-12-01 18:10:36 +00001309// SJLJ Exception handling intrinsics
Owen Andersonb7456232011-05-11 17:00:48 +00001310//
Bill Wendling9c258942010-12-01 02:36:55 +00001311
1312// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1313// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1314// from some other function to get here, and we're using the stack frame for the
1315// containing function to save/restore registers, we can't keep anything live in
1316// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner0ab5e2c2011-04-15 05:18:47 +00001317// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling9c258942010-12-01 02:36:55 +00001318// registers except for our own input by listing the relevant registers in
1319// Defs. By doing so, we also cause the prologue/epilogue code to actively
1320// preserve all of the callee-saved resgisters, which is exactly what we want.
1321// $val is a scratch register for our use.
Andrew Trick410172b2011-06-07 00:08:49 +00001322let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendlingaa9047d2011-10-17 22:26:23 +00001323 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1324 usesCustomInserter = 1 in
Bill Wendlingddce9f32010-11-30 00:50:22 +00001325def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson651b2302011-07-13 23:22:26 +00001326 AddrModeNone, 0, NoItinerary, "","",
Bill Wendlingddce9f32010-11-30 00:50:22 +00001327 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001328
Evan Cheng68132d82011-12-20 18:26:50 +00001329// FIXME: Non-IOS version(s)
Chris Lattner9492c172010-10-31 19:15:18 +00001330let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001331 Defs = [ R7, LR, SP ] in
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001332def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson651b2302011-07-13 23:22:26 +00001333 AddrModeNone, 0, IndexModeNone,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001334 Pseudo, NoItinerary, "", "",
1335 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
Saleem Abdulrasool1632fe12016-03-10 16:26:37 +00001336 Requires<[IsThumb,IsNotWindows]>;
1337
1338let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1339 Defs = [ R11, LR, SP ] in
1340def tInt_WIN_eh_sjlj_longjmp
1341 : XI<(outs), (ins GPR:$src, GPR:$scratch), AddrModeNone, 0, IndexModeNone,
1342 Pseudo, NoItinerary, "", "", [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1343 Requires<[IsThumb,IsWindows]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001344
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001345//===----------------------------------------------------------------------===//
Evan Cheng10043e22007-01-19 07:51:42 +00001346// Non-Instruction Patterns
1347//
1348
Jim Grosbach327cf8e2010-12-07 20:41:06 +00001349// Comparisons
1350def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1351 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1352def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1353 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1354
Evan Cheng61671c82009-07-10 02:09:04 +00001355// Add with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001356def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1357 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1358def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng01de9852009-08-20 17:01:04 +00001359 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwine5b969f2009-07-27 19:59:26 +00001360def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1361 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001362
1363// Subtract with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001364def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1365 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1366def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1367 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1368def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1369 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001370
Louis Gerbargefdcf232014-05-12 19:53:52 +00001371// Bswap 16 with load/store
Louis Gerbargefdcf232014-05-12 19:53:52 +00001372def : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
1373 (tREV16 (tLDRHi t_addrmode_is2:$addr))>;
John Brawn68acdcb2015-08-13 10:48:22 +00001374def : T1Pat<(srl (bswap (extloadi16 t_addrmode_rr:$addr)), (i32 16)),
1375 (tREV16 (tLDRHr t_addrmode_rr:$addr))>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001376def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1377 t_addrmode_is2:$addr),
1378 (tSTRHi(tREV16 tGPR:$Rn), t_addrmode_is2:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001379def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1380 t_addrmode_rr:$addr),
1381 (tSTRHr (tREV16 tGPR:$Rn), t_addrmode_rr:$addr)>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001382
Tim Northoverdfe2156c2013-11-25 14:40:57 +00001383// ConstantPool
David Goodwine5b969f2009-07-27 19:59:26 +00001384def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001385
Tim Northover72360d22013-12-02 10:35:41 +00001386// GlobalAddress
Tim Northover1328c1a2014-01-13 14:19:17 +00001387def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
Tim Northover72360d22013-12-02 10:35:41 +00001388 IIC_iLoadiALU,
Tim Northover1328c1a2014-01-13 14:19:17 +00001389 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001390 (ARMWrapperPIC tglobaladdr:$addr))]>,
1391 Requires<[IsThumb, DontUseMovt]>;
1392
Tim Northover1328c1a2014-01-13 14:19:17 +00001393def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1394 IIC_iLoad_i,
1395 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001396 (ARMWrapper tglobaladdr:$src))]>,
1397 Requires<[IsThumb, DontUseMovt]>;
1398
Tim Northoverbd41cf82016-01-07 09:03:03 +00001399// TLS globals
1400def : Pat<(ARMWrapperPIC tglobaltlsaddr:$addr),
1401 (tLDRLIT_ga_pcrel tglobaltlsaddr:$addr)>,
1402 Requires<[IsThumb, DontUseMovt]>;
1403def : Pat<(ARMWrapper tglobaltlsaddr:$addr),
1404 (tLDRLIT_ga_abs tglobaltlsaddr:$addr)>,
1405 Requires<[IsThumb, DontUseMovt]>;
1406
Tim Northover72360d22013-12-02 10:35:41 +00001407
Evan Cheng0701c5a2007-01-27 02:29:45 +00001408// JumpTable
Tim Northover4998a472015-05-13 20:28:38 +00001409def : T1Pat<(ARMWrapperJT tjumptable:$dst),
1410 (tLEApcrelJT tjumptable:$dst)>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001411
Evan Cheng10043e22007-01-19 07:51:42 +00001412// Direct calls
Tim Northoverb5ece522016-05-10 19:17:47 +00001413def : T1Pat<(ARMcall texternalsym:$func), (tBL texternalsym:$func)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001414 Requires<[IsThumb]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001415
Evan Cheng10043e22007-01-19 07:51:42 +00001416// zextload i1 -> zextload i8
Bill Wendling092a7bd2010-12-14 03:36:38 +00001417def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1418 (tLDRBi t_addrmode_is1:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001419def : T1Pat<(zextloadi1 t_addrmode_rr:$addr),
1420 (tLDRBr t_addrmode_rr:$addr)>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001421
Renato Golinb9887ef2015-02-25 14:41:06 +00001422// extload from the stack -> word load from the stack, as it avoids having to
1423// materialize the base in a separate register. This only works when a word
1424// load puts the byte/halfword value in the same place in the register that the
1425// byte/halfword load would, i.e. when little-endian.
1426def : T1Pat<(extloadi1 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1427 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1428def : T1Pat<(extloadi8 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1429 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1430def : T1Pat<(extloadi16 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1431 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1432
Evan Chengd02d75c2007-01-26 19:13:16 +00001433// extload -> zextload
John Brawn68acdcb2015-08-13 10:48:22 +00001434def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1435def : T1Pat<(extloadi1 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1436def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1437def : T1Pat<(extloadi8 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1438def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1439def : T1Pat<(extloadi16 t_addrmode_rr:$addr), (tLDRHr t_addrmode_rr:$addr)>;
Evan Chengd02d75c2007-01-26 19:13:16 +00001440
Evan Cheng6da267d2009-08-28 00:31:43 +00001441// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng0794c6a2009-07-11 07:08:13 +00001442// ldr{b|h} + sxt{b|h} instead.
Bill Wendling1171e9e2010-12-15 00:58:57 +00001443def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1444 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1445 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001446def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1447 (tSXTB (tLDRBr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001448 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001449def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1450 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1451 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001452def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1453 (tSXTH (tLDRHr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001454 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001455
Bill Wendling1171e9e2010-12-15 00:58:57 +00001456def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1457 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001458def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1459 (tASRri (tLSLri (tLDRBr t_addrmode_rr:$addr), 24), 24)>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001460def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1461 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001462def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1463 (tASRri (tLSLri (tLDRHr t_addrmode_rr:$addr), 16), 16)>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001464
Eli Friedmanba912e02011-09-15 22:18:49 +00001465def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001466 (tLDRBi t_addrmode_is1:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001467def : T1Pat<(atomic_load_8 t_addrmode_rr:$src),
1468 (tLDRBr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001469def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001470 (tLDRHi t_addrmode_is2:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001471def : T1Pat<(atomic_load_16 t_addrmode_rr:$src),
1472 (tLDRHr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001473def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001474 (tLDRi t_addrmode_is4:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001475def : T1Pat<(atomic_load_32 t_addrmode_rr:$src),
1476 (tLDRr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001477def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1478 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001479def : T1Pat<(atomic_store_8 t_addrmode_rr:$ptr, tGPR:$val),
1480 (tSTRBr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001481def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1482 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001483def : T1Pat<(atomic_store_16 t_addrmode_rr:$ptr, tGPR:$val),
1484 (tSTRHr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001485def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1486 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001487def : T1Pat<(atomic_store_32 t_addrmode_rr:$ptr, tGPR:$val),
1488 (tSTRr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001489
Evan Cheng10043e22007-01-19 07:51:42 +00001490// Large immediate handling.
1491
1492// Two piece imms.
Evan Chengeab9ca72009-06-27 02:26:13 +00001493def : T1Pat<(i32 thumb_immshifted:$src),
1494 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1495 (thumb_immshifted_shamt imm:$src))>;
Evan Cheng10043e22007-01-19 07:51:42 +00001496
Evan Chengeab9ca72009-06-27 02:26:13 +00001497def : T1Pat<(i32 imm0_255_comp:$src),
1498 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Cheng207b2462009-11-06 23:52:48 +00001499
James Molloy65b6be12016-06-14 13:33:07 +00001500def : T1Pat<(i32 imm256_510:$src),
James Molloyb1013832016-06-07 13:10:14 +00001501 (tADDi8 (tMOVi8 255),
James Molloy65b6be12016-06-14 13:33:07 +00001502 (thumb_imm256_510_addend imm:$src))>;
James Molloyb1013832016-06-07 13:10:14 +00001503
Evan Cheng207b2462009-11-06 23:52:48 +00001504// Pseudo instruction that combines ldr from constpool and add pc. This should
1505// be expanded into two instructions late to allow if-conversion and
1506// scheduling.
1507let isReMaterializable = 1 in
1508def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling9c258942010-12-01 02:36:55 +00001509 NoItinerary,
Evan Cheng207b2462009-11-06 23:52:48 +00001510 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1511 imm:$cp))]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001512 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001513
1514// Pseudo-instruction for merged POP and return.
1515// FIXME: remove when we have a way to marking a MI with these properties.
1516let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1517 hasExtraDefRegAllocReq = 1 in
1518def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +00001519 2, IIC_iPop_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001520 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001521
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001522// Indirect branch using "mov pc, $Rm"
1523let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach39c67b52011-07-08 22:33:49 +00001524 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001525 2, IIC_Br, [(brind GPR:$Rm)],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001526 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001527}
Jim Grosbach25977222011-08-19 23:24:36 +00001528
1529
1530// In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1531// encoding is available on ARMv6K, but we don't differentiate that finely.
Sjoerd Meijer9da258d2016-06-03 13:19:43 +00001532def : InstAlias<"nop", (tMOVr R8, R8, 14, 0), 0>, Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach08a47802011-09-20 00:10:37 +00001533
1534
1535// For round-trip assembly/disassembly, we have to handle a CPS instruction
1536// without any iflags. That's not, strictly speaking, valid syntax, but it's
Benjamin Kramerbde91762012-06-02 10:20:22 +00001537// a useful extension and assembles to defined behaviour (the insn does
Jim Grosbach08a47802011-09-20 00:10:37 +00001538// nothing).
1539def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1540def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
Jim Grosbach561e4e12011-12-13 20:23:22 +00001541
1542// "neg" is and alias for "rsb rd, rn, #0"
1543def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1544 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1545
Jim Grosbachad66de12012-04-11 00:15:16 +00001546
1547// Implied destination operand forms for shifts.
1548def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1549 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1550def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1551 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1552def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1553 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
Renato Golin3f126132016-05-12 21:22:31 +00001554
1555// Pseudo instruction ldr Rt, =immediate
1556def tLDRConstPool
1557 : tAsmPseudo<"ldr${p} $Rt, $immediate",
1558 (ins tGPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;