Hexagon: Set accessSize and addrMode on all load/store instructions.
[oota-llvm.git] / lib / Target / Hexagon / HexagonInstrFormats.td
1 //==- HexagonInstrFormats.td - Hexagon 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 //                         Hexagon Intruction Flags +
12 //
13 //                    *** Must match HexagonBaseInfo.h ***
14 //===----------------------------------------------------------------------===//
15
16 class IType<bits<5> t> {
17   bits<5> Value = t;
18 }
19 def TypePSEUDO : IType<0>;
20 def TypeALU32  : IType<1>;
21 def TypeCR     : IType<2>;
22 def TypeJR     : IType<3>;
23 def TypeJ      : IType<4>;
24 def TypeLD     : IType<5>;
25 def TypeST     : IType<6>;
26 def TypeSYSTEM : IType<7>;
27 def TypeXTYPE  : IType<8>;
28 def TypeENDLOOP: IType<31>;
29
30 // Maintain list of valid subtargets for each instruction.
31 class SubTarget<bits<4> value> {
32   bits<4> Value = value;
33 }
34
35 def HasV2SubT     : SubTarget<0xf>;
36 def HasV2SubTOnly : SubTarget<0x1>;
37 def NoV2SubT      : SubTarget<0x0>;
38 def HasV3SubT     : SubTarget<0xe>;
39 def HasV3SubTOnly : SubTarget<0x2>;
40 def NoV3SubT      : SubTarget<0x1>;
41 def HasV4SubT     : SubTarget<0xc>;
42 def NoV4SubT      : SubTarget<0x3>;
43 def HasV5SubT     : SubTarget<0x8>;
44 def NoV5SubT      : SubTarget<0x7>;
45
46 // Addressing modes for load/store instructions
47 class AddrModeType<bits<3> value> {
48   bits<3> Value = value;
49 }
50
51 def NoAddrMode     : AddrModeType<0>;  // No addressing mode
52 def Absolute       : AddrModeType<1>;  // Absolute addressing mode
53 def AbsoluteSet    : AddrModeType<2>;  // Absolute set addressing mode
54 def BaseImmOffset  : AddrModeType<3>;  // Indirect with offset
55 def BaseLongOffset : AddrModeType<4>;  // Indirect with long offset
56 def BaseRegOffset  : AddrModeType<5>;  // Indirect with register offset
57 def PostInc        : AddrModeType<6>;  // Post increment addressing mode
58
59 class MemAccessSize<bits<3> value> {
60   bits<3> Value = value;
61 }
62
63 def NoMemAccess      : MemAccessSize<0>;// Not a memory acces instruction.
64 def ByteAccess       : MemAccessSize<1>;// Byte access instruction (memb).
65 def HalfWordAccess   : MemAccessSize<2>;// Half word access instruction (memh).
66 def WordAccess       : MemAccessSize<3>;// Word access instrution (memw).
67 def DoubleWordAccess : MemAccessSize<4>;// Double word access instruction (memd)
68
69
70 //===----------------------------------------------------------------------===//
71 //                         Intruction Class Declaration +
72 //===----------------------------------------------------------------------===//
73
74 class OpcodeHexagon {
75   field bits<32> Inst = ?; // Default to an invalid insn.
76   bits<4> IClass = 0; // ICLASS
77   bits<2> IParse = 0; // Parse bits.
78
79   let Inst{31-28} = IClass;
80   let Inst{15-14} = IParse;
81
82   bits<1> zero = 0;
83 }
84
85 class InstHexagon<dag outs, dag ins, string asmstr, list<dag> pattern,
86                   string cstr, InstrItinClass itin, IType type>
87   : Instruction, OpcodeHexagon {
88   let Namespace = "Hexagon";
89
90   dag OutOperandList = outs;
91   dag InOperandList = ins;
92   let AsmString = asmstr;
93   let Pattern = pattern;
94   let Constraints = cstr;
95   let Itinerary = itin;
96   let Size = 4;
97
98   // *** Must match MCTargetDesc/HexagonBaseInfo.h ***
99
100   // Instruction type according to the ISA.
101   IType Type = type;
102   let TSFlags{4-0} = Type.Value;
103
104   // Solo instructions, i.e., those that cannot be in a packet with others.
105   bits<1> isSolo = 0;
106   let TSFlags{5} = isSolo;
107
108   // Predicated instructions.
109   bits<1> isPredicated = 0;
110   let TSFlags{6} = isPredicated;
111   bits<1> isPredicatedFalse = 0;
112   let TSFlags{7} = isPredicatedFalse;
113   bits<1> isPredicatedNew = 0;
114   let TSFlags{8} = isPredicatedNew;
115
116   // New-value insn helper fields.
117   bits<1> isNewValue = 0;
118   let TSFlags{9} = isNewValue; // New-value consumer insn.
119   bits<1> hasNewValue = 0;
120   let TSFlags{10} = hasNewValue; // New-value producer insn.
121   bits<3> opNewValue = 0;
122   let TSFlags{13-11} = opNewValue; // New-value produced operand.
123   bits<2> opNewBits = 0;
124   let TSFlags{15-14} = opNewBits; // New-value opcode bits location: 0, 8, 16.
125   bits<1> isNVStorable = 0;
126   let TSFlags{16} = isNVStorable; // Store that can become new-value store.
127   bits<1> isNVStore = 0;
128   let TSFlags{17} = isNVStore; // New-value store insn.
129
130   // Immediate extender helper fields.
131   bits<1> isExtendable = 0;
132   let TSFlags{18} = isExtendable; // Insn may be extended.
133   bits<1> isExtended = 0;
134   let TSFlags{19} = isExtended; // Insn must be extended.
135   bits<3> opExtendable = 0;
136   let TSFlags{22-20} = opExtendable; // Which operand may be extended.
137   bits<1> isExtentSigned = 0;
138   let TSFlags{23} = isExtentSigned; // Signed or unsigned range.
139   bits<5> opExtentBits = 0;
140   let TSFlags{28-24} = opExtentBits; //Number of bits of range before extending.
141
142   // If an instruction is valid on a subtarget (v2-v5), set the corresponding
143   // bit from validSubTargets. v2 is the least significant bit.
144   // By default, instruction is valid on all subtargets.
145   SubTarget validSubTargets = HasV2SubT;
146   let TSFlags{32-29} = validSubTargets.Value;
147
148   // Addressing mode for load/store instructions.
149   AddrModeType addrMode = NoAddrMode;
150   let TSFlags{35-33} = addrMode.Value;
151
152   // Memory access size for mem access instructions (load/store)
153   MemAccessSize accessSize = NoMemAccess;
154   let TSFlags{38-36} = accessSize.Value;
155
156   // Fields used for relation models.
157   string BaseOpcode = "";
158   string CextOpcode = "";
159   string PredSense = "";
160   string PNewValue = "";
161   string InputType = "";    // Input is "imm" or "reg" type.
162   string isMEMri = "false"; // Set to "true" for load/store with MEMri operand.
163   string isFloat = "false"; // Set to "true" for the floating-point load/store.
164   string isBrTaken = ""; // Set to "true"/"false" for jump instructions
165
166   let PredSense = !if(isPredicated, !if(isPredicatedFalse, "false", "true"),
167                                     "");
168   let PNewValue = !if(isPredicatedNew, "new", "");
169
170   // *** Must match MCTargetDesc/HexagonBaseInfo.h ***
171 }
172
173 //===----------------------------------------------------------------------===//
174 //                         Intruction Classes Definitions +
175 //===----------------------------------------------------------------------===//
176
177 // LD Instruction Class in V2/V3/V4.
178 // Definition of the instruction class NOT CHANGED.
179 class LDInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
180              string cstr = "">
181   : InstHexagon<outs, ins, asmstr, pattern, cstr, LD, TypeLD>;
182
183 let mayLoad = 1 in
184 class LDInst2<dag outs, dag ins, string asmstr, list<dag> pattern = [],
185               string cstr = "">
186   : LDInst<outs, ins, asmstr, pattern, cstr>;
187
188 class CONSTLDInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
189                   string cstr = "">
190   : LDInst<outs, ins, asmstr, pattern, cstr>;
191
192 // LD Instruction Class in V2/V3/V4.
193 // Definition of the instruction class NOT CHANGED.
194 class LDInstPost<dag outs, dag ins, string asmstr, list<dag> pattern = [],
195                  string cstr = "">
196   : LDInst<outs, ins, asmstr, pattern, cstr>;
197
198 let mayLoad = 1 in
199 class LD0Inst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
200               string cstr = "">
201   : LDInst<outs, ins, asmstr, pattern, cstr>;
202
203 // ST Instruction Class in V2/V3 can take SLOT0 only.
204 // ST Instruction Class in V4    can take SLOT0 & SLOT1.
205 // Definition of the instruction class CHANGED from V2/V3 to V4.
206 let mayStore = 1 in
207 class STInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
208              string cstr = "">
209   : InstHexagon<outs, ins, asmstr, pattern, cstr, ST, TypeST>;
210
211 class STInst2<dag outs, dag ins, string asmstr, list<dag> pattern = [],
212               string cstr = "">
213   : STInst<outs, ins, asmstr, pattern, cstr>;
214
215 let mayStore = 1 in
216 class ST0Inst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
217               string cstr = "">
218   : InstHexagon<outs, ins, asmstr, pattern, cstr, ST0, TypeST>;
219
220 // ST Instruction Class in V2/V3 can take SLOT0 only.
221 // ST Instruction Class in V4    can take SLOT0 & SLOT1.
222 // Definition of the instruction class CHANGED from V2/V3 to V4.
223 class STInstPost<dag outs, dag ins, string asmstr, list<dag> pattern = [],
224                  string cstr = "">
225   : STInst<outs, ins, asmstr, pattern, cstr>;
226
227 // SYSTEM Instruction Class in V4 can take SLOT0 only
228 // In V2/V3 we used ST for this but in v4 ST can take SLOT0 or SLOT1.
229 class SYSInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
230               string cstr = "">
231   : InstHexagon<outs, ins, asmstr, pattern, cstr, SYS, TypeSYSTEM>;
232
233 // ALU32 Instruction Class in V2/V3/V4.
234 // Definition of the instruction class NOT CHANGED.
235 class ALU32Inst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
236                 string cstr = "">
237    : InstHexagon<outs, ins, asmstr, pattern, cstr, ALU32, TypeALU32>;
238
239 // ALU64 Instruction Class in V2/V3.
240 // XTYPE Instruction Class in V4.
241 // Definition of the instruction class NOT CHANGED.
242 // Name of the Instruction Class changed from ALU64 to XTYPE from V2/V3 to V4.
243 class ALU64Inst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
244                 string cstr = "">
245    : InstHexagon<outs, ins, asmstr, pattern, cstr, ALU64, TypeXTYPE>;
246
247 class ALU64_acc<dag outs, dag ins, string asmstr, list<dag> pattern = [],
248                 string cstr = "">
249   : ALU64Inst<outs, ins, asmstr, pattern, cstr>;
250
251
252 // M Instruction Class in V2/V3.
253 // XTYPE Instruction Class in V4.
254 // Definition of the instruction class NOT CHANGED.
255 // Name of the Instruction Class changed from M to XTYPE from V2/V3 to V4.
256 class MInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
257             string cstr = "">
258   : InstHexagon<outs, ins, asmstr, pattern, cstr, M, TypeXTYPE>;
259
260 // M Instruction Class in V2/V3.
261 // XTYPE Instruction Class in V4.
262 // Definition of the instruction class NOT CHANGED.
263 // Name of the Instruction Class changed from M to XTYPE from V2/V3 to V4.
264 class MInst_acc<dag outs, dag ins, string asmstr, list<dag> pattern = [],
265                 string cstr = "">
266     : MInst<outs, ins, asmstr, pattern, cstr>;
267
268 // S Instruction Class in V2/V3.
269 // XTYPE Instruction Class in V4.
270 // Definition of the instruction class NOT CHANGED.
271 // Name of the Instruction Class changed from S to XTYPE from V2/V3 to V4.
272 class SInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
273             string cstr = "">
274   : InstHexagon<outs, ins, asmstr, pattern, cstr, S, TypeXTYPE>;
275
276 // S Instruction Class in V2/V3.
277 // XTYPE Instruction Class in V4.
278 // Definition of the instruction class NOT CHANGED.
279 // Name of the Instruction Class changed from S to XTYPE from V2/V3 to V4.
280 class SInst_acc<dag outs, dag ins, string asmstr, list<dag> pattern = [],
281                 string cstr = "">
282   : SInst<outs, ins, asmstr, pattern, cstr>;
283
284 // J Instruction Class in V2/V3/V4.
285 // Definition of the instruction class NOT CHANGED.
286 class JInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
287             string cstr = "">
288   : InstHexagon<outs, ins, asmstr, pattern, cstr, J, TypeJ>;
289
290 // JR Instruction Class in V2/V3/V4.
291 // Definition of the instruction class NOT CHANGED.
292 class JRInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
293              string cstr = "">
294   : InstHexagon<outs, ins, asmstr, pattern, cstr, JR, TypeJR>;
295
296 // CR Instruction Class in V2/V3/V4.
297 // Definition of the instruction class NOT CHANGED.
298 class CRInst<dag outs, dag ins, string asmstr, list<dag> pattern = [],
299              string cstr = "">
300   : InstHexagon<outs, ins, asmstr, pattern, cstr, CR, TypeCR>;
301
302 let isCodeGenOnly = 1, isPseudo = 1 in
303 class Endloop<dag outs, dag ins, string asmstr, list<dag> pattern = [],
304               string cstr = "">
305   : InstHexagon<outs, ins, asmstr, pattern, cstr, ENDLOOP, TypeENDLOOP>;
306
307 let isCodeGenOnly = 1, isPseudo = 1 in
308 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern = [],
309              string cstr = "">
310   : InstHexagon<outs, ins, asmstr, pattern, cstr, PSEUDO, TypePSEUDO>;
311
312 let isCodeGenOnly = 1, isPseudo = 1 in
313 class PseudoM<dag outs, dag ins, string asmstr, list<dag> pattern = [],
314               string cstr="">
315   : InstHexagon<outs, ins, asmstr, pattern, cstr, PSEUDOM, TypePSEUDO>;
316
317 //===----------------------------------------------------------------------===//
318 //                         Intruction Classes Definitions -
319 //===----------------------------------------------------------------------===//
320
321
322 //
323 // ALU32 patterns
324 //.
325 class ALU32_rr<dag outs, dag ins, string asmstr, list<dag> pattern,
326                string cstr = "">
327    : ALU32Inst<outs, ins, asmstr, pattern, cstr>;
328
329 class ALU32_ir<dag outs, dag ins, string asmstr, list<dag> pattern,
330                string cstr = "">
331    : ALU32Inst<outs, ins, asmstr, pattern, cstr>;
332
333 class ALU32_ri<dag outs, dag ins, string asmstr, list<dag> pattern,
334                string cstr = "">
335    : ALU32Inst<outs, ins, asmstr, pattern, cstr>;
336
337 class ALU32_ii<dag outs, dag ins, string asmstr, list<dag> pattern,
338                string cstr = "">
339    : ALU32Inst<outs, ins, asmstr, pattern, cstr>;
340
341 //
342 // ALU64 patterns.
343 //
344 class ALU64_rr<dag outs, dag ins, string asmstr, list<dag> pattern,
345                string cstr = "">
346    : ALU64Inst<outs, ins, asmstr, pattern, cstr>;
347
348 class ALU64_ri<dag outs, dag ins, string asmstr, list<dag> pattern,
349                string cstr = "">
350    : ALU64Inst<outs, ins, asmstr, pattern, cstr>;
351
352 // Post increment ST Instruction.
353 class STInstPI<dag outs, dag ins, string asmstr, list<dag> pattern = [],
354                string cstr = "">
355   : STInst<outs, ins, asmstr, pattern, cstr>;
356
357 let mayStore = 1 in
358 class STInst2PI<dag outs, dag ins, string asmstr, list<dag> pattern = [],
359                 string cstr = "">
360   : STInst<outs, ins, asmstr, pattern, cstr>;
361
362 // Post increment LD Instruction.
363 class LDInstPI<dag outs, dag ins, string asmstr, list<dag> pattern = [],
364                string cstr = "">
365   : LDInst<outs, ins, asmstr, pattern, cstr>;
366
367 let mayLoad = 1 in
368 class LDInst2PI<dag outs, dag ins, string asmstr, list<dag> pattern = [],
369                 string cstr = "">
370   : LDInst<outs, ins, asmstr, pattern, cstr>;
371
372 //===----------------------------------------------------------------------===//
373 // V4 Instruction Format Definitions +
374 //===----------------------------------------------------------------------===//
375
376 include "HexagonInstrFormatsV4.td"
377
378 //===----------------------------------------------------------------------===//
379 // V4 Instruction Format Definitions +
380 //===----------------------------------------------------------------------===//