1//===- HexagonBaseInfo.h - Top level definitions for Hexagon ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains small standalone helper functions and enum definitions for
10// the Hexagon target useful for the compiler back-end and the MC libraries.
11// As such, it deliberately does not include references to LLVM core
12// code gen types, passes, etc..
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONBASEINFO_H
17#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONBASEINFO_H
18
19#include <cstdint>
20
21#include "HexagonDepITypes.h"
22#include "MCTargetDesc/HexagonMCTargetDesc.h"
23#include "llvm/MC/MCInstrDesc.h"
24
25namespace llvm {
26
27/// HexagonII - This namespace holds all of the target specific flags that
28/// instruction info tracks.
29namespace HexagonII {
30 unsigned const TypeCVI_FIRST = TypeCVI_4SLOT_MPY;
31 unsigned const TypeCVI_LAST = TypeCVI_ZW;
32
33 enum AddrMode {
34 NoAddrMode = 0, // No addressing mode
35 Absolute = 1, // Absolute addressing mode
36 AbsoluteSet = 2, // Absolute set addressing mode
37 BaseImmOffset = 3, // Indirect with offset
38 BaseLongOffset = 4, // Indirect with long offset
39 BaseRegOffset = 5, // Indirect with register offset
40 PostInc = 6 // Post increment addressing mode
41 };
42
43 enum MemAccessSize {
44 NoMemAccess = 0,
45 ByteAccess,
46 HalfWordAccess,
47 WordAccess,
48 DoubleWordAccess,
49 HVXVectorAccess,
50 HLXVectorAccess
51 };
52
53 enum class RegType : uint8_t {
54 Unknown = 0,
55 QF32,
56 QF16,
57 };
58
59 struct RegTypeInfo {
60 RegType Output = RegType::Unknown;
61 RegType Input1 = RegType::Unknown;
62 RegType Input2 = RegType::Unknown;
63 RegType Input3 = RegType::Unknown;
64 };
65
66 RegTypeInfo getRegTypeInfo(unsigned Opcode);
67
68 inline RegType getOpRegType(unsigned Opcode) {
69 return getRegTypeInfo(Opcode).Output;
70 }
71 inline RegType getInp1RegType(unsigned Opcode) {
72 return getRegTypeInfo(Opcode).Input1;
73 }
74 inline RegType getInp2RegType(unsigned Opcode) {
75 return getRegTypeInfo(Opcode).Input2;
76 }
77 inline RegType getInp3RegType(unsigned Opcode) {
78 return getRegTypeInfo(Opcode).Input3;
79 }
80
81 // MCInstrDesc TSFlags
82 // *** Must match HexagonInstrFormat*.td ***
83 enum HexagonTSFlagsVal {
84 // This 7-bit field describes the insn type.
85 TypePos = 0,
86 TypeMask = 0x7f,
87
88 // Solo instructions.
89 SoloPos = 7,
90 SoloMask = 0x1,
91 // Packed only with A or X-type instructions.
92 SoloAXPos = 8,
93 SoloAXMask = 0x1,
94 // Only A-type instruction in first slot or nothing.
95 RestrictSlot1AOKPos = 9,
96 RestrictSlot1AOKMask = 0x1,
97
98 // Predicated instructions.
99 PredicatedPos = 10,
100 PredicatedMask = 0x1,
101 PredicatedFalsePos = 11,
102 PredicatedFalseMask = 0x1,
103 PredicatedNewPos = 12,
104 PredicatedNewMask = 0x1,
105 PredicateLatePos = 13,
106 PredicateLateMask = 0x1,
107
108 // New-Value consumer instructions.
109 NewValuePos = 14,
110 NewValueMask = 0x1,
111 // New-Value producer instructions.
112 hasNewValuePos = 15,
113 hasNewValueMask = 0x1,
114 // Which operand consumes or produces a new value.
115 NewValueOpPos = 16,
116 NewValueOpMask = 0x7,
117 // Stores that can become new-value stores.
118 mayNVStorePos = 19,
119 mayNVStoreMask = 0x1,
120 // New-value store instructions.
121 NVStorePos = 20,
122 NVStoreMask = 0x1,
123 // Loads that can become current-value loads.
124 mayCVLoadPos = 21,
125 mayCVLoadMask = 0x1,
126 // Current-value load instructions.
127 CVLoadPos = 22,
128 CVLoadMask = 0x1,
129
130 // Extendable insns.
131 ExtendablePos = 23,
132 ExtendableMask = 0x1,
133 // Insns must be extended.
134 ExtendedPos = 24,
135 ExtendedMask = 0x1,
136 // Which operand may be extended.
137 ExtendableOpPos = 25,
138 ExtendableOpMask = 0x7,
139 // Signed or unsigned range.
140 ExtentSignedPos = 28,
141 ExtentSignedMask = 0x1,
142 // Number of bits of range before extending operand.
143 ExtentBitsPos = 29,
144 ExtentBitsMask = 0x1f,
145 // Alignment power-of-two before extending operand.
146 ExtentAlignPos = 34,
147 ExtentAlignMask = 0x3,
148
149 CofMax1Pos = 36,
150 CofMax1Mask = 0x1,
151 CofRelax1Pos = 37,
152 CofRelax1Mask = 0x1,
153 CofRelax2Pos = 38,
154 CofRelax2Mask = 0x1,
155
156 RestrictNoSlot1StorePos = 39,
157 RestrictNoSlot1StoreMask = 0x1,
158
159 // Addressing mode for load/store instructions.
160 AddrModePos = 40,
161 AddrModeMask = 0x7,
162 // Access size for load/store instructions.
163 MemAccessSizePos = 43,
164 MemAccesSizeMask = 0xf,
165
166 // Branch predicted taken.
167 TakenPos = 47,
168 TakenMask = 0x1,
169
170 // Floating-point instructions.
171 FPPos = 48,
172 FPMask = 0x1,
173
174 isHMXActivatePos = 49,
175
176 // New-Value producer-2 instructions.
177 hasNewValuePos2 = 50,
178 hasNewValueMask2 = 0x1,
179 // Which operand consumes or produces a new value.
180 NewValueOpPos2 = 51,
181 NewValueOpMask2 = 0x7,
182
183 // Accumulator instructions.
184 AccumulatorPos = 54,
185 AccumulatorMask = 0x1,
186
187 // Complex XU, prevent xu competition by preferring slot3
188 PrefersSlot3Pos = 55,
189 PrefersSlot3Mask = 0x1,
190
191 isTmpWritePos = 56,
192
193 isHMXWeightPos = 57,
194
195 CVINewPos = 58,
196 CVINewMask = 0x1,
197
198 isCVIPos = 59,
199 isCVIMask = 0x1,
200
201 isHVXALUPos = 60,
202 isHVXALUMask = 0x1,
203
204 isHVXALU2SRCPos = 61,
205 isHVXALU2SRCMask = 0x1,
206
207 hasUnaryRestrictionPos = 62,
208 hasUnaryRestrictionMask = 0x1,
209
210 isHLXPos = 63,
211 isHLXMask = 0x1,
212 };
213
214 inline bool getTSFlag(const MCInstrDesc &MID, HexagonTSFlagsVal Pos) {
215 return (MID.TSFlags >> Pos) & 1;
216 }
217
218 // *** The code above must match HexagonInstrFormat*.td *** //
219
220 // Hexagon specific MO operand flag mask.
221 enum HexagonMOTargetFlagVal {
222 // Hexagon-specific MachineOperand target flags.
223 //
224 // When changing these, make sure to update
225 // getSerializableDirectMachineOperandTargetFlags and
226 // getSerializableBitmaskMachineOperandTargetFlags if needed.
227 MO_NO_FLAG,
228
229 /// MO_PCREL - On a symbol operand, indicates a PC-relative relocation
230 /// Used for computing a global address for PIC compilations
231 MO_PCREL,
232
233 /// MO_GOT - Indicates a GOT-relative relocation
234 MO_GOT,
235
236 // Low or high part of a symbol.
237 MO_LO16,
238 MO_HI16,
239
240 // Offset from the base of the SDA.
241 MO_GPREL,
242
243 // MO_GDGOT - indicates GOT relative relocation for TLS
244 // GeneralDynamic method
245 MO_GDGOT,
246
247 // MO_GDPLT - indicates PLT relative relocation for TLS
248 // GeneralDynamic method
249 MO_GDPLT,
250
251 // MO_IE - indicates non PIC relocation for TLS
252 // Initial Executable method
253 MO_IE,
254
255 // MO_IEGOT - indicates PIC relocation for TLS
256 // Initial Executable method
257 MO_IEGOT,
258
259 // MO_TPREL - indicates relocation for TLS
260 // local Executable method
261 MO_TPREL,
262
263 // HMOTF_ConstExtended
264 // Addendum to above, indicates a const extended op
265 // Can be used as a mask.
266 HMOTF_ConstExtended = 0x80,
267
268 // Union of all bitmasks (currently only HMOTF_ConstExtended).
269 MO_Bitmasks = HMOTF_ConstExtended
270 };
271
272 // Hexagon Sub-instruction classes.
273 enum SubInstructionGroup {
274 HSIG_None = 0,
275 HSIG_L1,
276 HSIG_L2,
277 HSIG_S1,
278 HSIG_S2,
279 HSIG_A,
280 HSIG_Compound
281 };
282
283 // Hexagon Compound classes.
284 enum CompoundGroup {
285 HCG_None = 0,
286 HCG_A,
287 HCG_B,
288 HCG_C
289 };
290
291 enum InstParseBits {
292 INST_PARSE_MASK = 0x0000c000,
293 INST_PARSE_PACKET_END = 0x0000c000,
294 INST_PARSE_LOOP_END = 0x00008000,
295 INST_PARSE_NOT_END = 0x00004000,
296 INST_PARSE_DUPLEX = 0x00000000,
297 INST_PARSE_EXTENDER = 0x00000000
298 };
299
300 enum InstIClassBits : unsigned {
301 INST_ICLASS_MASK = 0xf0000000,
302 INST_ICLASS_EXTENDER = 0x00000000,
303 INST_ICLASS_J_1 = 0x10000000,
304 INST_ICLASS_J_2 = 0x20000000,
305 INST_ICLASS_LD_ST_1 = 0x30000000,
306 INST_ICLASS_LD_ST_2 = 0x40000000,
307 INST_ICLASS_J_3 = 0x50000000,
308 INST_ICLASS_CR = 0x60000000,
309 INST_ICLASS_ALU32_1 = 0x70000000,
310 INST_ICLASS_XTYPE_1 = 0x80000000,
311 INST_ICLASS_LD = 0x90000000,
312 INST_ICLASS_ST = 0xa0000000,
313 INST_ICLASS_ALU32_2 = 0xb0000000,
314 INST_ICLASS_XTYPE_2 = 0xc0000000,
315 INST_ICLASS_XTYPE_3 = 0xd0000000,
316 INST_ICLASS_XTYPE_4 = 0xe0000000,
317 INST_ICLASS_ALU32_3 = 0xf0000000
318 };
319
320 [[maybe_unused]]
321 static unsigned getMemAccessSizeInBytes(MemAccessSize S) {
322 switch (S) {
323 case ByteAccess: return 1;
324 case HalfWordAccess: return 2;
325 case WordAccess: return 4;
326 case DoubleWordAccess: return 8;
327 default: return 0;
328 }
329 }
330} // end namespace HexagonII
331
332} // end namespace llvm
333
334#endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONBASEINFO_H
335