summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Scheidegger <sroland@vmware.com>2014-06-19 03:27:26 +0200
committerEmil Velikov <emil.l.velikov@gmail.com>2014-09-17 01:38:40 +0100
commitc68183afef3ee29e56f6d0b5571ad6e79664247b (patch)
tree70745905cfcd367bfb3b3096b3be90c0cc7d019a
parentff935f267ea67933bbafb661f2b8257179435450 (diff)
gallivm: set mcpu when initializing llvm execution engine
Previously llvm detected cpu features automatically when the execution engine was created (based on host cpu). This is no longer the case, which meant llvm was then not able to emit some of the intrinsics we used as we didn't specify any sse attributes (only on avx supporting systems this was not a problem since despite at least some llvm versions enabling it anyway we always set this manually). So, instead of trying to figure out which MAttrs to set just set MCPU. This fixes https://bugs.freedesktop.org/show_bug.cgi?id=77493. Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Tested-by: Vinson Lee <vlee@freedesktop.org> (cherry picked from commit cad60420d5ea36a4b6fa2e6c91317f71423aa63e) Conflicts: src/gallium/auxiliary/gallivm/lp_bld_misc.cpp Nominated-by: Laurent Carlier <lordheavym@gmail.com> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=83735
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_misc.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index 45c985dd656..87247ebe62f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -73,6 +73,10 @@
#include <llvm/Support/CBindingWrapping.h>
#endif
+#if HAVE_LLVM >= 0x0305
+#include <llvm/Support/Host.h>
+#endif
+
#include "pipe/p_config.h"
#include "util/u_debug.h"
#include "util/u_cpu_detect.h"
@@ -309,8 +313,8 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
/*
* 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) {
@@ -320,7 +324,25 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
}
builder.setJITMemoryManager(JITMemoryManager::CreateDefaultMemManager());
+#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
+
ExecutionEngine *JIT;
+
#if HAVE_LLVM >= 0x0302
JIT = builder.create();
#else