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