686c11c6691af138dd81e60fc656d658d4b27ab5
[oota-llvm.git] / lib / Target / PowerPC / PPCSubtarget.cpp
1 //===- PowerPCSubtarget.cpp - PPC Subtarget Information ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the PPC specific subclass of TargetSubtarget.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PowerPCSubtarget.h"
15 #include "PowerPC.h"
16 #include "llvm/Module.h"
17 #include "llvm/Support/CommandLine.h"
18 using namespace llvm;
19 PPCTargetEnum llvm::PPCTarget = TargetDefault;
20
21 namespace llvm {
22   cl::opt<PPCTargetEnum, true>
23   PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"),
24                cl::values(
25                           clEnumValN(TargetAIX,  "aix", "  Enable AIX codegen"),
26                           clEnumValN(TargetDarwin,"darwin","  Enable Darwin codegen"),
27                           clEnumValEnd),
28                cl::location(PPCTarget), cl::init(TargetDefault));
29   cl::opt<bool> EnableGPOPT("enable-gpopt", cl::Hidden,
30                              cl::desc("Enable optimizations for GP cpus"));
31 }
32
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>
38
39 static boolean_t IsGP() {
40   host_basic_info_data_t hostInfo;
41   mach_msg_type_number_t infoCount;
42
43   infoCount = HOST_BASIC_INFO_COUNT;
44   host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, 
45             &infoCount);
46   
47   return ((hostInfo.cpu_type == CPU_TYPE_POWERPC) &&
48           (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970));
49
50 #endif
51
52 PPCSubtarget::PPCSubtarget(const Module &M)
53   : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
54
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();
62 #endif
63   } else if (TT.empty()) {
64 #if defined(_POWER)
65     IsAIX = true;
66 #elif defined(__APPLE__)
67     IsDarwin = true;
68     IsGigaProcessor = IsGP();
69 #endif
70   }
71   
72   // If GP opts are forced on by the commandline, do so now.
73   if (EnableGPOPT) IsGigaProcessor = true;
74 }