llvmpipe: Always using util_get_cpu_caps to get cpu caps for llvm on x86
authorYonggang Luo <luoyonggang@gmail.com>
Tue, 23 Aug 2022 17:20:43 +0000 (01:20 +0800)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Sep 2022 01:51:42 +0000 (01:51 +0000)
As we can override cpu features with environment variables, so always using util_get_cpu_caps
instead llvm::sys::getHostCPUFeatures to get cpu features is a better option

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17813>

src/gallium/auxiliary/gallivm/lp_bld_misc.cpp

index 2c99368..3b91276 100644 (file)
@@ -379,11 +379,10 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
 
    llvm::SmallVector<std::string, 16> MAttrs;
 
-#if LLVM_VERSION_MAJOR >= 4 && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) || defined(PIPE_ARCH_ARM))
-   /* llvm-3.3+ implements sys::getHostCPUFeatures for Arm
-    * and llvm-3.7+ for x86, which allows us to enable/disable
-    * code generation based on the results of cpuid on these
-    * architectures.
+#if defined(PIPE_ARCH_ARM)
+   /* llvm-3.3+ implements sys::getHostCPUFeatures for Arm,
+    * which allows us to enable/disable code generation based
+    * on the results of cpuid on these architectures.
     */
    llvm::StringMap<bool> features;
    llvm::sys::getHostCPUFeatures(features);
@@ -395,13 +394,9 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
    }
 #elif defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
    /*
-    * We need to unset attributes because sometimes LLVM mistakenly assumes
-    * certain features are present given the processor name.
-    *
-    * https://bugs.freedesktop.org/show_bug.cgi?id=92214
-    * http://llvm.org/PR25021
-    * http://llvm.org/PR19429
-    * http://llvm.org/PR16721
+    * Because we can override cpu caps with environment variables,
+    * so we do not use llvm::sys::getHostCPUFeatures to detect cpu features
+    * but using util_get_cpu_caps() instead.
     */
    MAttrs.push_back(util_get_cpu_caps()->has_sse    ? "+sse"    : "-sse"   );
    MAttrs.push_back(util_get_cpu_caps()->has_sse2   ? "+sse2"   : "-sse2"  );