blob: 798f8c36fc78e384d715ddbd4138885100a4900a [file] [log] [blame]
Evan Cheng37f25d92008-08-28 23:39:26 +00001//===- ARMInstrFormats.td - ARM Instruction Formats --*- tablegen -*---------=//
2//
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//===----------------------------------------------------------------------===//
11//
12// ARM Instruction Format Definitions.
13//
14
15// Format specifies the encoding used by the instruction. This is part of the
16// ad-hoc solution used to emit machine instruction encodings by our machine
17// code emitter.
18class Format<bits<5> val> {
19 bits<5> Value = val;
20}
21
22def Pseudo : Format<1>;
23def MulFrm : Format<2>;
24def MulSMLAW : Format<3>;
25def MulSMULW : Format<4>;
26def MulSMLA : Format<5>;
27def MulSMUL : Format<6>;
28def Branch : Format<7>;
29def BranchMisc : Format<8>;
30
31def DPRdIm : Format<9>;
32def DPRdReg : Format<10>;
33def DPRdSoReg : Format<11>;
34def DPRdMisc : Format<12>;
35def DPRnIm : Format<13>;
36def DPRnReg : Format<14>;
37def DPRnSoReg : Format<15>;
38def DPRIm : Format<16>;
39def DPRReg : Format<17>;
40def DPRSoReg : Format<18>;
41def DPRImS : Format<19>;
42def DPRRegS : Format<20>;
43def DPRSoRegS : Format<21>;
44
45def LdFrm : Format<22>;
46def StFrm : Format<23>;
47
48def ArithMisc : Format<24>;
49def ThumbFrm : Format<25>;
50def VFPFrm : Format<26>;
51
52
Evan Cheng37f25d92008-08-28 23:39:26 +000053//===----------------------------------------------------------------------===//
54
55// ARM Instruction templates.
56//
57
58class InstARM<bits<4> opcod, AddrMode am, SizeFlagVal sz, IndexMode im,
59 Format f, string cstr>
60 : Instruction {
Evan Cheng612b79e2008-08-29 07:40:52 +000061 field bits<32> Inst;
62
Evan Cheng37f25d92008-08-28 23:39:26 +000063 let Namespace = "ARM";
64
65 bits<4> Opcode = opcod;
66 AddrMode AM = am;
67 bits<4> AddrModeBits = AM.Value;
68
69 SizeFlagVal SZ = sz;
70 bits<3> SizeFlag = SZ.Value;
71
72 IndexMode IM = im;
73 bits<2> IndexModeBits = IM.Value;
74
75 Format F = f;
76 bits<5> Form = F.Value;
77
78 let Constraints = cstr;
79}
80
81class PseudoInst<dag oops, dag iops, string asm, list<dag> pattern>
82 : InstARM<0, AddrModeNone, SizeSpecial, IndexModeNone, Pseudo, ""> {
83 let OutOperandList = oops;
84 let InOperandList = iops;
85 let AsmString = asm;
86 let Pattern = pattern;
87}
88
89// Almost all ARM instructions are predicable.
90class I<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
91 IndexMode im, Format f, string opc, string asm, string cstr,
92 list<dag> pattern>
93 : InstARM<opcod, am, sz, im, f, cstr> {
94 let OutOperandList = oops;
95 let InOperandList = !con(iops, (ops pred:$p));
96 let AsmString = !strconcat(opc, !strconcat("${p}", asm));
97 let Pattern = pattern;
98 list<Predicate> Predicates = [IsARM];
99}
100
101// Same as I except it can optionally modify CPSR. Note it's modeled as
102// an input operand since by default it's a zero register. It will
103// become an implicit def once it's "flipped".
104class sI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
105 IndexMode im, Format f, string opc, string asm, string cstr,
106 list<dag> pattern>
107 : InstARM<opcod, am, sz, im, f, cstr> {
108 let OutOperandList = oops;
109 let InOperandList = !con(iops, (ops pred:$p, cc_out:$s));
110 let AsmString = !strconcat(opc, !strconcat("${p}${s}", asm));
111 let Pattern = pattern;
112 list<Predicate> Predicates = [IsARM];
113}
114
115class AI<bits<4> opcod, dag oops, dag iops, Format f, string opc,
116 string asm, list<dag> pattern>
117 : I<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, opc,
118 asm,"",pattern>;
119class AsI<bits<4> opcod, dag oops, dag iops, Format f, string opc,
120 string asm, list<dag> pattern>
121 : sI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, opc,
122 asm,"",pattern>;
123class AI1<bits<4> opcod, dag oops, dag iops, Format f, string opc,
124 string asm, list<dag> pattern>
125 : I<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc,
Evan Cheng612b79e2008-08-29 07:40:52 +0000126 asm, "", pattern> {
Evan Chengb7880ac2008-08-31 18:32:16 +0000127 let Inst{21-24} = opcod;
128 let Inst{26-27} = 0;
Evan Cheng612b79e2008-08-29 07:40:52 +0000129}
Evan Cheng37f25d92008-08-28 23:39:26 +0000130class AsI1<bits<4> opcod, dag oops, dag iops, Format f, string opc,
131 string asm, list<dag> pattern>
132 : sI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc,
Evan Cheng612b79e2008-08-29 07:40:52 +0000133 asm, "", pattern> {
Evan Chengb7880ac2008-08-31 18:32:16 +0000134 let Inst{20} = 1;
135 let Inst{21-24} = opcod;
136 let Inst{26-27} = 0;
Evan Cheng612b79e2008-08-29 07:40:52 +0000137}
Evan Cheng17222df2008-08-31 19:02:21 +0000138
Evan Cheng37f25d92008-08-28 23:39:26 +0000139class AI2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
140 string asm, list<dag> pattern>
141 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, opc,
Evan Cheng17222df2008-08-31 19:02:21 +0000142 asm, "", pattern> {
143 let Inst{26-27} = 1;
144}
Evan Cheng93912732008-09-01 01:27:33 +0000145
146// loads
Evan Cheng17222df2008-08-31 19:02:21 +0000147class AI2ldw<bits<4> opcod, dag oops, dag iops, Format f, string opc,
148 string asm, list<dag> pattern>
149 : AI2<opcod, oops, iops, f, opc, asm, pattern> {
150 let Inst{20} = 1; // load bit
151 let Inst{21} = 0; // W bit
152 let Inst{22} = 0; // B bit
153 let Inst{24} = 1; // P bit
154}
155class AI2ldb<bits<4> opcod, dag oops, dag iops, Format f, string opc,
156 string asm, list<dag> pattern>
157 : AI2<opcod, oops, iops, f, opc, asm, pattern> {
158 let Inst{20} = 1; // load bit
159 let Inst{21} = 0; // W bit
160 let Inst{22} = 1; // B bit
161 let Inst{24} = 1; // P bit
162}
163
Evan Cheng93912732008-09-01 01:27:33 +0000164// stores
165class AI2stw<bits<4> opcod, dag oops, dag iops, Format f, string opc,
166 string asm, list<dag> pattern>
167 : AI2<opcod, oops, iops, f, opc, asm, pattern> {
168 let Inst{20} = 0; // load bit
169 let Inst{21} = 0; // W bit
170 let Inst{22} = 0; // B bit
171 let Inst{24} = 1; // P bit
172}
173class AI2stb<bits<4> opcod, dag oops, dag iops, Format f, string opc,
174 string asm, list<dag> pattern>
175 : AI2<opcod, oops, iops, f, opc, asm, pattern> {
176 let Inst{20} = 0; // load bit
177 let Inst{21} = 0; // W bit
178 let Inst{22} = 1; // B bit
179 let Inst{24} = 1; // P bit
180}
181
Evan Cheng37f25d92008-08-28 23:39:26 +0000182class AI3<bits<4> opcod, dag oops, dag iops, Format f, string opc,
183 string asm, list<dag> pattern>
184 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, opc,
185 asm, "", pattern>;
186class AI4<bits<4> opcod, dag oops, dag iops, Format f, string opc,
187 string asm, list<dag> pattern>
188 : I<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, opc,
189 asm, "", pattern>;
190class AI1x2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
191 string asm, list<dag> pattern>
192 : I<opcod, oops, iops, AddrMode1, Size8Bytes, IndexModeNone, f, opc,
193 asm, "", pattern>;
194
195// Pre-indexed ops
Evan Cheng93912732008-09-01 01:27:33 +0000196// loads
197class AI2ldwpr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
Evan Cheng37f25d92008-08-28 23:39:26 +0000198 string asm, string cstr, list<dag> pattern>
199 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
Evan Cheng93912732008-09-01 01:27:33 +0000200 asm, cstr, pattern> {
201 let Inst{20} = 1; // load bit
202 let Inst{21} = 1; // W bit
203 let Inst{22} = 0; // B bit
204 let Inst{24} = 1; // P bit
205}
206class AI2ldbpr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
207 string asm, string cstr, list<dag> pattern>
208 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
209 asm, cstr, pattern> {
210 let Inst{20} = 1; // load bit
211 let Inst{21} = 1; // W bit
212 let Inst{22} = 1; // B bit
213 let Inst{24} = 1; // P bit
214}
215
216// stores
217class AI2stwpr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
218 string asm, string cstr, list<dag> pattern>
219 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
220 asm, cstr, pattern> {
221 let Inst{20} = 0; // load bit
222 let Inst{21} = 1; // W bit
223 let Inst{22} = 0; // B bit
224 let Inst{24} = 1; // P bit
225}
226class AI2stbpr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
227 string asm, string cstr, list<dag> pattern>
228 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
229 asm, cstr, pattern> {
230 let Inst{20} = 0; // load bit
231 let Inst{21} = 1; // W bit
232 let Inst{22} = 1; // B bit
233 let Inst{24} = 1; // P bit
234}
235
Evan Cheng37f25d92008-08-28 23:39:26 +0000236class AI3pr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
237 string asm, string cstr, list<dag> pattern>
238 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePre, f, opc,
239 asm, cstr, pattern>;
240
241// Post-indexed ops
Evan Cheng93912732008-09-01 01:27:33 +0000242// loads
243class AI2ldwpo<bits<4> opcod, dag oops, dag iops, Format f, string opc,
Evan Cheng37f25d92008-08-28 23:39:26 +0000244 string asm, string cstr, list<dag> pattern>
245 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
Evan Cheng93912732008-09-01 01:27:33 +0000246 asm, cstr,pattern> {
247 let Inst{20} = 1; // load bit
248 let Inst{21} = 0; // W bit
249 let Inst{22} = 0; // B bit
250 let Inst{24} = 0; // P bit
251}
252class AI2ldbpo<bits<4> opcod, dag oops, dag iops, Format f, string opc,
253 string asm, string cstr, list<dag> pattern>
254 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
255 asm, cstr,pattern> {
256 let Inst{20} = 1; // load bit
257 let Inst{21} = 0; // W bit
258 let Inst{22} = 1; // B bit
259 let Inst{24} = 0; // P bit
260}
261
262// stores
263class AI2stwpo<bits<4> opcod, dag oops, dag iops, Format f, string opc,
264 string asm, string cstr, list<dag> pattern>
265 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
266 asm, cstr,pattern> {
267 let Inst{20} = 0; // load bit
268 let Inst{21} = 0; // W bit
269 let Inst{22} = 0; // B bit
270 let Inst{24} = 0; // P bit
271}
272class AI2stbpo<bits<4> opcod, dag oops, dag iops, Format f, string opc,
273 string asm, string cstr, list<dag> pattern>
274 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
275 asm, cstr,pattern> {
276 let Inst{20} = 0; // load bit
277 let Inst{21} = 0; // W bit
278 let Inst{22} = 1; // B bit
279 let Inst{24} = 0; // P bit
280}
281
Evan Cheng37f25d92008-08-28 23:39:26 +0000282class AI3po<bits<4> opcod, dag oops, dag iops, Format f, string opc,
283 string asm, string cstr, list<dag> pattern>
284 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePost, f, opc,
285 asm, cstr,pattern>;
286
287
288// Special cases.
289class XI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
290 IndexMode im, Format f, string asm, string cstr, list<dag> pattern>
291 : InstARM<opcod, am, sz, im, f, cstr> {
292 let OutOperandList = oops;
293 let InOperandList = iops;
294 let AsmString = asm;
295 let Pattern = pattern;
296 list<Predicate> Predicates = [IsARM];
297}
298
299class AXI<bits<4> opcod, dag oops, dag iops, Format f, string asm,
300 list<dag> pattern>
301 : XI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, asm,
302 "", pattern>;
303class AXI1<bits<4> opcod, dag oops, dag iops, Format f, string asm,
304 list<dag> pattern>
305 : XI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, asm,
306 "", pattern>;
307class AXI2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
308 list<dag> pattern>
309 : XI<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, asm,
310 "", pattern>;
311class AXI3<bits<4> opcod, dag oops, dag iops, Format f, string asm,
312 list<dag> pattern>
313 : XI<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, asm,
314 "", pattern>;
315class AXI4<bits<4> opcod, dag oops, dag iops, Format f, string asm,
316 list<dag> pattern>
317 : XI<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, asm,
318 "", pattern>;
319
320class AXIx2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
321 list<dag> pattern>
322 : XI<opcod, oops, iops, AddrModeNone, Size8Bytes, IndexModeNone, f, asm,
323 "", pattern>;
324
325// BR_JT instructions
326class JTI<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
327 : XI<opcod, oops, iops, AddrModeNone, SizeSpecial, IndexModeNone, BranchMisc,
328 asm, "", pattern>;
329class JTI1<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
330 : XI<opcod, oops, iops, AddrMode1, SizeSpecial, IndexModeNone, BranchMisc,
331 asm, "", pattern>;
332class JTI2<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
333 : XI<opcod, oops, iops, AddrMode2, SizeSpecial, IndexModeNone, BranchMisc,
334 asm, "", pattern>;
335
336
337//===----------------------------------------------------------------------===//
338
339// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
340class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
341 list<Predicate> Predicates = [IsARM];
342}
343class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
344 list<Predicate> Predicates = [IsARM, HasV5TE];
345}
346class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
347 list<Predicate> Predicates = [IsARM, HasV6];
348}
Evan Cheng13096642008-08-29 06:41:12 +0000349
350//===----------------------------------------------------------------------===//
351//
352// Thumb Instruction Format Definitions.
353//
354
355
356// TI - Thumb instruction.
357
358class ThumbI<dag outs, dag ins, AddrMode am, SizeFlagVal sz,
359 string asm, string cstr, list<dag> pattern>
360 // FIXME: Set all opcodes to 0 for now.
361 : InstARM<0, am, sz, IndexModeNone, ThumbFrm, cstr> {
362 let OutOperandList = outs;
363 let InOperandList = ins;
364 let AsmString = asm;
365 let Pattern = pattern;
366 list<Predicate> Predicates = [IsThumb];
367}
368
369class TI<dag outs, dag ins, string asm, list<dag> pattern>
370 : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "", pattern>;
371class TI1<dag outs, dag ins, string asm, list<dag> pattern>
372 : ThumbI<outs, ins, AddrModeT1, Size2Bytes, asm, "", pattern>;
373class TI2<dag outs, dag ins, string asm, list<dag> pattern>
374 : ThumbI<outs, ins, AddrModeT2, Size2Bytes, asm, "", pattern>;
375class TI4<dag outs, dag ins, string asm, list<dag> pattern>
376 : ThumbI<outs, ins, AddrModeT4, Size2Bytes, asm, "", pattern>;
377class TIs<dag outs, dag ins, string asm, list<dag> pattern>
378 : ThumbI<outs, ins, AddrModeTs, Size2Bytes, asm, "", pattern>;
379
380// Two-address instructions
381class TIt<dag outs, dag ins, string asm, list<dag> pattern>
382 : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "$lhs = $dst", pattern>;
383
384// BL, BLX(1) are translated by assembler into two instructions
385class TIx2<dag outs, dag ins, string asm, list<dag> pattern>
386 : ThumbI<outs, ins, AddrModeNone, Size4Bytes, asm, "", pattern>;
387
388// BR_JT instructions
389class TJTI<dag outs, dag ins, string asm, list<dag> pattern>
390 : ThumbI<outs, ins, AddrModeNone, SizeSpecial, asm, "", pattern>;
391
392
393//===----------------------------------------------------------------------===//
394
395
396// ThumbPat - Same as Pat<>, but requires that the compiler be in Thumb mode.
397class ThumbPat<dag pattern, dag result> : Pat<pattern, result> {
398 list<Predicate> Predicates = [IsThumb];
399}
400
401class ThumbV5Pat<dag pattern, dag result> : Pat<pattern, result> {
402 list<Predicate> Predicates = [IsThumb, HasV5T];
403}