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[] = { |
| 43 | { "601" , 0 }, |
| 44 | { "602" , 0 }, |
| 45 | { "603" , 0 }, |
| 46 | { "603e" , 0 }, |
| 47 | { "603ev" , 0 }, |
| 48 | { "604" , 0 }, |
| 49 | { "604e" , 0 }, |
| 50 | { "620" , 0 }, |
| 51 | { "7400" , PowerPCFeatureAltivec }, |
| 52 | { "7450" , PowerPCFeatureAltivec }, |
| 53 | { "750" , 0 }, |
| 54 | { "970" , PowerPCFeature64Bit | PowerPCFeatureAltivec | |
| 55 | PowerPCFeatureFSqrt | PowerPCFeatureGPUL }, |
| 56 | { "g3" , 0 }, |
| 57 | { "g4" , PowerPCFeatureAltivec }, |
| 58 | { "g4+" , PowerPCFeatureAltivec }, |
| 59 | { "g5" , PowerPCFeature64Bit | PowerPCFeatureAltivec | |
| 60 | PowerPCFeatureFSqrt | PowerPCFeatureGPUL }, |
| 61 | { "generic", 0 } |
| 62 | }; |
| 63 | /// Length of PowerPCSubTypeKV. |
| 64 | static const unsigned PowerPCSubTypeKVSize = sizeof(PowerPCSubTypeKV) |
| 65 | / sizeof(SubtargetFeatureKV); |
| 66 | |
| 67 | /// Sorted (by key) array of values for CPU features. |
| 68 | static SubtargetFeatureKV PowerPCFeatureKV[] = { |
| 69 | { "64bit" , PowerPCFeature64Bit }, |
| 70 | { "altivec", PowerPCFeatureAltivec }, |
| 71 | { "fsqrt" , PowerPCFeatureFSqrt }, |
| 72 | { "gpul" , PowerPCFeatureGPUL } |
| 73 | }; |
| 74 | /// Length of PowerPCFeatureKV. |
| 75 | static const unsigned PowerPCFeatureKVSize = sizeof(PowerPCFeatureKV) |
| 76 | / sizeof(SubtargetFeatureKV); |
| 77 | |
| 78 | |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 79 | #if defined(__APPLE__) |
| 80 | #include <mach/mach.h> |
| 81 | #include <mach/mach_host.h> |
| 82 | #include <mach/host_info.h> |
| 83 | #include <mach/machine.h> |
| 84 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 85 | /// GetCurrentPowerPCFeatures - Returns the current CPUs features. |
| 86 | static const char *GetCurrentPowerPCCPU() { |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 87 | host_basic_info_data_t hostInfo; |
| 88 | mach_msg_type_number_t infoCount; |
| 89 | |
| 90 | infoCount = HOST_BASIC_INFO_COUNT; |
| 91 | host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, |
| 92 | &infoCount); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 93 | |
| 94 | if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic"; |
| 95 | |
| 96 | switch(hostInfo.cpu_subtype) { |
| 97 | case CPU_SUBTYPE_POWERPC_601: return "601"; |
| 98 | case CPU_SUBTYPE_POWERPC_602: return "602"; |
| 99 | case CPU_SUBTYPE_POWERPC_603: return "603"; |
| 100 | case CPU_SUBTYPE_POWERPC_603e: return "603e"; |
| 101 | case CPU_SUBTYPE_POWERPC_603ev: return "603ev"; |
| 102 | case CPU_SUBTYPE_POWERPC_604: return "604"; |
| 103 | case CPU_SUBTYPE_POWERPC_604e: return "604e"; |
| 104 | case CPU_SUBTYPE_POWERPC_620: return "620"; |
| 105 | case CPU_SUBTYPE_POWERPC_750: return "750"; |
| 106 | case CPU_SUBTYPE_POWERPC_7400: return "7400"; |
| 107 | case CPU_SUBTYPE_POWERPC_7450: return "7450"; |
| 108 | case CPU_SUBTYPE_POWERPC_970: return "970"; |
| 109 | default: ; |
| 110 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 111 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 112 | return "generic"; |
| 113 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 114 | #endif |
| 115 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 116 | PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 117 | : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) { |
| 118 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 119 | // Determine default and user specified characteristics |
| 120 | std::string CPU; |
| 121 | #if defined(__APPLE__) |
| 122 | CPU = GetCurrentPowerPCCPU(); |
| 123 | #endif |
| 124 | uint32_t Bits = |
| 125 | SubtargetFeatures::Parse(FS, CPU, |
| 126 | PowerPCSubTypeKV, PowerPCSubTypeKVSize, |
| 127 | PowerPCFeatureKV, PowerPCFeatureKVSize); |
Chris Lattner | 1e9de3e | 2005-09-02 18:33:05 +0000 | [diff] [blame] | 128 | IsGigaProcessor = (Bits & PowerPCFeatureGPUL ) != 0; |
| 129 | HasFSQRT = (Bits & PowerPCFeatureFSqrt) != 0; |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 130 | |
| 131 | // Set the boolean corresponding to the current target triple, or the default |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 132 | // if one cannot be determined, to true. |
| 133 | const std::string& TT = M.getTargetTriple(); |
| 134 | if (TT.length() > 5) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 135 | IsDarwin = TT.find("darwin") != std::string::npos; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 136 | } else if (TT.empty()) { |
| 137 | #if defined(_POWER) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 138 | IsAIX = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 139 | #elif defined(__APPLE__) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 140 | IsDarwin = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 141 | #endif |
| 142 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 143 | } |