make this work on non-native hosts
[oota-llvm.git] / lib / Target / X86 / X86Subtarget.cpp
index faa090718b9ae305588d664d9d1a0ee6973d7b27..3553c60cada7c8af35a06527f67453a059043128 100644 (file)
 #include "X86GenSubtarget.inc"
 using namespace llvm;
 
-static void GetCpuIDAndInfo(unsigned value, unsigned *EAX, unsigned *EBX,
+// FIXME: temporary.
+#include "llvm/Support/CommandLine.h"
+namespace {
+  cl::opt<bool> EnableSSE("enable-x86-sse", cl::Hidden,
+                          cl::desc("Enable sse on X86"));
+}
+
+/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
+/// specified arguments.  If we can't run cpuid on the host, return true.
+static bool GetCpuIDAndInfo(unsigned value, unsigned *EAX, unsigned *EBX,
                             unsigned *ECX, unsigned *EDX) {
 #if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
 #if defined(__GNUC__)
@@ -29,13 +38,16 @@ static void GetCpuIDAndInfo(unsigned value, unsigned *EAX, unsigned *EBX,
          "=c" (*ECX),
          "=d" (*EDX)
        :  "a" (value));
+  return false;
 #endif
 #endif
+  return true;
 }
 
 static const char *GetCurrentX86CPU() {
   unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
-  GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX);
+  if (GetCpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
+    return "generic";
   unsigned Family  = (EAX & (0xffffffff >> (32 - 4)) << 8) >> 8; // Bits 8 - 11
   unsigned Model   = (EAX & (0xffffffff >> (32 - 4)) << 4) >> 4; // Bits 4 - 7
   GetCpuIDAndInfo(0x80000001, &EAX, &EBX, &ECX, &EDX);
@@ -51,7 +63,6 @@ static const char *GetCurrentX86CPU() {
       case 4:  return "pentium-mmx";
       default: return "pentium";
       }
-      break;
     case 6:
       switch (Model) {
       case 1:  return "pentiumpro";
@@ -82,9 +93,13 @@ static const char *GetCurrentX86CPU() {
   }
 }
 
-X86Subtarget::X86Subtarget(const Module &M, const std::string &FS)
-  : stackAlignment(8), indirectExternAndWeakGlobals(false) {
-      
+X86Subtarget::X86Subtarget(const Module &M, const std::string &FS) {
+  stackAlignment = 8;
+  indirectExternAndWeakGlobals = false;
+  X86SSELevel = NoMMXSSE;
+  X863DNowLevel = NoThreeDNow;
+  Is64Bit = false;
+
   // Determine default and user specified characteristics
   std::string CPU = GetCurrentX86CPU();
 
@@ -96,8 +111,10 @@ X86Subtarget::X86Subtarget(const Module &M, const std::string &FS)
   
   // FIXME: Force these off until they work.  An llc-beta option should turn
   // them back on.
-  X86SSELevel = NoMMXSSE;
-  X863DNowLevel = NoThreeDNow;
+  if (!EnableSSE) {
+    X86SSELevel = NoMMXSSE;
+    X863DNowLevel = NoThreeDNow;
+  }
       
   // Set the boolean corresponding to the current target triple, or the default
   // if one cannot be determined, to true.