Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 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" |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame^] | 15 | #include "PowerPC.h" |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 16 | #include "llvm/Module.h" |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame^] | 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 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 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 | |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 52 | PPCSubtarget::PPCSubtarget(const Module &M) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame^] | 53 | : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) { |
| 54 | |
| 55 | // Set the boolean corresponding to the current target triple, or the default |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 56 | // if one cannot be determined, to true. |
| 57 | const std::string& TT = M.getTargetTriple(); |
| 58 | if (TT.length() > 5) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame^] | 59 | IsDarwin = TT.find("darwin") != std::string::npos; |
Chris Lattner | ba25365 | 2005-08-05 21:25:13 +0000 | [diff] [blame] | 60 | #if defined(__APPLE__) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame^] | 61 | IsGigaProcessor = IsGP(); |
Chris Lattner | ba25365 | 2005-08-05 21:25:13 +0000 | [diff] [blame] | 62 | #endif |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 63 | } else if (TT.empty()) { |
| 64 | #if defined(_POWER) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame^] | 65 | IsAIX = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 66 | #elif defined(__APPLE__) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame^] | 67 | IsDarwin = true; |
| 68 | IsGigaProcessor = IsGP(); |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 69 | #endif |
| 70 | } |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame^] | 71 | |
| 72 | // If GP opts are forced on by the commandline, do so now. |
| 73 | if (EnableGPOPT) IsGigaProcessor = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 74 | } |