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 | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 19 | static void GetCpuIDAndInfo(unsigned value, unsigned *EAX, unsigned *EBX, |
| 20 | unsigned *ECX, unsigned *EDX) { |
| 21 | #if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86) |
| 22 | #if defined(__GNUC__) |
| 23 | asm ("pushl\t%%ebx\n\t" |
| 24 | "cpuid\n\t" |
| 25 | "popl\t%%ebx" |
| 26 | : "=a" (*EAX), |
| 27 | #if !defined(__DYNAMIC__) // This works around a gcc -fPIC bug |
| 28 | "=b" (*EBX), |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame] | 29 | #endif |
Evan Cheng | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 30 | "=c" (*ECX), |
| 31 | "=d" (*EDX) |
| 32 | : "a" (value)); |
| 33 | #endif |
| 34 | #endif |
| 35 | } |
| 36 | |
| 37 | static const char *GetCurrentX86CPU() { |
| 38 | unsigned EAX = 0, DUMMY = 0, ECX = 0, EDX = 0; |
| 39 | GetCpuIDAndInfo(0x1, &EAX, &DUMMY, &ECX, &EDX); |
| 40 | unsigned Family = (EAX & (0xffffffff >> (32 - 4)) << 8) >> 8; // Bits 8 - 11 |
| 41 | unsigned Model = (EAX & (0xffffffff >> (32 - 4)) << 4) >> 4; // Bits 4 - 7 |
| 42 | GetCpuIDAndInfo(0x80000001, &EAX, &DUMMY, &ECX, &EDX); |
| 43 | bool Em64T = EDX & (1 << 29); |
| 44 | |
| 45 | switch (Family) { |
| 46 | case 3: |
| 47 | return "i386"; |
| 48 | case 4: |
| 49 | return "i486"; |
| 50 | case 5: |
| 51 | switch (Model) { |
| 52 | case 4: return "pentium-mmx"; |
| 53 | default: return "pentium"; |
| 54 | } |
| 55 | break; |
| 56 | case 6: |
| 57 | switch (Model) { |
| 58 | case 1: return "pentiumpro"; |
| 59 | case 3: |
| 60 | case 5: |
| 61 | case 6: return "pentium2"; |
| 62 | case 7: |
| 63 | case 8: |
| 64 | case 10: |
| 65 | case 11: return "pentium3"; |
| 66 | case 9: |
| 67 | case 13: return "pentium-m"; |
| 68 | case 14: return "yonah"; |
| 69 | default: return "i686"; |
| 70 | } |
| 71 | case 15: { |
| 72 | switch (Model) { |
| 73 | case 3: |
| 74 | case 4: |
| 75 | return (Em64T) ? "nocona" : "prescott"; |
| 76 | default: |
| 77 | return (Em64T) ? "x86-64" : "pentium4"; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | default: |
| 82 | return "generic"; |
| 83 | } |
| 84 | } |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame] | 85 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 86 | X86Subtarget::X86Subtarget(const Module &M, const std::string &FS) |
Chris Lattner | d460f57 | 2005-11-21 22:43:58 +0000 | [diff] [blame] | 87 | : stackAlignment(8), indirectExternAndWeakGlobals(false) { |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 88 | |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame] | 89 | // Determine default and user specified characteristics |
Evan Cheng | 559806f | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 90 | std::string CPU = GetCurrentX86CPU(); |
Evan Cheng | 97c7fc3 | 2006-01-26 09:53:06 +0000 | [diff] [blame] | 91 | |
| 92 | // Parse features string. |
| 93 | ParseSubtargetFeatures(FS, CPU); |
| 94 | |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 95 | // Default to ELF unless otherwise specified. |
| 96 | TargetType = isELF; |
Chris Lattner | 9f96a32 | 2006-01-27 18:30:50 +0000 | [diff] [blame^] | 97 | |
| 98 | // FIXME: Force these off until they work. An llc-beta option should turn |
| 99 | // them back on. |
| 100 | X86SSELevel = NoMMXSSE; |
| 101 | X863DNowLevel = NoThreeDNow; |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 102 | |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 103 | // Set the boolean corresponding to the current target triple, or the default |
| 104 | // if one cannot be determined, to true. |
| 105 | const std::string& TT = M.getTargetTriple(); |
| 106 | if (TT.length() > 5) { |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 107 | if (TT.find("cygwin") != std::string::npos || |
| 108 | TT.find("mingw") != std::string::npos) |
| 109 | TargetType = isCygwin; |
| 110 | else if (TT.find("darwin") != std::string::npos) |
| 111 | TargetType = isDarwin; |
| 112 | else if (TT.find("win32") != std::string::npos) |
| 113 | TargetType = isWindows; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 114 | } else if (TT.empty()) { |
| 115 | #if defined(__CYGWIN__) || defined(__MINGW32__) |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 116 | TargetType = isCygwin; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 117 | #elif defined(__APPLE__) |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 118 | TargetType = isDarwin; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 119 | #elif defined(_WIN32) |
Chris Lattner | e5600e5 | 2005-11-21 22:31:58 +0000 | [diff] [blame] | 120 | TargetType = isWindows; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 121 | #endif |
| 122 | } |
| 123 | |
Chris Lattner | d460f57 | 2005-11-21 22:43:58 +0000 | [diff] [blame] | 124 | if (TargetType == isDarwin) { |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 125 | stackAlignment = 16; |
| 126 | indirectExternAndWeakGlobals = true; |
Nate Begeman | fb5792f | 2005-07-12 01:41:54 +0000 | [diff] [blame] | 127 | } |
| 128 | } |