LLVM API Documentation
00001 //===- PowerPCSubtarget.cpp - PPC Subtarget Information -------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by Nate Begeman and is distributed under the 00006 // University of Illinois Open Source 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 "PPCGenSubtarget.inc" 00018 #include <iostream> 00019 using namespace llvm; 00020 00021 #if defined(__APPLE__) 00022 #include <mach/mach.h> 00023 #include <mach/mach_host.h> 00024 #include <mach/host_info.h> 00025 #include <mach/machine.h> 00026 00027 /// GetCurrentPowerPCFeatures - Returns the current CPUs features. 00028 static const char *GetCurrentPowerPCCPU() { 00029 host_basic_info_data_t hostInfo; 00030 mach_msg_type_number_t infoCount; 00031 00032 infoCount = HOST_BASIC_INFO_COUNT; 00033 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, 00034 &infoCount); 00035 00036 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic"; 00037 00038 switch(hostInfo.cpu_subtype) { 00039 case CPU_SUBTYPE_POWERPC_601: return "601"; 00040 case CPU_SUBTYPE_POWERPC_602: return "602"; 00041 case CPU_SUBTYPE_POWERPC_603: return "603"; 00042 case CPU_SUBTYPE_POWERPC_603e: return "603e"; 00043 case CPU_SUBTYPE_POWERPC_603ev: return "603ev"; 00044 case CPU_SUBTYPE_POWERPC_604: return "604"; 00045 case CPU_SUBTYPE_POWERPC_604e: return "604e"; 00046 case CPU_SUBTYPE_POWERPC_620: return "620"; 00047 case CPU_SUBTYPE_POWERPC_750: return "750"; 00048 case CPU_SUBTYPE_POWERPC_7400: return "7400"; 00049 case CPU_SUBTYPE_POWERPC_7450: return "7450"; 00050 case CPU_SUBTYPE_POWERPC_970: return "970"; 00051 default: ; 00052 } 00053 00054 return "generic"; 00055 } 00056 #endif 00057 00058 00059 PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS, bool is64Bit) 00060 : StackAlignment(16) 00061 , InstrItins() 00062 , IsGigaProcessor(false) 00063 , Has64BitSupport(false) 00064 , Use64BitRegs(false) 00065 , IsPPC64(is64Bit) 00066 , HasAltivec(false) 00067 , HasFSQRT(false) 00068 , HasSTFIWX(false) 00069 , IsDarwin(false) { 00070 00071 // Determine default and user specified characteristics 00072 std::string CPU = "generic"; 00073 #if defined(__APPLE__) 00074 CPU = GetCurrentPowerPCCPU(); 00075 #endif 00076 00077 // Parse features string. 00078 ParseSubtargetFeatures(FS, CPU); 00079 00080 // If we are generating code for ppc64, verify that options make sense. 00081 if (is64Bit) { 00082 if (!has64BitSupport()) { 00083 std::cerr << "PPC: Generation of 64-bit code for a 32-bit processor " 00084 "requested. Ignoring 32-bit processor feature.\n"; 00085 Has64BitSupport = true; 00086 } 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, warn and ignore. 00093 if (use64BitRegs() && !has64BitSupport()) { 00094 std::cerr << "PPC: 64-bit registers requested on CPU without support. " 00095 "Disabling 64-bit register use.\n"; 00096 Use64BitRegs = false; 00097 } 00098 00099 // Set the boolean corresponding to the current target triple, or the default 00100 // if one cannot be determined, to true. 00101 const std::string& TT = M.getTargetTriple(); 00102 if (TT.length() > 5) { 00103 IsDarwin = TT.find("-darwin") != std::string::npos; 00104 } else if (TT.empty()) { 00105 #if defined(__APPLE__) 00106 IsDarwin = true; 00107 #endif 00108 } 00109 }