blob: 2c62fdb3866f6453d53947c57b0dd5189c22cef5 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- ARMInstrThumb2.td - Thumb2 support for ARM ---------*- tablegen -*-===//
Anton Korobeynikovd4022c32009-05-29 23:41:08 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb2 instruction set.
11//
12//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +000013
Evan Cheng06e16582009-07-10 01:54:42 +000014// IT block predicate field
Jim Grosbach89df9962011-08-26 21:43:41 +000015def it_pred_asmoperand : AsmOperandClass {
16 let Name = "ITCondCode";
17 let ParserMethod = "parseITCondCode";
18}
Evan Cheng06e16582009-07-10 01:54:42 +000019def it_pred : Operand<i32> {
Johnny Chen9d3acaa2010-03-02 17:57:15 +000020 let PrintMethod = "printMandatoryPredicateOperand";
Jim Grosbach89df9962011-08-26 21:43:41 +000021 let ParserMatchClass = it_pred_asmoperand;
Evan Cheng06e16582009-07-10 01:54:42 +000022}
23
24// IT block condition mask
Jim Grosbach89df9962011-08-26 21:43:41 +000025def it_mask_asmoperand : AsmOperandClass { let Name = "ITMask"; }
Evan Cheng06e16582009-07-10 01:54:42 +000026def it_mask : Operand<i32> {
27 let PrintMethod = "printThumbITMask";
Jim Grosbach89df9962011-08-26 21:43:41 +000028 let ParserMatchClass = it_mask_asmoperand;
Evan Cheng06e16582009-07-10 01:54:42 +000029}
30
Owen Anderson0afa0092011-09-26 21:06:22 +000031// t2_shift_imm: An integer that encodes a shift amount and the type of shift
32// (asr or lsl). The 6-bit immediate encodes as:
33// {5} 0 ==> lsl
34// 1 asr
35// {4-0} imm5 shift amount.
36// asr #32 not allowed
37def t2_shift_imm : Operand<i32> {
38 let PrintMethod = "printShiftImmOperand";
39 let ParserMatchClass = ShifterImmAsmOperand;
40 let DecoderMethod = "DecodeT2ShifterImmOperand";
41}
42
Anton Korobeynikov52237112009-06-17 18:13:58 +000043// Shifted operands. No register controlled shifts for Thumb2.
44// Note: We do not support rrx shifted operands yet.
45def t2_so_reg : Operand<i32>, // reg imm
Evan Cheng9cb9e672009-06-27 02:26:13 +000046 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
Anton Korobeynikov52237112009-06-17 18:13:58 +000047 [shl,srl,sra,rotr]> {
Chris Lattner2ac19022010-11-15 05:19:05 +000048 let EncoderMethod = "getT2SORegOpValue";
Evan Cheng9cb9e672009-06-27 02:26:13 +000049 let PrintMethod = "printT2SOOperand";
Owen Anderson2c9f8352011-08-22 23:10:16 +000050 let DecoderMethod = "DecodeSORegImmOperand";
Jim Grosbach72335d52011-08-31 18:23:08 +000051 let ParserMatchClass = ShiftedImmAsmOperand;
52 let MIOperandInfo = (ops rGPR, i32imm);
Anton Korobeynikov52237112009-06-17 18:13:58 +000053}
54
Evan Chengf49810c2009-06-23 17:48:47 +000055// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
56def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000057 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000058}]>;
59
Evan Chengf49810c2009-06-23 17:48:47 +000060// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
61def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000062 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
Evan Chengf49810c2009-06-23 17:48:47 +000063}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000064
Joel Jones96ef2842012-06-18 14:51:32 +000065// so_imm_notSext_XFORM - Return a so_imm value packed into the format
66// described for so_imm_notSext def below, with sign extension from 16
67// bits.
68def t2_so_imm_notSext16_XFORM : SDNodeXForm<imm, [{
69 APInt apIntN = N->getAPIntValue();
70 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
71 return CurDAG->getTargetConstant(~N16bitSignExt, MVT::i32);
72}]>;
73
Evan Chengf49810c2009-06-23 17:48:47 +000074// t2_so_imm - Match a 32-bit immediate operand, which is an
75// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
Bob Wilson09989942011-02-07 17:43:06 +000076// immediate splatted into multiple bytes of the word.
Jim Grosbach9588c102011-11-12 00:58:43 +000077def t2_so_imm_asmoperand : ImmAsmOperand { let Name = "T2SOImm"; }
Eli Friedmanc573e2c2011-04-29 22:48:03 +000078def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
79 return ARM_AM::getT2SOImmVal(Imm) != -1;
80 }]> {
Jim Grosbach6b8f1e32011-06-27 23:54:06 +000081 let ParserMatchClass = t2_so_imm_asmoperand;
Chris Lattner2ac19022010-11-15 05:19:05 +000082 let EncoderMethod = "getT2SOImmOpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +000083 let DecoderMethod = "DecodeT2SOImm";
Owen Anderson5de6d842010-11-12 21:12:40 +000084}
Anton Korobeynikov52237112009-06-17 18:13:58 +000085
Jim Grosbach64171712010-02-16 21:07:46 +000086// t2_so_imm_not - Match an immediate that is a complement
Evan Chengf49810c2009-06-23 17:48:47 +000087// of a t2_so_imm.
Jim Grosbach89a63372011-10-28 22:36:30 +000088// Note: this pattern doesn't require an encoder method and such, as it's
89// only used on aliases (Pat<> and InstAlias<>). The actual encoding
90// is handled by the destination instructions, which use t2_so_imm.
91def t2_so_imm_not_asmoperand : AsmOperandClass { let Name = "T2SOImmNot"; }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +000092def t2_so_imm_not : Operand<i32>, PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000093 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
Jim Grosbach89a63372011-10-28 22:36:30 +000094}], t2_so_imm_not_XFORM> {
95 let ParserMatchClass = t2_so_imm_not_asmoperand;
96}
Evan Chengf49810c2009-06-23 17:48:47 +000097
Joel Jones96ef2842012-06-18 14:51:32 +000098// t2_so_imm_notSext - match an immediate that is a complement of a t2_so_imm
99// if the upper 16 bits are zero.
100def t2_so_imm_notSext : Operand<i32>, PatLeaf<(imm), [{
101 APInt apIntN = N->getAPIntValue();
102 if (!apIntN.isIntN(16)) return false;
103 unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
104 return ARM_AM::getT2SOImmVal(~N16bitSignExt) != -1;
105 }], t2_so_imm_notSext16_XFORM> {
106 let ParserMatchClass = t2_so_imm_not_asmoperand;
107}
108
Evan Chengf49810c2009-06-23 17:48:47 +0000109// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000110def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; }
111def t2_so_imm_neg : Operand<i32>, PatLeaf<(imm), [{
Jim Grosbachb22e70d2012-03-29 21:19:52 +0000112 int64_t Value = -(int)N->getZExtValue();
113 return Value && ARM_AM::getT2SOImmVal(Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000114}], t2_so_imm_neg_XFORM> {
115 let ParserMatchClass = t2_so_imm_neg_asmoperand;
116}
Evan Chengf49810c2009-06-23 17:48:47 +0000117
118/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000119def imm0_4095_asmoperand: ImmAsmOperand { let Name = "Imm0_4095"; }
120def imm0_4095 : Operand<i32>, ImmLeaf<i32, [{
Eric Christopher8f232d32011-04-28 05:49:04 +0000121 return Imm >= 0 && Imm < 4096;
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000122}]> {
123 let ParserMatchClass = imm0_4095_asmoperand;
124}
Anton Korobeynikov52237112009-06-17 18:13:58 +0000125
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000126def imm0_4095_neg_asmoperand: AsmOperandClass { let Name = "Imm0_4095Neg"; }
127def imm0_4095_neg : Operand<i32>, PatLeaf<(i32 imm), [{
Jim Grosbach64171712010-02-16 21:07:46 +0000128 return (uint32_t)(-N->getZExtValue()) < 4096;
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000129}], imm_neg_XFORM> {
130 let ParserMatchClass = imm0_4095_neg_asmoperand;
131}
Anton Korobeynikov52237112009-06-17 18:13:58 +0000132
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000133def imm0_255_neg : PatLeaf<(i32 imm), [{
134 return (uint32_t)(-N->getZExtValue()) < 255;
Jim Grosbach64171712010-02-16 21:07:46 +0000135}], imm_neg_XFORM>;
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000136
Jim Grosbach502e0aa2010-07-14 17:45:16 +0000137def imm0_255_not : PatLeaf<(i32 imm), [{
138 return (uint32_t)(~N->getZExtValue()) < 255;
139}], imm_comp_XFORM>;
140
Andrew Trickd49ffe82011-04-29 14:18:15 +0000141def lo5AllOne : PatLeaf<(i32 imm), [{
142 // Returns true if all low 5-bits are 1.
143 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
144}]>;
145
Evan Cheng055b0312009-06-29 07:51:04 +0000146// Define Thumb2 specific addressing modes.
147
148// t2addrmode_imm12 := reg + imm12
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000149def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";}
Evan Cheng055b0312009-06-29 07:51:04 +0000150def t2addrmode_imm12 : Operand<i32>,
151 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000152 let PrintMethod = "printAddrModeImm12Operand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000153 let EncoderMethod = "getAddrModeImm12OpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000154 let DecoderMethod = "DecodeT2AddrModeImm12";
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000155 let ParserMatchClass = t2addrmode_imm12_asmoperand;
Evan Cheng055b0312009-06-29 07:51:04 +0000156 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
157}
158
Owen Andersonc9bd4962011-03-18 17:42:55 +0000159// t2ldrlabel := imm12
160def t2ldrlabel : Operand<i32> {
161 let EncoderMethod = "getAddrModeImm12OpValue";
Owen Andersone1368722011-09-21 23:44:46 +0000162 let PrintMethod = "printT2LdrLabelOperand";
Owen Andersonc9bd4962011-03-18 17:42:55 +0000163}
164
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000165def t2ldr_pcrel_imm12_asmoperand : AsmOperandClass {let Name = "MemPCRelImm12";}
166def t2ldr_pcrel_imm12 : Operand<i32> {
167 let ParserMatchClass = t2ldr_pcrel_imm12_asmoperand;
168 // used for assembler pseudo instruction and maps to t2ldrlabel, so
169 // doesn't need encoder or print methods of its own.
170}
Owen Andersonc9bd4962011-03-18 17:42:55 +0000171
Owen Andersona838a252010-12-14 00:36:49 +0000172// ADR instruction labels.
173def t2adrlabel : Operand<i32> {
174 let EncoderMethod = "getT2AdrLabelOpValue";
Jiangning Liu1fb27ec2012-08-02 08:13:13 +0000175 let PrintMethod = "printAdrLabelOperand";
Owen Andersona838a252010-12-14 00:36:49 +0000176}
177
178
Jim Grosbachf0eee6e2011-09-07 23:39:14 +0000179// t2addrmode_posimm8 := reg + imm8
180def MemPosImm8OffsetAsmOperand : AsmOperandClass {let Name="MemPosImm8Offset";}
181def t2addrmode_posimm8 : Operand<i32> {
182 let PrintMethod = "printT2AddrModeImm8Operand";
183 let EncoderMethod = "getT2AddrModeImm8OpValue";
184 let DecoderMethod = "DecodeT2AddrModeImm8";
185 let ParserMatchClass = MemPosImm8OffsetAsmOperand;
186 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
187}
188
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000189// t2addrmode_negimm8 := reg - imm8
190def MemNegImm8OffsetAsmOperand : AsmOperandClass {let Name="MemNegImm8Offset";}
191def t2addrmode_negimm8 : Operand<i32>,
192 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
193 let PrintMethod = "printT2AddrModeImm8Operand";
194 let EncoderMethod = "getT2AddrModeImm8OpValue";
195 let DecoderMethod = "DecodeT2AddrModeImm8";
196 let ParserMatchClass = MemNegImm8OffsetAsmOperand;
197 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
198}
199
Johnny Chen0635fc52010-03-04 17:40:44 +0000200// t2addrmode_imm8 := reg +/- imm8
Jim Grosbach7ce05792011-08-03 23:50:40 +0000201def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; }
Evan Cheng055b0312009-06-29 07:51:04 +0000202def t2addrmode_imm8 : Operand<i32>,
203 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
204 let PrintMethod = "printT2AddrModeImm8Operand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000205 let EncoderMethod = "getT2AddrModeImm8OpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000206 let DecoderMethod = "DecodeT2AddrModeImm8";
Jim Grosbach7ce05792011-08-03 23:50:40 +0000207 let ParserMatchClass = MemImm8OffsetAsmOperand;
Evan Cheng055b0312009-06-29 07:51:04 +0000208 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
209}
210
Evan Cheng6d94f112009-07-03 00:06:39 +0000211def t2am_imm8_offset : Operand<i32>,
Chris Lattner52a261b2010-09-21 20:31:19 +0000212 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
213 [], [SDNPWantRoot]> {
Evan Chenge88d5ce2009-07-02 07:28:31 +0000214 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000215 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000216 let DecoderMethod = "DecodeT2Imm8";
Evan Chenge88d5ce2009-07-02 07:28:31 +0000217}
218
Evan Cheng5c874172009-07-09 22:21:59 +0000219// t2addrmode_imm8s4 := reg +/- (imm8 << 2)
Jim Grosbacha77295d2011-09-08 22:07:06 +0000220def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";}
Chris Lattner979b0612010-09-05 22:51:11 +0000221def t2addrmode_imm8s4 : Operand<i32> {
Evan Cheng5c874172009-07-09 22:21:59 +0000222 let PrintMethod = "printT2AddrModeImm8s4Operand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000223 let EncoderMethod = "getT2AddrModeImm8s4OpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000224 let DecoderMethod = "DecodeT2AddrModeImm8s4";
Jim Grosbacha77295d2011-09-08 22:07:06 +0000225 let ParserMatchClass = MemImm8s4OffsetAsmOperand;
David Goodwin6647cea2009-06-30 22:50:01 +0000226 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
227}
228
Jim Grosbacha77295d2011-09-08 22:07:06 +0000229def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
Johnny Chenae1757b2010-03-11 01:13:36 +0000230def t2am_imm8s4_offset : Operand<i32> {
231 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
Jim Grosbacha77295d2011-09-08 22:07:06 +0000232 let EncoderMethod = "getT2Imm8s4OpValue";
Owen Anderson14c903a2011-08-04 23:18:05 +0000233 let DecoderMethod = "DecodeT2Imm8S4";
Johnny Chenae1757b2010-03-11 01:13:36 +0000234}
235
Jim Grosbachb6aed502011-09-09 18:37:27 +0000236// t2addrmode_imm0_1020s4 := reg + (imm8 << 2)
237def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
238 let Name = "MemImm0_1020s4Offset";
239}
240def t2addrmode_imm0_1020s4 : Operand<i32> {
241 let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
242 let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
243 let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
244 let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
245 let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
246}
247
Evan Chengcba962d2009-07-09 20:40:44 +0000248// t2addrmode_so_reg := reg + (reg << imm2)
Jim Grosbachab899c12011-09-07 23:10:15 +0000249def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
Evan Cheng055b0312009-06-29 07:51:04 +0000250def t2addrmode_so_reg : Operand<i32>,
251 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
252 let PrintMethod = "printT2AddrModeSoRegOperand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000253 let EncoderMethod = "getT2AddrModeSORegOpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000254 let DecoderMethod = "DecodeT2AddrModeSOReg";
Jim Grosbachab899c12011-09-07 23:10:15 +0000255 let ParserMatchClass = t2addrmode_so_reg_asmoperand;
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000256 let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
Evan Cheng055b0312009-06-29 07:51:04 +0000257}
258
Jim Grosbach7f739be2011-09-19 22:21:13 +0000259// Addresses for the TBB/TBH instructions.
260def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
261def addrmode_tbb : Operand<i32> {
262 let PrintMethod = "printAddrModeTBB";
263 let ParserMatchClass = addrmode_tbb_asmoperand;
264 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
265}
266def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
267def addrmode_tbh : Operand<i32> {
268 let PrintMethod = "printAddrModeTBH";
269 let ParserMatchClass = addrmode_tbh_asmoperand;
270 let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
271}
272
Anton Korobeynikov52237112009-06-17 18:13:58 +0000273//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000274// Multiclass helpers...
Anton Korobeynikov52237112009-06-17 18:13:58 +0000275//
276
Owen Andersona99e7782010-11-15 18:45:17 +0000277
278class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
Owen Anderson83da6cd2010-11-14 05:37:38 +0000279 string opc, string asm, list<dag> pattern>
280 : T2I<oops, iops, itin, opc, asm, pattern> {
281 bits<4> Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000282 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000283
Jim Grosbach86386922010-12-08 22:10:43 +0000284 let Inst{11-8} = Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000285 let Inst{26} = imm{11};
286 let Inst{14-12} = imm{10-8};
287 let Inst{7-0} = imm{7-0};
288}
289
Owen Andersonbb6315d2010-11-15 19:58:36 +0000290
Owen Andersona99e7782010-11-15 18:45:17 +0000291class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
292 string opc, string asm, list<dag> pattern>
293 : T2sI<oops, iops, itin, opc, asm, pattern> {
294 bits<4> Rd;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000295 bits<4> Rn;
296 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000297
Jim Grosbach86386922010-12-08 22:10:43 +0000298 let Inst{11-8} = Rd;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000299 let Inst{26} = imm{11};
300 let Inst{14-12} = imm{10-8};
301 let Inst{7-0} = imm{7-0};
302}
303
Owen Andersonbb6315d2010-11-15 19:58:36 +0000304class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
305 string opc, string asm, list<dag> pattern>
306 : T2I<oops, iops, itin, opc, asm, pattern> {
307 bits<4> Rn;
308 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000309
Jim Grosbach86386922010-12-08 22:10:43 +0000310 let Inst{19-16} = Rn;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000311 let Inst{26} = imm{11};
312 let Inst{14-12} = imm{10-8};
313 let Inst{7-0} = imm{7-0};
314}
315
316
Owen Andersona99e7782010-11-15 18:45:17 +0000317class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
318 string opc, string asm, list<dag> pattern>
319 : T2I<oops, iops, itin, opc, asm, pattern> {
320 bits<4> Rd;
321 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000322
Jim Grosbach86386922010-12-08 22:10:43 +0000323 let Inst{11-8} = Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000324 let Inst{3-0} = ShiftedRm{3-0};
325 let Inst{5-4} = ShiftedRm{6-5};
326 let Inst{14-12} = ShiftedRm{11-9};
327 let Inst{7-6} = ShiftedRm{8-7};
328}
329
330class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
331 string opc, string asm, list<dag> pattern>
Owen Andersonbdf71442010-12-07 20:50:15 +0000332 : T2sI<oops, iops, itin, opc, asm, pattern> {
Owen Andersona99e7782010-11-15 18:45:17 +0000333 bits<4> Rd;
334 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000335
Jim Grosbach86386922010-12-08 22:10:43 +0000336 let Inst{11-8} = Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000337 let Inst{3-0} = ShiftedRm{3-0};
338 let Inst{5-4} = ShiftedRm{6-5};
339 let Inst{14-12} = ShiftedRm{11-9};
340 let Inst{7-6} = ShiftedRm{8-7};
341}
342
Owen Andersonbb6315d2010-11-15 19:58:36 +0000343class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
344 string opc, string asm, list<dag> pattern>
345 : T2I<oops, iops, itin, opc, asm, pattern> {
346 bits<4> Rn;
347 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000348
Jim Grosbach86386922010-12-08 22:10:43 +0000349 let Inst{19-16} = Rn;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000350 let Inst{3-0} = ShiftedRm{3-0};
351 let Inst{5-4} = ShiftedRm{6-5};
352 let Inst{14-12} = ShiftedRm{11-9};
353 let Inst{7-6} = ShiftedRm{8-7};
354}
355
Owen Andersona99e7782010-11-15 18:45:17 +0000356class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
357 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000358 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Andersona99e7782010-11-15 18:45:17 +0000359 bits<4> Rd;
360 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000361
Jim Grosbach86386922010-12-08 22:10:43 +0000362 let Inst{11-8} = Rd;
363 let Inst{3-0} = Rm;
Owen Andersona99e7782010-11-15 18:45:17 +0000364}
365
366class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
367 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000368 : T2sI<oops, iops, itin, opc, asm, pattern> {
Owen Andersona99e7782010-11-15 18:45:17 +0000369 bits<4> Rd;
370 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000371
Jim Grosbach86386922010-12-08 22:10:43 +0000372 let Inst{11-8} = Rd;
373 let Inst{3-0} = Rm;
Owen Andersona99e7782010-11-15 18:45:17 +0000374}
375
Owen Andersonbb6315d2010-11-15 19:58:36 +0000376class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
377 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000378 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Andersonbb6315d2010-11-15 19:58:36 +0000379 bits<4> Rn;
380 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000381
Jim Grosbach86386922010-12-08 22:10:43 +0000382 let Inst{19-16} = Rn;
383 let Inst{3-0} = Rm;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000384}
385
Owen Andersona99e7782010-11-15 18:45:17 +0000386
387class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
388 string opc, string asm, list<dag> pattern>
389 : T2I<oops, iops, itin, opc, asm, pattern> {
390 bits<4> Rd;
Jim Grosbach07e9b262010-12-08 23:04:16 +0000391 bits<4> Rn;
Jim Grosbach20e0fa62010-12-08 23:24:29 +0000392 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000393
Jim Grosbach86386922010-12-08 22:10:43 +0000394 let Inst{11-8} = Rd;
Jim Grosbach20e0fa62010-12-08 23:24:29 +0000395 let Inst{19-16} = Rn;
396 let Inst{26} = imm{11};
397 let Inst{14-12} = imm{10-8};
398 let Inst{7-0} = imm{7-0};
Owen Andersona99e7782010-11-15 18:45:17 +0000399}
400
Owen Anderson83da6cd2010-11-14 05:37:38 +0000401class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
Owen Anderson5de6d842010-11-12 21:12:40 +0000402 string opc, string asm, list<dag> pattern>
403 : T2sI<oops, iops, itin, opc, asm, pattern> {
404 bits<4> Rd;
405 bits<4> Rn;
406 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000407
Jim Grosbach86386922010-12-08 22:10:43 +0000408 let Inst{11-8} = Rd;
409 let Inst{19-16} = Rn;
Owen Anderson5de6d842010-11-12 21:12:40 +0000410 let Inst{26} = imm{11};
411 let Inst{14-12} = imm{10-8};
412 let Inst{7-0} = imm{7-0};
413}
414
Owen Andersonbb6315d2010-11-15 19:58:36 +0000415class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
416 string opc, string asm, list<dag> pattern>
417 : T2I<oops, iops, itin, opc, asm, pattern> {
418 bits<4> Rd;
419 bits<4> Rm;
420 bits<5> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000421
Jim Grosbach86386922010-12-08 22:10:43 +0000422 let Inst{11-8} = Rd;
423 let Inst{3-0} = Rm;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000424 let Inst{14-12} = imm{4-2};
425 let Inst{7-6} = imm{1-0};
426}
427
428class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
429 string opc, string asm, list<dag> pattern>
430 : T2sI<oops, iops, itin, opc, asm, pattern> {
431 bits<4> Rd;
432 bits<4> Rm;
433 bits<5> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000434
Jim Grosbach86386922010-12-08 22:10:43 +0000435 let Inst{11-8} = Rd;
436 let Inst{3-0} = Rm;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000437 let Inst{14-12} = imm{4-2};
438 let Inst{7-6} = imm{1-0};
439}
440
Owen Anderson5de6d842010-11-12 21:12:40 +0000441class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
442 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000443 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson83da6cd2010-11-14 05:37:38 +0000444 bits<4> Rd;
445 bits<4> Rn;
446 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000447
Jim Grosbach86386922010-12-08 22:10:43 +0000448 let Inst{11-8} = Rd;
449 let Inst{19-16} = Rn;
450 let Inst{3-0} = Rm;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000451}
452
453class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
454 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000455 : T2sI<oops, iops, itin, opc, asm, pattern> {
Owen Anderson5de6d842010-11-12 21:12:40 +0000456 bits<4> Rd;
457 bits<4> Rn;
458 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000459
Jim Grosbach86386922010-12-08 22:10:43 +0000460 let Inst{11-8} = Rd;
461 let Inst{19-16} = Rn;
462 let Inst{3-0} = Rm;
Owen Anderson5de6d842010-11-12 21:12:40 +0000463}
464
465class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
466 string opc, string asm, list<dag> pattern>
Owen Anderson83da6cd2010-11-14 05:37:38 +0000467 : T2I<oops, iops, itin, opc, asm, pattern> {
468 bits<4> Rd;
469 bits<4> Rn;
470 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000471
Jim Grosbach86386922010-12-08 22:10:43 +0000472 let Inst{11-8} = Rd;
473 let Inst{19-16} = Rn;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000474 let Inst{3-0} = ShiftedRm{3-0};
475 let Inst{5-4} = ShiftedRm{6-5};
476 let Inst{14-12} = ShiftedRm{11-9};
477 let Inst{7-6} = ShiftedRm{8-7};
478}
479
480class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
481 string opc, string asm, list<dag> pattern>
Owen Anderson5de6d842010-11-12 21:12:40 +0000482 : T2sI<oops, iops, itin, opc, asm, pattern> {
483 bits<4> Rd;
484 bits<4> Rn;
485 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000486
Jim Grosbach86386922010-12-08 22:10:43 +0000487 let Inst{11-8} = Rd;
488 let Inst{19-16} = Rn;
Owen Anderson5de6d842010-11-12 21:12:40 +0000489 let Inst{3-0} = ShiftedRm{3-0};
490 let Inst{5-4} = ShiftedRm{6-5};
491 let Inst{14-12} = ShiftedRm{11-9};
492 let Inst{7-6} = ShiftedRm{8-7};
493}
494
Owen Anderson35141a92010-11-18 01:08:42 +0000495class T2FourReg<dag oops, dag iops, InstrItinClass itin,
496 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000497 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson35141a92010-11-18 01:08:42 +0000498 bits<4> Rd;
499 bits<4> Rn;
500 bits<4> Rm;
501 bits<4> Ra;
Jim Grosbach7a088642010-11-19 17:11:02 +0000502
Jim Grosbach86386922010-12-08 22:10:43 +0000503 let Inst{19-16} = Rn;
504 let Inst{15-12} = Ra;
505 let Inst{11-8} = Rd;
506 let Inst{3-0} = Rm;
Owen Anderson35141a92010-11-18 01:08:42 +0000507}
508
Jim Grosbach7c6d85a2010-12-08 22:38:41 +0000509class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
510 dag oops, dag iops, InstrItinClass itin,
511 string opc, string asm, list<dag> pattern>
Jim Grosbach52082042010-12-08 22:29:28 +0000512 : T2I<oops, iops, itin, opc, asm, pattern> {
513 bits<4> RdLo;
514 bits<4> RdHi;
515 bits<4> Rn;
516 bits<4> Rm;
517
Jim Grosbach7c6d85a2010-12-08 22:38:41 +0000518 let Inst{31-23} = 0b111110111;
519 let Inst{22-20} = opc22_20;
Jim Grosbach52082042010-12-08 22:29:28 +0000520 let Inst{19-16} = Rn;
521 let Inst{15-12} = RdLo;
522 let Inst{11-8} = RdHi;
Jim Grosbach7c6d85a2010-12-08 22:38:41 +0000523 let Inst{7-4} = opc7_4;
Jim Grosbach52082042010-12-08 22:29:28 +0000524 let Inst{3-0} = Rm;
525}
Arnold Schwaighofer67514e92012-09-04 14:37:49 +0000526class T2MlaLong<bits<3> opc22_20, bits<4> opc7_4,
527 dag oops, dag iops, InstrItinClass itin,
528 string opc, string asm, list<dag> pattern>
529 : T2I<oops, iops, itin, opc, asm, pattern> {
530 bits<4> RdLo;
531 bits<4> RdHi;
532 bits<4> Rn;
533 bits<4> Rm;
534
535 let Inst{31-23} = 0b111110111;
536 let Inst{22-20} = opc22_20;
537 let Inst{19-16} = Rn;
538 let Inst{15-12} = RdLo;
539 let Inst{11-8} = RdHi;
540 let Inst{7-4} = opc7_4;
541 let Inst{3-0} = Rm;
542}
Jim Grosbach52082042010-12-08 22:29:28 +0000543
Owen Anderson35141a92010-11-18 01:08:42 +0000544
Evan Chenga67efd12009-06-23 19:39:13 +0000545/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Bob Wilson4876bdb2010-05-25 04:43:08 +0000546/// binary operation that produces a value. These are predicable and can be
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000547/// changed to modify CPSR.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000548multiclass T2I_bin_irs<bits<4> opcod, string opc,
549 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000550 PatFrag opnode, bit Commutable = 0,
Jim Grosbachadf73662011-06-28 00:19:13 +0000551 string wide = ""> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000552 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000553 def ri : T2sTwoRegImm<
554 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
555 opc, "\t$Rd, $Rn, $imm",
556 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000557 let Inst{31-27} = 0b11110;
558 let Inst{25} = 0;
559 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000560 let Inst{15} = 0;
561 }
Evan Chenga67efd12009-06-23 19:39:13 +0000562 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000563 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
564 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
565 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000566 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000567 let Inst{31-27} = 0b11101;
568 let Inst{26-25} = 0b01;
569 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000570 let Inst{14-12} = 0b000; // imm3
571 let Inst{7-6} = 0b00; // imm2
572 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000573 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000574 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000575 def rs : T2sTwoRegShiftedReg<
576 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
577 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
578 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000579 let Inst{31-27} = 0b11101;
580 let Inst{26-25} = 0b01;
581 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000582 }
Jim Grosbachadf73662011-06-28 00:19:13 +0000583 // Assembly aliases for optional destination operand when it's the same
584 // as the source operand.
Jim Grosbacha33b31b2011-08-22 18:04:24 +0000585 def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000586 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn,
Jim Grosbachadf73662011-06-28 00:19:13 +0000587 t2_so_imm:$imm, pred:$p,
Jim Grosbacha33b31b2011-08-22 18:04:24 +0000588 cc_out:$s)>;
589 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000590 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn,
Jim Grosbachadf73662011-06-28 00:19:13 +0000591 rGPR:$Rm, pred:$p,
Jim Grosbacha33b31b2011-08-22 18:04:24 +0000592 cc_out:$s)>;
593 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000594 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn,
Jim Grosbachadf73662011-06-28 00:19:13 +0000595 t2_so_reg:$shift, pred:$p,
Jim Grosbacha33b31b2011-08-22 18:04:24 +0000596 cc_out:$s)>;
Bill Wendling4822bce2010-08-30 01:47:35 +0000597}
598
David Goodwin1f096272009-07-27 23:34:12 +0000599/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
Jim Grosbachadf73662011-06-28 00:19:13 +0000600// the ".w" suffix to indicate that they are wide.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000601multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
602 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000603 PatFrag opnode, bit Commutable = 0> :
604 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w"> {
Jim Grosbach9e931f62012-02-24 19:06:05 +0000605 // Assembler aliases w/ the ".w" suffix.
606 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rd, $Rn, $imm"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000607 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p,
608 cc_out:$s)>;
Jim Grosbach5c1ac552011-09-02 18:41:35 +0000609 // Assembler aliases w/o the ".w" suffix.
610 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000611 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
612 cc_out:$s)>;
Jim Grosbach5c1ac552011-09-02 18:41:35 +0000613 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000614 (!cast<Instruction>(NAME#"rs") rGPR:$Rd, rGPR:$Rn, t2_so_reg:$shift,
615 pred:$p, cc_out:$s)>;
Jim Grosbach5c1ac552011-09-02 18:41:35 +0000616
617 // and with the optional destination operand, too.
Jim Grosbach11d5dc32012-03-16 22:18:29 +0000618 def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rdn, $imm"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000619 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm,
620 pred:$p, cc_out:$s)>;
Jim Grosbach5c1ac552011-09-02 18:41:35 +0000621 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000622 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
623 cc_out:$s)>;
Jim Grosbach5c1ac552011-09-02 18:41:35 +0000624 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
Jim Grosbach5c6c1282012-08-02 21:50:41 +0000625 (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$shift,
626 pred:$p, cc_out:$s)>;
Jim Grosbach5c1ac552011-09-02 18:41:35 +0000627}
Bill Wendling1f7bf0e2010-08-29 03:55:31 +0000628
Evan Cheng1e249e32009-06-25 20:59:23 +0000629/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000630/// reversed. The 'rr' form is only defined for the disassembler; for codegen
631/// it is equivalent to the T2I_bin_irs counterpart.
632multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000633 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000634 def ri : T2sTwoRegImm<
635 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
636 opc, ".w\t$Rd, $Rn, $imm",
637 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000638 let Inst{31-27} = 0b11110;
639 let Inst{25} = 0;
640 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000641 let Inst{15} = 0;
642 }
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000643 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000644 def rr : T2sThreeReg<
645 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
646 opc, "\t$Rd, $Rn, $Rm",
Bob Wilson136e4912010-08-14 03:18:29 +0000647 [/* For disassembly only; pattern left blank */]> {
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000648 let Inst{31-27} = 0b11101;
649 let Inst{26-25} = 0b01;
650 let Inst{24-21} = opcod;
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000651 let Inst{14-12} = 0b000; // imm3
652 let Inst{7-6} = 0b00; // imm2
653 let Inst{5-4} = 0b00; // type
654 }
Evan Chengf49810c2009-06-23 17:48:47 +0000655 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000656 def rs : T2sTwoRegShiftedReg<
657 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
658 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
659 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000660 let Inst{31-27} = 0b11101;
661 let Inst{26-25} = 0b01;
662 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000663 }
Evan Chengf49810c2009-06-23 17:48:47 +0000664}
665
Evan Chenga67efd12009-06-23 19:39:13 +0000666/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000667/// instruction modifies the CPSR register.
Andrew Trick3be654f2011-09-21 02:20:46 +0000668///
669/// These opcodes will be converted to the real non-S opcodes by
670/// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
Andrew Trick90b7b122011-10-18 19:18:52 +0000671let hasPostISelHook = 1, Defs = [CPSR] in {
672multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
673 InstrItinClass iis, PatFrag opnode,
674 bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000675 // shifted imm
Andrew Trick90b7b122011-10-18 19:18:52 +0000676 def ri : t2PseudoInst<(outs rGPR:$Rd),
677 (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
678 4, iii,
679 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
680 t2_so_imm:$imm))]>;
Evan Chenga67efd12009-06-23 19:39:13 +0000681 // register
Andrew Trick90b7b122011-10-18 19:18:52 +0000682 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p),
683 4, iir,
684 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
685 rGPR:$Rm))]> {
686 let isCommutable = Commutable;
687 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000688 // shifted register
Andrew Trick90b7b122011-10-18 19:18:52 +0000689 def rs : t2PseudoInst<(outs rGPR:$Rd),
690 (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
691 4, iis,
692 [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
693 t2_so_reg:$ShiftedRm))]>;
694}
695}
696
697/// T2I_rbin_s_is - Same as T2I_bin_s_irs, except selection DAG
698/// operands are reversed.
699let hasPostISelHook = 1, Defs = [CPSR] in {
700multiclass T2I_rbin_s_is<PatFrag opnode> {
701 // shifted imm
702 def ri : t2PseudoInst<(outs rGPR:$Rd),
Jim Grosbachb551f0c2012-05-21 17:57:17 +0000703 (ins rGPR:$Rn, t2_so_imm:$imm, pred:$p),
Andrew Trick90b7b122011-10-18 19:18:52 +0000704 4, IIC_iALUi,
705 [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm,
Jim Grosbachb551f0c2012-05-21 17:57:17 +0000706 rGPR:$Rn))]>;
Andrew Trick90b7b122011-10-18 19:18:52 +0000707 // shifted register
708 def rs : t2PseudoInst<(outs rGPR:$Rd),
Jim Grosbachb551f0c2012-05-21 17:57:17 +0000709 (ins rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
Andrew Trick90b7b122011-10-18 19:18:52 +0000710 4, IIC_iALUsi,
711 [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm,
Jim Grosbachb551f0c2012-05-21 17:57:17 +0000712 rGPR:$Rn))]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000713}
714}
715
Evan Chenga67efd12009-06-23 19:39:13 +0000716/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
717/// patterns for a binary operation that produces a value.
Johnny Chend68e1192009-12-15 17:24:14 +0000718multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
719 bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000720 // shifted imm
Jim Grosbach663e3392010-08-30 19:49:58 +0000721 // The register-immediate version is re-materializable. This is useful
722 // in particular for taking the address of a local.
723 let isReMaterializable = 1 in {
Owen Anderson83da6cd2010-11-14 05:37:38 +0000724 def ri : T2sTwoRegImm<
Jim Grosbachb95ed6e2011-10-03 20:51:59 +0000725 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
726 opc, ".w\t$Rd, $Rn, $imm",
727 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000728 let Inst{31-27} = 0b11110;
729 let Inst{25} = 0;
730 let Inst{24} = 1;
731 let Inst{23-21} = op23_21;
Johnny Chend68e1192009-12-15 17:24:14 +0000732 let Inst{15} = 0;
733 }
Jim Grosbach663e3392010-08-30 19:49:58 +0000734 }
Evan Chengf49810c2009-06-23 17:48:47 +0000735 // 12-bit imm
Jim Grosbach07e9b262010-12-08 23:04:16 +0000736 def ri12 : T2I<
Jim Grosbachb95ed6e2011-10-03 20:51:59 +0000737 (outs GPRnopc:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
Owen Anderson83da6cd2010-11-14 05:37:38 +0000738 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +0000739 [(set GPRnopc:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> {
Jim Grosbach07e9b262010-12-08 23:04:16 +0000740 bits<4> Rd;
741 bits<4> Rn;
742 bits<12> imm;
Johnny Chend68e1192009-12-15 17:24:14 +0000743 let Inst{31-27} = 0b11110;
Jim Grosbach07e9b262010-12-08 23:04:16 +0000744 let Inst{26} = imm{11};
745 let Inst{25-24} = 0b10;
Johnny Chend68e1192009-12-15 17:24:14 +0000746 let Inst{23-21} = op23_21;
747 let Inst{20} = 0; // The S bit.
Jim Grosbach07e9b262010-12-08 23:04:16 +0000748 let Inst{19-16} = Rn;
Johnny Chend68e1192009-12-15 17:24:14 +0000749 let Inst{15} = 0;
Jim Grosbach07e9b262010-12-08 23:04:16 +0000750 let Inst{14-12} = imm{10-8};
751 let Inst{11-8} = Rd;
752 let Inst{7-0} = imm{7-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000753 }
Evan Chenga67efd12009-06-23 19:39:13 +0000754 // register
Jim Grosbachb95ed6e2011-10-03 20:51:59 +0000755 def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm),
756 IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm",
757 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000758 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000759 let Inst{31-27} = 0b11101;
760 let Inst{26-25} = 0b01;
761 let Inst{24} = 1;
762 let Inst{23-21} = op23_21;
Johnny Chend68e1192009-12-15 17:24:14 +0000763 let Inst{14-12} = 0b000; // imm3
764 let Inst{7-6} = 0b00; // imm2
765 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000766 }
Evan Chengf49810c2009-06-23 17:48:47 +0000767 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000768 def rs : T2sTwoRegShiftedReg<
Jim Grosbachb95ed6e2011-10-03 20:51:59 +0000769 (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
Owen Anderson83da6cd2010-11-14 05:37:38 +0000770 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +0000771 [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000772 let Inst{31-27} = 0b11101;
Johnny Chend68e1192009-12-15 17:24:14 +0000773 let Inst{26-25} = 0b01;
Johnny Chend248ffb2010-01-08 17:41:33 +0000774 let Inst{24} = 1;
Johnny Chend68e1192009-12-15 17:24:14 +0000775 let Inst{23-21} = op23_21;
Johnny Chend68e1192009-12-15 17:24:14 +0000776 }
Evan Chengf49810c2009-06-23 17:48:47 +0000777}
778
Jim Grosbach6935efc2009-11-24 00:20:27 +0000779/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000780/// for a binary operation that produces a value and use the carry
Jim Grosbach6935efc2009-11-24 00:20:27 +0000781/// bit. It's not predicable.
Evan Cheng342e3162011-08-30 01:34:54 +0000782let Defs = [CPSR], Uses = [CPSR] in {
Jim Grosbach80dc1162010-02-16 21:23:02 +0000783multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
784 bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000785 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000786 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
Owen Anderson5de6d842010-11-12 21:12:40 +0000787 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
Evan Cheng342e3162011-08-30 01:34:54 +0000788 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000789 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000790 let Inst{31-27} = 0b11110;
791 let Inst{25} = 0;
792 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000793 let Inst{15} = 0;
794 }
Evan Chenga67efd12009-06-23 19:39:13 +0000795 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000796 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
Owen Anderson5de6d842010-11-12 21:12:40 +0000797 opc, ".w\t$Rd, $Rn, $Rm",
Evan Cheng342e3162011-08-30 01:34:54 +0000798 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000799 Requires<[IsThumb2]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000800 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000801 let Inst{31-27} = 0b11101;
802 let Inst{26-25} = 0b01;
803 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000804 let Inst{14-12} = 0b000; // imm3
805 let Inst{7-6} = 0b00; // imm2
806 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000807 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000808 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000809 def rs : T2sTwoRegShiftedReg<
Jim Grosbach7a088642010-11-19 17:11:02 +0000810 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
Owen Anderson5de6d842010-11-12 21:12:40 +0000811 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
Evan Cheng342e3162011-08-30 01:34:54 +0000812 [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000813 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000814 let Inst{31-27} = 0b11101;
815 let Inst{26-25} = 0b01;
816 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000817 }
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000818}
Andrew Trick1c3af772011-04-23 03:55:32 +0000819}
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000820
Evan Chenga67efd12009-06-23 19:39:13 +0000821/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
822// rotate operation that produces a value.
Jim Grosbach9249ef32012-08-02 21:59:52 +0000823multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, PatFrag opnode> {
Evan Chenga67efd12009-06-23 19:39:13 +0000824 // 5-bit imm
Owen Andersonbb6315d2010-11-15 19:58:36 +0000825 def ri : T2sTwoRegShiftImm<
Owen Anderson6d746312011-08-08 20:42:17 +0000826 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
Owen Andersonbb6315d2010-11-15 19:58:36 +0000827 opc, ".w\t$Rd, $Rm, $imm",
Jim Grosbach70939ee2011-08-17 21:51:27 +0000828 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000829 let Inst{31-27} = 0b11101;
830 let Inst{26-21} = 0b010010;
831 let Inst{19-16} = 0b1111; // Rn
832 let Inst{5-4} = opcod;
833 }
Evan Chenga67efd12009-06-23 19:39:13 +0000834 // register
Owen Andersonbb6315d2010-11-15 19:58:36 +0000835 def rr : T2sThreeReg<
836 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
837 opc, ".w\t$Rd, $Rn, $Rm",
838 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000839 let Inst{31-27} = 0b11111;
840 let Inst{26-23} = 0b0100;
841 let Inst{22-21} = opcod;
842 let Inst{15-12} = 0b1111;
843 let Inst{7-4} = 0b0000;
844 }
Jim Grosbach5f25fb02011-09-02 21:28:54 +0000845
846 // Optional destination register
847 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
Jim Grosbach9249ef32012-08-02 21:59:52 +0000848 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
849 cc_out:$s)>;
Jim Grosbach5f25fb02011-09-02 21:28:54 +0000850 def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
Jim Grosbach9249ef32012-08-02 21:59:52 +0000851 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
852 cc_out:$s)>;
Jim Grosbach5f25fb02011-09-02 21:28:54 +0000853
854 // Assembler aliases w/o the ".w" suffix.
855 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
Jim Grosbach9249ef32012-08-02 21:59:52 +0000856 (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, ty:$imm, pred:$p,
857 cc_out:$s)>;
Jim Grosbach5f25fb02011-09-02 21:28:54 +0000858 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
Jim Grosbach9249ef32012-08-02 21:59:52 +0000859 (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
860 cc_out:$s)>;
Jim Grosbach5f25fb02011-09-02 21:28:54 +0000861
862 // and with the optional destination operand, too.
863 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
Jim Grosbach9249ef32012-08-02 21:59:52 +0000864 (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
865 cc_out:$s)>;
Jim Grosbach5f25fb02011-09-02 21:28:54 +0000866 def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
Jim Grosbach9249ef32012-08-02 21:59:52 +0000867 (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
868 cc_out:$s)>;
Evan Chenga67efd12009-06-23 19:39:13 +0000869}
Evan Chengf49810c2009-06-23 17:48:47 +0000870
Johnny Chend68e1192009-12-15 17:24:14 +0000871/// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
Evan Chenga67efd12009-06-23 19:39:13 +0000872/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000873/// a explicit result, only implicitly set CPSR.
Evan Cheng5d42c562010-09-29 00:49:25 +0000874multiclass T2I_cmp_irs<bits<4> opcod, string opc,
875 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
Jim Grosbach9249ef32012-08-02 21:59:52 +0000876 PatFrag opnode> {
Jim Grosbachef88a922011-09-06 21:44:58 +0000877let isCompare = 1, Defs = [CPSR] in {
Evan Chengf49810c2009-06-23 17:48:47 +0000878 // shifted imm
Owen Andersonbb6315d2010-11-15 19:58:36 +0000879 def ri : T2OneRegCmpImm<
Jim Grosbachef88a922011-09-06 21:44:58 +0000880 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), iii,
Owen Andersonbb6315d2010-11-15 19:58:36 +0000881 opc, ".w\t$Rn, $imm",
Jim Grosbachef88a922011-09-06 21:44:58 +0000882 [(opnode GPRnopc:$Rn, t2_so_imm:$imm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000883 let Inst{31-27} = 0b11110;
884 let Inst{25} = 0;
885 let Inst{24-21} = opcod;
886 let Inst{20} = 1; // The S bit.
887 let Inst{15} = 0;
888 let Inst{11-8} = 0b1111; // Rd
889 }
Evan Chenga67efd12009-06-23 19:39:13 +0000890 // register
Owen Andersonbb6315d2010-11-15 19:58:36 +0000891 def rr : T2TwoRegCmp<
Jim Grosbachef88a922011-09-06 21:44:58 +0000892 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), iir,
Owen Andersone732cb02011-08-23 17:37:32 +0000893 opc, ".w\t$Rn, $Rm",
Jim Grosbachef88a922011-09-06 21:44:58 +0000894 [(opnode GPRnopc:$Rn, rGPR:$Rm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000895 let Inst{31-27} = 0b11101;
896 let Inst{26-25} = 0b01;
897 let Inst{24-21} = opcod;
898 let Inst{20} = 1; // The S bit.
899 let Inst{14-12} = 0b000; // imm3
900 let Inst{11-8} = 0b1111; // Rd
901 let Inst{7-6} = 0b00; // imm2
902 let Inst{5-4} = 0b00; // type
903 }
Evan Chengf49810c2009-06-23 17:48:47 +0000904 // shifted register
Owen Andersonbb6315d2010-11-15 19:58:36 +0000905 def rs : T2OneRegCmpShiftedReg<
Jim Grosbachef88a922011-09-06 21:44:58 +0000906 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), iis,
Owen Andersonbb6315d2010-11-15 19:58:36 +0000907 opc, ".w\t$Rn, $ShiftedRm",
Jim Grosbachef88a922011-09-06 21:44:58 +0000908 [(opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000909 let Inst{31-27} = 0b11101;
910 let Inst{26-25} = 0b01;
911 let Inst{24-21} = opcod;
912 let Inst{20} = 1; // The S bit.
913 let Inst{11-8} = 0b1111; // Rd
914 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000915}
Jim Grosbachef88a922011-09-06 21:44:58 +0000916
917 // Assembler aliases w/o the ".w" suffix.
918 // No alias here for 'rr' version as not all instantiations of this
919 // multiclass want one (CMP in particular, does not).
920 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
Jim Grosbach9249ef32012-08-02 21:59:52 +0000921 (!cast<Instruction>(NAME#"ri") GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
Jim Grosbachef88a922011-09-06 21:44:58 +0000922 def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
Jim Grosbach9249ef32012-08-02 21:59:52 +0000923 (!cast<Instruction>(NAME#"rs") GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000924}
925
Evan Chengf3c21b82009-06-30 02:15:48 +0000926/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000927multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000928 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
929 PatFrag opnode> {
930 def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
Owen Anderson75579f72010-11-29 22:44:32 +0000931 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000932 [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]> {
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000933 bits<4> Rt;
934 bits<17> addr;
935 let Inst{31-25} = 0b1111100;
Johnny Chend68e1192009-12-15 17:24:14 +0000936 let Inst{24} = signed;
937 let Inst{23} = 1;
938 let Inst{22-21} = opcod;
939 let Inst{20} = 1; // load
Owen Anderson80dd3e02010-11-30 22:45:47 +0000940 let Inst{19-16} = addr{16-13}; // Rn
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000941 let Inst{15-12} = Rt;
Owen Anderson80dd3e02010-11-30 22:45:47 +0000942 let Inst{11-0} = addr{11-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +0000943 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000944 def i8 : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
Owen Anderson75579f72010-11-29 22:44:32 +0000945 opc, "\t$Rt, $addr",
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000946 [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]> {
947 bits<4> Rt;
948 bits<13> addr;
Johnny Chend68e1192009-12-15 17:24:14 +0000949 let Inst{31-27} = 0b11111;
950 let Inst{26-25} = 0b00;
951 let Inst{24} = signed;
952 let Inst{23} = 0;
953 let Inst{22-21} = opcod;
954 let Inst{20} = 1; // load
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000955 let Inst{19-16} = addr{12-9}; // Rn
956 let Inst{15-12} = Rt;
Johnny Chend68e1192009-12-15 17:24:14 +0000957 let Inst{11} = 1;
958 // Offset: index==TRUE, wback==FALSE
959 let Inst{10} = 1; // The P bit.
Owen Anderson75579f72010-11-29 22:44:32 +0000960 let Inst{9} = addr{8}; // U
Jim Grosbacha8307dd2011-09-07 20:58:57 +0000961 let Inst{8} = 0; // The W bit.
Owen Anderson75579f72010-11-29 22:44:32 +0000962 let Inst{7-0} = addr{7-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +0000963 }
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000964 def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
Owen Anderson75579f72010-11-29 22:44:32 +0000965 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000966 [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000967 let Inst{31-27} = 0b11111;
968 let Inst{26-25} = 0b00;
969 let Inst{24} = signed;
970 let Inst{23} = 0;
971 let Inst{22-21} = opcod;
972 let Inst{20} = 1; // load
973 let Inst{11-6} = 0b000000;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000974
Owen Anderson75579f72010-11-29 22:44:32 +0000975 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +0000976 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000977
Owen Anderson75579f72010-11-29 22:44:32 +0000978 bits<10> addr;
979 let Inst{19-16} = addr{9-6}; // Rn
980 let Inst{3-0} = addr{5-2}; // Rm
981 let Inst{5-4} = addr{1-0}; // imm
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000982
983 let DecoderMethod = "DecodeT2LoadShift";
Johnny Chend68e1192009-12-15 17:24:14 +0000984 }
Evan Chengbc7deb02010-11-03 05:14:24 +0000985
Jim Grosbach5aa53682012-01-18 22:04:42 +0000986 // pci variant is very similar to i12, but supports negative offsets
987 // from the PC.
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000988 def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
Owen Anderson971b83b2011-02-08 22:39:40 +0000989 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000990 [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> {
Owen Anderson971b83b2011-02-08 22:39:40 +0000991 let isReMaterializable = 1;
992 let Inst{31-27} = 0b11111;
993 let Inst{26-25} = 0b00;
994 let Inst{24} = signed;
995 let Inst{23} = ?; // add = (U == '1')
996 let Inst{22-21} = opcod;
997 let Inst{20} = 1; // load
998 let Inst{19-16} = 0b1111; // Rn
999 bits<4> Rt;
1000 bits<12> addr;
1001 let Inst{15-12} = Rt{3-0};
1002 let Inst{11-0} = addr{11-0};
1003 }
Evan Chengf3c21b82009-06-30 02:15:48 +00001004}
1005
David Goodwin73b8f162009-06-30 22:11:34 +00001006/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +00001007multiclass T2I_st<bits<2> opcod, string opc,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001008 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
1009 PatFrag opnode> {
1010 def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
Owen Anderson75579f72010-11-29 22:44:32 +00001011 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001012 [(opnode target:$Rt, t2addrmode_imm12:$addr)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001013 let Inst{31-27} = 0b11111;
1014 let Inst{26-23} = 0b0001;
1015 let Inst{22-21} = opcod;
1016 let Inst{20} = 0; // !load
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001017
Owen Anderson75579f72010-11-29 22:44:32 +00001018 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +00001019 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001020
Owen Anderson80dd3e02010-11-30 22:45:47 +00001021 bits<17> addr;
Johnny Chenf9ce2cb2011-04-12 18:48:00 +00001022 let addr{12} = 1; // add = TRUE
Owen Anderson80dd3e02010-11-30 22:45:47 +00001023 let Inst{19-16} = addr{16-13}; // Rn
1024 let Inst{23} = addr{12}; // U
1025 let Inst{11-0} = addr{11-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +00001026 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001027 def i8 : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
Owen Anderson75579f72010-11-29 22:44:32 +00001028 opc, "\t$Rt, $addr",
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001029 [(opnode target:$Rt, t2addrmode_negimm8:$addr)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001030 let Inst{31-27} = 0b11111;
1031 let Inst{26-23} = 0b0000;
1032 let Inst{22-21} = opcod;
1033 let Inst{20} = 0; // !load
1034 let Inst{11} = 1;
1035 // Offset: index==TRUE, wback==FALSE
1036 let Inst{10} = 1; // The P bit.
1037 let Inst{8} = 0; // The W bit.
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001038
Owen Anderson75579f72010-11-29 22:44:32 +00001039 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +00001040 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001041
Owen Anderson75579f72010-11-29 22:44:32 +00001042 bits<13> addr;
1043 let Inst{19-16} = addr{12-9}; // Rn
1044 let Inst{9} = addr{8}; // U
1045 let Inst{7-0} = addr{7-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +00001046 }
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001047 def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
Owen Anderson75579f72010-11-29 22:44:32 +00001048 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001049 [(opnode target:$Rt, t2addrmode_so_reg:$addr)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001050 let Inst{31-27} = 0b11111;
1051 let Inst{26-23} = 0b0000;
1052 let Inst{22-21} = opcod;
1053 let Inst{20} = 0; // !load
1054 let Inst{11-6} = 0b000000;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001055
Owen Anderson75579f72010-11-29 22:44:32 +00001056 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +00001057 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001058
Owen Anderson75579f72010-11-29 22:44:32 +00001059 bits<10> addr;
1060 let Inst{19-16} = addr{9-6}; // Rn
1061 let Inst{3-0} = addr{5-2}; // Rm
1062 let Inst{5-4} = addr{1-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +00001063 }
David Goodwin73b8f162009-06-30 22:11:34 +00001064}
1065
Evan Cheng0e55fd62010-09-30 01:08:25 +00001066/// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +00001067/// register and one whose operand is a register rotated by 8/16/24.
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001068class T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode>
1069 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
1070 opc, ".w\t$Rd, $Rm$rot",
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00001071 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
1072 Requires<[IsThumb2]> {
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001073 let Inst{31-27} = 0b11111;
1074 let Inst{26-23} = 0b0100;
1075 let Inst{22-20} = opcod;
1076 let Inst{19-16} = 0b1111; // Rn
1077 let Inst{15-12} = 0b1111;
1078 let Inst{7} = 1;
Jim Grosbach7a088642010-11-19 17:11:02 +00001079
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001080 bits<2> rot;
1081 let Inst{5-4} = rot{1-0}; // rotate
Evan Chengd27c9fc2009-07-03 01:43:10 +00001082}
1083
Eli Friedman761fa7a2010-06-24 18:20:04 +00001084// UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
Jim Grosbach70327412011-07-27 17:48:13 +00001085class T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode>
Owen Andersone732cb02011-08-23 17:37:32 +00001086 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot),
1087 IIC_iEXTr, opc, "\t$Rd, $Rm$rot",
1088 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
Jim Grosbach70327412011-07-27 17:48:13 +00001089 Requires<[HasT2ExtractPack, IsThumb2]> {
1090 bits<2> rot;
1091 let Inst{31-27} = 0b11111;
1092 let Inst{26-23} = 0b0100;
1093 let Inst{22-20} = opcod;
1094 let Inst{19-16} = 0b1111; // Rn
1095 let Inst{15-12} = 0b1111;
1096 let Inst{7} = 1;
1097 let Inst{5-4} = rot;
Johnny Chen267124c2010-03-04 22:24:41 +00001098}
1099
Eli Friedman761fa7a2010-06-24 18:20:04 +00001100// SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
1101// supported yet.
Jim Grosbach70327412011-07-27 17:48:13 +00001102class T2I_ext_rrot_sxtb16<bits<3> opcod, string opc>
1103 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
1104 opc, "\t$Rd, $Rm$rot", []>,
Jim Grosbacha7603982011-07-01 21:12:19 +00001105 Requires<[IsThumb2, HasT2ExtractPack]> {
Jim Grosbach70327412011-07-27 17:48:13 +00001106 bits<2> rot;
1107 let Inst{31-27} = 0b11111;
1108 let Inst{26-23} = 0b0100;
1109 let Inst{22-20} = opcod;
1110 let Inst{19-16} = 0b1111; // Rn
1111 let Inst{15-12} = 0b1111;
1112 let Inst{7} = 1;
1113 let Inst{5-4} = rot;
Johnny Chen93042d12010-03-02 18:14:57 +00001114}
1115
Evan Cheng0e55fd62010-09-30 01:08:25 +00001116/// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +00001117/// register and one whose operand is a register rotated by 8/16/24.
Jim Grosbach70327412011-07-27 17:48:13 +00001118class T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode>
1119 : T2ThreeReg<(outs rGPR:$Rd),
1120 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1121 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot",
1122 [(set rGPR:$Rd, (opnode rGPR:$Rn, (rotr rGPR:$Rm,rot_imm:$rot)))]>,
1123 Requires<[HasT2ExtractPack, IsThumb2]> {
1124 bits<2> rot;
1125 let Inst{31-27} = 0b11111;
1126 let Inst{26-23} = 0b0100;
1127 let Inst{22-20} = opcod;
1128 let Inst{15-12} = 0b1111;
1129 let Inst{7} = 1;
1130 let Inst{5-4} = rot;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001131}
1132
Jim Grosbach70327412011-07-27 17:48:13 +00001133class T2I_exta_rrot_np<bits<3> opcod, string opc>
1134 : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm,rot_imm:$rot),
1135 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []> {
1136 bits<2> rot;
1137 let Inst{31-27} = 0b11111;
1138 let Inst{26-23} = 0b0100;
1139 let Inst{22-20} = opcod;
1140 let Inst{15-12} = 0b1111;
1141 let Inst{7} = 1;
1142 let Inst{5-4} = rot;
Johnny Chen93042d12010-03-02 18:14:57 +00001143}
1144
Anton Korobeynikov52237112009-06-17 18:13:58 +00001145//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +00001146// Instructions
1147//===----------------------------------------------------------------------===//
1148
1149//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +00001150// Miscellaneous Instructions.
1151//
1152
Owen Andersonda663f72010-11-15 21:30:39 +00001153class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1154 string asm, list<dag> pattern>
1155 : T2XI<oops, iops, itin, asm, pattern> {
1156 bits<4> Rd;
1157 bits<12> label;
Jim Grosbach7a088642010-11-19 17:11:02 +00001158
Jim Grosbach86386922010-12-08 22:10:43 +00001159 let Inst{11-8} = Rd;
Owen Andersonda663f72010-11-15 21:30:39 +00001160 let Inst{26} = label{11};
1161 let Inst{14-12} = label{10-8};
1162 let Inst{7-0} = label{7-0};
1163}
1164
Evan Chenga09b9ca2009-06-24 23:47:58 +00001165// LEApcrel - Load a pc-relative address into a register without offending the
1166// assembler.
Owen Andersona838a252010-12-14 00:36:49 +00001167def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1168 (ins t2adrlabel:$addr, pred:$p),
Owen Anderson08fef882011-09-09 22:24:36 +00001169 IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001170 let Inst{31-27} = 0b11110;
1171 let Inst{25-24} = 0b10;
1172 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1173 let Inst{22} = 0;
1174 let Inst{20} = 0;
1175 let Inst{19-16} = 0b1111; // Rn
1176 let Inst{15} = 0;
Jim Grosbach00f25fa2010-12-14 20:46:39 +00001177
Owen Andersona838a252010-12-14 00:36:49 +00001178 bits<4> Rd;
1179 bits<13> addr;
1180 let Inst{11-8} = Rd;
1181 let Inst{23} = addr{12};
1182 let Inst{21} = addr{12};
1183 let Inst{26} = addr{11};
1184 let Inst{14-12} = addr{10-8};
1185 let Inst{7-0} = addr{7-0};
Owen Anderson08fef882011-09-09 22:24:36 +00001186
1187 let DecoderMethod = "DecodeT2Adr";
Owen Anderson6b8719f2010-12-13 22:51:08 +00001188}
Owen Andersona838a252010-12-14 00:36:49 +00001189
1190let neverHasSideEffects = 1, isReMaterializable = 1 in
Jim Grosbach41b1d4e2010-12-15 18:48:45 +00001191def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001192 4, IIC_iALUi, []>;
Jakob Stoklund Olesen7778ee12012-08-24 21:44:11 +00001193let hasSideEffects = 1 in
Jim Grosbach41b1d4e2010-12-15 18:48:45 +00001194def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1195 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001196 4, IIC_iALUi,
Jim Grosbach41b1d4e2010-12-15 18:48:45 +00001197 []>;
Evan Chenga09b9ca2009-06-24 23:47:58 +00001198
Jim Grosbach60fc2ed2010-12-08 23:30:19 +00001199
Evan Chenga09b9ca2009-06-24 23:47:58 +00001200//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +00001201// Load / store Instructions.
1202//
1203
Evan Cheng055b0312009-06-29 07:51:04 +00001204// Load
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001205let canFoldAsLoad = 1, isReMaterializable = 1 in
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001206defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001207 UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001208
Evan Chengf3c21b82009-06-30 02:15:48 +00001209// Loads with zero extension
Evan Cheng7e2fe912010-10-28 06:47:08 +00001210defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001211 rGPR, UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001212defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001213 rGPR, UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001214
Evan Chengf3c21b82009-06-30 02:15:48 +00001215// Loads with sign extension
Evan Cheng7e2fe912010-10-28 06:47:08 +00001216defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001217 rGPR, UnOpFrag<(sextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001218defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001219 rGPR, UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001220
Owen Anderson9d63d902010-12-01 19:18:46 +00001221let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
Evan Chengf3c21b82009-06-30 02:15:48 +00001222// Load doubleword
Owen Anderson9d63d902010-12-01 19:18:46 +00001223def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
Evan Chenge298ab22009-09-27 09:46:04 +00001224 (ins t2addrmode_imm8s4:$addr),
Jim Grosbacha77295d2011-09-08 22:07:06 +00001225 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "", []>;
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001226} // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
Evan Chengf3c21b82009-06-30 02:15:48 +00001227
1228// zextload i1 -> zextload i8
1229def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1230 (t2LDRBi12 t2addrmode_imm12:$addr)>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001231def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
1232 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
Evan Chengf3c21b82009-06-30 02:15:48 +00001233def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1234 (t2LDRBs t2addrmode_so_reg:$addr)>;
1235def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1236 (t2LDRBpci tconstpool:$addr)>;
1237
1238// extload -> zextload
1239// FIXME: Reduce the number of patterns by legalizing extload to zextload
1240// earlier?
1241def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1242 (t2LDRBi12 t2addrmode_imm12:$addr)>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001243def : T2Pat<(extloadi1 t2addrmode_negimm8:$addr),
1244 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
Evan Chengf3c21b82009-06-30 02:15:48 +00001245def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1246 (t2LDRBs t2addrmode_so_reg:$addr)>;
1247def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1248 (t2LDRBpci tconstpool:$addr)>;
1249
1250def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1251 (t2LDRBi12 t2addrmode_imm12:$addr)>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001252def : T2Pat<(extloadi8 t2addrmode_negimm8:$addr),
1253 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
Evan Chengf3c21b82009-06-30 02:15:48 +00001254def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1255 (t2LDRBs t2addrmode_so_reg:$addr)>;
1256def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1257 (t2LDRBpci tconstpool:$addr)>;
1258
1259def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1260 (t2LDRHi12 t2addrmode_imm12:$addr)>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001261def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
1262 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
Evan Chengf3c21b82009-06-30 02:15:48 +00001263def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1264 (t2LDRHs t2addrmode_so_reg:$addr)>;
1265def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1266 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +00001267
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001268// FIXME: The destination register of the loads and stores can't be PC, but
1269// can be SP. We need another regclass (similar to rGPR) to represent
1270// that. Not a pressing issue since these are selected manually,
1271// not via pattern.
1272
Evan Chenge88d5ce2009-07-02 07:28:31 +00001273// Indexed loads
Owen Anderson6af50f72010-11-30 00:14:31 +00001274
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001275let mayLoad = 1, neverHasSideEffects = 1 in {
Jim Grosbacheeec0252011-09-08 00:39:19 +00001276def t2LDR_PRE : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001277 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001278 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
Jim Grosbacheeec0252011-09-08 00:39:19 +00001279 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1280 []> {
1281 let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1282}
Evan Chenge88d5ce2009-07-02 07:28:31 +00001283
Jim Grosbacheeec0252011-09-08 00:39:19 +00001284def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
Jim Grosbache64fb282011-09-08 01:01:32 +00001285 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1286 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
Owen Anderson0781c1f2011-09-23 21:26:40 +00001287 "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001288
Jim Grosbacheeec0252011-09-08 00:39:19 +00001289def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001290 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001291 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Jim Grosbacheeec0252011-09-08 00:39:19 +00001292 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1293 []> {
1294 let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1295}
1296def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
Jim Grosbache64fb282011-09-08 01:01:32 +00001297 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1298 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Owen Anderson0781c1f2011-09-23 21:26:40 +00001299 "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001300
Jim Grosbacheeec0252011-09-08 00:39:19 +00001301def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001302 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001303 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Jim Grosbacheeec0252011-09-08 00:39:19 +00001304 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1305 []> {
1306 let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1307}
1308def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
Jim Grosbache64fb282011-09-08 01:01:32 +00001309 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1310 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Owen Anderson0781c1f2011-09-23 21:26:40 +00001311 "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001312
Jim Grosbacheeec0252011-09-08 00:39:19 +00001313def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001314 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001315 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Jim Grosbacheeec0252011-09-08 00:39:19 +00001316 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1317 []> {
1318 let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1319}
1320def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
Jim Grosbache64fb282011-09-08 01:01:32 +00001321 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1322 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Owen Anderson0781c1f2011-09-23 21:26:40 +00001323 "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
Evan Cheng4fbb9962009-07-02 23:16:11 +00001324
Jim Grosbacheeec0252011-09-08 00:39:19 +00001325def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001326 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001327 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Jim Grosbacheeec0252011-09-08 00:39:19 +00001328 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
1329 []> {
1330 let AsmMatchConverter = "cvtLdWriteBackRegT2AddrModeImm8";
1331}
1332def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
Jim Grosbache64fb282011-09-08 01:01:32 +00001333 (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
1334 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Owen Anderson0781c1f2011-09-23 21:26:40 +00001335 "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
Jim Grosbach7a088642010-11-19 17:11:02 +00001336} // mayLoad = 1, neverHasSideEffects = 1
Evan Cheng4fbb9962009-07-02 23:16:11 +00001337
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001338// LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
Johnny Chene54a3ef2010-03-03 18:45:36 +00001339// Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001340class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001341 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001342 "\t$Rt, $addr", []> {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001343 bits<4> Rt;
1344 bits<13> addr;
Johnny Chene54a3ef2010-03-03 18:45:36 +00001345 let Inst{31-27} = 0b11111;
1346 let Inst{26-25} = 0b00;
1347 let Inst{24} = signed;
1348 let Inst{23} = 0;
1349 let Inst{22-21} = type;
1350 let Inst{20} = 1; // load
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001351 let Inst{19-16} = addr{12-9};
1352 let Inst{15-12} = Rt;
Johnny Chene54a3ef2010-03-03 18:45:36 +00001353 let Inst{11} = 1;
1354 let Inst{10-8} = 0b110; // PUW.
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001355 let Inst{7-0} = addr{7-0};
Johnny Chene54a3ef2010-03-03 18:45:36 +00001356}
1357
Evan Cheng0e55fd62010-09-30 01:08:25 +00001358def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1359def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1360def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1361def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1362def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
Johnny Chene54a3ef2010-03-03 18:45:36 +00001363
David Goodwin73b8f162009-06-30 22:11:34 +00001364// Store
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001365defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001366 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001367defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001368 rGPR, BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001369defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001370 rGPR, BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
David Goodwin73b8f162009-06-30 22:11:34 +00001371
David Goodwin6647cea2009-06-30 22:50:01 +00001372// Store doubleword
Cameron Zwarichd5751372011-10-16 06:38:06 +00001373let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
Johnny Chend68e1192009-12-15 17:24:14 +00001374def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
Owen Anderson9d63d902010-12-01 19:18:46 +00001375 (ins GPR:$Rt, GPR:$Rt2, t2addrmode_imm8s4:$addr),
Jim Grosbacha77295d2011-09-08 22:07:06 +00001376 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "", []>;
David Goodwin6647cea2009-06-30 22:50:01 +00001377
Evan Cheng6d94f112009-07-03 00:06:39 +00001378// Indexed stores
Cameron Zwarichdaada342011-10-16 06:38:10 +00001379
1380let mayStore = 1, neverHasSideEffects = 1 in {
Jim Grosbacheeec0252011-09-08 00:39:19 +00001381def t2STR_PRE : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
Jim Grosbachb0659872011-12-13 21:10:25 +00001382 (ins GPRnopc:$Rt, t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001383 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Jim Grosbachee2c2a42011-09-16 21:55:56 +00001384 "str", "\t$Rt, $addr!",
1385 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1386 let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1387}
1388def t2STRH_PRE : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
1389 (ins rGPR:$Rt, t2addrmode_imm8:$addr),
1390 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
1391 "strh", "\t$Rt, $addr!",
1392 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1393 let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1394}
1395
1396def t2STRB_PRE : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
1397 (ins rGPR:$Rt, t2addrmode_imm8:$addr),
1398 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
1399 "strb", "\t$Rt, $addr!",
1400 "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []> {
1401 let AsmMatchConverter = "cvtStWriteBackRegT2AddrModeImm8";
1402}
Eli Friedman0851a292011-10-18 03:17:34 +00001403} // mayStore = 1, neverHasSideEffects = 1
Evan Cheng6d94f112009-07-03 00:06:39 +00001404
Jim Grosbacheeec0252011-09-08 00:39:19 +00001405def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
Jim Grosbachb0659872011-12-13 21:10:25 +00001406 (ins GPRnopc:$Rt, addr_offset_none:$Rn,
Jim Grosbach947a24c2011-09-16 21:09:00 +00001407 t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001408 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
Owen Anderson0781c1f2011-09-23 21:26:40 +00001409 "str", "\t$Rt, $Rn$offset",
Jim Grosbacheeec0252011-09-08 00:39:19 +00001410 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1411 [(set GPRnopc:$Rn_wb,
Jim Grosbachb0659872011-12-13 21:10:25 +00001412 (post_store GPRnopc:$Rt, addr_offset_none:$Rn,
Jim Grosbach947a24c2011-09-16 21:09:00 +00001413 t2am_imm8_offset:$offset))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001414
Jim Grosbacheeec0252011-09-08 00:39:19 +00001415def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
Jim Grosbach947a24c2011-09-16 21:09:00 +00001416 (ins rGPR:$Rt, addr_offset_none:$Rn,
1417 t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001418 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Owen Anderson0781c1f2011-09-23 21:26:40 +00001419 "strh", "\t$Rt, $Rn$offset",
Jim Grosbacheeec0252011-09-08 00:39:19 +00001420 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1421 [(set GPRnopc:$Rn_wb,
Jim Grosbach947a24c2011-09-16 21:09:00 +00001422 (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
1423 t2am_imm8_offset:$offset))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001424
Jim Grosbacheeec0252011-09-08 00:39:19 +00001425def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
Jim Grosbach947a24c2011-09-16 21:09:00 +00001426 (ins rGPR:$Rt, addr_offset_none:$Rn,
1427 t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001428 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Owen Anderson0781c1f2011-09-23 21:26:40 +00001429 "strb", "\t$Rt, $Rn$offset",
Jim Grosbacheeec0252011-09-08 00:39:19 +00001430 "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
1431 [(set GPRnopc:$Rn_wb,
Jim Grosbach947a24c2011-09-16 21:09:00 +00001432 (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
1433 t2am_imm8_offset:$offset))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001434
Jim Grosbachee2c2a42011-09-16 21:55:56 +00001435// Pseudo-instructions for pattern matching the pre-indexed stores. We can't
1436// put the patterns on the instruction definitions directly as ISel wants
1437// the address base and offset to be separate operands, not a single
1438// complex operand like we represent the instructions themselves. The
1439// pseudos map between the two.
1440let usesCustomInserter = 1,
1441 Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
1442def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1443 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1444 4, IIC_iStore_ru,
1445 [(set GPRnopc:$Rn_wb,
1446 (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1447def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1448 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1449 4, IIC_iStore_ru,
1450 [(set GPRnopc:$Rn_wb,
1451 (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1452def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
1453 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
1454 4, IIC_iStore_ru,
1455 [(set GPRnopc:$Rn_wb,
1456 (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
1457}
Jim Grosbachee2c2a42011-09-16 21:55:56 +00001458
Johnny Chene54a3ef2010-03-03 18:45:36 +00001459// STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1460// only.
1461// Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001462class T2IstT<bits<2> type, string opc, InstrItinClass ii>
Johnny Chen471d73d2011-04-13 21:04:32 +00001463 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001464 "\t$Rt, $addr", []> {
Johnny Chene54a3ef2010-03-03 18:45:36 +00001465 let Inst{31-27} = 0b11111;
1466 let Inst{26-25} = 0b00;
1467 let Inst{24} = 0; // not signed
1468 let Inst{23} = 0;
1469 let Inst{22-21} = type;
1470 let Inst{20} = 0; // store
1471 let Inst{11} = 1;
1472 let Inst{10-8} = 0b110; // PUW
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001473
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001474 bits<4> Rt;
1475 bits<13> addr;
Jim Grosbach86386922010-12-08 22:10:43 +00001476 let Inst{15-12} = Rt;
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001477 let Inst{19-16} = addr{12-9};
1478 let Inst{7-0} = addr{7-0};
Johnny Chene54a3ef2010-03-03 18:45:36 +00001479}
1480
Evan Cheng0e55fd62010-09-30 01:08:25 +00001481def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1482def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1483def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
David Goodwind1fa1202009-07-01 00:01:13 +00001484
Johnny Chenae1757b2010-03-11 01:13:36 +00001485// ldrd / strd pre / post variants
1486// For disassembly only.
1487
Jim Grosbacha77295d2011-09-08 22:07:06 +00001488def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1489 (ins t2addrmode_imm8s4:$addr), IIC_iLoad_d_ru,
1490 "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []> {
1491 let AsmMatchConverter = "cvtT2LdrdPre";
1492 let DecoderMethod = "DecodeT2LDRDPreInstruction";
1493}
Johnny Chenae1757b2010-03-11 01:13:36 +00001494
Jim Grosbacha77295d2011-09-08 22:07:06 +00001495def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
1496 (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
Owen Anderson7782a582011-09-13 20:46:26 +00001497 IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
Jim Grosbacha77295d2011-09-08 22:07:06 +00001498 "$addr.base = $wb", []>;
Johnny Chenae1757b2010-03-11 01:13:36 +00001499
Jim Grosbacha77295d2011-09-08 22:07:06 +00001500def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
1501 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
1502 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
1503 "$addr.base = $wb", []> {
1504 let AsmMatchConverter = "cvtT2StrdPre";
1505 let DecoderMethod = "DecodeT2STRDPreInstruction";
1506}
Johnny Chenae1757b2010-03-11 01:13:36 +00001507
Jim Grosbacha77295d2011-09-08 22:07:06 +00001508def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
1509 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
1510 t2am_imm8s4_offset:$imm),
Owen Anderson7782a582011-09-13 20:46:26 +00001511 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
Jim Grosbacha77295d2011-09-08 22:07:06 +00001512 "$addr.base = $wb", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +00001513
Johnny Chen0635fc52010-03-04 17:40:44 +00001514// T2Ipl (Preload Data/Instruction) signals the memory system of possible future
Jim Grosbacha5813282011-10-26 22:22:01 +00001515// data/instruction access.
Evan Chengdfed19f2010-11-03 06:34:55 +00001516// instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1517// (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
Evan Cheng416941d2010-11-04 05:19:35 +00001518multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001519
Evan Chengdfed19f2010-11-03 06:34:55 +00001520 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001521 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001522 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001523 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001524 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001525 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001526 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001527 let Inst{20} = 1;
1528 let Inst{15-12} = 0b1111;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001529
Owen Anderson80dd3e02010-11-30 22:45:47 +00001530 bits<17> addr;
Johnny Chenf9ce2cb2011-04-12 18:48:00 +00001531 let addr{12} = 1; // add = TRUE
Owen Anderson80dd3e02010-11-30 22:45:47 +00001532 let Inst{19-16} = addr{16-13}; // Rn
1533 let Inst{23} = addr{12}; // U
Owen Anderson0e1bcdf2010-11-30 19:19:31 +00001534 let Inst{11-0} = addr{11-0}; // imm12
Johnny Chen0635fc52010-03-04 17:40:44 +00001535 }
1536
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001537 def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001538 "\t$addr",
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001539 [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001540 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001541 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001542 let Inst{23} = 0; // U = 0
1543 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001544 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001545 let Inst{20} = 1;
1546 let Inst{15-12} = 0b1111;
1547 let Inst{11-8} = 0b1100;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001548
Owen Anderson0e1bcdf2010-11-30 19:19:31 +00001549 bits<13> addr;
1550 let Inst{19-16} = addr{12-9}; // Rn
1551 let Inst{7-0} = addr{7-0}; // imm8
Johnny Chen0635fc52010-03-04 17:40:44 +00001552 }
1553
Evan Chengdfed19f2010-11-03 06:34:55 +00001554 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001555 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001556 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
Evan Chengbc7deb02010-11-03 05:14:24 +00001557 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001558 let Inst{24} = instr;
Evan Chengbc7deb02010-11-03 05:14:24 +00001559 let Inst{23} = 0; // add = TRUE for T1
1560 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001561 let Inst{21} = write;
Evan Chengbc7deb02010-11-03 05:14:24 +00001562 let Inst{20} = 1;
1563 let Inst{15-12} = 0b1111;
1564 let Inst{11-6} = 0000000;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001565
Owen Anderson0e1bcdf2010-11-30 19:19:31 +00001566 bits<10> addr;
1567 let Inst{19-16} = addr{9-6}; // Rn
1568 let Inst{3-0} = addr{5-2}; // Rm
1569 let Inst{5-4} = addr{1-0}; // imm2
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001570
1571 let DecoderMethod = "DecodeT2LoadShift";
Evan Chengbc7deb02010-11-03 05:14:24 +00001572 }
Jim Grosbacha5813282011-10-26 22:22:01 +00001573 // FIXME: We should have a separate 'pci' variant here. As-is we represent
1574 // it via the i12 variant, which it's related to, but that means we can
1575 // represent negative immediates, which aren't legal for anything except
1576 // the 'pci' case (Rn == 15).
Johnny Chen0635fc52010-03-04 17:40:44 +00001577}
1578
Evan Cheng416941d2010-11-04 05:19:35 +00001579defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1580defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1581defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
Johnny Chen0635fc52010-03-04 17:40:44 +00001582
Evan Cheng2889cce2009-07-03 00:18:36 +00001583//===----------------------------------------------------------------------===//
1584// Load / store multiple Instructions.
1585//
1586
Owen Andersoncd00dc62011-09-12 21:28:46 +00001587multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
Bill Wendling6c470b82010-11-13 09:09:38 +00001588 InstrItinClass itin_upd, bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +00001589 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +00001590 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Jim Grosbachffa5a762011-09-07 16:22:42 +00001591 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
Bill Wendling6c470b82010-11-13 09:09:38 +00001592 bits<4> Rn;
1593 bits<16> regs;
Jim Grosbach7a088642010-11-19 17:11:02 +00001594
Bill Wendling6c470b82010-11-13 09:09:38 +00001595 let Inst{31-27} = 0b11101;
1596 let Inst{26-25} = 0b00;
1597 let Inst{24-23} = 0b01; // Increment After
1598 let Inst{22} = 0;
1599 let Inst{21} = 0; // No writeback
1600 let Inst{20} = L_bit;
1601 let Inst{19-16} = Rn;
Jim Grosbachf8e74f82011-10-24 17:16:24 +00001602 let Inst{15-0} = regs;
Bill Wendling6c470b82010-11-13 09:09:38 +00001603 }
Bill Wendling73fe34a2010-11-16 01:16:36 +00001604 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001605 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Jim Grosbachffa5a762011-09-07 16:22:42 +00001606 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
Bill Wendling6c470b82010-11-13 09:09:38 +00001607 bits<4> Rn;
1608 bits<16> regs;
Jim Grosbach7a088642010-11-19 17:11:02 +00001609
Bill Wendling6c470b82010-11-13 09:09:38 +00001610 let Inst{31-27} = 0b11101;
1611 let Inst{26-25} = 0b00;
1612 let Inst{24-23} = 0b01; // Increment After
1613 let Inst{22} = 0;
1614 let Inst{21} = 1; // Writeback
1615 let Inst{20} = L_bit;
1616 let Inst{19-16} = Rn;
Jim Grosbachf8e74f82011-10-24 17:16:24 +00001617 let Inst{15-0} = regs;
Bill Wendling6c470b82010-11-13 09:09:38 +00001618 }
Bill Wendling73fe34a2010-11-16 01:16:36 +00001619 def DB :
Bill Wendling6c470b82010-11-13 09:09:38 +00001620 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Jim Grosbachcfbb3a72011-09-07 18:39:47 +00001621 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
Bill Wendling6c470b82010-11-13 09:09:38 +00001622 bits<4> Rn;
1623 bits<16> regs;
1624
1625 let Inst{31-27} = 0b11101;
1626 let Inst{26-25} = 0b00;
1627 let Inst{24-23} = 0b10; // Decrement Before
1628 let Inst{22} = 0;
1629 let Inst{21} = 0; // No writeback
1630 let Inst{20} = L_bit;
1631 let Inst{19-16} = Rn;
Jim Grosbachf8e74f82011-10-24 17:16:24 +00001632 let Inst{15-0} = regs;
Bill Wendling6c470b82010-11-13 09:09:38 +00001633 }
Bill Wendling73fe34a2010-11-16 01:16:36 +00001634 def DB_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001635 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Jim Grosbachcfbb3a72011-09-07 18:39:47 +00001636 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
Bill Wendling6c470b82010-11-13 09:09:38 +00001637 bits<4> Rn;
1638 bits<16> regs;
1639
1640 let Inst{31-27} = 0b11101;
1641 let Inst{26-25} = 0b00;
1642 let Inst{24-23} = 0b10; // Decrement Before
1643 let Inst{22} = 0;
1644 let Inst{21} = 1; // Writeback
1645 let Inst{20} = L_bit;
1646 let Inst{19-16} = Rn;
Jim Grosbachf8e74f82011-10-24 17:16:24 +00001647 let Inst{15-0} = regs;
Bill Wendling6c470b82010-11-13 09:09:38 +00001648 }
1649}
1650
Bill Wendlingc93989a2010-11-13 11:20:05 +00001651let neverHasSideEffects = 1 in {
Bill Wendlingddc918b2010-11-13 10:57:02 +00001652
1653let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
Owen Andersoncd00dc62011-09-12 21:28:46 +00001654defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1655
1656multiclass thumb2_st_mult<string asm, InstrItinClass itin,
1657 InstrItinClass itin_upd, bit L_bit> {
1658 def IA :
1659 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1660 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1661 bits<4> Rn;
1662 bits<16> regs;
1663
1664 let Inst{31-27} = 0b11101;
1665 let Inst{26-25} = 0b00;
1666 let Inst{24-23} = 0b01; // Increment After
1667 let Inst{22} = 0;
1668 let Inst{21} = 0; // No writeback
1669 let Inst{20} = L_bit;
1670 let Inst{19-16} = Rn;
1671 let Inst{15} = 0;
1672 let Inst{14} = regs{14};
1673 let Inst{13} = 0;
1674 let Inst{12-0} = regs{12-0};
1675 }
1676 def IA_UPD :
1677 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1678 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1679 bits<4> Rn;
1680 bits<16> regs;
1681
1682 let Inst{31-27} = 0b11101;
1683 let Inst{26-25} = 0b00;
1684 let Inst{24-23} = 0b01; // Increment After
1685 let Inst{22} = 0;
1686 let Inst{21} = 1; // Writeback
1687 let Inst{20} = L_bit;
1688 let Inst{19-16} = Rn;
1689 let Inst{15} = 0;
1690 let Inst{14} = regs{14};
1691 let Inst{13} = 0;
1692 let Inst{12-0} = regs{12-0};
1693 }
1694 def DB :
1695 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1696 itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
1697 bits<4> Rn;
1698 bits<16> regs;
1699
1700 let Inst{31-27} = 0b11101;
1701 let Inst{26-25} = 0b00;
1702 let Inst{24-23} = 0b10; // Decrement Before
1703 let Inst{22} = 0;
1704 let Inst{21} = 0; // No writeback
1705 let Inst{20} = L_bit;
1706 let Inst{19-16} = Rn;
1707 let Inst{15} = 0;
1708 let Inst{14} = regs{14};
1709 let Inst{13} = 0;
1710 let Inst{12-0} = regs{12-0};
1711 }
1712 def DB_UPD :
1713 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1714 itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
1715 bits<4> Rn;
1716 bits<16> regs;
1717
1718 let Inst{31-27} = 0b11101;
1719 let Inst{26-25} = 0b00;
1720 let Inst{24-23} = 0b10; // Decrement Before
1721 let Inst{22} = 0;
1722 let Inst{21} = 1; // Writeback
1723 let Inst{20} = L_bit;
1724 let Inst{19-16} = Rn;
1725 let Inst{15} = 0;
1726 let Inst{14} = regs{14};
1727 let Inst{13} = 0;
1728 let Inst{12-0} = regs{12-0};
1729 }
1730}
1731
Bill Wendlingddc918b2010-11-13 10:57:02 +00001732
1733let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
Owen Andersoncd00dc62011-09-12 21:28:46 +00001734defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
Bill Wendlingddc918b2010-11-13 10:57:02 +00001735
1736} // neverHasSideEffects
1737
Bob Wilson815baeb2010-03-13 01:08:20 +00001738
Evan Cheng9cb9e672009-06-27 02:26:13 +00001739//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001740// Move Instructions.
1741//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001742
Evan Chengf49810c2009-06-23 17:48:47 +00001743let neverHasSideEffects = 1 in
Jim Grosbach1ad60c22011-09-10 00:15:36 +00001744def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPR:$Rm), IIC_iMOVr,
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001745 "mov", ".w\t$Rd, $Rm", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001746 let Inst{31-27} = 0b11101;
1747 let Inst{26-25} = 0b01;
1748 let Inst{24-21} = 0b0010;
Johnny Chend68e1192009-12-15 17:24:14 +00001749 let Inst{19-16} = 0b1111; // Rn
1750 let Inst{14-12} = 0b000;
1751 let Inst{7-4} = 0b0000;
1752}
Jim Grosbach9858a482011-10-18 17:09:35 +00001753def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
1754 pred:$p, zero_reg)>;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00001755def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
1756 pred:$p, CPSR)>;
1757def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
1758 pred:$p, CPSR)>;
Evan Chengf49810c2009-06-23 17:48:47 +00001759
Evan Cheng5adb66a2009-09-28 09:14:39 +00001760// AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
Evan Chengc4af4632010-11-17 20:13:28 +00001761let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
1762 AddedComplexity = 1 in
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001763def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
1764 "mov", ".w\t$Rd, $imm",
1765 [(set rGPR:$Rd, t2_so_imm:$imm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001766 let Inst{31-27} = 0b11110;
1767 let Inst{25} = 0;
1768 let Inst{24-21} = 0b0010;
Johnny Chend68e1192009-12-15 17:24:14 +00001769 let Inst{19-16} = 0b1111; // Rn
1770 let Inst{15} = 0;
1771}
David Goodwin83b35932009-06-26 16:10:07 +00001772
Jim Grosbach1ad60c22011-09-10 00:15:36 +00001773// cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
1774// Use aliases to get that to play nice here.
1775def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1776 pred:$p, CPSR)>;
1777def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1778 pred:$p, CPSR)>;
1779
1780def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1781 pred:$p, zero_reg)>;
1782def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1783 pred:$p, zero_reg)>;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00001784
Evan Chengc4af4632010-11-17 20:13:28 +00001785let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
Jim Grosbachffa32252011-07-19 19:13:28 +00001786def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001787 "movw", "\t$Rd, $imm",
1788 [(set rGPR:$Rd, imm0_65535:$imm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001789 let Inst{31-27} = 0b11110;
1790 let Inst{25} = 1;
1791 let Inst{24-21} = 0b0010;
1792 let Inst{20} = 0; // The S bit.
1793 let Inst{15} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00001794
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001795 bits<4> Rd;
1796 bits<16> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +00001797
Jim Grosbach86386922010-12-08 22:10:43 +00001798 let Inst{11-8} = Rd;
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001799 let Inst{19-16} = imm{15-12};
1800 let Inst{26} = imm{11};
1801 let Inst{14-12} = imm{10-8};
1802 let Inst{7-0} = imm{7-0};
Kevin Enderby9e5887b2011-10-04 22:44:48 +00001803 let DecoderMethod = "DecodeT2MOVTWInstruction";
Johnny Chend68e1192009-12-15 17:24:14 +00001804}
Evan Chengf49810c2009-06-23 17:48:47 +00001805
Evan Cheng53519f02011-01-21 18:55:51 +00001806def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
Evan Cheng5de5d4b2011-01-17 08:03:18 +00001807 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1808
1809let Constraints = "$src = $Rd" in {
Evan Cheng75972122011-01-13 07:58:56 +00001810def t2MOVTi16 : T2I<(outs rGPR:$Rd),
Jim Grosbachffa32252011-07-19 19:13:28 +00001811 (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001812 "movt", "\t$Rd, $imm",
1813 [(set rGPR:$Rd,
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001814 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001815 let Inst{31-27} = 0b11110;
1816 let Inst{25} = 1;
1817 let Inst{24-21} = 0b0110;
1818 let Inst{20} = 0; // The S bit.
1819 let Inst{15} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00001820
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001821 bits<4> Rd;
1822 bits<16> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +00001823
Jim Grosbach86386922010-12-08 22:10:43 +00001824 let Inst{11-8} = Rd;
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001825 let Inst{19-16} = imm{15-12};
1826 let Inst{26} = imm{11};
1827 let Inst{14-12} = imm{10-8};
1828 let Inst{7-0} = imm{7-0};
Kevin Enderby9e5887b2011-10-04 22:44:48 +00001829 let DecoderMethod = "DecodeT2MOVTWInstruction";
Johnny Chend68e1192009-12-15 17:24:14 +00001830}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001831
Evan Cheng53519f02011-01-21 18:55:51 +00001832def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
Evan Cheng5de5d4b2011-01-17 08:03:18 +00001833 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1834} // Constraints
1835
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001836def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
Evan Cheng20956592009-10-21 08:15:52 +00001837
Anton Korobeynikov52237112009-06-17 18:13:58 +00001838//===----------------------------------------------------------------------===//
Evan Chengd27c9fc2009-07-03 01:43:10 +00001839// Extend Instructions.
1840//
1841
1842// Sign extenders
1843
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001844def t2SXTB : T2I_ext_rrot<0b100, "sxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001845 UnOpFrag<(sext_inreg node:$Src, i8)>>;
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001846def t2SXTH : T2I_ext_rrot<0b000, "sxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001847 UnOpFrag<(sext_inreg node:$Src, i16)>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001848def t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001849
Jim Grosbach70327412011-07-27 17:48:13 +00001850def t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001851 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001852def t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001853 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001854def t2SXTAB16 : T2I_exta_rrot_np<0b010, "sxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001855
Evan Chengd27c9fc2009-07-03 01:43:10 +00001856// Zero extenders
1857
1858let AddedComplexity = 16 in {
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001859def t2UXTB : T2I_ext_rrot<0b101, "uxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001860 UnOpFrag<(and node:$Src, 0x000000FF)>>;
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001861def t2UXTH : T2I_ext_rrot<0b001, "uxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001862 UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001863def t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
Johnny Chend68e1192009-12-15 17:24:14 +00001864 UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001865
Jim Grosbach79464942010-07-28 23:17:45 +00001866// FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1867// The transformation should probably be done as a combiner action
1868// instead so we can include a check for masking back in the upper
1869// eight bits of the source into the lower eight bits of the result.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001870//def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach70327412011-07-27 17:48:13 +00001871// (t2UXTB16 rGPR:$Src, 3)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001872// Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001873def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach70327412011-07-27 17:48:13 +00001874 (t2UXTB16 rGPR:$Src, 1)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001875 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001876
Jim Grosbach70327412011-07-27 17:48:13 +00001877def t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001878 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001879def t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001880 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001881def t2UXTAB16 : T2I_exta_rrot_np<0b011, "uxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001882}
1883
1884//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001885// Arithmetic Instructions.
1886//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001887
Johnny Chend68e1192009-12-15 17:24:14 +00001888defm t2ADD : T2I_bin_ii12rs<0b000, "add",
1889 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
1890defm t2SUB : T2I_bin_ii12rs<0b101, "sub",
1891 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001892
Evan Chengf49810c2009-06-23 17:48:47 +00001893// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Andrew Trick3be654f2011-09-21 02:20:46 +00001894//
1895// Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
1896// selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
1897// AdjustInstrPostInstrSelection where we determine whether or not to
1898// set the "s" bit based on CPSR liveness.
1899//
1900// FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
1901// support for an optional CPSR definition that corresponds to the DAG
1902// node's second value. We can then eliminate the implicit def of CPSR.
Andrew Trick90b7b122011-10-18 19:18:52 +00001903defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Evan Cheng342e3162011-08-30 01:34:54 +00001904 BinOpFrag<(ARMaddc node:$LHS, node:$RHS)>, 1>;
Andrew Trick90b7b122011-10-18 19:18:52 +00001905defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Evan Cheng342e3162011-08-30 01:34:54 +00001906 BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001907
Andrew Trick83a80312011-09-20 18:22:31 +00001908let hasPostISelHook = 1 in {
Johnny Chend68e1192009-12-15 17:24:14 +00001909defm t2ADC : T2I_adde_sube_irs<0b1010, "adc",
Evan Cheng342e3162011-08-30 01:34:54 +00001910 BinOpWithFlagFrag<(ARMadde node:$LHS, node:$RHS, node:$FLAG)>, 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00001911defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc",
Evan Cheng342e3162011-08-30 01:34:54 +00001912 BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>>;
Andrew Trick83a80312011-09-20 18:22:31 +00001913}
Evan Chengf49810c2009-06-23 17:48:47 +00001914
David Goodwin752aa7d2009-07-27 16:39:05 +00001915// RSB
Bob Wilson20d8e4e2010-08-13 23:24:25 +00001916defm t2RSB : T2I_rbin_irs <0b1110, "rsb",
Johnny Chend68e1192009-12-15 17:24:14 +00001917 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Evan Cheng4a517082011-09-06 18:52:20 +00001918
1919// FIXME: Eliminate them if we can write def : Pat patterns which defines
1920// CPSR and the implicit def of CPSR is not needed.
Andrew Trick90b7b122011-10-18 19:18:52 +00001921defm t2RSBS : T2I_rbin_s_is <BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001922
1923// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001924// The assume-no-carry-in form uses the negation of the input since add/sub
1925// assume opposite meanings of the carry flag (i.e., carry == !borrow).
1926// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1927// details.
1928// The AddedComplexity preferences the first variant over the others since
1929// it can be shrunk to a 16-bit wide encoding, while the others cannot.
Evan Chengfa2ea1a2009-08-04 01:41:15 +00001930let AddedComplexity = 1 in
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001931def : T2Pat<(add GPR:$src, imm0_255_neg:$imm),
1932 (t2SUBri GPR:$src, imm0_255_neg:$imm)>;
1933def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
1934 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
1935def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
1936 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
Evan Chengfc472532012-06-23 00:29:06 +00001937def : T2Pat<(add GPR:$src, imm0_65535_neg:$imm),
1938 (t2SUBrr GPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
1939
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001940let AddedComplexity = 1 in
Evan Cheng342e3162011-08-30 01:34:54 +00001941def : T2Pat<(ARMaddc rGPR:$src, imm0_255_neg:$imm),
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001942 (t2SUBSri rGPR:$src, imm0_255_neg:$imm)>;
Evan Cheng342e3162011-08-30 01:34:54 +00001943def : T2Pat<(ARMaddc rGPR:$src, t2_so_imm_neg:$imm),
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001944 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengfc472532012-06-23 00:29:06 +00001945def : T2Pat<(ARMaddc rGPR:$src, imm0_65535_neg:$imm),
1946 (t2SUBSrr rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001947// The with-carry-in form matches bitwise not instead of the negation.
1948// Effectively, the inverse interpretation of the carry flag already accounts
1949// for part of the negation.
1950let AddedComplexity = 1 in
Evan Cheng342e3162011-08-30 01:34:54 +00001951def : T2Pat<(ARMadde rGPR:$src, imm0_255_not:$imm, CPSR),
Andrew Trick1c3af772011-04-23 03:55:32 +00001952 (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
Evan Cheng342e3162011-08-30 01:34:54 +00001953def : T2Pat<(ARMadde rGPR:$src, t2_so_imm_not:$imm, CPSR),
Andrew Trick1c3af772011-04-23 03:55:32 +00001954 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
Evan Chengfc472532012-06-23 00:29:06 +00001955def : T2Pat<(ARMadde rGPR:$src, imm0_65535_neg:$imm, CPSR),
1956 (t2SBCrr rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001957
Johnny Chen93042d12010-03-02 18:14:57 +00001958// Select Bytes -- for disassembly only
1959
Owen Andersonc7373f82010-11-30 20:00:01 +00001960def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00001961 NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []>,
1962 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chen93042d12010-03-02 18:14:57 +00001963 let Inst{31-27} = 0b11111;
1964 let Inst{26-24} = 0b010;
1965 let Inst{23} = 0b1;
1966 let Inst{22-20} = 0b010;
1967 let Inst{15-12} = 0b1111;
1968 let Inst{7} = 0b1;
1969 let Inst{6-4} = 0b000;
1970}
1971
Johnny Chenadc77332010-02-26 22:04:29 +00001972// A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1973// And Miscellaneous operations -- for disassembly only
Nate Begeman692433b2010-07-29 17:56:55 +00001974class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
Bruno Cardoso Lopes03016002011-01-21 14:07:40 +00001975 list<dag> pat = [/* For disassembly only; pattern left blank */],
1976 dag iops = (ins rGPR:$Rn, rGPR:$Rm),
1977 string asm = "\t$Rd, $Rn, $Rm">
Jim Grosbacha7603982011-07-01 21:12:19 +00001978 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
1979 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001980 let Inst{31-27} = 0b11111;
1981 let Inst{26-23} = 0b0101;
1982 let Inst{22-20} = op22_20;
1983 let Inst{15-12} = 0b1111;
1984 let Inst{7-4} = op7_4;
Jim Grosbach7a088642010-11-19 17:11:02 +00001985
Owen Anderson46c478e2010-11-17 19:57:38 +00001986 bits<4> Rd;
1987 bits<4> Rn;
1988 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +00001989
Jim Grosbach86386922010-12-08 22:10:43 +00001990 let Inst{11-8} = Rd;
1991 let Inst{19-16} = Rn;
1992 let Inst{3-0} = Rm;
Johnny Chenadc77332010-02-26 22:04:29 +00001993}
1994
1995// Saturating add/subtract -- for disassembly only
1996
Nate Begeman692433b2010-07-29 17:56:55 +00001997def t2QADD : T2I_pam<0b000, 0b1000, "qadd",
Bruno Cardoso Lopes03016002011-01-21 14:07:40 +00001998 [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))],
1999 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
Johnny Chenadc77332010-02-26 22:04:29 +00002000def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">;
2001def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">;
2002def t2QASX : T2I_pam<0b010, 0b0001, "qasx">;
Bruno Cardoso Lopes03016002011-01-21 14:07:40 +00002003def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd", [],
2004 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
2005def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub", [],
2006 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
Johnny Chenadc77332010-02-26 22:04:29 +00002007def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">;
Nate Begeman692433b2010-07-29 17:56:55 +00002008def t2QSUB : T2I_pam<0b000, 0b1010, "qsub",
Bruno Cardoso Lopes03016002011-01-21 14:07:40 +00002009 [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))],
2010 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
Johnny Chenadc77332010-02-26 22:04:29 +00002011def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">;
2012def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">;
2013def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
2014def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">;
2015def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">;
2016def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">;
2017def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
2018def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">;
2019
2020// Signed/Unsigned add/subtract -- for disassembly only
2021
2022def t2SASX : T2I_pam<0b010, 0b0000, "sasx">;
2023def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">;
2024def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">;
2025def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">;
2026def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">;
2027def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">;
2028def t2UASX : T2I_pam<0b010, 0b0100, "uasx">;
2029def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">;
2030def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">;
2031def t2USAX : T2I_pam<0b110, 0b0100, "usax">;
2032def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">;
2033def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">;
2034
2035// Signed/Unsigned halving add/subtract -- for disassembly only
2036
2037def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">;
2038def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
2039def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">;
2040def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">;
2041def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
2042def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">;
2043def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">;
2044def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
2045def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">;
2046def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">;
2047def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
2048def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">;
2049
Owen Anderson821752e2010-11-18 20:32:18 +00002050// Helper class for disassembly only
2051// A6.3.16 & A6.3.17
2052// T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
2053class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2054 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2055 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
2056 let Inst{31-27} = 0b11111;
2057 let Inst{26-24} = 0b011;
2058 let Inst{23} = long;
2059 let Inst{22-20} = op22_20;
2060 let Inst{7-4} = op7_4;
2061}
2062
2063class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
2064 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
2065 : T2FourReg<oops, iops, itin, opc, asm, pattern> {
2066 let Inst{31-27} = 0b11111;
2067 let Inst{26-24} = 0b011;
2068 let Inst{23} = long;
2069 let Inst{22-20} = op22_20;
2070 let Inst{7-4} = op7_4;
2071}
2072
Jim Grosbach8c989842011-09-20 00:26:34 +00002073// Unsigned Sum of Absolute Differences [and Accumulate].
Owen Anderson821752e2010-11-18 20:32:18 +00002074def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
2075 (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002076 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []>,
2077 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002078 let Inst{15-12} = 0b1111;
2079}
Owen Anderson821752e2010-11-18 20:32:18 +00002080def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
Jim Grosbach7a088642010-11-19 17:11:02 +00002081 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
Jim Grosbacha7603982011-07-01 21:12:19 +00002082 "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>,
2083 Requires<[IsThumb2, HasThumb2DSP]>;
Johnny Chenadc77332010-02-26 22:04:29 +00002084
Jim Grosbach8c989842011-09-20 00:26:34 +00002085// Signed/Unsigned saturate.
Owen Anderson46c478e2010-11-17 19:57:38 +00002086class T2SatI<dag oops, dag iops, InstrItinClass itin,
2087 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +00002088 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson46c478e2010-11-17 19:57:38 +00002089 bits<4> Rd;
2090 bits<4> Rn;
2091 bits<5> sat_imm;
2092 bits<7> sh;
Jim Grosbach7a088642010-11-19 17:11:02 +00002093
Jim Grosbach86386922010-12-08 22:10:43 +00002094 let Inst{11-8} = Rd;
2095 let Inst{19-16} = Rn;
Jim Grosbach580f4a92011-07-25 22:20:28 +00002096 let Inst{4-0} = sat_imm;
2097 let Inst{21} = sh{5};
Owen Anderson46c478e2010-11-17 19:57:38 +00002098 let Inst{14-12} = sh{4-2};
2099 let Inst{7-6} = sh{1-0};
2100}
2101
Owen Andersonc7373f82010-11-30 20:00:01 +00002102def t2SSAT: T2SatI<
Owen Anderson0afa0092011-09-26 21:06:22 +00002103 (outs rGPR:$Rd),
2104 (ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
Jim Grosbach8c989842011-09-20 00:26:34 +00002105 NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002106 let Inst{31-27} = 0b11110;
2107 let Inst{25-22} = 0b1100;
2108 let Inst{20} = 0;
2109 let Inst{15} = 0;
Owen Anderson061c3c42011-09-19 20:00:02 +00002110 let Inst{5} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00002111}
2112
Owen Andersonc7373f82010-11-30 20:00:01 +00002113def t2SSAT16: T2SatI<
Jim Grosbachf4943352011-07-25 23:09:14 +00002114 (outs rGPR:$Rd), (ins imm1_16:$sat_imm, rGPR:$Rn), NoItinerary,
Jim Grosbach8c989842011-09-20 00:26:34 +00002115 "ssat16", "\t$Rd, $sat_imm, $Rn", []>,
Jim Grosbacha7603982011-07-01 21:12:19 +00002116 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002117 let Inst{31-27} = 0b11110;
2118 let Inst{25-22} = 0b1100;
2119 let Inst{20} = 0;
2120 let Inst{15} = 0;
2121 let Inst{21} = 1; // sh = '1'
2122 let Inst{14-12} = 0b000; // imm3 = '000'
2123 let Inst{7-6} = 0b00; // imm2 = '00'
Owen Anderson8a28bdc2011-09-16 22:17:02 +00002124 let Inst{5-4} = 0b00;
Johnny Chenadc77332010-02-26 22:04:29 +00002125}
2126
Owen Andersonc7373f82010-11-30 20:00:01 +00002127def t2USAT: T2SatI<
Owen Anderson0afa0092011-09-26 21:06:22 +00002128 (outs rGPR:$Rd),
2129 (ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
Jim Grosbach8c989842011-09-20 00:26:34 +00002130 NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002131 let Inst{31-27} = 0b11110;
2132 let Inst{25-22} = 0b1110;
2133 let Inst{20} = 0;
2134 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00002135}
2136
Jim Grosbachb105b992011-09-16 18:32:30 +00002137def t2USAT16: T2SatI<(outs rGPR:$Rd), (ins imm0_15:$sat_imm, rGPR:$Rn),
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00002138 NoItinerary,
Jim Grosbach8c989842011-09-20 00:26:34 +00002139 "usat16", "\t$Rd, $sat_imm, $Rn", []>,
Jim Grosbacha7603982011-07-01 21:12:19 +00002140 Requires<[IsThumb2, HasThumb2DSP]> {
Owen Anderson4a713572011-09-23 21:57:50 +00002141 let Inst{31-22} = 0b1111001110;
Johnny Chenadc77332010-02-26 22:04:29 +00002142 let Inst{20} = 0;
2143 let Inst{15} = 0;
2144 let Inst{21} = 1; // sh = '1'
2145 let Inst{14-12} = 0b000; // imm3 = '000'
2146 let Inst{7-6} = 0b00; // imm2 = '00'
Owen Anderson4a713572011-09-23 21:57:50 +00002147 let Inst{5-4} = 0b00;
Johnny Chenadc77332010-02-26 22:04:29 +00002148}
Anton Korobeynikov52237112009-06-17 18:13:58 +00002149
Bob Wilson38aa2872010-08-13 21:48:10 +00002150def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
2151def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
Nate Begeman0e0a20e2010-07-29 22:48:09 +00002152
Evan Chengf49810c2009-06-23 17:48:47 +00002153//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +00002154// Shift and rotate Instructions.
2155//
2156
Jim Grosbach5f25fb02011-09-02 21:28:54 +00002157defm t2LSL : T2I_sh_ir<0b00, "lsl", imm0_31,
Jim Grosbach9249ef32012-08-02 21:59:52 +00002158 BinOpFrag<(shl node:$LHS, node:$RHS)>>;
Jim Grosbachd2990102011-09-02 18:43:25 +00002159defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr,
Jim Grosbach9249ef32012-08-02 21:59:52 +00002160 BinOpFrag<(srl node:$LHS, node:$RHS)>>;
Jim Grosbachd2990102011-09-02 18:43:25 +00002161defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr,
Jim Grosbach9249ef32012-08-02 21:59:52 +00002162 BinOpFrag<(sra node:$LHS, node:$RHS)>>;
Jim Grosbach5f25fb02011-09-02 21:28:54 +00002163defm t2ROR : T2I_sh_ir<0b11, "ror", imm0_31,
Jim Grosbach9249ef32012-08-02 21:59:52 +00002164 BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
Evan Chenga67efd12009-06-23 19:39:13 +00002165
Andrew Trickd49ffe82011-04-29 14:18:15 +00002166// (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
Bob Wilsonac03af42012-07-02 17:22:47 +00002167def : T2Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
2168 (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
Andrew Trickd49ffe82011-04-29 14:18:15 +00002169
David Goodwinca01a8d2009-09-01 18:32:09 +00002170let Uses = [CPSR] in {
Owen Anderson46c478e2010-11-17 19:57:38 +00002171def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2172 "rrx", "\t$Rd, $Rm",
2173 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002174 let Inst{31-27} = 0b11101;
2175 let Inst{26-25} = 0b01;
2176 let Inst{24-21} = 0b0010;
Johnny Chend68e1192009-12-15 17:24:14 +00002177 let Inst{19-16} = 0b1111; // Rn
2178 let Inst{14-12} = 0b000;
2179 let Inst{7-4} = 0b0011;
2180}
David Goodwinca01a8d2009-09-01 18:32:09 +00002181}
Evan Chenga67efd12009-06-23 19:39:13 +00002182
Daniel Dunbar8d66b782011-01-10 15:26:39 +00002183let isCodeGenOnly = 1, Defs = [CPSR] in {
Owen Andersonbb6315d2010-11-15 19:58:36 +00002184def t2MOVsrl_flag : T2TwoRegShiftImm<
2185 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2186 "lsrs", ".w\t$Rd, $Rm, #1",
2187 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002188 let Inst{31-27} = 0b11101;
2189 let Inst{26-25} = 0b01;
2190 let Inst{24-21} = 0b0010;
2191 let Inst{20} = 1; // The S bit.
2192 let Inst{19-16} = 0b1111; // Rn
2193 let Inst{5-4} = 0b01; // Shift type.
2194 // Shift amount = Inst{14-12:7-6} = 1.
2195 let Inst{14-12} = 0b000;
2196 let Inst{7-6} = 0b01;
2197}
Owen Andersonbb6315d2010-11-15 19:58:36 +00002198def t2MOVsra_flag : T2TwoRegShiftImm<
2199 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
2200 "asrs", ".w\t$Rd, $Rm, #1",
2201 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002202 let Inst{31-27} = 0b11101;
2203 let Inst{26-25} = 0b01;
2204 let Inst{24-21} = 0b0010;
2205 let Inst{20} = 1; // The S bit.
2206 let Inst{19-16} = 0b1111; // Rn
2207 let Inst{5-4} = 0b10; // Shift type.
2208 // Shift amount = Inst{14-12:7-6} = 1.
2209 let Inst{14-12} = 0b000;
2210 let Inst{7-6} = 0b01;
2211}
David Goodwin3583df72009-07-28 17:06:49 +00002212}
2213
Evan Chenga67efd12009-06-23 19:39:13 +00002214//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +00002215// Bitwise Instructions.
2216//
Anton Korobeynikov52237112009-06-17 18:13:58 +00002217
Johnny Chend68e1192009-12-15 17:24:14 +00002218defm t2AND : T2I_bin_w_irs<0b0000, "and",
Evan Cheng7e1bf302010-09-29 00:27:46 +00002219 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbach5c6c1282012-08-02 21:50:41 +00002220 BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00002221defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
Evan Cheng7e1bf302010-09-29 00:27:46 +00002222 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbach5c6c1282012-08-02 21:50:41 +00002223 BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00002224defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
Evan Cheng7e1bf302010-09-29 00:27:46 +00002225 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbach5c6c1282012-08-02 21:50:41 +00002226 BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +00002227
Johnny Chend68e1192009-12-15 17:24:14 +00002228defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
Evan Cheng7e1bf302010-09-29 00:27:46 +00002229 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbach5c6c1282012-08-02 21:50:41 +00002230 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002231
Owen Anderson2f7aed32010-11-17 22:16:31 +00002232class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2233 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +00002234 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson2f7aed32010-11-17 22:16:31 +00002235 bits<4> Rd;
2236 bits<5> msb;
2237 bits<5> lsb;
Jim Grosbach7a088642010-11-19 17:11:02 +00002238
Jim Grosbach86386922010-12-08 22:10:43 +00002239 let Inst{11-8} = Rd;
Owen Anderson2f7aed32010-11-17 22:16:31 +00002240 let Inst{4-0} = msb{4-0};
2241 let Inst{14-12} = lsb{4-2};
2242 let Inst{7-6} = lsb{1-0};
2243}
2244
2245class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2246 string opc, string asm, list<dag> pattern>
2247 : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2248 bits<4> Rn;
Jim Grosbach7a088642010-11-19 17:11:02 +00002249
Jim Grosbach86386922010-12-08 22:10:43 +00002250 let Inst{19-16} = Rn;
Owen Anderson2f7aed32010-11-17 22:16:31 +00002251}
2252
2253let Constraints = "$src = $Rd" in
2254def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2255 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2256 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002257 let Inst{31-27} = 0b11110;
Johnny Chen3a961222011-04-15 22:52:15 +00002258 let Inst{26} = 0; // should be 0.
Johnny Chend68e1192009-12-15 17:24:14 +00002259 let Inst{25} = 1;
2260 let Inst{24-20} = 0b10110;
2261 let Inst{19-16} = 0b1111; // Rn
2262 let Inst{15} = 0;
Johnny Chen3a961222011-04-15 22:52:15 +00002263 let Inst{5} = 0; // should be 0.
Jim Grosbach7a088642010-11-19 17:11:02 +00002264
Owen Anderson2f7aed32010-11-17 22:16:31 +00002265 bits<10> imm;
2266 let msb{4-0} = imm{9-5};
2267 let lsb{4-0} = imm{4-0};
Johnny Chend68e1192009-12-15 17:24:14 +00002268}
Evan Chengf49810c2009-06-23 17:48:47 +00002269
Owen Anderson2f7aed32010-11-17 22:16:31 +00002270def t2SBFX: T2TwoRegBitFI<
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002271 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
Owen Anderson2f7aed32010-11-17 22:16:31 +00002272 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002273 let Inst{31-27} = 0b11110;
2274 let Inst{25} = 1;
2275 let Inst{24-20} = 0b10100;
2276 let Inst{15} = 0;
2277}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002278
Owen Anderson2f7aed32010-11-17 22:16:31 +00002279def t2UBFX: T2TwoRegBitFI<
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002280 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
Owen Anderson2f7aed32010-11-17 22:16:31 +00002281 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002282 let Inst{31-27} = 0b11110;
2283 let Inst{25} = 1;
2284 let Inst{24-20} = 0b11100;
2285 let Inst{15} = 0;
2286}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002287
Johnny Chen9474d552010-02-02 19:31:58 +00002288// A8.6.18 BFI - Bitfield insert (Encoding T1)
Bruno Cardoso Lopesa461d422011-01-18 20:45:56 +00002289let Constraints = "$src = $Rd" in {
2290 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2291 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2292 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2293 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2294 bf_inv_mask_imm:$imm))]> {
2295 let Inst{31-27} = 0b11110;
Johnny Chen188ce9c2011-04-15 00:35:08 +00002296 let Inst{26} = 0; // should be 0.
Bruno Cardoso Lopesa461d422011-01-18 20:45:56 +00002297 let Inst{25} = 1;
2298 let Inst{24-20} = 0b10110;
2299 let Inst{15} = 0;
Johnny Chen188ce9c2011-04-15 00:35:08 +00002300 let Inst{5} = 0; // should be 0.
Jim Grosbach7a088642010-11-19 17:11:02 +00002301
Bruno Cardoso Lopesa461d422011-01-18 20:45:56 +00002302 bits<10> imm;
2303 let msb{4-0} = imm{9-5};
2304 let lsb{4-0} = imm{4-0};
2305 }
Johnny Chen9474d552010-02-02 19:31:58 +00002306}
Evan Chengf49810c2009-06-23 17:48:47 +00002307
Evan Cheng7e1bf302010-09-29 00:27:46 +00002308defm t2ORN : T2I_bin_irs<0b0011, "orn",
2309 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbach5c6c1282012-08-02 21:50:41 +00002310 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002311
Jim Grosbachd32872f2011-09-14 21:24:41 +00002312/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
2313/// unary operation that produces a value. These are predicable and can be
2314/// changed to modify CPSR.
2315multiclass T2I_un_irs<bits<4> opcod, string opc,
2316 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
2317 PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
2318 // shifted imm
2319 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
2320 opc, "\t$Rd, $imm",
2321 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]> {
2322 let isAsCheapAsAMove = Cheap;
2323 let isReMaterializable = ReMat;
2324 let Inst{31-27} = 0b11110;
2325 let Inst{25} = 0;
2326 let Inst{24-21} = opcod;
2327 let Inst{19-16} = 0b1111; // Rn
2328 let Inst{15} = 0;
2329 }
2330 // register
2331 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
2332 opc, ".w\t$Rd, $Rm",
2333 [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
2334 let Inst{31-27} = 0b11101;
2335 let Inst{26-25} = 0b01;
2336 let Inst{24-21} = opcod;
2337 let Inst{19-16} = 0b1111; // Rn
2338 let Inst{14-12} = 0b000; // imm3
2339 let Inst{7-6} = 0b00; // imm2
2340 let Inst{5-4} = 0b00; // type
2341 }
2342 // shifted register
2343 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
2344 opc, ".w\t$Rd, $ShiftedRm",
2345 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]> {
2346 let Inst{31-27} = 0b11101;
2347 let Inst{26-25} = 0b01;
2348 let Inst{24-21} = opcod;
2349 let Inst{19-16} = 0b1111; // Rn
2350 }
2351}
2352
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002353// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2354let AddedComplexity = 1 in
Evan Cheng5d42c562010-09-29 00:49:25 +00002355defm t2MVN : T2I_un_irs <0b0011, "mvn",
Evan Cheng3881cb72010-09-29 22:42:35 +00002356 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
Evan Cheng5d42c562010-09-29 00:49:25 +00002357 UnOpFrag<(not node:$Src)>, 1, 1>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002358
Jim Grosbachf084a5e2010-07-20 16:07:04 +00002359let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002360def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
2361 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002362
Joel Jones96ef2842012-06-18 14:51:32 +00002363// top16Zero - answer true if the upper 16 bits of $src are 0, false otherwise
2364def top16Zero: PatLeaf<(i32 rGPR:$src), [{
2365 return CurDAG->MaskedValueIsZero(SDValue(N,0), APInt::getHighBitsSet(32, 16));
2366 }]>;
2367
2368// so_imm_notSext is needed instead of so_imm_not, as the value of imm
2369// will match the extended, not the original bitWidth for $src.
2370def : T2Pat<(and top16Zero:$src, t2_so_imm_notSext:$imm),
2371 (t2BICri rGPR:$src, t2_so_imm_notSext:$imm)>;
2372
2373
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002374// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002375def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
2376 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
Evan Chengea253b92009-08-12 01:56:42 +00002377 Requires<[IsThumb2]>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002378
2379def : T2Pat<(t2_so_imm_not:$src),
2380 (t2MVNi t2_so_imm_not:$src)>;
2381
Evan Chengf49810c2009-06-23 17:48:47 +00002382//===----------------------------------------------------------------------===//
2383// Multiply Instructions.
2384//
Evan Cheng8de898a2009-06-26 00:19:44 +00002385let isCommutable = 1 in
Owen Anderson35141a92010-11-18 01:08:42 +00002386def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2387 "mul", "\t$Rd, $Rn, $Rm",
2388 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002389 let Inst{31-27} = 0b11111;
2390 let Inst{26-23} = 0b0110;
2391 let Inst{22-20} = 0b000;
2392 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2393 let Inst{7-4} = 0b0000; // Multiply
2394}
Evan Chengf49810c2009-06-23 17:48:47 +00002395
Owen Anderson35141a92010-11-18 01:08:42 +00002396def t2MLA: T2FourReg<
2397 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2398 "mla", "\t$Rd, $Rn, $Rm, $Ra",
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002399 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]>,
2400 Requires<[IsThumb2, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002401 let Inst{31-27} = 0b11111;
2402 let Inst{26-23} = 0b0110;
2403 let Inst{22-20} = 0b000;
Johnny Chend68e1192009-12-15 17:24:14 +00002404 let Inst{7-4} = 0b0000; // Multiply
2405}
Evan Chengf49810c2009-06-23 17:48:47 +00002406
Owen Anderson35141a92010-11-18 01:08:42 +00002407def t2MLS: T2FourReg<
2408 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2409 "mls", "\t$Rd, $Rn, $Rm, $Ra",
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002410 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]>,
2411 Requires<[IsThumb2, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002412 let Inst{31-27} = 0b11111;
2413 let Inst{26-23} = 0b0110;
2414 let Inst{22-20} = 0b000;
Johnny Chend68e1192009-12-15 17:24:14 +00002415 let Inst{7-4} = 0b0001; // Multiply and Subtract
2416}
Evan Chengf49810c2009-06-23 17:48:47 +00002417
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002418// Extra precision multiplies with low / high results
2419let neverHasSideEffects = 1 in {
2420let isCommutable = 1 in {
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002421def t2SMULL : T2MulLong<0b000, 0b0000,
Owen Anderson796c3652011-08-22 23:16:48 +00002422 (outs rGPR:$RdLo, rGPR:$RdHi),
Owen Anderson35141a92010-11-18 01:08:42 +00002423 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
Owen Anderson796c3652011-08-22 23:16:48 +00002424 "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002425
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002426def t2UMULL : T2MulLong<0b010, 0b0000,
Jim Grosbach52082042010-12-08 22:29:28 +00002427 (outs rGPR:$RdLo, rGPR:$RdHi),
Owen Anderson35141a92010-11-18 01:08:42 +00002428 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002429 "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
Johnny Chend68e1192009-12-15 17:24:14 +00002430} // isCommutable
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002431
2432// Multiply + accumulate
Arnold Schwaighofer67514e92012-09-04 14:37:49 +00002433def t2SMLAL : T2MlaLong<0b100, 0b0000,
Arnold Schwaighofera7016d62012-08-12 05:11:56 +00002434 (outs rGPR:$RdLo, rGPR:$RdHi),
Arnold Schwaighofer67514e92012-09-04 14:37:49 +00002435 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
2436 "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
2437 RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002438
Arnold Schwaighofer67514e92012-09-04 14:37:49 +00002439def t2UMLAL : T2MlaLong<0b110, 0b0000,
Arnold Schwaighofera7016d62012-08-12 05:11:56 +00002440 (outs rGPR:$RdLo, rGPR:$RdHi),
Arnold Schwaighofer67514e92012-09-04 14:37:49 +00002441 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
2442 "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
2443 RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002444
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002445def t2UMAAL : T2MulLong<0b110, 0b0110,
2446 (outs rGPR:$RdLo, rGPR:$RdHi),
Owen Anderson35141a92010-11-18 01:08:42 +00002447 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
Jim Grosbacha7603982011-07-01 21:12:19 +00002448 "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
2449 Requires<[IsThumb2, HasThumb2DSP]>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002450} // neverHasSideEffects
2451
Johnny Chen93042d12010-03-02 18:14:57 +00002452// Rounding variants of the below included for disassembly only
2453
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002454// Most significant word multiply
Owen Anderson821752e2010-11-18 20:32:18 +00002455def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2456 "smmul", "\t$Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002457 [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]>,
2458 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002459 let Inst{31-27} = 0b11111;
2460 let Inst{26-23} = 0b0110;
2461 let Inst{22-20} = 0b101;
2462 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2463 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2464}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002465
Owen Anderson821752e2010-11-18 20:32:18 +00002466def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
Jim Grosbacha7603982011-07-01 21:12:19 +00002467 "smmulr", "\t$Rd, $Rn, $Rm", []>,
2468 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chen93042d12010-03-02 18:14:57 +00002469 let Inst{31-27} = 0b11111;
2470 let Inst{26-23} = 0b0110;
2471 let Inst{22-20} = 0b101;
2472 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2473 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2474}
2475
Owen Anderson821752e2010-11-18 20:32:18 +00002476def t2SMMLA : T2FourReg<
2477 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2478 "smmla", "\t$Rd, $Rn, $Rm, $Ra",
Jim Grosbacha7603982011-07-01 21:12:19 +00002479 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>,
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002480 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002481 let Inst{31-27} = 0b11111;
2482 let Inst{26-23} = 0b0110;
2483 let Inst{22-20} = 0b101;
Johnny Chend68e1192009-12-15 17:24:14 +00002484 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2485}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002486
Owen Anderson821752e2010-11-18 20:32:18 +00002487def t2SMMLAR: T2FourReg<
2488 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
Jim Grosbacha7603982011-07-01 21:12:19 +00002489 "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
2490 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chen93042d12010-03-02 18:14:57 +00002491 let Inst{31-27} = 0b11111;
2492 let Inst{26-23} = 0b0110;
2493 let Inst{22-20} = 0b101;
Johnny Chen93042d12010-03-02 18:14:57 +00002494 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2495}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002496
Owen Anderson821752e2010-11-18 20:32:18 +00002497def t2SMMLS: T2FourReg<
2498 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2499 "smmls", "\t$Rd, $Rn, $Rm, $Ra",
Jim Grosbacha7603982011-07-01 21:12:19 +00002500 [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]>,
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002501 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002502 let Inst{31-27} = 0b11111;
2503 let Inst{26-23} = 0b0110;
2504 let Inst{22-20} = 0b110;
Johnny Chend68e1192009-12-15 17:24:14 +00002505 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2506}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002507
Owen Anderson821752e2010-11-18 20:32:18 +00002508def t2SMMLSR:T2FourReg<
2509 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
Jim Grosbacha7603982011-07-01 21:12:19 +00002510 "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
2511 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chen93042d12010-03-02 18:14:57 +00002512 let Inst{31-27} = 0b11111;
2513 let Inst{26-23} = 0b0110;
2514 let Inst{22-20} = 0b110;
Johnny Chen93042d12010-03-02 18:14:57 +00002515 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2516}
2517
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002518multiclass T2I_smul<string opc, PatFrag opnode> {
Owen Anderson821752e2010-11-18 20:32:18 +00002519 def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2520 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
2521 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
Jim Grosbacha7603982011-07-01 21:12:19 +00002522 (sext_inreg rGPR:$Rm, i16)))]>,
2523 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002524 let Inst{31-27} = 0b11111;
2525 let Inst{26-23} = 0b0110;
2526 let Inst{22-20} = 0b001;
2527 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2528 let Inst{7-6} = 0b00;
2529 let Inst{5-4} = 0b00;
2530 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002531
Owen Anderson821752e2010-11-18 20:32:18 +00002532 def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2533 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
2534 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
Jim Grosbacha7603982011-07-01 21:12:19 +00002535 (sra rGPR:$Rm, (i32 16))))]>,
2536 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002537 let Inst{31-27} = 0b11111;
2538 let Inst{26-23} = 0b0110;
2539 let Inst{22-20} = 0b001;
2540 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2541 let Inst{7-6} = 0b00;
2542 let Inst{5-4} = 0b01;
2543 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002544
Owen Anderson821752e2010-11-18 20:32:18 +00002545 def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2546 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
2547 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
Jim Grosbacha7603982011-07-01 21:12:19 +00002548 (sext_inreg rGPR:$Rm, i16)))]>,
2549 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002550 let Inst{31-27} = 0b11111;
2551 let Inst{26-23} = 0b0110;
2552 let Inst{22-20} = 0b001;
2553 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2554 let Inst{7-6} = 0b00;
2555 let Inst{5-4} = 0b10;
2556 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002557
Owen Anderson821752e2010-11-18 20:32:18 +00002558 def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2559 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
2560 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
Jim Grosbacha7603982011-07-01 21:12:19 +00002561 (sra rGPR:$Rm, (i32 16))))]>,
2562 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002563 let Inst{31-27} = 0b11111;
2564 let Inst{26-23} = 0b0110;
2565 let Inst{22-20} = 0b001;
2566 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2567 let Inst{7-6} = 0b00;
2568 let Inst{5-4} = 0b11;
2569 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002570
Owen Anderson821752e2010-11-18 20:32:18 +00002571 def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2572 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
2573 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
Jim Grosbacha7603982011-07-01 21:12:19 +00002574 (sext_inreg rGPR:$Rm, i16)), (i32 16)))]>,
2575 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002576 let Inst{31-27} = 0b11111;
2577 let Inst{26-23} = 0b0110;
2578 let Inst{22-20} = 0b011;
2579 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2580 let Inst{7-6} = 0b00;
2581 let Inst{5-4} = 0b00;
2582 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002583
Owen Anderson821752e2010-11-18 20:32:18 +00002584 def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2585 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
2586 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
Jim Grosbacha7603982011-07-01 21:12:19 +00002587 (sra rGPR:$Rm, (i32 16))), (i32 16)))]>,
2588 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002589 let Inst{31-27} = 0b11111;
2590 let Inst{26-23} = 0b0110;
2591 let Inst{22-20} = 0b011;
2592 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2593 let Inst{7-6} = 0b00;
2594 let Inst{5-4} = 0b01;
2595 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002596}
2597
2598
2599multiclass T2I_smla<string opc, PatFrag opnode> {
Owen Anderson821752e2010-11-18 20:32:18 +00002600 def BB : T2FourReg<
2601 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2602 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
2603 [(set rGPR:$Rd, (add rGPR:$Ra,
2604 (opnode (sext_inreg rGPR:$Rn, i16),
Jim Grosbacha7603982011-07-01 21:12:19 +00002605 (sext_inreg rGPR:$Rm, i16))))]>,
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002606 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002607 let Inst{31-27} = 0b11111;
2608 let Inst{26-23} = 0b0110;
2609 let Inst{22-20} = 0b001;
Johnny Chend68e1192009-12-15 17:24:14 +00002610 let Inst{7-6} = 0b00;
2611 let Inst{5-4} = 0b00;
2612 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002613
Owen Anderson821752e2010-11-18 20:32:18 +00002614 def BT : T2FourReg<
2615 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2616 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
2617 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16),
Jim Grosbacha7603982011-07-01 21:12:19 +00002618 (sra rGPR:$Rm, (i32 16)))))]>,
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002619 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002620 let Inst{31-27} = 0b11111;
2621 let Inst{26-23} = 0b0110;
2622 let Inst{22-20} = 0b001;
Johnny Chend68e1192009-12-15 17:24:14 +00002623 let Inst{7-6} = 0b00;
2624 let Inst{5-4} = 0b01;
2625 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002626
Owen Anderson821752e2010-11-18 20:32:18 +00002627 def TB : T2FourReg<
2628 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2629 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
2630 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
Jim Grosbacha7603982011-07-01 21:12:19 +00002631 (sext_inreg rGPR:$Rm, i16))))]>,
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002632 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002633 let Inst{31-27} = 0b11111;
2634 let Inst{26-23} = 0b0110;
2635 let Inst{22-20} = 0b001;
Johnny Chend68e1192009-12-15 17:24:14 +00002636 let Inst{7-6} = 0b00;
2637 let Inst{5-4} = 0b10;
2638 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002639
Owen Anderson821752e2010-11-18 20:32:18 +00002640 def TT : T2FourReg<
2641 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2642 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
2643 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
Jim Grosbacha7603982011-07-01 21:12:19 +00002644 (sra rGPR:$Rm, (i32 16)))))]>,
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002645 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002646 let Inst{31-27} = 0b11111;
2647 let Inst{26-23} = 0b0110;
2648 let Inst{22-20} = 0b001;
Johnny Chend68e1192009-12-15 17:24:14 +00002649 let Inst{7-6} = 0b00;
2650 let Inst{5-4} = 0b11;
2651 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002652
Owen Anderson821752e2010-11-18 20:32:18 +00002653 def WB : T2FourReg<
2654 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2655 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
2656 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
Jim Grosbacha7603982011-07-01 21:12:19 +00002657 (sext_inreg rGPR:$Rm, i16)), (i32 16))))]>,
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002658 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002659 let Inst{31-27} = 0b11111;
2660 let Inst{26-23} = 0b0110;
2661 let Inst{22-20} = 0b011;
Johnny Chend68e1192009-12-15 17:24:14 +00002662 let Inst{7-6} = 0b00;
2663 let Inst{5-4} = 0b00;
2664 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002665
Owen Anderson821752e2010-11-18 20:32:18 +00002666 def WT : T2FourReg<
2667 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2668 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
2669 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
Jim Grosbacha7603982011-07-01 21:12:19 +00002670 (sra rGPR:$Rm, (i32 16))), (i32 16))))]>,
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002671 Requires<[IsThumb2, HasThumb2DSP, UseMulOps]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002672 let Inst{31-27} = 0b11111;
2673 let Inst{26-23} = 0b0110;
2674 let Inst{22-20} = 0b011;
Johnny Chend68e1192009-12-15 17:24:14 +00002675 let Inst{7-6} = 0b00;
2676 let Inst{5-4} = 0b01;
2677 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002678}
2679
2680defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2681defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2682
Jim Grosbacheeca7582011-09-15 23:45:50 +00002683// Halfword multiple accumulate long: SMLAL<x><y>
Owen Anderson821752e2010-11-18 20:32:18 +00002684def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd),
2685 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002686 [/* For disassembly only; pattern left blank */]>,
2687 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002688def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd),
2689 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002690 [/* For disassembly only; pattern left blank */]>,
2691 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002692def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd),
2693 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002694 [/* For disassembly only; pattern left blank */]>,
2695 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002696def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd),
2697 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002698 [/* For disassembly only; pattern left blank */]>,
2699 Requires<[IsThumb2, HasThumb2DSP]>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002700
Johnny Chenadc77332010-02-26 22:04:29 +00002701// Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
Owen Anderson821752e2010-11-18 20:32:18 +00002702def t2SMUAD: T2ThreeReg_mac<
2703 0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002704 IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []>,
2705 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002706 let Inst{15-12} = 0b1111;
2707}
Owen Anderson821752e2010-11-18 20:32:18 +00002708def t2SMUADX:T2ThreeReg_mac<
2709 0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002710 IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []>,
2711 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002712 let Inst{15-12} = 0b1111;
2713}
Owen Anderson821752e2010-11-18 20:32:18 +00002714def t2SMUSD: T2ThreeReg_mac<
2715 0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002716 IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []>,
2717 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002718 let Inst{15-12} = 0b1111;
2719}
Owen Anderson821752e2010-11-18 20:32:18 +00002720def t2SMUSDX:T2ThreeReg_mac<
2721 0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002722 IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []>,
2723 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002724 let Inst{15-12} = 0b1111;
2725}
Owen Andersonc6788c82011-08-22 23:31:45 +00002726def t2SMLAD : T2FourReg_mac<
Owen Anderson821752e2010-11-18 20:32:18 +00002727 0, 0b010, 0b0000, (outs rGPR:$Rd),
2728 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad",
Jim Grosbacha7603982011-07-01 21:12:19 +00002729 "\t$Rd, $Rn, $Rm, $Ra", []>,
2730 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002731def t2SMLADX : T2FourReg_mac<
2732 0, 0b010, 0b0001, (outs rGPR:$Rd),
2733 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx",
Jim Grosbacha7603982011-07-01 21:12:19 +00002734 "\t$Rd, $Rn, $Rm, $Ra", []>,
2735 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002736def t2SMLSD : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd),
2737 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd",
Jim Grosbacha7603982011-07-01 21:12:19 +00002738 "\t$Rd, $Rn, $Rm, $Ra", []>,
2739 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002740def t2SMLSDX : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd),
2741 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx",
Jim Grosbacha7603982011-07-01 21:12:19 +00002742 "\t$Rd, $Rn, $Rm, $Ra", []>,
2743 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002744def t2SMLALD : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
Jim Grosbach231948f2011-09-16 16:58:03 +00002745 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, "smlald",
2746 "\t$Ra, $Rd, $Rn, $Rm", []>,
Jim Grosbacha7603982011-07-01 21:12:19 +00002747 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002748def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
Jim Grosbach231948f2011-09-16 16:58:03 +00002749 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaldx",
2750 "\t$Ra, $Rd, $Rn, $Rm", []>,
Jim Grosbacha7603982011-07-01 21:12:19 +00002751 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002752def t2SMLSLD : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
Jim Grosbach7ff24722011-09-16 17:10:44 +00002753 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlsld",
2754 "\t$Ra, $Rd, $Rn, $Rm", []>,
Jim Grosbacha7603982011-07-01 21:12:19 +00002755 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002756def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2757 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx",
Jim Grosbach7ff24722011-09-16 17:10:44 +00002758 "\t$Ra, $Rd, $Rn, $Rm", []>,
Jim Grosbacha7603982011-07-01 21:12:19 +00002759 Requires<[IsThumb2, HasThumb2DSP]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002760
2761//===----------------------------------------------------------------------===//
Evan Cheng734f63b2011-06-21 19:00:54 +00002762// Division Instructions.
2763// Signed and unsigned division on v7-M
2764//
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002765def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
Evan Cheng734f63b2011-06-21 19:00:54 +00002766 "sdiv", "\t$Rd, $Rn, $Rm",
2767 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
2768 Requires<[HasDivide, IsThumb2]> {
2769 let Inst{31-27} = 0b11111;
2770 let Inst{26-21} = 0b011100;
2771 let Inst{20} = 0b1;
2772 let Inst{15-12} = 0b1111;
2773 let Inst{7-4} = 0b1111;
2774}
2775
Bob Wilsoneb1641d2012-09-29 21:43:49 +00002776def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
Evan Cheng734f63b2011-06-21 19:00:54 +00002777 "udiv", "\t$Rd, $Rn, $Rm",
2778 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
2779 Requires<[HasDivide, IsThumb2]> {
2780 let Inst{31-27} = 0b11111;
2781 let Inst{26-21} = 0b011101;
2782 let Inst{20} = 0b1;
2783 let Inst{15-12} = 0b1111;
2784 let Inst{7-4} = 0b1111;
2785}
2786
2787//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +00002788// Misc. Arithmetic Instructions.
2789//
2790
Jim Grosbach80dc1162010-02-16 21:23:02 +00002791class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2792 InstrItinClass itin, string opc, string asm, list<dag> pattern>
Owen Anderson612fb5b2010-11-18 21:15:19 +00002793 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
Johnny Chend68e1192009-12-15 17:24:14 +00002794 let Inst{31-27} = 0b11111;
2795 let Inst{26-22} = 0b01010;
2796 let Inst{21-20} = op1;
2797 let Inst{15-12} = 0b1111;
2798 let Inst{7-6} = 0b10;
2799 let Inst{5-4} = op2;
Jim Grosbach86386922010-12-08 22:10:43 +00002800 let Rn{3-0} = Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00002801}
Evan Chengf49810c2009-06-23 17:48:47 +00002802
Owen Anderson612fb5b2010-11-18 21:15:19 +00002803def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2804 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002805
Owen Anderson612fb5b2010-11-18 21:15:19 +00002806def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2807 "rbit", "\t$Rd, $Rm",
2808 [(set rGPR:$Rd, (ARMrbit rGPR:$Rm))]>;
Jim Grosbach3482c802010-01-18 19:58:49 +00002809
Owen Anderson612fb5b2010-11-18 21:15:19 +00002810def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2811 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>;
Johnny Chend68e1192009-12-15 17:24:14 +00002812
Owen Anderson612fb5b2010-11-18 21:15:19 +00002813def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2814 "rev16", ".w\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00002815 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>;
Evan Cheng6d6c55b2011-06-17 20:47:21 +00002816
Owen Anderson612fb5b2010-11-18 21:15:19 +00002817def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2818 "revsh", ".w\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00002819 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>;
Evan Cheng3f30af32011-03-18 21:52:42 +00002820
Evan Chengf60ceac2011-06-15 17:17:48 +00002821def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
Evan Cheng9568e5c2011-06-21 06:01:08 +00002822 (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
Evan Chengf60ceac2011-06-15 17:17:48 +00002823 (t2REVSH rGPR:$Rm)>;
2824
Owen Anderson612fb5b2010-11-18 21:15:19 +00002825def t2PKHBT : T2ThreeReg<
Jim Grosbach0b692472011-09-14 23:16:41 +00002826 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
2827 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
Owen Anderson612fb5b2010-11-18 21:15:19 +00002828 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
Jim Grosbach1769a3d2011-07-20 20:49:03 +00002829 (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
Jim Grosbachb1dc3932010-05-05 20:44:35 +00002830 0xFFFF0000)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002831 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002832 let Inst{31-27} = 0b11101;
2833 let Inst{26-25} = 0b01;
2834 let Inst{24-20} = 0b01100;
2835 let Inst{5} = 0; // BT form
2836 let Inst{4} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00002837
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002838 bits<5> sh;
2839 let Inst{14-12} = sh{4-2};
2840 let Inst{7-6} = sh{1-0};
Johnny Chend68e1192009-12-15 17:24:14 +00002841}
Evan Cheng40289b02009-07-07 05:35:52 +00002842
2843// Alternate cases for PKHBT where identities eliminate some nodes.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002844def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2845 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002846 Requires<[HasT2ExtractPack, IsThumb2]>;
Bob Wilsonf955f292010-08-17 17:23:19 +00002847def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002848 (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002849 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Cheng40289b02009-07-07 05:35:52 +00002850
Bob Wilsondc66eda2010-08-16 22:26:55 +00002851// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2852// will match the pattern below.
Owen Anderson612fb5b2010-11-18 21:15:19 +00002853def t2PKHTB : T2ThreeReg<
Jim Grosbach0b692472011-09-14 23:16:41 +00002854 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
2855 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
Owen Anderson612fb5b2010-11-18 21:15:19 +00002856 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
Jim Grosbach1769a3d2011-07-20 20:49:03 +00002857 (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
Bob Wilsonf955f292010-08-17 17:23:19 +00002858 0xFFFF)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002859 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002860 let Inst{31-27} = 0b11101;
2861 let Inst{26-25} = 0b01;
2862 let Inst{24-20} = 0b01100;
2863 let Inst{5} = 1; // TB form
2864 let Inst{4} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00002865
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002866 bits<5> sh;
2867 let Inst{14-12} = sh{4-2};
2868 let Inst{7-6} = sh{1-0};
Johnny Chend68e1192009-12-15 17:24:14 +00002869}
Evan Cheng40289b02009-07-07 05:35:52 +00002870
2871// Alternate cases for PKHTB where identities eliminate some nodes. Note that
2872// a shift amount of 0 is *not legal* here, it is PKHBT instead.
Bob Wilsondc66eda2010-08-16 22:26:55 +00002873def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002874 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002875 Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002876def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
Bob Wilsonf955f292010-08-17 17:23:19 +00002877 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002878 (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002879 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002880
2881//===----------------------------------------------------------------------===//
2882// Comparison Instructions...
2883//
Johnny Chend68e1192009-12-15 17:24:14 +00002884defm t2CMP : T2I_cmp_irs<0b1101, "cmp",
Evan Cheng5d42c562010-09-29 00:49:25 +00002885 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Jim Grosbach9249ef32012-08-02 21:59:52 +00002886 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
Jim Grosbach97a884d2010-12-07 20:41:06 +00002887
Jim Grosbachef88a922011-09-06 21:44:58 +00002888def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_imm:$imm),
2889 (t2CMPri GPRnopc:$lhs, t2_so_imm:$imm)>;
2890def : T2Pat<(ARMcmpZ GPRnopc:$lhs, rGPR:$rhs),
2891 (t2CMPrr GPRnopc:$lhs, rGPR:$rhs)>;
2892def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_reg:$rhs),
2893 (t2CMPrs GPRnopc:$lhs, t2_so_reg:$rhs)>;
Evan Chengf49810c2009-06-23 17:48:47 +00002894
Bill Wendlingad5c8802012-06-11 08:07:26 +00002895let isCompare = 1, Defs = [CPSR] in {
2896 // shifted imm
2897 def t2CMNri : T2OneRegCmpImm<
2898 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iCMPi,
2899 "cmn", ".w\t$Rn, $imm",
2900 [(ARMcmn GPRnopc:$Rn, (ineg t2_so_imm:$imm))]> {
2901 let Inst{31-27} = 0b11110;
2902 let Inst{25} = 0;
2903 let Inst{24-21} = 0b1000;
2904 let Inst{20} = 1; // The S bit.
2905 let Inst{15} = 0;
2906 let Inst{11-8} = 0b1111; // Rd
2907 }
2908 // register
2909 def t2CMNzrr : T2TwoRegCmp<
2910 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iCMPr,
2911 "cmn", ".w\t$Rn, $Rm",
2912 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
2913 GPRnopc:$Rn, rGPR:$Rm)]> {
2914 let Inst{31-27} = 0b11101;
2915 let Inst{26-25} = 0b01;
2916 let Inst{24-21} = 0b1000;
2917 let Inst{20} = 1; // The S bit.
2918 let Inst{14-12} = 0b000; // imm3
2919 let Inst{11-8} = 0b1111; // Rd
2920 let Inst{7-6} = 0b00; // imm2
2921 let Inst{5-4} = 0b00; // type
2922 }
2923 // shifted register
2924 def t2CMNzrs : T2OneRegCmpShiftedReg<
2925 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), IIC_iCMPsi,
2926 "cmn", ".w\t$Rn, $ShiftedRm",
2927 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
2928 GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]> {
2929 let Inst{31-27} = 0b11101;
2930 let Inst{26-25} = 0b01;
2931 let Inst{24-21} = 0b1000;
2932 let Inst{20} = 1; // The S bit.
2933 let Inst{11-8} = 0b1111; // Rd
2934 }
2935}
Dan Gohman4b7dff92010-08-26 15:50:25 +00002936
Bill Wendlingad5c8802012-06-11 08:07:26 +00002937// Assembler aliases w/o the ".w" suffix.
2938// No alias here for 'rr' version as not all instantiations of this multiclass
2939// want one (CMP in particular, does not).
Jim Grosbach9249ef32012-08-02 21:59:52 +00002940def : t2InstAlias<"cmn${p} $Rn, $imm",
2941 (t2CMNri GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
2942def : t2InstAlias<"cmn${p} $Rn, $shift",
2943 (t2CMNzrs GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002944
Bill Wendlingad5c8802012-06-11 08:07:26 +00002945def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
2946 (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
2947
2948def : T2Pat<(ARMcmpZ GPRnopc:$src, t2_so_imm_neg:$imm),
2949 (t2CMNri GPRnopc:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +00002950
Johnny Chend68e1192009-12-15 17:24:14 +00002951defm t2TST : T2I_cmp_irs<0b0000, "tst",
Evan Cheng5d42c562010-09-29 00:49:25 +00002952 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Jim Grosbach9249ef32012-08-02 21:59:52 +00002953 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
Johnny Chend68e1192009-12-15 17:24:14 +00002954defm t2TEQ : T2I_cmp_irs<0b0100, "teq",
Evan Cheng5d42c562010-09-29 00:49:25 +00002955 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Jim Grosbach9249ef32012-08-02 21:59:52 +00002956 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002957
Evan Chenge253c952009-07-07 20:39:03 +00002958// Conditional moves
2959// FIXME: should be able to write a pattern for ARMcmov, but can't use
Jim Grosbach64171712010-02-16 21:07:46 +00002960// a two-value operand where a dag node expects two operands. :(
Evan Cheng63f35442010-11-13 02:25:14 +00002961let neverHasSideEffects = 1 in {
Jakob Stoklund Olesenc5041ca2012-04-04 18:23:42 +00002962
Jakob Stoklund Olesen053b5b02012-08-16 23:14:20 +00002963let isCommutable = 1, isSelect = 1 in
Jim Grosbachefeedce2011-07-01 17:14:11 +00002964def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
2965 (ins rGPR:$false, rGPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00002966 4, IIC_iCMOVr,
Owen Anderson8ee97792010-11-18 21:46:31 +00002967 [/*(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
Jim Grosbachefeedce2011-07-01 17:14:11 +00002968 RegConstraint<"$false = $Rd">;
2969
2970let isMoveImm = 1 in
2971def t2MOVCCi : t2PseudoInst<(outs rGPR:$Rd),
2972 (ins rGPR:$false, t2_so_imm:$imm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00002973 4, IIC_iCMOVi,
Jim Grosbachefeedce2011-07-01 17:14:11 +00002974[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm:$imm, imm:$cc, CCR:$ccr))*/]>,
2975 RegConstraint<"$false = $Rd">;
Evan Chenge253c952009-07-07 20:39:03 +00002976
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00002977// FIXME: Pseudo-ize these. For now, just mark codegen only.
2978let isCodeGenOnly = 1 in {
Evan Chengc4af4632010-11-17 20:13:28 +00002979let isMoveImm = 1 in
Jim Grosbachffa32252011-07-19 19:13:28 +00002980def t2MOVCCi16 : T2I<(outs rGPR:$Rd), (ins rGPR:$false, imm0_65535_expr:$imm),
Evan Cheng875a6ac2010-11-12 22:42:47 +00002981 IIC_iCMOVi,
Owen Andersonc56dcbf2010-11-16 00:29:56 +00002982 "movw", "\t$Rd, $imm", []>,
2983 RegConstraint<"$false = $Rd"> {
Jim Grosbacha4257162010-10-07 00:53:56 +00002984 let Inst{31-27} = 0b11110;
2985 let Inst{25} = 1;
2986 let Inst{24-21} = 0b0010;
2987 let Inst{20} = 0; // The S bit.
2988 let Inst{15} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00002989
Owen Andersonc56dcbf2010-11-16 00:29:56 +00002990 bits<4> Rd;
2991 bits<16> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +00002992
Jim Grosbach86386922010-12-08 22:10:43 +00002993 let Inst{11-8} = Rd;
Owen Andersonc56dcbf2010-11-16 00:29:56 +00002994 let Inst{19-16} = imm{15-12};
2995 let Inst{26} = imm{11};
2996 let Inst{14-12} = imm{10-8};
2997 let Inst{7-0} = imm{7-0};
Jim Grosbacha4257162010-10-07 00:53:56 +00002998}
2999
Evan Chengc4af4632010-11-17 20:13:28 +00003000let isMoveImm = 1 in
Evan Cheng63f35442010-11-13 02:25:14 +00003001def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
3002 (ins rGPR:$false, i32imm:$src, pred:$p),
Jim Grosbach99594eb2010-11-18 01:38:26 +00003003 IIC_iCMOVix2, []>, RegConstraint<"$false = $dst">;
Evan Cheng63f35442010-11-13 02:25:14 +00003004
Evan Chengc4af4632010-11-17 20:13:28 +00003005let isMoveImm = 1 in
Owen Anderson8ee97792010-11-18 21:46:31 +00003006def t2MVNCCi : T2OneRegImm<(outs rGPR:$Rd), (ins rGPR:$false, t2_so_imm:$imm),
Jim Grosbach9c5edc02011-10-26 17:28:15 +00003007 IIC_iCMOVi, "mvn", "\t$Rd, $imm",
Owen Anderson8ee97792010-11-18 21:46:31 +00003008[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm_not:$imm,
Evan Cheng875a6ac2010-11-12 22:42:47 +00003009 imm:$cc, CCR:$ccr))*/]>,
Owen Anderson8ee97792010-11-18 21:46:31 +00003010 RegConstraint<"$false = $Rd"> {
Evan Cheng875a6ac2010-11-12 22:42:47 +00003011 let Inst{31-27} = 0b11110;
3012 let Inst{25} = 0;
3013 let Inst{24-21} = 0b0011;
3014 let Inst{20} = 0; // The S bit.
3015 let Inst{19-16} = 0b1111; // Rn
3016 let Inst{15} = 0;
3017}
3018
Johnny Chend68e1192009-12-15 17:24:14 +00003019class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
3020 string opc, string asm, list<dag> pattern>
Owen Andersonbb6315d2010-11-15 19:58:36 +00003021 : T2TwoRegShiftImm<oops, iops, itin, opc, asm, pattern> {
Johnny Chend68e1192009-12-15 17:24:14 +00003022 let Inst{31-27} = 0b11101;
3023 let Inst{26-25} = 0b01;
3024 let Inst{24-21} = 0b0010;
3025 let Inst{20} = 0; // The S bit.
3026 let Inst{19-16} = 0b1111; // Rn
3027 let Inst{5-4} = opcod; // Shift type.
3028}
Owen Andersonbb6315d2010-11-15 19:58:36 +00003029def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$Rd),
3030 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
3031 IIC_iCMOVsi, "lsl", ".w\t$Rd, $Rm, $imm", []>,
3032 RegConstraint<"$false = $Rd">;
3033def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$Rd),
3034 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
3035 IIC_iCMOVsi, "lsr", ".w\t$Rd, $Rm, $imm", []>,
3036 RegConstraint<"$false = $Rd">;
3037def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$Rd),
3038 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
3039 IIC_iCMOVsi, "asr", ".w\t$Rd, $Rm, $imm", []>,
3040 RegConstraint<"$false = $Rd">;
3041def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$Rd),
3042 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
3043 IIC_iCMOVsi, "ror", ".w\t$Rd, $Rm, $imm", []>,
3044 RegConstraint<"$false = $Rd">;
Evan Cheng03a18522012-03-20 21:28:05 +00003045} // isCodeGenOnly = 1
Evan Chengc892aeb2012-02-23 01:19:06 +00003046
Jim Grosbachefeedce2011-07-01 17:14:11 +00003047} // neverHasSideEffects
Evan Cheng13f8b362009-08-01 01:43:45 +00003048
David Goodwin5e47a9a2009-06-30 18:04:13 +00003049//===----------------------------------------------------------------------===//
Jim Grosbachc219e4d2009-12-14 18:56:47 +00003050// Atomic operations intrinsics
3051//
3052
3053// memory barriers protect the atomic sequences
3054let hasSideEffects = 1 in {
Bob Wilsonf74a4292010-10-30 00:54:37 +00003055def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
3056 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
3057 Requires<[IsThumb, HasDB]> {
3058 bits<4> opt;
3059 let Inst{31-4} = 0xf3bf8f5;
3060 let Inst{3-0} = opt;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00003061}
3062}
3063
Bob Wilsonf74a4292010-10-30 00:54:37 +00003064def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
Jim Grosbachaa833e52011-09-06 22:53:27 +00003065 "dsb", "\t$opt", []>,
Bob Wilsonf74a4292010-10-30 00:54:37 +00003066 Requires<[IsThumb, HasDB]> {
3067 bits<4> opt;
3068 let Inst{31-4} = 0xf3bf8f4;
3069 let Inst{3-0} = opt;
Johnny Chena4339822010-03-03 00:16:28 +00003070}
3071
Jim Grosbachaa833e52011-09-06 22:53:27 +00003072def t2ISB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
3073 "isb", "\t$opt",
Evan Cheng97a45432012-04-27 01:27:19 +00003074 []>, Requires<[IsThumb, HasDB]> {
Jim Grosbachaa833e52011-09-06 22:53:27 +00003075 bits<4> opt;
Bob Wilsonf74a4292010-10-30 00:54:37 +00003076 let Inst{31-4} = 0xf3bf8f6;
Jim Grosbachaa833e52011-09-06 22:53:27 +00003077 let Inst{3-0} = opt;
Johnny Chena4339822010-03-03 00:16:28 +00003078}
3079
Owen Anderson16884412011-07-13 23:22:26 +00003080class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz,
Johnny Chend68e1192009-12-15 17:24:14 +00003081 InstrItinClass itin, string opc, string asm, string cstr,
3082 list<dag> pattern, bits<4> rt2 = 0b1111>
3083 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3084 let Inst{31-27} = 0b11101;
3085 let Inst{26-20} = 0b0001101;
3086 let Inst{11-8} = rt2;
3087 let Inst{7-6} = 0b01;
3088 let Inst{5-4} = opcod;
3089 let Inst{3-0} = 0b1111;
Jim Grosbach7a088642010-11-19 17:11:02 +00003090
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00003091 bits<4> addr;
Owen Anderson91a7c592010-11-19 00:28:38 +00003092 bits<4> Rt;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00003093 let Inst{19-16} = addr;
Jim Grosbach86386922010-12-08 22:10:43 +00003094 let Inst{15-12} = Rt;
Johnny Chend68e1192009-12-15 17:24:14 +00003095}
Owen Anderson16884412011-07-13 23:22:26 +00003096class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz,
Johnny Chend68e1192009-12-15 17:24:14 +00003097 InstrItinClass itin, string opc, string asm, string cstr,
3098 list<dag> pattern, bits<4> rt2 = 0b1111>
3099 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
3100 let Inst{31-27} = 0b11101;
3101 let Inst{26-20} = 0b0001100;
3102 let Inst{11-8} = rt2;
3103 let Inst{7-6} = 0b01;
3104 let Inst{5-4} = opcod;
Jim Grosbach7a088642010-11-19 17:11:02 +00003105
Owen Anderson91a7c592010-11-19 00:28:38 +00003106 bits<4> Rd;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00003107 bits<4> addr;
Owen Anderson91a7c592010-11-19 00:28:38 +00003108 bits<4> Rt;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00003109 let Inst{3-0} = Rd;
3110 let Inst{19-16} = addr;
Jim Grosbach86386922010-12-08 22:10:43 +00003111 let Inst{15-12} = Rt;
Johnny Chend68e1192009-12-15 17:24:14 +00003112}
3113
Jim Grosbachc219e4d2009-12-14 18:56:47 +00003114let mayLoad = 1 in {
Jim Grosbachb6aed502011-09-09 18:37:27 +00003115def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00003116 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00003117 "ldrexb", "\t$Rt, $addr", "", []>;
Jim Grosbachb6aed502011-09-09 18:37:27 +00003118def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00003119 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00003120 "ldrexh", "\t$Rt, $addr", "", []>;
Jim Grosbachb6aed502011-09-09 18:37:27 +00003121def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00003122 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00003123 "ldrex", "\t$Rt, $addr", "", []> {
Jim Grosbachb6aed502011-09-09 18:37:27 +00003124 bits<4> Rt;
3125 bits<12> addr;
Johnny Chend68e1192009-12-15 17:24:14 +00003126 let Inst{31-27} = 0b11101;
3127 let Inst{26-20} = 0b0000101;
Jim Grosbachb6aed502011-09-09 18:37:27 +00003128 let Inst{19-16} = addr{11-8};
Owen Anderson808c7d12010-12-10 21:52:38 +00003129 let Inst{15-12} = Rt;
Jim Grosbachb6aed502011-09-09 18:37:27 +00003130 let Inst{11-8} = 0b1111;
3131 let Inst{7-0} = addr{7-0};
Johnny Chend68e1192009-12-15 17:24:14 +00003132}
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00003133let hasExtraDefRegAllocReq = 1 in
3134def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$Rt, rGPR:$Rt2),
Jim Grosbachb6aed502011-09-09 18:37:27 +00003135 (ins addr_offset_none:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00003136 AddrModeNone, 4, NoItinerary,
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00003137 "ldrexd", "\t$Rt, $Rt2, $addr", "",
Owen Anderson91a7c592010-11-19 00:28:38 +00003138 [], {?, ?, ?, ?}> {
3139 bits<4> Rt2;
Jim Grosbach86386922010-12-08 22:10:43 +00003140 let Inst{11-8} = Rt2;
Owen Anderson91a7c592010-11-19 00:28:38 +00003141}
Jim Grosbachc219e4d2009-12-14 18:56:47 +00003142}
3143
Owen Anderson91a7c592010-11-19 00:28:38 +00003144let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00003145def t2STREXB : T2I_strex<0b00, (outs rGPR:$Rd),
Jim Grosbachb6aed502011-09-09 18:37:27 +00003146 (ins rGPR:$Rt, addr_offset_none:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00003147 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00003148 "strexb", "\t$Rd, $Rt, $addr", "", []>;
3149def t2STREXH : T2I_strex<0b01, (outs rGPR:$Rd),
Jim Grosbachb6aed502011-09-09 18:37:27 +00003150 (ins rGPR:$Rt, addr_offset_none:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00003151 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00003152 "strexh", "\t$Rd, $Rt, $addr", "", []>;
Jim Grosbachb6aed502011-09-09 18:37:27 +00003153def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
3154 t2addrmode_imm0_1020s4:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00003155 AddrModeNone, 4, NoItinerary,
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00003156 "strex", "\t$Rd, $Rt, $addr", "",
3157 []> {
Jim Grosbachb6aed502011-09-09 18:37:27 +00003158 bits<4> Rd;
3159 bits<4> Rt;
3160 bits<12> addr;
Johnny Chend68e1192009-12-15 17:24:14 +00003161 let Inst{31-27} = 0b11101;
3162 let Inst{26-20} = 0b0000100;
Jim Grosbachb6aed502011-09-09 18:37:27 +00003163 let Inst{19-16} = addr{11-8};
Owen Anderson808c7d12010-12-10 21:52:38 +00003164 let Inst{15-12} = Rt;
Jim Grosbachb6aed502011-09-09 18:37:27 +00003165 let Inst{11-8} = Rd;
3166 let Inst{7-0} = addr{7-0};
Johnny Chend68e1192009-12-15 17:24:14 +00003167}
Anton Korobeynikov2c6d0f22012-01-23 22:57:52 +00003168let hasExtraSrcRegAllocReq = 1 in
Owen Anderson91a7c592010-11-19 00:28:38 +00003169def t2STREXD : T2I_strex<0b11, (outs rGPR:$Rd),
Jim Grosbachb6aed502011-09-09 18:37:27 +00003170 (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00003171 AddrModeNone, 4, NoItinerary,
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00003172 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
Owen Anderson91a7c592010-11-19 00:28:38 +00003173 {?, ?, ?, ?}> {
3174 bits<4> Rt2;
Jim Grosbach86386922010-12-08 22:10:43 +00003175 let Inst{11-8} = Rt2;
Owen Anderson91a7c592010-11-19 00:28:38 +00003176}
Anton Korobeynikov2c6d0f22012-01-23 22:57:52 +00003177}
Jim Grosbachc219e4d2009-12-14 18:56:47 +00003178
Jim Grosbachad2dad92011-09-06 20:27:04 +00003179def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", []>,
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00003180 Requires<[IsThumb2, HasV7]> {
3181 let Inst{31-16} = 0xf3bf;
Johnny Chen10a77e12010-03-02 22:11:06 +00003182 let Inst{15-14} = 0b10;
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00003183 let Inst{13} = 0;
Johnny Chen10a77e12010-03-02 22:11:06 +00003184 let Inst{12} = 0;
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00003185 let Inst{11-8} = 0b1111;
Johnny Chen10a77e12010-03-02 22:11:06 +00003186 let Inst{7-4} = 0b0010;
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00003187 let Inst{3-0} = 0b1111;
Johnny Chen10a77e12010-03-02 22:11:06 +00003188}
3189
Jim Grosbachc219e4d2009-12-14 18:56:47 +00003190//===----------------------------------------------------------------------===//
Jim Grosbach5aa16842009-08-11 19:42:21 +00003191// SJLJ Exception handling intrinsics
Jim Grosbach1add6592009-08-13 15:11:43 +00003192// eh_sjlj_setjmp() is an instruction sequence to store the return
Jim Grosbach5aa16842009-08-11 19:42:21 +00003193// address and save #0 in R0 for the non-longjmp case.
3194// Since by its nature we may be coming from some other function to get
3195// here, and we're using the stack frame for the containing function to
3196// save/restore registers, we can't keep anything live in regs across
3197// the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
Chris Lattner7a2bdde2011-04-15 05:18:47 +00003198// when we get here from a longjmp(). We force everything out of registers
Jim Grosbach5aa16842009-08-11 19:42:21 +00003199// except for our own input by listing the relevant registers in Defs. By
3200// doing so, we also cause the prologue/epilogue code to actively preserve
3201// all of the callee-saved resgisters, which is exactly what we want.
Jim Grosbach0798edd2010-05-27 23:49:24 +00003202// $val is a scratch register for our use.
Jim Grosbacha87ded22010-02-08 23:22:00 +00003203let Defs =
Andrew Tricka1099f12011-06-07 00:08:49 +00003204 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
Jakob Stoklund Olesenece8b732012-01-13 22:55:42 +00003205 Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15],
Bill Wendling13a71212011-10-17 22:26:23 +00003206 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3207 usesCustomInserter = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00003208 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Owen Anderson16884412011-07-13 23:22:26 +00003209 AddrModeNone, 0, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00003210 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00003211 Requires<[IsThumb2, HasVFP2]>;
Jim Grosbach5aa16842009-08-11 19:42:21 +00003212}
3213
Bob Wilsonec80e262010-04-09 20:41:18 +00003214let Defs =
Andrew Tricka1099f12011-06-07 00:08:49 +00003215 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
Bill Wendling13a71212011-10-17 22:26:23 +00003216 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
3217 usesCustomInserter = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00003218 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Owen Anderson16884412011-07-13 23:22:26 +00003219 AddrModeNone, 0, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00003220 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00003221 Requires<[IsThumb2, NoVFP]>;
3222}
Jim Grosbach5aa16842009-08-11 19:42:21 +00003223
3224
3225//===----------------------------------------------------------------------===//
David Goodwin5e47a9a2009-06-30 18:04:13 +00003226// Control-Flow Instructions
3227//
3228
Evan Chengc50a1cb2009-07-09 22:58:39 +00003229// FIXME: remove when we have a way to marking a MI with these properties.
Evan Chengc50a1cb2009-07-09 22:58:39 +00003230// FIXME: Should pc be an implicit operand like PICADD, etc?
Evan Cheng0d92f5f2009-10-01 08:22:27 +00003231let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
Chris Lattner39ee0362010-10-31 19:10:56 +00003232 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
Jim Grosbach53e3fc42011-07-08 17:40:42 +00003233def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
Jim Grosbach16f99242011-06-30 18:25:42 +00003234 reglist:$regs, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +00003235 4, IIC_iLoad_mBr, [],
Jim Grosbach53e3fc42011-07-08 17:40:42 +00003236 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
Jim Grosbach16f99242011-06-30 18:25:42 +00003237 RegConstraint<"$Rn = $wb">;
Evan Chengc50a1cb2009-07-09 22:58:39 +00003238
David Goodwin5e47a9a2009-06-30 18:04:13 +00003239let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
3240let isPredicable = 1 in
Owen Anderson51f6a7a2011-09-09 21:48:23 +00003241def t2B : T2I<(outs), (ins uncondbrtarget:$target), IIC_Br,
3242 "b", ".w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00003243 [(br bb:$target)]> {
3244 let Inst{31-27} = 0b11110;
3245 let Inst{15-14} = 0b10;
3246 let Inst{12} = 1;
Owen Anderson05bf5952010-11-29 18:54:38 +00003247
3248 bits<20> target;
3249 let Inst{26} = target{19};
3250 let Inst{11} = target{18};
3251 let Inst{13} = target{17};
3252 let Inst{21-16} = target{16-11};
3253 let Inst{10-0} = target{10-0};
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003254 let DecoderMethod = "DecodeT2BInstruction";
Johnny Chend68e1192009-12-15 17:24:14 +00003255}
David Goodwin5e47a9a2009-06-30 18:04:13 +00003256
Jim Grosbacha0bb2532010-11-29 22:40:58 +00003257let isNotDuplicable = 1, isIndirectBranch = 1 in {
Jim Grosbachd4811102010-12-15 19:03:16 +00003258def t2BR_JT : t2PseudoInst<(outs),
Jim Grosbach5ca66692010-11-29 22:37:40 +00003259 (ins GPR:$target, GPR:$index, i32imm:$jt, i32imm:$id),
Owen Anderson16884412011-07-13 23:22:26 +00003260 0, IIC_Br,
Jim Grosbach5ca66692010-11-29 22:37:40 +00003261 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>;
Evan Cheng5657c012009-07-29 02:18:14 +00003262
Evan Cheng25f7cfc2009-08-01 06:13:52 +00003263// FIXME: Add a non-pc based case that can be predicated.
Jim Grosbachd4811102010-12-15 19:03:16 +00003264def t2TBB_JT : t2PseudoInst<(outs),
Jim Grosbachbc80e942011-09-19 20:31:59 +00003265 (ins GPR:$index, i32imm:$jt, i32imm:$id), 0, IIC_Br, []>;
Jim Grosbach5ca66692010-11-29 22:37:40 +00003266
Jim Grosbachd4811102010-12-15 19:03:16 +00003267def t2TBH_JT : t2PseudoInst<(outs),
Jim Grosbachbc80e942011-09-19 20:31:59 +00003268 (ins GPR:$index, i32imm:$jt, i32imm:$id), 0, IIC_Br, []>;
Jim Grosbach5ca66692010-11-29 22:37:40 +00003269
Jim Grosbach7f739be2011-09-19 22:21:13 +00003270def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
3271 "tbb", "\t$addr", []> {
Jim Grosbach5ca66692010-11-29 22:37:40 +00003272 bits<4> Rn;
3273 bits<4> Rm;
Jim Grosbachf0db2612010-12-17 18:42:56 +00003274 let Inst{31-20} = 0b111010001101;
Jim Grosbach5ca66692010-11-29 22:37:40 +00003275 let Inst{19-16} = Rn;
3276 let Inst{15-5} = 0b11110000000;
3277 let Inst{4} = 0; // B form
3278 let Inst{3-0} = Rm;
Jim Grosbach7f739be2011-09-19 22:21:13 +00003279
3280 let DecoderMethod = "DecodeThumbTableBranch";
Johnny Chend68e1192009-12-15 17:24:14 +00003281}
Evan Cheng5657c012009-07-29 02:18:14 +00003282
Jim Grosbach7f739be2011-09-19 22:21:13 +00003283def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
3284 "tbh", "\t$addr", []> {
Jim Grosbach5ca66692010-11-29 22:37:40 +00003285 bits<4> Rn;
3286 bits<4> Rm;
Jim Grosbachf0db2612010-12-17 18:42:56 +00003287 let Inst{31-20} = 0b111010001101;
Jim Grosbach5ca66692010-11-29 22:37:40 +00003288 let Inst{19-16} = Rn;
3289 let Inst{15-5} = 0b11110000000;
3290 let Inst{4} = 1; // H form
3291 let Inst{3-0} = Rm;
Jim Grosbach7f739be2011-09-19 22:21:13 +00003292
3293 let DecoderMethod = "DecodeThumbTableBranch";
Johnny Chen93042d12010-03-02 18:14:57 +00003294}
Evan Cheng5657c012009-07-29 02:18:14 +00003295} // isNotDuplicable, isIndirectBranch
3296
David Goodwinc9a59b52009-06-30 19:50:22 +00003297} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +00003298
3299// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Owen Anderson51f6a7a2011-09-09 21:48:23 +00003300// a two-value operand where a dag node expects ", "two operands. :(
David Goodwin5e47a9a2009-06-30 18:04:13 +00003301let isBranch = 1, isTerminator = 1 in
David Goodwin8b7d7ad2009-08-06 16:52:47 +00003302def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00003303 "b", ".w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00003304 [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
3305 let Inst{31-27} = 0b11110;
3306 let Inst{15-14} = 0b10;
3307 let Inst{12} = 0;
Jim Grosbach00f25fa2010-12-14 20:46:39 +00003308
Owen Andersonfb20d892010-12-09 00:27:41 +00003309 bits<4> p;
3310 let Inst{25-22} = p;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003311
Owen Andersonfb20d892010-12-09 00:27:41 +00003312 bits<21> target;
3313 let Inst{26} = target{20};
3314 let Inst{11} = target{19};
3315 let Inst{13} = target{18};
3316 let Inst{21-16} = target{17-12};
3317 let Inst{10-0} = target{11-1};
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003318
3319 let DecoderMethod = "DecodeThumb2BCCInstruction";
Johnny Chend68e1192009-12-15 17:24:14 +00003320}
Evan Chengf49810c2009-06-23 17:48:47 +00003321
Evan Chengafff9412011-12-20 18:26:50 +00003322// Tail calls. The IOS version of thumb tail calls uses a t2 branch, so
Jim Grosbachaf7f2d62011-07-08 20:32:21 +00003323// it goes here.
3324let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
Evan Chengafff9412011-12-20 18:26:50 +00003325 // IOS version.
Jakob Stoklund Olesenc54f6342012-02-24 01:19:29 +00003326 let Uses = [SP] in
Owen Anderson51f6a7a2011-09-09 21:48:23 +00003327 def tTAILJMPd: tPseudoExpand<(outs),
Jakob Stoklund Olesen135fb452012-07-13 20:27:00 +00003328 (ins uncondbrtarget:$dst, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00003329 4, IIC_Br, [],
Owen Anderson51f6a7a2011-09-09 21:48:23 +00003330 (t2B uncondbrtarget:$dst, pred:$p)>,
Evan Chengafff9412011-12-20 18:26:50 +00003331 Requires<[IsThumb2, IsIOS]>;
Jim Grosbachaf7f2d62011-07-08 20:32:21 +00003332}
Evan Cheng06e16582009-07-10 01:54:42 +00003333
Jakob Stoklund Olesenf16936e2012-04-06 00:04:58 +00003334let isCall = 1, Defs = [LR], Uses = [SP] in {
Evan Cheng4bfcd4a2012-02-28 18:51:51 +00003335 // mov lr, pc; b if callee is marked noreturn to avoid confusing the
3336 // return stack predictor.
3337 def t2BMOVPCB_CALL : tPseudoInst<(outs),
Jakob Stoklund Olesen135fb452012-07-13 20:27:00 +00003338 (ins t_bltarget:$func),
Evan Cheng4bfcd4a2012-02-28 18:51:51 +00003339 6, IIC_Br, [(ARMcall_nolink tglobaladdr:$func)]>,
Jakob Stoklund Olesenf16936e2012-04-06 00:04:58 +00003340 Requires<[IsThumb]>;
Evan Cheng4bfcd4a2012-02-28 18:51:51 +00003341}
3342
3343// Direct calls
3344def : T2Pat<(ARMcall_nolink texternalsym:$func),
3345 (t2BMOVPCB_CALL texternalsym:$func)>,
Jakob Stoklund Olesenf16936e2012-04-06 00:04:58 +00003346 Requires<[IsThumb]>;
Evan Cheng4bfcd4a2012-02-28 18:51:51 +00003347
Evan Cheng06e16582009-07-10 01:54:42 +00003348// IT block
Evan Cheng86050dc2010-06-18 23:09:54 +00003349let Defs = [ITSTATE] in
Evan Cheng06e16582009-07-10 01:54:42 +00003350def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
Owen Anderson16884412011-07-13 23:22:26 +00003351 AddrModeNone, 2, IIC_iALUx,
Johnny Chend68e1192009-12-15 17:24:14 +00003352 "it$mask\t$cc", "", []> {
3353 // 16-bit instruction.
Johnny Chenbbc71b22009-12-16 02:32:54 +00003354 let Inst{31-16} = 0x0000;
Johnny Chend68e1192009-12-15 17:24:14 +00003355 let Inst{15-8} = 0b10111111;
Owen Anderson05bf5952010-11-29 18:54:38 +00003356
3357 bits<4> cc;
3358 bits<4> mask;
Jim Grosbach86386922010-12-08 22:10:43 +00003359 let Inst{7-4} = cc;
3360 let Inst{3-0} = mask;
Owen Andersoneaca9282011-08-30 22:58:27 +00003361
3362 let DecoderMethod = "DecodeIT";
Johnny Chend68e1192009-12-15 17:24:14 +00003363}
Evan Cheng06e16582009-07-10 01:54:42 +00003364
Johnny Chence6275f2010-02-25 19:05:29 +00003365// Branch and Exchange Jazelle -- for disassembly only
3366// Rm = Inst{19-16}
Jim Grosbach6c3e11e2011-09-02 23:43:09 +00003367def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func", []> {
3368 bits<4> func;
Johnny Chence6275f2010-02-25 19:05:29 +00003369 let Inst{31-27} = 0b11110;
3370 let Inst{26} = 0;
3371 let Inst{25-20} = 0b111100;
Jim Grosbach86386922010-12-08 22:10:43 +00003372 let Inst{19-16} = func;
Jim Grosbach6c3e11e2011-09-02 23:43:09 +00003373 let Inst{15-0} = 0b1000111100000000;
Johnny Chence6275f2010-02-25 19:05:29 +00003374}
3375
Jim Grosbach11cca7a2011-08-18 17:51:36 +00003376// Compare and branch on zero / non-zero
3377let isBranch = 1, isTerminator = 1 in {
3378 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
3379 "cbz\t$Rn, $target", []>,
3380 T1Misc<{0,0,?,1,?,?,?}>,
3381 Requires<[IsThumb2]> {
3382 // A8.6.27
3383 bits<6> target;
3384 bits<3> Rn;
3385 let Inst{9} = target{5};
3386 let Inst{7-3} = target{4-0};
3387 let Inst{2-0} = Rn;
3388 }
3389
3390 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
3391 "cbnz\t$Rn, $target", []>,
3392 T1Misc<{1,0,?,1,?,?,?}>,
3393 Requires<[IsThumb2]> {
3394 // A8.6.27
3395 bits<6> target;
3396 bits<3> Rn;
3397 let Inst{9} = target{5};
3398 let Inst{7-3} = target{4-0};
3399 let Inst{2-0} = Rn;
3400 }
3401}
3402
3403
Jim Grosbach32f36892011-09-19 23:38:34 +00003404// Change Processor State is a system instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003405// FIXME: Since the asm parser has currently no clean way to handle optional
3406// operands, create 3 versions of the same instruction. Once there's a clean
3407// framework to represent optional operands, change this behavior.
3408class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
Jim Grosbach32f36892011-09-19 23:38:34 +00003409 !strconcat("cps", asm_op), []> {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003410 bits<2> imod;
3411 bits<3> iflags;
3412 bits<5> mode;
3413 bit M;
3414
Johnny Chen93042d12010-03-02 18:14:57 +00003415 let Inst{31-27} = 0b11110;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003416 let Inst{26} = 0;
Johnny Chen93042d12010-03-02 18:14:57 +00003417 let Inst{25-20} = 0b111010;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003418 let Inst{19-16} = 0b1111;
Johnny Chen93042d12010-03-02 18:14:57 +00003419 let Inst{15-14} = 0b10;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003420 let Inst{12} = 0;
3421 let Inst{10-9} = imod;
3422 let Inst{8} = M;
3423 let Inst{7-5} = iflags;
3424 let Inst{4-0} = mode;
Owen Anderson6153a032011-08-23 17:45:18 +00003425 let DecoderMethod = "DecodeT2CPSInstruction";
Johnny Chen93042d12010-03-02 18:14:57 +00003426}
3427
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003428let M = 1 in
3429 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3430 "$imod.w\t$iflags, $mode">;
3431let mode = 0, M = 0 in
3432 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3433 "$imod.w\t$iflags">;
3434let imod = 0, iflags = 0, M = 1 in
Jim Grosbach0efe2132011-09-19 23:58:31 +00003435 def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003436
Johnny Chen0f7866e2010-03-03 02:09:43 +00003437// A6.3.4 Branches and miscellaneous control
3438// Table A6-14 Change Processor State, and hint instructions
Jim Grosbach7e99a602012-06-18 19:45:50 +00003439def t2HINT : T2I<(outs), (ins imm0_255:$imm), NoItinerary, "hint", "\t$imm",[]>{
3440 bits<8> imm;
3441 let Inst{31-8} = 0b111100111010111110000000;
3442 let Inst{7-0} = imm;
Johnny Chen0f7866e2010-03-03 02:09:43 +00003443}
3444
Jim Grosbach7e99a602012-06-18 19:45:50 +00003445def : t2InstAlias<"hint$p.w $imm", (t2HINT imm0_255:$imm, pred:$p)>;
3446def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p)>;
3447def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p)>;
3448def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p)>;
3449def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p)>;
3450def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p)>;
Johnny Chen0f7866e2010-03-03 02:09:43 +00003451
Jim Grosbach6f9f8842011-07-13 22:59:38 +00003452def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt", []> {
Owen Andersonc7373f82010-11-30 20:00:01 +00003453 bits<4> opt;
Jim Grosbach77951902011-09-06 22:06:40 +00003454 let Inst{31-20} = 0b111100111010;
3455 let Inst{19-16} = 0b1111;
3456 let Inst{15-8} = 0b10000000;
3457 let Inst{7-4} = 0b1111;
Jim Grosbach86386922010-12-08 22:10:43 +00003458 let Inst{3-0} = opt;
Johnny Chen0f7866e2010-03-03 02:09:43 +00003459}
3460
Jim Grosbach32f36892011-09-19 23:38:34 +00003461// Secure Monitor Call is a system instruction.
Johnny Chen6341c5a2010-02-25 20:25:24 +00003462// Option = Inst{19-16}
Jim Grosbach32f36892011-09-19 23:38:34 +00003463def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt", []> {
Johnny Chen6341c5a2010-02-25 20:25:24 +00003464 let Inst{31-27} = 0b11110;
3465 let Inst{26-20} = 0b1111111;
3466 let Inst{15-12} = 0b1000;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003467
Owen Andersond18a9c92010-11-29 19:22:08 +00003468 bits<4> opt;
Jim Grosbach86386922010-12-08 22:10:43 +00003469 let Inst{19-16} = opt;
Owen Andersond18a9c92010-11-29 19:22:08 +00003470}
3471
Jim Grosbach05ec8f72011-09-16 18:25:22 +00003472class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
3473 string opc, string asm, list<dag> pattern>
Owen Andersond18a9c92010-11-29 19:22:08 +00003474 : T2I<oops, iops, itin, opc, asm, pattern> {
3475 bits<5> mode;
Jim Grosbach05ec8f72011-09-16 18:25:22 +00003476 let Inst{31-25} = 0b1110100;
3477 let Inst{24-23} = Op;
3478 let Inst{22} = 0;
3479 let Inst{21} = W;
3480 let Inst{20-16} = 0b01101;
3481 let Inst{15-5} = 0b11000000000;
Owen Andersond18a9c92010-11-29 19:22:08 +00003482 let Inst{4-0} = mode{4-0};
Johnny Chen6341c5a2010-02-25 20:25:24 +00003483}
3484
Jim Grosbach05ec8f72011-09-16 18:25:22 +00003485// Store Return State is a system instruction.
3486def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3487 "srsdb", "\tsp!, $mode", []>;
3488def t2SRSDB : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3489 "srsdb","\tsp, $mode", []>;
3490def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
3491 "srsia","\tsp!, $mode", []>;
3492def t2SRSIA : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
3493 "srsia","\tsp, $mode", []>;
Johnny Chen6341c5a2010-02-25 20:25:24 +00003494
Jim Grosbach05ec8f72011-09-16 18:25:22 +00003495// Return From Exception is a system instruction.
Owen Anderson5404c2b2010-11-29 20:38:48 +00003496class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
Owen Andersond18a9c92010-11-29 19:22:08 +00003497 string opc, string asm, list<dag> pattern>
3498 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson5404c2b2010-11-29 20:38:48 +00003499 let Inst{31-20} = op31_20{11-0};
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003500
Owen Andersond18a9c92010-11-29 19:22:08 +00003501 bits<4> Rn;
Jim Grosbach86386922010-12-08 22:10:43 +00003502 let Inst{19-16} = Rn;
Johnny Chenec51a622011-04-12 21:41:51 +00003503 let Inst{15-0} = 0xc000;
Owen Andersond18a9c92010-11-29 19:22:08 +00003504}
3505
Owen Anderson5404c2b2010-11-29 20:38:48 +00003506def t2RFEDBW : T2RFE<0b111010000011,
Johnny Chenec51a622011-04-12 21:41:51 +00003507 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003508 [/* For disassembly only; pattern left blank */]>;
3509def t2RFEDB : T2RFE<0b111010000001,
Johnny Chenec51a622011-04-12 21:41:51 +00003510 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003511 [/* For disassembly only; pattern left blank */]>;
3512def t2RFEIAW : T2RFE<0b111010011011,
Johnny Chenec51a622011-04-12 21:41:51 +00003513 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003514 [/* For disassembly only; pattern left blank */]>;
3515def t2RFEIA : T2RFE<0b111010011001,
Johnny Chenec51a622011-04-12 21:41:51 +00003516 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003517 [/* For disassembly only; pattern left blank */]>;
Johnny Chen6341c5a2010-02-25 20:25:24 +00003518
Evan Chengf49810c2009-06-23 17:48:47 +00003519//===----------------------------------------------------------------------===//
3520// Non-Instruction Patterns
3521//
3522
Evan Cheng5adb66a2009-09-28 09:14:39 +00003523// 32-bit immediate using movw + movt.
Evan Cheng5be39222010-09-24 22:03:46 +00003524// This is a single pseudo instruction to make it re-materializable.
3525// FIXME: Remove this when we can do generalized remat.
Evan Chengfc8475b2011-01-19 02:16:49 +00003526let isReMaterializable = 1, isMoveImm = 1 in
Jim Grosbach3c38f962010-10-06 22:01:26 +00003527def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
Jim Grosbach99594eb2010-11-18 01:38:26 +00003528 [(set rGPR:$dst, (i32 imm:$src))]>,
Jim Grosbach3c38f962010-10-06 22:01:26 +00003529 Requires<[IsThumb, HasV6T2]>;
Evan Chengb9803a82009-11-06 23:52:48 +00003530
Evan Cheng53519f02011-01-21 18:55:51 +00003531// Pseudo instruction that combines movw + movt + add pc (if pic).
Evan Cheng9fe20092011-01-20 08:34:58 +00003532// It also makes it possible to rematerialize the instructions.
3533// FIXME: Remove this when we can do generalized remat and when machine licm
3534// can properly the instructions.
Evan Cheng53519f02011-01-21 18:55:51 +00003535let isReMaterializable = 1 in {
3536def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3537 IIC_iMOVix2addpc,
Evan Cheng9fe20092011-01-20 08:34:58 +00003538 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
3539 Requires<[IsThumb2, UseMovt]>;
Evan Cheng5de5d4b2011-01-17 08:03:18 +00003540
Evan Cheng53519f02011-01-21 18:55:51 +00003541def t2MOV_ga_dyn : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3542 IIC_iMOVix2,
3543 [(set rGPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
3544 Requires<[IsThumb2, UseMovt]>;
3545}
3546
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00003547// ConstantPool, GlobalAddress, and JumpTable
3548def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
3549 Requires<[IsThumb2, DontUseMovt]>;
3550def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
3551def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
3552 Requires<[IsThumb2, UseMovt]>;
3553
3554def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
3555 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
3556
Evan Chengb9803a82009-11-06 23:52:48 +00003557// Pseudo instruction that combines ldr from constpool and add pc. This should
3558// be expanded into two instructions late to allow if-conversion and
3559// scheduling.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00003560let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng9fe20092011-01-20 08:34:58 +00003561def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Jim Grosbach99594eb2010-11-18 01:38:26 +00003562 IIC_iLoadiALU,
Evan Cheng9fe20092011-01-20 08:34:58 +00003563 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
Evan Chengb9803a82009-11-06 23:52:48 +00003564 imm:$cp))]>,
3565 Requires<[IsThumb2]>;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00003566
Andrew Trick7f5f0da2011-10-18 18:40:53 +00003567// Pseudo isntruction that combines movs + predicated rsbmi
Bill Wendlingef2c86f2011-10-10 22:59:55 +00003568// to implement integer ABS
3569let usesCustomInserter = 1, Defs = [CPSR] in {
3570def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
3571 NoItinerary, []>, Requires<[IsThumb2]>;
3572}
3573
Owen Anderson8a83f712011-09-07 21:10:42 +00003574//===----------------------------------------------------------------------===//
3575// Coprocessor load/store -- for disassembly only
3576//
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003577class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm>
Owen Anderson8a83f712011-09-07 21:10:42 +00003578 : T2I<oops, iops, NoItinerary, opc, asm, []> {
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003579 let Inst{31-28} = op31_28;
Owen Anderson8a83f712011-09-07 21:10:42 +00003580 let Inst{27-25} = 0b110;
3581}
3582
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003583multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm> {
3584 def _OFFSET : T2CI<op31_28,
3585 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
3586 asm, "\t$cop, $CRd, $addr"> {
3587 bits<13> addr;
3588 bits<4> cop;
3589 bits<4> CRd;
Owen Anderson8a83f712011-09-07 21:10:42 +00003590 let Inst{24} = 1; // P = 1
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003591 let Inst{23} = addr{8};
3592 let Inst{22} = Dbit;
Owen Anderson8a83f712011-09-07 21:10:42 +00003593 let Inst{21} = 0; // W = 0
Owen Anderson8a83f712011-09-07 21:10:42 +00003594 let Inst{20} = load;
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003595 let Inst{19-16} = addr{12-9};
3596 let Inst{15-12} = CRd;
3597 let Inst{11-8} = cop;
3598 let Inst{7-0} = addr{7-0};
Owen Anderson8a83f712011-09-07 21:10:42 +00003599 let DecoderMethod = "DecodeCopMemInstruction";
3600 }
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003601 def _PRE : T2CI<op31_28,
3602 (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
3603 asm, "\t$cop, $CRd, $addr!"> {
3604 bits<13> addr;
3605 bits<4> cop;
3606 bits<4> CRd;
Owen Anderson8a83f712011-09-07 21:10:42 +00003607 let Inst{24} = 1; // P = 1
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003608 let Inst{23} = addr{8};
3609 let Inst{22} = Dbit;
Owen Anderson8a83f712011-09-07 21:10:42 +00003610 let Inst{21} = 1; // W = 1
Owen Anderson8a83f712011-09-07 21:10:42 +00003611 let Inst{20} = load;
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003612 let Inst{19-16} = addr{12-9};
3613 let Inst{15-12} = CRd;
3614 let Inst{11-8} = cop;
3615 let Inst{7-0} = addr{7-0};
Owen Anderson8a83f712011-09-07 21:10:42 +00003616 let DecoderMethod = "DecodeCopMemInstruction";
3617 }
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003618 def _POST: T2CI<op31_28,
3619 (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
3620 postidx_imm8s4:$offset),
3621 asm, "\t$cop, $CRd, $addr, $offset"> {
3622 bits<9> offset;
3623 bits<4> addr;
3624 bits<4> cop;
3625 bits<4> CRd;
Owen Anderson8a83f712011-09-07 21:10:42 +00003626 let Inst{24} = 0; // P = 0
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003627 let Inst{23} = offset{8};
3628 let Inst{22} = Dbit;
Owen Anderson8a83f712011-09-07 21:10:42 +00003629 let Inst{21} = 1; // W = 1
Owen Anderson8a83f712011-09-07 21:10:42 +00003630 let Inst{20} = load;
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003631 let Inst{19-16} = addr;
3632 let Inst{15-12} = CRd;
3633 let Inst{11-8} = cop;
3634 let Inst{7-0} = offset{7-0};
Owen Anderson8a83f712011-09-07 21:10:42 +00003635 let DecoderMethod = "DecodeCopMemInstruction";
3636 }
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003637 def _OPTION : T2CI<op31_28, (outs),
3638 (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
3639 coproc_option_imm:$option),
3640 asm, "\t$cop, $CRd, $addr, $option"> {
3641 bits<8> option;
3642 bits<4> addr;
3643 bits<4> cop;
3644 bits<4> CRd;
Owen Anderson8a83f712011-09-07 21:10:42 +00003645 let Inst{24} = 0; // P = 0
3646 let Inst{23} = 1; // U = 1
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003647 let Inst{22} = Dbit;
Owen Anderson8a83f712011-09-07 21:10:42 +00003648 let Inst{21} = 0; // W = 0
Owen Anderson8a83f712011-09-07 21:10:42 +00003649 let Inst{20} = load;
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003650 let Inst{19-16} = addr;
3651 let Inst{15-12} = CRd;
3652 let Inst{11-8} = cop;
3653 let Inst{7-0} = option;
Owen Anderson8a83f712011-09-07 21:10:42 +00003654 let DecoderMethod = "DecodeCopMemInstruction";
3655 }
3656}
3657
Jim Grosbachc66e7af2011-10-12 20:54:17 +00003658defm t2LDC : t2LdStCop<0b1110, 1, 0, "ldc">;
3659defm t2LDCL : t2LdStCop<0b1110, 1, 1, "ldcl">;
3660defm t2STC : t2LdStCop<0b1110, 0, 0, "stc">;
3661defm t2STCL : t2LdStCop<0b1110, 0, 1, "stcl">;
3662defm t2LDC2 : t2LdStCop<0b1111, 1, 0, "ldc2">;
3663defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l">;
3664defm t2STC2 : t2LdStCop<0b1111, 0, 0, "stc2">;
3665defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l">;
Owen Anderson8a83f712011-09-07 21:10:42 +00003666
Johnny Chen23336552010-02-25 18:46:43 +00003667
3668//===----------------------------------------------------------------------===//
3669// Move between special register and ARM core register -- for disassembly only
3670//
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003671// Move to ARM core register from Special Register
James Molloyacad68d2011-09-28 14:21:38 +00003672
3673// A/R class MRS.
3674//
3675// A/R class can only move from CPSR or SPSR.
Jim Grosbachc92ba4e2012-04-23 22:04:10 +00003676def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr",
3677 []>, Requires<[IsThumb2,IsARClass]> {
Owen Anderson00a035f2010-11-29 19:29:15 +00003678 bits<4> Rd;
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003679 let Inst{31-12} = 0b11110011111011111000;
Jim Grosbach86386922010-12-08 22:10:43 +00003680 let Inst{11-8} = Rd;
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003681 let Inst{7-0} = 0b0000;
Owen Anderson00a035f2010-11-29 19:29:15 +00003682}
3683
James Molloyacad68d2011-09-28 14:21:38 +00003684def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003685
Jim Grosbachc92ba4e2012-04-23 22:04:10 +00003686def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
3687 []>, Requires<[IsThumb2,IsARClass]> {
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003688 bits<4> Rd;
3689 let Inst{31-12} = 0b11110011111111111000;
3690 let Inst{11-8} = Rd;
3691 let Inst{7-0} = 0b0000;
3692}
Johnny Chen23336552010-02-25 18:46:43 +00003693
James Molloyacad68d2011-09-28 14:21:38 +00003694// M class MRS.
3695//
3696// This MRS has a mask field in bits 7-0 and can take more values than
3697// the A/R class (a full msr_mask).
3698def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$mask), NoItinerary,
3699 "mrs", "\t$Rd, $mask", []>,
Evan Cheng97a45432012-04-27 01:27:19 +00003700 Requires<[IsThumb,IsMClass]> {
James Molloyacad68d2011-09-28 14:21:38 +00003701 bits<4> Rd;
3702 bits<8> mask;
3703 let Inst{31-12} = 0b11110011111011111000;
3704 let Inst{11-8} = Rd;
3705 let Inst{19-16} = 0b1111;
3706 let Inst{7-0} = mask;
3707}
3708
3709
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003710// Move from ARM core register to Special Register
3711//
James Molloyacad68d2011-09-28 14:21:38 +00003712// A/R class MSR.
3713//
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003714// No need to have both system and application versions, the encodings are the
3715// same and the assembly parser has no way to distinguish between them. The mask
3716// operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
3717// the mask with the fields to be accessed in the special register.
James Molloyacad68d2011-09-28 14:21:38 +00003718def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
3719 NoItinerary, "msr", "\t$mask, $Rn", []>,
3720 Requires<[IsThumb2,IsARClass]> {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003721 bits<5> mask;
Owen Anderson00a035f2010-11-29 19:29:15 +00003722 bits<4> Rn;
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003723 let Inst{31-21} = 0b11110011100;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003724 let Inst{20} = mask{4}; // R Bit
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003725 let Inst{19-16} = Rn;
3726 let Inst{15-12} = 0b1000;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003727 let Inst{11-8} = mask{3-0};
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003728 let Inst{7-0} = 0;
Owen Anderson00a035f2010-11-29 19:29:15 +00003729}
3730
James Molloyacad68d2011-09-28 14:21:38 +00003731// M class MSR.
3732//
3733// Move from ARM core register to Special Register
3734def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
3735 NoItinerary, "msr", "\t$SYSm, $Rn", []>,
Evan Cheng97a45432012-04-27 01:27:19 +00003736 Requires<[IsThumb,IsMClass]> {
Kevin Enderby0fd4f3c2012-05-17 22:18:01 +00003737 bits<12> SYSm;
James Molloyacad68d2011-09-28 14:21:38 +00003738 bits<4> Rn;
3739 let Inst{31-21} = 0b11110011100;
3740 let Inst{20} = 0b0;
3741 let Inst{19-16} = Rn;
3742 let Inst{15-12} = 0b1000;
Kevin Enderby0fd4f3c2012-05-17 22:18:01 +00003743 let Inst{11-0} = SYSm;
James Molloyacad68d2011-09-28 14:21:38 +00003744}
3745
3746
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003747//===----------------------------------------------------------------------===//
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003748// Move between coprocessor and ARM core register
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003749//
3750
Jim Grosbache35c5e02011-07-13 21:35:10 +00003751class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
3752 list<dag> pattern>
3753 : T2Cop<Op, oops, iops,
Jim Grosbach0d8dae22011-07-13 21:17:59 +00003754 !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003755 pattern> {
3756 let Inst{27-24} = 0b1110;
3757 let Inst{20} = direction;
3758 let Inst{4} = 1;
3759
3760 bits<4> Rt;
3761 bits<4> cop;
3762 bits<3> opc1;
3763 bits<3> opc2;
3764 bits<4> CRm;
3765 bits<4> CRn;
3766
3767 let Inst{15-12} = Rt;
3768 let Inst{11-8} = cop;
3769 let Inst{23-21} = opc1;
3770 let Inst{7-5} = opc2;
3771 let Inst{3-0} = CRm;
3772 let Inst{19-16} = CRn;
3773}
3774
Jim Grosbache35c5e02011-07-13 21:35:10 +00003775class t2MovRRCopro<bits<4> Op, string opc, bit direction,
3776 list<dag> pattern = []>
3777 : T2Cop<Op, (outs),
Jim Grosbachc8ae39e2011-07-14 21:26:42 +00003778 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
Jim Grosbache35c5e02011-07-13 21:35:10 +00003779 !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
3780 let Inst{27-24} = 0b1100;
3781 let Inst{23-21} = 0b010;
3782 let Inst{20} = direction;
3783
3784 bits<4> Rt;
3785 bits<4> Rt2;
3786 bits<4> cop;
3787 bits<4> opc1;
3788 bits<4> CRm;
3789
3790 let Inst{15-12} = Rt;
3791 let Inst{19-16} = Rt2;
3792 let Inst{11-8} = cop;
3793 let Inst{7-4} = opc1;
3794 let Inst{3-0} = CRm;
3795}
3796
3797/* from ARM core register to coprocessor */
3798def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003799 (outs),
Jim Grosbache540c742011-07-14 21:19:17 +00003800 (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3801 c_imm:$CRm, imm0_7:$opc2),
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003802 [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3803 imm:$CRm, imm:$opc2)]>;
Jim Grosbach213d2e72012-03-16 00:45:58 +00003804def : t2InstAlias<"mcr $cop, $opc1, $Rt, $CRn, $CRm",
3805 (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3806 c_imm:$CRm, 0)>;
Jim Grosbache35c5e02011-07-13 21:35:10 +00003807def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
Jim Grosbache540c742011-07-14 21:19:17 +00003808 (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3809 c_imm:$CRm, imm0_7:$opc2),
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00003810 [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3811 imm:$CRm, imm:$opc2)]>;
Jim Grosbach213d2e72012-03-16 00:45:58 +00003812def : t2InstAlias<"mcr2 $cop, $opc1, $Rt, $CRn, $CRm",
3813 (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3814 c_imm:$CRm, 0)>;
Jim Grosbache35c5e02011-07-13 21:35:10 +00003815
3816/* from coprocessor to ARM core register */
3817def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
Jim Grosbachccfd9312011-07-19 20:35:35 +00003818 (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3819 c_imm:$CRm, imm0_7:$opc2), []>;
Jim Grosbach213d2e72012-03-16 00:45:58 +00003820def : t2InstAlias<"mrc $cop, $opc1, $Rt, $CRn, $CRm",
3821 (t2MRC GPR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3822 c_imm:$CRm, 0)>;
Jim Grosbache35c5e02011-07-13 21:35:10 +00003823
3824def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
Jim Grosbachccfd9312011-07-19 20:35:35 +00003825 (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3826 c_imm:$CRm, imm0_7:$opc2), []>;
Jim Grosbach213d2e72012-03-16 00:45:58 +00003827def : t2InstAlias<"mrc2 $cop, $opc1, $Rt, $CRn, $CRm",
3828 (t2MRC2 GPR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3829 c_imm:$CRm, 0)>;
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003830
Jim Grosbache35c5e02011-07-13 21:35:10 +00003831def : T2v6Pat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
3832 (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3833
3834def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
Bruno Cardoso Lopes54ad87a2011-05-03 17:29:22 +00003835 (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3836
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003837
Jim Grosbache35c5e02011-07-13 21:35:10 +00003838/* from ARM core register to coprocessor */
3839def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0,
3840 [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
3841 imm:$CRm)]>;
3842def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0,
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00003843 [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt,
3844 GPR:$Rt2, imm:$CRm)]>;
Jim Grosbache35c5e02011-07-13 21:35:10 +00003845/* from coprocessor to ARM core register */
3846def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1>;
3847
3848def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1>;
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003849
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00003850//===----------------------------------------------------------------------===//
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003851// Other Coprocessor Instructions.
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00003852//
3853
Jim Grosbach1cbb0c12011-07-13 22:06:11 +00003854def tCDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
Jim Grosbach83ab0702011-07-13 22:01:08 +00003855 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003856 "cdp\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
3857 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3858 imm:$CRm, imm:$opc2)]> {
3859 let Inst{27-24} = 0b1110;
3860
3861 bits<4> opc1;
3862 bits<4> CRn;
3863 bits<4> CRd;
3864 bits<4> cop;
3865 bits<3> opc2;
3866 bits<4> CRm;
3867
3868 let Inst{3-0} = CRm;
3869 let Inst{4} = 0;
3870 let Inst{7-5} = opc2;
3871 let Inst{11-8} = cop;
3872 let Inst{15-12} = CRd;
3873 let Inst{19-16} = CRn;
3874 let Inst{23-20} = opc1;
3875}
3876
Jim Grosbach1cbb0c12011-07-13 22:06:11 +00003877def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
Jim Grosbach83ab0702011-07-13 22:01:08 +00003878 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00003879 "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00003880 [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3881 imm:$CRm, imm:$opc2)]> {
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00003882 let Inst{27-24} = 0b1110;
3883
3884 bits<4> opc1;
3885 bits<4> CRn;
3886 bits<4> CRd;
3887 bits<4> cop;
3888 bits<3> opc2;
3889 bits<4> CRm;
3890
3891 let Inst{3-0} = CRm;
3892 let Inst{4} = 0;
3893 let Inst{7-5} = opc2;
3894 let Inst{11-8} = cop;
3895 let Inst{15-12} = CRd;
3896 let Inst{19-16} = CRn;
3897 let Inst{23-20} = opc1;
3898}
Jim Grosbachc5a8c862011-07-27 16:47:19 +00003899
3900
3901
3902//===----------------------------------------------------------------------===//
3903// Non-Instruction Patterns
3904//
3905
3906// SXT/UXT with no rotate
Jim Grosbach70327412011-07-27 17:48:13 +00003907let AddedComplexity = 16 in {
3908def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00003909 Requires<[IsThumb2]>;
Jim Grosbach70327412011-07-27 17:48:13 +00003910def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00003911 Requires<[IsThumb2]>;
Jim Grosbach70327412011-07-27 17:48:13 +00003912def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
3913 Requires<[HasT2ExtractPack, IsThumb2]>;
3914def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
3915 (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
3916 Requires<[HasT2ExtractPack, IsThumb2]>;
3917def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
3918 (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
3919 Requires<[HasT2ExtractPack, IsThumb2]>;
3920}
Jim Grosbachc5a8c862011-07-27 16:47:19 +00003921
Jim Grosbach70327412011-07-27 17:48:13 +00003922def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>,
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00003923 Requires<[IsThumb2]>;
Jim Grosbach70327412011-07-27 17:48:13 +00003924def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00003925 Requires<[IsThumb2]>;
Jim Grosbach70327412011-07-27 17:48:13 +00003926def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
3927 (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
3928 Requires<[HasT2ExtractPack, IsThumb2]>;
3929def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
3930 (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
3931 Requires<[HasT2ExtractPack, IsThumb2]>;
Eli Friedman069e2ed2011-08-26 02:59:24 +00003932
3933// Atomic load/store patterns
Jakob Stoklund Olesencff9baa2012-08-28 03:11:27 +00003934def : T2Pat<(atomic_load_8 t2addrmode_imm12:$addr),
3935 (t2LDRBi12 t2addrmode_imm12:$addr)>;
3936def : T2Pat<(atomic_load_8 t2addrmode_negimm8:$addr),
3937 (t2LDRBi8 t2addrmode_negimm8:$addr)>;
Eli Friedman069e2ed2011-08-26 02:59:24 +00003938def : T2Pat<(atomic_load_8 t2addrmode_so_reg:$addr),
Jakob Stoklund Olesencff9baa2012-08-28 03:11:27 +00003939 (t2LDRBs t2addrmode_so_reg:$addr)>;
3940def : T2Pat<(atomic_load_16 t2addrmode_imm12:$addr),
3941 (t2LDRHi12 t2addrmode_imm12:$addr)>;
3942def : T2Pat<(atomic_load_16 t2addrmode_negimm8:$addr),
3943 (t2LDRHi8 t2addrmode_negimm8:$addr)>;
Eli Friedman069e2ed2011-08-26 02:59:24 +00003944def : T2Pat<(atomic_load_16 t2addrmode_so_reg:$addr),
Jakob Stoklund Olesencff9baa2012-08-28 03:11:27 +00003945 (t2LDRHs t2addrmode_so_reg:$addr)>;
3946def : T2Pat<(atomic_load_32 t2addrmode_imm12:$addr),
3947 (t2LDRi12 t2addrmode_imm12:$addr)>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00003948def : T2Pat<(atomic_load_32 t2addrmode_negimm8:$addr),
Jakob Stoklund Olesencff9baa2012-08-28 03:11:27 +00003949 (t2LDRi8 t2addrmode_negimm8:$addr)>;
Eli Friedman069e2ed2011-08-26 02:59:24 +00003950def : T2Pat<(atomic_load_32 t2addrmode_so_reg:$addr),
Jakob Stoklund Olesencff9baa2012-08-28 03:11:27 +00003951 (t2LDRs t2addrmode_so_reg:$addr)>;
Eli Friedman069e2ed2011-08-26 02:59:24 +00003952def : T2Pat<(atomic_store_8 t2addrmode_imm12:$addr, GPR:$val),
3953 (t2STRBi12 GPR:$val, t2addrmode_imm12:$addr)>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00003954def : T2Pat<(atomic_store_8 t2addrmode_negimm8:$addr, GPR:$val),
3955 (t2STRBi8 GPR:$val, t2addrmode_negimm8:$addr)>;
Eli Friedman069e2ed2011-08-26 02:59:24 +00003956def : T2Pat<(atomic_store_8 t2addrmode_so_reg:$addr, GPR:$val),
3957 (t2STRBs GPR:$val, t2addrmode_so_reg:$addr)>;
3958def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
3959 (t2STRHi12 GPR:$val, t2addrmode_imm12:$addr)>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00003960def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
3961 (t2STRHi8 GPR:$val, t2addrmode_negimm8:$addr)>;
Eli Friedman069e2ed2011-08-26 02:59:24 +00003962def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
3963 (t2STRHs GPR:$val, t2addrmode_so_reg:$addr)>;
3964def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
3965 (t2STRi12 GPR:$val, t2addrmode_imm12:$addr)>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00003966def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
3967 (t2STRi8 GPR:$val, t2addrmode_negimm8:$addr)>;
Eli Friedman069e2ed2011-08-26 02:59:24 +00003968def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
3969 (t2STRs GPR:$val, t2addrmode_so_reg:$addr)>;
Jim Grosbach72335d52011-08-31 18:23:08 +00003970
3971
3972//===----------------------------------------------------------------------===//
3973// Assembler aliases
3974//
3975
3976// Aliases for ADC without the ".w" optional width specifier.
3977def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
3978 (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3979def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
3980 (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
3981 pred:$p, cc_out:$s)>;
3982
3983// Aliases for SBC without the ".w" optional width specifier.
3984def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
3985 (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
3986def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
3987 (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
3988 pred:$p, cc_out:$s)>;
3989
Jim Grosbachf0851e52011-09-02 18:14:46 +00003990// Aliases for ADD without the ".w" optional width specifier.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00003991def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +00003992 (t2ADDri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
Jim Grosbach20ed2e72011-09-01 00:28:52 +00003993def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +00003994 (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
Jim Grosbachf0851e52011-09-02 18:14:46 +00003995def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +00003996 (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
Jim Grosbachf0851e52011-09-02 18:14:46 +00003997def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +00003998 (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
Jim Grosbachf0851e52011-09-02 18:14:46 +00003999 pred:$p, cc_out:$s)>;
Jim Grosbach5d0492c2011-10-28 16:57:07 +00004000// ... and with the destination and source register combined.
4001def : t2InstAlias<"add${s}${p} $Rdn, $imm",
4002 (t2ADDri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4003def : t2InstAlias<"add${p} $Rdn, $imm",
4004 (t2ADDri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
4005def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
4006 (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4007def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
4008 (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4009 pred:$p, cc_out:$s)>;
Jim Grosbachef88a922011-09-06 21:44:58 +00004010
Jim Grosbach4e53fe82012-04-05 20:57:13 +00004011// add w/ negative immediates is just a sub.
4012def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
4013 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4014 cc_out:$s)>;
4015def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
4016 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4017def : t2InstAlias<"add${s}${p} $Rdn, $imm",
4018 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4019 cc_out:$s)>;
4020def : t2InstAlias<"add${p} $Rdn, $imm",
4021 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4022
Jim Grosbach54319e22012-05-01 21:17:34 +00004023def : t2InstAlias<"add${s}${p}.w $Rd, $Rn, $imm",
4024 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
4025 cc_out:$s)>;
4026def : t2InstAlias<"addw${p} $Rd, $Rn, $imm",
4027 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
4028def : t2InstAlias<"add${s}${p}.w $Rdn, $imm",
4029 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
4030 cc_out:$s)>;
4031def : t2InstAlias<"addw${p} $Rdn, $imm",
4032 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
4033
Jim Grosbach4e53fe82012-04-05 20:57:13 +00004034
Jim Grosbachf67e8552011-09-16 22:58:42 +00004035// Aliases for SUB without the ".w" optional width specifier.
4036def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +00004037 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004038def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +00004039 (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004040def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +00004041 (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004042def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
Jim Grosbachb95ed6e2011-10-03 20:51:59 +00004043 (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
Jim Grosbachf67e8552011-09-16 22:58:42 +00004044 pred:$p, cc_out:$s)>;
Jim Grosbach5d0492c2011-10-28 16:57:07 +00004045// ... and with the destination and source register combined.
4046def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
4047 (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4048def : t2InstAlias<"sub${p} $Rdn, $imm",
4049 (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004050def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm",
4051 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
Jim Grosbach5d0492c2011-10-28 16:57:07 +00004052def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
4053 (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4054def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
4055 (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
4056 pred:$p, cc_out:$s)>;
4057
Jim Grosbachef88a922011-09-06 21:44:58 +00004058// Alias for compares without the ".w" optional width specifier.
4059def : t2InstAlias<"cmn${p} $Rn, $Rm",
4060 (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4061def : t2InstAlias<"teq${p} $Rn, $Rm",
4062 (t2TEQrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4063def : t2InstAlias<"tst${p} $Rn, $Rm",
4064 (t2TSTrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
4065
Jim Grosbach06c1a512011-09-06 22:14:58 +00004066// Memory barriers
Evan Cheng97a45432012-04-27 01:27:19 +00004067def : InstAlias<"dmb", (t2DMB 0xf)>, Requires<[IsThumb, HasDB]>;
4068def : InstAlias<"dsb", (t2DSB 0xf)>, Requires<[IsThumb, HasDB]>;
4069def : InstAlias<"isb", (t2ISB 0xf)>, Requires<[IsThumb, HasDB]>;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00004070
Jim Grosbach0811fe12011-09-09 19:42:40 +00004071// Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
4072// width specifier.
Jim Grosbach8bb5a862011-09-07 21:41:25 +00004073def : t2InstAlias<"ldr${p} $Rt, $addr",
4074 (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4075def : t2InstAlias<"ldrb${p} $Rt, $addr",
4076 (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4077def : t2InstAlias<"ldrh${p} $Rt, $addr",
4078 (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
Jim Grosbach0811fe12011-09-09 19:42:40 +00004079def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4080 (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4081def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4082 (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4083
Jim Grosbachab899c12011-09-07 23:10:15 +00004084def : t2InstAlias<"ldr${p} $Rt, $addr",
4085 (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4086def : t2InstAlias<"ldrb${p} $Rt, $addr",
4087 (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4088def : t2InstAlias<"ldrh${p} $Rt, $addr",
4089 (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
Jim Grosbach0811fe12011-09-09 19:42:40 +00004090def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4091 (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4092def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4093 (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
Jim Grosbachd32872f2011-09-14 21:24:41 +00004094
Jim Grosbacha5813282011-10-26 22:22:01 +00004095def : t2InstAlias<"ldr${p} $Rt, $addr",
4096 (t2LDRpci GPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4097def : t2InstAlias<"ldrb${p} $Rt, $addr",
4098 (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4099def : t2InstAlias<"ldrh${p} $Rt, $addr",
4100 (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4101def : t2InstAlias<"ldrsb${p} $Rt, $addr",
4102 (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4103def : t2InstAlias<"ldrsh${p} $Rt, $addr",
4104 (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
4105
Jim Grosbach036a67d2011-10-27 17:16:55 +00004106// Alias for MVN with(out) the ".w" optional width specifier.
4107def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
4108 (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
Jim Grosbachd32872f2011-09-14 21:24:41 +00004109def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
4110 (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
4111def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
4112 (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
Jim Grosbach0b692472011-09-14 23:16:41 +00004113
4114// PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT when the
4115// shift amount is zero (i.e., unspecified).
4116def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
4117 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
4118 Requires<[HasT2ExtractPack, IsThumb2]>;
4119def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
4120 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
4121 Requires<[HasT2ExtractPack, IsThumb2]>;
4122
Jim Grosbach57b21e42011-09-15 15:55:04 +00004123// PUSH/POP aliases for STM/LDM
4124def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4125def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
4126def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4127def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
4128
Jim Grosbach8524bca2011-12-07 18:32:28 +00004129// STMIA/STMIA_UPD aliases w/o the optional .w suffix
4130def : t2InstAlias<"stm${p} $Rn, $regs",
4131 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4132def : t2InstAlias<"stm${p} $Rn!, $regs",
4133 (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4134
4135// LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
4136def : t2InstAlias<"ldm${p} $Rn, $regs",
4137 (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
4138def : t2InstAlias<"ldm${p} $Rn!, $regs",
4139 (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4140
Jim Grosbach3c5d6e42011-11-09 23:44:23 +00004141// STMDB/STMDB_UPD aliases w/ the optional .w suffix
4142def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
4143 (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4144def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
4145 (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4146
Jim Grosbach88484c02011-10-27 17:33:59 +00004147// LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
4148def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
4149 (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
4150def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
4151 (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
4152
Jim Grosbach689b86e2011-09-15 19:46:13 +00004153// Alias for REV/REV16/REVSH without the ".w" optional width specifier.
Jim Grosbach1b69a122011-09-15 18:13:30 +00004154def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
Jim Grosbach689b86e2011-09-15 19:46:13 +00004155def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
4156def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
Jim Grosbach191d33f2011-09-15 20:54:14 +00004157
4158
4159// Alias for RSB without the ".w" optional width specifier, and with optional
4160// implied destination register.
4161def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
4162 (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4163def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
4164 (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
4165def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
4166 (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
4167def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
4168 (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
4169 cc_out:$s)>;
Jim Grosbachb105b992011-09-16 18:32:30 +00004170
4171// SSAT/USAT optional shift operand.
4172def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
4173 (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4174def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
4175 (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
4176
Jim Grosbach8213c962011-09-16 20:50:13 +00004177// STM w/o the .w suffix.
4178def : t2InstAlias<"stm${p} $Rn, $regs",
4179 (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
Jim Grosbach642caea2011-09-16 21:06:12 +00004180
4181// Alias for STR, STRB, and STRH without the ".w" optional
4182// width specifier.
4183def : t2InstAlias<"str${p} $Rt, $addr",
4184 (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4185def : t2InstAlias<"strb${p} $Rt, $addr",
4186 (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4187def : t2InstAlias<"strh${p} $Rt, $addr",
4188 (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
4189
4190def : t2InstAlias<"str${p} $Rt, $addr",
4191 (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4192def : t2InstAlias<"strb${p} $Rt, $addr",
4193 (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
4194def : t2InstAlias<"strh${p} $Rt, $addr",
4195 (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
Jim Grosbach8a8d28b2011-09-19 17:56:37 +00004196
4197// Extend instruction optional rotate operand.
4198def : t2InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
4199 (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4200def : t2InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
4201 (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4202def : t2InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
4203 (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
Jim Grosbach25ddc2b2011-09-27 22:18:54 +00004204
Jim Grosbach326efe52011-09-19 20:29:33 +00004205def : t2InstAlias<"sxtb${p} $Rd, $Rm",
4206 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4207def : t2InstAlias<"sxtb16${p} $Rd, $Rm",
4208 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4209def : t2InstAlias<"sxth${p} $Rd, $Rm",
4210 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
Jim Grosbach25ddc2b2011-09-27 22:18:54 +00004211def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
4212 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4213def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
4214 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
Jim Grosbach326efe52011-09-19 20:29:33 +00004215
Jim Grosbach50f1c372011-09-20 00:46:54 +00004216def : t2InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
4217 (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4218def : t2InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
4219 (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4220def : t2InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
4221 (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>;
4222def : t2InstAlias<"uxtb${p} $Rd, $Rm",
4223 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4224def : t2InstAlias<"uxtb16${p} $Rd, $Rm",
4225 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4226def : t2InstAlias<"uxth${p} $Rd, $Rm",
4227 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4228
Jim Grosbach25ddc2b2011-09-27 22:18:54 +00004229def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
4230 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4231def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
4232 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
4233
Jim Grosbach326efe52011-09-19 20:29:33 +00004234// Extend instruction w/o the ".w" optional width specifier.
Jim Grosbach50f1c372011-09-20 00:46:54 +00004235def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
4236 (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4237def : t2InstAlias<"uxtb16${p} $Rd, $Rm$rot",
4238 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4239def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
4240 (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4241
Jim Grosbach326efe52011-09-19 20:29:33 +00004242def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
4243 (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4244def : t2InstAlias<"sxtb16${p} $Rd, $Rm$rot",
4245 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
4246def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
4247 (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
Jim Grosbach89a63372011-10-28 22:36:30 +00004248
4249
4250// "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
4251// for isel.
4252def : t2InstAlias<"mov${p} $Rd, $imm",
4253 (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
Jim Grosbach46777082011-12-14 17:56:51 +00004254def : t2InstAlias<"mvn${p} $Rd, $imm",
4255 (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
Jim Grosbach840bf7e2011-12-09 22:02:17 +00004256// Same for AND <--> BIC
4257def : t2InstAlias<"bic${s}${p} $Rd, $Rn, $imm",
4258 (t2ANDri rGPR:$Rd, rGPR:$Rn, so_imm_not:$imm,
4259 pred:$p, cc_out:$s)>;
4260def : t2InstAlias<"bic${s}${p} $Rdn, $imm",
4261 (t2ANDri rGPR:$Rdn, rGPR:$Rdn, so_imm_not:$imm,
4262 pred:$p, cc_out:$s)>;
4263def : t2InstAlias<"and${s}${p} $Rd, $Rn, $imm",
4264 (t2BICri rGPR:$Rd, rGPR:$Rn, so_imm_not:$imm,
4265 pred:$p, cc_out:$s)>;
4266def : t2InstAlias<"and${s}${p} $Rdn, $imm",
4267 (t2BICri rGPR:$Rdn, rGPR:$Rdn, so_imm_not:$imm,
4268 pred:$p, cc_out:$s)>;
Jim Grosbach8d11c632011-12-14 17:30:24 +00004269// Likewise, "add Rd, t2_so_imm_neg" -> sub
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00004270def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
4271 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
4272 pred:$p, cc_out:$s)>;
4273def : t2InstAlias<"add${s}${p} $Rd, $imm",
4274 (t2SUBri GPRnopc:$Rd, GPRnopc:$Rd, t2_so_imm_neg:$imm,
4275 pred:$p, cc_out:$s)>;
Jim Grosbach8d11c632011-12-14 17:30:24 +00004276// Same for CMP <--> CMN via t2_so_imm_neg
4277def : t2InstAlias<"cmp${p} $Rd, $imm",
Bill Wendlingad5c8802012-06-11 08:07:26 +00004278 (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
Jim Grosbach8d11c632011-12-14 17:30:24 +00004279def : t2InstAlias<"cmn${p} $Rd, $imm",
4280 (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004281
4282
4283// Wide 'mul' encoding can be specified with only two operands.
4284def : t2InstAlias<"mul${p} $Rn, $Rm",
Jim Grosbachcf9814d2011-12-06 05:03:45 +00004285 (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
Jim Grosbache91e7bc2011-12-13 20:23:22 +00004286
4287// "neg" is and alias for "rsb rd, rn, #0"
4288def : t2InstAlias<"neg${s}${p} $Rd, $Rm",
4289 (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>;
Jim Grosbach863d2af2011-12-13 22:45:11 +00004290
4291// MOV so_reg assembler pseudos. InstAlias isn't expressive enough for
4292// these, unfortunately.
4293def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift",
4294 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
4295def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift",
4296 (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
Jim Grosbachb6744db2011-12-15 23:52:17 +00004297
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00004298def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift",
4299 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4300def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift",
4301 (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
4302
Jim Grosbachb6744db2011-12-15 23:52:17 +00004303// ADR w/o the .w suffix
4304def : t2InstAlias<"adr${p} $Rd, $addr",
4305 (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00004306
4307// LDR(literal) w/ alternate [pc, #imm] syntax.
4308def t2LDRpcrel : t2AsmPseudo<"ldr${p} $Rt, $addr",
4309 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4310def t2LDRBpcrel : t2AsmPseudo<"ldrb${p} $Rt, $addr",
4311 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4312def t2LDRHpcrel : t2AsmPseudo<"ldrh${p} $Rt, $addr",
4313 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4314def t2LDRSBpcrel : t2AsmPseudo<"ldrsb${p} $Rt, $addr",
4315 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4316def t2LDRSHpcrel : t2AsmPseudo<"ldrsh${p} $Rt, $addr",
4317 (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4318 // Version w/ the .w suffix.
4319def : t2InstAlias<"ldr${p}.w $Rt, $addr",
4320 (t2LDRpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4321def : t2InstAlias<"ldrb${p}.w $Rt, $addr",
4322 (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4323def : t2InstAlias<"ldrh${p}.w $Rt, $addr",
4324 (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4325def : t2InstAlias<"ldrsb${p}.w $Rt, $addr",
4326 (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
4327def : t2InstAlias<"ldrsh${p}.w $Rt, $addr",
4328 (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
Jim Grosbach12a88632012-01-21 00:07:56 +00004329
4330def : t2InstAlias<"add${p} $Rd, pc, $imm",
4331 (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>;