Nate Begeman | 8c00f8c | 2005-08-04 07:12:09 +0000 | [diff] [blame] | 1 | //===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===// |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +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 X86 specific subclass of TargetSubtarget. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "X86Subtarget.h" |
| 15 | #include "llvm/Module.h" |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame^] | 16 | #include "X86GenSubtarget.inc" |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 17 | using namespace llvm; |
| 18 | |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame^] | 19 | #if defined(__APPLE__) |
| 20 | #include <mach/mach.h> |
| 21 | #include <mach/mach_host.h> |
| 22 | #include <mach/host_info.h> |
| 23 | #include <mach/machine.h> |
| 24 | |
| 25 | /// GetCurrentX86CPU - Returns the current CPUs features. |
| 26 | static const char *GetCurrentX86CPU() { |
| 27 | host_basic_info_data_t hostInfo; |
| 28 | mach_msg_type_number_t infoCount; |
| 29 | |
| 30 | infoCount = HOST_BASIC_INFO_COUNT; |
| 31 | host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, |
| 32 | &infoCount); |
| 33 | |
| 34 | if (hostInfo.cpu_type != CPU_TYPE_I386) return "generic"; |
| 35 | |
| 36 | switch(hostInfo.cpu_subtype) { |
| 37 | case CPU_SUBTYPE_386: return "i386"; |
| 38 | case CPU_SUBTYPE_486: |
| 39 | case CPU_SUBTYPE_486SX: return "i486"; |
| 40 | case CPU_SUBTYPE_PENT: return "pentium"; |
| 41 | case CPU_SUBTYPE_PENTPRO: return "pentiumpro"; |
| 42 | case CPU_SUBTYPE_PENTII_M3: return "pentium2"; |
| 43 | case CPU_SUBTYPE_PENTII_M5: return "pentium2"; |
| 44 | case CPU_SUBTYPE_CELERON: |
| 45 | case CPU_SUBTYPE_CELERON_MOBILE: return "celeron"; |
| 46 | case CPU_SUBTYPE_PENTIUM_3: return "pentium3"; |
| 47 | case CPU_SUBTYPE_PENTIUM_3_M: return "pentium3m"; |
| 48 | case CPU_SUBTYPE_PENTIUM_3_XEON: return "pentium3"; // FIXME: not sure. |
| 49 | case CPU_SUBTYPE_PENTIUM_M: return "pentium-m"; |
| 50 | case CPU_SUBTYPE_PENTIUM_4: return "pentium4"; |
| 51 | case CPU_SUBTYPE_PENTIUM_4_M: return "pentium4m"; |
| 52 | // FIXME: prescott, yonah? Check CPU_THREADTYPE_INTEL_HTT? |
| 53 | case CPU_SUBTYPE_XEON: |
| 54 | case CPU_SUBTYPE_XEON_MP: return "nocona"; |
| 55 | default: ; |
| 56 | } |
| 57 | |
| 58 | return "generic"; |
| 59 | } |
| 60 | #endif |
| 61 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 62 | X86Subtarget::X86Subtarget(const Module &M, const std::string &FS) |
Chris Lattner | d460f57 | 2005-11-21 22:43:58 +0000 | [diff] [blame] | 63 | : stackAlignment(8), indirectExternAndWeakGlobals(false) { |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 64 | |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame^] | 65 | // Determine default and user specified characteristics |
| 66 | std::string CPU = "generic"; |
| 67 | #if defined(__APPLE__) |
| 68 | CPU = GetCurrentX86CPU(); |
| 69 | #endif |
| 70 | |
| 71 | // Parse features string. |
| 72 | ParseSubtargetFeatures(FS, CPU); |
| 73 | |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 74 | // Default to ELF unless otherwise specified. |
| 75 | TargetType = isELF; |
| 76 | |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 77 | // Set the boolean corresponding to the current target triple, or the default |
| 78 | // if one cannot be determined, to true. |
| 79 | const std::string& TT = M.getTargetTriple(); |
| 80 | if (TT.length() > 5) { |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 81 | if (TT.find("cygwin") != std::string::npos || |
| 82 | TT.find("mingw") != std::string::npos) |
| 83 | TargetType = isCygwin; |
| 84 | else if (TT.find("darwin") != std::string::npos) |
| 85 | TargetType = isDarwin; |
| 86 | else if (TT.find("win32") != std::string::npos) |
| 87 | TargetType = isWindows; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 88 | } else if (TT.empty()) { |
| 89 | #if defined(__CYGWIN__) || defined(__MINGW32__) |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 90 | TargetType = isCygwin; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 91 | #elif defined(__APPLE__) |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 92 | TargetType = isDarwin; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 93 | #elif defined(_WIN32) |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 94 | TargetType = isWindows; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 95 | #endif |
| 96 | } |
| 97 | |
Chris Lattner | d460f57 | 2005-11-21 22:43:58 +0000 | [diff] [blame] | 98 | if (TargetType == isDarwin) { |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 99 | stackAlignment = 16; |
| 100 | indirectExternAndWeakGlobals = true; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 101 | } |
| 102 | } |