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 "PowerPCSubtarget.h"
16 #include "llvm/Module.h"
17 #include "llvm/Support/CommandLine.h"
19 PPCTargetEnum llvm::PPCTarget = TargetDefault;
22 cl::opt<PPCTargetEnum, true>
23 PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"),
25 clEnumValN(TargetAIX, "aix", " Enable AIX codegen"),
26 clEnumValN(TargetDarwin,"darwin"," Enable Darwin codegen"),
28 cl::location(PPCTarget), cl::init(TargetDefault));
29 cl::opt<bool> EnableGPOPT("enable-gpopt", cl::Hidden,
30 cl::desc("Enable optimizations for GP cpus"));
33 #if defined(__APPLE__)
34 #include <mach/mach.h>
35 #include <mach/mach_host.h>
36 #include <mach/host_info.h>
37 #include <mach/machine.h>
39 static boolean_t IsGP() {
40 host_basic_info_data_t hostInfo;
41 mach_msg_type_number_t infoCount;
43 infoCount = HOST_BASIC_INFO_COUNT;
44 host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
47 return ((hostInfo.cpu_type == CPU_TYPE_POWERPC) &&
48 (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970));
52 PPCSubtarget::PPCSubtarget(const Module &M)
53 : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
55 // Set the boolean corresponding to the current target triple, or the default
56 // if one cannot be determined, to true.
57 const std::string& TT = M.getTargetTriple();
58 if (TT.length() > 5) {
59 IsDarwin = TT.find("darwin") != std::string::npos;
60 #if defined(__APPLE__)
61 IsGigaProcessor = IsGP();
63 } else if (TT.empty()) {
66 #elif defined(__APPLE__)
68 IsGigaProcessor = IsGP();
72 // If GP opts are forced on by the commandline, do so now.
73 if (EnableGPOPT) IsGigaProcessor = true;