LLVM 24.0.0git
PPCSubtarget.h
Go to the documentation of this file.
1//===-- PPCSubtarget.h - Define Subtarget for the PPC ----------*- 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 declares the PowerPC specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
14#define LLVM_LIB_TARGET_POWERPC_PPCSUBTARGET_H
15
16#include "PPCFrameLowering.h"
17#include "PPCISelLowering.h"
18#include "PPCInstrInfo.h"
23#include "llvm/IR/DataLayout.h"
26#include <cstdint>
27#include <optional>
28
29#define GET_SUBTARGETINFO_HEADER
30#include "PPCGenSubtargetInfo.inc"
31
32// GCC #defines PPC on Linux but we use it as our namespace name
33#undef PPC
34
35namespace llvm::PPC {
49} // namespace llvm::PPC
50
51#define OPTIONS_STRUCT_DECL
52#include "PPCOptions.inc"
53
54namespace llvm {
55class SelectionDAGTargetInfo;
56class StringRef;
57
58namespace PPC {
59 // -m directive values.
60enum {
87};
88}
89
90class GlobalValue;
91
93public:
99
100protected:
101 const PPCOptions &CLOpts;
102
103 /// stackAlignment - The minimum alignment known to hold of the stack frame on
104 /// entry to the function and which must be maintained by every function.
106
107 /// Selected instruction itineraries (one entry per itinerary class.)
109
110// Bool members corresponding to the SubtargetFeatures defined in tablegen.
111#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
112 bool ATTRIBUTE = DEFAULT;
113#include "PPCGenSubtargetInfo.inc"
114
115 /// Which cpu directive was used.
116 unsigned CPUDirective;
117
119
120 /// The selected ABI variant.
122
124
129
130 // SelectionDAGISel related APIs.
131 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
132
133 /// GlobalISel related APIs.
134 std::unique_ptr<CallLowering> CallLoweringInfo;
135 std::unique_ptr<LegalizerInfo> Legalizer;
136 std::unique_ptr<RegisterBankInfo> RegBankInfo;
137 std::unique_ptr<InstructionSelector> InstSelector;
138
139public:
140 /// This constructor initializes the data members to match that
141 /// of the specified triple.
142 ///
143 PPCSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
144 StringRef ABIName, const PPCTargetMachine &TM);
145
146 ~PPCSubtarget() override;
147
148 /// ParseSubtargetFeatures - Parses features string setting specified
149 /// subtarget options. Definition of function is auto generated by tblgen.
151
152 /// getStackAlignment - Returns the minimum alignment known to hold of the
153 /// stack frame on entry to the function and which must be maintained by every
154 /// function for this subtarget.
156
157 /// getCPUDirective - Returns the -m directive specified for the cpu.
158 ///
159 unsigned getCPUDirective() const { return CPUDirective; }
160
161 /// getInstrItins - Return the instruction itineraries based on subtarget
162 /// selection.
164 return &InstrItins;
165 }
166
167 const PPCFrameLowering *getFrameLowering() const override {
168 return &FrameLowering;
169 }
170 const PPCInstrInfo *getInstrInfo() const override { return &InstrInfo; }
171 const PPCTargetLowering *getTargetLowering() const override {
172 return &TLInfo;
173 }
174
175 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
176
177 const PPCRegisterInfo *getRegisterInfo() const override {
178 return &getInstrInfo()->getRegisterInfo();
179 }
180 const PPCTargetMachine &getTargetMachine() const { return TM; }
181 const PPCOptions &getCLOpts() const { return CLOpts; }
182 /// Paired vector stores (STXVP) are enabled by default for -mcpu=future.
184 return valueOr(CLOpts.auto_paired_vec_st,
186 }
187
188 /// initializeSubtargetDependencies - Initializes using a CPU, a TuneCPU, and
189 /// feature string so that we can use initializer lists for subtarget
190 /// initialization.
192 StringRef TuneCPU,
193 StringRef FS);
194
195private:
196 void initializeEnvironment();
197 void initSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
198
199public:
200 // useSoftFloat - Return true if soft-float option is turned on.
201 bool useSoftFloat() const {
202 if (isAIXABI() && !HasHardFloat)
203 report_fatal_error("soft-float is not yet supported on AIX.");
204 return !HasHardFloat;
205 }
206
207 // isLittleEndian - True if generating little-endian code
208 bool isLittleEndian() const { return IsLittleEndian; }
209
210// Getters for SubtargetFeatures defined in tablegen.
211#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
212 bool GETTER() const { return ATTRIBUTE; }
213#include "PPCGenSubtargetInfo.inc"
214
216 return Align(16);
217 }
218
219 unsigned getRedZoneSize() const {
220 if (isPPC64())
221 // 288 bytes = 18*8 (FPRs) + 18*8 (GPRs, GPR13 reserved)
222 return 288;
223
224 // AIX PPC32: 220 bytes = 18*8 (FPRs) + 19*4 (GPRs);
225 // PPC32 SVR4ABI has no redzone.
226 return isAIXABI() ? 220 : 0;
227 }
228
230 return hasVSX() && isLittleEndian() && !hasP9Vector();
231 }
232
234
235 bool isTargetELF() const { return getTargetTriple().isOSBinFormatELF(); }
236 bool isTargetMachO() const { return getTargetTriple().isOSBinFormatMachO(); }
237 bool isTargetLinux() const { return getTargetTriple().isOSLinux(); }
238
239 bool isAIXABI() const { return getTargetTriple().isOSAIX(); }
240 bool isSVR4ABI() const { return !isAIXABI(); }
241 bool isELFv2ABI() const;
242
243 /// Returns true when the AIX extended Altivec ABI ("vec-extabi") is in
244 /// effect, allowing use of the nonvolatile vector registers.
247 }
248
249 bool is64BitELFABI() const { return isSVR4ABI() && isPPC64(); }
250 bool is32BitELFABI() const { return isSVR4ABI() && !isPPC64(); }
251 bool isUsingPCRelativeCalls() const;
252
253 /// Originally, this function return hasISEL(). Now we always enable it,
254 /// but may expand the ISEL instruction later.
255 bool enableEarlyIfConversion() const override { return true; }
256
257 /// Scheduling customization.
258 bool enableMachineScheduler() const override;
259 /// Pipeliner customization.
260 bool enableMachinePipeliner() const override;
261 /// Machine Pipeliner customization
262 bool useDFAforSMS() const override;
263 /// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
264 bool enablePostRAScheduler() const override;
265 AntiDepBreakMode getAntiDepBreakMode() const override;
266 void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
267
269 const SchedRegion &Region) const override;
270
271 bool useAA() const override;
272
273 bool enableSubRegLiveness() const override;
274
275 bool enableSpillageCopyElimination() const override { return true; }
276
277 /// True if the GV will be accessed via an indirect symbol.
278 bool isGVIndirectSymbol(const GlobalValue *GV) const;
279
280 MVT getScalarIntVT() const { return isPPC64() ? MVT::i64 : MVT::i32; }
281
282 /// Calculates the effective code model for argument GV.
284 const GlobalValue *GV) const;
285
286 /// True if the ABI is descriptor based.
288 // Both 32-bit and 64-bit AIX are descriptor based. For ELF only the 64-bit
289 // v1 ABI uses descriptors.
290 return isAIXABI() || (is64BitELFABI() && !isELFv2ABI());
291 }
292
293 unsigned descriptorTOCAnchorOffset() const {
295 "Should only be called when the target uses descriptors.");
296 return IsPPC64 ? 8 : 4;
297 }
298
301 "Should only be called when the target uses descriptors.");
302 return IsPPC64 ? 16 : 8;
303 }
304
307 "Should only be called when the target uses descriptors.");
308 return IsPPC64 ? PPC::X11 : PPC::R11;
309 }
310
312 assert((is64BitELFABI() || isAIXABI()) &&
313 "Should only be called when the target is a TOC based ABI.");
314 return IsPPC64 ? PPC::X2 : PPC::R2;
315 }
316
318 assert((is64BitELFABI() || isAIXABI()) &&
319 "Should only be called for targets with a thread pointer register.");
320 return IsPPC64 ? PPC::X13 : PPC::R13;
321 }
322
324 return IsPPC64 ? PPC::X1 : PPC::R1;
325 }
326
328 return IsPPC64 ? PPC::X11 : PPC::R11;
329 }
330
331 bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
332
334 return PredictableSelectIsExpensive;
335 }
336
337 // Select allocation orders of GPRC and G8RC. It should be strictly consistent
338 // with corresponding AltOrders in PPCRegisterInfo.td.
339 unsigned getGPRAllocationOrderIdx() const {
340 if (is64BitELFABI())
341 return 1;
342 if (isAIXABI())
343 return 2;
344 return 0;
345 }
346
347 // GlobalISEL
348 const CallLowering *getCallLowering() const override;
349 const RegisterBankInfo *getRegBankInfo() const override;
350 const LegalizerInfo *getLegalizerInfo() const override;
352};
353} // End llvm namespace
354
355#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file describes how to lower LLVM calls to machine code calls.
Interface for Targets to specify which operations they can successfully select and how the others sho...
Itinerary data supplied by a subtarget to be used by a target.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Machine Value Type.
const PPCRegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
std::unique_ptr< InstructionSelector > InstSelector
bool enableMachinePipeliner() const override
Pipeliner customization.
bool useDFAforSMS() const override
Machine Pipeliner customization.
bool is32BitELFABI() const
std::unique_ptr< LegalizerInfo > Legalizer
PPCTargetLowering TLInfo
const PPCOptions & CLOpts
PPCSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS, StringRef ABIName, const PPCTargetMachine &TM)
This constructor initializes the data members to match that of the specified triple.
unsigned descriptorTOCAnchorOffset() const
bool isTargetMachO() const
MVT getScalarIntVT() const
PPCFrameLowering FrameLowering
bool isAIXABI() const
const CallLowering * getCallLowering() const override
const LegalizerInfo * getLegalizerInfo() const override
MCRegister getGlueCodeDescriptorRegister() const
unsigned getGPRAllocationOrderIdx() const
bool useSoftFloat() const
std::unique_ptr< RegisterBankInfo > RegBankInfo
~PPCSubtarget() override
bool isXRaySupported() const override
POPCNTDKind HasPOPCNTD
InstrItineraryData InstrItins
Selected instruction itineraries (one entry per itinerary class.)
Align StackAlignment
stackAlignment - The minimum alignment known to hold of the stack frame on entry to the function and ...
const PPCFrameLowering * getFrameLowering() const override
bool needsSwapsForVSXMemOps() const
const PPCOptions & getCLOpts() const
PPCInstrInfo InstrInfo
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override
bool isUsingPCRelativeCalls() const
bool enableSubRegLiveness() const override
bool usesFunctionDescriptors() const
True if the ABI is descriptor based.
const PPCTargetLowering * getTargetLowering() const override
const InstrItineraryData * getInstrItineraryData() const override
getInstrItins - Return the instruction itineraries based on subtarget selection.
InstructionSelector * getInstructionSelector() const override
bool enableEarlyIfConversion() const override
Originally, this function return hasISEL().
MCRegister getEnvironmentPointerRegister() const
bool enableAutoPairedVecSt() const
Paired vector stores (STXVP) are enabled by default for -mcpu=future.
unsigned CPUDirective
Which cpu directive was used.
const PPCInstrInfo * getInstrInfo() const override
unsigned getRedZoneSize() const
AntiDepBreakMode getAntiDepBreakMode() const override
MCRegister getThreadPointerRegister() const
bool isSVR4ABI() const
bool isAIXExtendedAltivecABI() const
Returns true when the AIX extended Altivec ABI ("vec-extabi") is in effect, allowing use of the nonvo...
unsigned getCPUDirective() const
getCPUDirective - Returns the -m directive specified for the cpu.
bool enableSpillageCopyElimination() const override
POPCNTDKind hasPOPCNTD() const
bool isLittleEndian() const
bool isTargetLinux() const
MCRegister getTOCPointerRegister() const
bool isTargetELF() const
MCRegister getStackPointerRegister() const
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool useAA() const override
PPCABI TargetABI
The selected ABI variant.
Align getStackAlignment() const
getStackAlignment - Returns the minimum alignment known to hold of the stack frame on entry to the fu...
PPCSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef TuneCPU, StringRef FS)
initializeSubtargetDependencies - Initializes using a CPU, a TuneCPU, and feature string so that we c...
bool is64BitELFABI() const
CodeModel::Model getCodeModel(const TargetMachine &TM, const GlobalValue *GV) const
Calculates the effective code model for argument GV.
bool isELFv2ABI() const
Align getPlatformStackAlignment() const
const PPCTargetMachine & getTargetMachine() const
const PPCTargetMachine & TM
bool isPredictableSelectIsExpensive() const
std::unique_ptr< const SelectionDAGTargetInfo > TSInfo
bool enableMachineScheduler() const override
Scheduling customization.
void overrideSchedPolicy(MachineSchedPolicy &Policy, const SchedRegion &Region) const override
const RegisterBankInfo * getRegBankInfo() const override
const PPCRegisterInfo * getRegisterInfo() const override
bool isGVIndirectSymbol(const GlobalValue *GV) const
True if the GV will be accessed via an indirect symbol.
unsigned descriptorEnvironmentPointerOffset() const
std::unique_ptr< CallLowering > CallLoweringInfo
GlobalISel related APIs.
bool enablePostRAScheduler() const override
This overrides the PostRAScheduler bit in the SchedModel for each CPU.
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
Common code between 32-bit and 64-bit PowerPC targets.
Holds all the information related to register banks.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
Define some predicates that are used for node matching.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr bool valueOr(BoolOrDefault X, bool Default)
PPCABI
The PowerPC ABI variant.
Definition PPC.h:101
@ PPC_ABI_UNKNOWN
Definition PPC.h:102
@ PPC_ABI_AIX_EXTABI
Definition PPC.h:105
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Define a generic scheduling policy for targets that don't provide their own MachineSchedStrategy.
A region of an MBB for scheduling.