LLVM  10.0.0
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"
14 #include "PPC.h"
15 #include "PPCRegisterInfo.h"
16 #include "PPCTargetMachine.h"
19 #include "llvm/IR/Attributes.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/GlobalValue.h"
25 #include <cstdlib>
26 
27 using namespace llvm;
28 
29 #define DEBUG_TYPE "ppc-subtarget"
30 
31 #define GET_SUBTARGETINFO_TARGET_DESC
32 #define GET_SUBTARGETINFO_CTOR
33 #include "PPCGenSubtargetInfo.inc"
34 
35 static cl::opt<bool> UseSubRegLiveness("ppc-track-subreg-liveness",
36 cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden);
37 
38 static cl::opt<bool> QPXStackUnaligned("qpx-stack-unaligned",
39  cl::desc("Even when QPX is enabled the stack is not 32-byte aligned"),
40  cl::Hidden);
41 
42 static 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 FS) {
49  initializeEnvironment();
50  initSubtargetFeatures(CPU, FS);
51  return *this;
52 }
53 
54 PPCSubtarget::PPCSubtarget(const Triple &TT, const std::string &CPU,
55  const std::string &FS, const PPCTargetMachine &TM)
56  : PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT),
57  IsPPC64(TargetTriple.getArch() == Triple::ppc64 ||
58  TargetTriple.getArch() == Triple::ppc64le),
60  InstrInfo(*this), TLInfo(TM, *this) {}
61 
62 void PPCSubtarget::initializeEnvironment() {
63  StackAlignment = Align(16);
65  HasMFOCRF = false;
66  Has64BitSupport = false;
67  Use64BitRegs = false;
68  UseCRBits = false;
69  HasHardFloat = false;
70  HasAltivec = false;
71  HasSPE = false;
72  HasFPU = false;
73  HasQPX = false;
74  HasVSX = false;
75  NeedsTwoConstNR = false;
76  HasP8Vector = false;
77  HasP8Altivec = false;
78  HasP8Crypto = false;
79  HasP9Vector = false;
80  HasP9Altivec = false;
81  HasFCPSGN = false;
82  HasFSQRT = false;
83  HasFRE = false;
84  HasFRES = false;
85  HasFRSQRTE = false;
86  HasFRSQRTES = false;
87  HasRecipPrec = false;
88  HasSTFIWX = false;
89  HasLFIWAX = false;
90  HasFPRND = false;
91  HasFPCVT = false;
92  HasISEL = false;
93  HasBPERMD = false;
94  HasExtDiv = false;
95  HasCMPB = false;
96  HasLDBRX = false;
97  IsBookE = false;
98  HasOnlyMSYNC = false;
99  IsPPC4xx = false;
100  IsPPC6xx = false;
101  IsE500 = false;
102  FeatureMFTB = false;
103  AllowsUnalignedFPAccess = false;
104  DeprecatedDST = false;
105  HasLazyResolverStubs = false;
106  HasICBT = false;
108  HasPartwordAtomics = false;
109  HasDirectMove = false;
110  IsQPXStackUnaligned = false;
111  HasHTM = false;
112  HasFloat128 = false;
113  IsISA3_0 = false;
114  UseLongCalls = false;
115  SecurePlt = false;
116  VectorsUseTwoUnits = false;
117  UsePPCPreRASchedStrategy = false;
119 
121 }
122 
123 void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
124  // Determine default and user specified characteristics
125  std::string CPUName = CPU;
126  if (CPUName.empty() || CPU == "generic") {
127  // If cross-compiling with -march=ppc64le without -mcpu
129  CPUName = "ppc64le";
131  CPUName = "e500";
132  else
133  CPUName = "generic";
134  }
135 
136  // Initialize scheduling itinerary for the specified CPU.
137  InstrItins = getInstrItineraryForCPU(CPUName);
138 
139  // Parse features string.
140  ParseSubtargetFeatures(CPUName, FS);
141 
142  // If the user requested use of 64-bit regs, but the cpu selected doesn't
143  // support it, ignore.
144  if (IsPPC64 && has64BitSupport())
145  Use64BitRegs = true;
146 
147  // Set up darwin-specific properties.
148  if (isDarwin())
149  HasLazyResolverStubs = true;
150 
154  SecurePlt = true;
155 
156  if (HasSPE && IsPPC64)
157  report_fatal_error( "SPE is only supported for 32-bit targets.\n", false);
158  if (HasSPE && (HasAltivec || HasQPX || HasVSX || HasFPU))
160  "SPE and traditional floating point cannot both be enabled.\n", false);
161 
162  // If not SPE, set standard FPU
163  if (!HasSPE)
164  HasFPU = true;
165 
166  // QPX requires a 32-byte aligned stack. Note that we need to do this if
167  // we're compiling for a BG/Q system regardless of whether or not QPX
168  // is enabled because external functions will assume this alignment.
171 
172  // Determine endianness.
173  // FIXME: Part of the TargetMachine.
175 }
176 
177 /// Return true if accesses to the specified global have to go through a dyld
178 /// lazy resolution stub. This means that an extra load is required to get the
179 /// address of the global.
182  return false;
183  if (!TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
184  return true;
185  // 32 bit macho has no relocation for a-b if a is undefined, even if b is in
186  // the section that is being relocated. This means we have to use o load even
187  // for GVs that are known to be local to the dso.
188  if (GV->isDeclarationForLinker() || GV->hasCommonLinkage())
189  return true;
190  return false;
191 }
192 
193 bool PPCSubtarget::enableMachineScheduler() const { return true; }
194 
197 }
198 
199 bool PPCSubtarget::useDFAforSMS() const { return false; }
200 
201 // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
202 bool PPCSubtarget::enablePostRAScheduler() const { return true; }
203 
204 PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
205  return TargetSubtargetInfo::ANTIDEP_ALL;
206 }
207 
208 void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
209  CriticalPathRCs.clear();
210  CriticalPathRCs.push_back(isPPC64() ?
211  &PPC::G8RCRegClass : &PPC::GPRCRegClass);
212 }
213 
215  unsigned NumRegionInstrs) const {
216  // The GenericScheduler that we use defaults to scheduling bottom up only.
217  // We want to schedule from both the top and the bottom and so we set
218  // OnlyBottomUp to false.
219  // We want to do bi-directional scheduling since it provides a more balanced
220  // schedule leading to better performance.
221  Policy.OnlyBottomUp = false;
222  // Spilling is generally expensive on all PPC cores, so always enable
223  // register-pressure tracking.
224  Policy.ShouldTrackPressure = true;
225 }
226 
227 bool PPCSubtarget::useAA() const {
228  return true;
229 }
230 
232  return UseSubRegLiveness;
233 }
234 
236  // Large code model always uses the TOC even for local symbols.
238  return true;
239  if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
240  return false;
241  return true;
242 }
243 
244 bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
245 bool PPCSubtarget::isPPC64() const { return TM.isPPC64(); }
bool isDeclarationForLinker() const
Definition: GlobalValue.h:533
void overrideSchedPolicy(MachineSchedPolicy &Policy, unsigned NumRegionInstrs) const override
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
PPCSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const PPCTargetMachine &TM)
This constructor initializes the data members to match that of the specified triple.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Align getPlatformStackAlignment() const
Definition: PPCSubtarget.h:290
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
bool IsQPXStackUnaligned
When targeting QPX running a stock PPC64 Linux kernel where the stack alignment has not been changed...
Definition: PPCSubtarget.h:149
Align StackAlignment
stackAlignment - The minimum alignment known to hold of the stack frame on entry to the function and ...
Definition: PPCSubtarget.h:82
bool useAA() const override
bool useDFAforSMS() const override
Machine Pipeliner customization.
POPCNTDKind HasPOPCNTD
Definition: PPCSubtarget.h:144
This file contains the simple types necessary to represent the attributes associated with functions a...
bool hasCommonLinkage() const
Definition: GlobalValue.h:449
SubArchType getSubArch() const
getSubArch - get the parsed subarchitecture type for this triple.
Definition: Triple.h:300
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:297
bool isELFv2ABI() const
bool has64BitSupport() const
has64BitSupport - Return true if the selected CPU supports 64-bit instructions, regardless of whether...
Definition: PPCSubtarget.h:216
bool isOSNetBSD() const
Definition: Triple.h:494
InstrItineraryData InstrItins
Selected instruction itineraries (one entry per itinerary class.)
Definition: PPCSubtarget.h:85
bool isMusl() const
Tests whether the environment is musl-libc.
Definition: Triple.h:678
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:435
bool shouldAssumeDSOLocal(const Module &M, const GlobalValue *GV) const
bool enableSubRegLiveness() const override
bool isOSOpenBSD() const
Definition: Triple.h:498
AntiDepBreakMode getAntiDepBreakMode() const override
PPCSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
initializeSubtargetDependencies - Initializes using a CPU and feature string so that we can use initi...
bool HasInvariantFunctionDescriptors
Definition: PPCSubtarget.h:132
PPCFrameLowering FrameLowering
Definition: PPCSubtarget.h:152
static cl::opt< bool > QPXStackUnaligned("qpx-stack-unaligned", cl::desc("Even when QPX is enabled the stack is not 32-byte aligned"), cl::Hidden)
PPCInstrInfo InstrInfo
Definition: PPCSubtarget.h:153
static cl::opt< bool > EnableMachinePipeliner("ppc-enable-pipeliner", cl::desc("Enable Machine Pipeliner for PPC"), cl::init(false), cl::Hidden)
Common code between 32-bit and 64-bit PowerPC targets.
unsigned getOSMajorVersion() const
getOSMajorVersion - Return just the major version number, this is specialized because it is a common ...
Definition: Triple.h:339
const PPCTargetMachine & TM
Definition: PPCSubtarget.h:151
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override
void ParseSubtargetFeatures(StringRef CPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
bool isOSFreeBSD() const
Definition: Triple.h:502
bool UsePPCPostRASchedStrategy
Definition: PPCSubtarget.h:142
CodeModel::Model getCodeModel() const
Returns the code model.
Triple TargetTriple
TargetTriple - What processor and OS we&#39;re targeting.
Definition: PPCSubtarget.h:78
bool enableMachineScheduler() const override
Scheduling customization.
Define a generic scheduling policy for targets that don&#39;t provide their own MachineSchedStrategy.
static cl::opt< bool > UseSubRegLiveness("ppc-track-subreg-liveness", cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden)
bool hasLazyResolverStub(const GlobalValue *GV) const
hasLazyResolverStub - Return true if accesses to the specified global have to go through a dyld lazy ...
PPCTargetLowering TLInfo
Definition: PPCSubtarget.h:154
bool enableMachinePipeliner() const override
Pipeliner customization.
bool isDarwin() const
isDarwin - True if this is any darwin platform.
Definition: PPCSubtarget.h:316
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
bool isGVIndirectSymbol(const GlobalValue *GV) const
True if the GV will be accessed via an indirect symbol.
bool HasMFOCRF
Used by the ISel to turn in optimizations for POWER4-derived architectures.
Definition: PPCSubtarget.h:91
unsigned CPUDirective
Which cpu directive was used.
Definition: PPCSubtarget.h:88
bool enablePostRAScheduler() const override
This overrides the PostRAScheduler bit in the SchedModel for each CPU.