1 //===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements the X86 specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #include "X86Subtarget.h"
15 #include "llvm/Module.h"
16 #include "X86GenSubtarget.inc"
20 #include "llvm/Support/CommandLine.h"
22 cl::opt<bool> EnableSSE("enable-x86-sse", cl::Hidden,
23 cl::desc("Enable sse on X86"));
26 /// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
27 /// specified arguments. If we can't run cpuid on the host, return true.
28 static bool GetCpuIDAndInfo(unsigned value, unsigned *EAX, unsigned *EBX,
29 unsigned *ECX, unsigned *EDX) {
30 #if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
32 asm ("pushl\t%%ebx\n\t"
34 "movl\t%%ebx, %%esi\n\t"
47 static const char *GetCurrentX86CPU() {
48 unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
49 if (GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
51 unsigned Family = (EAX & (0xffffffff >> (32 - 4)) << 8) >> 8; // Bits 8 - 11
52 unsigned Model = (EAX & (0xffffffff >> (32 - 4)) << 4) >> 4; // Bits 4 - 7
53 GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
54 bool Em64T = EDX & (1 << 29);
63 case 4: return "pentium-mmx";
64 default: return "pentium";
68 case 1: return "pentiumpro";
71 case 6: return "pentium2";
75 case 11: return "pentium3";
77 case 13: return "pentium-m";
78 case 14: return "yonah";
79 default: return "i686";
85 return (Em64T) ? "nocona" : "prescott";
87 return (Em64T) ? "x86-64" : "pentium4";
96 X86Subtarget::X86Subtarget(const Module &M, const std::string &FS) {
98 indirectExternAndWeakGlobals = false;
99 X86SSELevel = NoMMXSSE;
100 X863DNowLevel = NoThreeDNow;
103 // Determine default and user specified characteristics
104 std::string CPU = GetCurrentX86CPU();
106 // Parse features string.
107 ParseSubtargetFeatures(FS, CPU);
109 // Default to ELF unless otherwise specified.
112 // FIXME: Force these off until they work. An llc-beta option should turn
115 X86SSELevel = NoMMXSSE;
116 X863DNowLevel = NoThreeDNow;
119 // Set the boolean corresponding to the current target triple, or the default
120 // if one cannot be determined, to true.
121 const std::string& TT = M.getTargetTriple();
122 if (TT.length() > 5) {
123 if (TT.find("cygwin") != std::string::npos ||
124 TT.find("mingw") != std::string::npos)
125 TargetType = isCygwin;
126 else if (TT.find("darwin") != std::string::npos)
127 TargetType = isDarwin;
128 else if (TT.find("win32") != std::string::npos)
129 TargetType = isWindows;
130 } else if (TT.empty()) {
131 #if defined(__CYGWIN__) || defined(__MINGW32__)
132 TargetType = isCygwin;
133 #elif defined(__APPLE__)
134 TargetType = isDarwin;
135 #elif defined(_WIN32)
136 TargetType = isWindows;
140 if (TargetType == isDarwin) {
142 indirectExternAndWeakGlobals = true;