blob: 93a174f3678a6c246b6de2e9c54c599c80183292 [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
Tim Northover3e036172016-07-11 22:29:37 +0000128
129def thumb_br_target : Operand<OtherVT> {
130 let ParserMatchClass = ThumbBranchTarget;
131 let EncoderMethod = "getThumbBranchTargetOpValue";
132 let OperandType = "OPERAND_PCREL";
Jim Grosbach78485ad2010-12-10 17:13:40 +0000133}
134
Tim Northover3e036172016-07-11 22:29:37 +0000135def thumb_bl_target : Operand<i32> {
136 let ParserMatchClass = ThumbBranchTarget;
Jim Grosbach9e199462010-12-06 23:57:07 +0000137 let EncoderMethod = "getThumbBLTargetOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000138 let DecoderMethod = "DecodeThumbBLTargetOperand";
Jim Grosbach9e199462010-12-06 23:57:07 +0000139}
140
Tim Northover3e036172016-07-11 22:29:37 +0000141// Target for BLX *from* thumb mode.
142def thumb_blx_target : Operand<i32> {
143 let ParserMatchClass = ARMBranchTarget;
Bill Wendling3392bfc2010-12-09 00:39:08 +0000144 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
Tim Northover3e036172016-07-11 22:29:37 +0000148def thumb_bcc_target : Operand<OtherVT> {
149 let ParserMatchClass = ThumbBranchTarget;
150 let EncoderMethod = "getThumbBCCTargetOpValue";
151 let DecoderMethod = "DecodeThumbBCCTargetOperand";
152}
153
154def thumb_cb_target : Operand<OtherVT> {
155 let ParserMatchClass = ThumbBranchTarget;
156 let EncoderMethod = "getThumbCBTargetOpValue";
157 let DecoderMethod = "DecodeThumbCmpBROperand";
158}
159
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000160// t_addrmode_pc := <label> => pc + imm8 * 4
161//
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000162def t_addrmode_pc : MemOperand {
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000163 let EncoderMethod = "getAddrModePCOpValue";
164 let DecoderMethod = "DecodeThumbAddrModePC";
165 let PrintMethod = "printThumbLdrLabelOperand";
166 let ParserMatchClass = ThumbMemPC;
167}
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000168}
Bill Wendling3392bfc2010-12-09 00:39:08 +0000169
Evan Cheng10043e22007-01-19 07:51:42 +0000170// t_addrmode_rr := reg + reg
171//
Jim Grosbachd3595712011-08-03 23:50:40 +0000172def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000173def t_addrmode_rr : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000174 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000175 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Cheng10043e22007-01-19 07:51:42 +0000176 let PrintMethod = "printThumbAddrModeRROperand";
Owen Anderson3157f2e2011-08-15 19:00:06 +0000177 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbach7c4739d2011-08-19 19:17:58 +0000178 let ParserMatchClass = t_addrmode_rr_asm_operand;
Jim Grosbachfde21102009-04-07 20:34:09 +0000179 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000180}
181
Bill Wendling092a7bd2010-12-14 03:36:38 +0000182// t_addrmode_rrs := reg + reg
Evan Cheng10043e22007-01-19 07:51:42 +0000183//
Jim Grosbache9380702011-08-19 16:52:32 +0000184// We use separate scaled versions because the Select* functions need
185// to explicitly check for a matching constant and return false here so that
186// the reg+imm forms will match instead. This is a horrible way to do that,
187// as it forces tight coupling between the methods, but it's how selectiondag
188// currently works.
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000189def t_addrmode_rrs1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000190 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
191 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
192 let PrintMethod = "printThumbAddrModeRROperand";
Owen Andersone0152a72011-08-09 20:55:18 +0000193 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbachd3595712011-08-03 23:50:40 +0000194 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000195 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000196}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000197def t_addrmode_rrs2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000198 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
199 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000200 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000201 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000202 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000203 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000204}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000205def t_addrmode_rrs4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000206 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
207 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000208 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000209 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000210 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000211 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000212}
Evan Chengc0b73662007-01-23 22:59:13 +0000213
Bill Wendling092a7bd2010-12-14 03:36:38 +0000214// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc0b73662007-01-23 22:59:13 +0000215//
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000216def t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000217def t_addrmode_is4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000218 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
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 = "printThumbAddrModeImm5S4Operand";
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000222 let ParserMatchClass = t_addrmode_is4_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_is2 := reg + imm5 * 2
227//
Jim Grosbach26d35872011-08-19 18:55:51 +0000228def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000229def t_addrmode_is2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000230 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
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 = "printThumbAddrModeImm5S2Operand";
Jim Grosbach26d35872011-08-19 18:55:51 +0000234 let ParserMatchClass = t_addrmode_is2_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000235 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000236}
237
238// t_addrmode_is1 := reg + imm5
239//
Jim Grosbacha32c7532011-08-19 18:49:59 +0000240def t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000241def t_addrmode_is1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000242 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
243 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000244 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000245 let PrintMethod = "printThumbAddrModeImm5S1Operand";
Jim Grosbacha32c7532011-08-19 18:49:59 +0000246 let ParserMatchClass = t_addrmode_is1_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000247 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000248}
249
250// t_addrmode_sp := sp + imm8 * 4
251//
Jim Grosbach505be7592011-08-23 18:39:41 +0000252// FIXME: This really shouldn't have an explicit SP operand at all. It should
253// be implicit, just like in the instruction encoding itself.
Jim Grosbach23983d62011-08-19 18:13:48 +0000254def t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000255def t_addrmode_sp : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000256 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000257 let EncoderMethod = "getAddrModeThumbSPOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000258 let DecoderMethod = "DecodeThumbAddrModeSP";
Evan Cheng10043e22007-01-19 07:51:42 +0000259 let PrintMethod = "printThumbAddrModeSPOperand";
Jim Grosbach23983d62011-08-19 18:13:48 +0000260 let ParserMatchClass = t_addrmode_sp_asm_operand;
Jakob Stoklund Olesena94837d2010-01-13 00:43:06 +0000261 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000262}
263
264//===----------------------------------------------------------------------===//
265// Miscellaneous Instructions.
266//
267
Jim Grosbach45fceea2010-02-22 23:10:38 +0000268// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
269// from removing one half of the matched pairs. That breaks PEI, which assumes
270// these will always be in pairs, and asserts if it finds otherwise. Better way?
271let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000272def tADJCALLSTACKUP :
Bill Wendling49a2e232010-11-19 22:02:18 +0000273 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
274 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
275 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000276
Jim Grosbach669f1d02009-03-27 23:06:27 +0000277def tADJCALLSTACKDOWN :
Bill Wendling49a2e232010-11-19 22:02:18 +0000278 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
279 [(ARMcallseq_start imm:$amt)]>,
280 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000281}
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000282
Jim Grosbach23b729e2011-08-17 23:08:57 +0000283class T1SystemEncoding<bits<8> opc>
Bill Wendling5da8cae2010-11-29 22:15:03 +0000284 : T1Encoding<0b101111> {
Jim Grosbach23b729e2011-08-17 23:08:57 +0000285 let Inst{9-8} = 0b11;
286 let Inst{7-0} = opc;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000287}
288
Saleem Abdulrasool7e7c2f92014-04-25 17:24:24 +0000289def tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
290 [(int_arm_hint imm0_15:$imm)]>,
Richard Barton87dacc32013-10-18 14:09:49 +0000291 T1SystemEncoding<0x00>,
292 Requires<[IsThumb, HasV6M]> {
293 bits<4> imm;
294 let Inst{7-4} = imm;
295}
Johnny Chen90adefc2010-02-25 03:28:51 +0000296
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000297// Note: When EmitPriority == 1, the alias will be used for printing
298class tHintAlias<string Asm, dag Result, bit EmitPriority = 0> : tInstAlias<Asm, Result, EmitPriority> {
Richard Barton87dacc32013-10-18 14:09:49 +0000299 let Predicates = [IsThumb, HasV6M];
300}
Johnny Chen74cca5a2010-02-25 17:51:03 +0000301
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000302def : tHintAlias<"nop$p", (tHINT 0, pred:$p), 1>; // A8.6.110
303def : tHintAlias<"yield$p", (tHINT 1, pred:$p), 1>; // A8.6.410
304def : tHintAlias<"wfe$p", (tHINT 2, pred:$p), 1>; // A8.6.408
305def : tHintAlias<"wfi$p", (tHINT 3, pred:$p), 1>; // A8.6.409
306def : tHintAlias<"sev$p", (tHINT 4, pred:$p), 1>; // A8.6.157
307def : tInstAlias<"sevl$p", (tHINT 5, pred:$p), 1> {
Richard Barton87dacc32013-10-18 14:09:49 +0000308 let Predicates = [IsThumb2, HasV8];
309}
Joey Goulyad98f162013-10-01 12:39:11 +0000310
Jim Grosbach23b729e2011-08-17 23:08:57 +0000311// The imm operand $val can be used by a debugger to store more information
Bill Wendling5da8cae2010-11-29 22:15:03 +0000312// about the breakpoint.
Jim Grosbach23b729e2011-08-17 23:08:57 +0000313def tBKPT : T1I<(outs), (ins imm0_255:$val), NoItinerary, "bkpt\t$val",
314 []>,
315 T1Encoding<0b101111> {
316 let Inst{9-8} = 0b10;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000317 // A8.6.22
318 bits<8> val;
319 let Inst{7-0} = val;
320}
Saleem Abdulrasool70187552013-12-23 17:23:58 +0000321// default immediate for breakpoint mnemonic
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000322def : InstAlias<"bkpt", (tBKPT 0), 0>, Requires<[IsThumb]>;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000323
Richard Barton8d519fe2013-09-05 14:14:19 +0000324def tHLT : T1I<(outs), (ins imm0_63:$val), NoItinerary, "hlt\t$val",
325 []>, T1Encoding<0b101110>, Requires<[IsThumb, HasV8]> {
326 let Inst{9-6} = 0b1010;
327 bits<6> val;
328 let Inst{5-0} = val;
329}
330
Jim Grosbach39f93882011-07-22 17:52:23 +0000331def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
Keith Walker10457172014-08-05 15:11:59 +0000332 []>, T1Encoding<0b101101>, Requires<[IsNotMClass]>, Deprecated<HasV8Ops> {
Jim Grosbach39f93882011-07-22 17:52:23 +0000333 bits<1> end;
Bill Wendling3acd0272010-11-21 10:55:23 +0000334 // A8.6.156
Johnny Chen74cca5a2010-02-25 17:51:03 +0000335 let Inst{9-5} = 0b10010;
Bill Wendling49a2e232010-11-19 22:02:18 +0000336 let Inst{4} = 1;
Jim Grosbach39f93882011-07-22 17:52:23 +0000337 let Inst{3} = end;
Bill Wendling49a2e232010-11-19 22:02:18 +0000338 let Inst{2-0} = 0b000;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000339}
340
Johnny Chen44908a52010-03-02 18:14:57 +0000341// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000342def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
Jim Grosbach4da03f02011-09-20 00:00:06 +0000343 NoItinerary, "cps$imod $iflags", []>,
Bill Wendling775899e2010-11-29 00:18:15 +0000344 T1Misc<0b0110011> {
345 // A8.6.38 & B6.1.1
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000346 bit imod;
347 bits<3> iflags;
348
349 let Inst{4} = imod;
350 let Inst{3} = 0;
351 let Inst{2-0} = iflags;
Owen Andersone0152a72011-08-09 20:55:18 +0000352 let DecoderMethod = "DecodeThumbCPS";
Bill Wendling775899e2010-11-29 00:18:15 +0000353}
Johnny Chen44908a52010-03-02 18:14:57 +0000354
Evan Cheng7cc6aca2009-08-04 23:47:55 +0000355// For both thumb1 and thumb2.
Chris Lattner9492c172010-10-31 19:15:18 +0000356let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +0000357def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendlinga82fb712010-11-19 22:37:33 +0000358 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000359 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlingddce9f32010-11-30 00:50:22 +0000360 // A8.6.6
Bill Wendlinga82fb712010-11-19 22:37:33 +0000361 bits<3> dst;
Bill Wendlingddce9f32010-11-30 00:50:22 +0000362 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendlinga82fb712010-11-19 22:37:33 +0000363 let Inst{2-0} = dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000364}
Evan Cheng10043e22007-01-19 07:51:42 +0000365
Bill Wendlinga82fb712010-11-19 22:37:33 +0000366// ADD <Rd>, sp, #<imm8>
Jakob Stoklund Olesendd2b39d2011-10-15 00:57:13 +0000367// FIXME: This should not be marked as having side effects, and it should be
368// rematerializable. Clearing the side effect bit causes miscompilations,
369// probably because the instruction can be moved around.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000370def tADDrSPi : T1pI<(outs tGPR:$dst), (ins GPRsp:$sp, t_imm0_1020s4:$imm),
371 IIC_iALUi, "add", "\t$dst, $sp, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000372 T1Encoding<{1,0,1,0,1,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000373 // A6.2 & A8.6.8
374 bits<3> dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000375 bits<8> imm;
Bill Wendlinga82fb712010-11-19 22:37:33 +0000376 let Inst{10-8} = dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000377 let Inst{7-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000378 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000379}
380
Tim Northover23075cc2014-10-20 21:28:41 +0000381// Thumb1 frame lowering is rather fragile, we hope to be able to use
382// tADDrSPi, but we may need to insert a sequence that clobbers CPSR.
383def tADDframe : PseudoInst<(outs tGPR:$dst), (ins i32imm:$base, i32imm:$offset),
384 NoItinerary, []>,
385 Requires<[IsThumb, IsThumb1Only]> {
386 let Defs = [CPSR];
387}
388
Bill Wendlinga82fb712010-11-19 22:37:33 +0000389// ADD sp, sp, #<imm7>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000390def tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
391 IIC_iALUi, "add", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000392 T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000393 // A6.2.5 & A8.6.8
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000394 bits<7> imm;
395 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000396 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000397}
Evan Chengb566ab72009-06-25 01:05:06 +0000398
Bill Wendlinga82fb712010-11-19 22:37:33 +0000399// SUB sp, sp, #<imm7>
400// FIXME: The encoding and the ASM string don't match up.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000401def tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
402 IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000403 T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000404 // A6.2.5 & A8.6.214
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000405 bits<7> imm;
406 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000407 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000408}
Evan Chengb972e562009-08-07 00:34:42 +0000409
Jim Grosbach930f2f62012-04-05 20:57:13 +0000410def : tInstAlias<"add${p} sp, $imm",
411 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
412def : tInstAlias<"add${p} sp, sp, $imm",
413 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
414
Jim Grosbach4b701af2011-08-24 21:42:27 +0000415// Can optionally specify SP as a three operand instruction.
416def : tInstAlias<"add${p} sp, sp, $imm",
417 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
418def : tInstAlias<"sub${p} sp, sp, $imm",
419 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
420
Bill Wendlinga82fb712010-11-19 22:37:33 +0000421// ADD <Rm>, sp
Jim Grosbachc6f32b32012-04-27 23:51:36 +0000422def tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
423 "add", "\t$Rdn, $sp, $Rn", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000424 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000425 // A8.6.9 Encoding T1
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000426 bits<4> Rdn;
427 let Inst{7} = Rdn{3};
Bill Wendlinga82fb712010-11-19 22:37:33 +0000428 let Inst{6-3} = 0b1101;
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000429 let Inst{2-0} = Rdn{2-0};
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
Bill Wendlinga82fb712010-11-19 22:37:33 +0000433// ADD sp, <Rm>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000434def tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
435 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000436 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Johnny Chenc28e6292009-12-15 17:24:14 +0000437 // A8.6.9 Encoding T2
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000438 bits<4> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000439 let Inst{7} = 1;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000440 let Inst{6-3} = Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000441 let Inst{2-0} = 0b101;
Owen Andersone0152a72011-08-09 20:55:18 +0000442 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000443}
Evan Chengb972e562009-08-07 00:34:42 +0000444
Evan Cheng10043e22007-01-19 07:51:42 +0000445//===----------------------------------------------------------------------===//
446// Control Flow Instructions.
447//
448
Bob Wilson73789b82009-10-28 18:26:41 +0000449// Indirect branches
450let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000451 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000452 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000453 // A6.2.3 & A8.6.25
454 bits<4> Rm;
455 let Inst{6-3} = Rm;
456 let Inst{2-0} = 0b000;
James Molloyd9ba4fd2012-02-09 10:56:31 +0000457 let Unpredictable{2-0} = 0b111;
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000458 }
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000459 def tBXNS : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bxns${p}\t$Rm", []>,
460 Requires<[IsThumb, Has8MSecExt]>,
461 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
462 bits<4> Rm;
463 let Inst{6-3} = Rm;
464 let Inst{2-0} = 0b100;
465 let Unpredictable{1-0} = 0b11;
466 }
Bob Wilson73789b82009-10-28 18:26:41 +0000467}
468
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000469let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson651b2302011-07-13 23:22:26 +0000470 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000471 [(ARMretflag)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000472
473 // Alternative return instruction used by vararg functions.
Jim Grosbach74719372011-07-08 21:50:04 +0000474 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000475 2, IIC_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000476 (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000477}
478
Bill Wendling9c258942010-12-01 02:36:55 +0000479// All calls clobber the non-callee saved registers. SP is marked as a use to
480// prevent stack-pointer assignments that appear immediately before calls from
481// potentially appearing dead.
Jim Grosbach669f1d02009-03-27 23:06:27 +0000482let isCall = 1,
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000483 Defs = [LR], Uses = [SP] in {
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000484 // Also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000485 def tBL : TIx2<0b11110, 0b11, 1,
Tim Northover3e036172016-07-11 22:29:37 +0000486 (outs), (ins pred:$p, thumb_bl_target:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000487 "bl${p}\t$func",
Tim Northoverb5ece522016-05-10 19:17:47 +0000488 [(ARMcall tglobaladdr:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000489 Requires<[IsThumb]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000490 bits<24> func;
491 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000492 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000493 let Inst{13} = func{22};
494 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000495 let Inst{10-0} = func{10-0};
Bill Wendling4d8ff862010-12-03 01:55:47 +0000496 }
Evan Cheng175bd142009-07-29 21:26:42 +0000497
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000498 // ARMv5T and above, also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000499 def tBLXi : TIx2<0b11110, 0b11, 0,
Tim Northover3e036172016-07-11 22:29:37 +0000500 (outs), (ins pred:$p, thumb_blx_target:$func), IIC_Br,
Tim Northoverb5ece522016-05-10 19:17:47 +0000501 "blx${p}\t$func", []>,
Keith Walker10457172014-08-05 15:11:59 +0000502 Requires<[IsThumb, HasV5T, IsNotMClass]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000503 bits<24> func;
504 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000505 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000506 let Inst{13} = func{22};
507 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000508 let Inst{10-1} = func{10-1};
509 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbache4fee202010-12-03 22:33:42 +0000510 }
Evan Cheng175bd142009-07-29 21:26:42 +0000511
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000512 // Also used for Thumb2
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000513 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000514 "blx${p}\t$func",
Tim Northoverb5ece522016-05-10 19:17:47 +0000515 [(ARMcall GPR:$func)]>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +0000516 Requires<[IsThumb, HasV5T]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000517 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
Owen Andersonb7456232011-05-11 17:00:48 +0000518 bits<4> func;
519 let Inst{6-3} = func;
520 let Inst{2-0} = 0b000;
521 }
Evan Cheng175bd142009-07-29 21:26:42 +0000522
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000523 // ARMv8-M Security Extensions
524 def tBLXNSr : TI<(outs), (ins pred:$p, GPRnopc:$func), IIC_Br,
525 "blxns${p}\t$func", []>,
526 Requires<[IsThumb, Has8MSecExt]>,
527 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> {
528 bits<4> func;
529 let Inst{6-3} = func;
530 let Inst{2-0} = 0b100;
531 let Unpredictable{1-0} = 0b11;
532 }
533
Lauro Ramos Venancio143b0df2007-03-27 16:19:21 +0000534 // ARMv4T
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000535 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
Owen Anderson651b2302011-07-13 23:22:26 +0000536 4, IIC_Br,
Evan Cheng175bd142009-07-29 21:26:42 +0000537 [(ARMcall_nolink tGPR:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000538 Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000539}
540
Bill Wendling9c258942010-12-01 02:36:55 +0000541let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
542 let isPredicable = 1 in
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000543 def tB : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
544 "b", "\t$target", [(br bb:$target)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000545 T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
Jim Grosbache119da12010-12-10 18:21:33 +0000546 bits<11> target;
547 let Inst{10-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000548 let AsmMatchConverter = "cvtThumbBranches";
549 }
Evan Cheng10043e22007-01-19 07:51:42 +0000550
Evan Cheng863736b2007-01-30 01:13:37 +0000551 // Far jump
Jim Grosbachb5743b92010-12-16 19:11:16 +0000552 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
553 // the clobber of LR.
Evan Cheng317bd7a2009-08-07 05:45:07 +0000554 let Defs = [LR] in
Tim Northover3e036172016-07-11 22:29:37 +0000555 def tBfar : tPseudoExpand<(outs), (ins thumb_bl_target:$target, pred:$p),
556 4, IIC_Br, [],
557 (tBL pred:$p, thumb_bl_target:$target)>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000558 Sched<[WriteBrTbl]>;
Evan Cheng863736b2007-01-30 01:13:37 +0000559
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000560 def tBR_JTr : tPseudoInst<(outs),
Tim Northover4998a472015-05-13 20:28:38 +0000561 (ins tGPR:$target, i32imm:$jt),
Owen Anderson651b2302011-07-13 23:22:26 +0000562 0, IIC_Br,
Tim Northover4998a472015-05-13 20:28:38 +0000563 [(ARMbrjt tGPR:$target, tjumptable:$jt)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000564 Sched<[WriteBrTbl]> {
Tim Northovera603c402015-05-31 19:22:07 +0000565 let Size = 2;
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000566 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chen466231a2009-12-16 02:32:54 +0000567 }
Evan Cheng0701c5a2007-01-27 02:29:45 +0000568}
569
Evan Chengaa3b8012007-07-05 07:13:32 +0000570// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach669f1d02009-03-27 23:06:27 +0000571// a two-value operand where a dag node expects two operands. :(
Evan Chengac1591b2007-07-21 00:34:19 +0000572let isBranch = 1, isTerminator = 1 in
Tim Northover3e036172016-07-11 22:29:37 +0000573 def tBcc : T1I<(outs), (ins thumb_bcc_target:$target, pred:$p), IIC_Br,
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000574 "b${p}\t$target",
Johnny Chenc28e6292009-12-15 17:24:14 +0000575 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000576 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000577 bits<4> p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000578 bits<8> target;
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000579 let Inst{11-8} = p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000580 let Inst{7-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000581 let AsmMatchConverter = "cvtThumbBranches";
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000582}
Evan Cheng10043e22007-01-19 07:51:42 +0000583
Mihai Popad36cbaa2013-07-03 09:21:44 +0000584
Jim Grosbach166cd882011-07-08 20:13:35 +0000585// Tail calls
586let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
Evan Cheng68132d82011-12-20 18:26:50 +0000587 // IOS versions.
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000588 let Uses = [SP] in {
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000589 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
Owen Anderson651b2302011-07-13 23:22:26 +0000590 4, IIC_Br, [],
Jim Grosbach204c1282011-07-08 20:39:19 +0000591 (tBX GPR:$dst, (ops 14, zero_reg))>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000592 Requires<[IsThumb]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000593 }
Tim Northoverd6a729b2014-01-06 14:28:05 +0000594 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
595 // on MachO), so it's in ARMInstrThumb2.td.
596 // Non-MachO version:
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000597 let Uses = [SP] in {
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000598 def tTAILJMPdND : tPseudoExpand<(outs),
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000599 (ins t_brtarget:$dst, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000600 4, IIC_Br, [],
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000601 (tB t_brtarget:$dst, pred:$p)>,
Tim Northoverd6a729b2014-01-06 14:28:05 +0000602 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000603 }
604}
605
606
Jim Grosbach5cc338d2011-08-23 19:49:10 +0000607// A8.6.218 Supervisor Call (Software Interrupt)
Johnny Chen57656da2010-02-25 02:21:11 +0000608// A8.6.16 B: Encoding T1
609// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng9a133f62010-11-29 22:43:27 +0000610let isCall = 1, Uses = [SP] in
Jim Grosbachf1637842011-07-26 16:24:27 +0000611def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000612 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000613 bits<8> imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000614 let Inst{15-12} = 0b1101;
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000615 let Inst{11-8} = 0b1111;
616 let Inst{7-0} = imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000617}
618
Bill Wendling811c9362010-11-30 07:44:32 +0000619// The assembler uses 0xDEFE for a trap instruction.
Evan Cheng2fa5a7e2010-05-11 07:26:32 +0000620let isBarrier = 1, isTerminator = 1 in
Owen Andersonb7456232011-05-11 17:00:48 +0000621def tTRAP : TI<(outs), (ins), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000622 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
Bill Wendling3acd0272010-11-21 10:55:23 +0000623 let Inst = 0xdefe;
Johnny Chen57656da2010-02-25 02:21:11 +0000624}
625
Evan Cheng10043e22007-01-19 07:51:42 +0000626//===----------------------------------------------------------------------===//
627// Load Store Instructions.
628//
629
John Brawn68acdcb2015-08-13 10:48:22 +0000630// PC-relative loads need to be matched first as constant pool accesses need to
631// always be PC-relative. We do this using AddedComplexity, as the pattern is
632// simpler than the patterns of the other load instructions.
633let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 10 in
634def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
635 "ldr", "\t$Rt, $addr",
636 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
637 T1Encoding<{0,1,0,0,1,?}> {
638 // A6.2 & A8.6.59
639 bits<3> Rt;
640 bits<8> addr;
641 let Inst{10-8} = Rt;
642 let Inst{7-0} = addr;
643}
644
645// SP-relative loads should be matched before standard immediate-offset loads as
646// it means we avoid having to move SP to another register.
647let canFoldAsLoad = 1 in
648def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
649 "ldr", "\t$Rt, $addr",
650 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
651 T1LdStSP<{1,?,?}> {
652 bits<3> Rt;
653 bits<8> addr;
654 let Inst{10-8} = Rt;
655 let Inst{7-0} = addr;
656}
657
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000658// Loads: reg/reg and reg/imm5
Dan Gohman8c5d6832010-02-27 23:47:46 +0000659let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000660multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
661 Operand AddrMode_r, Operand AddrMode_i,
662 AddrMode am, InstrItinClass itin_r,
663 InstrItinClass itin_i, string asm,
664 PatFrag opnode> {
John Brawn68acdcb2015-08-13 10:48:22 +0000665 // Immediate-offset loads should be matched before register-offset loads as
666 // when the offset is a constant it's simpler to first check if it fits in the
667 // immediate offset field then fall back to register-offset if it doesn't.
Bill Wendling5ab38b52010-12-14 23:42:48 +0000668 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000669 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
670 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
671 am, itin_i, asm, "\t$Rt, $addr",
672 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000673 // Register-offset loads are matched last.
674 def r : // reg/reg
675 T1pILdStEncode<reg_opc,
676 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
677 am, itin_r, asm, "\t$Rt, $addr",
678 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000679}
680// Stores: reg/reg and reg/imm5
681multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
682 Operand AddrMode_r, Operand AddrMode_i,
683 AddrMode am, InstrItinClass itin_r,
684 InstrItinClass itin_i, string asm,
685 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000686 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000687 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
688 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
689 am, itin_i, asm, "\t$Rt, $addr",
690 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000691 def r : // reg/reg
692 T1pILdStEncode<reg_opc,
693 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
694 am, itin_r, asm, "\t$Rt, $addr",
695 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000696}
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000697
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000698// A8.6.57 & A8.6.60
John Brawn68acdcb2015-08-13 10:48:22 +0000699defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000700 t_addrmode_is4, AddrModeT1_4,
701 IIC_iLoad_r, IIC_iLoad_i, "ldr",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000702 load>;
Evan Cheng10043e22007-01-19 07:51:42 +0000703
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000704// A8.6.64 & A8.6.61
John Brawn68acdcb2015-08-13 10:48:22 +0000705defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000706 t_addrmode_is1, AddrModeT1_1,
707 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000708 zextloadi8>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000709
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000710// A8.6.76 & A8.6.73
John Brawn68acdcb2015-08-13 10:48:22 +0000711defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000712 t_addrmode_is2, AddrModeT1_2,
713 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000714 zextloadi16>;
Evan Chengc0b73662007-01-23 22:59:13 +0000715
Evan Cheng0794c6a2009-07-11 07:08:13 +0000716let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000717def tLDRSB : // A8.6.80
Owen Anderson3157f2e2011-08-15 19:00:06 +0000718 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000719 AddrModeT1_1, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000720 "ldrsb", "\t$Rt, $addr",
721 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000722
Evan Cheng0794c6a2009-07-11 07:08:13 +0000723let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000724def tLDRSH : // A8.6.84
Owen Anderson3157f2e2011-08-15 19:00:06 +0000725 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000726 AddrModeT1_2, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000727 "ldrsh", "\t$Rt, $addr",
728 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000729
Evan Cheng10043e22007-01-19 07:51:42 +0000730
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000731def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000732 "str", "\t$Rt, $addr",
733 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000734 T1LdStSP<{0,?,?}> {
735 bits<3> Rt;
736 bits<8> addr;
737 let Inst{10-8} = Rt;
738 let Inst{7-0} = addr;
739}
Evan Chengec13f8262007-02-07 00:06:56 +0000740
John Brawn68acdcb2015-08-13 10:48:22 +0000741// A8.6.194 & A8.6.192
742defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rr,
743 t_addrmode_is4, AddrModeT1_4,
744 IIC_iStore_r, IIC_iStore_i, "str",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000745 store>;
John Brawn68acdcb2015-08-13 10:48:22 +0000746
747// A8.6.197 & A8.6.195
748defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rr,
749 t_addrmode_is1, AddrModeT1_1,
750 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000751 truncstorei8>;
John Brawn68acdcb2015-08-13 10:48:22 +0000752
753// A8.6.207 & A8.6.205
754defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rr,
755 t_addrmode_is2, AddrModeT1_2,
756 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
Artyom Skrobov5ddea6a2016-03-08 16:23:54 +0000757 truncstorei16>;
John Brawn68acdcb2015-08-13 10:48:22 +0000758
759
Evan Cheng10043e22007-01-19 07:51:42 +0000760//===----------------------------------------------------------------------===//
761// Load / store multiple Instructions.
762//
763
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000764// These require base address to be written back or one of the loaded regs.
Craig Topperc50d64b2014-11-26 00:46:26 +0000765let hasSideEffects = 0 in {
Bill Wendling705ec772010-11-13 10:57:02 +0000766
767let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000768def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
769 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
770 bits<3> Rn;
771 bits<8> regs;
772 let Inst{10-8} = Rn;
773 let Inst{7-0} = regs;
774}
Bill Wendling705ec772010-11-13 10:57:02 +0000775
Jim Grosbache364ad52011-08-23 17:41:15 +0000776// Writeback version is just a pseudo, as there's no encoding difference.
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +0000777// Writeback happens iff the base register is not in the destination register
Jim Grosbache364ad52011-08-23 17:41:15 +0000778// list.
Scott Douglass953f9082015-10-05 14:49:54 +0000779let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000780def tLDMIA_UPD :
781 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
782 "$Rn = $wb", IIC_iLoad_mu>,
783 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
784 let Size = 2;
785 let OutOperandList = (outs GPR:$wb);
786 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
787 let Pattern = [];
788 let isCodeGenOnly = 1;
789 let isPseudo = 1;
790 list<Predicate> Predicates = [IsThumb];
791}
792
793// There is no non-writeback version of STM for Thumb.
Bill Wendling705ec772010-11-13 10:57:02 +0000794let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
Jim Grosbach6ccd79f2011-08-24 18:19:42 +0000795def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
796 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
797 AddrModeNone, 2, IIC_iStore_mu,
798 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
Jim Grosbache364ad52011-08-23 17:41:15 +0000799 T1Encoding<{1,1,0,0,0,?}> {
800 bits<3> Rn;
801 bits<8> regs;
802 let Inst{10-8} = Rn;
803 let Inst{7-0} = regs;
804}
Owen Andersonb7456232011-05-11 17:00:48 +0000805
Craig Topperc50d64b2014-11-26 00:46:26 +0000806} // hasSideEffects
Evan Chengcc9ca352009-08-11 21:11:32 +0000807
Jim Grosbach90103cc2011-08-18 21:50:53 +0000808def : InstAlias<"ldm${p} $Rn!, $regs",
Sjoerd Meijer9da258d2016-06-03 13:19:43 +0000809 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs), 0>,
Jim Grosbach90103cc2011-08-18 21:50:53 +0000810 Requires<[IsThumb, IsThumb1Only]>;
811
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000812let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling945b7762010-11-19 01:33:10 +0000813def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000814 IIC_iPop,
Bill Wendling945b7762010-11-19 01:33:10 +0000815 "pop${p}\t$regs", []>,
816 T1Misc<{1,1,0,?,?,?,?}> {
817 bits<16> regs;
Bill Wendling945b7762010-11-19 01:33:10 +0000818 let Inst{8} = regs{15};
819 let Inst{7-0} = regs{7-0};
820}
Evan Chengcc9ca352009-08-11 21:11:32 +0000821
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000822let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000823def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000824 IIC_iStore_m,
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000825 "push${p}\t$regs", []>,
826 T1Misc<{0,1,0,?,?,?,?}> {
827 bits<16> regs;
828 let Inst{8} = regs{14};
829 let Inst{7-0} = regs{7-0};
830}
Evan Cheng10043e22007-01-19 07:51:42 +0000831
832//===----------------------------------------------------------------------===//
833// Arithmetic Instructions.
834//
835
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000836// Helper classes for encoding T1pI patterns:
837class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
838 string opc, string asm, list<dag> pattern>
839 : T1pI<oops, iops, itin, opc, asm, pattern>,
840 T1DataProcessing<opA> {
841 bits<3> Rm;
842 bits<3> Rn;
843 let Inst{5-3} = Rm;
844 let Inst{2-0} = Rn;
845}
846class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
847 string opc, string asm, list<dag> pattern>
848 : T1pI<oops, iops, itin, opc, asm, pattern>,
849 T1Misc<opA> {
850 bits<3> Rm;
851 bits<3> Rd;
852 let Inst{5-3} = Rm;
853 let Inst{2-0} = Rd;
854}
855
Bill Wendling490240a2010-12-01 01:20:15 +0000856// Helper classes for encoding T1sI patterns:
857class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
858 string opc, string asm, list<dag> pattern>
859 : T1sI<oops, iops, itin, opc, asm, pattern>,
860 T1DataProcessing<opA> {
861 bits<3> Rd;
862 bits<3> Rn;
863 let Inst{5-3} = Rn;
864 let Inst{2-0} = Rd;
865}
866class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
867 string opc, string asm, list<dag> pattern>
868 : T1sI<oops, iops, itin, opc, asm, pattern>,
869 T1General<opA> {
870 bits<3> Rm;
871 bits<3> Rn;
872 bits<3> Rd;
873 let Inst{8-6} = Rm;
874 let Inst{5-3} = Rn;
875 let Inst{2-0} = Rd;
876}
877class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
878 string opc, string asm, list<dag> pattern>
879 : T1sI<oops, iops, itin, opc, asm, pattern>,
880 T1General<opA> {
881 bits<3> Rd;
882 bits<3> Rm;
883 let Inst{5-3} = Rm;
884 let Inst{2-0} = Rd;
885}
886
887// Helper classes for encoding T1sIt patterns:
Bill Wendling4915f562010-12-01 00:48:44 +0000888class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
889 string opc, string asm, list<dag> pattern>
890 : T1sIt<oops, iops, itin, opc, asm, pattern>,
891 T1DataProcessing<opA> {
Bill Wendling05632cb2010-11-30 23:54:45 +0000892 bits<3> Rdn;
893 bits<3> Rm;
Bill Wendling4915f562010-12-01 00:48:44 +0000894 let Inst{5-3} = Rm;
895 let Inst{2-0} = Rdn;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000896}
Bill Wendling4915f562010-12-01 00:48:44 +0000897class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
898 string opc, string asm, list<dag> pattern>
899 : T1sIt<oops, iops, itin, opc, asm, pattern>,
900 T1General<opA> {
901 bits<3> Rdn;
902 bits<8> imm8;
903 let Inst{10-8} = Rdn;
904 let Inst{7-0} = imm8;
905}
906
907// Add with carry register
908let isCommutable = 1, Uses = [CPSR] in
909def tADC : // A8.6.2
910 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
911 "adc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000912 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Chengf40b9002007-01-27 00:07:15 +0000913
David Goodwine85169c2009-06-25 22:49:55 +0000914// Add immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000915def tADDi3 : // A8.6.4 T1
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000916 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000917 IIC_iALUi,
Bill Wendling490240a2010-12-01 01:20:15 +0000918 "add", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000919 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
920 Sched<[WriteALU]> {
Bill Wendlingfe1de032010-11-20 01:00:29 +0000921 bits<3> imm3;
922 let Inst{8-6} = imm3;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000923}
Evan Cheng10043e22007-01-19 07:51:42 +0000924
Bill Wendling4915f562010-12-01 00:48:44 +0000925def tADDi8 : // A8.6.4 T2
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000926 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
927 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +0000928 "add", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000929 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
930 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000931
David Goodwine85169c2009-06-25 22:49:55 +0000932// Add register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000933let isCommutable = 1 in
Bill Wendling490240a2010-12-01 01:20:15 +0000934def tADDrr : // A8.6.6 T1
935 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
936 IIC_iALUr,
937 "add", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000938 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000939
Craig Topperc50d64b2014-11-26 00:46:26 +0000940let hasSideEffects = 0 in
Bill Wendling7c646b92010-12-01 01:32:02 +0000941def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
942 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000943 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000944 // A8.6.6 T2
Bill Wendling7c646b92010-12-01 01:32:02 +0000945 bits<4> Rdn;
946 bits<4> Rm;
947 let Inst{7} = Rdn{3};
948 let Inst{6-3} = Rm;
949 let Inst{2-0} = Rdn{2-0};
Bill Wendling284326b2010-11-20 01:18:47 +0000950}
Evan Cheng10043e22007-01-19 07:51:42 +0000951
Bill Wendling284326b2010-11-20 01:18:47 +0000952// AND register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000953let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000954def tAND : // A8.6.12
955 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
956 IIC_iBITr,
957 "and", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000958 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000959
David Goodwine85169c2009-06-25 22:49:55 +0000960// ASR immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000961def tASRri : // A8.6.14
Owen Andersonc4030382011-08-08 20:42:17 +0000962 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +0000963 IIC_iMOVsi,
964 "asr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000965 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
966 Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000967 bits<5> imm5;
968 let Inst{10-6} = imm5;
Bill Wendling284326b2010-11-20 01:18:47 +0000969}
Evan Cheng10043e22007-01-19 07:51:42 +0000970
David Goodwine85169c2009-06-25 22:49:55 +0000971// ASR register
Bill Wendling4915f562010-12-01 00:48:44 +0000972def tASRrr : // A8.6.15
973 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
974 IIC_iMOVsr,
975 "asr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000976 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000977
David Goodwine85169c2009-06-25 22:49:55 +0000978// BIC register
Bill Wendling4915f562010-12-01 00:48:44 +0000979def tBIC : // A8.6.20
980 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
981 IIC_iBITr,
982 "bic", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000983 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
984 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000985
David Goodwine85169c2009-06-25 22:49:55 +0000986// CMN register
Gabor Greif22f69222010-09-14 22:00:50 +0000987let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach267430f2010-01-22 00:08:13 +0000988//FIXME: Disable CMN, as CCodes are backwards from compare expectations
989// Compare-to-zero still works out, just not the relationals
Bill Wendling9c258942010-12-01 02:36:55 +0000990//def tCMN : // A8.6.33
991// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
992// IIC_iCMPr,
993// "cmn", "\t$lhs, $rhs",
994// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000995
996def tCMNz : // A8.6.33
997 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
998 IIC_iCMPr,
999 "cmn", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001000 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001001
1002} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +00001003
David Goodwine85169c2009-06-25 22:49:55 +00001004// CMP immediate
Gabor Greif22f69222010-09-14 22:00:50 +00001005let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach4f240a12011-08-18 18:08:29 +00001006def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
Bill Wendlingc31de252010-11-20 22:52:33 +00001007 "cmp", "\t$Rn, $imm8",
1008 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001009 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendlingc31de252010-11-20 22:52:33 +00001010 // A8.6.35
1011 bits<3> Rn;
1012 bits<8> imm8;
1013 let Inst{10-8} = Rn;
1014 let Inst{7-0} = imm8;
1015}
1016
David Goodwine85169c2009-06-25 22:49:55 +00001017// CMP register
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001018def tCMPr : // A8.6.36 T1
1019 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1020 IIC_iCMPr,
1021 "cmp", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001022 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001023
Bill Wendling775899e2010-11-29 00:18:15 +00001024def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1025 "cmp", "\t$Rn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001026 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendling775899e2010-11-29 00:18:15 +00001027 // A8.6.36 T2
1028 bits<4> Rm;
1029 bits<4> Rn;
1030 let Inst{7} = Rn{3};
1031 let Inst{6-3} = Rm;
1032 let Inst{2-0} = Rn{2-0};
1033}
Bill Wendlingc31de252010-11-20 22:52:33 +00001034} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +00001035
Evan Cheng10043e22007-01-19 07:51:42 +00001036
David Goodwine85169c2009-06-25 22:49:55 +00001037// XOR register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001038let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001039def tEOR : // A8.6.45
1040 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1041 IIC_iBITr,
1042 "eor", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001043 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001044
David Goodwine85169c2009-06-25 22:49:55 +00001045// LSL immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001046def tLSLri : // A8.6.88
Jim Grosbach5503c3a2011-08-19 19:29:25 +00001047 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001048 IIC_iMOVsi,
1049 "lsl", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001050 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
1051 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001052 bits<5> imm5;
1053 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001054}
Evan Cheng10043e22007-01-19 07:51:42 +00001055
David Goodwine85169c2009-06-25 22:49:55 +00001056// LSL register
Bill Wendling4915f562010-12-01 00:48:44 +00001057def tLSLrr : // A8.6.89
1058 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1059 IIC_iMOVsr,
1060 "lsl", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001061 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001062
David Goodwine85169c2009-06-25 22:49:55 +00001063// LSR immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001064def tLSRri : // A8.6.90
Owen Andersonc4030382011-08-08 20:42:17 +00001065 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001066 IIC_iMOVsi,
1067 "lsr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001068 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1069 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001070 bits<5> imm5;
1071 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001072}
Evan Cheng10043e22007-01-19 07:51:42 +00001073
David Goodwine85169c2009-06-25 22:49:55 +00001074// LSR register
Bill Wendling4915f562010-12-01 00:48:44 +00001075def tLSRrr : // A8.6.91
1076 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1077 IIC_iMOVsr,
1078 "lsr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001079 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001080
Bill Wendling22db3132010-11-21 11:49:36 +00001081// Move register
Evan Cheng7f8ab6e2010-11-17 20:13:28 +00001082let isMoveImm = 1 in
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001083def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendling22db3132010-11-21 11:49:36 +00001084 "mov", "\t$Rd, $imm8",
1085 [(set tGPR:$Rd, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001086 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001087 // A8.6.96
1088 bits<3> Rd;
1089 bits<8> imm8;
1090 let Inst{10-8} = Rd;
1091 let Inst{7-0} = imm8;
1092}
Jim Grosbachf86cd372011-08-19 20:46:54 +00001093// Because we have an explicit tMOVSr below, we need an alias to handle
1094// the immediate "movs" form here. Blech.
Jim Grosbach6caa5572011-08-22 18:04:24 +00001095def : tInstAlias <"movs $Rdn, $imm",
1096 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001097
Jim Grosbach4def7042011-07-01 17:14:11 +00001098// A7-73: MOV(2) - mov setting flag.
Evan Cheng10043e22007-01-19 07:51:42 +00001099
Craig Topperc50d64b2014-11-26 00:46:26 +00001100let hasSideEffects = 0 in {
Jim Grosbache9cc9012011-06-30 23:38:17 +00001101def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson651b2302011-07-13 23:22:26 +00001102 2, IIC_iMOVr,
Jim Grosbachb98ab912011-06-30 22:10:46 +00001103 "mov", "\t$Rd, $Rm", "", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001104 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001105 // A8.6.97
1106 bits<4> Rd;
1107 bits<4> Rm;
Jim Grosbache9cc9012011-06-30 23:38:17 +00001108 let Inst{7} = Rd{3};
1109 let Inst{6-3} = Rm;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001110 let Inst{2-0} = Rd{2-0};
1111}
Evan Chengcd4cdd12009-07-11 06:43:01 +00001112let Defs = [CPSR] in
Bill Wendling4d8ff862010-12-03 01:55:47 +00001113def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001114 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001115 // A8.6.97
1116 bits<3> Rd;
1117 bits<3> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +00001118 let Inst{15-6} = 0b0000000000;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001119 let Inst{5-3} = Rm;
1120 let Inst{2-0} = Rd;
Johnny Chenc28e6292009-12-15 17:24:14 +00001121}
Craig Topperc50d64b2014-11-26 00:46:26 +00001122} // hasSideEffects
Evan Cheng10043e22007-01-19 07:51:42 +00001123
Bill Wendling9c258942010-12-01 02:36:55 +00001124// Multiply register
Jim Grosbachbfeb4f72011-08-22 23:25:48 +00001125let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001126def tMUL : // A8.6.105 T1
Jim Grosbach8e048492011-08-19 22:07:46 +00001127 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1128 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1129 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1130 T1DataProcessing<0b1101> {
1131 bits<3> Rd;
1132 bits<3> Rn;
1133 let Inst{5-3} = Rn;
1134 let Inst{2-0} = Rd;
1135 let AsmMatchConverter = "cvtThumbMultiply";
1136}
1137
Jim Grosbach6caa5572011-08-22 18:04:24 +00001138def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1139 pred:$p)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001140
Bill Wendling490240a2010-12-01 01:20:15 +00001141// Move inverse register
1142def tMVN : // A8.6.107
1143 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1144 "mvn", "\t$Rd, $Rn",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001145 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001146
Bill Wendling22db3132010-11-21 11:49:36 +00001147// Bitwise or register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001148let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001149def tORR : // A8.6.114
1150 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1151 IIC_iBITr,
1152 "orr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001153 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001154
Bill Wendling22db3132010-11-21 11:49:36 +00001155// Swaps
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001156def tREV : // A8.6.134
1157 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1158 IIC_iUNAr,
1159 "rev", "\t$Rd, $Rm",
1160 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001161 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001162
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001163def tREV16 : // A8.6.135
1164 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1165 IIC_iUNAr,
1166 "rev16", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001167 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001168 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001169
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001170def tREVSH : // A8.6.136
1171 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1172 IIC_iUNAr,
1173 "revsh", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001174 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001175 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001176
Bill Wendling4915f562010-12-01 00:48:44 +00001177// Rotate right register
1178def tROR : // A8.6.139
1179 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1180 IIC_iMOVsr,
1181 "ror", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001182 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1183 Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001184
Bill Wendling4915f562010-12-01 00:48:44 +00001185// Negate register
Bill Wendling490240a2010-12-01 01:20:15 +00001186def tRSB : // A8.6.141
1187 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1188 IIC_iALUi,
1189 "rsb", "\t$Rd, $Rn, #0",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001190 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001191
David Goodwine85169c2009-06-25 22:49:55 +00001192// Subtract with carry register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001193let Uses = [CPSR] in
Bill Wendling4915f562010-12-01 00:48:44 +00001194def tSBC : // A8.6.151
1195 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1196 IIC_iALUr,
1197 "sbc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001198 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>,
1199 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001200
David Goodwine85169c2009-06-25 22:49:55 +00001201// Subtract immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001202def tSUBi3 : // A8.6.210 T1
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001203 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Bill Wendling490240a2010-12-01 01:20:15 +00001204 IIC_iALUi,
1205 "sub", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001206 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1207 Sched<[WriteALU]> {
Bill Wendlingccba1a82010-11-29 01:00:43 +00001208 bits<3> imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001209 let Inst{8-6} = imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001210}
Jim Grosbach669f1d02009-03-27 23:06:27 +00001211
Bill Wendling4915f562010-12-01 00:48:44 +00001212def tSUBi8 : // A8.6.210 T2
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001213 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1214 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +00001215 "sub", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001216 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1217 Sched<[WriteALU]>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001218
Bill Wendling490240a2010-12-01 01:20:15 +00001219// Subtract register
1220def tSUBrr : // A8.6.212
1221 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1222 IIC_iALUr,
1223 "sub", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001224 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1225 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001226
Bill Wendling490240a2010-12-01 01:20:15 +00001227// Sign-extend byte
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001228def tSXTB : // A8.6.222
1229 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1230 IIC_iUNAr,
1231 "sxtb", "\t$Rd, $Rm",
1232 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001233 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1234 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001235
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001236// Sign-extend short
1237def tSXTH : // A8.6.224
1238 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1239 IIC_iUNAr,
1240 "sxth", "\t$Rd, $Rm",
1241 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001242 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1243 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001244
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001245// Test
Gabor Greif2afac8e2010-09-14 20:47:43 +00001246let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001247def tTST : // A8.6.230
1248 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1249 "tst", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001250 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1251 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001252
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001253// A8.8.247 UDF - Undefined (Encoding T1)
Saleem Abdulrasool2bd12622014-05-22 04:46:46 +00001254def tUDF : TI<(outs), (ins imm0_255:$imm8), IIC_Br, "udf\t$imm8",
1255 [(int_arm_undefined imm0_255:$imm8)]>, Encoding16 {
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001256 bits<8> imm8;
1257 let Inst{15-12} = 0b1101;
1258 let Inst{11-8} = 0b1110;
1259 let Inst{7-0} = imm8;
1260}
1261
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001262// Zero-extend byte
1263def tUXTB : // A8.6.262
1264 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1265 IIC_iUNAr,
1266 "uxtb", "\t$Rd, $Rm",
1267 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001268 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1269 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001270
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001271// Zero-extend short
1272def tUXTH : // A8.6.264
1273 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1274 IIC_iUNAr,
1275 "uxth", "\t$Rd, $Rm",
1276 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001277 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001278
Jim Grosbach3e2cad32010-02-16 21:23:02 +00001279// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman453d64c2009-10-29 18:10:34 +00001280// Expanded after instruction selection into a branch sequence.
1281let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Chengbb2af352009-08-12 05:17:19 +00001282 def tMOVCCr_pseudo :
Tim Northover42180442013-08-22 09:57:11 +00001283 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1284 NoItinerary,
1285 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001286
1287// tLEApcrel - Load a pc-relative address into a register without offending the
1288// assembler.
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001289
1290def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
Jim Grosbache2a04042011-08-17 20:37:40 +00001291 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001292 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
Bill Wendling85a8a722010-11-30 00:18:30 +00001293 bits<3> Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001294 bits<8> addr;
Bill Wendling85a8a722010-11-30 00:18:30 +00001295 let Inst{10-8} = Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001296 let Inst{7-0} = addr;
Owen Andersone0152a72011-08-09 20:55:18 +00001297 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendling85a8a722010-11-30 00:18:30 +00001298}
Evan Cheng10043e22007-01-19 07:51:42 +00001299
Craig Topperc50d64b2014-11-26 00:46:26 +00001300let hasSideEffects = 0, isReMaterializable = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001301def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001302 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001303
Jakob Stoklund Olesen74352492012-08-24 22:46:55 +00001304let hasSideEffects = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001305def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
Tim Northover4998a472015-05-13 20:28:38 +00001306 (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001307 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001308
Evan Cheng10043e22007-01-19 07:51:42 +00001309//===----------------------------------------------------------------------===//
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001310// TLS Instructions
1311//
1312
1313// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbache4750ef2011-06-30 19:38:01 +00001314// This is a pseudo inst so that we can get the encoding right,
1315// complete with fixup for the aeabi_read_tp function.
1316let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson651b2302011-07-13 23:22:26 +00001317def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001318 [(set R0, ARMthread_pointer)]>,
1319 Sched<[WriteBr]>;
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001320
Bill Wendling9c258942010-12-01 02:36:55 +00001321//===----------------------------------------------------------------------===//
Jim Grosbach36d4dec2009-12-01 18:10:36 +00001322// SJLJ Exception handling intrinsics
Owen Andersonb7456232011-05-11 17:00:48 +00001323//
Bill Wendling9c258942010-12-01 02:36:55 +00001324
1325// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1326// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1327// from some other function to get here, and we're using the stack frame for the
1328// containing function to save/restore registers, we can't keep anything live in
1329// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner0ab5e2c2011-04-15 05:18:47 +00001330// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling9c258942010-12-01 02:36:55 +00001331// registers except for our own input by listing the relevant registers in
1332// Defs. By doing so, we also cause the prologue/epilogue code to actively
1333// preserve all of the callee-saved resgisters, which is exactly what we want.
1334// $val is a scratch register for our use.
Andrew Trick410172b2011-06-07 00:08:49 +00001335let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendlingaa9047d2011-10-17 22:26:23 +00001336 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1337 usesCustomInserter = 1 in
Bill Wendlingddce9f32010-11-30 00:50:22 +00001338def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson651b2302011-07-13 23:22:26 +00001339 AddrModeNone, 0, NoItinerary, "","",
Bill Wendlingddce9f32010-11-30 00:50:22 +00001340 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001341
Evan Cheng68132d82011-12-20 18:26:50 +00001342// FIXME: Non-IOS version(s)
Chris Lattner9492c172010-10-31 19:15:18 +00001343let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001344 Defs = [ R7, LR, SP ] in
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001345def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson651b2302011-07-13 23:22:26 +00001346 AddrModeNone, 0, IndexModeNone,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001347 Pseudo, NoItinerary, "", "",
1348 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
Saleem Abdulrasool1632fe12016-03-10 16:26:37 +00001349 Requires<[IsThumb,IsNotWindows]>;
1350
1351let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
1352 Defs = [ R11, LR, SP ] in
1353def tInt_WIN_eh_sjlj_longjmp
1354 : XI<(outs), (ins GPR:$src, GPR:$scratch), AddrModeNone, 0, IndexModeNone,
1355 Pseudo, NoItinerary, "", "", [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
1356 Requires<[IsThumb,IsWindows]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001357
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001358//===----------------------------------------------------------------------===//
Evan Cheng10043e22007-01-19 07:51:42 +00001359// Non-Instruction Patterns
1360//
1361
Jim Grosbach327cf8e2010-12-07 20:41:06 +00001362// Comparisons
1363def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1364 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1365def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1366 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1367
Evan Cheng61671c82009-07-10 02:09:04 +00001368// Add with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001369def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1370 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1371def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng01de9852009-08-20 17:01:04 +00001372 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwine5b969f2009-07-27 19:59:26 +00001373def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1374 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001375
1376// Subtract with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001377def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1378 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1379def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1380 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1381def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1382 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001383
Louis Gerbargefdcf232014-05-12 19:53:52 +00001384// Bswap 16 with load/store
Louis Gerbargefdcf232014-05-12 19:53:52 +00001385def : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
1386 (tREV16 (tLDRHi t_addrmode_is2:$addr))>;
John Brawn68acdcb2015-08-13 10:48:22 +00001387def : T1Pat<(srl (bswap (extloadi16 t_addrmode_rr:$addr)), (i32 16)),
1388 (tREV16 (tLDRHr t_addrmode_rr:$addr))>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001389def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1390 t_addrmode_is2:$addr),
1391 (tSTRHi(tREV16 tGPR:$Rn), t_addrmode_is2:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001392def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1393 t_addrmode_rr:$addr),
1394 (tSTRHr (tREV16 tGPR:$Rn), t_addrmode_rr:$addr)>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001395
Tim Northoverdfe2156c2013-11-25 14:40:57 +00001396// ConstantPool
David Goodwine5b969f2009-07-27 19:59:26 +00001397def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001398
Tim Northover72360d22013-12-02 10:35:41 +00001399// GlobalAddress
Tim Northover1328c1a2014-01-13 14:19:17 +00001400def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
Tim Northover72360d22013-12-02 10:35:41 +00001401 IIC_iLoadiALU,
Tim Northover1328c1a2014-01-13 14:19:17 +00001402 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001403 (ARMWrapperPIC tglobaladdr:$addr))]>,
1404 Requires<[IsThumb, DontUseMovt]>;
1405
Tim Northover1328c1a2014-01-13 14:19:17 +00001406def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1407 IIC_iLoad_i,
1408 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001409 (ARMWrapper tglobaladdr:$src))]>,
1410 Requires<[IsThumb, DontUseMovt]>;
1411
Tim Northoverbd41cf82016-01-07 09:03:03 +00001412// TLS globals
1413def : Pat<(ARMWrapperPIC tglobaltlsaddr:$addr),
1414 (tLDRLIT_ga_pcrel tglobaltlsaddr:$addr)>,
1415 Requires<[IsThumb, DontUseMovt]>;
1416def : Pat<(ARMWrapper tglobaltlsaddr:$addr),
1417 (tLDRLIT_ga_abs tglobaltlsaddr:$addr)>,
1418 Requires<[IsThumb, DontUseMovt]>;
1419
Tim Northover72360d22013-12-02 10:35:41 +00001420
Evan Cheng0701c5a2007-01-27 02:29:45 +00001421// JumpTable
Tim Northover4998a472015-05-13 20:28:38 +00001422def : T1Pat<(ARMWrapperJT tjumptable:$dst),
1423 (tLEApcrelJT tjumptable:$dst)>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001424
Evan Cheng10043e22007-01-19 07:51:42 +00001425// Direct calls
Tim Northoverb5ece522016-05-10 19:17:47 +00001426def : T1Pat<(ARMcall texternalsym:$func), (tBL texternalsym:$func)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001427 Requires<[IsThumb]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001428
Evan Cheng10043e22007-01-19 07:51:42 +00001429// zextload i1 -> zextload i8
Bill Wendling092a7bd2010-12-14 03:36:38 +00001430def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1431 (tLDRBi t_addrmode_is1:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001432def : T1Pat<(zextloadi1 t_addrmode_rr:$addr),
1433 (tLDRBr t_addrmode_rr:$addr)>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001434
Renato Golinb9887ef2015-02-25 14:41:06 +00001435// extload from the stack -> word load from the stack, as it avoids having to
1436// materialize the base in a separate register. This only works when a word
1437// load puts the byte/halfword value in the same place in the register that the
1438// byte/halfword load would, i.e. when little-endian.
1439def : T1Pat<(extloadi1 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1440 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1441def : T1Pat<(extloadi8 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1442 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1443def : T1Pat<(extloadi16 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1444 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1445
Evan Chengd02d75c2007-01-26 19:13:16 +00001446// extload -> zextload
John Brawn68acdcb2015-08-13 10:48:22 +00001447def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1448def : T1Pat<(extloadi1 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1449def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1450def : T1Pat<(extloadi8 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1451def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1452def : T1Pat<(extloadi16 t_addrmode_rr:$addr), (tLDRHr t_addrmode_rr:$addr)>;
Evan Chengd02d75c2007-01-26 19:13:16 +00001453
James Molloyb3326df2016-07-15 08:03:56 +00001454// post-inc loads and stores
1455
1456// post-inc LDR -> LDM r0!, {r1}. The way operands are layed out in LDMs is
1457// different to how ISel expects them for a post-inc load, so use a pseudo
1458// and expand it just after ISel.
1459let usesCustomInserter = 1,
1460 Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in
1461 def tLDR_postidx: tPseudoInst<(outs rGPR:$Rt, rGPR:$Rn_wb),
1462 (ins rGPR:$Rn, pred:$p),
1463 4, IIC_iStore_ru,
1464 []>;
1465
1466// post-inc STR -> STM r0!, {r1}. The layout of this (because it doesn't def
1467// multiple registers) is the same in ISel as MachineInstr, so there's no need
1468// for a pseudo.
1469def : T1Pat<(post_store rGPR:$Rt, rGPR:$Rn, 4),
1470 (tSTMIA_UPD rGPR:$Rn, rGPR:$Rt)>;
1471
Evan Cheng6da267d2009-08-28 00:31:43 +00001472// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng0794c6a2009-07-11 07:08:13 +00001473// ldr{b|h} + sxt{b|h} instead.
Bill Wendling1171e9e2010-12-15 00:58:57 +00001474def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1475 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1476 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001477def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1478 (tSXTB (tLDRBr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001479 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001480def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1481 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1482 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001483def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1484 (tSXTH (tLDRHr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001485 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001486
Bill Wendling1171e9e2010-12-15 00:58:57 +00001487def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1488 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001489def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1490 (tASRri (tLSLri (tLDRBr t_addrmode_rr:$addr), 24), 24)>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001491def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1492 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001493def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1494 (tASRri (tLSLri (tLDRHr t_addrmode_rr:$addr), 16), 16)>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001495
Eli Friedmanba912e02011-09-15 22:18:49 +00001496def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001497 (tLDRBi t_addrmode_is1:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001498def : T1Pat<(atomic_load_8 t_addrmode_rr:$src),
1499 (tLDRBr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001500def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001501 (tLDRHi t_addrmode_is2:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001502def : T1Pat<(atomic_load_16 t_addrmode_rr:$src),
1503 (tLDRHr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001504def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001505 (tLDRi t_addrmode_is4:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001506def : T1Pat<(atomic_load_32 t_addrmode_rr:$src),
1507 (tLDRr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001508def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1509 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001510def : T1Pat<(atomic_store_8 t_addrmode_rr:$ptr, tGPR:$val),
1511 (tSTRBr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001512def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1513 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001514def : T1Pat<(atomic_store_16 t_addrmode_rr:$ptr, tGPR:$val),
1515 (tSTRHr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001516def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1517 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001518def : T1Pat<(atomic_store_32 t_addrmode_rr:$ptr, tGPR:$val),
1519 (tSTRr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001520
Evan Cheng10043e22007-01-19 07:51:42 +00001521// Large immediate handling.
1522
1523// Two piece imms.
Evan Chengeab9ca72009-06-27 02:26:13 +00001524def : T1Pat<(i32 thumb_immshifted:$src),
1525 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1526 (thumb_immshifted_shamt imm:$src))>;
Evan Cheng10043e22007-01-19 07:51:42 +00001527
Evan Chengeab9ca72009-06-27 02:26:13 +00001528def : T1Pat<(i32 imm0_255_comp:$src),
1529 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Cheng207b2462009-11-06 23:52:48 +00001530
James Molloy65b6be12016-06-14 13:33:07 +00001531def : T1Pat<(i32 imm256_510:$src),
James Molloyb1013832016-06-07 13:10:14 +00001532 (tADDi8 (tMOVi8 255),
James Molloy65b6be12016-06-14 13:33:07 +00001533 (thumb_imm256_510_addend imm:$src))>;
James Molloyb1013832016-06-07 13:10:14 +00001534
Evan Cheng207b2462009-11-06 23:52:48 +00001535// Pseudo instruction that combines ldr from constpool and add pc. This should
1536// be expanded into two instructions late to allow if-conversion and
1537// scheduling.
1538let isReMaterializable = 1 in
1539def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling9c258942010-12-01 02:36:55 +00001540 NoItinerary,
Evan Cheng207b2462009-11-06 23:52:48 +00001541 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1542 imm:$cp))]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001543 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001544
1545// Pseudo-instruction for merged POP and return.
1546// FIXME: remove when we have a way to marking a MI with these properties.
1547let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1548 hasExtraDefRegAllocReq = 1 in
1549def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +00001550 2, IIC_iPop_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001551 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001552
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001553// Indirect branch using "mov pc, $Rm"
1554let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach39c67b52011-07-08 22:33:49 +00001555 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001556 2, IIC_Br, [(brind GPR:$Rm)],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001557 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001558}
Jim Grosbach25977222011-08-19 23:24:36 +00001559
1560
1561// In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1562// encoding is available on ARMv6K, but we don't differentiate that finely.
Sjoerd Meijer9da258d2016-06-03 13:19:43 +00001563def : InstAlias<"nop", (tMOVr R8, R8, 14, 0), 0>, Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach08a47802011-09-20 00:10:37 +00001564
1565
1566// For round-trip assembly/disassembly, we have to handle a CPS instruction
1567// without any iflags. That's not, strictly speaking, valid syntax, but it's
Benjamin Kramerbde91762012-06-02 10:20:22 +00001568// a useful extension and assembles to defined behaviour (the insn does
Jim Grosbach08a47802011-09-20 00:10:37 +00001569// nothing).
1570def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1571def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
Jim Grosbach561e4e12011-12-13 20:23:22 +00001572
1573// "neg" is and alias for "rsb rd, rn, #0"
1574def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1575 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1576
Jim Grosbachad66de12012-04-11 00:15:16 +00001577
1578// Implied destination operand forms for shifts.
1579def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1580 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1581def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1582 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1583def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1584 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
Renato Golin3f126132016-05-12 21:22:31 +00001585
1586// Pseudo instruction ldr Rt, =immediate
1587def tLDRConstPool
1588 : tAsmPseudo<"ldr${p} $Rt, $immediate",
1589 (ins tGPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;