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/IR/GlobalValue.h"
18 #include "llvm/Support/Host.h"
19 #include "llvm/Support/TargetRegistry.h"
20 #include "llvm/Target/TargetMachine.h"
23 #define GET_SUBTARGETINFO_TARGET_DESC
24 #define GET_SUBTARGETINFO_CTOR
25 #include "PPCGenSubtargetInfo.inc"
29 PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU,
30 const std::string &FS, bool is64Bit)
31 : PPCGenSubtargetInfo(TT, CPU, FS)
33 , DarwinDirective(PPC::DIR_NONE)
35 , Has64BitSupport(false)
49 , HasLazyResolverStubs(false)
50 , IsJITCodeModel(false)
53 // Determine default and user specified characteristics
54 std::string CPUName = CPU;
57 #if (defined(__APPLE__) || defined(__linux__)) && \
58 (defined(__ppc__) || defined(__powerpc__))
59 if (CPUName == "generic")
60 CPUName = sys::getHostCPUName();
63 // Initialize scheduling itinerary for the specified CPU.
64 InstrItins = getInstrItineraryForCPU(CPUName);
66 // Make sure 64-bit features are available when CPUname is generic
67 std::string FullFS = FS;
69 // If we are generating code for ppc64, verify that options make sense.
71 Has64BitSupport = true;
72 // Silently force 64-bit register use on ppc64.
75 FullFS = "+64bit," + FullFS;
80 // Parse features string.
81 ParseSubtargetFeatures(CPUName, FullFS);
83 // If the user requested use of 64-bit regs, but the cpu selected doesn't
84 // support it, ignore.
85 if (use64BitRegs() && !has64BitSupport())
88 // Set up darwin-specific properties.
90 HasLazyResolverStubs = true;
92 // QPX requires a 32-byte aligned stack. Note that we need to do this if
93 // we're compiling for a BG/Q system regardless of whether or not QPX
94 // is enabled because external functions will assume this alignment.
95 if (hasQPX() || isBGQ())
99 /// SetJITMode - This is called to inform the subtarget info that we are
100 /// producing code for the JIT.
101 void PPCSubtarget::SetJITMode() {
102 // JIT mode doesn't want lazy resolver stubs, it knows exactly where
103 // everything is. This matters for PPC64, which codegens in PIC mode without
105 HasLazyResolverStubs = false;
107 // Calls to external functions need to use indirect calls
108 IsJITCodeModel = true;
112 /// hasLazyResolverStub - Return true if accesses to the specified global have
113 /// to go through a dyld lazy resolution stub. This means that an extra load
114 /// is required to get the address of the global.
115 bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV,
116 const TargetMachine &TM) const {
117 // We never have stubs if HasLazyResolverStubs=false or if in static mode.
118 if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static)
120 // If symbol visibility is hidden, the extra load is not needed if
121 // the symbol is definitely defined in the current translation unit.
122 bool isDecl = GV->isDeclaration() && !GV->isMaterializable();
123 if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage())
125 return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
126 GV->hasCommonLinkage() || isDecl;
129 bool PPCSubtarget::enablePostRAScheduler(
130 CodeGenOpt::Level OptLevel,
131 TargetSubtargetInfo::AntiDepBreakMode& Mode,
132 RegClassVector& CriticalPathRCs) const {
133 // FIXME: It would be best to use TargetSubtargetInfo::ANTIDEP_ALL here,
134 // but we can't because we can't reassign the cr registers. There is a
135 // dependence between the cr register and the RLWINM instruction used
136 // to extract its value which the anti-dependency breaker can't currently
137 // see. Maybe we should make a late-expanded pseudo to encode this dependency.
138 // (the relevant code is in PPCDAGToDAGISel::SelectSETCC)
140 Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
142 CriticalPathRCs.clear();
145 CriticalPathRCs.push_back(&PPC::G8RCRegClass);
147 CriticalPathRCs.push_back(&PPC::GPRCRegClass);
149 CriticalPathRCs.push_back(&PPC::F8RCRegClass);
150 CriticalPathRCs.push_back(&PPC::VRRCRegClass);
152 return OptLevel >= CodeGenOpt::Default;