blob: a7c994f2a3f34fe4350a144cd9881ad6e0845c2f [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> {
127 let Inst{5-6} = 0;
128 let Inst{7-10} = opcod;
129}
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> {
134 let Inst{5-6} = 0;
135 let Inst{7-10} = opcod;
136}
Evan Cheng37f25d92008-08-28 23:39:26 +0000137class AI2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
138 string asm, list<dag> pattern>
139 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, opc,
140 asm, "", pattern>;
141class AI3<bits<4> opcod, dag oops, dag iops, Format f, string opc,
142 string asm, list<dag> pattern>
143 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, opc,
144 asm, "", pattern>;
145class AI4<bits<4> opcod, dag oops, dag iops, Format f, string opc,
146 string asm, list<dag> pattern>
147 : I<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, opc,
148 asm, "", pattern>;
149class AI1x2<bits<4> opcod, dag oops, dag iops, Format f, string opc,
150 string asm, list<dag> pattern>
151 : I<opcod, oops, iops, AddrMode1, Size8Bytes, IndexModeNone, f, opc,
152 asm, "", pattern>;
153
154// Pre-indexed ops
155class AI2pr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
156 string asm, string cstr, list<dag> pattern>
157 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePre, f, opc,
158 asm, cstr, pattern>;
159class AI3pr<bits<4> opcod, dag oops, dag iops, Format f, string opc,
160 string asm, string cstr, list<dag> pattern>
161 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePre, f, opc,
162 asm, cstr, pattern>;
163
164// Post-indexed ops
165class AI2po<bits<4> opcod, dag oops, dag iops, Format f, string opc,
166 string asm, string cstr, list<dag> pattern>
167 : I<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModePost, f, opc,
168 asm, cstr,pattern>;
169class AI3po<bits<4> opcod, dag oops, dag iops, Format f, string opc,
170 string asm, string cstr, list<dag> pattern>
171 : I<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModePost, f, opc,
172 asm, cstr,pattern>;
173
174
175// Special cases.
176class XI<bits<4> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
177 IndexMode im, Format f, string asm, string cstr, list<dag> pattern>
178 : InstARM<opcod, am, sz, im, f, cstr> {
179 let OutOperandList = oops;
180 let InOperandList = iops;
181 let AsmString = asm;
182 let Pattern = pattern;
183 list<Predicate> Predicates = [IsARM];
184}
185
186class AXI<bits<4> opcod, dag oops, dag iops, Format f, string asm,
187 list<dag> pattern>
188 : XI<opcod, oops, iops, AddrModeNone, Size4Bytes, IndexModeNone, f, asm,
189 "", pattern>;
190class AXI1<bits<4> opcod, dag oops, dag iops, Format f, string asm,
191 list<dag> pattern>
192 : XI<opcod, oops, iops, AddrMode1, Size4Bytes, IndexModeNone, f, asm,
193 "", pattern>;
194class AXI2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
195 list<dag> pattern>
196 : XI<opcod, oops, iops, AddrMode2, Size4Bytes, IndexModeNone, f, asm,
197 "", pattern>;
198class AXI3<bits<4> opcod, dag oops, dag iops, Format f, string asm,
199 list<dag> pattern>
200 : XI<opcod, oops, iops, AddrMode3, Size4Bytes, IndexModeNone, f, asm,
201 "", pattern>;
202class AXI4<bits<4> opcod, dag oops, dag iops, Format f, string asm,
203 list<dag> pattern>
204 : XI<opcod, oops, iops, AddrMode4, Size4Bytes, IndexModeNone, f, asm,
205 "", pattern>;
206
207class AXIx2<bits<4> opcod, dag oops, dag iops, Format f, string asm,
208 list<dag> pattern>
209 : XI<opcod, oops, iops, AddrModeNone, Size8Bytes, IndexModeNone, f, asm,
210 "", pattern>;
211
212// BR_JT instructions
213class JTI<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
214 : XI<opcod, oops, iops, AddrModeNone, SizeSpecial, IndexModeNone, BranchMisc,
215 asm, "", pattern>;
216class JTI1<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
217 : XI<opcod, oops, iops, AddrMode1, SizeSpecial, IndexModeNone, BranchMisc,
218 asm, "", pattern>;
219class JTI2<bits<4> opcod, dag oops, dag iops, string asm, list<dag> pattern>
220 : XI<opcod, oops, iops, AddrMode2, SizeSpecial, IndexModeNone, BranchMisc,
221 asm, "", pattern>;
222
223
224//===----------------------------------------------------------------------===//
225
226// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
227class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
228 list<Predicate> Predicates = [IsARM];
229}
230class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
231 list<Predicate> Predicates = [IsARM, HasV5TE];
232}
233class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
234 list<Predicate> Predicates = [IsARM, HasV6];
235}
Evan Cheng13096642008-08-29 06:41:12 +0000236
237//===----------------------------------------------------------------------===//
238//
239// Thumb Instruction Format Definitions.
240//
241
242
243// TI - Thumb instruction.
244
245class ThumbI<dag outs, dag ins, AddrMode am, SizeFlagVal sz,
246 string asm, string cstr, list<dag> pattern>
247 // FIXME: Set all opcodes to 0 for now.
248 : InstARM<0, am, sz, IndexModeNone, ThumbFrm, cstr> {
249 let OutOperandList = outs;
250 let InOperandList = ins;
251 let AsmString = asm;
252 let Pattern = pattern;
253 list<Predicate> Predicates = [IsThumb];
254}
255
256class TI<dag outs, dag ins, string asm, list<dag> pattern>
257 : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "", pattern>;
258class TI1<dag outs, dag ins, string asm, list<dag> pattern>
259 : ThumbI<outs, ins, AddrModeT1, Size2Bytes, asm, "", pattern>;
260class TI2<dag outs, dag ins, string asm, list<dag> pattern>
261 : ThumbI<outs, ins, AddrModeT2, Size2Bytes, asm, "", pattern>;
262class TI4<dag outs, dag ins, string asm, list<dag> pattern>
263 : ThumbI<outs, ins, AddrModeT4, Size2Bytes, asm, "", pattern>;
264class TIs<dag outs, dag ins, string asm, list<dag> pattern>
265 : ThumbI<outs, ins, AddrModeTs, Size2Bytes, asm, "", pattern>;
266
267// Two-address instructions
268class TIt<dag outs, dag ins, string asm, list<dag> pattern>
269 : ThumbI<outs, ins, AddrModeNone, Size2Bytes, asm, "$lhs = $dst", pattern>;
270
271// BL, BLX(1) are translated by assembler into two instructions
272class TIx2<dag outs, dag ins, string asm, list<dag> pattern>
273 : ThumbI<outs, ins, AddrModeNone, Size4Bytes, asm, "", pattern>;
274
275// BR_JT instructions
276class TJTI<dag outs, dag ins, string asm, list<dag> pattern>
277 : ThumbI<outs, ins, AddrModeNone, SizeSpecial, asm, "", pattern>;
278
279
280//===----------------------------------------------------------------------===//
281
282
283// ThumbPat - Same as Pat<>, but requires that the compiler be in Thumb mode.
284class ThumbPat<dag pattern, dag result> : Pat<pattern, result> {
285 list<Predicate> Predicates = [IsThumb];
286}
287
288class ThumbV5Pat<dag pattern, dag result> : Pat<pattern, result> {
289 list<Predicate> Predicates = [IsThumb, HasV5T];
290}