Chris Lattner | 9690979 | 2006-01-28 05:40:47 +0000 | [diff] [blame^] | 1 | //===- PowerPCSubtarget.cpp - PPC Subtarget Information -------------------===// |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 2668959 | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 14 | #include "PPCSubtarget.h" |
| 15 | #include "PPC.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" |
Jim Laskey | f5fc2cb | 2005-10-21 19:05:19 +0000 | [diff] [blame] | 18 | #include "PPCGenSubtarget.inc" |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | PPCTargetEnum llvm::PPCTarget = TargetDefault; |
Chris Lattner | 1d05cb4 | 2005-11-17 18:55:48 +0000 | [diff] [blame] | 22 | bool llvm::PPCGenerateStaticCode = false; |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
| 25 | cl::opt<PPCTargetEnum, true> |
| 26 | PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"), |
| 27 | cl::values( |
| 28 | clEnumValN(TargetAIX, "aix", " Enable AIX codegen"), |
Chris Lattner | 1e9de3e | 2005-09-02 18:33:05 +0000 | [diff] [blame] | 29 | clEnumValN(TargetDarwin,"darwin", |
| 30 | " Enable Darwin codegen"), |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 31 | clEnumValEnd), |
| 32 | cl::location(PPCTarget), cl::init(TargetDefault)); |
Chris Lattner | 1d05cb4 | 2005-11-17 18:55:48 +0000 | [diff] [blame] | 33 | |
| 34 | cl::opt<bool, true> |
| 35 | PPCStaticCode("ppc-static", |
| 36 | cl::desc("PowerPC: generate completely non-pic code"), |
| 37 | cl::location(PPCGenerateStaticCode)); |
Jim Laskey | f5fc2cb | 2005-10-21 19:05:19 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 40 | #if defined(__APPLE__) |
| 41 | #include <mach/mach.h> |
| 42 | #include <mach/mach_host.h> |
| 43 | #include <mach/host_info.h> |
| 44 | #include <mach/machine.h> |
| 45 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 46 | /// GetCurrentPowerPCFeatures - Returns the current CPUs features. |
| 47 | static const char *GetCurrentPowerPCCPU() { |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 48 | host_basic_info_data_t hostInfo; |
| 49 | mach_msg_type_number_t infoCount; |
| 50 | |
| 51 | infoCount = HOST_BASIC_INFO_COUNT; |
| 52 | host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, |
| 53 | &infoCount); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 54 | |
| 55 | if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic"; |
| 56 | |
| 57 | switch(hostInfo.cpu_subtype) { |
| 58 | case CPU_SUBTYPE_POWERPC_601: return "601"; |
| 59 | case CPU_SUBTYPE_POWERPC_602: return "602"; |
| 60 | case CPU_SUBTYPE_POWERPC_603: return "603"; |
| 61 | case CPU_SUBTYPE_POWERPC_603e: return "603e"; |
| 62 | case CPU_SUBTYPE_POWERPC_603ev: return "603ev"; |
| 63 | case CPU_SUBTYPE_POWERPC_604: return "604"; |
| 64 | case CPU_SUBTYPE_POWERPC_604e: return "604e"; |
| 65 | case CPU_SUBTYPE_POWERPC_620: return "620"; |
| 66 | case CPU_SUBTYPE_POWERPC_750: return "750"; |
| 67 | case CPU_SUBTYPE_POWERPC_7400: return "7400"; |
| 68 | case CPU_SUBTYPE_POWERPC_7450: return "7450"; |
| 69 | case CPU_SUBTYPE_POWERPC_970: return "970"; |
| 70 | default: ; |
| 71 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 72 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 73 | return "generic"; |
| 74 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 75 | #endif |
| 76 | |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 77 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 78 | PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS) |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 79 | : StackAlignment(16) |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 80 | , InstrItins() |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 81 | , IsGigaProcessor(false) |
| 82 | , Is64Bit(false) |
| 83 | , Has64BitRegs(false) |
| 84 | , HasAltivec(false) |
| 85 | , HasFSQRT(false) |
| 86 | , IsAIX(false) |
| 87 | , IsDarwin(false) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 88 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 89 | // Determine default and user specified characteristics |
Chris Lattner | c98d823 | 2005-09-07 05:45:33 +0000 | [diff] [blame] | 90 | std::string CPU = "generic"; |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 91 | #if defined(__APPLE__) |
| 92 | CPU = GetCurrentPowerPCCPU(); |
| 93 | #endif |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 94 | |
| 95 | // Parse features string. |
| 96 | ParseSubtargetFeatures(FS, CPU); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 97 | |
| 98 | // Set the boolean corresponding to the current target triple, or the default |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 99 | // if one cannot be determined, to true. |
| 100 | const std::string& TT = M.getTargetTriple(); |
| 101 | if (TT.length() > 5) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 102 | IsDarwin = TT.find("darwin") != std::string::npos; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 103 | } else if (TT.empty()) { |
| 104 | #if defined(_POWER) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 105 | IsAIX = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 106 | #elif defined(__APPLE__) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 107 | IsDarwin = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 108 | #endif |
| 109 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 110 | } |