LLVM 22.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),
58 IsPPC64(getTargetTriple().getArch() == Triple::ppc64 ||
59 getTargetTriple().getArch() == Triple::ppc64le),
61 InstrInfo(*this), TLInfo(TM, *this) {
62 TSInfo = std::make_unique<PPCSelectionDAGInfo>();
63
65 Legalizer.reset(new PPCLegalizerInfo(*this));
66 auto *RBI = new PPCRegisterBankInfo(*getRegisterInfo());
67 RegBankInfo.reset(RBI);
68
69 InstSelector.reset(createPPCInstructionSelector(TM, *this, *RBI));
70}
71
73
77
78void PPCSubtarget::initializeEnvironment() {
82}
83
84void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
85 StringRef FS) {
86 // Determine default and user specified characteristics
87 std::string CPUName = std::string(CPU);
88 if (CPUName.empty() || CPU == "generic") {
89 if (getTargetTriple().getSubArch() == Triple::PPCSubArch_spe)
90 CPUName = "e500";
91 else
92 CPUName = std::string(PPC::getNormalizedPPCTargetCPU(getTargetTriple()));
93 }
94
95 // Determine the CPU to schedule for.
96 if (TuneCPU.empty()) TuneCPU = CPUName;
97
98 // Initialize scheduling itinerary for the specified CPU.
99 InstrItins = getInstrItineraryForCPU(CPUName);
100
101 // Parse features string.
102 ParseSubtargetFeatures(CPUName, TuneCPU, FS);
103
104 // If the user requested use of 64-bit regs, but the cpu selected doesn't
105 // support it, ignore.
106 if (IsPPC64 && has64BitSupport())
107 Use64BitRegs = true;
108
109 if (getTargetTriple().isPPC32SecurePlt())
110 IsSecurePlt = true;
111
112 if (HasSPE && IsPPC64)
113 report_fatal_error( "SPE is only supported for 32-bit targets.\n", false);
114 if (HasSPE && (HasAltivec || HasVSX || HasFPU))
116 "SPE and traditional floating point cannot both be enabled.\n", false);
117
118 // If not SPE, set standard FPU
119 if (!HasSPE)
120 HasFPU = true;
121
123
124 // Determine endianness.
125 IsLittleEndian = TM.isLittleEndian();
126
127 if (HasAIXSmallLocalExecTLS || HasAIXSmallLocalDynamicTLS) {
128 if (!getTargetTriple().isOSAIX() || !IsPPC64)
129 report_fatal_error("The aix-small-local-[exec|dynamic]-tls attribute is "
130 "only supported on AIX in "
131 "64-bit mode.\n",
132 false);
133 // The aix-small-local-[exec|dynamic]-tls attribute should only be used with
134 // -data-sections, as having data sections turned off with this option
135 // is not ideal for performance. Moreover, the
136 // small-local-[exec|dynamic]-tls region is a limited resource, and should
137 // not be used for variables that may be replaced.
138 if (!TM.getDataSections())
139 report_fatal_error("The aix-small-local-[exec|dynamic]-tls attribute can "
140 "only be specified with "
141 "-data-sections.\n",
142 false);
143 }
144
145 if (HasAIXShLibTLSModelOpt && (!getTargetTriple().isOSAIX() || !IsPPC64))
146 report_fatal_error("The aix-shared-lib-tls-model-opt attribute "
147 "is only supported on AIX in 64-bit mode.\n",
148 false);
149}
150
151bool PPCSubtarget::enableMachineScheduler() const { return true; }
152
154 return getSchedModel().hasInstrSchedModel() && EnableMachinePipeliner;
155}
156
157bool PPCSubtarget::useDFAforSMS() const { return false; }
158
159// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
160bool PPCSubtarget::enablePostRAScheduler() const { return true; }
161
162PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
163 return TargetSubtargetInfo::ANTIDEP_ALL;
164}
165
166void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
167 CriticalPathRCs.clear();
168 CriticalPathRCs.push_back(isPPC64() ?
169 &PPC::G8RCRegClass : &PPC::GPRCRegClass);
170}
171
173 const SchedRegion &Region) const {
174 // The GenericScheduler that we use defaults to scheduling bottom up only.
175 // We want to schedule from both the top and the bottom and so we set
176 // OnlyBottomUp to false.
177 // We want to do bi-directional scheduling since it provides a more balanced
178 // schedule leading to better performance.
179 Policy.OnlyBottomUp = false;
180 // Spilling is generally expensive on all PPC cores, so always enable
181 // register-pressure tracking.
182 Policy.ShouldTrackPressure = true;
183}
184
186 return true;
187}
188
189bool PPCSubtarget::enableSubRegLiveness() const { return true; }
190
192 if (isAIXABI()) {
193 if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
194 // On AIX the only symbols that aren't indirect are toc-data.
195 return !GVar->hasAttribute("toc-data");
196
197 return true;
198 }
199
200 // Large code model always uses the TOC even for local symbols.
201 if (TM.getCodeModel() == CodeModel::Large)
202 return true;
203
204 if (TM.shouldAssumeDSOLocal(GV))
205 return false;
206 return true;
207}
208
210 const GlobalValue *GV) const {
211 // If there isn't an attribute to override the module code model
212 // this will be the effective code model.
213 CodeModel::Model ModuleModel = TM.getCodeModel();
214
215 // Initially support per global code model for AIX only.
216 if (!isAIXABI())
217 return ModuleModel;
218
219 // Only GlobalVariables carry an attribute which can override the module code
220 // model.
221 assert(GV && "Unexpected NULL GlobalValue");
222 const GlobalVariable *GlobalVar =
223 [](const GlobalValue *GV) -> const GlobalVariable * {
225 if (Var)
226 return Var;
227
228 const GlobalAlias *Alias = dyn_cast<GlobalAlias>(GV);
229 if (Alias)
231
232 return nullptr;
233 }(GV);
234
235 if (!GlobalVar)
236 return ModuleModel;
237
238 std::optional<CodeModel::Model> MaybeCodeModel = GlobalVar->getCodeModel();
239 if (MaybeCodeModel) {
240 CodeModel::Model CM = *MaybeCodeModel;
241 assert((CM == CodeModel::Small || CM == CodeModel::Large) &&
242 "invalid code model for AIX");
243 return CM;
244 }
245
246 return ModuleModel;
247}
248
249bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
250bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); }
251
253 return isPPC64() && hasPCRelativeMemops() && isELFv2ABI() &&
255}
256
257// GlobalISEL
259 return CallLoweringInfo.get();
260}
261
263 return RegBankInfo.get();
264}
265
267 return Legalizer.get();
268}
269
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:623
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
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
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...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:151
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:162
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:649
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
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.