1 //===-- PowerPCSubtarget.cpp - PPC Subtarget Information ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PPC specific subclass of TargetSubtargetInfo.
12 //===----------------------------------------------------------------------===//
14 #include "PPCSubtarget.h"
16 #include "PPCRegisterInfo.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineScheduler.h"
19 #include "llvm/IR/Attributes.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/GlobalValue.h"
22 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/Host.h"
24 #include "llvm/Support/TargetRegistry.h"
25 #include "llvm/Target/TargetMachine.h"
30 #define DEBUG_TYPE "ppc-subtarget"
32 #define GET_SUBTARGETINFO_TARGET_DESC
33 #define GET_SUBTARGETINFO_CTOR
34 #include "PPCGenSubtargetInfo.inc"
36 static cl::opt<bool> UseSubRegLiveness("ppc-track-subreg-liveness",
37 cl::desc("Enable subregister liveness tracking for PPC"), cl::Hidden);
39 /// Return the datalayout string of a subtarget.
40 static std::string getDataLayoutString(const Triple &T) {
41 bool is64Bit = T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le;
44 // Most PPC* platforms are big endian, PPC64LE is little endian.
45 if (T.getArch() == Triple::ppc64le)
50 Ret += DataLayout::getManglingComponent(T);
52 // PPC32 has 32 bit pointers. The PS3 (OS Lv2) is a PPC64 machine with 32 bit
54 if (!is64Bit || T.getOS() == Triple::Lv2)
57 // Note, the alignment values for f64 and i64 on ppc64 in Darwin
58 // documentation are wrong; these are correct (i.e. "what gcc does").
59 if (is64Bit || !T.isOSDarwin())
64 // PPC64 has 32 and 64 bit registers, PPC32 has only 32 bit ones.
73 PPCSubtarget &PPCSubtarget::initializeSubtargetDependencies(StringRef CPU,
75 initializeEnvironment();
76 initSubtargetFeatures(CPU, FS);
80 PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU,
81 const std::string &FS, const PPCTargetMachine &TM)
82 : PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT),
83 DL(getDataLayoutString(TargetTriple)),
84 IsPPC64(TargetTriple.getArch() == Triple::ppc64 ||
85 TargetTriple.getArch() == Triple::ppc64le),
86 TargetABI(PPC_ABI_UNKNOWN),
87 FrameLowering(initializeSubtargetDependencies(CPU, FS)), InstrInfo(*this),
88 TLInfo(TM), TSInfo(&DL) {}
90 void PPCSubtarget::initializeEnvironment() {
92 DarwinDirective = PPC::DIR_NONE;
94 Has64BitSupport = false;
108 HasRecipPrec = false;
118 HasOnlyMSYNC = false;
122 DeprecatedMFTB = false;
123 DeprecatedDST = false;
124 HasLazyResolverStubs = false;
129 void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
130 // Determine default and user specified characteristics
131 std::string CPUName = CPU;
134 #if (defined(__APPLE__) || defined(__linux__)) && \
135 (defined(__ppc__) || defined(__powerpc__))
136 if (CPUName == "generic")
137 CPUName = sys::getHostCPUName();
140 // Initialize scheduling itinerary for the specified CPU.
141 InstrItins = getInstrItineraryForCPU(CPUName);
143 // Parse features string.
144 ParseSubtargetFeatures(CPUName, FS);
146 // If the user requested use of 64-bit regs, but the cpu selected doesn't
147 // support it, ignore.
148 if (IsPPC64 && has64BitSupport())
151 // Set up darwin-specific properties.
153 HasLazyResolverStubs = true;
155 // QPX requires a 32-byte aligned stack. Note that we need to do this if
156 // we're compiling for a BG/Q system regardless of whether or not QPX
157 // is enabled because external functions will assume this alignment.
158 if (hasQPX() || isBGQ())
161 // Determine endianness.
162 IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le);
164 // Determine default ABI.
165 if (TargetABI == PPC_ABI_UNKNOWN) {
166 if (!isDarwin() && IsPPC64) {
168 TargetABI = PPC_ABI_ELFv2;
170 TargetABI = PPC_ABI_ELFv1;
175 /// hasLazyResolverStub - Return true if accesses to the specified global have
176 /// to go through a dyld lazy resolution stub. This means that an extra load
177 /// is required to get the address of the global.
178 bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV,
179 const TargetMachine &TM) const {
180 // We never have stubs if HasLazyResolverStubs=false or if in static mode.
181 if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static)
183 bool isDecl = GV->isDeclaration();
184 if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage())
186 return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
187 GV->hasCommonLinkage() || isDecl;
190 // Embedded cores need aggressive scheduling (and some others also benefit).
191 static bool needsAggressiveScheduling(unsigned Directive) {
193 default: return false;
196 case PPC::DIR_E500mc:
204 bool PPCSubtarget::enableMachineScheduler() const {
205 // Enable MI scheduling for the embedded cores.
206 // FIXME: Enable this for all cores (some additional modeling
207 // may be necessary).
208 return needsAggressiveScheduling(DarwinDirective);
211 // This overrides the PostRAScheduler bit in the SchedModel for each CPU.
212 bool PPCSubtarget::enablePostMachineScheduler() const { return true; }
214 PPCGenSubtargetInfo::AntiDepBreakMode PPCSubtarget::getAntiDepBreakMode() const {
215 return TargetSubtargetInfo::ANTIDEP_ALL;
218 void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
219 CriticalPathRCs.clear();
220 CriticalPathRCs.push_back(isPPC64() ?
221 &PPC::G8RCRegClass : &PPC::GPRCRegClass);
224 void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
227 unsigned NumRegionInstrs) const {
228 if (needsAggressiveScheduling(DarwinDirective)) {
229 Policy.OnlyTopDown = false;
230 Policy.OnlyBottomUp = false;
233 // Spilling is generally expensive on all PPC cores, so always enable
234 // register-pressure tracking.
235 Policy.ShouldTrackPressure = true;
238 bool PPCSubtarget::useAA() const {
239 // Use AA during code generation for the embedded cores.
240 return needsAggressiveScheduling(DarwinDirective);
243 bool PPCSubtarget::enableSubRegLiveness() const {
244 return UseSubRegLiveness;