LLVM 23.0.0git
M68kBaseInfo.h
Go to the documentation of this file.
1//===-- M68kBaseInfo.h - Top level definitions for M68k MC ------*- 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/// \file
10/// This file contains small standalone helper functions and enum definitions
11/// for the M68k target useful for the compiler back-end and the MC
12/// libraries. As such, it deliberately does not include references to LLVM
13/// core code gen types, passes, etc..
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_LIB_TARGET_M68K_MCTARGETDESC_M68KBASEINFO_H
18#define LLVM_LIB_TARGET_M68K_MCTARGETDESC_M68KBASEINFO_H
19
20#include "M68kMCTargetDesc.h"
21
22#include "llvm/MC/MCExpr.h"
24#include "llvm/Support/Endian.h"
26
27#define GET_INSTRINFO_MI_OPS_INFO
28#define GET_INSTRINFO_OPERAND_TYPES_ENUM
29#define GET_INSTRINFO_LOGICAL_OPERAND_SIZE_MAP
30#include "M68kGenInstrInfo.inc"
31
32namespace llvm {
33
34namespace M68k {
35
36/// Enums for memory operand decoding. Supports these forms:
37/// (d,An)
38/// (d,An,Xn)
39/// ([bd,An],Xn,od)
40/// ([bd,An,Xn],od)
41/// TODO Implement scaling other than 1
42enum { MemDisp = 0, MemBase = 1, MemIndex = 2, MemOuter = 3 };
43
44/// Enums for pc-relative memory operand decoding. Supports these forms:
45/// (d,PC)
46/// (d,PC,Xn)
47/// (bd,PC,Xn.Size*SCALE)
48enum { PCRelDisp = 0, PCRelIndex = 1, PCRelScale = 2 };
49
50enum class MemAddrModeKind : unsigned {
51 j = 1, // (An)
52 o, // (An)+
53 e, // -(An)
54 p, // (d,An)
55 f, // (d,An,Xn.L)
56 F, // (d,An,Xn.W)
57 g, // (d,An,Xn.L,SCALE)
58 G, // (d,An,Xn.W,SCALE)
59 u, // ([bd,An],Xn.L,SCALE,od)
60 U, // ([bd,An],Xn.W,SCALE,od)
61 v, // ([bd,An,Xn.L,SCALE],od)
62 V, // ([bd,An,Xn.W,SCALE],od)
63 b, // abs.L
64 B, // abs.W
65 q, // (d,PC)
66 k, // (d,PC,Xn.L)
67 K, // (d,PC,Xn.W)
68 l, // (bd,PC,Xn.L,SCALE)
69 L, // (bd,PC,Xn.W,SCALE)
70 x, // ([bd,PC],Xn.L,SCALE,od)
71 X, // ([bd,PC],Xn.W,SCALE,od)
72 y, // ([bd,PC,Xn.L,SCALE],od)
73 Y // ([bd,PC,Xn.W,SCALE],od)
74};
75
76// On a LE host:
77// MSB LSB MSB LSB
78// | 0x12 0x34 | 0xAB 0xCD | -> | 0xAB 0xCD | 0x12 0x34 |
79// (On a BE host nothing changes)
80template <typename value_t> value_t swapWord(value_t Val) {
81 const unsigned NumWords = sizeof(Val) / 2;
82 if (NumWords <= 1)
83 return Val;
85 value_t NewVal = 0;
86 for (unsigned i = 0U; i != NumWords; ++i) {
87 uint16_t Part = (Val >> (i * 16)) & 0xFFFF;
89 NewVal |= (Part << (i * 16));
90 }
91 return NewVal;
92}
93} // namespace M68k
94
95namespace M68kBeads {
96enum {
97 Ctrl = 0x0,
98 Bits1 = 0x1,
99 Bits2 = 0x2,
100 Bits3 = 0x3,
101 Bits4 = 0x4,
102 DAReg = 0x5,
103 DA = 0x6,
104 Reg = 0x7,
105 DReg = 0x8,
106 Disp8 = 0x9,
107 Imm8 = 0xA,
108 Imm16 = 0xB,
109 Imm32 = 0xC,
110 Imm3 = 0xD,
111};
112
113// Ctrl payload
114enum {
115 Term = 0x0,
116 Ignore = 0x1,
117};
118} // namespace M68kBeads
119
120/// This namespace holds all of the target specific flags that instruction info
121/// tracks.
122namespace M68kII {
123/// Target Operand Flag enum.
124enum TOF {
125
127
128 /// On a symbol operand this indicates that the immediate is the absolute
129 /// address of the symbol.
131
132 /// On a symbol operand this indicates that the immediate is the pc-relative
133 /// address of the symbol.
135
136 /// On a symbol operand this indicates that the immediate is the offset to
137 /// the GOT entry for the symbol name from the base of the GOT.
138 ///
139 /// name@GOT
141
142 /// On a symbol operand this indicates that the immediate is the offset to
143 /// the location of the symbol name from the base of the GOT.
144 ///
145 /// name@GOTOFF
147
148 /// On a symbol operand this indicates that the immediate is offset to the
149 /// GOT entry for the symbol name from the current code location.
150 ///
151 /// name@GOTPCREL
153
154 /// On a symbol operand this indicates that the immediate is offset to the
155 /// PLT entry of symbol name from the current code location.
156 ///
157 /// name@PLT
159
160 /// On a symbol operand, this indicates that the immediate is the offset to
161 /// the slot in GOT which stores the information for accessing the TLS
162 /// variable. This is used when operating in Global Dynamic mode.
163 /// name@TLSGD
165
166 /// On a symbol operand, this indicates that the immediate is the offset to
167 /// variable within the thread local storage when operating in Local Dynamic
168 /// mode.
169 /// name@TLSLD
171
172 /// On a symbol operand, this indicates that the immediate is the offset to
173 /// the slot in GOT which stores the information for accessing the TLS
174 /// variable. This is used when operating in Local Dynamic mode.
175 /// name@TLSLDM
177
178 /// On a symbol operand, this indicates that the immediate is the offset to
179 /// the variable within the thread local storage when operating in Initial
180 /// Exec mode.
181 /// name@TLSIE
183
184 /// On a symbol operand, this indicates that the immediate is the offset to
185 /// the variable within in the thread local storage when operating in Local
186 /// Exec mode.
187 /// name@TLSLE
189
190}; // enum TOF
191
192/// Return true if the specified TargetFlag operand is a reference to a stub
193/// for a global, not the global itself.
194inline static bool isGlobalStubReference(unsigned char TargetFlag) {
195 switch (TargetFlag) {
196 default:
197 return false;
198 case M68kII::MO_GOTPCREL: // pc-relative GOT reference.
199 case M68kII::MO_GOT: // normal GOT reference.
200 return true;
201 }
202}
203
204/// Return True if the specified GlobalValue is a direct reference for a
205/// symbol.
206inline static bool isDirectGlobalReference(unsigned char Flag) {
207 switch (Flag) {
208 default:
209 return false;
213 return true;
214 }
215}
216
217/// Return true if the specified global value reference is relative to a 32-bit
218/// PIC base (M68kISD::GLOBAL_BASE_REG). If this is true, the addressing mode
219/// has the PIC base register added in.
220inline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {
221 switch (TargetFlag) {
222 default:
223 return false;
224 case M68kII::MO_GOTOFF: // isPICStyleGOT: local global.
225 case M68kII::MO_GOT: // isPICStyleGOT: other global.
226 return true;
227 }
228}
229
230/// Return True if the specified GlobalValue requires PC addressing mode.
231inline static bool isPCRelGlobalReference(unsigned char Flag) {
232 switch (Flag) {
233 default:
234 return false;
237 return true;
238 }
239}
240
241/// Return True if the Block is referenced using PC
242inline static bool isPCRelBlockReference(unsigned char Flag) {
243 switch (Flag) {
244 default:
245 return false;
247 return true;
248 }
249}
250
251static inline bool isAddressRegister(unsigned RegNo) {
252 switch (RegNo) {
253 case M68k::WA0:
254 case M68k::WA1:
255 case M68k::WA2:
256 case M68k::WA3:
257 case M68k::WA4:
258 case M68k::WA5:
259 case M68k::WA6:
260 case M68k::WSP:
261 case M68k::A0:
262 case M68k::A1:
263 case M68k::A2:
264 case M68k::A3:
265 case M68k::A4:
266 case M68k::A5:
267 case M68k::A6:
268 case M68k::SP:
269 return true;
270 default:
271 return false;
272 }
273}
274
275static inline bool hasMultiMIOperands(unsigned Op, unsigned LogicalOpIdx) {
276 return M68k::getLogicalOperandSize(Op, LogicalOpIdx) > 1;
277}
278
279static inline unsigned getMaskedSpillRegister(unsigned order) {
280 switch (order) {
281 default:
282 return 0;
283 case 0:
284 return M68k::D0;
285 case 1:
286 return M68k::D1;
287 case 2:
288 return M68k::D2;
289 case 3:
290 return M68k::D3;
291 case 4:
292 return M68k::D4;
293 case 5:
294 return M68k::D5;
295 case 6:
296 return M68k::D6;
297 case 7:
298 return M68k::D7;
299 case 8:
300 return M68k::A0;
301 case 9:
302 return M68k::A1;
303 case 10:
304 return M68k::A2;
305 case 11:
306 return M68k::A3;
307 case 12:
308 return M68k::A4;
309 case 13:
310 return M68k::A5;
311 case 14:
312 return M68k::A6;
313 case 15:
314 return M68k::SP;
315 }
316}
317
318} // namespace M68kII
319
320} // namespace llvm
321
322#endif // LLVM_LIB_TARGET_M68K_MCTARGETDESC_M68KBASEINFO_H
This file provides M68k specific target descriptions.
This namespace holds all of the target specific flags that instruction info tracks.
static bool isAddressRegister(unsigned RegNo)
static bool isPCRelBlockReference(unsigned char Flag)
Return True if the Block is referenced using PC.
static bool isGlobalRelativeToPICBase(unsigned char TargetFlag)
Return true if the specified global value reference is relative to a 32-bit PIC base (M68kISD::GLOBAL...
static bool isGlobalStubReference(unsigned char TargetFlag)
Return true if the specified TargetFlag operand is a reference to a stub for a global,...
static bool isPCRelGlobalReference(unsigned char Flag)
Return True if the specified GlobalValue requires PC addressing mode.
static bool hasMultiMIOperands(unsigned Op, unsigned LogicalOpIdx)
static unsigned getMaskedSpillRegister(unsigned order)
TOF
Target Operand Flag enum.
@ MO_GOTOFF
On a symbol operand this indicates that the immediate is the offset to the location of the symbol nam...
@ MO_TLSLDM
On a symbol operand, this indicates that the immediate is the offset to the slot in GOT which stores ...
@ MO_PLT
On a symbol operand this indicates that the immediate is offset to the PLT entry of symbol name from ...
@ MO_TLSLE
On a symbol operand, this indicates that the immediate is the offset to the variable within in the th...
@ MO_GOT
On a symbol operand this indicates that the immediate is the offset to the GOT entry for the symbol n...
@ MO_TLSGD
On a symbol operand, this indicates that the immediate is the offset to the slot in GOT which stores ...
@ MO_ABSOLUTE_ADDRESS
On a symbol operand this indicates that the immediate is the absolute address of the symbol.
@ MO_GOTPCREL
On a symbol operand this indicates that the immediate is offset to the GOT entry for the symbol name ...
@ MO_PC_RELATIVE_ADDRESS
On a symbol operand this indicates that the immediate is the pc-relative address of the symbol.
@ MO_TLSIE
On a symbol operand, this indicates that the immediate is the offset to the variable within the threa...
@ MO_TLSLD
On a symbol operand, this indicates that the immediate is the offset to variable within the thread lo...
static bool isDirectGlobalReference(unsigned char Flag)
Return True if the specified GlobalValue is a direct reference for a symbol.
value_t swapWord(value_t Val)
value_type byte_swap(value_type value, endianness endian)
Definition Endian.h:44
This is an optimization pass for GlobalISel generic memory operations.
DWARFExpression::Operation Op