1 //===- PowerPCSubtarget.cpp - PPC Subtarget Information ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Nate Begeman and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the PPC specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #include "PPCSubtarget.h"
16 #include "llvm/Module.h"
17 #include "llvm/Support/CommandLine.h"
18 #include "PPCGenSubtarget.inc"
21 PPCTargetEnum llvm::PPCTarget = TargetDefault;
22 bool llvm::PPCGenerateStaticCode = false;
25 cl::opt<PPCTargetEnum, true>
26 PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"),
28 clEnumValN(TargetAIX, "aix", " Enable AIX codegen"),
29 clEnumValN(TargetDarwin,"darwin",
30 " Enable Darwin codegen"),
32 cl::location(PPCTarget), cl::init(TargetDefault));
35 PPCStaticCode("ppc-static",
36 cl::desc("PowerPC: generate completely non-pic code"),
37 cl::location(PPCGenerateStaticCode));
40 #if defined(__APPLE__)
41 #include <mach/mach.h>
42 #include <mach/mach_host.h>
43 #include <mach/host_info.h>
44 #include <mach/machine.h>
46 /// GetCurrentPowerPCFeatures - Returns the current CPUs features.
47 static const char *GetCurrentPowerPCCPU() {
48 host_basic_info_data_t hostInfo;
49 mach_msg_type_number_t infoCount;
51 infoCount = HOST_BASIC_INFO_COUNT;
52 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
55 if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic";
57 switch(hostInfo.cpu_subtype) {
58 case CPU_SUBTYPE_POWERPC_601: return "601";
59 case CPU_SUBTYPE_POWERPC_602: return "602";
60 case CPU_SUBTYPE_POWERPC_603: return "603";
61 case CPU_SUBTYPE_POWERPC_603e: return "603e";
62 case CPU_SUBTYPE_POWERPC_603ev: return "603ev";
63 case CPU_SUBTYPE_POWERPC_604: return "604";
64 case CPU_SUBTYPE_POWERPC_604e: return "604e";
65 case CPU_SUBTYPE_POWERPC_620: return "620";
66 case CPU_SUBTYPE_POWERPC_750: return "750";
67 case CPU_SUBTYPE_POWERPC_7400: return "7400";
68 case CPU_SUBTYPE_POWERPC_7450: return "7450";
69 case CPU_SUBTYPE_POWERPC_970: return "970";
78 PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS)
81 , IsGigaProcessor(false)
89 // Determine default and user specified characteristics
90 std::string CPU = "generic";
91 #if defined(__APPLE__)
92 CPU = GetCurrentPowerPCCPU();
95 // Parse features string.
96 ParseSubtargetFeatures(FS, CPU);
98 // Set the boolean corresponding to the current target triple, or the default
99 // if one cannot be determined, to true.
100 const std::string& TT = M.getTargetTriple();
101 if (TT.length() > 5) {
102 IsDarwin = TT.find("darwin") != std::string::npos;
103 } else if (TT.empty()) {
106 #elif defined(__APPLE__)