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 | 57fc62c | 2006-12-11 23:22:45 +0000 | [diff] [blame^] | 17 | #include "llvm/Target/TargetMachine.h" |
Jim Laskey | f5fc2cb | 2005-10-21 19:05:19 +0000 | [diff] [blame] | 18 | #include "PPCGenSubtarget.inc" |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 19 | using namespace llvm; |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 20 | |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 21 | #if defined(__APPLE__) |
| 22 | #include <mach/mach.h> |
| 23 | #include <mach/mach_host.h> |
| 24 | #include <mach/host_info.h> |
| 25 | #include <mach/machine.h> |
| 26 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 27 | /// GetCurrentPowerPCFeatures - Returns the current CPUs features. |
| 28 | static const char *GetCurrentPowerPCCPU() { |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 29 | host_basic_info_data_t hostInfo; |
| 30 | mach_msg_type_number_t infoCount; |
| 31 | |
| 32 | infoCount = HOST_BASIC_INFO_COUNT; |
| 33 | host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, |
| 34 | &infoCount); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 35 | |
| 36 | if (hostInfo.cpu_type != CPU_TYPE_POWERPC) return "generic"; |
| 37 | |
| 38 | switch(hostInfo.cpu_subtype) { |
| 39 | case CPU_SUBTYPE_POWERPC_601: return "601"; |
| 40 | case CPU_SUBTYPE_POWERPC_602: return "602"; |
| 41 | case CPU_SUBTYPE_POWERPC_603: return "603"; |
| 42 | case CPU_SUBTYPE_POWERPC_603e: return "603e"; |
| 43 | case CPU_SUBTYPE_POWERPC_603ev: return "603ev"; |
| 44 | case CPU_SUBTYPE_POWERPC_604: return "604"; |
| 45 | case CPU_SUBTYPE_POWERPC_604e: return "604e"; |
| 46 | case CPU_SUBTYPE_POWERPC_620: return "620"; |
| 47 | case CPU_SUBTYPE_POWERPC_750: return "750"; |
| 48 | case CPU_SUBTYPE_POWERPC_7400: return "7400"; |
| 49 | case CPU_SUBTYPE_POWERPC_7450: return "7450"; |
| 50 | case CPU_SUBTYPE_POWERPC_970: return "970"; |
| 51 | default: ; |
| 52 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 53 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 54 | return "generic"; |
| 55 | } |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 56 | #endif |
| 57 | |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 58 | |
Chris Lattner | 57fc62c | 2006-12-11 23:22:45 +0000 | [diff] [blame^] | 59 | PPCSubtarget::PPCSubtarget(const TargetMachine &tm, const Module &M, |
| 60 | const std::string &FS, bool is64Bit) |
| 61 | : TM(tm) |
| 62 | , StackAlignment(16) |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 63 | , IsGigaProcessor(false) |
Chris Lattner | a7a5854 | 2006-06-16 17:34:12 +0000 | [diff] [blame] | 64 | , Has64BitSupport(false) |
| 65 | , Use64BitRegs(false) |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 66 | , IsPPC64(is64Bit) |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 67 | , HasAltivec(false) |
| 68 | , HasFSQRT(false) |
Chris Lattner | 5126984 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 69 | , HasSTFIWX(false) |
Chris Lattner | 57fc62c | 2006-12-11 23:22:45 +0000 | [diff] [blame^] | 70 | , IsDarwin(false) |
| 71 | , HasLazyResolverStubs(false) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 72 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 73 | // Determine default and user specified characteristics |
Chris Lattner | c98d823 | 2005-09-07 05:45:33 +0000 | [diff] [blame] | 74 | std::string CPU = "generic"; |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 75 | #if defined(__APPLE__) |
| 76 | CPU = GetCurrentPowerPCCPU(); |
| 77 | #endif |
Jim Laskey | 581a8f7 | 2005-10-26 17:30:34 +0000 | [diff] [blame] | 78 | |
| 79 | // Parse features string. |
| 80 | ParseSubtargetFeatures(FS, CPU); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 81 | |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 82 | // If we are generating code for ppc64, verify that options make sense. |
| 83 | if (is64Bit) { |
| 84 | if (!has64BitSupport()) { |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 85 | cerr << "PPC: Generation of 64-bit code for a 32-bit processor " |
| 86 | << "requested. Ignoring 32-bit processor feature.\n"; |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 87 | Has64BitSupport = true; |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 88 | } |
Chris Lattner | 8fa05da | 2006-06-16 20:05:06 +0000 | [diff] [blame] | 89 | // Silently force 64-bit register use on ppc64. |
| 90 | Use64BitRegs = true; |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | // If the user requested use of 64-bit regs, but the cpu selected doesn't |
| 94 | // support it, warn and ignore. |
| 95 | if (use64BitRegs() && !has64BitSupport()) { |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 96 | cerr << "PPC: 64-bit registers requested on CPU without support. " |
| 97 | << "Disabling 64-bit register use.\n"; |
Chris Lattner | 7c1fb5f | 2006-06-16 17:50:12 +0000 | [diff] [blame] | 98 | Use64BitRegs = false; |
| 99 | } |
| 100 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 101 | // Set the boolean corresponding to the current target triple, or the default |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 102 | // if one cannot be determined, to true. |
| 103 | const std::string& TT = M.getTargetTriple(); |
| 104 | if (TT.length() > 5) { |
Chris Lattner | af89fa6 | 2006-06-16 18:50:48 +0000 | [diff] [blame] | 105 | IsDarwin = TT.find("-darwin") != std::string::npos; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 106 | } else if (TT.empty()) { |
Chris Lattner | ba4733d | 2006-07-15 01:24:23 +0000 | [diff] [blame] | 107 | #if defined(__APPLE__) |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 108 | IsDarwin = true; |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 109 | #endif |
| 110 | } |
Chris Lattner | 57fc62c | 2006-12-11 23:22:45 +0000 | [diff] [blame^] | 111 | |
| 112 | // Set up darwin-specific properties. |
| 113 | if (IsDarwin) { |
| 114 | HasLazyResolverStubs = true; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /// SetJITMode - This is called to inform the subtarget info that we are |
| 119 | /// producing code for the JIT. |
| 120 | void PPCSubtarget::SetJITMode() { |
| 121 | // JIT mode doesn't want lazy resolver stubs, it knows exactly where |
| 122 | // everything is. This matters for PPC64, which codegens in PIC mode without |
| 123 | // stubs. |
| 124 | HasLazyResolverStubs = false; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /// hasLazyResolverStub - Return true if accesses to the specified global have |
| 129 | /// to go through a dyld lazy resolution stub. This means that an extra load |
| 130 | /// is required to get the address of the global. |
| 131 | bool PPCSubtarget::hasLazyResolverStub(const GlobalValue *GV) const { |
| 132 | // We never hae stubs if HasLazyResolverStubs=false or if in static mode. |
| 133 | if (!HasLazyResolverStubs || TM.getRelocationModel() == Reloc::Static) |
| 134 | return false; |
| 135 | |
| 136 | return GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || |
| 137 | (GV->isExternal() && !GV->hasNotBeenReadFromBytecode()); |
Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 138 | } |