Hi Brian,

On Tuesday, September 30, 2014 13:30:21 Brian Paul wrote:
> Move the USE_MCJIT / HAVE_AVX determination logic to lp_bld.h.  If we
> don't have MCJIT define a dummy LLVMMCJITMemoryManagerRef type to avoid
> excessive #ifdef testing elsewhere.
[...]
> @@ -219,7 +188,7 @@ gallivm_free_code(struct gallivm_state *gallivm)
>     assert(!gallivm->engine);
>     lp_free_generated_code(gallivm->code);
>     gallivm->code = NULL;
> -#if HAVE_LLVM < 0x0306
> +#if USE_MCJIT
We will probably still need the < 0x0306 check:
#if HAVE_LLVM < 0x0306 && USE_MCJIT
since this memorymanager stuff just vanished in the way 3.5 implemented
this with version 3.6.

>     LLVMDisposeMCJITMemoryManager(gallivm->memorymgr);
>     gallivm->memorymgr = NULL;
>  #endif
> 

Also, we will probably fail to compile the LLVMDisposeMCJITMemoryManager
call under some configurations with MCJIT and older llvm.
So, additionally to what you had, how about the attached one?
I am still trying to verify this change against 3.5 and 3.6.
I am not sure about 3.2 since it did not build out of the box with
my configure line.

Greetings

Mathias
>From 915222ba9ed262d4c8deeafd2bfd530bb0a769ba Mon Sep 17 00:00:00 2001
Message-Id: <915222ba9ed262d4c8deeafd2bfd530bb0a769ba.1412109598.git.mathias.froehl...@gmx.net>
From: =?UTF-8?q?Mathias=20Fr=C3=B6hlich?= <[email protected]>
Date: Tue, 30 Sep 2014 22:11:30 +0200
Subject: [PATCH] gallivm: fix build for LLVM 3.2

---
 src/gallium/auxiliary/gallivm/lp_bld.h        | 40 +++++++++++++++++++++++++++
 src/gallium/auxiliary/gallivm/lp_bld_init.c   | 37 ++-----------------------
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp |  9 ++++++
 src/gallium/auxiliary/gallivm/lp_bld_misc.h   |  3 ++
 4 files changed, 54 insertions(+), 35 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld.h b/src/gallium/auxiliary/gallivm/lp_bld.h
index fcf4f16..218f537 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld.h
@@ -58,6 +58,46 @@
 #endif
 
 
+/* Only MCJIT is available as of LLVM SVN r216982 */
+#if HAVE_LLVM >= 0x0306
+
+#define USE_MCJIT 1
+#define HAVE_AVX 1
+
+#else
+
+/**
+ * AVX is supported in:
+ * - standard JIT from LLVM 3.2 onwards
+ * - MC-JIT from LLVM 3.1
+ *   - MC-JIT supports limited OSes (MacOSX and Linux)
+ * - standard JIT in LLVM 3.1, with backports
+ */
+#if defined(PIPE_ARCH_PPC_64) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_ARM) || defined(PIPE_ARCH_AARCH64)
+#  define USE_MCJIT 1
+#  define HAVE_AVX 0
+#elif HAVE_LLVM >= 0x0302 || (HAVE_LLVM == 0x0301 && defined(HAVE_JIT_AVX_SUPPORT))
+#  define USE_MCJIT 0
+#  define HAVE_AVX 1
+#elif HAVE_LLVM == 0x0301 && (defined(PIPE_OS_LINUX) || defined(PIPE_OS_APPLE))
+#  define USE_MCJIT 1
+#  define HAVE_AVX 1
+#else
+#  define USE_MCJIT 0
+#  define HAVE_AVX 0
+#endif
+
+#endif /* HAVE_LLVM >= 0x0306 */
+
+
+#if HAVE_LLVM <= 0x0303
+/* We won't actually use LLVMMCJITMemoryManagerRef, just create a dummy
+ * typedef to simplify things elsewhere.
+ */
+typedef void *LLVMMCJITMemoryManagerRef;
+#endif
+
+
 /**
  * Redefine these LLVM entrypoints as invalid macros to make sure we
  * don't accidentally use them.  We need to use the functions which
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 4e4aecb..2f5b4ba 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -43,37 +43,6 @@
 #include <llvm-c/BitWriter.h>
 
 
-/* Only MCJIT is available as of LLVM SVN r216982 */
-#if HAVE_LLVM >= 0x0306
-
-#define USE_MCJIT 1
-#define HAVE_AVX 1
-
-#else
-
-/**
- * AVX is supported in:
- * - standard JIT from LLVM 3.2 onwards
- * - MC-JIT from LLVM 3.1
- *   - MC-JIT supports limited OSes (MacOSX and Linux)
- * - standard JIT in LLVM 3.1, with backports
- */
-#if defined(PIPE_ARCH_PPC_64) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_ARM) || defined(PIPE_ARCH_AARCH64)
-#  define USE_MCJIT 1
-#  define HAVE_AVX 0
-#elif HAVE_LLVM >= 0x0302 || (HAVE_LLVM == 0x0301 && defined(HAVE_JIT_AVX_SUPPORT))
-#  define USE_MCJIT 0
-#  define HAVE_AVX 1
-#elif HAVE_LLVM == 0x0301 && (defined(PIPE_OS_LINUX) || defined(PIPE_OS_APPLE))
-#  define USE_MCJIT 1
-#  define HAVE_AVX 1
-#else
-#  define USE_MCJIT 0
-#  define HAVE_AVX 0
-#endif
-
-#endif /* HAVE_LLVM >= 0x0306 */
-
 #if USE_MCJIT
 void LLVMLinkInMCJIT();
 #endif
@@ -219,10 +188,8 @@ gallivm_free_code(struct gallivm_state *gallivm)
    assert(!gallivm->engine);
    lp_free_generated_code(gallivm->code);
    gallivm->code = NULL;
-#if HAVE_LLVM < 0x0306
-   LLVMDisposeMCJITMemoryManager(gallivm->memorymgr);
+   lp_free_memory_manager(gallivm->memorymgr);
    gallivm->memorymgr = NULL;
-#endif
 }
 
 
@@ -317,7 +284,7 @@ init_gallivm_state(struct gallivm_state *gallivm, const char *name,
    if (!gallivm->builder)
       goto fail;
 
-#if HAVE_LLVM < 0x0306
+#if USE_MCJIT && HAVE_LLVM < 0x0306
    gallivm->memorymgr = lp_get_default_memory_manager();
    if (!gallivm->memorymgr)
       goto fail;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index c173ab6..9c2de2c 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -554,3 +554,12 @@ lp_get_default_memory_manager()
    return 0;
 #endif
 }
+
+extern "C"
+void
+lp_free_memory_manager(LLVMMCJITMemoryManagerRef memorymgr)
+{
+#if HAVE_LLVM < 0x0306
+   delete reinterpret_cast<llvm::JITMemoryManager*>(memorymgr);
+#endif
+}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
index 40d3e79..36923aa 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
@@ -65,6 +65,9 @@ lp_free_generated_code(struct lp_generated_code *code);
 extern LLVMMCJITMemoryManagerRef
 lp_get_default_memory_manager();
 
+extern void
+lp_free_memory_manager(LLVMMCJITMemoryManagerRef memorymgr);
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.9.3

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to