blob: 686c11c6691af138dd81e60fc656d658d4b27ab5 [file] [log] [blame]
Nate Begeman8c00f8c2005-08-04 07:12:09 +00001//===- 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"
Chris Lattner3c304a32005-08-05 22:05:03 +000015#include "PowerPC.h"
Nate Begeman8c00f8c2005-08-04 07:12:09 +000016#include "llvm/Module.h"
Chris Lattner3c304a32005-08-05 22:05:03 +000017#include "llvm/Support/CommandLine.h"
18using namespace llvm;
19PPCTargetEnum llvm::PPCTarget = TargetDefault;
20
21namespace 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}
Nate Begeman8c00f8c2005-08-04 07:12:09 +000032
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
39static 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
Nate Begeman8c00f8c2005-08-04 07:12:09 +000052PPCSubtarget::PPCSubtarget(const Module &M)
Chris Lattner3c304a32005-08-05 22:05:03 +000053 : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) {
54
55 // Set the boolean corresponding to the current target triple, or the default
Nate Begeman8c00f8c2005-08-04 07:12:09 +000056 // if one cannot be determined, to true.
57 const std::string& TT = M.getTargetTriple();
58 if (TT.length() > 5) {
Chris Lattner3c304a32005-08-05 22:05:03 +000059 IsDarwin = TT.find("darwin") != std::string::npos;
Chris Lattnerba253652005-08-05 21:25:13 +000060#if defined(__APPLE__)
Chris Lattner3c304a32005-08-05 22:05:03 +000061 IsGigaProcessor = IsGP();
Chris Lattnerba253652005-08-05 21:25:13 +000062#endif
Nate Begeman8c00f8c2005-08-04 07:12:09 +000063 } else if (TT.empty()) {
64#if defined(_POWER)
Chris Lattner3c304a32005-08-05 22:05:03 +000065 IsAIX = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +000066#elif defined(__APPLE__)
Chris Lattner3c304a32005-08-05 22:05:03 +000067 IsDarwin = true;
68 IsGigaProcessor = IsGP();
Nate Begeman8c00f8c2005-08-04 07:12:09 +000069#endif
70 }
Chris Lattner3c304a32005-08-05 22:05:03 +000071
72 // If GP opts are forced on by the commandline, do so now.
73 if (EnableGPOPT) IsGigaProcessor = true;
Nate Begeman8c00f8c2005-08-04 07:12:09 +000074}