LLVM 24.0.0git
PPCMCTargetDesc.h
Go to the documentation of this file.
1//===-- PPCMCTargetDesc.h - PowerPC Target Descriptions ---------*- 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 provides PowerPC specific target descriptions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H
14#define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H
15
16// GCC #defines PPC on Linux but we use it as our namespace name
17#undef PPC
18
21#include <cstdint>
22#include <memory>
23
24namespace llvm {
25
26class MCAsmBackend;
27class MCCodeEmitter;
28class MCContext;
29class MCInstrDesc;
30class MCInstrInfo;
32class MCRegisterInfo;
33class MCSubtargetInfo;
34class MCTargetOptions;
35class Target;
36
37namespace PPC {
38/// stripRegisterPrefix - This method strips the character prefix from a
39/// register name so that only the number is left. Used by for linux asm.
40const char *stripRegisterPrefix(const char *RegName);
41
42/// getRegNumForOperand - some operands use different numbering schemes
43/// for the same registers. For example, a VSX instruction may have any of
44/// vs0-vs63 allocated whereas an Altivec instruction could only have
45/// vs32-vs63 allocated (numbered as v0-v31). This function returns the actual
46/// register number needed for the opcode/operand number combination.
47/// The operand number argument will be useful when we need to extend this
48/// to instructions that use both Altivec and VSX numbering (for different
49/// operands).
50MCRegister getRegNumForOperand(const MCInstrDesc &Desc, MCRegister Reg,
51 unsigned OpNo);
52
53} // namespace PPC
54
56 MCContext &Ctx);
57
59 const MCRegisterInfo &MRI,
61
62/// Construct an PPC ELF object writer.
63std::unique_ptr<MCObjectTargetWriter> createPPCELFObjectWriter(bool Is64Bit,
64 uint8_t OSABI);
65
66/// Construct a PPC XCOFF object writer.
67std::unique_ptr<MCObjectTargetWriter> createPPCXCOFFObjectWriter(bool Is64Bit);
68
69/// Returns true iff Val consists of one contiguous run of 1s with any number of
70/// 0s on either side. The 1s are allowed to wrap from LSB to MSB, so
71/// 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is not,
72/// since all 1s are not contiguous.
73static inline bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) {
74 if (!Val)
75 return false;
76
77 if (isShiftedMask_32(Val)) {
78 // look for the first non-zero bit
79 MB = llvm::countl_zero(Val);
80 // look for the first zero bit after the run of ones
81 ME = llvm::countl_zero((Val - 1) ^ Val);
82 return true;
83 } else {
84 Val = ~Val; // invert mask
85 if (isShiftedMask_32(Val)) {
86 // effectively look for the first zero bit
87 ME = llvm::countl_zero(Val) - 1;
88 // effectively look for the first one bit after the run of zeros
89 MB = llvm::countl_zero((Val - 1) ^ Val) + 1;
90 return true;
91 }
92 }
93 // no run present
94 return false;
95}
96
97static inline bool isRunOfOnes64(uint64_t Val, unsigned &MB, unsigned &ME) {
98 if (!Val)
99 return false;
100
101 if (isShiftedMask_64(Val)) {
102 // look for the first non-zero bit
103 MB = llvm::countl_zero(Val);
104 // look for the first zero bit after the run of ones
105 ME = llvm::countl_zero((Val - 1) ^ Val);
106 return true;
107 } else {
108 Val = ~Val; // invert mask
109 if (isShiftedMask_64(Val)) {
110 // effectively look for the first zero bit
111 ME = llvm::countl_zero(Val) - 1;
112 // effectively look for the first one bit after the run of zeros
113 MB = llvm::countl_zero((Val - 1) ^ Val) + 1;
114 return true;
115 }
116 }
117 // no run present
118 return false;
119}
120
121/// PPCII - This namespace holds all of the PowerPC target-specific
122/// per-instruction flags. These must match the corresponding definitions in
123/// PPC.td and PPCInstrFormats.td.
124namespace PPCII {
125enum {
126 // PPC970 Instruction Flags. These flags describe the characteristics of the
127 // PowerPC 970 (aka G5) dispatch groups and how they are formed out of
128 // raw machine instructions.
129
130 /// PPC970_First - This instruction starts a new dispatch group, so it will
131 /// always be the first one in the group.
133
134 /// PPC970_Single - This instruction starts a new dispatch group and
135 /// terminates it, so it will be the sole instruction in the group.
137
138 /// PPC970_Cracked - This instruction is cracked into two pieces, requiring
139 /// two dispatch pipes to be available to issue.
141
142 /// PPC970_Mask/Shift - This is a bitmask that selects the pipeline type that
143 /// an instruction is issued to.
146};
148 /// These are the various PPC970 execution unit pipelines. Each instruction
149 /// is one of these.
150 PPC970_Pseudo = 0 << PPC970_Shift, // Pseudo instruction
151 PPC970_FXU = 1 << PPC970_Shift, // Fixed Point (aka Integer/ALU) Unit
152 PPC970_LSU = 2 << PPC970_Shift, // Load Store Unit
153 PPC970_FPU = 3 << PPC970_Shift, // Floating Point Unit
154 PPC970_CRU = 4 << PPC970_Shift, // Control Register Unit
155 PPC970_VALU = 5 << PPC970_Shift, // Vector ALU
156 PPC970_VPERM = 6 << PPC970_Shift, // Vector Permute Unit
157 PPC970_BRU = 7 << PPC970_Shift // Branch Unit
158};
159
160enum {
161 /// Shift count to bypass PPC970 flags
163
164 /// This instruction is an X-Form memory operation.
166 /// This instruction is prefixed.
167 Prefixed = 0x1 << (NewDef_Shift + 1),
168 /// This instruction produced a sign extended result.
169 SExt32To64 = 0x1 << (NewDef_Shift + 2),
170 /// This instruction produced a zero extended result.
171 ZExt32To64 = 0x1 << (NewDef_Shift + 3),
172 /// This instruction takes a register+immediate memory operand.
173 MemriOp = 0x1 << (NewDef_Shift + 4)
174};
175} // end namespace PPCII
176
177} // end namespace llvm
178
179// Defines symbolic names for PowerPC registers. This defines a mapping from
180// register name to register number.
181//
182#define GET_REGINFO_ENUM
183#include "PPCGenRegisterInfo.inc"
184
185// Defines symbolic names for the PowerPC instructions.
186//
187#define GET_INSTRINFO_ENUM
188#define GET_INSTRINFO_SCHED_ENUM
189#define GET_INSTRINFO_MC_HELPER_DECLS
190#include "PPCGenInstrInfo.inc"
191
192#define GET_SUBTARGETINFO_ENUM
193#include "PPCGenSubtargetInfo.inc"
194
195#define PPC_REGS0_7(X) \
196 { \
197 X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7 \
198 }
199
200#define PPC_REGS0_31(X) \
201 { \
202 X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \
203 X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \
204 X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31 \
205 }
206
207#define PPC_REGS_EVEN0_30(X) \
208 { \
209 X##0, X##2, X##4, X##6, X##8, X##10, X##12, X##14, X##16, X##18, X##20, \
210 X##22, X##24, X##26, X##28, X##30 \
211 }
212
213#define PPC_REGS0_63(X) \
214 { \
215 X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \
216 X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \
217 X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31, \
218 X##32, X##33, X##34, X##35, X##36, X##37, X##38, X##39, X##40, X##41, \
219 X##42, X##43, X##44, X##45, X##46, X##47, X##48, X##49, X##50, X##51, \
220 X##52, X##53, X##54, X##55, X##56, X##57, X##58, X##59, X##60, X##61, \
221 X##62, X##63 \
222 }
223
224#define PPC_REGS_NO0_31(Z, X) \
225 { \
226 Z, X##1, X##2, X##3, X##4, X##5, X##6, X##7, X##8, X##9, X##10, X##11, \
227 X##12, X##13, X##14, X##15, X##16, X##17, X##18, X##19, X##20, X##21, \
228 X##22, X##23, X##24, X##25, X##26, X##27, X##28, X##29, X##30, X##31 \
229 }
230
231#define PPC_REGS_LO_HI(LO, HI) \
232 { \
233 LO##0, LO##1, LO##2, LO##3, LO##4, LO##5, LO##6, LO##7, LO##8, LO##9, \
234 LO##10, LO##11, LO##12, LO##13, LO##14, LO##15, LO##16, LO##17, \
235 LO##18, LO##19, LO##20, LO##21, LO##22, LO##23, LO##24, LO##25, \
236 LO##26, LO##27, LO##28, LO##29, LO##30, LO##31, HI##0, HI##1, HI##2, \
237 HI##3, HI##4, HI##5, HI##6, HI##7, HI##8, HI##9, HI##10, HI##11, \
238 HI##12, HI##13, HI##14, HI##15, HI##16, HI##17, HI##18, HI##19, \
239 HI##20, HI##21, HI##22, HI##23, HI##24, HI##25, HI##26, HI##27, \
240 HI##28, HI##29, HI##30, HI##31 \
241 }
242
243#define PPC_REGS0_7(X) \
244 { \
245 X##0, X##1, X##2, X##3, X##4, X##5, X##6, X##7 \
246 }
247
248#define PPC_REGS0_3(X) \
249 { \
250 X##0, X##1, X##2, X##3 \
251 }
252
253using llvm::MCPhysReg;
254
255#define DEFINE_PPC_REGCLASSES \
256 static const MCPhysReg RRegs[32] = PPC_REGS0_31(PPC::R); \
257 static const MCPhysReg XRegs[32] = PPC_REGS0_31(PPC::X); \
258 static const MCPhysReg FRegs[32] = PPC_REGS0_31(PPC::F); \
259 static const MCPhysReg FpRegs[16] = PPC_REGS_EVEN0_30(PPC::Fpair); \
260 static const MCPhysReg VSRpRegs[32] = PPC_REGS0_31(PPC::VSRp); \
261 static const MCPhysReg SPERegs[32] = PPC_REGS0_31(PPC::S); \
262 static const MCPhysReg VFRegs[32] = PPC_REGS0_31(PPC::VF); \
263 static const MCPhysReg VRegs[32] = PPC_REGS0_31(PPC::V); \
264 static const MCPhysReg RRegsNoR0[32] = PPC_REGS_NO0_31(PPC::ZERO, PPC::R); \
265 static const MCPhysReg XRegsNoX0[32] = PPC_REGS_NO0_31(PPC::ZERO8, PPC::X); \
266 static const MCPhysReg VSRegs[64] = PPC_REGS_LO_HI(PPC::VSL, PPC::V); \
267 static const MCPhysReg VSFRegs[64] = PPC_REGS_LO_HI(PPC::F, PPC::VF); \
268 static const MCPhysReg VSSRegs[64] = PPC_REGS_LO_HI(PPC::F, PPC::VF); \
269 static const MCPhysReg CRBITRegs[32] = { \
270 PPC::CR0LT, PPC::CR0GT, PPC::CR0EQ, PPC::CR0UN, PPC::CR1LT, PPC::CR1GT, \
271 PPC::CR1EQ, PPC::CR1UN, PPC::CR2LT, PPC::CR2GT, PPC::CR2EQ, PPC::CR2UN, \
272 PPC::CR3LT, PPC::CR3GT, PPC::CR3EQ, PPC::CR3UN, PPC::CR4LT, PPC::CR4GT, \
273 PPC::CR4EQ, PPC::CR4UN, PPC::CR5LT, PPC::CR5GT, PPC::CR5EQ, PPC::CR5UN, \
274 PPC::CR6LT, PPC::CR6GT, PPC::CR6EQ, PPC::CR6UN, PPC::CR7LT, PPC::CR7GT, \
275 PPC::CR7EQ, PPC::CR7UN}; \
276 static const MCPhysReg CRRegs[8] = PPC_REGS0_7(PPC::CR); \
277 static const MCPhysReg ACCRegs[8] = PPC_REGS0_7(PPC::ACC); \
278 static const MCPhysReg WACCRegs[8] = PPC_REGS0_7(PPC::WACC); \
279 static const MCPhysReg WACC_HIRegs[8] = PPC_REGS0_7(PPC::WACC_HI); \
280 static const MCPhysReg DMRROWpRegs[32] = PPC_REGS0_31(PPC::DMRROWp); \
281 static const MCPhysReg DMRROWRegs[64] = PPC_REGS0_63(PPC::DMRROW); \
282 static const MCPhysReg DMRRegs[8] = PPC_REGS0_7(PPC::DMR); \
283 static const MCPhysReg DMRpRegs[4] = PPC_REGS0_3(PPC::DMRp);
284
285namespace llvm {
286namespace PPC {
287static inline bool isVFRegister(MCRegister Reg) {
288 return Reg >= PPC::VF0 && Reg <= PPC::VF31;
289}
290
291static inline bool isVRRegister(MCRegister Reg) {
292 return Reg >= PPC::V0 && Reg <= PPC::V31;
293}
294
295static inline bool isDMRROWpRegister(unsigned Reg) {
296 return Reg >= PPC::DMRROWp0 && Reg <= PPC::DMRROWp31;
297}
298} // namespace PPC
299} // namespace llvm
300
301#endif // LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCTARGETDESC_H
unsigned uint64_t
#define RegName(no)
static LVOptions Options
Definition LVOptions.cpp:25
Register Reg
#define T
Generic interface to target specific assembler backends.
MCCodeEmitter - Generic instruction encoding interface.
Context object for machine code objects.
Definition MCContext.h:83
Describe properties that are true of each instruction in the target description file.
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
Base class for classes that define behaviour that is specific to both the target and the object forma...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Generic base class for all target subtargets.
Target - Wrapper for Target specific information.
PPCII - This namespace holds all of the PowerPC target-specific per-instruction flags.
@ ZExt32To64
This instruction produced a zero extended result.
@ NewDef_Shift
Shift count to bypass PPC970 flags.
@ SExt32To64
This instruction produced a sign extended result.
@ Prefixed
This instruction is prefixed.
@ MemriOp
This instruction takes a register+immediate memory operand.
@ XFormMemOp
This instruction is an X-Form memory operation.
@ PPC970_Pseudo
These are the various PPC970 execution unit pipelines.
@ PPC970_First
PPC970_First - This instruction starts a new dispatch group, so it will always be the first one in th...
@ PPC970_Cracked
PPC970_Cracked - This instruction is cracked into two pieces, requiring two dispatch pipes to be avai...
@ PPC970_Shift
PPC970_Mask/Shift - This is a bitmask that selects the pipeline type that an instruction is issued to...
@ PPC970_Single
PPC970_Single - This instruction starts a new dispatch group and terminates it, so it will be the sol...
Define some predicates that are used for node matching.
static bool isDMRROWpRegister(unsigned Reg)
const char * stripRegisterPrefix(const char *RegName)
stripRegisterPrefix - This method strips the character prefix from a register name so that only the n...
MCRegister getRegNumForOperand(const MCInstrDesc &Desc, MCRegister Reg, unsigned OpNo)
getRegNumForOperand - some operands use different numbering schemes for the same registers.
static bool isVRRegister(MCRegister Reg)
static bool isVFRegister(MCRegister Reg)
This is an optimization pass for GlobalISel generic memory operations.
MCAsmBackend * createPPCAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
static bool isRunOfOnes64(uint64_t Val, unsigned &MB, unsigned &ME)
Op::Description Desc
constexpr bool isShiftedMask_32(uint32_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (32 bit ver...
Definition MathExtras.h:268
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
Definition MathExtras.h:274
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
Definition bit.h:263
std::unique_ptr< MCObjectTargetWriter > createPPCXCOFFObjectWriter(bool Is64Bit)
Construct a PPC XCOFF object writer.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
MCCodeEmitter * createPPCMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
std::unique_ptr< MCObjectTargetWriter > createPPCELFObjectWriter(bool Is64Bit, uint8_t OSABI)
Construct an PPC ELF object writer.
static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME)
Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side.