Blame SOURCES/mesa-llvm-3.5-cpu-fix.patch

ede8cb
diff -up mesa-20140910/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp.dma mesa-20140910/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
ede8cb
--- mesa-20140910/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp.dma	2014-09-10 06:29:29.000000000 +1000
ede8cb
+++ mesa-20140910/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp	2014-09-17 12:58:19.526487782 +1000
ede8cb
@@ -59,6 +59,7 @@
ede8cb
 #include <llvm/ExecutionEngine/JITMemoryManager.h>
ede8cb
 #endif
ede8cb
 #include <llvm/Support/CommandLine.h>
ede8cb
+#include <llvm/Support/Host.h>
ede8cb
 #include <llvm/Support/PrettyStackTrace.h>
ede8cb
 
ede8cb
 #if HAVE_LLVM >= 0x0300
ede8cb
@@ -309,8 +310,8 @@ lp_build_create_jit_compiler_for_module(
ede8cb
       /*
ede8cb
        * AVX feature is not automatically detected from CPUID by the X86 target
ede8cb
        * yet, because the old (yet default) JIT engine is not capable of
ede8cb
-       * emitting the opcodes.  But as we're using MCJIT here, it is safe to
ede8cb
-       * add set this attribute.
ede8cb
+       * emitting the opcodes. On newer llvm versions it is and at least some
ede8cb
+       * versions (tested with 3.3) will emit avx opcodes without this anyway.
ede8cb
        */
ede8cb
       MAttrs.push_back("+avx");
ede8cb
       if (util_cpu_caps.has_f16c) {
ede8cb
@@ -318,14 +319,33 @@ lp_build_create_jit_compiler_for_module(
ede8cb
       }
ede8cb
       builder.setMAttrs(MAttrs);
ede8cb
    }
ede8cb
+
ede8cb
+#if HAVE_LLVM >= 0x0305
ede8cb
+   StringRef MCPU = llvm::sys::getHostCPUName();
ede8cb
+   /*
ede8cb
+    * The cpu bits are no longer set automatically, so need to set mcpu manually.
ede8cb
+    * Note that the MAttrs set above will be sort of ignored (since we should
ede8cb
+    * not set any which would not be set by specifying the cpu anyway).
ede8cb
+    * It ought to be safe though since getHostCPUName() should include bits
ede8cb
+    * not only from the cpu but environment as well (for instance if it's safe
ede8cb
+    * to use avx instructions which need OS support). According to
ede8cb
+    * http://llvm.org/bugs/show_bug.cgi?id=19429 however if I understand this
ede8cb
+    * right it may be necessary to specify older cpu (or disable mattrs) though
ede8cb
+    * when not using MCJIT so no instructions are generated which the old JIT
ede8cb
+    * can't handle. Not entirely sure if we really need to do anything yet.
ede8cb
+    */
ede8cb
+   builder.setMCPU(MCPU);
ede8cb
+#endif
ede8cb
+
ede8cb
    builder.setJITMemoryManager(JITMemoryManager::CreateDefaultMemManager());
ede8cb
 
ede8cb
    ExecutionEngine *JIT;
ede8cb
-#if 0
ede8cb
+
ede8cb
+#if HAVE_LLVM >= 0x0302
ede8cb
    JIT = builder.create();
ede8cb
 #else
ede8cb
    /*
ede8cb
-    * Workaround http://llvm.org/bugs/show_bug.cgi?id=12833
ede8cb
+    * Workaround http://llvm.org/PR12833
ede8cb
     */
ede8cb
    StringRef MArch = "";
ede8cb
    StringRef MCPU = "";