]> granicus.if.org Git - clang/commitdiff
Revert "[X86] Make _xgetbv/_xsetbv on non-windows platforms"
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 15 Jan 2019 17:23:36 +0000 (17:23 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 15 Jan 2019 17:23:36 +0000 (17:23 +0000)
This reverts commit r351160. Breaks building v8.

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

include/clang/Basic/BuiltinsX86.def
lib/CodeGen/CGBuiltin.cpp
lib/Headers/immintrin.h
lib/Headers/intrin.h
lib/Headers/xsaveintrin.h
test/CodeGen/builtins-x86.c
test/CodeGen/x86_32-xsave.c
test/CodeGen/x86_64-xsave.c
test/Headers/ms-intrin.cpp

index e67e700314ead3dd845fc02918d7a761915be942..4ee2a705da5ecba31f4dacbc9b62bac2c07c8a36 100644 (file)
@@ -693,10 +693,6 @@ TARGET_BUILTIN(__builtin_ia32_fxsave, "vv*", "n", "fxsr")
 // XSAVE
 TARGET_BUILTIN(__builtin_ia32_xsave, "vv*ULLi", "n", "xsave")
 TARGET_BUILTIN(__builtin_ia32_xrstor, "vv*ULLi", "n", "xsave")
-TARGET_BUILTIN(__builtin_ia32_xgetbv, "ULLiUi", "n", "xsave")
-TARGET_HEADER_BUILTIN(_xgetbv, "UWiUi", "nh", "immintrin.h", ALL_MS_LANGUAGES, "")
-TARGET_BUILTIN(__builtin_ia32_xsetbv, "vUiULLi", "n", "xsave")
-TARGET_HEADER_BUILTIN(_xsetbv, "vUiUWi", "nh", "immintrin.h", ALL_MS_LANGUAGES, "")
 TARGET_BUILTIN(__builtin_ia32_xsaveopt, "vv*ULLi", "n", "xsaveopt")
 TARGET_BUILTIN(__builtin_ia32_xrstors, "vv*ULLi", "n", "xsaves")
 TARGET_BUILTIN(__builtin_ia32_xsavec, "vv*ULLi", "n", "xsavec")
index 32c27edfd0a042fc5c6f77408be8c6db0c0d270a..a718f2f19aa65c728283a5f0d28fec68f7e775b2 100644 (file)
@@ -9833,9 +9833,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
   case X86::BI__builtin_ia32_xsavec:
   case X86::BI__builtin_ia32_xsavec64:
   case X86::BI__builtin_ia32_xsaves:
-  case X86::BI__builtin_ia32_xsaves64:
-  case X86::BI__builtin_ia32_xsetbv:
-  case X86::BI_xsetbv: {
+  case X86::BI__builtin_ia32_xsaves64: {
     Intrinsic::ID ID;
 #define INTRINSIC_X86_XSAVE_ID(NAME) \
     case X86::BI__builtin_ia32_##NAME: \
@@ -9855,10 +9853,6 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
     INTRINSIC_X86_XSAVE_ID(xsavec64);
     INTRINSIC_X86_XSAVE_ID(xsaves);
     INTRINSIC_X86_XSAVE_ID(xsaves64);
-    INTRINSIC_X86_XSAVE_ID(xsetbv);
-    case X86::BI_xsetbv:
-      ID = Intrinsic::x86_xsetbv;
-      break;
     }
 #undef INTRINSIC_X86_XSAVE_ID
     Value *Mhi = Builder.CreateTrunc(
@@ -9868,9 +9862,6 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
     Ops.push_back(Mlo);
     return Builder.CreateCall(CGM.getIntrinsic(ID), Ops);
   }
-  case X86::BI__builtin_ia32_xgetbv:
-  case X86::BI_xgetbv:
-    return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_xgetbv), Ops);
   case X86::BI__builtin_ia32_storedqudi128_mask:
   case X86::BI__builtin_ia32_storedqusi128_mask:
   case X86::BI__builtin_ia32_storedquhi128_mask:
index 19edd4ac4a49300968d168b0a0c33293c395170f..7d0722ec765283cab889107414d02aaee3efe7e6 100644 (file)
@@ -378,8 +378,9 @@ _storebe_i64(void * __P, long long __D) {
 #include <fxsrintrin.h>
 #endif
 
-/* No feature check desired due to internal MSC_VER checks */
+#if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVE__)
 #include <xsaveintrin.h>
+#endif
 
 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__XSAVEOPT__)
 #include <xsaveoptintrin.h>
index acc08abaf0345deaea9850df3c1e4fc0507bb069..c86f41faeb88a93a49501fae3cde86273d8adfca 100644 (file)
@@ -200,7 +200,10 @@ __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
 _WriteBarrier(void);
 unsigned __int32 xbegin(void);
 void _xend(void);
+static __inline__
 #define _XCR_XFEATURE_ENABLED_MASK 0
+unsigned __int64 __cdecl _xgetbv(unsigned int);
+void __cdecl _xsetbv(unsigned int, unsigned __int64);
 
 /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
 #ifdef __x86_64__
@@ -536,6 +539,12 @@ __cpuidex(int __info[4], int __level, int __ecx) {
   __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
                    : "a"(__level), "c"(__ecx));
 }
+static __inline__ unsigned __int64 __cdecl __DEFAULT_FN_ATTRS
+_xgetbv(unsigned int __xcr_no) {
+  unsigned int __eax, __edx;
+  __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no));
+  return ((unsigned __int64)__edx << 32) | __eax;
+}
 static __inline__ void __DEFAULT_FN_ATTRS
 __halt(void) {
   __asm__ volatile ("hlt");
index 788f9e000b52279252c90acc41a54a0a59643059..16f3a78d3f5b02daea44b5ee1b738c46d1d1d13d 100644 (file)
 #ifndef __XSAVEINTRIN_H
 #define __XSAVEINTRIN_H
 
-#ifndef _MSC_VER
-#define _XCR_XFEATURE_ENABLED_MASK 0
-#endif
-
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__,  __target__("xsave")))
 
@@ -45,20 +41,6 @@ _xrstor(void *__p, unsigned long long __m) {
   __builtin_ia32_xrstor(__p, __m);
 }
 
-#ifndef _MSC_VER
-#define _xgetbv(A) __builtin_ia32_xgetbv((long long)(A))
-#define _xsetbv(A, B) __builtin_ia32_xsetbv((unsigned int)(A), (unsigned long long)(B));
-#else
-#ifdef __cplusplus
-extern "C" {
-#endif
-unsigned __int64 __cdecl _xgetbv(unsigned int);
-void __cdecl _xsetbv(unsigned int, unsigned __int64);
-#ifdef __cplusplus
-}
-#endif
-#endif /* _MSC_VER */
-
 #ifdef __x86_64__
 static __inline__ void __DEFAULT_FN_ATTRS
 _xsave64(void *__p, unsigned long long __m) {
@@ -69,7 +51,6 @@ static __inline__ void __DEFAULT_FN_ATTRS
 _xrstor64(void *__p, unsigned long long __m) {
   __builtin_ia32_xrstor64(__p, __m);
 }
-
 #endif
 
 #undef __DEFAULT_FN_ATTRS
index e237bc2d12b8a62379bdbb02666a2e593d18bbc7..fd99dd2be31f836e29dfe1dd34df84040412b179 100644 (file)
@@ -281,8 +281,6 @@ void f0() {
 
   (void)__builtin_ia32_xsave(tmp_vp, tmp_ULLi);
   (void)__builtin_ia32_xsave64(tmp_vp, tmp_ULLi);
-  tmp_ULLi = __builtin_ia32_xgetbv(tmp_Ui);
-  (void)__builtin_ia32_xsetbv(tmp_Ui, tmp_ULLi);
   (void)__builtin_ia32_xrstor(tmp_vp, tmp_ULLi);
   (void)__builtin_ia32_xrstor64(tmp_vp, tmp_ULLi);
   (void)__builtin_ia32_xsaveopt(tmp_vp, tmp_ULLi);
index e1acdff12407aa49ba241d222c6f680524554f5d..f5d84e2d920a75b10b8b097b53f514b024f17fad 100644 (file)
@@ -1,9 +1,6 @@
 // RUN: %clang_cc1 %s -DTEST_XSAVE -O0 -triple=i686-unknown-unknown -target-feature +xsave -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVE
 // RUN: %clang_cc1 %s -DTEST_XSAVE -O0 -triple=i686-unknown-unknown -target-feature +xsave -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVE
 
-// RUN: %clang_cc1 %s -DTEST_XGETBV -O0 -triple=i686-unknown-unknown -target-feature +xsave -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XGETBV
-// RUN: %clang_cc1 %s -DTEST_XSETBV -O0 -triple=i686-unknown-unknown -target-feature +xsave -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSETBV
-
 // RUN: %clang_cc1 %s -DTEST_XSAVEOPT -O0 -triple=i686-unknown-unknown -target-feature +xsave -target-feature +xsaveopt -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVEOPT
 // RUN: %clang_cc1 %s -DTEST_XSAVEOPT -O0 -triple=i686-unknown-unknown -target-feature +xsave -target-feature +xsaveopt -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVEOPT
 
 // RUN: %clang_cc1 %s -DTEST_XSAVES -O0 -triple=i686-unknown-unknown -target-feature +xsave -target-feature +xsaves -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVES
 // RUN: %clang_cc1 %s -DTEST_XSAVES -O0 -triple=i686-unknown-unknown -target-feature +xsave -target-feature +xsaves -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVES
 
-// Don't include mm_malloc.h, it's system specific.
-#define __MM_MALLOC_H
-#include <x86intrin.h>
-
 void test() {
-  unsigned long long tmp_ULLi;
-  unsigned int       tmp_Ui;
-  void*              tmp_vp;
-  tmp_ULLi = 0; tmp_Ui = 0; tmp_vp = 0;
+  unsigned long long tmp_ULLi = 0;
+  void*              tmp_vp = 0;
 
 #ifdef TEST_XSAVE
 // XSAVE: [[tmp_vp_1:%[0-9a-zA-Z]+]] = load i8*, i8** %tmp_vp, align 4
@@ -39,12 +30,6 @@ void test() {
 // XSAVE: [[low32_3:%[0-9a-zA-Z]+]] = trunc i64 [[tmp_ULLi_3]] to i32
 // XSAVE: call void @llvm.x86.xrstor(i8* [[tmp_vp_3]], i32 [[high32_3]], i32 [[low32_3]])
   (void)__builtin_ia32_xrstor(tmp_vp, tmp_ULLi);
-  
-// XSAVE: call void @llvm.x86.xsave
-  (void)_xsave(tmp_vp, tmp_ULLi);
-  
-// XSAVE: call void @llvm.x86.xrstor
-  (void)_xrstor(tmp_vp, tmp_ULLi);
 #endif
 
 #ifdef TEST_XSAVEOPT
@@ -55,9 +40,6 @@ void test() {
 // XSAVEOPT: [[low32_1:%[0-9a-zA-Z]+]] = trunc i64 [[tmp_ULLi_1]] to i32
 // XSAVEOPT: call void @llvm.x86.xsaveopt(i8* [[tmp_vp_1]], i32 [[high32_1]], i32 [[low32_1]])
   (void)__builtin_ia32_xsaveopt(tmp_vp, tmp_ULLi);
-  
-// XSAVEOPT: call void @llvm.x86.xsaveopt
-  (void)_xsaveopt(tmp_vp, tmp_ULLi);
 #endif
 
 #ifdef TEST_XSAVEC
@@ -68,9 +50,6 @@ void test() {
 // XSAVEC: [[low32_1:%[0-9a-zA-Z]+]] = trunc i64 [[tmp_ULLi_1]] to i32
 // XSAVEC: call void @llvm.x86.xsavec(i8* [[tmp_vp_1]], i32 [[high32_1]], i32 [[low32_1]])
   (void)__builtin_ia32_xsavec(tmp_vp, tmp_ULLi);
-// XSAVEC: call void @llvm.x86.xsavec 
-  (void)_xsavec(tmp_vp, tmp_ULLi);
 #endif
 
 #ifdef TEST_XSAVES
@@ -89,34 +68,5 @@ void test() {
 // XSAVES: [[low32_3:%[0-9a-zA-Z]+]] = trunc i64 [[tmp_ULLi_3]] to i32
 // XSAVES: call void @llvm.x86.xrstors(i8* [[tmp_vp_3]], i32 [[high32_3]], i32 [[low32_3]])
   (void)__builtin_ia32_xrstors(tmp_vp, tmp_ULLi);
-  
-// XSAVES: call void @llvm.x86.xsaves
-  (void)_xsaves(tmp_vp, tmp_ULLi); 
-
-// XSAVES: call void @llvm.x86.xrstors
-  (void)_xrstors(tmp_vp, tmp_ULLi);
-#endif
-
-#ifdef TEST_XGETBV
-// XGETBV: [[tmp_Ui:%[0-9a-zA-z]+]] = load i32, i32* %tmp_Ui, align 4
-// XGETBV: call i64 @llvm.x86.xgetbv(i32 [[tmp_Ui]])
-  tmp_ULLi = __builtin_ia32_xgetbv(tmp_Ui);
-  
-// XGETBV: call i64 @llvm.x86.xgetbv
-  tmp_ULLi = _xgetbv(tmp_Ui);
-#endif
-
-#ifdef TEST_XSETBV
-// XSETBV: [[tmp_Ui:%[0-9a-zA-z]+]] = load i32, i32* %tmp_Ui, align 4
-// XSETBV: [[tmp_ULLi_3:%[0-9a-zA-z]+]] = load i64, i64* %tmp_ULLi, align 8
-// XSETBV: [[high64_3:%[0-9a-zA-z]+]] = lshr i64 [[tmp_ULLi_3]], 32
-// XSETBV: [[high32_3:%[0-9a-zA-z]+]] = trunc i64 [[high64_3]] to i32
-// XSETBV: [[low32_3:%[0-9a-zA-z]+]] = trunc i64 [[tmp_ULLi_3]] to i32
-// XSETBV: call void @llvm.x86.xsetbv(i32 [[tmp_Ui]], i32 [[high32_3]], i32 [[low32_3]])
-  (void)__builtin_ia32_xsetbv(tmp_Ui, tmp_ULLi);
-  
-  // XSETBV: call void @llvm.x86.xsetbv
-  (void)_xsetbv(tmp_Ui, tmp_ULLi);
 #endif
-
 }
index cfc33cb0672155e108b2115dddf0b577e36400d6..beb775c0e47fe1d3a188903f50f94e5e90760b1d 100644 (file)
@@ -1,9 +1,6 @@
 // RUN: %clang_cc1 %s -DTEST_XSAVE -O0 -triple=x86_64-unknown-unknown -target-feature +xsave -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVE
 // RUN: %clang_cc1 %s -DTEST_XSAVE -O0 -triple=x86_64-unknown-unknown -target-feature +xsave -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVE
 
-// RUN: %clang_cc1 %s -DTEST_XGETBV -O0 -triple=x86_64-unknown-unknown -target-feature +xsave -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XGETBV
-// RUN: %clang_cc1 %s -DTEST_XSETBV -O0 -triple=x86_64-unknown-unknown -target-feature +xsave -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSETBV
-
 // RUN: %clang_cc1 %s -DTEST_XSAVEOPT -O0 -triple=x86_64-unknown-unknown -target-feature +xsave -target-feature +xsaveopt -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVEOPT
 // RUN: %clang_cc1 %s -DTEST_XSAVEOPT -O0 -triple=x86_64-unknown-unknown -target-feature +xsave -target-feature +xsaveopt -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVEOPT
 
 // RUN: %clang_cc1 %s -DTEST_XSAVES -O0 -triple=x86_64-unknown-unknown -target-feature +xsave -target-feature +xsaves -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVES
 // RUN: %clang_cc1 %s -DTEST_XSAVES -O0 -triple=x86_64-unknown-unknown -target-feature +xsave -target-feature +xsaves -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=XSAVES
 
-// Don't include mm_malloc.h, it's system specific.
-#define __MM_MALLOC_H
-#include <x86intrin.h>
-
-
 void test() {
-  unsigned long long tmp_ULLi;
-  unsigned int       tmp_Ui;
-  void*              tmp_vp;
-  tmp_ULLi = 0; tmp_Ui = 0; tmp_vp = 0;
+  unsigned long long tmp_ULLi = 0;
+  void*              tmp_vp = 0;
 
 #ifdef TEST_XSAVE
 // XSAVE: [[tmp_vp_1:%[0-9a-zA-Z]+]] = load i8*, i8** %tmp_vp, align 8
@@ -56,18 +46,6 @@ void test() {
 // XSAVE: [[low32_4:%[0-9a-zA-Z]+]] = trunc i64 [[tmp_ULLi_4]] to i32
 // XSAVE: call void @llvm.x86.xrstor64(i8* [[tmp_vp_4]], i32 [[high32_4]], i32 [[low32_4]])
   (void)__builtin_ia32_xrstor64(tmp_vp, tmp_ULLi);
-  
-// XSAVE: call void @llvm.x86.xsave
-  (void)_xsave(tmp_vp, tmp_ULLi);
-  
-// XSAVE: call void @llvm.x86.xsave64
-  (void)_xsave64(tmp_vp, tmp_ULLi);
-  
-// XSAVE: call void @llvm.x86.xrstor
-  (void)_xrstor(tmp_vp, tmp_ULLi);
-  
-// XSAVE: call void @llvm.x86.xrstor64
-  (void)_xrstor64(tmp_vp, tmp_ULLi);
 #endif
 
 #ifdef TEST_XSAVEOPT
@@ -86,12 +64,6 @@ void test() {
 // XSAVEOPT: [[low32_2:%[0-9a-zA-Z]+]] = trunc i64 [[tmp_ULLi_2]] to i32
 // XSAVEOPT: call void @llvm.x86.xsaveopt64(i8* [[tmp_vp_2]], i32 [[high32_2]], i32 [[low32_2]])
   (void)__builtin_ia32_xsaveopt64(tmp_vp, tmp_ULLi);
-  
-// XSAVEOPT: call void @llvm.x86.xsaveopt
-  (void)_xsaveopt(tmp_vp, tmp_ULLi);
-  
-// XSAVEOPT: call void @llvm.x86.xsaveopt64
-  (void)_xsaveopt64(tmp_vp, tmp_ULLi);
 #endif
 
 #ifdef TEST_XSAVEC
@@ -110,12 +82,6 @@ void test() {
 // XSAVEC: [[low32_2:%[0-9a-zA-Z]+]] = trunc i64 [[tmp_ULLi_2]] to i32
 // XSAVEC: call void @llvm.x86.xsavec64(i8* [[tmp_vp_2]], i32 [[high32_2]], i32 [[low32_2]])
   (void)__builtin_ia32_xsavec64(tmp_vp, tmp_ULLi);
-  
-// XSAVEC: call void @llvm.x86.xsavec 
-  (void)_xsavec(tmp_vp, tmp_ULLi);
-  
-// XSAVEC: call void @llvm.x86.xsavec64
-  (void)_xsavec64(tmp_vp, tmp_ULLi);
 #endif
 
 #ifdef TEST_XSAVES
@@ -150,39 +116,5 @@ void test() {
 // XSAVES: [[low32_4:%[0-9a-zA-Z]+]] = trunc i64 [[tmp_ULLi_4]] to i32
 // XSAVES: call void @llvm.x86.xrstors64(i8* [[tmp_vp_4]], i32 [[high32_4]], i32 [[low32_4]])
   (void)__builtin_ia32_xrstors64(tmp_vp, tmp_ULLi);
-  
-// XSAVES: call void @llvm.x86.xsaves
-  (void)_xsaves(tmp_vp, tmp_ULLi); 
-  
-// XSAVES: call void @llvm.x86.xsaves64
-  (void)_xsaves64(tmp_vp, tmp_ULLi); 
-
-// XSAVES: call void @llvm.x86.xrstors
-  (void)_xrstors(tmp_vp, tmp_ULLi);
-  
-// XSAVES: call void @llvm.x86.xrstors64
-  (void)_xrstors64(tmp_vp, tmp_ULLi);
-#endif
-
-#ifdef TEST_XGETBV
-// XGETBV: [[tmp_Ui:%[0-9a-zA-z]+]] = load i32, i32* %tmp_Ui, align 4
-// XGETBV: call i64 @llvm.x86.xgetbv(i32 [[tmp_Ui]])
-  tmp_ULLi = __builtin_ia32_xgetbv(tmp_Ui);
-  
-// XGETBV: call i64 @llvm.x86.xgetbv
-  tmp_ULLi = _xgetbv(tmp_Ui);
-#endif
-
-#ifdef TEST_XSETBV
-// XSETBV: [[tmp_Ui:%[0-9a-zA-z]+]] = load i32, i32* %tmp_Ui, align 4
-// XSETBV: [[tmp_ULLi_3:%[0-9a-zA-z]+]] = load i64, i64* %tmp_ULLi, align 8
-// XSETBV: [[high64_3:%[0-9a-zA-z]+]] = lshr i64 [[tmp_ULLi_3]], 32
-// XSETBV: [[high32_3:%[0-9a-zA-z]+]] = trunc i64 [[high64_3]] to i32
-// XSETBV: [[low32_3:%[0-9a-zA-z]+]] = trunc i64 [[tmp_ULLi_3]] to i32
-// XSETBV: call void @llvm.x86.xsetbv(i32 [[tmp_Ui]], i32 [[high32_3]], i32 [[low32_3]])
-  (void)__builtin_ia32_xsetbv(tmp_Ui, tmp_ULLi);
-  
-  // XSETBV: call void @llvm.x86.xsetbv
-  (void)_xsetbv(tmp_Ui, tmp_ULLi);
 #endif
 }
index 18bb79820378d74f1d4d421a0384fdbeaad43846..b0fef9cc06a79db1bf7e4fd375d3d48891c58cd1 100644 (file)
@@ -49,9 +49,7 @@ void f() {
   int info[4];
   __cpuid(info, 0);
   __cpuidex(info, 0, 0);
-#if defined(_M_X64) || defined(_M_IX86)
   _xgetbv(0);
-#endif
   __halt();
   __nop();
   __readmsr(0);