blob: d3b97239fe4dc8bb832fa39bf459fcf77a05eb9d [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>;
Evan Cheng0d14fc82008-09-01 01:51:14 +0000123
124// addrmode1 instructions
Evan Cheng37f25d92008-08-28 23:39:26 +0000125class AI1<bits<4> opcod, dag oops, dag iops, Format f, string opc,
126 string asm, list<dag> pattern>
127 : I<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc,
Evan Cheng612b79e2008-08-29 07:40:52 +0000128 asm, "", pattern> {
Evan Chengb7880ac2008-08-31 18:32:16 +0000129 let Inst{21-24} = opcod;
130 let Inst{26-27} = 0;
Evan Cheng612b79e2008-08-29 07:40:52 +0000131}
Evan Cheng37f25d92008-08-28 23:39:26 +0000132class AsI1<bits<4> opcod, dag oops, dag iops, Format f, string opc,
133 string asm, list<dag> pattern>
134 : sI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, opc,
Evan Cheng612b79e2008-08-29 07:40:52 +0000135 asm, "", pattern> {
Evan Chengb7880ac2008-08-31 18:32:16 +0000136 let Inst{20} = 1;
137 let Inst{21-24} = opcod;
138 let Inst{26-27} = 0;
Evan Cheng612b79e2008-08-29 07:40:52 +0000139}
Evan Cheng0d14fc82008-09-01 01:51:14 +0000140class AI1x2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
141 string asm, list<dag> pattern>
142 : I<opcod, oops, iops, AddrMode1, Size8Bytes, IndexModeNone, f, opc,
143 asm, "", pattern>;
Evan Cheng17222df2008-08-31 19:02:21 +0000144
Evan Cheng0d14fc82008-09-01 01:51:14 +0000145
146// addrmode2 loads and stores
Evan Cheng37f25d92008-08-28 23:39:26 +0000147class AI2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
148 string asm, list<dag> pattern>
149 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, opc,
Evan Cheng17222df2008-08-31 19:02:21 +0000150 asm, "", pattern> {
151 let Inst{26-27} = 1;
152}
Evan Cheng93912732008-09-01 01:27:33 +0000153
154// loads
Evan Cheng17222df2008-08-31 19:02:21 +0000155class AI2ldw<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} = 0; // B bit
161 let Inst{24} = 1; // P bit
162}
163class AI2ldb<bits<4> opcod, dag oops, dag iops, Format f, string opc,
164 string asm, list<dag> pattern>
165 : AI2<opcod, oops, iops, f, opc, asm, pattern> {
166 let Inst{20} = 1; // load bit
167 let Inst{21} = 0; // W bit
168 let Inst{22} = 1; // B bit
169 let Inst{24} = 1; // P bit
170}
171
Evan Cheng93912732008-09-01 01:27:33 +0000172// stores
173class AI2stw<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} = 0; // B bit
179 let Inst{24} = 1; // P bit
180}
181class AI2stb<bits<4> opcod, dag oops, dag iops, Format f, string opc,
182 string asm, list<dag> pattern>
183 : AI2<opcod, oops, iops, f, opc, asm, pattern> {
184 let Inst{20} = 0; // load bit
185 let Inst{21} = 0; // W bit
186 let Inst{22} = 1; // B bit
187 let Inst{24} = 1; // P bit
188}
189
Evan Cheng37f25d92008-08-28 23:39:26 +0000190// Pre-indexed ops
Evan Cheng93912732008-09-01 01:27:33 +0000191// loads
192class AI2ldwpr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
Evan Cheng37f25d92008-08-28 23:39:26 +0000193 string asm, string cstr, list<dag> pattern>
194 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
Evan Cheng93912732008-09-01 01:27:33 +0000195 asm, cstr, pattern> {
196 let Inst{20} = 1; // load bit
197 let Inst{21} = 1; // W bit
198 let Inst{22} = 0; // B bit
199 let Inst{24} = 1; // P bit
200}
201class AI2ldbpr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
202 string asm, string cstr, list<dag> pattern>
203 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
204 asm, cstr, pattern> {
205 let Inst{20} = 1; // load bit
206 let Inst{21} = 1; // W bit
207 let Inst{22} = 1; // B bit
208 let Inst{24} = 1; // P bit
209}
210
211// stores
212class AI2stwpr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
213 string asm, string cstr, list<dag> pattern>
214 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
215 asm, cstr, pattern> {
216 let Inst{20} = 0; // load bit
217 let Inst{21} = 1; // W bit
218 let Inst{22} = 0; // B bit
219 let Inst{24} = 1; // P bit
220}
221class AI2stbpr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
222 string asm, string cstr, list<dag> pattern>
223 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
224 asm, cstr, pattern> {
225 let Inst{20} = 0; // load bit
226 let Inst{21} = 1; // W bit
227 let Inst{22} = 1; // B bit
228 let Inst{24} = 1; // P bit
229}
230
Evan Cheng37f25d92008-08-28 23:39:26 +0000231// Post-indexed ops
Evan Cheng93912732008-09-01 01:27:33 +0000232// loads
233class AI2ldwpo<bits<4> opcod, dag oops, dag iops, Format f, string opc,
Evan Cheng37f25d92008-08-28 23:39:26 +0000234 string asm, string cstr, list<dag> pattern>
235 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
Evan Cheng93912732008-09-01 01:27:33 +0000236 asm, cstr,pattern> {
237 let Inst{20} = 1; // load bit
238 let Inst{21} = 0; // W bit
239 let Inst{22} = 0; // B bit
240 let Inst{24} = 0; // P bit
241}
242class AI2ldbpo<bits<4> opcod, dag oops, dag iops, Format f, string opc,
243 string asm, string cstr, list<dag> pattern>
244 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
245 asm, cstr,pattern> {
246 let Inst{20} = 1; // load bit
247 let Inst{21} = 0; // W bit
248 let Inst{22} = 1; // B bit
249 let Inst{24} = 0; // P bit
250}
251
252// stores
253class AI2stwpo<bits<4> opcod, dag oops, dag iops, Format f, string opc,
254 string asm, string cstr, list<dag> pattern>
255 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
256 asm, cstr,pattern> {
257 let Inst{20} = 0; // load bit
258 let Inst{21} = 0; // W bit
259 let Inst{22} = 0; // B bit
260 let Inst{24} = 0; // P bit
261}
262class AI2stbpo<bits<4> opcod, dag oops, dag iops, Format f, string opc,
263 string asm, string cstr, list<dag> pattern>
264 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
265 asm, cstr,pattern> {
266 let Inst{20} = 0; // load bit
267 let Inst{21} = 0; // W bit
268 let Inst{22} = 1; // B bit
269 let Inst{24} = 0; // P bit
270}
271
Evan Cheng0d14fc82008-09-01 01:51:14 +0000272// addrmode3 instructions
273class AI3<bits<4> opcod, dag oops, dag iops, Format f, string opc,
274 string asm, list<dag> pattern>
275 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, opc,
276 asm, "", pattern>;
277
278// addrmode4 instructions
279class AI4<bits<4> opcod, dag oops, dag iops, Format f, string opc,
280 string asm, list<dag> pattern>
281 : I<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, opc,
282 asm, "", pattern>;
283
284
285// Pre-indexed ops
286class AI3pr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
287 string asm, string cstr, list<dag> pattern>
288 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePre, f, opc,
289 asm, cstr, pattern>;
290
291
292// Post-indexed ops
Evan Cheng37f25d92008-08-28 23:39:26 +0000293class AI3po<bits<4> opcod, dag oops, dag iops, Format f, string opc,
294 string asm, string cstr, list<dag> pattern>
295 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePost, f, opc,
296 asm, cstr,pattern>;
297
298
299// Special cases.
300class XI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
301 IndexMode im, Format f, string asm, string cstr, list<dag> pattern>
302 : InstARM<opcod, am, sz, im, f, cstr> {
303 let OutOperandList = oops;
304 let InOperandList = iops;
305 let AsmString = asm;
306 let Pattern = pattern;
307 list<Predicate> Predicates = [IsARM];
308}
309
310class AXI<bits<4> opcod, dag oops, dag iops, Format f, string asm,
311 list<dag> pattern>
312 : XI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, asm,
313 "", pattern>;
314class AXI1<bits<4> opcod, dag oops, dag iops, Format f, string asm,
315 list<dag> pattern>
316 : XI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, asm,
317 "", pattern>;
318class AXI2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
319 list<dag> pattern>
320 : XI<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, asm,
321 "", pattern>;
322class AXI3<bits<4> opcod, dag oops, dag iops, Format f, string asm,
323 list<dag> pattern>
324 : XI<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, asm,
325 "", pattern>;
326class AXI4<bits<4> opcod, dag oops, dag iops, Format f, string asm,
327 list<dag> pattern>
328 : XI<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, asm,
329 "", pattern>;
330
331class AXIx2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
332 list<dag> pattern>
333 : XI<opcod, oops, iops, AddrModeNone, Size8Bytes, IndexModeNone, f, asm,
334 "", pattern>;
335
336// BR_JT instructions
337class JTI<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
338 : XI<opcod, oops, iops, AddrModeNone, SizeSpecial, IndexModeNone, BranchMisc,
339 asm, "", pattern>;
340class JTI1<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
341 : XI<opcod, oops, iops, AddrMode1, SizeSpecial, IndexModeNone, BranchMisc,
342 asm, "", pattern>;
343class JTI2<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
344 : XI<opcod, oops, iops, AddrMode2, SizeSpecial, IndexModeNone, BranchMisc,
345 asm, "", pattern>;
346
347
348//===----------------------------------------------------------------------===//
349
350// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
351class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
352 list<Predicate> Predicates = [IsARM];
353}
354class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
355 list<Predicate> Predicates = [IsARM, HasV5TE];
356}
357class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
358 list<Predicate> Predicates = [IsARM, HasV6];
359}
Evan Cheng13096642008-08-29 06:41:12 +0000360
361//===----------------------------------------------------------------------===//
362//
363// Thumb Instruction Format Definitions.
364//
365
366
367// TI - Thumb instruction.
368
369class ThumbI<dag outs, dag ins, AddrMode am, SizeFlagVal sz,
370 string asm, string cstr, list<dag> pattern>
371 // FIXME: Set all opcodes to 0 for now.
372 : InstARM<0, am, sz, IndexModeNone, ThumbFrm, cstr> {
373 let OutOperandList = outs;
374 let InOperandList = ins;
375 let AsmString = asm;
376 let Pattern = pattern;
377 list<Predicate> Predicates = [IsThumb];
378}
379
380class TI<dag outs, dag ins, string asm, list<dag> pattern>
381 : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "", pattern>;
382class TI1<dag outs, dag ins, string asm, list<dag> pattern>
383 : ThumbI<outs, ins, AddrModeT1, Size2Bytes, asm, "", pattern>;
384class TI2<dag outs, dag ins, string asm, list<dag> pattern>
385 : ThumbI<outs, ins, AddrModeT2, Size2Bytes, asm, "", pattern>;
386class TI4<dag outs, dag ins, string asm, list<dag> pattern>
387 : ThumbI<outs, ins, AddrModeT4, Size2Bytes, asm, "", pattern>;
388class TIs<dag outs, dag ins, string asm, list<dag> pattern>
389 : ThumbI<outs, ins, AddrModeTs, Size2Bytes, asm, "", pattern>;
390
391// Two-address instructions
392class TIt<dag outs, dag ins, string asm, list<dag> pattern>
393 : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "$lhs = $dst", pattern>;
394
395// BL, BLX(1) are translated by assembler into two instructions
396class TIx2<dag outs, dag ins, string asm, list<dag> pattern>
397 : ThumbI<outs, ins, AddrModeNone, Size4Bytes, asm, "", pattern>;
398
399// BR_JT instructions
400class TJTI<dag outs, dag ins, string asm, list<dag> pattern>
401 : ThumbI<outs, ins, AddrModeNone, SizeSpecial, asm, "", pattern>;
402
403
404//===----------------------------------------------------------------------===//
405
406
407// ThumbPat - Same as Pat<>, but requires that the compiler be in Thumb mode.
408class ThumbPat<dag pattern, dag result> : Pat<pattern, result> {
409 list<Predicate> Predicates = [IsThumb];
410}
411
412class ThumbV5Pat<dag pattern, dag result> : Pat<pattern, result> {
413 list<Predicate> Predicates = [IsThumb, HasV5T];
414}