LLVM 23.0.0git
PPCSubtarget.cpp
Go to the documentation of this file.
1//===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===//
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 implements the PPC specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#include "PPCSubtarget.h"
17#include "PPC.h"
18#include "PPCRegisterInfo.h"
19#include "PPCSelectionDAGInfo.h"
20#include "PPCTargetMachine.h"
25#include "llvm/IR/GlobalAlias.h"
26#include "llvm/IR/GlobalValue.h"
32#include <cstdlib>
33
34using namespace llvm;
35
36#define DEBUG_TYPE "ppc-subtarget"
37
38#define GET_SUBTARGETINFO_TARGET_DESC
39#define GET_SUBTARGETINFO_CTOR
40#include "PPCGenSubtargetInfo.inc"
41
42static cl::opt<bool>
43 EnableMachinePipeliner("ppc-enable-pipeliner",
44 cl::desc("Enable Machine Pipeliner for PPC"),
45 cl::init(false), cl::Hidden);
46
48 StringRef TuneCPU,
49 StringRef FS) {
50 initializeEnvironment();
51 initSubtargetFeatures(CPU, TuneCPU, FS);
52 return *this;
53}
54
56 StringRef FS, const PPCTargetMachine &TM)
57 : PPCGenSubtargetInfo(TT, CPU, TuneCPU, FS), TM(TM),
59 InstrInfo(*this), TLInfo(TM, *this) {
60 TSInfo = std::make_unique<PPCSelectionDAGInfo>();
61
63 Legalizer.reset(new PPCLegalizerInfo(*this));
64 auto *RBI = new PPCRegisterBankInfo(*getRegisterInfo());
65 RegBankInfo.reset(RBI);
66
67 InstSelector.reset(createPPCInstructionSelector(TM, *this, *RBI));
68}
69
71
75
76void PPCSubtarget::initializeEnvironment() {
80}
81
82void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
83 StringRef FS) {
84 // Determine default and user specified characteristics
85 std::string CPUName = std::string(CPU);
86 if (CPUName.empty() || CPU == "generic") {
87 if (getTargetTriple().getSubArch() == Triple::PPCSubArch_spe)
88 CPUName = "e500";
89 else
90 CPUName = std::string(PPC::getNormalizedPPCTargetCPU(getTargetTriple()));
91 }
92
93 // Determine the CPU to schedule for.
94 if (TuneCPU.empty()) TuneCPU = CPUName;
95
96 // Initialize scheduling itinerary for the specified CPU.
97 InstrItins = getInstrItineraryForCPU(CPUName);
98
99 // Parse features string.
100 ParseSubtargetFeatures(CPUName, TuneCPU, FS);
101
102 // If the user requested use of 64-bit regs, but the cpu selected doesn't
103 // support it, ignore.
104 if (IsPPC64 && has64BitSupport())
105 Use64BitRegs = true;
106
107 if (getTargetTriple().isPPC32SecurePlt())
108 IsSecurePlt = true;
109
110 if (HasSPE && IsPPC64)
111 report_fatal_error( "SPE is only supported for 32-bit targets.\n", false);
112 if (HasSPE && (HasAltivec || HasVSX || HasFPU))
114 "SPE and traditional floating point cannot both be enabled.\n", false);
115
116 // If not SPE, set standard FPU
117 if (!HasSPE)
118 HasFPU = true;
119
121
122 // Determine endianness.
123 IsLittleEndian = TM.isLittleEndian();
124
125 if (HasAIXSmallLocalExecTLS || HasAIXSmallLocalDynamicTLS) {
126 if (!getTargetTriple().isOSAIX() || !IsPPC64)
127 report_fatal_error("The aix-small-local-[exec|dynamic]-tls attribute is "
128 "only supported on AIX in "
129 "64-bit mode.\n",
130 false);
131 // The aix-small-local-[exec|dynamic]-tls attribute should only be used with
132 // -data-sections, as having data sections turned off with this option
133 // is not ideal for performance. Moreover, the
134 // small-local-[exec|dynamic]-tls region is a limited resource, and should
135 // not be used for variables that may be replaced.
136 if (!TM.getDataSections())
137 report_fatal_error("The aix-small-local-[exec|dynamic]-tls attribute can "
138 "only be specified with "
139 "-data-sections.\n",
140 false);
141 }
142
143 if (HasAIXShLibTLSModelOpt && (!getTargetTriple().isOSAIX() || !IsPPC64))
144 report_fatal_error("The aix-shared-lib-tls-model-opt attribute "
145 "is only supported on AIX in 64-bit mode.\n",
146 false);
147
148 if (UsePointerGlueHelper && !getTargetTriple().isOSAIX())
149 report_fatal_error("use-ptrgl-helper feature is only supported on AIX\n",
150 false);
151}
152
153bool PPCSubtarget::enableMachineScheduler() const { return true; }
154
156 return getSchedModel().hasInstrSchedModel() && EnableMachinePipeliner;
157}
158
159bool PPCSubtarget::useDFAforSMS() const { return false; }
160
161// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
162bool PPCSubtarget::enablePostRAScheduler() const { return true; }
163
164PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
165 return TargetSubtargetInfo::ANTIDEP_ALL;
166}
167
168void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
169 CriticalPathRCs.clear();
170 CriticalPathRCs.push_back(isPPC64() ?
171 &PPC::G8RCRegClass : &PPC::GPRCRegClass);
172}
173
175 const SchedRegion &Region) const {
176 // The GenericScheduler that we use defaults to scheduling bottom up only.
177 // We want to schedule from both the top and the bottom and so we set
178 // OnlyBottomUp to false.
179 // We want to do bi-directional scheduling since it provides a more balanced
180 // schedule leading to better performance.
181 Policy.OnlyBottomUp = false;
182 // Spilling is generally expensive on all PPC cores, so always enable
183 // register-pressure tracking.
184 Policy.ShouldTrackPressure = true;
185}
186
188 return true;
189}
190
191bool PPCSubtarget::enableSubRegLiveness() const { return true; }
192
194 if (isAIXABI()) {
195 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
196 // On AIX the only symbols that aren't indirect are toc-data.
197 return !GVar->hasAttribute("toc-data");
198
199 return true;
200 }
201
202 // Large code model always uses the TOC even for local symbols.
203 if (TM.getCodeModel() == CodeModel::Large)
204 return true;
205
206 if (TM.shouldAssumeDSOLocal(GV))
207 return false;
208 return true;
209}
210
212 const GlobalValue *GV) const {
213 // If there isn't an attribute to override the module code model
214 // this will be the effective code model.
215 CodeModel::Model ModuleModel = TM.getCodeModel();
216
217 // Initially support per global code model for AIX only.
218 if (!isAIXABI())
219 return ModuleModel;
220
221 // Only GlobalVariables carry an attribute which can override the module code
222 // model.
223 assert(GV && "Unexpected NULL GlobalValue");
224 const GlobalVariable *GlobalVar =
225 [](const GlobalValue *GV) -> const GlobalVariable * {
227 if (Var)
228 return Var;
229
230 const GlobalAlias *Alias = dyn_cast<GlobalAlias>(GV);
231 if (Alias)
233
234 return nullptr;
235 }(GV);
236
237 if (!GlobalVar)
238 return ModuleModel;
239
240 std::optional<CodeModel::Model> MaybeCodeModel = GlobalVar->getCodeModel();
241 if (MaybeCodeModel) {
242 CodeModel::Model CM = *MaybeCodeModel;
243 assert((CM == CodeModel::Small || CM == CodeModel::Large) &&
244 "invalid code model for AIX");
245 return CM;
246 }
247
248 return ModuleModel;
249}
250
251bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
252
254 return isPPC64() && hasPCRelativeMemops() && isELFv2ABI() &&
256}
257
258// GlobalISEL
260 return CallLoweringInfo.get();
261}
262
264 return RegBankInfo.get();
265}
266
268 return Legalizer.get();
269}
270
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > EnableMachinePipeliner("aarch64-enable-pipeliner", cl::desc("Enable Machine Pipeliner for AArch64"), cl::init(false), cl::Hidden)
This file describes how to lower LLVM calls to machine code calls.
This file declares the targeting of the Machinelegalizer class for PowerPC.
This file declares the targeting of the RegisterBankInfo class for PowerPC.
static cl::opt< bool > EnableMachinePipeliner("ppc-enable-pipeliner", cl::desc("Enable Machine Pipeliner for PPC"), cl::init(false), cl::Hidden)
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:659
This class provides the information for the PowerPC target legalizer for GlobalISel.
std::unique_ptr< InstructionSelector > InstSelector
bool enableMachinePipeliner() const override
Pipeliner customization.
bool useDFAforSMS() const override
Machine Pipeliner customization.
std::unique_ptr< LegalizerInfo > Legalizer
PPCTargetLowering TLInfo
PPCFrameLowering FrameLowering
bool isAIXABI() const
const CallLowering * getCallLowering() const override
const LegalizerInfo * getLegalizerInfo() const override
std::unique_ptr< RegisterBankInfo > RegBankInfo
~PPCSubtarget() 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 ...
PPCInstrInfo InstrInfo
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override
bool isUsingPCRelativeCalls() const
bool enableSubRegLiveness() const override
const PPCTargetLowering * getTargetLowering() const override
InstructionSelector * getInstructionSelector() const override
unsigned CPUDirective
Which cpu directive was used.
AntiDepBreakMode getAntiDepBreakMode() const override
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool useAA() const override
PPCSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef TuneCPU, StringRef FS)
initializeSubtargetDependencies - Initializes using a CPU, a TuneCPU, and feature string so that we c...
CodeModel::Model getCodeModel(const TargetMachine &TM, const GlobalValue *GV) const
Calculates the effective code model for argument GV.
PPCSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS, const PPCTargetMachine &TM)
This constructor initializes the data members to match that of the specified triple.
bool isELFv2ABI() const
Align getPlatformStackAlignment() const
const PPCTargetMachine & getTargetMachine() const
const PPCTargetMachine & TM
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.
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
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Primary interface to the complete machine description for the target machine.
CodeModel::Model getCodeModel() const
Returns the code model.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
@ PPCSubArch_spe
Definition Triple.h:168
LLVM_ABI StringRef getNormalizedPPCTargetCPU(const Triple &T, StringRef CPUName="")
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
InstructionSelector * createPPCInstructionSelector(const PPCTargetMachine &TM, const PPCSubtarget &Subtarget, const PPCRegisterBankInfo &RBI)
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.