1 //===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the PPC specific subclass of TargetSubtargetInfo.
11 //===----------------------------------------------------------------------===//
13 #include "PPCSubtarget.h"
14 #include "GISel/PPCCallLowering.h"
15 #include "GISel/PPCLegalizerInfo.h"
16 #include "GISel/PPCRegisterBankInfo.h"
18 #include "PPCRegisterInfo.h"
19 #include "PPCTargetMachine.h"
20 #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/MachineScheduler.h"
23 #include "llvm/IR/Attributes.h"
24 #include "llvm/IR/Function.h"
25 #include "llvm/IR/GlobalValue.h"
26 #include "llvm/Support/CommandLine.h"
27 #include "llvm/Support/TargetRegistry.h"
28 #include "llvm/Target/TargetMachine.h"
33 #define DEBUG_TYPE "ppc-subtarget"
35 #define GET_SUBTARGETINFO_TARGET_DESC
36 #define GET_SUBTARGETINFO_CTOR
37 #include "PPCGenSubtargetInfo.inc"
39 static cl::opt
<bool> UseSubRegLiveness("ppc-track-subreg-liveness",
40 cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden
);
43 EnableMachinePipeliner("ppc-enable-pipeliner",
44 cl::desc("Enable Machine Pipeliner for PPC"),
45 cl::init(false), cl::Hidden
);
47 PPCSubtarget
&PPCSubtarget::initializeSubtargetDependencies(StringRef CPU
,
49 initializeEnvironment();
50 initSubtargetFeatures(CPU
, FS
);
54 PPCSubtarget::PPCSubtarget(const Triple
&TT
, const std::string
&CPU
,
55 const std::string
&FS
, const PPCTargetMachine
&TM
)
56 : PPCGenSubtargetInfo(TT
, CPU
, /*TuneCPU*/ CPU
, FS
), TargetTriple(TT
),
57 IsPPC64(TargetTriple
.getArch() == Triple::ppc64
||
58 TargetTriple
.getArch() == Triple::ppc64le
),
59 TM(TM
), FrameLowering(initializeSubtargetDependencies(CPU
, FS
)),
60 InstrInfo(*this), TLInfo(TM
, *this) {
61 CallLoweringInfo
.reset(new PPCCallLowering(*getTargetLowering()));
62 Legalizer
.reset(new PPCLegalizerInfo(*this));
63 auto *RBI
= new PPCRegisterBankInfo(*getRegisterInfo());
64 RegBankInfo
.reset(RBI
);
66 InstSelector
.reset(createPPCInstructionSelector(
67 *static_cast<const PPCTargetMachine
*>(&TM
), *this, *RBI
));
70 void PPCSubtarget::initializeEnvironment() {
71 StackAlignment
= Align(16);
72 CPUDirective
= PPC::DIR_NONE
;
74 Has64BitSupport
= false;
83 NeedsTwoConstNR
= false;
90 HasROPProtect
= false;
91 HasPrivileged
= false;
93 HasPrefixInstrs
= false;
94 HasPCRelativeMemops
= false;
101 HasRecipPrec
= false;
112 HasOnlyMSYNC
= false;
117 AllowsUnalignedFPAccess
= false;
118 DeprecatedDST
= false;
120 HasInvariantFunctionDescriptors
= false;
121 HasPartwordAtomics
= false;
122 HasQuadwordAtomics
= false;
123 HasDirectMove
= false;
127 HasStoreFusion
= false;
128 HasAddiLoadFusion
= false;
129 HasAddisLoadFusion
= false;
133 UseLongCalls
= false;
135 VectorsUseTwoUnits
= false;
136 UsePPCPreRASchedStrategy
= false;
137 UsePPCPostRASchedStrategy
= false;
138 PairedVectorMemops
= false;
139 PredictableSelectIsExpensive
= false;
140 HasModernAIXAs
= false;
143 HasPOPCNTD
= POPCNTD_Unavailable
;
146 void PPCSubtarget::initSubtargetFeatures(StringRef CPU
, StringRef FS
) {
147 // Determine default and user specified characteristics
148 std::string CPUName
= std::string(CPU
);
149 if (CPUName
.empty() || CPU
== "generic") {
150 // If cross-compiling with -march=ppc64le without -mcpu
151 if (TargetTriple
.getArch() == Triple::ppc64le
)
153 else if (TargetTriple
.getSubArch() == Triple::PPCSubArch_spe
)
159 // Initialize scheduling itinerary for the specified CPU.
160 InstrItins
= getInstrItineraryForCPU(CPUName
);
162 // Parse features string.
163 ParseSubtargetFeatures(CPUName
, /*TuneCPU*/ CPUName
, FS
);
165 // If the user requested use of 64-bit regs, but the cpu selected doesn't
166 // support it, ignore.
167 if (IsPPC64
&& has64BitSupport())
170 if ((TargetTriple
.isOSFreeBSD() && TargetTriple
.getOSMajorVersion() >= 13) ||
171 TargetTriple
.isOSNetBSD() || TargetTriple
.isOSOpenBSD() ||
172 TargetTriple
.isMusl())
175 if (HasSPE
&& IsPPC64
)
176 report_fatal_error( "SPE is only supported for 32-bit targets.\n", false);
177 if (HasSPE
&& (HasAltivec
|| HasVSX
|| HasFPU
))
179 "SPE and traditional floating point cannot both be enabled.\n", false);
181 // If not SPE, set standard FPU
185 StackAlignment
= getPlatformStackAlignment();
187 // Determine endianness.
188 IsLittleEndian
= TM
.isLittleEndian();
191 bool PPCSubtarget::enableMachineScheduler() const { return true; }
193 bool PPCSubtarget::enableMachinePipeliner() const {
194 return getSchedModel().hasInstrSchedModel() && EnableMachinePipeliner
;
197 bool PPCSubtarget::useDFAforSMS() const { return false; }
199 // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
200 bool PPCSubtarget::enablePostRAScheduler() const { return true; }
202 PPCGenSubtargetInfo::AntiDepBreakMode
PPCSubtarget::getAntiDepBreakMode() const {
203 return TargetSubtargetInfo::ANTIDEP_ALL
;
206 void PPCSubtarget::getCriticalPathRCs(RegClassVector
&CriticalPathRCs
) const {
207 CriticalPathRCs
.clear();
208 CriticalPathRCs
.push_back(isPPC64() ?
209 &PPC::G8RCRegClass
: &PPC::GPRCRegClass
);
212 void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy
&Policy
,
213 unsigned NumRegionInstrs
) const {
214 // The GenericScheduler that we use defaults to scheduling bottom up only.
215 // We want to schedule from both the top and the bottom and so we set
216 // OnlyBottomUp to false.
217 // We want to do bi-directional scheduling since it provides a more balanced
218 // schedule leading to better performance.
219 Policy
.OnlyBottomUp
= false;
220 // Spilling is generally expensive on all PPC cores, so always enable
221 // register-pressure tracking.
222 Policy
.ShouldTrackPressure
= true;
225 bool PPCSubtarget::useAA() const {
229 bool PPCSubtarget::enableSubRegLiveness() const {
230 return UseSubRegLiveness
;
233 bool PPCSubtarget::isGVIndirectSymbol(const GlobalValue
*GV
) const {
234 // Large code model always uses the TOC even for local symbols.
235 if (TM
.getCodeModel() == CodeModel::Large
)
237 if (TM
.shouldAssumeDSOLocal(*GV
->getParent(), GV
))
242 bool PPCSubtarget::isELFv2ABI() const { return TM
.isELFv2ABI(); }
243 bool PPCSubtarget::isPPC64() const { return TM
.isPPC64(); }
245 bool PPCSubtarget::isUsingPCRelativeCalls() const {
246 return isPPC64() && hasPCRelativeMemops() && isELFv2ABI() &&
247 CodeModel::Medium
== getTargetMachine().getCodeModel();
251 const CallLowering
*PPCSubtarget::getCallLowering() const {
252 return CallLoweringInfo
.get();
255 const RegisterBankInfo
*PPCSubtarget::getRegBankInfo() const {
256 return RegBankInfo
.get();
259 const LegalizerInfo
*PPCSubtarget::getLegalizerInfo() const {
260 return Legalizer
.get();
263 InstructionSelector
*PPCSubtarget::getInstructionSelector() const {
264 return InstSelector
.get();