PPCSubtarget.cpp revision 221345
1193323Sed//===- PowerPCSubtarget.cpp - PPC Subtarget Information -------------------===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file implements the PPC specific subclass of TargetSubtarget. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14193323Sed#include "PPCSubtarget.h" 15193323Sed#include "PPC.h" 16198090Srdivacky#include "llvm/GlobalValue.h" 17193323Sed#include "llvm/Target/TargetMachine.h" 18193323Sed#include "PPCGenSubtarget.inc" 19193323Sed#include <cstdlib> 20193323Sedusing namespace llvm; 21193323Sed 22193323Sed#if defined(__APPLE__) 23193323Sed#include <mach/mach.h> 24193323Sed#include <mach/mach_host.h> 25193323Sed#include <mach/host_info.h> 26193323Sed#include <mach/machine.h> 27193323Sed 28193323Sed/// GetCurrentPowerPCFeatures - Returns the current CPUs features. 29193323Sedstatic const char *GetCurrentPowerPCCPU() { 30193323Sed host_basic_info_data_t hostInfo; 31193323Sed mach_msg_type_number_t infoCount; 32193323Sed 33193323Sed infoCount = HOST_BASIC_INFO_COUNT; 34193323Sed host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, 35193323Sed &infoCount); 36193323Sed 37193323Sed if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic"; 38193323Sed 39193323Sed switch(hostInfo.cpu_subtype) { 40193323Sed case CPU_SUBTYPE_POWERPC_601: return "601"; 41193323Sed case CPU_SUBTYPE_POWERPC_602: return "602"; 42193323Sed case CPU_SUBTYPE_POWERPC_603: return "603"; 43193323Sed case CPU_SUBTYPE_POWERPC_603e: return "603e"; 44193323Sed case CPU_SUBTYPE_POWERPC_603ev: return "603ev"; 45193323Sed case CPU_SUBTYPE_POWERPC_604: return "604"; 46193323Sed case CPU_SUBTYPE_POWERPC_604e: return "604e"; 47193323Sed case CPU_SUBTYPE_POWERPC_620: return "620"; 48193323Sed case CPU_SUBTYPE_POWERPC_750: return "750"; 49193323Sed case CPU_SUBTYPE_POWERPC_7400: return "7400"; 50193323Sed case CPU_SUBTYPE_POWERPC_7450: return "7450"; 51193323Sed case CPU_SUBTYPE_POWERPC_970: return "970"; 52193323Sed default: ; 53193323Sed } 54193323Sed 55193323Sed return "generic"; 56193323Sed} 57193323Sed#endif 58193323Sed 59193323Sed 60198090SrdivackyPPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &FS, 61198090Srdivacky bool is64Bit) 62198090Srdivacky : StackAlignment(16) 63193323Sed , DarwinDirective(PPC::DIR_NONE) 64193323Sed , IsGigaProcessor(false) 65193323Sed , Has64BitSupport(false) 66193323Sed , Use64BitRegs(false) 67193323Sed , IsPPC64(is64Bit) 68193323Sed , HasAltivec(false) 69193323Sed , HasFSQRT(false) 70193323Sed , HasSTFIWX(false) 71193323Sed , HasLazyResolverStubs(false) 72212904Sdim , IsJITCodeModel(false) 73221345Sdim , TargetTriple(TT) { 74193323Sed 75193323Sed // Determine default and user specified characteristics 76193323Sed std::string CPU = "generic"; 77193323Sed#if defined(__APPLE__) 78193323Sed CPU = GetCurrentPowerPCCPU(); 79193323Sed#endif 80193323Sed 81193323Sed // Parse features string. 82193323Sed ParseSubtargetFeatures(FS, CPU); 83193323Sed 84193323Sed // If we are generating code for ppc64, verify that options make sense. 85193323Sed if (is64Bit) { 86193323Sed Has64BitSupport = true; 87193323Sed // Silently force 64-bit register use on ppc64. 88193323Sed Use64BitRegs = true; 89193323Sed } 90193323Sed 91193323Sed // If the user requested use of 64-bit regs, but the cpu selected doesn't 92193323Sed // support it, ignore. 93193323Sed if (use64BitRegs() && !has64BitSupport()) 94193323Sed Use64BitRegs = false; 95193323Sed 96193323Sed // Set up darwin-specific properties. 97198090Srdivacky if (isDarwin()) 98193323Sed HasLazyResolverStubs = true; 99193323Sed} 100193323Sed 101193323Sed/// SetJITMode - This is called to inform the subtarget info that we are 102193323Sed/// producing code for the JIT. 103193323Sedvoid PPCSubtarget::SetJITMode() { 104193323Sed // JIT mode doesn't want lazy resolver stubs, it knows exactly where 105193323Sed // everything is. This matters for PPC64, which codegens in PIC mode without 106193323Sed // stubs. 107193323Sed HasLazyResolverStubs = false; 108212904Sdim 109212904Sdim // Calls to external functions need to use indirect calls 110212904Sdim IsJITCodeModel = true; 111193323Sed} 112193323Sed 113193323Sed 114193323Sed/// hasLazyResolverStub - Return true if accesses to the specified global have 115193323Sed/// to go through a dyld lazy resolution stub. This means that an extra load 116193323Sed/// is required to get the address of the global. 117198090Srdivackybool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV, 118198090Srdivacky const TargetMachine &TM) const { 119218893Sdim // We never have stubs if HasLazyResolverStubs=false or if in static mode. 120193323Sed if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static) 121193323Sed return false; 122193323Sed // If symbol visibility is hidden, the extra load is not needed if 123193323Sed // the symbol is definitely defined in the current translation unit. 124203954Srdivacky bool isDecl = GV->isDeclaration() && !GV->isMaterializable(); 125193323Sed if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage()) 126193323Sed return false; 127193323Sed return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || 128193323Sed GV->hasCommonLinkage() || isDecl; 129193323Sed} 130