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" |
Jim Laskey | f5fc2cb | 2005-10-21 19:05:19 +0000 | [diff] [blame] | 17 | #include "PPCGenSubtarget.inc" |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 18 | using namespace llvm; |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 19 | |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 20 | #if defined(__APPLE__) |
| 21 | #include <mach/mach.h> |
| 22 | #include <mach/mach_host.h> |
| 23 | #include <mach/host_info.h> |
| 24 | #include <mach/machine.h> |
| 25 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 26 | /// GetCurrentPowerPCFeatures - Returns the current CPUs features. |
| 27 | static const char *GetCurrentPowerPCCPU() { |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 28 | host_basic_info_data_t hostInfo; |
| 29 | mach_msg_type_number_t infoCount; |
| 30 | |
| 31 | infoCount = HOST_BASIC_INFO_COUNT; |
| 32 | host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, |
| 33 | &infoCount); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 34 | |
| 35 | if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic"; |
| 36 | |
| 37 | switch(hostInfo.cpu_subtype) { |
| 38 | case CPU_SUBTYPE_POWERPC_601: return "601"; |
| 39 | case CPU_SUBTYPE_POWERPC_602: return "602"; |
| 40 | case CPU_SUBTYPE_POWERPC_603: return "603"; |
| 41 | case CPU_SUBTYPE_POWERPC_603e: return "603e"; |
| 42 | case CPU_SUBTYPE_POWERPC_603ev: return "603ev"; |
| 43 | case CPU_SUBTYPE_POWERPC_604: return "604"; |
| 44 | case CPU_SUBTYPE_POWERPC_604e: return "604e"; |
| 45 | case CPU_SUBTYPE_POWERPC_620: return "620"; |
| 46 | case CPU_SUBTYPE_POWERPC_750: return "750"; |
| 47 | case CPU_SUBTYPE_POWERPC_7400: return "7400"; |
| 48 | case CPU_SUBTYPE_POWERPC_7450: return "7450"; |
| 49 | case CPU_SUBTYPE_POWERPC_970: return "970"; |
| 50 | default: ; |
| 51 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 52 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 53 | return "generic"; |
| 54 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 57 | |
Chris Lattner | 94de9a8 | 2006-06-16 01:37:27 +0000 | [diff] [blame] | 58 | PPCSubtarget::PPCSubtarget(const Module &M, const std::string &FS, bool is64Bit) |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 59 | : StackAlignment(16) |
Jim Laskey | 6cee630 | 2005-11-01 20:06:59 +0000 | [diff] [blame] | 60 | , InstrItins() |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 61 | , IsGigaProcessor(false) |
Chris Lattner | a7a5854 | 2006-06-16 17:34:12 +0000 | [diff] [blame] | 62 | , Has64BitSupport(false) |
| 63 | , Use64BitRegs(false) |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 64 | , IsPPC64(is64Bit) |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 65 | , HasAltivec(false) |
| 66 | , HasFSQRT(false) |
Chris Lattner | 5126984 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 67 | , HasSTFIWX(false) |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 68 | , IsDarwin(false) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 69 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 70 | // Determine default and user specified characteristics |
Chris Lattner | c98d823 | 2005-09-07 05:45:33 +0000 | [diff] [blame] | 71 | std::string CPU = "generic"; |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 72 | #if defined(__APPLE__) |
| 73 | CPU = GetCurrentPowerPCCPU(); |
| 74 | #endif |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 75 | |
| 76 | // Parse features string. |
| 77 | ParseSubtargetFeatures(FS, CPU); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 78 | |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 79 | // If we are generating code for ppc64, verify that options make sense. |
| 80 | if (is64Bit) { |
| 81 | if (!has64BitSupport()) { |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame^] | 82 | cerr << "PPC: Generation of 64-bit code for a 32-bit processor " |
| 83 | << "requested. Ignoring 32-bit processor feature.\n"; |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 84 | Has64BitSupport = true; |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 85 | } |
Chris Lattner | 8fa05da | 2006-06-16 20:05:06 +0000 | [diff] [blame] | 86 | // Silently force 64-bit register use on ppc64. |
| 87 | Use64BitRegs = true; |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | // If the user requested use of 64-bit regs, but the cpu selected doesn't |
| 91 | // support it, warn and ignore. |
| 92 | if (use64BitRegs() && !has64BitSupport()) { |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame^] | 93 | cerr << "PPC: 64-bit registers requested on CPU without support. " |
| 94 | << "Disabling 64-bit register use.\n"; |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 95 | Use64BitRegs = false; |
| 96 | } |
| 97 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 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 | af89fa6 | 2006-06-16 18:50:48 +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()) { |
Chris Lattner | ba4733d | 2006-07-15 01:24:23 +0000 | [diff] [blame] | 104 | #if defined(__APPLE__) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 105 | IsDarwin = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 106 | #endif |
| 107 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 108 | } |