LLVM API Documentation

PPCSubtarget.cpp

Go to the documentation of this file.
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 "llvm/Support/CommandLine.h"
00018 #include "PPCGenSubtarget.inc"
00019 
00020 using namespace llvm;
00021 PPCTargetEnum llvm::PPCTarget = TargetDefault;
00022 
00023 namespace llvm {
00024   cl::opt<PPCTargetEnum, true>
00025   PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"),
00026                cl::values(
00027                           clEnumValN(TargetAIX,  "aix", "  Enable AIX codegen"),
00028                           clEnumValN(TargetDarwin,"darwin",
00029                                      "  Enable Darwin codegen"),
00030                           clEnumValEnd),
00031                cl::location(PPCTarget), cl::init(TargetDefault));  
00032 } 
00033  
00034 #if defined(__APPLE__)
00035 #include <mach/mach.h>
00036 #include <mach/mach_host.h>
00037 #include <mach/host_info.h>
00038 #include <mach/machine.h>
00039 
00040 /// GetCurrentPowerPCFeatures - Returns the current CPUs features.
00041 static const char *GetCurrentPowerPCCPU() {
00042   host_basic_info_data_t hostInfo;
00043   mach_msg_type_number_t infoCount;
00044 
00045   infoCount = HOST_BASIC_INFO_COUNT;
00046   host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, 
00047             &infoCount);
00048             
00049   if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
00050 
00051   switch(hostInfo.cpu_subtype) {
00052   case CPU_SUBTYPE_POWERPC_601:   return "601";
00053   case CPU_SUBTYPE_POWERPC_602:   return "602";
00054   case CPU_SUBTYPE_POWERPC_603:   return "603";
00055   case CPU_SUBTYPE_POWERPC_603e:  return "603e";
00056   case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
00057   case CPU_SUBTYPE_POWERPC_604:   return "604";
00058   case CPU_SUBTYPE_POWERPC_604e:  return "604e";
00059   case CPU_SUBTYPE_POWERPC_620:   return "620";
00060   case CPU_SUBTYPE_POWERPC_750:   return "750";
00061   case CPU_SUBTYPE_POWERPC_7400:  return "7400";
00062   case CPU_SUBTYPE_POWERPC_7450:  return "7450";
00063   case CPU_SUBTYPE_POWERPC_970:   return "970";
00064   default: ;
00065   }
00066   
00067   return "generic";
00068 }
00069 #endif
00070 
00071 
00072 PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
00073   : StackAlignment(16)
00074   , InstrItins()
00075   , IsGigaProcessor(false)
00076   , Is64Bit(false)
00077   , Has64BitRegs(false)
00078   , HasAltivec(false)
00079   , HasFSQRT(false)
00080   , HasSTFIWX(false)
00081   , IsAIX(false)
00082   , IsDarwin(false) {
00083 
00084   // Determine default and user specified characteristics
00085   std::string CPU = "generic";
00086 #if defined(__APPLE__)
00087   CPU = GetCurrentPowerPCCPU();
00088 #endif
00089 
00090   // Parse features string.
00091   ParseSubtargetFeatures(FS, CPU);
00092 
00093   // Set the boolean corresponding to the current target triple, or the default
00094   // if one cannot be determined, to true.
00095   const std::string& TT = M.getTargetTriple();
00096   if (TT.length() > 5) {
00097     IsDarwin = TT.find("darwin") != std::string::npos;
00098   } else if (TT.empty()) {
00099 #if defined(_POWER)
00100     IsAIX = true;
00101 #elif defined(__APPLE__)
00102     IsDarwin = true;
00103 #endif
00104   }
00105 }