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