Actually, use GNU inline asm for cpuid with clang
authorReid Kleckner <reid@kleckner.net>
Fri, 16 Aug 2013 22:42:42 +0000 (22:42 +0000)
committerReid Kleckner <reid@kleckner.net>
Fri, 16 Aug 2013 22:42:42 +0000 (22:42 +0000)
Clang doesn't support the MSVC __cpuid intrinsic yet, and fixing that is
blocked on some fairly complicated issues.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188584 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Host.cpp

index 9360cb979f7a7663a2a0745c2ade046852382bf3..ad0ac93b6bd3e8f23f8ed44804fba824a691da68 100644 (file)
@@ -54,16 +54,7 @@ using namespace llvm;
 /// specified arguments.  If we can't run cpuid on the host, return true.
 static bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
                                unsigned *rECX, unsigned *rEDX) {
-#if defined(_MSC_VER)
-  // The MSVC intrinsic is portable across x86 and x64.
-  int registers[4];
-  __cpuid(registers, value);
-  *rEAX = registers[0];
-  *rEBX = registers[1];
-  *rECX = registers[2];
-  *rEDX = registers[3];
-  return false;
-#elif defined(__GNUC__)
+#if defined(__GNUC__) || defined(__clang__)
   #if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64)
     // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
     asm ("movq\t%%rbx, %%rsi\n\t"
@@ -90,6 +81,15 @@ static bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
   #else
     return true;
   #endif
+#elif defined(_MSC_VER)
+  // The MSVC intrinsic is portable across x86 and x64.
+  int registers[4];
+  __cpuid(registers, value);
+  *rEAX = registers[0];
+  *rEBX = registers[1];
+  *rECX = registers[2];
+  *rEDX = registers[3];
+  return false;
 #else
   return true;
 #endif