blob: 842ddcde4944fdedff0f2d081d97db68c9c77548 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- ARMInstrThumb.td - Thumb support for ARM -----------*- tablegen -*-===//
Evan Cheng10043e22007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Cheng10043e22007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Thumb specific DAG Nodes.
16//
17
18def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
Chris Lattner2a0a3b42010-12-23 18:28:41 +000019 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
Chris Lattner04336992010-03-19 05:33:51 +000020 SDNPVariadic]>;
Evan Cheng10043e22007-01-19 07:51:42 +000021
Jim Grosbach46dd4132011-08-17 21:51:27 +000022def imm_sr_XFORM: SDNodeXForm<imm, [{
23 unsigned Imm = N->getZExtValue();
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000024 return CurDAG->getTargetConstant((Imm == 32 ? 0 : Imm), SDLoc(N), MVT::i32);
Jim Grosbach46dd4132011-08-17 21:51:27 +000025}]>;
26def ThumbSRImmAsmOperand: AsmOperandClass { let Name = "ImmThumbSR"; }
27def imm_sr : Operand<i32>, PatLeaf<(imm), [{
28 uint64_t Imm = N->getZExtValue();
Owen Andersonc4030382011-08-08 20:42:17 +000029 return Imm > 0 && Imm <= 32;
Jim Grosbach46dd4132011-08-17 21:51:27 +000030}], imm_sr_XFORM> {
31 let PrintMethod = "printThumbSRImm";
32 let ParserMatchClass = ThumbSRImmAsmOperand;
Owen Andersonc4030382011-08-08 20:42:17 +000033}
34
Evan Cheng10043e22007-01-19 07:51:42 +000035def imm_comp_XFORM : SDNodeXForm<imm, [{
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000036 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), SDLoc(N),
37 MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000038}]>;
39
Evan Cheng10043e22007-01-19 07:51:42 +000040def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000041 return (uint32_t)-N->getZExtValue() < 8;
Evan Cheng10043e22007-01-19 07:51:42 +000042}], imm_neg_XFORM>;
43
Evan Cheng10043e22007-01-19 07:51:42 +000044def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000045 return ~((uint32_t)N->getZExtValue()) < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000046}]>;
47
Eric Christophera98cd222011-04-28 05:49:04 +000048def imm8_255 : ImmLeaf<i32, [{
49 return Imm >= 8 && Imm < 256;
Evan Cheng10043e22007-01-19 07:51:42 +000050}]>;
51def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000052 unsigned Val = -N->getZExtValue();
Evan Cheng10043e22007-01-19 07:51:42 +000053 return Val >= 8 && Val < 256;
54}], imm_neg_XFORM>;
55
Bill Wendling9c258942010-12-01 02:36:55 +000056// Break imm's up into two pieces: an immediate + a left shift. This uses
57// thumb_immshifted to match and thumb_immshifted_val and thumb_immshifted_shamt
58// to get the val/shift pieces.
Evan Cheng10043e22007-01-19 07:51:42 +000059def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000060 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Evan Cheng10043e22007-01-19 07:51:42 +000061}]>;
62
63def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000064 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000065 return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000066}]>;
67
68def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000069 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Sergey Dmitrouk842a51b2015-04-28 14:05:47 +000070 return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);
Evan Cheng10043e22007-01-19 07:51:42 +000071}]>;
72
Evan Chengb1852592009-11-19 06:57:41 +000073// Scaled 4 immediate.
Jim Grosbach0a0b3072011-08-24 21:22:15 +000074def t_imm0_1020s4_asmoperand: AsmOperandClass { let Name = "Imm0_1020s4"; }
75def t_imm0_1020s4 : Operand<i32> {
Evan Chengb1852592009-11-19 06:57:41 +000076 let PrintMethod = "printThumbS4ImmOperand";
Jim Grosbach0a0b3072011-08-24 21:22:15 +000077 let ParserMatchClass = t_imm0_1020s4_asmoperand;
78 let OperandType = "OPERAND_IMMEDIATE";
79}
80
81def t_imm0_508s4_asmoperand: AsmOperandClass { let Name = "Imm0_508s4"; }
82def t_imm0_508s4 : Operand<i32> {
83 let PrintMethod = "printThumbS4ImmOperand";
84 let ParserMatchClass = t_imm0_508s4_asmoperand;
Benjamin Kramer3ceac212011-07-14 21:47:24 +000085 let OperandType = "OPERAND_IMMEDIATE";
Evan Chengb1852592009-11-19 06:57:41 +000086}
Jim Grosbach930f2f62012-04-05 20:57:13 +000087// Alias use only, so no printer is necessary.
88def t_imm0_508s4_neg_asmoperand: AsmOperandClass { let Name = "Imm0_508s4Neg"; }
89def t_imm0_508s4_neg : Operand<i32> {
90 let ParserMatchClass = t_imm0_508s4_neg_asmoperand;
91 let OperandType = "OPERAND_IMMEDIATE";
92}
Evan Chengb1852592009-11-19 06:57:41 +000093
Evan Cheng10043e22007-01-19 07:51:42 +000094// Define Thumb specific addressing modes.
95
Mihai Popad36cbaa2013-07-03 09:21:44 +000096// unsigned 8-bit, 2-scaled memory offset
97class OperandUnsignedOffset_b8s2 : AsmOperandClass {
98 let Name = "UnsignedOffset_b8s2";
99 let PredicateMethod = "isUnsignedOffset<8, 2>";
100}
101
102def UnsignedOffset_b8s2 : OperandUnsignedOffset_b8s2;
103
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000104// thumb style PC relative operand. signed, 8 bits magnitude,
105// two bits shift. can be represented as either [pc, #imm], #imm,
106// or relocatable expression...
107def ThumbMemPC : AsmOperandClass {
108 let Name = "ThumbMemPC";
109}
110
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000111let OperandType = "OPERAND_PCREL" in {
Jim Grosbache119da12010-12-10 18:21:33 +0000112def t_brtarget : Operand<OtherVT> {
113 let EncoderMethod = "getThumbBRTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000114 let DecoderMethod = "DecodeThumbBROperand";
Jim Grosbache119da12010-12-10 18:21:33 +0000115}
116
Mihai Popad36cbaa2013-07-03 09:21:44 +0000117// ADR instruction labels.
118def t_adrlabel : Operand<i32> {
119 let EncoderMethod = "getThumbAdrLabelOpValue";
120 let PrintMethod = "printAdrLabelOperand<2>";
121 let ParserMatchClass = UnsignedOffset_b8s2;
122}
123
Jim Grosbach78485ad2010-12-10 17:13:40 +0000124def t_bcctarget : Operand<i32> {
125 let EncoderMethod = "getThumbBCCTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000126 let DecoderMethod = "DecodeThumbBCCTargetOperand";
Jim Grosbach78485ad2010-12-10 17:13:40 +0000127}
128
Jim Grosbach529c7e82010-12-09 19:01:46 +0000129def t_cbtarget : Operand<i32> {
Jim Grosbach62b68112010-12-09 19:04:53 +0000130 let EncoderMethod = "getThumbCBTargetOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000131 let DecoderMethod = "DecodeThumbCmpBROperand";
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000132}
133
Jim Grosbach9e199462010-12-06 23:57:07 +0000134def t_bltarget : Operand<i32> {
135 let EncoderMethod = "getThumbBLTargetOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000136 let DecoderMethod = "DecodeThumbBLTargetOperand";
Jim Grosbach9e199462010-12-06 23:57:07 +0000137}
138
Bill Wendling3392bfc2010-12-09 00:39:08 +0000139def t_blxtarget : Operand<i32> {
140 let EncoderMethod = "getThumbBLXTargetOpValue";
Owen Andersonc4030382011-08-08 20:42:17 +0000141 let DecoderMethod = "DecodeThumbBLXOffset";
Bill Wendling3392bfc2010-12-09 00:39:08 +0000142}
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000143
144// t_addrmode_pc := <label> => pc + imm8 * 4
145//
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000146def t_addrmode_pc : MemOperand {
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000147 let EncoderMethod = "getAddrModePCOpValue";
148 let DecoderMethod = "DecodeThumbAddrModePC";
149 let PrintMethod = "printThumbLdrLabelOperand";
150 let ParserMatchClass = ThumbMemPC;
151}
Benjamin Kramer3ceac212011-07-14 21:47:24 +0000152}
Bill Wendling3392bfc2010-12-09 00:39:08 +0000153
Evan Cheng10043e22007-01-19 07:51:42 +0000154// t_addrmode_rr := reg + reg
155//
Jim Grosbachd3595712011-08-03 23:50:40 +0000156def t_addrmode_rr_asm_operand : AsmOperandClass { let Name = "MemThumbRR"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000157def t_addrmode_rr : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000158 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
Bill Wendling092a7bd2010-12-14 03:36:38 +0000159 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Evan Cheng10043e22007-01-19 07:51:42 +0000160 let PrintMethod = "printThumbAddrModeRROperand";
Owen Anderson3157f2e2011-08-15 19:00:06 +0000161 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbach7c4739d2011-08-19 19:17:58 +0000162 let ParserMatchClass = t_addrmode_rr_asm_operand;
Jim Grosbachfde21102009-04-07 20:34:09 +0000163 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000164}
165
Bill Wendling092a7bd2010-12-14 03:36:38 +0000166// t_addrmode_rrs := reg + reg
Evan Cheng10043e22007-01-19 07:51:42 +0000167//
Jim Grosbache9380702011-08-19 16:52:32 +0000168// We use separate scaled versions because the Select* functions need
169// to explicitly check for a matching constant and return false here so that
170// the reg+imm forms will match instead. This is a horrible way to do that,
171// as it forces tight coupling between the methods, but it's how selectiondag
172// currently works.
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000173def t_addrmode_rrs1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000174 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S1", []> {
175 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
176 let PrintMethod = "printThumbAddrModeRROperand";
Owen Andersone0152a72011-08-09 20:55:18 +0000177 let DecoderMethod = "DecodeThumbAddrModeRR";
Jim Grosbachd3595712011-08-03 23:50:40 +0000178 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000179 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Evan Cheng10043e22007-01-19 07:51:42 +0000180}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000181def t_addrmode_rrs2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000182 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S2", []> {
183 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000184 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000185 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbachd3595712011-08-03 23:50:40 +0000186 let ParserMatchClass = t_addrmode_rr_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000187 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000188}
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000189def t_addrmode_rrs4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000190 ComplexPattern<i32, 2, "SelectThumbAddrModeRI5S4", []> {
191 let EncoderMethod = "getThumbAddrModeRegRegOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000192 let DecoderMethod = "DecodeThumbAddrModeRR";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000193 let PrintMethod = "printThumbAddrModeRROperand";
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}
Evan Chengc0b73662007-01-23 22:59:13 +0000197
Bill Wendling092a7bd2010-12-14 03:36:38 +0000198// t_addrmode_is4 := reg + imm5 * 4
Evan Chengc0b73662007-01-23 22:59:13 +0000199//
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000200def t_addrmode_is4_asm_operand : AsmOperandClass { let Name = "MemThumbRIs4"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000201def t_addrmode_is4 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000202 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S4", []> {
203 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000204 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000205 let PrintMethod = "printThumbAddrModeImm5S4Operand";
Jim Grosbach3fe94e32011-08-19 17:55:24 +0000206 let ParserMatchClass = t_addrmode_is4_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000207 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000208}
209
210// t_addrmode_is2 := reg + imm5 * 2
211//
Jim Grosbach26d35872011-08-19 18:55:51 +0000212def t_addrmode_is2_asm_operand : AsmOperandClass { let Name = "MemThumbRIs2"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000213def t_addrmode_is2 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000214 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S2", []> {
215 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000216 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000217 let PrintMethod = "printThumbAddrModeImm5S2Operand";
Jim Grosbach26d35872011-08-19 18:55:51 +0000218 let ParserMatchClass = t_addrmode_is2_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000219 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000220}
221
222// t_addrmode_is1 := reg + imm5
223//
Jim Grosbacha32c7532011-08-19 18:49:59 +0000224def t_addrmode_is1_asm_operand : AsmOperandClass { let Name = "MemThumbRIs1"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000225def t_addrmode_is1 : MemOperand,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000226 ComplexPattern<i32, 2, "SelectThumbAddrModeImm5S1", []> {
227 let EncoderMethod = "getAddrModeISOpValue";
Owen Andersone0152a72011-08-09 20:55:18 +0000228 let DecoderMethod = "DecodeThumbAddrModeIS";
Bill Wendling092a7bd2010-12-14 03:36:38 +0000229 let PrintMethod = "printThumbAddrModeImm5S1Operand";
Jim Grosbacha32c7532011-08-19 18:49:59 +0000230 let ParserMatchClass = t_addrmode_is1_asm_operand;
Bill Wendling092a7bd2010-12-14 03:36:38 +0000231 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000232}
233
234// t_addrmode_sp := sp + imm8 * 4
235//
Jim Grosbach505be7592011-08-23 18:39:41 +0000236// FIXME: This really shouldn't have an explicit SP operand at all. It should
237// be implicit, just like in the instruction encoding itself.
Jim Grosbach23983d62011-08-19 18:13:48 +0000238def t_addrmode_sp_asm_operand : AsmOperandClass { let Name = "MemThumbSPI"; }
Ahmed Bougacha273a9b42015-04-07 20:31:16 +0000239def t_addrmode_sp : MemOperand,
Evan Cheng10043e22007-01-19 07:51:42 +0000240 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000241 let EncoderMethod = "getAddrModeThumbSPOpValue";
Owen Anderson03ac20f2011-08-08 23:25:22 +0000242 let DecoderMethod = "DecodeThumbAddrModeSP";
Evan Cheng10043e22007-01-19 07:51:42 +0000243 let PrintMethod = "printThumbAddrModeSPOperand";
Jim Grosbach23983d62011-08-19 18:13:48 +0000244 let ParserMatchClass = t_addrmode_sp_asm_operand;
Jakob Stoklund Olesena94837d2010-01-13 00:43:06 +0000245 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
Evan Cheng10043e22007-01-19 07:51:42 +0000246}
247
248//===----------------------------------------------------------------------===//
249// Miscellaneous Instructions.
250//
251
Jim Grosbach45fceea2010-02-22 23:10:38 +0000252// FIXME: Marking these as hasSideEffects is necessary to prevent machine DCE
253// from removing one half of the matched pairs. That breaks PEI, which assumes
254// these will always be in pairs, and asserts if it finds otherwise. Better way?
255let Defs = [SP], Uses = [SP], hasSideEffects = 1 in {
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000256def tADJCALLSTACKUP :
Bill Wendling49a2e232010-11-19 22:02:18 +0000257 PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2), NoItinerary,
258 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>,
259 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000260
Jim Grosbach669f1d02009-03-27 23:06:27 +0000261def tADJCALLSTACKDOWN :
Bill Wendling49a2e232010-11-19 22:02:18 +0000262 PseudoInst<(outs), (ins i32imm:$amt), NoItinerary,
263 [(ARMcallseq_start imm:$amt)]>,
264 Requires<[IsThumb, IsThumb1Only]>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000265}
Evan Cheng0f7cbe82007-05-15 01:29:07 +0000266
Jim Grosbach23b729e2011-08-17 23:08:57 +0000267class T1SystemEncoding<bits<8> opc>
Bill Wendling5da8cae2010-11-29 22:15:03 +0000268 : T1Encoding<0b101111> {
Jim Grosbach23b729e2011-08-17 23:08:57 +0000269 let Inst{9-8} = 0b11;
270 let Inst{7-0} = opc;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000271}
272
Saleem Abdulrasool7e7c2f92014-04-25 17:24:24 +0000273def tHINT : T1pI<(outs), (ins imm0_15:$imm), NoItinerary, "hint", "\t$imm",
274 [(int_arm_hint imm0_15:$imm)]>,
Richard Barton87dacc32013-10-18 14:09:49 +0000275 T1SystemEncoding<0x00>,
276 Requires<[IsThumb, HasV6M]> {
277 bits<4> imm;
278 let Inst{7-4} = imm;
279}
Johnny Chen90adefc2010-02-25 03:28:51 +0000280
Richard Barton87dacc32013-10-18 14:09:49 +0000281class tHintAlias<string Asm, dag Result> : tInstAlias<Asm, Result> {
282 let Predicates = [IsThumb, HasV6M];
283}
Johnny Chen74cca5a2010-02-25 17:51:03 +0000284
Richard Barton87dacc32013-10-18 14:09:49 +0000285def : tHintAlias<"nop$p", (tHINT 0, pred:$p)>; // A8.6.110
286def : tHintAlias<"yield$p", (tHINT 1, pred:$p)>; // A8.6.410
287def : tHintAlias<"wfe$p", (tHINT 2, pred:$p)>; // A8.6.408
288def : tHintAlias<"wfi$p", (tHINT 3, pred:$p)>; // A8.6.409
289def : tHintAlias<"sev$p", (tHINT 4, pred:$p)>; // A8.6.157
290def : tInstAlias<"sevl$p", (tHINT 5, pred:$p)> {
291 let Predicates = [IsThumb2, HasV8];
292}
Joey Goulyad98f162013-10-01 12:39:11 +0000293
Jim Grosbach23b729e2011-08-17 23:08:57 +0000294// The imm operand $val can be used by a debugger to store more information
Bill Wendling5da8cae2010-11-29 22:15:03 +0000295// about the breakpoint.
Jim Grosbach23b729e2011-08-17 23:08:57 +0000296def tBKPT : T1I<(outs), (ins imm0_255:$val), NoItinerary, "bkpt\t$val",
297 []>,
298 T1Encoding<0b101111> {
299 let Inst{9-8} = 0b10;
Bill Wendling5da8cae2010-11-29 22:15:03 +0000300 // A8.6.22
301 bits<8> val;
302 let Inst{7-0} = val;
303}
Saleem Abdulrasool70187552013-12-23 17:23:58 +0000304// default immediate for breakpoint mnemonic
305def : InstAlias<"bkpt", (tBKPT 0)>, Requires<[IsThumb]>;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000306
Richard Barton8d519fe2013-09-05 14:14:19 +0000307def tHLT : T1I<(outs), (ins imm0_63:$val), NoItinerary, "hlt\t$val",
308 []>, T1Encoding<0b101110>, Requires<[IsThumb, HasV8]> {
309 let Inst{9-6} = 0b1010;
310 bits<6> val;
311 let Inst{5-0} = val;
312}
313
Jim Grosbach39f93882011-07-22 17:52:23 +0000314def tSETEND : T1I<(outs), (ins setend_op:$end), NoItinerary, "setend\t$end",
Keith Walker10457172014-08-05 15:11:59 +0000315 []>, T1Encoding<0b101101>, Requires<[IsNotMClass]>, Deprecated<HasV8Ops> {
Jim Grosbach39f93882011-07-22 17:52:23 +0000316 bits<1> end;
Bill Wendling3acd0272010-11-21 10:55:23 +0000317 // A8.6.156
Johnny Chen74cca5a2010-02-25 17:51:03 +0000318 let Inst{9-5} = 0b10010;
Bill Wendling49a2e232010-11-19 22:02:18 +0000319 let Inst{4} = 1;
Jim Grosbach39f93882011-07-22 17:52:23 +0000320 let Inst{3} = end;
Bill Wendling49a2e232010-11-19 22:02:18 +0000321 let Inst{2-0} = 0b000;
Johnny Chen74cca5a2010-02-25 17:51:03 +0000322}
323
Johnny Chen44908a52010-03-02 18:14:57 +0000324// Change Processor State is a system instruction -- for disassembly only.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000325def tCPS : T1I<(outs), (ins imod_op:$imod, iflags_op:$iflags),
Jim Grosbach4da03f02011-09-20 00:00:06 +0000326 NoItinerary, "cps$imod $iflags", []>,
Bill Wendling775899e2010-11-29 00:18:15 +0000327 T1Misc<0b0110011> {
328 // A8.6.38 & B6.1.1
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000329 bit imod;
330 bits<3> iflags;
331
332 let Inst{4} = imod;
333 let Inst{3} = 0;
334 let Inst{2-0} = iflags;
Owen Andersone0152a72011-08-09 20:55:18 +0000335 let DecoderMethod = "DecodeThumbCPS";
Bill Wendling775899e2010-11-29 00:18:15 +0000336}
Johnny Chen44908a52010-03-02 18:14:57 +0000337
Evan Cheng7cc6aca2009-08-04 23:47:55 +0000338// For both thumb1 and thumb2.
Chris Lattner9492c172010-10-31 19:15:18 +0000339let isNotDuplicable = 1, isCodeGenOnly = 1 in
Jim Grosbachc8e2e9d2010-09-30 19:53:58 +0000340def tPICADD : TIt<(outs GPR:$dst), (ins GPR:$lhs, pclabel:$cp), IIC_iALUr, "",
Bill Wendlinga82fb712010-11-19 22:37:33 +0000341 [(set GPR:$dst, (ARMpic_add GPR:$lhs, imm:$cp))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000342 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlingddce9f32010-11-30 00:50:22 +0000343 // A8.6.6
Bill Wendlinga82fb712010-11-19 22:37:33 +0000344 bits<3> dst;
Bill Wendlingddce9f32010-11-30 00:50:22 +0000345 let Inst{6-3} = 0b1111; // Rm = pc
Bill Wendlinga82fb712010-11-19 22:37:33 +0000346 let Inst{2-0} = dst;
Johnny Chenc28e6292009-12-15 17:24:14 +0000347}
Evan Cheng10043e22007-01-19 07:51:42 +0000348
Bill Wendlinga82fb712010-11-19 22:37:33 +0000349// ADD <Rd>, sp, #<imm8>
Jakob Stoklund Olesendd2b39d2011-10-15 00:57:13 +0000350// FIXME: This should not be marked as having side effects, and it should be
351// rematerializable. Clearing the side effect bit causes miscompilations,
352// probably because the instruction can be moved around.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000353def tADDrSPi : T1pI<(outs tGPR:$dst), (ins GPRsp:$sp, t_imm0_1020s4:$imm),
354 IIC_iALUi, "add", "\t$dst, $sp, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000355 T1Encoding<{1,0,1,0,1,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000356 // A6.2 & A8.6.8
357 bits<3> dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000358 bits<8> imm;
Bill Wendlinga82fb712010-11-19 22:37:33 +0000359 let Inst{10-8} = dst;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000360 let Inst{7-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000361 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000362}
363
Tim Northover23075cc2014-10-20 21:28:41 +0000364// Thumb1 frame lowering is rather fragile, we hope to be able to use
365// tADDrSPi, but we may need to insert a sequence that clobbers CPSR.
366def tADDframe : PseudoInst<(outs tGPR:$dst), (ins i32imm:$base, i32imm:$offset),
367 NoItinerary, []>,
368 Requires<[IsThumb, IsThumb1Only]> {
369 let Defs = [CPSR];
370}
371
Bill Wendlinga82fb712010-11-19 22:37:33 +0000372// ADD sp, sp, #<imm7>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000373def tADDspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
374 IIC_iALUi, "add", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000375 T1Misc<{0,0,0,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000376 // A6.2.5 & A8.6.8
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000377 bits<7> imm;
378 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000379 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000380}
Evan Chengb566ab72009-06-25 01:05:06 +0000381
Bill Wendlinga82fb712010-11-19 22:37:33 +0000382// SUB sp, sp, #<imm7>
383// FIXME: The encoding and the ASM string don't match up.
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000384def tSUBspi : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, t_imm0_508s4:$imm),
385 IIC_iALUi, "sub", "\t$Rdn, $imm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000386 T1Misc<{0,0,0,0,1,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000387 // A6.2.5 & A8.6.214
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000388 bits<7> imm;
389 let Inst{6-0} = imm;
Owen Andersone0152a72011-08-09 20:55:18 +0000390 let DecoderMethod = "DecodeThumbAddSPImm";
Bill Wendlinga82fb712010-11-19 22:37:33 +0000391}
Evan Chengb972e562009-08-07 00:34:42 +0000392
Jim Grosbach930f2f62012-04-05 20:57:13 +0000393def : tInstAlias<"add${p} sp, $imm",
394 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
395def : tInstAlias<"add${p} sp, sp, $imm",
396 (tSUBspi SP, t_imm0_508s4_neg:$imm, pred:$p)>;
397
Jim Grosbach4b701af2011-08-24 21:42:27 +0000398// Can optionally specify SP as a three operand instruction.
399def : tInstAlias<"add${p} sp, sp, $imm",
400 (tADDspi SP, t_imm0_508s4:$imm, pred:$p)>;
401def : tInstAlias<"sub${p} sp, sp, $imm",
402 (tSUBspi SP, t_imm0_508s4:$imm, pred:$p)>;
403
Bill Wendlinga82fb712010-11-19 22:37:33 +0000404// ADD <Rm>, sp
Jim Grosbachc6f32b32012-04-27 23:51:36 +0000405def tADDrSP : T1pI<(outs GPR:$Rdn), (ins GPRsp:$sp, GPR:$Rn), IIC_iALUr,
406 "add", "\t$Rdn, $sp, $Rn", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000407 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendlinga82fb712010-11-19 22:37:33 +0000408 // A8.6.9 Encoding T1
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000409 bits<4> Rdn;
410 let Inst{7} = Rdn{3};
Bill Wendlinga82fb712010-11-19 22:37:33 +0000411 let Inst{6-3} = 0b1101;
Jim Grosbach1b8457a2011-08-24 17:46:13 +0000412 let Inst{2-0} = Rdn{2-0};
Owen Andersone0152a72011-08-09 20:55:18 +0000413 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000414}
Evan Chengb972e562009-08-07 00:34:42 +0000415
Bill Wendlinga82fb712010-11-19 22:37:33 +0000416// ADD sp, <Rm>
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000417def tADDspr : T1pIt<(outs GPRsp:$Rdn), (ins GPRsp:$Rn, GPR:$Rm), IIC_iALUr,
418 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000419 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Johnny Chenc28e6292009-12-15 17:24:14 +0000420 // A8.6.9 Encoding T2
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000421 bits<4> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000422 let Inst{7} = 1;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000423 let Inst{6-3} = Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +0000424 let Inst{2-0} = 0b101;
Owen Andersone0152a72011-08-09 20:55:18 +0000425 let DecoderMethod = "DecodeThumbAddSPReg";
Johnny Chenc28e6292009-12-15 17:24:14 +0000426}
Evan Chengb972e562009-08-07 00:34:42 +0000427
Evan Cheng10043e22007-01-19 07:51:42 +0000428//===----------------------------------------------------------------------===//
429// Control Flow Instructions.
430//
431
Bob Wilson73789b82009-10-28 18:26:41 +0000432// Indirect branches
433let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000434 def tBX : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bx${p}\t$Rm", []>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000435 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000436 // A6.2.3 & A8.6.25
437 bits<4> Rm;
438 let Inst{6-3} = Rm;
439 let Inst{2-0} = 0b000;
James Molloyd9ba4fd2012-02-09 10:56:31 +0000440 let Unpredictable{2-0} = 0b111;
Cameron Zwarich26ddb122011-05-26 03:41:12 +0000441 }
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000442 def tBXNS : TI<(outs), (ins GPR:$Rm, pred:$p), IIC_Br, "bxns${p}\t$Rm", []>,
443 Requires<[IsThumb, Has8MSecExt]>,
444 T1Special<{1,1,0,?}>, Sched<[WriteBr]> {
445 bits<4> Rm;
446 let Inst{6-3} = Rm;
447 let Inst{2-0} = 0b100;
448 let Unpredictable{1-0} = 0b11;
449 }
Bob Wilson73789b82009-10-28 18:26:41 +0000450}
451
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000452let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
Owen Anderson651b2302011-07-13 23:22:26 +0000453 def tBX_RET : tPseudoExpand<(outs), (ins pred:$p), 2, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000454 [(ARMretflag)], (tBX LR, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000455
456 // Alternative return instruction used by vararg functions.
Jim Grosbach74719372011-07-08 21:50:04 +0000457 def tBX_RET_vararg : tPseudoExpand<(outs), (ins tGPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000458 2, IIC_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000459 (tBX GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbachcb1b0b72011-07-08 21:04:05 +0000460}
461
Bill Wendling9c258942010-12-01 02:36:55 +0000462// All calls clobber the non-callee saved registers. SP is marked as a use to
463// prevent stack-pointer assignments that appear immediately before calls from
464// potentially appearing dead.
Jim Grosbach669f1d02009-03-27 23:06:27 +0000465let isCall = 1,
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000466 Defs = [LR], Uses = [SP] in {
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000467 // Also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000468 def tBL : TIx2<0b11110, 0b11, 1,
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000469 (outs), (ins pred:$p, t_bltarget:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000470 "bl${p}\t$func",
Johnny Chenc28e6292009-12-15 17:24:14 +0000471 [(ARMtcall tglobaladdr:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000472 Requires<[IsThumb]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000473 bits<24> func;
474 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000475 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000476 let Inst{13} = func{22};
477 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000478 let Inst{10-0} = func{10-0};
Bill Wendling4d8ff862010-12-03 01:55:47 +0000479 }
Evan Cheng175bd142009-07-29 21:26:42 +0000480
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000481 // ARMv5T and above, also used for Thumb2
Johnny Chenc28e6292009-12-15 17:24:14 +0000482 def tBLXi : TIx2<0b11110, 0b11, 0,
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000483 (outs), (ins pred:$p, t_blxtarget:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000484 "blx${p}\t$func",
Johnny Chenc28e6292009-12-15 17:24:14 +0000485 [(ARMcall tglobaladdr:$func)]>,
Keith Walker10457172014-08-05 15:11:59 +0000486 Requires<[IsThumb, HasV5T, IsNotMClass]>, Sched<[WriteBrL]> {
Kevin Enderby91422302012-05-03 22:41:56 +0000487 bits<24> func;
488 let Inst{26} = func{23};
Jim Grosbach9e199462010-12-06 23:57:07 +0000489 let Inst{25-16} = func{20-11};
Kevin Enderby91422302012-05-03 22:41:56 +0000490 let Inst{13} = func{22};
491 let Inst{11} = func{21};
Jim Grosbach9e199462010-12-06 23:57:07 +0000492 let Inst{10-1} = func{10-1};
493 let Inst{0} = 0; // func{0} is assumed zero
Jim Grosbache4fee202010-12-03 22:33:42 +0000494 }
Evan Cheng175bd142009-07-29 21:26:42 +0000495
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000496 // Also used for Thumb2
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000497 def tBLXr : TI<(outs), (ins pred:$p, GPR:$func), IIC_Br,
Owen Anderson64d53622011-07-18 18:50:52 +0000498 "blx${p}\t$func",
Evan Cheng6ab54fd2009-08-01 00:16:10 +0000499 [(ARMtcall GPR:$func)]>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +0000500 Requires<[IsThumb, HasV5T]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000501 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> { // A6.2.3 & A8.6.24;
Owen Andersonb7456232011-05-11 17:00:48 +0000502 bits<4> func;
503 let Inst{6-3} = func;
504 let Inst{2-0} = 0b000;
505 }
Evan Cheng175bd142009-07-29 21:26:42 +0000506
Bradley Smithfed3e4a2016-01-25 11:24:47 +0000507 // ARMv8-M Security Extensions
508 def tBLXNSr : TI<(outs), (ins pred:$p, GPRnopc:$func), IIC_Br,
509 "blxns${p}\t$func", []>,
510 Requires<[IsThumb, Has8MSecExt]>,
511 T1Special<{1,1,1,?}>, Sched<[WriteBrL]> {
512 bits<4> func;
513 let Inst{6-3} = func;
514 let Inst{2-0} = 0b100;
515 let Unpredictable{1-0} = 0b11;
516 }
517
Lauro Ramos Venancio143b0df2007-03-27 16:19:21 +0000518 // ARMv4T
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000519 def tBX_CALL : tPseudoInst<(outs), (ins tGPR:$func),
Owen Anderson651b2302011-07-13 23:22:26 +0000520 4, IIC_Br,
Evan Cheng175bd142009-07-29 21:26:42 +0000521 [(ARMcall_nolink tGPR:$func)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000522 Requires<[IsThumb, IsThumb1Only]>, Sched<[WriteBr]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000523}
524
Bill Wendling9c258942010-12-01 02:36:55 +0000525let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
526 let isPredicable = 1 in
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000527 def tB : T1pI<(outs), (ins t_brtarget:$target), IIC_Br,
528 "b", "\t$target", [(br bb:$target)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000529 T1Encoding<{1,1,1,0,0,?}>, Sched<[WriteBr]> {
Jim Grosbache119da12010-12-10 18:21:33 +0000530 bits<11> target;
531 let Inst{10-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000532 let AsmMatchConverter = "cvtThumbBranches";
533 }
Evan Cheng10043e22007-01-19 07:51:42 +0000534
Evan Cheng863736b2007-01-30 01:13:37 +0000535 // Far jump
Jim Grosbachb5743b92010-12-16 19:11:16 +0000536 // Just a pseudo for a tBL instruction. Needed to let regalloc know about
537 // the clobber of LR.
Evan Cheng317bd7a2009-08-07 05:45:07 +0000538 let Defs = [LR] in
Owen Anderson64d53622011-07-18 18:50:52 +0000539 def tBfar : tPseudoExpand<(outs), (ins t_bltarget:$target, pred:$p),
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000540 4, IIC_Br, [], (tBL pred:$p, t_bltarget:$target)>,
541 Sched<[WriteBrTbl]>;
Evan Cheng863736b2007-01-30 01:13:37 +0000542
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000543 def tBR_JTr : tPseudoInst<(outs),
Tim Northover4998a472015-05-13 20:28:38 +0000544 (ins tGPR:$target, i32imm:$jt),
Owen Anderson651b2302011-07-13 23:22:26 +0000545 0, IIC_Br,
Tim Northover4998a472015-05-13 20:28:38 +0000546 [(ARMbrjt tGPR:$target, tjumptable:$jt)]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000547 Sched<[WriteBrTbl]> {
Tim Northovera603c402015-05-31 19:22:07 +0000548 let Size = 2;
Jim Grosbach58bc36a2010-11-29 19:32:47 +0000549 list<Predicate> Predicates = [IsThumb, IsThumb1Only];
Johnny Chen466231a2009-12-16 02:32:54 +0000550 }
Evan Cheng0701c5a2007-01-27 02:29:45 +0000551}
552
Evan Chengaa3b8012007-07-05 07:13:32 +0000553// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach669f1d02009-03-27 23:06:27 +0000554// a two-value operand where a dag node expects two operands. :(
Evan Chengac1591b2007-07-21 00:34:19 +0000555let isBranch = 1, isTerminator = 1 in
Jim Grosbach78485ad2010-12-10 17:13:40 +0000556 def tBcc : T1I<(outs), (ins t_bcctarget:$target, pred:$p), IIC_Br,
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000557 "b${p}\t$target",
Johnny Chenc28e6292009-12-15 17:24:14 +0000558 [/*(ARMbrcond bb:$target, imm:$cc)*/]>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000559 T1BranchCond<{1,1,0,1}>, Sched<[WriteBr]> {
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000560 bits<4> p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000561 bits<8> target;
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000562 let Inst{11-8} = p;
Jim Grosbach78485ad2010-12-10 17:13:40 +0000563 let Inst{7-0} = target;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000564 let AsmMatchConverter = "cvtThumbBranches";
Jim Grosbachce18d7e2010-12-04 00:20:40 +0000565}
Evan Cheng10043e22007-01-19 07:51:42 +0000566
Mihai Popad36cbaa2013-07-03 09:21:44 +0000567
Jim Grosbach166cd882011-07-08 20:13:35 +0000568// Tail calls
569let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
Evan Cheng68132d82011-12-20 18:26:50 +0000570 // IOS versions.
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000571 let Uses = [SP] in {
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000572 def tTAILJMPr : tPseudoExpand<(outs), (ins tcGPR:$dst),
Owen Anderson651b2302011-07-13 23:22:26 +0000573 4, IIC_Br, [],
Jim Grosbach204c1282011-07-08 20:39:19 +0000574 (tBX GPR:$dst, (ops 14, zero_reg))>,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000575 Requires<[IsThumb]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000576 }
Tim Northoverd6a729b2014-01-06 14:28:05 +0000577 // tTAILJMPd: MachO version uses a Thumb2 branch (no Thumb1 tail calls
578 // on MachO), so it's in ARMInstrThumb2.td.
579 // Non-MachO version:
Jakob Stoklund Olesenfa7a5372012-02-24 01:19:29 +0000580 let Uses = [SP] in {
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000581 def tTAILJMPdND : tPseudoExpand<(outs),
Jakob Stoklund Olesen6a81d302012-07-13 20:27:00 +0000582 (ins t_brtarget:$dst, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +0000583 4, IIC_Br, [],
Owen Anderson29cfe6c2011-09-09 21:48:23 +0000584 (tB t_brtarget:$dst, pred:$p)>,
Tim Northoverd6a729b2014-01-06 14:28:05 +0000585 Requires<[IsThumb, IsNotMachO]>, Sched<[WriteBr]>;
Jim Grosbach166cd882011-07-08 20:13:35 +0000586 }
587}
588
589
Jim Grosbach5cc338d2011-08-23 19:49:10 +0000590// A8.6.218 Supervisor Call (Software Interrupt)
Johnny Chen57656da2010-02-25 02:21:11 +0000591// A8.6.16 B: Encoding T1
592// If Inst{11-8} == 0b1111 then SEE SVC
Evan Cheng9a133f62010-11-29 22:43:27 +0000593let isCall = 1, Uses = [SP] in
Jim Grosbachf1637842011-07-26 16:24:27 +0000594def tSVC : T1pI<(outs), (ins imm0_255:$imm), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000595 "svc", "\t$imm", []>, Encoding16, Sched<[WriteBr]> {
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000596 bits<8> imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000597 let Inst{15-12} = 0b1101;
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000598 let Inst{11-8} = 0b1111;
599 let Inst{7-0} = imm;
Johnny Chen57656da2010-02-25 02:21:11 +0000600}
601
Bill Wendling811c9362010-11-30 07:44:32 +0000602// The assembler uses 0xDEFE for a trap instruction.
Evan Cheng2fa5a7e2010-05-11 07:26:32 +0000603let isBarrier = 1, isTerminator = 1 in
Owen Andersonb7456232011-05-11 17:00:48 +0000604def tTRAP : TI<(outs), (ins), IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +0000605 "trap", [(trap)]>, Encoding16, Sched<[WriteBr]> {
Bill Wendling3acd0272010-11-21 10:55:23 +0000606 let Inst = 0xdefe;
Johnny Chen57656da2010-02-25 02:21:11 +0000607}
608
Evan Cheng10043e22007-01-19 07:51:42 +0000609//===----------------------------------------------------------------------===//
610// Load Store Instructions.
611//
612
John Brawn68acdcb2015-08-13 10:48:22 +0000613// PC-relative loads need to be matched first as constant pool accesses need to
614// always be PC-relative. We do this using AddedComplexity, as the pattern is
615// simpler than the patterns of the other load instructions.
616let canFoldAsLoad = 1, isReMaterializable = 1, AddedComplexity = 10 in
617def tLDRpci : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_pc:$addr), IIC_iLoad_i,
618 "ldr", "\t$Rt, $addr",
619 [(set tGPR:$Rt, (load (ARMWrapper tconstpool:$addr)))]>,
620 T1Encoding<{0,1,0,0,1,?}> {
621 // A6.2 & A8.6.59
622 bits<3> Rt;
623 bits<8> addr;
624 let Inst{10-8} = Rt;
625 let Inst{7-0} = addr;
626}
627
628// SP-relative loads should be matched before standard immediate-offset loads as
629// it means we avoid having to move SP to another register.
630let canFoldAsLoad = 1 in
631def tLDRspi : T1pIs<(outs tGPR:$Rt), (ins t_addrmode_sp:$addr), IIC_iLoad_i,
632 "ldr", "\t$Rt, $addr",
633 [(set tGPR:$Rt, (load t_addrmode_sp:$addr))]>,
634 T1LdStSP<{1,?,?}> {
635 bits<3> Rt;
636 bits<8> addr;
637 let Inst{10-8} = Rt;
638 let Inst{7-0} = addr;
639}
640
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000641// Loads: reg/reg and reg/imm5
Dan Gohman8c5d6832010-02-27 23:47:46 +0000642let canFoldAsLoad = 1, isReMaterializable = 1 in
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000643multiclass thumb_ld_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
644 Operand AddrMode_r, Operand AddrMode_i,
645 AddrMode am, InstrItinClass itin_r,
646 InstrItinClass itin_i, string asm,
647 PatFrag opnode> {
John Brawn68acdcb2015-08-13 10:48:22 +0000648 // Immediate-offset loads should be matched before register-offset loads as
649 // when the offset is a constant it's simpler to first check if it fits in the
650 // immediate offset field then fall back to register-offset if it doesn't.
Bill Wendling5ab38b52010-12-14 23:42:48 +0000651 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000652 T1pILdStEncodeImm<imm_opc, 1 /* Load */,
653 (outs tGPR:$Rt), (ins AddrMode_i:$addr),
654 am, itin_i, asm, "\t$Rt, $addr",
655 [(set tGPR:$Rt, (opnode AddrMode_i:$addr))]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000656 // Register-offset loads are matched last.
657 def r : // reg/reg
658 T1pILdStEncode<reg_opc,
659 (outs tGPR:$Rt), (ins AddrMode_r:$addr),
660 am, itin_r, asm, "\t$Rt, $addr",
661 [(set tGPR:$Rt, (opnode AddrMode_r:$addr))]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000662}
663// Stores: reg/reg and reg/imm5
664multiclass thumb_st_rr_ri_enc<bits<3> reg_opc, bits<4> imm_opc,
665 Operand AddrMode_r, Operand AddrMode_i,
666 AddrMode am, InstrItinClass itin_r,
667 InstrItinClass itin_i, string asm,
668 PatFrag opnode> {
Bill Wendling5ab38b52010-12-14 23:42:48 +0000669 def i : // reg/imm5
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000670 T1pILdStEncodeImm<imm_opc, 0 /* Store */,
671 (outs), (ins tGPR:$Rt, AddrMode_i:$addr),
672 am, itin_i, asm, "\t$Rt, $addr",
673 [(opnode tGPR:$Rt, AddrMode_i:$addr)]>;
John Brawn68acdcb2015-08-13 10:48:22 +0000674 def r : // reg/reg
675 T1pILdStEncode<reg_opc,
676 (outs), (ins tGPR:$Rt, AddrMode_r:$addr),
677 am, itin_r, asm, "\t$Rt, $addr",
678 [(opnode tGPR:$Rt, AddrMode_r:$addr)]>;
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000679}
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000680
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000681// A8.6.57 & A8.6.60
John Brawn68acdcb2015-08-13 10:48:22 +0000682defm tLDR : thumb_ld_rr_ri_enc<0b100, 0b0110, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000683 t_addrmode_is4, AddrModeT1_4,
684 IIC_iLoad_r, IIC_iLoad_i, "ldr",
685 UnOpFrag<(load node:$Src)>>;
Evan Cheng10043e22007-01-19 07:51:42 +0000686
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000687// A8.6.64 & A8.6.61
John Brawn68acdcb2015-08-13 10:48:22 +0000688defm tLDRB : thumb_ld_rr_ri_enc<0b110, 0b0111, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000689 t_addrmode_is1, AddrModeT1_1,
690 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrb",
691 UnOpFrag<(zextloadi8 node:$Src)>>;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000692
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000693// A8.6.76 & A8.6.73
John Brawn68acdcb2015-08-13 10:48:22 +0000694defm tLDRH : thumb_ld_rr_ri_enc<0b101, 0b1000, t_addrmode_rr,
Bill Wendlingce4f87b2010-12-14 22:10:49 +0000695 t_addrmode_is2, AddrModeT1_2,
696 IIC_iLoad_bh_r, IIC_iLoad_bh_i, "ldrh",
697 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Chengc0b73662007-01-23 22:59:13 +0000698
Evan Cheng0794c6a2009-07-11 07:08:13 +0000699let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000700def tLDRSB : // A8.6.80
Owen Anderson3157f2e2011-08-15 19:00:06 +0000701 T1pILdStEncode<0b011, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000702 AddrModeT1_1, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000703 "ldrsb", "\t$Rt, $addr",
704 [(set tGPR:$Rt, (sextloadi8 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000705
Evan Cheng0794c6a2009-07-11 07:08:13 +0000706let AddedComplexity = 10 in
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000707def tLDRSH : // A8.6.84
Owen Anderson3157f2e2011-08-15 19:00:06 +0000708 T1pILdStEncode<0b111, (outs tGPR:$Rt), (ins t_addrmode_rr:$addr),
Bill Wendlingc25545a2010-12-01 01:38:08 +0000709 AddrModeT1_2, IIC_iLoad_bh_r,
Owen Anderson3157f2e2011-08-15 19:00:06 +0000710 "ldrsh", "\t$Rt, $addr",
711 [(set tGPR:$Rt, (sextloadi16 t_addrmode_rr:$addr))]>;
Evan Chengc0b73662007-01-23 22:59:13 +0000712
Evan Cheng10043e22007-01-19 07:51:42 +0000713
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000714def tSTRspi : T1pIs<(outs), (ins tGPR:$Rt, t_addrmode_sp:$addr), IIC_iStore_i,
Bill Wendling092a7bd2010-12-14 03:36:38 +0000715 "str", "\t$Rt, $addr",
716 [(store tGPR:$Rt, t_addrmode_sp:$addr)]>,
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000717 T1LdStSP<{0,?,?}> {
718 bits<3> Rt;
719 bits<8> addr;
720 let Inst{10-8} = Rt;
721 let Inst{7-0} = addr;
722}
Evan Chengec13f8262007-02-07 00:06:56 +0000723
John Brawn68acdcb2015-08-13 10:48:22 +0000724// A8.6.194 & A8.6.192
725defm tSTR : thumb_st_rr_ri_enc<0b000, 0b0110, t_addrmode_rr,
726 t_addrmode_is4, AddrModeT1_4,
727 IIC_iStore_r, IIC_iStore_i, "str",
728 BinOpFrag<(store node:$LHS, node:$RHS)>>;
729
730// A8.6.197 & A8.6.195
731defm tSTRB : thumb_st_rr_ri_enc<0b010, 0b0111, t_addrmode_rr,
732 t_addrmode_is1, AddrModeT1_1,
733 IIC_iStore_bh_r, IIC_iStore_bh_i, "strb",
734 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
735
736// A8.6.207 & A8.6.205
737defm tSTRH : thumb_st_rr_ri_enc<0b001, 0b1000, t_addrmode_rr,
738 t_addrmode_is2, AddrModeT1_2,
739 IIC_iStore_bh_r, IIC_iStore_bh_i, "strh",
740 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
741
742
Evan Cheng10043e22007-01-19 07:51:42 +0000743//===----------------------------------------------------------------------===//
744// Load / store multiple Instructions.
745//
746
Bill Wendlinga68e3a52010-11-16 01:16:36 +0000747// These require base address to be written back or one of the loaded regs.
Craig Topperc50d64b2014-11-26 00:46:26 +0000748let hasSideEffects = 0 in {
Bill Wendling705ec772010-11-13 10:57:02 +0000749
750let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000751def tLDMIA : T1I<(outs), (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
752 IIC_iLoad_m, "ldm${p}\t$Rn, $regs", []>, T1Encoding<{1,1,0,0,1,?}> {
753 bits<3> Rn;
754 bits<8> regs;
755 let Inst{10-8} = Rn;
756 let Inst{7-0} = regs;
757}
Bill Wendling705ec772010-11-13 10:57:02 +0000758
Jim Grosbache364ad52011-08-23 17:41:15 +0000759// Writeback version is just a pseudo, as there's no encoding difference.
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +0000760// Writeback happens iff the base register is not in the destination register
Jim Grosbache364ad52011-08-23 17:41:15 +0000761// list.
Scott Douglass953f9082015-10-05 14:49:54 +0000762let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Jim Grosbache364ad52011-08-23 17:41:15 +0000763def tLDMIA_UPD :
764 InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
765 "$Rn = $wb", IIC_iLoad_mu>,
766 PseudoInstExpansion<(tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)> {
767 let Size = 2;
768 let OutOperandList = (outs GPR:$wb);
769 let InOperandList = (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops);
770 let Pattern = [];
771 let isCodeGenOnly = 1;
772 let isPseudo = 1;
773 list<Predicate> Predicates = [IsThumb];
774}
775
776// There is no non-writeback version of STM for Thumb.
Bill Wendling705ec772010-11-13 10:57:02 +0000777let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
Jim Grosbach6ccd79f2011-08-24 18:19:42 +0000778def tSTMIA_UPD : Thumb1I<(outs GPR:$wb),
779 (ins tGPR:$Rn, pred:$p, reglist:$regs, variable_ops),
780 AddrModeNone, 2, IIC_iStore_mu,
781 "stm${p}\t$Rn!, $regs", "$Rn = $wb", []>,
Jim Grosbache364ad52011-08-23 17:41:15 +0000782 T1Encoding<{1,1,0,0,0,?}> {
783 bits<3> Rn;
784 bits<8> regs;
785 let Inst{10-8} = Rn;
786 let Inst{7-0} = regs;
787}
Owen Andersonb7456232011-05-11 17:00:48 +0000788
Craig Topperc50d64b2014-11-26 00:46:26 +0000789} // hasSideEffects
Evan Chengcc9ca352009-08-11 21:11:32 +0000790
Jim Grosbach90103cc2011-08-18 21:50:53 +0000791def : InstAlias<"ldm${p} $Rn!, $regs",
792 (tLDMIA tGPR:$Rn, pred:$p, reglist:$regs)>,
793 Requires<[IsThumb, IsThumb1Only]>;
794
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000795let mayLoad = 1, Uses = [SP], Defs = [SP], hasExtraDefRegAllocReq = 1 in
Bill Wendling945b7762010-11-19 01:33:10 +0000796def tPOP : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000797 IIC_iPop,
Bill Wendling945b7762010-11-19 01:33:10 +0000798 "pop${p}\t$regs", []>,
799 T1Misc<{1,1,0,?,?,?,?}> {
800 bits<16> regs;
Bill Wendling945b7762010-11-19 01:33:10 +0000801 let Inst{8} = regs{15};
802 let Inst{7-0} = regs{7-0};
803}
Evan Chengcc9ca352009-08-11 21:11:32 +0000804
Evan Cheng1b2b64f2009-10-01 08:22:27 +0000805let mayStore = 1, Uses = [SP], Defs = [SP], hasExtraSrcRegAllocReq = 1 in
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000806def tPUSH : T1I<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Evan Cheng49d4c0b2010-10-06 06:27:31 +0000807 IIC_iStore_m,
Bill Wendlinge60fd5a2010-11-20 00:53:35 +0000808 "push${p}\t$regs", []>,
809 T1Misc<{0,1,0,?,?,?,?}> {
810 bits<16> regs;
811 let Inst{8} = regs{14};
812 let Inst{7-0} = regs{7-0};
813}
Evan Cheng10043e22007-01-19 07:51:42 +0000814
815//===----------------------------------------------------------------------===//
816// Arithmetic Instructions.
817//
818
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000819// Helper classes for encoding T1pI patterns:
820class T1pIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
821 string opc, string asm, list<dag> pattern>
822 : T1pI<oops, iops, itin, opc, asm, pattern>,
823 T1DataProcessing<opA> {
824 bits<3> Rm;
825 bits<3> Rn;
826 let Inst{5-3} = Rm;
827 let Inst{2-0} = Rn;
828}
829class T1pIMiscEncode<bits<7> opA, dag oops, dag iops, InstrItinClass itin,
830 string opc, string asm, list<dag> pattern>
831 : T1pI<oops, iops, itin, opc, asm, pattern>,
832 T1Misc<opA> {
833 bits<3> Rm;
834 bits<3> Rd;
835 let Inst{5-3} = Rm;
836 let Inst{2-0} = Rd;
837}
838
Bill Wendling490240a2010-12-01 01:20:15 +0000839// Helper classes for encoding T1sI patterns:
840class T1sIDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
841 string opc, string asm, list<dag> pattern>
842 : T1sI<oops, iops, itin, opc, asm, pattern>,
843 T1DataProcessing<opA> {
844 bits<3> Rd;
845 bits<3> Rn;
846 let Inst{5-3} = Rn;
847 let Inst{2-0} = Rd;
848}
849class T1sIGenEncode<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
850 string opc, string asm, list<dag> pattern>
851 : T1sI<oops, iops, itin, opc, asm, pattern>,
852 T1General<opA> {
853 bits<3> Rm;
854 bits<3> Rn;
855 bits<3> Rd;
856 let Inst{8-6} = Rm;
857 let Inst{5-3} = Rn;
858 let Inst{2-0} = Rd;
859}
860class T1sIGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
861 string opc, string asm, list<dag> pattern>
862 : T1sI<oops, iops, itin, opc, asm, pattern>,
863 T1General<opA> {
864 bits<3> Rd;
865 bits<3> Rm;
866 let Inst{5-3} = Rm;
867 let Inst{2-0} = Rd;
868}
869
870// Helper classes for encoding T1sIt patterns:
Bill Wendling4915f562010-12-01 00:48:44 +0000871class T1sItDPEncode<bits<4> opA, dag oops, dag iops, InstrItinClass itin,
872 string opc, string asm, list<dag> pattern>
873 : T1sIt<oops, iops, itin, opc, asm, pattern>,
874 T1DataProcessing<opA> {
Bill Wendling05632cb2010-11-30 23:54:45 +0000875 bits<3> Rdn;
876 bits<3> Rm;
Bill Wendling4915f562010-12-01 00:48:44 +0000877 let Inst{5-3} = Rm;
878 let Inst{2-0} = Rdn;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000879}
Bill Wendling4915f562010-12-01 00:48:44 +0000880class T1sItGenEncodeImm<bits<5> opA, dag oops, dag iops, InstrItinClass itin,
881 string opc, string asm, list<dag> pattern>
882 : T1sIt<oops, iops, itin, opc, asm, pattern>,
883 T1General<opA> {
884 bits<3> Rdn;
885 bits<8> imm8;
886 let Inst{10-8} = Rdn;
887 let Inst{7-0} = imm8;
888}
889
890// Add with carry register
891let isCommutable = 1, Uses = [CPSR] in
892def tADC : // A8.6.2
893 T1sItDPEncode<0b0101, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm), IIC_iALUr,
894 "adc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000895 [(set tGPR:$Rdn, (adde tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Chengf40b9002007-01-27 00:07:15 +0000896
David Goodwine85169c2009-06-25 22:49:55 +0000897// Add immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000898def tADDi3 : // A8.6.4 T1
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000899 T1sIGenEncodeImm<0b01110, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Jim Grosbach7ef7ddd2011-06-13 22:54:22 +0000900 IIC_iALUi,
Bill Wendling490240a2010-12-01 01:20:15 +0000901 "add", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000902 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7:$imm3))]>,
903 Sched<[WriteALU]> {
Bill Wendlingfe1de032010-11-20 01:00:29 +0000904 bits<3> imm3;
905 let Inst{8-6} = imm3;
Bill Wendlingfe1de032010-11-20 01:00:29 +0000906}
Evan Cheng10043e22007-01-19 07:51:42 +0000907
Bill Wendling4915f562010-12-01 00:48:44 +0000908def tADDi8 : // A8.6.4 T2
Jim Grosbache9ab47a2011-08-16 23:57:34 +0000909 T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
910 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +0000911 "add", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000912 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
913 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000914
David Goodwine85169c2009-06-25 22:49:55 +0000915// Add register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000916let isCommutable = 1 in
Bill Wendling490240a2010-12-01 01:20:15 +0000917def tADDrr : // A8.6.6 T1
918 T1sIGenEncode<0b01100, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
919 IIC_iALUr,
920 "add", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000921 [(set tGPR:$Rd, (add tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000922
Craig Topperc50d64b2014-11-26 00:46:26 +0000923let hasSideEffects = 0 in
Bill Wendling7c646b92010-12-01 01:32:02 +0000924def tADDhirr : T1pIt<(outs GPR:$Rdn), (ins GPR:$Rn, GPR:$Rm), IIC_iALUr,
925 "add", "\t$Rdn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000926 T1Special<{0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000927 // A8.6.6 T2
Bill Wendling7c646b92010-12-01 01:32:02 +0000928 bits<4> Rdn;
929 bits<4> Rm;
930 let Inst{7} = Rdn{3};
931 let Inst{6-3} = Rm;
932 let Inst{2-0} = Rdn{2-0};
Bill Wendling284326b2010-11-20 01:18:47 +0000933}
Evan Cheng10043e22007-01-19 07:51:42 +0000934
Bill Wendling284326b2010-11-20 01:18:47 +0000935// AND register
Evan Chengcd4cdd12009-07-11 06:43:01 +0000936let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +0000937def tAND : // A8.6.12
938 T1sItDPEncode<0b0000, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
939 IIC_iBITr,
940 "and", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000941 [(set tGPR:$Rdn, (and tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000942
David Goodwine85169c2009-06-25 22:49:55 +0000943// ASR immediate
Bill Wendling490240a2010-12-01 01:20:15 +0000944def tASRri : // A8.6.14
Owen Andersonc4030382011-08-08 20:42:17 +0000945 T1sIGenEncodeImm<{0,1,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +0000946 IIC_iMOVsi,
947 "asr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000948 [(set tGPR:$Rd, (sra tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
949 Sched<[WriteALU]> {
Bill Wendling284326b2010-11-20 01:18:47 +0000950 bits<5> imm5;
951 let Inst{10-6} = imm5;
Bill Wendling284326b2010-11-20 01:18:47 +0000952}
Evan Cheng10043e22007-01-19 07:51:42 +0000953
David Goodwine85169c2009-06-25 22:49:55 +0000954// ASR register
Bill Wendling4915f562010-12-01 00:48:44 +0000955def tASRrr : // A8.6.15
956 T1sItDPEncode<0b0100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
957 IIC_iMOVsr,
958 "asr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000959 [(set tGPR:$Rdn, (sra tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000960
David Goodwine85169c2009-06-25 22:49:55 +0000961// BIC register
Bill Wendling4915f562010-12-01 00:48:44 +0000962def tBIC : // A8.6.20
963 T1sItDPEncode<0b1110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
964 IIC_iBITr,
965 "bic", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000966 [(set tGPR:$Rdn, (and tGPR:$Rn, (not tGPR:$Rm)))]>,
967 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +0000968
David Goodwine85169c2009-06-25 22:49:55 +0000969// CMN register
Gabor Greif22f69222010-09-14 22:00:50 +0000970let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach267430f2010-01-22 00:08:13 +0000971//FIXME: Disable CMN, as CCodes are backwards from compare expectations
972// Compare-to-zero still works out, just not the relationals
Bill Wendling9c258942010-12-01 02:36:55 +0000973//def tCMN : // A8.6.33
974// T1pIDPEncode<0b1011, (outs), (ins tGPR:$lhs, tGPR:$rhs),
975// IIC_iCMPr,
976// "cmn", "\t$lhs, $rhs",
977// [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000978
979def tCMNz : // A8.6.33
980 T1pIDPEncode<0b1011, (outs), (ins tGPR:$Rn, tGPR:$Rm),
981 IIC_iCMPr,
982 "cmn", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000983 [(ARMcmpZ tGPR:$Rn, (ineg tGPR:$Rm))]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +0000984
985} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +0000986
David Goodwine85169c2009-06-25 22:49:55 +0000987// CMP immediate
Gabor Greif22f69222010-09-14 22:00:50 +0000988let isCompare = 1, Defs = [CPSR] in {
Jim Grosbach4f240a12011-08-18 18:08:29 +0000989def tCMPi8 : T1pI<(outs), (ins tGPR:$Rn, imm0_255:$imm8), IIC_iCMPi,
Bill Wendlingc31de252010-11-20 22:52:33 +0000990 "cmp", "\t$Rn, $imm8",
991 [(ARMcmp tGPR:$Rn, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +0000992 T1General<{1,0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendlingc31de252010-11-20 22:52:33 +0000993 // A8.6.35
994 bits<3> Rn;
995 bits<8> imm8;
996 let Inst{10-8} = Rn;
997 let Inst{7-0} = imm8;
998}
999
David Goodwine85169c2009-06-25 22:49:55 +00001000// CMP register
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001001def tCMPr : // A8.6.36 T1
1002 T1pIDPEncode<0b1010, (outs), (ins tGPR:$Rn, tGPR:$Rm),
1003 IIC_iCMPr,
1004 "cmp", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001005 [(ARMcmp tGPR:$Rn, tGPR:$Rm)]>, Sched<[WriteCMP]>;
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001006
Bill Wendling775899e2010-11-29 00:18:15 +00001007def tCMPhir : T1pI<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_iCMPr,
1008 "cmp", "\t$Rn, $Rm", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001009 T1Special<{0,1,?,?}>, Sched<[WriteCMP]> {
Bill Wendling775899e2010-11-29 00:18:15 +00001010 // A8.6.36 T2
1011 bits<4> Rm;
1012 bits<4> Rn;
1013 let Inst{7} = Rn{3};
1014 let Inst{6-3} = Rm;
1015 let Inst{2-0} = Rn{2-0};
1016}
Bill Wendlingc31de252010-11-20 22:52:33 +00001017} // isCompare = 1, Defs = [CPSR]
Lauro Ramos Venancio6be85332007-04-02 01:30:03 +00001018
Evan Cheng10043e22007-01-19 07:51:42 +00001019
David Goodwine85169c2009-06-25 22:49:55 +00001020// XOR register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001021let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001022def tEOR : // A8.6.45
1023 T1sItDPEncode<0b0001, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1024 IIC_iBITr,
1025 "eor", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001026 [(set tGPR:$Rdn, (xor tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001027
David Goodwine85169c2009-06-25 22:49:55 +00001028// LSL immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001029def tLSLri : // A8.6.88
Jim Grosbach5503c3a2011-08-19 19:29:25 +00001030 T1sIGenEncodeImm<{0,0,0,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_31:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001031 IIC_iMOVsi,
1032 "lsl", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001033 [(set tGPR:$Rd, (shl tGPR:$Rm, (i32 imm:$imm5)))]>,
1034 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001035 bits<5> imm5;
1036 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001037}
Evan Cheng10043e22007-01-19 07:51:42 +00001038
David Goodwine85169c2009-06-25 22:49:55 +00001039// LSL register
Bill Wendling4915f562010-12-01 00:48:44 +00001040def tLSLrr : // A8.6.89
1041 T1sItDPEncode<0b0010, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1042 IIC_iMOVsr,
1043 "lsl", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001044 [(set tGPR:$Rdn, (shl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001045
David Goodwine85169c2009-06-25 22:49:55 +00001046// LSR immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001047def tLSRri : // A8.6.90
Owen Andersonc4030382011-08-08 20:42:17 +00001048 T1sIGenEncodeImm<{0,0,1,?,?}, (outs tGPR:$Rd), (ins tGPR:$Rm, imm_sr:$imm5),
Bill Wendling490240a2010-12-01 01:20:15 +00001049 IIC_iMOVsi,
1050 "lsr", "\t$Rd, $Rm, $imm5",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001051 [(set tGPR:$Rd, (srl tGPR:$Rm, (i32 imm_sr:$imm5)))]>,
1052 Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001053 bits<5> imm5;
1054 let Inst{10-6} = imm5;
Bill Wendling22db3132010-11-21 11:49:36 +00001055}
Evan Cheng10043e22007-01-19 07:51:42 +00001056
David Goodwine85169c2009-06-25 22:49:55 +00001057// LSR register
Bill Wendling4915f562010-12-01 00:48:44 +00001058def tLSRrr : // A8.6.91
1059 T1sItDPEncode<0b0011, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1060 IIC_iMOVsr,
1061 "lsr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001062 [(set tGPR:$Rdn, (srl tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001063
Bill Wendling22db3132010-11-21 11:49:36 +00001064// Move register
Evan Cheng7f8ab6e2010-11-17 20:13:28 +00001065let isMoveImm = 1 in
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001066def tMOVi8 : T1sI<(outs tGPR:$Rd), (ins imm0_255:$imm8), IIC_iMOVi,
Bill Wendling22db3132010-11-21 11:49:36 +00001067 "mov", "\t$Rd, $imm8",
1068 [(set tGPR:$Rd, imm0_255:$imm8)]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001069 T1General<{1,0,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling22db3132010-11-21 11:49:36 +00001070 // A8.6.96
1071 bits<3> Rd;
1072 bits<8> imm8;
1073 let Inst{10-8} = Rd;
1074 let Inst{7-0} = imm8;
1075}
Jim Grosbachf86cd372011-08-19 20:46:54 +00001076// Because we have an explicit tMOVSr below, we need an alias to handle
1077// the immediate "movs" form here. Blech.
Jim Grosbach6caa5572011-08-22 18:04:24 +00001078def : tInstAlias <"movs $Rdn, $imm",
1079 (tMOVi8 tGPR:$Rdn, CPSR, imm0_255:$imm, 14, 0)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001080
Jim Grosbach4def7042011-07-01 17:14:11 +00001081// A7-73: MOV(2) - mov setting flag.
Evan Cheng10043e22007-01-19 07:51:42 +00001082
Craig Topperc50d64b2014-11-26 00:46:26 +00001083let hasSideEffects = 0 in {
Jim Grosbache9cc9012011-06-30 23:38:17 +00001084def tMOVr : Thumb1pI<(outs GPR:$Rd), (ins GPR:$Rm), AddrModeNone,
Owen Anderson651b2302011-07-13 23:22:26 +00001085 2, IIC_iMOVr,
Jim Grosbachb98ab912011-06-30 22:10:46 +00001086 "mov", "\t$Rd, $Rm", "", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001087 T1Special<{1,0,?,?}>, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001088 // A8.6.97
1089 bits<4> Rd;
1090 bits<4> Rm;
Jim Grosbache9cc9012011-06-30 23:38:17 +00001091 let Inst{7} = Rd{3};
1092 let Inst{6-3} = Rm;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001093 let Inst{2-0} = Rd{2-0};
1094}
Evan Chengcd4cdd12009-07-11 06:43:01 +00001095let Defs = [CPSR] in
Bill Wendling4d8ff862010-12-03 01:55:47 +00001096def tMOVSr : T1I<(outs tGPR:$Rd), (ins tGPR:$Rm), IIC_iMOVr,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001097 "movs\t$Rd, $Rm", []>, Encoding16, Sched<[WriteALU]> {
Bill Wendling4d8ff862010-12-03 01:55:47 +00001098 // A8.6.97
1099 bits<3> Rd;
1100 bits<3> Rm;
Johnny Chenc28e6292009-12-15 17:24:14 +00001101 let Inst{15-6} = 0b0000000000;
Bill Wendling4d8ff862010-12-03 01:55:47 +00001102 let Inst{5-3} = Rm;
1103 let Inst{2-0} = Rd;
Johnny Chenc28e6292009-12-15 17:24:14 +00001104}
Craig Topperc50d64b2014-11-26 00:46:26 +00001105} // hasSideEffects
Evan Cheng10043e22007-01-19 07:51:42 +00001106
Bill Wendling9c258942010-12-01 02:36:55 +00001107// Multiply register
Jim Grosbachbfeb4f72011-08-22 23:25:48 +00001108let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001109def tMUL : // A8.6.105 T1
Jim Grosbach8e048492011-08-19 22:07:46 +00001110 Thumb1sI<(outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm), AddrModeNone, 2,
1111 IIC_iMUL32, "mul", "\t$Rd, $Rn, $Rm", "$Rm = $Rd",
1112 [(set tGPR:$Rd, (mul tGPR:$Rn, tGPR:$Rm))]>,
1113 T1DataProcessing<0b1101> {
1114 bits<3> Rd;
1115 bits<3> Rn;
1116 let Inst{5-3} = Rn;
1117 let Inst{2-0} = Rd;
1118 let AsmMatchConverter = "cvtThumbMultiply";
1119}
1120
Jim Grosbach6caa5572011-08-22 18:04:24 +00001121def :tInstAlias<"mul${s}${p} $Rdm, $Rn", (tMUL tGPR:$Rdm, s_cc_out:$s, tGPR:$Rn,
1122 pred:$p)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001123
Bill Wendling490240a2010-12-01 01:20:15 +00001124// Move inverse register
1125def tMVN : // A8.6.107
1126 T1sIDPEncode<0b1111, (outs tGPR:$Rd), (ins tGPR:$Rn), IIC_iMVNr,
1127 "mvn", "\t$Rd, $Rn",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001128 [(set tGPR:$Rd, (not tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001129
Bill Wendling22db3132010-11-21 11:49:36 +00001130// Bitwise or register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001131let isCommutable = 1 in
Bill Wendling4915f562010-12-01 00:48:44 +00001132def tORR : // A8.6.114
1133 T1sItDPEncode<0b1100, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1134 IIC_iBITr,
1135 "orr", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001136 [(set tGPR:$Rdn, (or tGPR:$Rn, tGPR:$Rm))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001137
Bill Wendling22db3132010-11-21 11:49:36 +00001138// Swaps
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001139def tREV : // A8.6.134
1140 T1pIMiscEncode<{1,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1141 IIC_iUNAr,
1142 "rev", "\t$Rd, $Rm",
1143 [(set tGPR:$Rd, (bswap tGPR:$Rm))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001144 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001145
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001146def tREV16 : // A8.6.135
1147 T1pIMiscEncode<{1,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1148 IIC_iUNAr,
1149 "rev16", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001150 [(set tGPR:$Rd, (rotr (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001151 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001152
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001153def tREVSH : // A8.6.136
1154 T1pIMiscEncode<{1,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1155 IIC_iUNAr,
1156 "revsh", "\t$Rd, $Rm",
Evan Cheng4c0bd962011-06-21 06:01:08 +00001157 [(set tGPR:$Rd, (sra (bswap tGPR:$Rm), (i32 16)))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001158 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001159
Bill Wendling4915f562010-12-01 00:48:44 +00001160// Rotate right register
1161def tROR : // A8.6.139
1162 T1sItDPEncode<0b0111, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1163 IIC_iMOVsr,
1164 "ror", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001165 [(set tGPR:$Rdn, (rotr tGPR:$Rn, tGPR:$Rm))]>,
1166 Sched<[WriteALU]>;
Evan Chengcd4cdd12009-07-11 06:43:01 +00001167
Bill Wendling4915f562010-12-01 00:48:44 +00001168// Negate register
Bill Wendling490240a2010-12-01 01:20:15 +00001169def tRSB : // A8.6.141
1170 T1sIDPEncode<0b1001, (outs tGPR:$Rd), (ins tGPR:$Rn),
1171 IIC_iALUi,
1172 "rsb", "\t$Rd, $Rn, #0",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001173 [(set tGPR:$Rd, (ineg tGPR:$Rn))]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001174
David Goodwine85169c2009-06-25 22:49:55 +00001175// Subtract with carry register
Evan Chengcd4cdd12009-07-11 06:43:01 +00001176let Uses = [CPSR] in
Bill Wendling4915f562010-12-01 00:48:44 +00001177def tSBC : // A8.6.151
1178 T1sItDPEncode<0b0110, (outs tGPR:$Rdn), (ins tGPR:$Rn, tGPR:$Rm),
1179 IIC_iALUr,
1180 "sbc", "\t$Rdn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001181 [(set tGPR:$Rdn, (sube tGPR:$Rn, tGPR:$Rm))]>,
1182 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001183
David Goodwine85169c2009-06-25 22:49:55 +00001184// Subtract immediate
Bill Wendling490240a2010-12-01 01:20:15 +00001185def tSUBi3 : // A8.6.210 T1
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001186 T1sIGenEncodeImm<0b01111, (outs tGPR:$Rd), (ins tGPR:$Rm, imm0_7:$imm3),
Bill Wendling490240a2010-12-01 01:20:15 +00001187 IIC_iALUi,
1188 "sub", "\t$Rd, $Rm, $imm3",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001189 [(set tGPR:$Rd, (add tGPR:$Rm, imm0_7_neg:$imm3))]>,
1190 Sched<[WriteALU]> {
Bill Wendlingccba1a82010-11-29 01:00:43 +00001191 bits<3> imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001192 let Inst{8-6} = imm3;
Bill Wendlingccba1a82010-11-29 01:00:43 +00001193}
Jim Grosbach669f1d02009-03-27 23:06:27 +00001194
Bill Wendling4915f562010-12-01 00:48:44 +00001195def tSUBi8 : // A8.6.210 T2
Jim Grosbachd0c435c2011-09-16 22:58:42 +00001196 T1sItGenEncodeImm<{1,1,1,?,?}, (outs tGPR:$Rdn),
1197 (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
Bill Wendling4915f562010-12-01 00:48:44 +00001198 "sub", "\t$Rdn, $imm8",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001199 [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255_neg:$imm8))]>,
1200 Sched<[WriteALU]>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001201
Bill Wendling490240a2010-12-01 01:20:15 +00001202// Subtract register
1203def tSUBrr : // A8.6.212
1204 T1sIGenEncode<0b01101, (outs tGPR:$Rd), (ins tGPR:$Rn, tGPR:$Rm),
1205 IIC_iALUr,
1206 "sub", "\t$Rd, $Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001207 [(set tGPR:$Rd, (sub tGPR:$Rn, tGPR:$Rm))]>,
1208 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001209
Bill Wendling490240a2010-12-01 01:20:15 +00001210// Sign-extend byte
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001211def tSXTB : // A8.6.222
1212 T1pIMiscEncode<{0,0,1,0,0,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1213 IIC_iUNAr,
1214 "sxtb", "\t$Rd, $Rm",
1215 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i8))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001216 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1217 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001218
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001219// Sign-extend short
1220def tSXTH : // A8.6.224
1221 T1pIMiscEncode<{0,0,1,0,0,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1222 IIC_iUNAr,
1223 "sxth", "\t$Rd, $Rm",
1224 [(set tGPR:$Rd, (sext_inreg tGPR:$Rm, i16))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001225 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1226 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001227
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001228// Test
Gabor Greif2afac8e2010-09-14 20:47:43 +00001229let isCompare = 1, isCommutable = 1, Defs = [CPSR] in
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001230def tTST : // A8.6.230
1231 T1pIDPEncode<0b1000, (outs), (ins tGPR:$Rn, tGPR:$Rm), IIC_iTSTr,
1232 "tst", "\t$Rn, $Rm",
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001233 [(ARMcmpZ (and_su tGPR:$Rn, tGPR:$Rm), 0)]>,
1234 Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001235
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001236// A8.8.247 UDF - Undefined (Encoding T1)
Saleem Abdulrasool2bd12622014-05-22 04:46:46 +00001237def tUDF : TI<(outs), (ins imm0_255:$imm8), IIC_Br, "udf\t$imm8",
1238 [(int_arm_undefined imm0_255:$imm8)]>, Encoding16 {
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00001239 bits<8> imm8;
1240 let Inst{15-12} = 0b1101;
1241 let Inst{11-8} = 0b1110;
1242 let Inst{7-0} = imm8;
1243}
1244
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001245// Zero-extend byte
1246def tUXTB : // A8.6.262
1247 T1pIMiscEncode<{0,0,1,0,1,1,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1248 IIC_iUNAr,
1249 "uxtb", "\t$Rd, $Rm",
1250 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001251 Requires<[IsThumb, IsThumb1Only, HasV6]>,
1252 Sched<[WriteALU]>;
David Goodwine85169c2009-06-25 22:49:55 +00001253
Bill Wendling8ed14ae2010-12-01 02:28:08 +00001254// Zero-extend short
1255def tUXTH : // A8.6.264
1256 T1pIMiscEncode<{0,0,1,0,1,0,?}, (outs tGPR:$Rd), (ins tGPR:$Rm),
1257 IIC_iUNAr,
1258 "uxth", "\t$Rd, $Rm",
1259 [(set tGPR:$Rd, (and tGPR:$Rm, 0xFFFF))]>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001260 Requires<[IsThumb, IsThumb1Only, HasV6]>, Sched<[WriteALU]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001261
Jim Grosbach3e2cad32010-02-16 21:23:02 +00001262// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC operation.
Dan Gohman453d64c2009-10-29 18:10:34 +00001263// Expanded after instruction selection into a branch sequence.
1264let usesCustomInserter = 1 in // Expanded after instruction selection.
Evan Chengbb2af352009-08-12 05:17:19 +00001265 def tMOVCCr_pseudo :
Tim Northover42180442013-08-22 09:57:11 +00001266 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, cmovpred:$p),
1267 NoItinerary,
1268 [(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, cmovpred:$p))]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001269
1270// tLEApcrel - Load a pc-relative address into a register without offending the
1271// assembler.
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001272
1273def tADR : T1I<(outs tGPR:$Rd), (ins t_adrlabel:$addr, pred:$p),
Jim Grosbache2a04042011-08-17 20:37:40 +00001274 IIC_iALUi, "adr{$p}\t$Rd, $addr", []>,
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001275 T1Encoding<{1,0,1,0,0,?}>, Sched<[WriteALU]> {
Bill Wendling85a8a722010-11-30 00:18:30 +00001276 bits<3> Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001277 bits<8> addr;
Bill Wendling85a8a722010-11-30 00:18:30 +00001278 let Inst{10-8} = Rd;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001279 let Inst{7-0} = addr;
Owen Andersone0152a72011-08-09 20:55:18 +00001280 let DecoderMethod = "DecodeThumbAddSpecialReg";
Bill Wendling85a8a722010-11-30 00:18:30 +00001281}
Evan Cheng10043e22007-01-19 07:51:42 +00001282
Craig Topperc50d64b2014-11-26 00:46:26 +00001283let hasSideEffects = 0, isReMaterializable = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001284def tLEApcrel : tPseudoInst<(outs tGPR:$Rd), (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001285 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001286
Jakob Stoklund Olesen74352492012-08-24 22:46:55 +00001287let hasSideEffects = 1 in
Jim Grosbach509dc2a2010-12-14 22:28:03 +00001288def tLEApcrelJT : tPseudoInst<(outs tGPR:$Rd),
Tim Northover4998a472015-05-13 20:28:38 +00001289 (ins i32imm:$label, pred:$p),
Arnold Schwaighofer654649d2013-06-06 17:03:13 +00001290 2, IIC_iALUi, []>, Sched<[WriteALU]>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001291
Evan Cheng10043e22007-01-19 07:51:42 +00001292//===----------------------------------------------------------------------===//
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001293// TLS Instructions
1294//
1295
1296// __aeabi_read_tp preserves the registers r1-r3.
Jim Grosbache4750ef2011-06-30 19:38:01 +00001297// This is a pseudo inst so that we can get the encoding right,
1298// complete with fixup for the aeabi_read_tp function.
1299let isCall = 1, Defs = [R0, R12, LR, CPSR], Uses = [SP] in
Owen Anderson651b2302011-07-13 23:22:26 +00001300def tTPsoft : tPseudoInst<(outs), (ins), 4, IIC_Br,
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001301 [(set R0, ARMthread_pointer)]>,
1302 Sched<[WriteBr]>;
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001303
Bill Wendling9c258942010-12-01 02:36:55 +00001304//===----------------------------------------------------------------------===//
Jim Grosbach36d4dec2009-12-01 18:10:36 +00001305// SJLJ Exception handling intrinsics
Owen Andersonb7456232011-05-11 17:00:48 +00001306//
Bill Wendling9c258942010-12-01 02:36:55 +00001307
1308// eh_sjlj_setjmp() is an instruction sequence to store the return address and
1309// save #0 in R0 for the non-longjmp case. Since by its nature we may be coming
1310// from some other function to get here, and we're using the stack frame for the
1311// containing function to save/restore registers, we can't keep anything live in
1312// regs across the eh_sjlj_setjmp(), else it will almost certainly have been
Chris Lattner0ab5e2c2011-04-15 05:18:47 +00001313// tromped upon when we get here from a longjmp(). We force everything out of
Bill Wendling9c258942010-12-01 02:36:55 +00001314// registers except for our own input by listing the relevant registers in
1315// Defs. By doing so, we also cause the prologue/epilogue code to actively
1316// preserve all of the callee-saved resgisters, which is exactly what we want.
1317// $val is a scratch register for our use.
Andrew Trick410172b2011-06-07 00:08:49 +00001318let Defs = [ R0, R1, R2, R3, R4, R5, R6, R7, R12, CPSR ],
Bill Wendlingaa9047d2011-10-17 22:26:23 +00001319 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
1320 usesCustomInserter = 1 in
Bill Wendlingddce9f32010-11-30 00:50:22 +00001321def tInt_eh_sjlj_setjmp : ThumbXI<(outs),(ins tGPR:$src, tGPR:$val),
Owen Anderson651b2302011-07-13 23:22:26 +00001322 AddrModeNone, 0, NoItinerary, "","",
Bill Wendlingddce9f32010-11-30 00:50:22 +00001323 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001324
Evan Cheng68132d82011-12-20 18:26:50 +00001325// FIXME: Non-IOS version(s)
Chris Lattner9492c172010-10-31 19:15:18 +00001326let isBarrier = 1, hasSideEffects = 1, isTerminator = 1, isCodeGenOnly = 1,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001327 Defs = [ R7, LR, SP ] in
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001328def tInt_eh_sjlj_longjmp : XI<(outs), (ins GPR:$src, GPR:$scratch),
Owen Anderson651b2302011-07-13 23:22:26 +00001329 AddrModeNone, 0, IndexModeNone,
Bill Wendlingddce9f32010-11-30 00:50:22 +00001330 Pseudo, NoItinerary, "", "",
1331 [(ARMeh_sjlj_longjmp GPR:$src, GPR:$scratch)]>,
Tim Northovere2c33712014-12-11 18:49:37 +00001332 Requires<[IsThumb]>;
Jim Grosbachbd9485d2010-05-22 01:06:18 +00001333
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +00001334//===----------------------------------------------------------------------===//
Evan Cheng10043e22007-01-19 07:51:42 +00001335// Non-Instruction Patterns
1336//
1337
Jim Grosbach327cf8e2010-12-07 20:41:06 +00001338// Comparisons
1339def : T1Pat<(ARMcmpZ tGPR:$Rn, imm0_255:$imm8),
1340 (tCMPi8 tGPR:$Rn, imm0_255:$imm8)>;
1341def : T1Pat<(ARMcmpZ tGPR:$Rn, tGPR:$Rm),
1342 (tCMPr tGPR:$Rn, tGPR:$Rm)>;
1343
Evan Cheng61671c82009-07-10 02:09:04 +00001344// Add with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001345def : T1Pat<(addc tGPR:$lhs, imm0_7:$rhs),
1346 (tADDi3 tGPR:$lhs, imm0_7:$rhs)>;
1347def : T1Pat<(addc tGPR:$lhs, imm8_255:$rhs),
Evan Cheng01de9852009-08-20 17:01:04 +00001348 (tADDi8 tGPR:$lhs, imm8_255:$rhs)>;
David Goodwine5b969f2009-07-27 19:59:26 +00001349def : T1Pat<(addc tGPR:$lhs, tGPR:$rhs),
1350 (tADDrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001351
1352// Subtract with carry
David Goodwine5b969f2009-07-27 19:59:26 +00001353def : T1Pat<(addc tGPR:$lhs, imm0_7_neg:$rhs),
1354 (tSUBi3 tGPR:$lhs, imm0_7_neg:$rhs)>;
1355def : T1Pat<(addc tGPR:$lhs, imm8_255_neg:$rhs),
1356 (tSUBi8 tGPR:$lhs, imm8_255_neg:$rhs)>;
1357def : T1Pat<(subc tGPR:$lhs, tGPR:$rhs),
1358 (tSUBrr tGPR:$lhs, tGPR:$rhs)>;
Evan Cheng61671c82009-07-10 02:09:04 +00001359
Louis Gerbargefdcf232014-05-12 19:53:52 +00001360// Bswap 16 with load/store
Louis Gerbargefdcf232014-05-12 19:53:52 +00001361def : T1Pat<(srl (bswap (extloadi16 t_addrmode_is2:$addr)), (i32 16)),
1362 (tREV16 (tLDRHi t_addrmode_is2:$addr))>;
John Brawn68acdcb2015-08-13 10:48:22 +00001363def : T1Pat<(srl (bswap (extloadi16 t_addrmode_rr:$addr)), (i32 16)),
1364 (tREV16 (tLDRHr t_addrmode_rr:$addr))>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001365def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1366 t_addrmode_is2:$addr),
1367 (tSTRHi(tREV16 tGPR:$Rn), t_addrmode_is2:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001368def : T1Pat<(truncstorei16 (srl (bswap tGPR:$Rn), (i32 16)),
1369 t_addrmode_rr:$addr),
1370 (tSTRHr (tREV16 tGPR:$Rn), t_addrmode_rr:$addr)>;
Louis Gerbargefdcf232014-05-12 19:53:52 +00001371
Tim Northoverdfe2156c2013-11-25 14:40:57 +00001372// ConstantPool
David Goodwine5b969f2009-07-27 19:59:26 +00001373def : T1Pat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Evan Cheng10043e22007-01-19 07:51:42 +00001374
Tim Northover72360d22013-12-02 10:35:41 +00001375// GlobalAddress
Tim Northover1328c1a2014-01-13 14:19:17 +00001376def tLDRLIT_ga_pcrel : PseudoInst<(outs tGPR:$dst), (ins i32imm:$addr),
Tim Northover72360d22013-12-02 10:35:41 +00001377 IIC_iLoadiALU,
Tim Northover1328c1a2014-01-13 14:19:17 +00001378 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001379 (ARMWrapperPIC tglobaladdr:$addr))]>,
1380 Requires<[IsThumb, DontUseMovt]>;
1381
Tim Northover1328c1a2014-01-13 14:19:17 +00001382def tLDRLIT_ga_abs : PseudoInst<(outs tGPR:$dst), (ins i32imm:$src),
1383 IIC_iLoad_i,
1384 [(set tGPR:$dst,
Tim Northover72360d22013-12-02 10:35:41 +00001385 (ARMWrapper tglobaladdr:$src))]>,
1386 Requires<[IsThumb, DontUseMovt]>;
1387
Tim Northoverbd41cf82016-01-07 09:03:03 +00001388// TLS globals
1389def : Pat<(ARMWrapperPIC tglobaltlsaddr:$addr),
1390 (tLDRLIT_ga_pcrel tglobaltlsaddr:$addr)>,
1391 Requires<[IsThumb, DontUseMovt]>;
1392def : Pat<(ARMWrapper tglobaltlsaddr:$addr),
1393 (tLDRLIT_ga_abs tglobaltlsaddr:$addr)>,
1394 Requires<[IsThumb, DontUseMovt]>;
1395
Tim Northover72360d22013-12-02 10:35:41 +00001396
Evan Cheng0701c5a2007-01-27 02:29:45 +00001397// JumpTable
Tim Northover4998a472015-05-13 20:28:38 +00001398def : T1Pat<(ARMWrapperJT tjumptable:$dst),
1399 (tLEApcrelJT tjumptable:$dst)>;
Evan Cheng0701c5a2007-01-27 02:29:45 +00001400
Evan Cheng10043e22007-01-19 07:51:42 +00001401// Direct calls
Evan Cheng175bd142009-07-29 21:26:42 +00001402def : T1Pat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001403 Requires<[IsThumb]>;
Evan Cheng175bd142009-07-29 21:26:42 +00001404
1405def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>,
Tim Northover2a417b92014-08-06 11:13:14 +00001406 Requires<[IsThumb, HasV5T, IsNotMClass]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001407
1408// Indirect calls to ARM routines
Evan Cheng6ab54fd2009-08-01 00:16:10 +00001409def : Tv5Pat<(ARMcall GPR:$dst), (tBLXr GPR:$dst)>,
Jakob Stoklund Olesen6a2e99a2012-04-06 00:04:58 +00001410 Requires<[IsThumb, HasV5T]>;
Evan Cheng10043e22007-01-19 07:51:42 +00001411
1412// zextload i1 -> zextload i8
Bill Wendling092a7bd2010-12-14 03:36:38 +00001413def : T1Pat<(zextloadi1 t_addrmode_is1:$addr),
1414 (tLDRBi t_addrmode_is1:$addr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001415def : T1Pat<(zextloadi1 t_addrmode_rr:$addr),
1416 (tLDRBr t_addrmode_rr:$addr)>;
Jim Grosbach669f1d02009-03-27 23:06:27 +00001417
Renato Golinb9887ef2015-02-25 14:41:06 +00001418// extload from the stack -> word load from the stack, as it avoids having to
1419// materialize the base in a separate register. This only works when a word
1420// load puts the byte/halfword value in the same place in the register that the
1421// byte/halfword load would, i.e. when little-endian.
1422def : T1Pat<(extloadi1 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1423 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1424def : T1Pat<(extloadi8 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1425 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1426def : T1Pat<(extloadi16 t_addrmode_sp:$addr), (tLDRspi t_addrmode_sp:$addr)>,
1427 Requires<[IsThumb, IsThumb1Only, IsLE]>;
1428
Evan Chengd02d75c2007-01-26 19:13:16 +00001429// extload -> zextload
John Brawn68acdcb2015-08-13 10:48:22 +00001430def : T1Pat<(extloadi1 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1431def : T1Pat<(extloadi1 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1432def : T1Pat<(extloadi8 t_addrmode_is1:$addr), (tLDRBi t_addrmode_is1:$addr)>;
1433def : T1Pat<(extloadi8 t_addrmode_rr:$addr), (tLDRBr t_addrmode_rr:$addr)>;
1434def : T1Pat<(extloadi16 t_addrmode_is2:$addr), (tLDRHi t_addrmode_is2:$addr)>;
1435def : T1Pat<(extloadi16 t_addrmode_rr:$addr), (tLDRHr t_addrmode_rr:$addr)>;
Evan Chengd02d75c2007-01-26 19:13:16 +00001436
Evan Cheng6da267d2009-08-28 00:31:43 +00001437// If it's impossible to use [r,r] address mode for sextload, select to
Evan Cheng0794c6a2009-07-11 07:08:13 +00001438// ldr{b|h} + sxt{b|h} instead.
Bill Wendling1171e9e2010-12-15 00:58:57 +00001439def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1440 (tSXTB (tLDRBi t_addrmode_is1:$addr))>,
1441 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001442def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1443 (tSXTB (tLDRBr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001444 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001445def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1446 (tSXTH (tLDRHi t_addrmode_is2:$addr))>,
1447 Requires<[IsThumb, IsThumb1Only, HasV6]>;
John Brawn68acdcb2015-08-13 10:48:22 +00001448def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1449 (tSXTH (tLDRHr t_addrmode_rr:$addr))>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001450 Requires<[IsThumb, IsThumb1Only, HasV6]>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001451
Bill Wendling1171e9e2010-12-15 00:58:57 +00001452def : T1Pat<(sextloadi8 t_addrmode_is1:$addr),
1453 (tASRri (tLSLri (tLDRBi t_addrmode_is1:$addr), 24), 24)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001454def : T1Pat<(sextloadi8 t_addrmode_rr:$addr),
1455 (tASRri (tLSLri (tLDRBr t_addrmode_rr:$addr), 24), 24)>;
Bill Wendling1171e9e2010-12-15 00:58:57 +00001456def : T1Pat<(sextloadi16 t_addrmode_is2:$addr),
1457 (tASRri (tLSLri (tLDRHi t_addrmode_is2:$addr), 16), 16)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001458def : T1Pat<(sextloadi16 t_addrmode_rr:$addr),
1459 (tASRri (tLSLri (tLDRHr t_addrmode_rr:$addr), 16), 16)>;
Evan Cheng0794c6a2009-07-11 07:08:13 +00001460
Eli Friedmanba912e02011-09-15 22:18:49 +00001461def : T1Pat<(atomic_load_8 t_addrmode_is1:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001462 (tLDRBi t_addrmode_is1:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001463def : T1Pat<(atomic_load_8 t_addrmode_rr:$src),
1464 (tLDRBr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001465def : T1Pat<(atomic_load_16 t_addrmode_is2:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001466 (tLDRHi t_addrmode_is2:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001467def : T1Pat<(atomic_load_16 t_addrmode_rr:$src),
1468 (tLDRHr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001469def : T1Pat<(atomic_load_32 t_addrmode_is4:$src),
Jakob Stoklund Olesenb3de7b12012-08-28 03:11:27 +00001470 (tLDRi t_addrmode_is4:$src)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001471def : T1Pat<(atomic_load_32 t_addrmode_rr:$src),
1472 (tLDRr t_addrmode_rr:$src)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001473def : T1Pat<(atomic_store_8 t_addrmode_is1:$ptr, tGPR:$val),
1474 (tSTRBi tGPR:$val, t_addrmode_is1:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001475def : T1Pat<(atomic_store_8 t_addrmode_rr:$ptr, tGPR:$val),
1476 (tSTRBr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001477def : T1Pat<(atomic_store_16 t_addrmode_is2:$ptr, tGPR:$val),
1478 (tSTRHi tGPR:$val, t_addrmode_is2:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001479def : T1Pat<(atomic_store_16 t_addrmode_rr:$ptr, tGPR:$val),
1480 (tSTRHr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001481def : T1Pat<(atomic_store_32 t_addrmode_is4:$ptr, tGPR:$val),
1482 (tSTRi tGPR:$val, t_addrmode_is4:$ptr)>;
John Brawn68acdcb2015-08-13 10:48:22 +00001483def : T1Pat<(atomic_store_32 t_addrmode_rr:$ptr, tGPR:$val),
1484 (tSTRr tGPR:$val, t_addrmode_rr:$ptr)>;
Eli Friedmanba912e02011-09-15 22:18:49 +00001485
Evan Cheng10043e22007-01-19 07:51:42 +00001486// Large immediate handling.
1487
1488// Two piece imms.
Evan Chengeab9ca72009-06-27 02:26:13 +00001489def : T1Pat<(i32 thumb_immshifted:$src),
1490 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
1491 (thumb_immshifted_shamt imm:$src))>;
Evan Cheng10043e22007-01-19 07:51:42 +00001492
Evan Chengeab9ca72009-06-27 02:26:13 +00001493def : T1Pat<(i32 imm0_255_comp:$src),
1494 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;
Evan Cheng207b2462009-11-06 23:52:48 +00001495
1496// Pseudo instruction that combines ldr from constpool and add pc. This should
1497// be expanded into two instructions late to allow if-conversion and
1498// scheduling.
1499let isReMaterializable = 1 in
1500def tLDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Bill Wendling9c258942010-12-01 02:36:55 +00001501 NoItinerary,
Evan Cheng207b2462009-11-06 23:52:48 +00001502 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
1503 imm:$cp))]>,
Jim Grosbachfddf36d2010-11-01 17:08:58 +00001504 Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001505
1506// Pseudo-instruction for merged POP and return.
1507// FIXME: remove when we have a way to marking a MI with these properties.
1508let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
1509 hasExtraDefRegAllocReq = 1 in
1510def tPOP_RET : tPseudoExpand<(outs), (ins pred:$p, reglist:$regs, variable_ops),
Owen Anderson651b2302011-07-13 23:22:26 +00001511 2, IIC_iPop_Br, [],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001512 (tPOP pred:$p, reglist:$regs)>, Sched<[WriteBrL]>;
Jim Grosbach95dee402011-07-08 17:40:42 +00001513
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001514// Indirect branch using "mov pc, $Rm"
1515let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
Jim Grosbach39c67b52011-07-08 22:33:49 +00001516 def tBRIND : tPseudoExpand<(outs), (ins GPR:$Rm, pred:$p),
Owen Anderson651b2302011-07-13 23:22:26 +00001517 2, IIC_Br, [(brind GPR:$Rm)],
Arnold Schwaighoferf1395b62013-06-06 18:51:01 +00001518 (tMOVr PC, GPR:$Rm, pred:$p)>, Sched<[WriteBr]>;
Jim Grosbach59a3ab62011-07-08 22:25:23 +00001519}
Jim Grosbach25977222011-08-19 23:24:36 +00001520
1521
1522// In Thumb1, "nop" is encoded as a "mov r8, r8". Technically, the bf00
1523// encoding is available on ARMv6K, but we don't differentiate that finely.
1524def : InstAlias<"nop", (tMOVr R8, R8, 14, 0)>,Requires<[IsThumb, IsThumb1Only]>;
Jim Grosbach08a47802011-09-20 00:10:37 +00001525
1526
1527// For round-trip assembly/disassembly, we have to handle a CPS instruction
1528// without any iflags. That's not, strictly speaking, valid syntax, but it's
Benjamin Kramerbde91762012-06-02 10:20:22 +00001529// a useful extension and assembles to defined behaviour (the insn does
Jim Grosbach08a47802011-09-20 00:10:37 +00001530// nothing).
1531def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
1532def : tInstAlias<"cps$imod", (tCPS imod_op:$imod, 0)>;
Jim Grosbach561e4e12011-12-13 20:23:22 +00001533
1534// "neg" is and alias for "rsb rd, rn, #0"
1535def : tInstAlias<"neg${s}${p} $Rd, $Rm",
1536 (tRSB tGPR:$Rd, s_cc_out:$s, tGPR:$Rm, pred:$p)>;
1537
Jim Grosbachad66de12012-04-11 00:15:16 +00001538
1539// Implied destination operand forms for shifts.
1540def : tInstAlias<"lsl${s}${p} $Rdm, $imm",
1541 (tLSLri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm0_31:$imm, pred:$p)>;
1542def : tInstAlias<"lsr${s}${p} $Rdm, $imm",
1543 (tLSRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;
1544def : tInstAlias<"asr${s}${p} $Rdm, $imm",
1545 (tASRri tGPR:$Rdm, cc_out:$s, tGPR:$Rdm, imm_sr:$imm, pred:$p)>;