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/Module.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 TargetMachine &tm, const Module &M, 00061 const std::string &FS, bool is64Bit) 00062 : TM(tm) 00063 , StackAlignment(16) 00064 , DarwinDirective(PPC::DIR_NONE) 00065 , IsGigaProcessor(false) 00066 , Has64BitSupport(false) 00067 , Use64BitRegs(false) 00068 , IsPPC64(is64Bit) 00069 , HasAltivec(false) 00070 , HasFSQRT(false) 00071 , HasSTFIWX(false) 00072 , HasLazyResolverStubs(false) 00073 , DarwinVers(0) { 00074 00075 // Determine default and user specified characteristics 00076 std::string CPU = "generic"; 00077 #if defined(__APPLE__) 00078 CPU = GetCurrentPowerPCCPU(); 00079 #endif 00080 00081 // Parse features string. 00082 ParseSubtargetFeatures(FS, CPU); 00083 00084 // If we are generating code for ppc64, verify that options make sense. 00085 if (is64Bit) { 00086 Has64BitSupport = true; 00087 // Silently force 64-bit register use on ppc64. 00088 Use64BitRegs = true; 00089 } 00090 00091 // If the user requested use of 64-bit regs, but the cpu selected doesn't 00092 // support it, ignore. 00093 if (use64BitRegs() && !has64BitSupport()) 00094 Use64BitRegs = false; 00095 00096 // Set the boolean corresponding to the current target triple, or the default 00097 // if one cannot be determined, to true. 00098 const std::string &TT = M.getTargetTriple(); 00099 if (TT.length() > 7) { 00100 // Determine which version of darwin this is. 00101 size_t DarwinPos = TT.find("-darwin"); 00102 if (DarwinPos != std::string::npos) { 00103 if (isdigit(TT[DarwinPos+7])) 00104 DarwinVers = atoi(&TT[DarwinPos+7]); 00105 else 00106 DarwinVers = 8; // Minimum supported darwin is Tiger. 00107 } 00108 } else if (TT.empty()) { 00109 // Try to autosense the subtarget from the host compiler. 00110 #if defined(__APPLE__) 00111 #if __APPLE_CC__ > 5400 00112 DarwinVers = 9; // GCC 5400+ is Leopard. 00113 #else 00114 DarwinVers = 8; // Minimum supported darwin is Tiger. 00115 #endif 00116 #endif 00117 } 00118 00119 // Set up darwin-specific properties. 00120 if (isDarwin()) { 00121 HasLazyResolverStubs = true; 00122 AsmFlavor = NewMnemonic; 00123 } else { 00124 AsmFlavor = OldMnemonic; 00125 } 00126 } 00127 00128 /// SetJITMode - This is called to inform the subtarget info that we are 00129 /// producing code for the JIT. 00130 void PPCSubtarget::SetJITMode() { 00131 // JIT mode doesn't want lazy resolver stubs, it knows exactly where 00132 // everything is. This matters for PPC64, which codegens in PIC mode without 00133 // stubs. 00134 HasLazyResolverStubs = false; 00135 } 00136 00137 00138 /// hasLazyResolverStub - Return true if accesses to the specified global have 00139 /// to go through a dyld lazy resolution stub. This means that an extra load 00140 /// is required to get the address of the global. 00141 bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV) const { 00142 // We never hae stubs if HasLazyResolverStubs=false or if in static mode. 00143 if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static) 00144 return false; 00145 // If symbol visibility is hidden, the extra load is not needed if 00146 // the symbol is definitely defined in the current translation unit. 00147 bool isDecl = GV->isDeclaration() && !GV->hasNotBeenReadFromBitcode(); 00148 if (GV->hasHiddenVisibility() && !isDecl && !GV->hasCommonLinkage()) 00149 return false; 00150 return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || 00151 GV->hasCommonLinkage() || isDecl; 00152 }