LLVM 17.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 "PPCTargetMachine.h"
24#include "llvm/IR/Attributes.h"
25#include "llvm/IR/Function.h"
26#include "llvm/IR/GlobalValue.h"
30#include <cstdlib>
31
32using namespace llvm;
33
34#define DEBUG_TYPE "ppc-subtarget"
35
36#define GET_SUBTARGETINFO_TARGET_DESC
37#define GET_SUBTARGETINFO_CTOR
38#include "PPCGenSubtargetInfo.inc"
39
40static cl::opt<bool>
41 UseSubRegLiveness("ppc-track-subreg-liveness",
42 cl::desc("Enable subregister liveness tracking for PPC"),
43 cl::init(true), cl::Hidden);
44
45static cl::opt<bool>
46 EnableMachinePipeliner("ppc-enable-pipeliner",
47 cl::desc("Enable Machine Pipeliner for PPC"),
48 cl::init(false), cl::Hidden);
49
51 StringRef TuneCPU,
52 StringRef FS) {
53 initializeEnvironment();
54 initSubtargetFeatures(CPU, TuneCPU, FS);
55 return *this;
56}
57
58PPCSubtarget::PPCSubtarget(const Triple &TT, const std::string &CPU,
59 const std::string &TuneCPU, const std::string &FS,
60 const PPCTargetMachine &TM)
61 : PPCGenSubtargetInfo(TT, CPU, TuneCPU, FS), TargetTriple(TT),
62 IsPPC64(TargetTriple.getArch() == Triple::ppc64 ||
63 TargetTriple.getArch() == Triple::ppc64le),
64 TM(TM), FrameLowering(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
65 InstrInfo(*this), TLInfo(TM, *this) {
67 Legalizer.reset(new PPCLegalizerInfo(*this));
68 auto *RBI = new PPCRegisterBankInfo(*getRegisterInfo());
69 RegBankInfo.reset(RBI);
70
72 *static_cast<const PPCTargetMachine *>(&TM), *this, *RBI));
73}
74
75void PPCSubtarget::initializeEnvironment() {
79}
80
81void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
82 StringRef FS) {
83 // Determine default and user specified characteristics
84 std::string CPUName = std::string(CPU);
85 if (CPUName.empty() || CPU == "generic") {
86 // If cross-compiling with -march=ppc64le without -mcpu
88 CPUName = "ppc64le";
90 CPUName = "e500";
91 else
92 CPUName = "generic";
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
112 IsSecurePlt = true;
113
114 if (HasSPE && IsPPC64)
115 report_fatal_error( "SPE is only supported for 32-bit targets.\n", false);
116 if (HasSPE && (HasAltivec || HasVSX || HasFPU))
118 "SPE and traditional floating point cannot both be enabled.\n", false);
119
120 // If not SPE, set standard FPU
121 if (!HasSPE)
122 HasFPU = true;
123
125
126 // Determine endianness.
128}
129
130bool PPCSubtarget::enableMachineScheduler() const { return true; }
131
133 return getSchedModel().hasInstrSchedModel() && EnableMachinePipeliner;
134}
135
136bool PPCSubtarget::useDFAforSMS() const { return false; }
137
138// This overrides the PostRAScheduler bit in the SchedModel for each CPU.
139bool PPCSubtarget::enablePostRAScheduler() const { return true; }
140
141PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
142 return TargetSubtargetInfo::ANTIDEP_ALL;
143}
144
145void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
146 CriticalPathRCs.clear();
147 CriticalPathRCs.push_back(isPPC64() ?
148 &PPC::G8RCRegClass : &PPC::GPRCRegClass);
149}
150
152 unsigned NumRegionInstrs) const {
153 // The GenericScheduler that we use defaults to scheduling bottom up only.
154 // We want to schedule from both the top and the bottom and so we set
155 // OnlyBottomUp to false.
156 // We want to do bi-directional scheduling since it provides a more balanced
157 // schedule leading to better performance.
158 Policy.OnlyBottomUp = false;
159 // Spilling is generally expensive on all PPC cores, so always enable
160 // register-pressure tracking.
161 Policy.ShouldTrackPressure = true;
162}
163
165 return true;
166}
167
169 return UseSubRegLiveness;
170}
171
173 // Large code model always uses the TOC even for local symbols.
175 return true;
176 if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
177 return false;
178 return true;
179}
180
181bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
182bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); }
183
185 return isPPC64() && hasPCRelativeMemops() && isELFv2ABI() &&
187}
188
189// GlobalISEL
191 return CallLoweringInfo.get();
192}
193
195 return RegBankInfo.get();
196}
197
199 return Legalizer.get();
200}
201
203 return InstSelector.get();
204}
This file contains the simple types necessary to represent the attributes associated with functions a...
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 > UseSubRegLiveness("ppc-track-subreg-liveness", cl::desc("Enable subregister liveness tracking for PPC"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableMachinePipeliner("ppc-enable-pipeliner", cl::desc("Enable Machine Pipeliner for PPC"), cl::init(false), cl::Hidden)
const char LLVMTargetMachineRef TM
return InstrInfo
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
Provides the logic to select generic machine instructions.
This class provides the information for the PowerPC target legalizer for GlobalISel.
std::unique_ptr< InstructionSelector > InstSelector
Definition: PPCSubtarget.h:113
bool enableMachinePipeliner() const override
Pipeliner customization.
bool useDFAforSMS() const override
Machine Pipeliner customization.
const CallLowering * getCallLowering() const override
Triple TargetTriple
TargetTriple - What processor and OS we're targeting.
Definition: PPCSubtarget.h:81
const LegalizerInfo * getLegalizerInfo() const override
std::unique_ptr< RegisterBankInfo > RegBankInfo
Definition: PPCSubtarget.h:112
POPCNTDKind HasPOPCNTD
Definition: PPCSubtarget.h:101
InstrItineraryData InstrItins
Selected instruction itineraries (one entry per itinerary class.)
Definition: PPCSubtarget.h:88
Align StackAlignment
stackAlignment - The minimum alignment known to hold of the stack frame on entry to the function and ...
Definition: PPCSubtarget.h:85
void overrideSchedPolicy(MachineSchedPolicy &Policy, unsigned NumRegionInstrs) const override
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
Definition: PPCSubtarget.h:146
InstructionSelector * getInstructionSelector() const override
unsigned CPUDirective
Which cpu directive was used.
Definition: PPCSubtarget.h:96
AntiDepBreakMode getAntiDepBreakMode() 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...
bool isELFv2ABI() const
Align getPlatformStackAlignment() const
Definition: PPCSubtarget.h:188
const PPCTargetMachine & getTargetMachine() const
Definition: PPCSubtarget.h:155
PPCSubtarget(const Triple &TT, const std::string &CPU, const std::string &TuneCPU, const std::string &FS, const PPCTargetMachine &TM)
This constructor initializes the data members to match that of the specified triple.
const PPCTargetMachine & TM
Definition: PPCSubtarget.h:103
bool enableMachineScheduler() const override
Scheduling customization.
const RegisterBankInfo * getRegBankInfo() const override
const PPCRegisterInfo * getRegisterInfo() const override
Definition: PPCSubtarget.h:152
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.
Definition: PPCSubtarget.h:110
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.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
bool shouldAssumeDSOLocal(const Module &M, const GlobalValue *GV) const
CodeModel::Model getCodeModel() const
Returns the code model.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
SubArchType getSubArch() const
get the parsed subarchitecture type for this triple.
Definition: Triple.h:358
bool isOSNetBSD() const
Definition: Triple.h:536
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:355
bool isOSOpenBSD() const
Definition: Triple.h:540
bool isMusl() const
Tests whether the environment is musl-libc.
Definition: Triple.h:739
@ PPCSubArch_spe
Definition: Triple.h:156
bool isOSFreeBSD() const
Definition: Triple.h:544
unsigned getOSMajorVersion() const
Return just the major version number, this is specialized because it is a common query.
Definition: Triple.h:391
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:445
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
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.