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" |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 18 | #include "llvm/Target/SubtargetFeature.h" |
| 19 | |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | PPCTargetEnum llvm::PPCTarget = TargetDefault; |
| 22 | |
| 23 | namespace llvm { |
| 24 | cl::opt<PPCTargetEnum, true> |
| 25 | PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"), |
| 26 | cl::values( |
| 27 | clEnumValN(TargetAIX, "aix", " Enable AIX codegen"), |
Chris Lattner | 1e9de3e | 2005-09-02 18:33:05 +0000 | [diff] [blame] | 28 | clEnumValN(TargetDarwin,"darwin", |
| 29 | " Enable Darwin codegen"), |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 30 | clEnumValEnd), |
| 31 | cl::location(PPCTarget), cl::init(TargetDefault)); |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 32 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 33 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 34 | enum PowerPCFeature { |
| 35 | PowerPCFeature64Bit = 1 << 0, |
| 36 | PowerPCFeatureAltivec = 1 << 1, |
| 37 | PowerPCFeatureFSqrt = 1 << 2, |
| 38 | PowerPCFeatureGPUL = 1 << 3, |
| 39 | }; |
| 40 | |
| 41 | /// Sorted (by key) array of values for CPU subtype. |
| 42 | static const SubtargetFeatureKV PowerPCSubTypeKV[] = { |
Jim Laskey | 839615a | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 43 | { "601" , "Select the PowerPC 601 processor", 0 }, |
| 44 | { "602" , "Select the PowerPC 602 processor", 0 }, |
| 45 | { "603" , "Select the PowerPC 603 processor", 0 }, |
| 46 | { "603e" , "Select the PowerPC 603e processor", 0 }, |
| 47 | { "603ev" , "Select the PowerPC 603ev processor", 0 }, |
| 48 | { "604" , "Select the PowerPC 604 processor", 0 }, |
| 49 | { "604e" , "Select the PowerPC 604e processor", 0 }, |
| 50 | { "620" , "Select the PowerPC 620 processor", 0 }, |
| 51 | { "7400" , "Select the PowerPC 7400 (G4) processor", |
| 52 | PowerPCFeatureAltivec }, |
| 53 | { "7450" , "Select the PowerPC 7450 (G4+) processor", |
| 54 | PowerPCFeatureAltivec }, |
| 55 | { "750" , "Select the PowerPC 750 (G3) processor", 0 }, |
| 56 | { "970" , "Select the PowerPC 970 (G5 - GPUL) processor", |
| 57 | PowerPCFeature64Bit | PowerPCFeatureAltivec | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 58 | PowerPCFeatureFSqrt | PowerPCFeatureGPUL }, |
Jim Laskey | 839615a | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 59 | { "g3" , "Select the PowerPC G3 (750) processor", 0 }, |
| 60 | { "g4" , "Select the PowerPC G4 (7400) processor", |
| 61 | PowerPCFeatureAltivec }, |
| 62 | { "g4+" , "Select the PowerPC G4+ (7450) processor", |
| 63 | PowerPCFeatureAltivec }, |
| 64 | { "g5" , "Select the PowerPC g5 (970 - GPUL) processor", |
| 65 | PowerPCFeature64Bit | PowerPCFeatureAltivec | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 66 | PowerPCFeatureFSqrt | PowerPCFeatureGPUL }, |
Jim Laskey | 839615a | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 67 | { "generic", "Select instructions for a generic PowerPC processor", 0 } |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 68 | }; |
| 69 | /// Length of PowerPCSubTypeKV. |
| 70 | static const unsigned PowerPCSubTypeKVSize = sizeof(PowerPCSubTypeKV) |
| 71 | / sizeof(SubtargetFeatureKV); |
| 72 | |
| 73 | /// Sorted (by key) array of values for CPU features. |
| 74 | static SubtargetFeatureKV PowerPCFeatureKV[] = { |
Jim Laskey | 839615a | 2005-09-02 19:27:43 +0000 | [diff] [blame] | 75 | { "64bit" , "Should 64 bit instructions be used" , PowerPCFeature64Bit }, |
| 76 | { "altivec", "Should Altivec instructions be used" , PowerPCFeatureAltivec }, |
| 77 | { "fsqrt" , "Should the fsqrt instruction be used", PowerPCFeatureFSqrt }, |
| 78 | { "gpul" , "Should GPUL instructions be used" , PowerPCFeatureGPUL } |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 79 | }; |
| 80 | /// Length of PowerPCFeatureKV. |
| 81 | static const unsigned PowerPCFeatureKVSize = sizeof(PowerPCFeatureKV) |
| 82 | / sizeof(SubtargetFeatureKV); |
| 83 | |
| 84 | |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 85 | #if defined(__APPLE__) |
| 86 | #include <mach/mach.h> |
| 87 | #include <mach/mach_host.h> |
| 88 | #include <mach/host_info.h> |
| 89 | #include <mach/machine.h> |
| 90 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 91 | /// GetCurrentPowerPCFeatures - Returns the current CPUs features. |
| 92 | static const char *GetCurrentPowerPCCPU() { |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 93 | host_basic_info_data_t hostInfo; |
| 94 | mach_msg_type_number_t infoCount; |
| 95 | |
| 96 | infoCount = HOST_BASIC_INFO_COUNT; |
| 97 | host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, |
| 98 | &infoCount); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 99 | |
| 100 | if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic"; |
| 101 | |
| 102 | switch(hostInfo.cpu_subtype) { |
| 103 | case CPU_SUBTYPE_POWERPC_601: return "601"; |
| 104 | case CPU_SUBTYPE_POWERPC_602: return "602"; |
| 105 | case CPU_SUBTYPE_POWERPC_603: return "603"; |
| 106 | case CPU_SUBTYPE_POWERPC_603e: return "603e"; |
| 107 | case CPU_SUBTYPE_POWERPC_603ev: return "603ev"; |
| 108 | case CPU_SUBTYPE_POWERPC_604: return "604"; |
| 109 | case CPU_SUBTYPE_POWERPC_604e: return "604e"; |
| 110 | case CPU_SUBTYPE_POWERPC_620: return "620"; |
| 111 | case CPU_SUBTYPE_POWERPC_750: return "750"; |
| 112 | case CPU_SUBTYPE_POWERPC_7400: return "7400"; |
| 113 | case CPU_SUBTYPE_POWERPC_7450: return "7450"; |
| 114 | case CPU_SUBTYPE_POWERPC_970: return "970"; |
| 115 | default: ; |
| 116 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 117 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 118 | return "generic"; |
| 119 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 120 | #endif |
| 121 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 122 | PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 123 | : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) { |
| 124 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 125 | // Determine default and user specified characteristics |
Chris Lattner | c98d823 | 2005-09-07 05:45:33 +0000 | [diff] [blame^] | 126 | std::string CPU = "generic"; |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 127 | #if defined(__APPLE__) |
| 128 | CPU = GetCurrentPowerPCCPU(); |
| 129 | #endif |
| 130 | uint32_t Bits = |
| 131 | SubtargetFeatures::Parse(FS, CPU, |
| 132 | PowerPCSubTypeKV, PowerPCSubTypeKVSize, |
| 133 | PowerPCFeatureKV, PowerPCFeatureKVSize); |
Chris Lattner | 1e9de3e | 2005-09-02 18:33:05 +0000 | [diff] [blame] | 134 | IsGigaProcessor = (Bits & PowerPCFeatureGPUL ) != 0; |
Nate Begeman | d401dff | 2005-09-06 15:30:12 +0000 | [diff] [blame] | 135 | Is64Bit = (Bits & PowerPCFeature64Bit) != 0; |
Chris Lattner | 1e9de3e | 2005-09-02 18:33:05 +0000 | [diff] [blame] | 136 | HasFSQRT = (Bits & PowerPCFeatureFSqrt) != 0; |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 137 | |
| 138 | // Set the boolean corresponding to the current target triple, or the default |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 139 | // if one cannot be determined, to true. |
| 140 | const std::string& TT = M.getTargetTriple(); |
| 141 | if (TT.length() > 5) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 142 | IsDarwin = TT.find("darwin") != std::string::npos; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 143 | } else if (TT.empty()) { |
| 144 | #if defined(_POWER) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 145 | IsAIX = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 146 | #elif defined(__APPLE__) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 147 | IsDarwin = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 148 | #endif |
| 149 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 150 | } |