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"
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)
23 asm ("pushl\t%%ebx\n\t"
27 #if !defined(__DYNAMIC__) // This works around a gcc -fPIC bug
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);
52 case 4: return "pentium-mmx";
53 default: return "pentium";
58 case 1: return "pentiumpro";
61 case 6: return "pentium2";
65 case 11: return "pentium3";
67 case 13: return "pentium-m";
68 case 14: return "yonah";
69 default: return "i686";
75 return (Em64T) ? "nocona" : "prescott";
77 return (Em64T) ? "x86-64" : "pentium4";
86 X86Subtarget::X86Subtarget(const Module &M, const std::string &FS)
87 : stackAlignment(8), indirectExternAndWeakGlobals(false) {
89 // Determine default and user specified characteristics
90 std::string CPU = GetCurrentX86CPU();
92 // Parse features string.
93 ParseSubtargetFeatures(FS, CPU);
95 // Default to ELF unless otherwise specified.
98 // FIXME: Force these off until they work. An llc-beta option should turn
100 X86SSELevel = NoMMXSSE;
101 X863DNowLevel = NoThreeDNow;
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) {
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;
114 } else if (TT.empty()) {
115 #if defined(__CYGWIN__) || defined(__MINGW32__)
116 TargetType = isCygwin;
117 #elif defined(__APPLE__)
118 TargetType = isDarwin;
119 #elif defined(_WIN32)
120 TargetType = isWindows;
124 if (TargetType == isDarwin) {
126 indirectExternAndWeakGlobals = true;