LLVM API Documentation
00001 //===- PowerPCSubtarget.cpp - PPC Subtarget Information -------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the PPC specific subclass of TargetSubtarget. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "PPCSubtarget.h" 00015 #include "PPC.h" 00016 #include "llvm/GlobalValue.h" 00017 #include "llvm/Target/TargetMachine.h" 00018 #include "PPCGenSubtarget.inc" 00019 #include <cstdlib> 00020 using namespace llvm; 00021 00022 #if defined(__APPLE__) 00023 #include <mach/mach.h> 00024 #include <mach/mach_host.h> 00025 #include <mach/host_info.h> 00026 #include <mach/machine.h> 00027 00028 /// GetCurrentPowerPCFeatures - Returns the current CPUs features. 00029 static const char *GetCurrentPowerPCCPU() { 00030 host_basic_info_data_t hostInfo; 00031 mach_msg_type_number_t infoCount; 00032 00033 infoCount = HOST_BASIC_INFO_COUNT; 00034 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, 00035 &infoCount); 00036 00037 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic"; 00038 00039 switch(hostInfo.cpu_subtype) { 00040 case CPU_SUBTYPE_POWERPC_601: return "601"; 00041 case CPU_SUBTYPE_POWERPC_602: return "602"; 00042 case CPU_SUBTYPE_POWERPC_603: return "603"; 00043 case CPU_SUBTYPE_POWERPC_603e: return "603e"; 00044 case CPU_SUBTYPE_POWERPC_603ev: return "603ev"; 00045 case CPU_SUBTYPE_POWERPC_604: return "604"; 00046 case CPU_SUBTYPE_POWERPC_604e: return "604e"; 00047 case CPU_SUBTYPE_POWERPC_620: return "620"; 00048 case CPU_SUBTYPE_POWERPC_750: return "750"; 00049 case CPU_SUBTYPE_POWERPC_7400: return "7400"; 00050 case CPU_SUBTYPE_POWERPC_7450: return "7450"; 00051 case CPU_SUBTYPE_POWERPC_970: return "970"; 00052 default: ; 00053 } 00054 00055 return "generic"; 00056 } 00057 #endif 00058 00059 00060 PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &FS, 00061 bool is64Bit) 00062 : StackAlignment(16) 00063 , DarwinDirective(PPC::DIR_NONE) 00064 , IsGigaProcessor(false) 00065 , Has64BitSupport(false) 00066 , Use64BitRegs(false) 00067 , IsPPC64(is64Bit) 00068 , HasAltivec(false) 00069 , HasFSQRT(false) 00070 , HasSTFIWX(false) 00071 , HasLazyResolverStubs(false) 00072 , DarwinVers(0) { 00073 00074 // Determine default and user specified characteristics 00075 std::string CPU = "generic"; 00076 #if defined(__APPLE__) 00077 CPU = GetCurrentPowerPCCPU(); 00078 #endif 00079 00080 // Parse features string. 00081 ParseSubtargetFeatures(FS, CPU); 00082 00083 // If we are generating code for ppc64, verify that options make sense. 00084 if (is64Bit) { 00085 Has64BitSupport = true; 00086 // Silently force 64-bit register use on ppc64. 00087 Use64BitRegs = true; 00088 } 00089 00090 // If the user requested use of 64-bit regs, but the cpu selected doesn't 00091 // support it, ignore. 00092 if (use64BitRegs() && !has64BitSupport()) 00093 Use64BitRegs = false; 00094 00095 // Set the boolean corresponding to the current target triple, or the default 00096 // if one cannot be determined, to true. 00097 if (TT.length() > 7) { 00098 // Determine which version of darwin this is. 00099 size_t DarwinPos = TT.find("-darwin"); 00100 if (DarwinPos != std::string::npos) { 00101 if (isdigit(TT[DarwinPos+7])) 00102 DarwinVers = atoi(&TT[DarwinPos+7]); 00103 else 00104 DarwinVers = 8; // Minimum supported darwin is Tiger. 00105 } 00106 } 00107 00108 // Set up darwin-specific properties. 00109 if (isDarwin()) 00110 HasLazyResolverStubs = true; 00111 } 00112 00113 /// SetJITMode - This is called to inform the subtarget info that we are 00114 /// producing code for the JIT. 00115 void PPCSubtarget::SetJITMode() { 00116 // JIT mode doesn't want lazy resolver stubs, it knows exactly where 00117 // everything is. This matters for PPC64, which codegens in PIC mode without 00118 // stubs. 00119 HasLazyResolverStubs = false; 00120 } 00121 00122 00123 /// hasLazyResolverStub - Return true if accesses to the specified global have 00124 /// to go through a dyld lazy resolution stub. This means that an extra load 00125 /// is required to get the address of the global. 00126 bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV, 00127 const TargetMachine &TM) const { 00128 // We never hae stubs if HasLazyResolverStubs=false or if in static mode. 00129 if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static) 00130 return false; 00131 // If symbol visibility is hidden, the extra load is not needed if 00132 // the symbol is definitely defined in the current translation unit. 00133 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode(); 00134 if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage()) 00135 return false; 00136 return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || 00137 GV->hasCommonLinkage() || isDecl; 00138 }