gallium/gallivm: code generation options for LLVM 3.1+
authorAlexander V. Nikolaev <avn@daemon.hole.ru>
Sun, 23 Sep 2012 02:28:39 +0000 (05:28 +0300)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 28 Oct 2012 10:34:26 +0000 (10:34 +0000)
LLVM 3.1+ haven't more "extern unsigned llvm::StackAlignmentOverride"
and friends for configuring code generation options, like stack
alignment.

So I restrict assiging of lvm::StackAlignmentOverride and other
variables to LLVM 3.0 only, and wrote similiar code using
TargetOptions.

This patch fix segfaulting of WINE using llvmpipe built with LLVM 3.1

Signed-off-by: Alexander V. Nikolaev <avn@daemon.hole.ru>
Signed-off-by: José Fonseca <jose.r.fonseca@gmail.com>
src/gallium/auxiliary/gallivm/lp_bld_init.c
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
src/gallium/auxiliary/gallivm/lp_bld_misc.h

index d364390cdf00b1ac358c676666b415b86fca212f..0065bb49a4bd89e064103f28c19ba75c746f57bb 100644 (file)
@@ -258,11 +258,12 @@ init_gallivm_engine(struct gallivm_state *gallivm)
          optlevel = Default;
       }
 
-#if USE_MCJIT
-      ret = lp_build_create_mcjit_compiler_for_module(&gallivm->engine,
-                                                      gallivm->module,
-                                                      (unsigned) optlevel,
-                                                      &error);
+#if HAVE_LLVM >= 0x0301
+      ret = lp_build_create_jit_compiler_for_module(&gallivm->engine,
+                                                    gallivm->module,
+                                                    (unsigned) optlevel,
+                                                    USE_MCJIT,
+                                                    &error);
 #else
       ret = LLVMCreateJITCompiler(&gallivm->engine, gallivm->provider,
                                   (unsigned) optlevel, &error);
index dd2c6120afb3993c510d08f1b8029af592942a60..6a560df065ab060eca6c3e79cc5172c41c1b5a67 100644 (file)
@@ -109,7 +109,7 @@ lp_set_target_options(void)
     * to only assume a 4 bytes alignment for backwards compatibility.
     */
 #if defined(PIPE_ARCH_X86)
-#if HAVE_LLVM >= 0x0300
+#if HAVE_LLVM == 0x0300
    llvm::StackAlignmentOverride = 4;
 #else
    llvm::StackAlignment = 4;
@@ -232,8 +232,9 @@ lp_set_store_alignment(LLVMValueRef Inst,
 #if HAVE_LLVM >= 0x301
 
 /**
- * Same as LLVMCreateJITCompilerForModule, but using MCJIT and enabling AVX
- * feature where available.
+ * Same as LLVMCreateJITCompilerForModule, but:
+ * - allows using MCJIT and enabling AVX feature where available.
+ * - set target options
  *
  * See also:
  * - llvm/lib/ExecutionEngine/ExecutionEngineBindings.cpp
@@ -242,20 +243,44 @@ lp_set_store_alignment(LLVMValueRef Inst,
  */
 extern "C"
 LLVMBool
-lp_build_create_mcjit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
-                                          LLVMModuleRef M,
-                                          unsigned OptLevel,
-                                          char **OutError)
+lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
+                                        LLVMModuleRef M,
+                                        unsigned OptLevel,
+                                        int useMCJIT,
+                                        char **OutError)
 {
    using namespace llvm;
 
    std::string Error;
    EngineBuilder builder(unwrap(M));
+
+   /**
+    * LLVM 3.1+ haven't more "extern unsigned llvm::StackAlignmentOverride" and
+    * friends for configuring code generation options, like stack alignment.
+    */
+   TargetOptions options;
+#if defined(PIPE_ARCH_X86)
+   options.StackAlignmentOverride = 4;
+   options.RealignStack = true;
+#endif
+
+#if defined(DEBUG)
+   options.JITEmitDebugInfo = true;
+#endif
+
+#if defined(DEBUG) || defined(PROFILE)
+   options.NoFramePointerElimNonLeaf = true;
+   options.NoFramePointerElim = true;
+#endif
+
    builder.setEngineKind(EngineKind::JIT)
           .setErrorStr(&Error)
+          .setTargetOptions(options)
           .setOptLevel((CodeGenOpt::Level)OptLevel);
 
-   builder.setUseMCJIT(true);
+   if (useMCJIT) {
+       builder.setUseMCJIT(true);
+   }
 
    llvm::SmallVector<std::string, 1> MAttrs;
    if (util_cpu_caps.has_avx) {
index 4f80b38280ceca84bbe64ab31362d9a20064d2b2..9ed7c348bb4f0fe30f5795b30e8d866fbf379ca8 100644 (file)
@@ -56,10 +56,11 @@ lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
                        const char *Name);
 
 extern int
-lp_build_create_mcjit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
-                                          LLVMModuleRef M,
-                                          unsigned OptLevel,
-                                          char **OutError);
+lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
+                                        LLVMModuleRef M,
+                                        unsigned OptLevel,
+                                        int useMCJIT,
+                                        char **OutError);
 
 
 #ifdef __cplusplus