3bfa7a6eefe8a1ebe2c90634eb30d7ee4143e338
[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 "llvm/Module.h"
16
17 #if defined(__APPLE__)
18 #include <mach/mach.h>
19 #include <mach/mach_host.h>
20 #include <mach/host_info.h>
21 #include <mach/machine.h>
22
23 static boolean_t IsGP() {
24   host_basic_info_data_t hostInfo;
25   mach_msg_type_number_t infoCount;
26
27   infoCount = HOST_BASIC_INFO_COUNT;
28   host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, 
29             &infoCount);
30   
31   return ((hostInfo.cpu_type == CPU_TYPE_POWERPC) &&
32           (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970));
33
34 #endif
35
36 using namespace llvm;
37
38 PPCSubtarget::PPCSubtarget(const Module &M)
39   : TargetSubtarget(), stackAlignment(16), isGigaProcessor(false), isAIX(false),
40     isDarwin(false) {
41   // Set the boolean corresponding to the current target triple, or the default
42   // if one cannot be determined, to true.
43   const std::string& TT = M.getTargetTriple();
44   if (TT.length() > 5) {
45     isDarwin = TT.find("darwin") != std::string::npos;
46 #if defined(__APPLE__)
47     isGigaProcessor = IsGP();
48 #endif
49   } else if (TT.empty()) {
50 #if defined(_POWER)
51     isAIX = true;
52 #elif defined(__APPLE__)
53     isDarwin = true;
54     isGigaProcessor = IsGP();
55 #endif
56   }
57 }