[Mesa-dev] [PATCH 09/12] gallivm: remove workarounds for pre LLVM 5.0

Emil Velikov emil.l.velikov at gmail.com
Wed Oct 31 13:30:01 UTC 2018


From: Emil Velikov <emil.velikov at collabora.com>

With LLVM 5.0.1 the minimum required version, we can drop all the dead
code.

Cc: Roland Scheidegger <sroland at vmware.com>
Cc: Jose Fonseca <jfonseca at vmware.com>
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
Gents this is a quick and dirty grep job. A couple of places may need
the comments to be tweaked/dropped - I've annotated those with XXX.
---
 src/gallium/auxiliary/gallivm/lp_bld.h        |  25 +-
 src/gallium/auxiliary/gallivm/lp_bld_arit.c   | 104 +-----
 .../auxiliary/gallivm/lp_bld_debug.cpp        |   9 -
 src/gallium/auxiliary/gallivm/lp_bld_gather.c |   4 +-
 src/gallium/auxiliary/gallivm/lp_bld_init.c   |  68 +---
 src/gallium/auxiliary/gallivm/lp_bld_intr.c   |  38 +-
 src/gallium/auxiliary/gallivm/lp_bld_intr.h   |   6 +-
 src/gallium/auxiliary/gallivm/lp_bld_logic.c  |   5 +-
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 346 +-----------------
 src/gallium/auxiliary/gallivm/lp_bld_misc.h   |   1 -
 10 files changed, 26 insertions(+), 580 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld.h b/src/gallium/auxiliary/gallivm/lp_bld.h
index 239c27e3c25..a008541c18d 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld.h
@@ -53,16 +53,8 @@
 #ifndef HAVE_LLVM
 #error "HAVE_LLVM should be set with LLVM's version number, e.g. (0x0207 for 2.7)"
 #endif
-#if HAVE_LLVM < 0x303
-#error "LLVM 3.3 or newer required"
-#endif
-
-
-#if HAVE_LLVM <= 0x0303
-/* We won't actually use LLVMMCJITMemoryManagerRef, just create a dummy
- * typedef to simplify things elsewhere.
- */
-typedef void *LLVMMCJITMemoryManagerRef;
+#if HAVE_LLVM < 0x500
+#error "LLVM 5.0 or newer required"
 #endif
 
 
@@ -96,17 +88,4 @@ typedef void *LLVMMCJITMemoryManagerRef;
 #define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION
 
 
-/*
- * Before LLVM 3.4 LLVMSetAlignment only supported GlobalValue, not
- * LoadInst/StoreInst as we need.
- */
-#if HAVE_LLVM < 0x0304
-#  ifdef __cplusplus
-      extern "C"
-#  endif
-   void LLVMSetAlignmentBackport(LLVMValueRef V, unsigned Bytes);
-#  define LLVMSetAlignment LLVMSetAlignmentBackport
-#endif
-
-
 #endif /* LP_BLD_H */
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index f348833206b..e91ff361924 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -142,49 +142,6 @@ lp_build_min_simple(struct lp_build_context *bld,
          intrinsic = "llvm.ppc.altivec.vminfp";
          intr_size = 128;
       }
-   } else if (HAVE_LLVM < 0x0309 &&
-              util_cpu_caps.has_avx2 && type.length > 4) {
-      intr_size = 256;
-      switch (type.width) {
-      case 8:
-         intrinsic = type.sign ? "llvm.x86.avx2.pmins.b" : "llvm.x86.avx2.pminu.b";
-         break;
-      case 16:
-         intrinsic = type.sign ? "llvm.x86.avx2.pmins.w" : "llvm.x86.avx2.pminu.w";
-         break;
-      case 32:
-         intrinsic = type.sign ? "llvm.x86.avx2.pmins.d" : "llvm.x86.avx2.pminu.d";
-         break;
-      }
-   } else if (HAVE_LLVM < 0x0309 &&
-              util_cpu_caps.has_sse2 && type.length >= 2) {
-      intr_size = 128;
-      if ((type.width == 8 || type.width == 16) &&
-          (type.width * type.length <= 64) &&
-          (gallivm_debug & GALLIVM_DEBUG_PERF)) {
-         debug_printf("%s: inefficient code, bogus shuffle due to packing\n",
-                      __FUNCTION__);
-      }
-      if (type.width == 8 && !type.sign) {
-         intrinsic = "llvm.x86.sse2.pminu.b";
-      }
-      else if (type.width == 16 && type.sign) {
-         intrinsic = "llvm.x86.sse2.pmins.w";
-      }
-      if (util_cpu_caps.has_sse4_1) {
-         if (type.width == 8 && type.sign) {
-            intrinsic = "llvm.x86.sse41.pminsb";
-         }
-         if (type.width == 16 && !type.sign) {
-            intrinsic = "llvm.x86.sse41.pminuw";
-         }
-         if (type.width == 32 && !type.sign) {
-            intrinsic = "llvm.x86.sse41.pminud";
-         }
-         if (type.width == 32 && type.sign) {
-            intrinsic = "llvm.x86.sse41.pminsd";
-         }
-      }
    } else if (util_cpu_caps.has_altivec) {
       intr_size = 128;
       if (type.width == 8) {
@@ -285,12 +242,6 @@ lp_build_fmuladd(LLVMBuilderRef builder,
    LLVMTypeRef type = LLVMTypeOf(a);
    assert(type == LLVMTypeOf(b));
    assert(type == LLVMTypeOf(c));
-   if (HAVE_LLVM < 0x0304) {
-      /* XXX: LLVM 3.3 does not breakdown llvm.fmuladd into mul+add when FMA is
-       * not supported, and instead it falls-back to a C function.
-       */
-      return LLVMBuildFAdd(builder, LLVMBuildFMul(builder, a, b, ""), c, "");
-   }
    char intrinsic[32];
    lp_format_intrinsic(intrinsic, sizeof intrinsic, "llvm.fmuladd", type);
    LLVMValueRef args[] = { a, b, c };
@@ -360,50 +311,6 @@ lp_build_max_simple(struct lp_build_context *bld,
          intrinsic = "llvm.ppc.altivec.vmaxfp";
          intr_size = 128;
       }
-   } else if (HAVE_LLVM < 0x0309 &&
-              util_cpu_caps.has_avx2 && type.length > 4) {
-      intr_size = 256;
-      switch (type.width) {
-      case 8:
-         intrinsic = type.sign ? "llvm.x86.avx2.pmaxs.b" : "llvm.x86.avx2.pmaxu.b";
-         break;
-      case 16:
-         intrinsic = type.sign ? "llvm.x86.avx2.pmaxs.w" : "llvm.x86.avx2.pmaxu.w";
-         break;
-      case 32:
-         intrinsic = type.sign ? "llvm.x86.avx2.pmaxs.d" : "llvm.x86.avx2.pmaxu.d";
-         break;
-      }
-   } else if (HAVE_LLVM < 0x0309 &&
-              util_cpu_caps.has_sse2 && type.length >= 2) {
-      intr_size = 128;
-      if ((type.width == 8 || type.width == 16) &&
-          (type.width * type.length <= 64) &&
-          (gallivm_debug & GALLIVM_DEBUG_PERF)) {
-         debug_printf("%s: inefficient code, bogus shuffle due to packing\n",
-                      __FUNCTION__);
-         }
-      if (type.width == 8 && !type.sign) {
-         intrinsic = "llvm.x86.sse2.pmaxu.b";
-         intr_size = 128;
-      }
-      else if (type.width == 16 && type.sign) {
-         intrinsic = "llvm.x86.sse2.pmaxs.w";
-      }
-      if (util_cpu_caps.has_sse4_1) {
-         if (type.width == 8 && type.sign) {
-            intrinsic = "llvm.x86.sse41.pmaxsb";
-         }
-         if (type.width == 16 && !type.sign) {
-            intrinsic = "llvm.x86.sse41.pmaxuw";
-         }
-         if (type.width == 32 && !type.sign) {
-            intrinsic = "llvm.x86.sse41.pmaxud";
-        }
-         if (type.width == 32 && type.sign) {
-            intrinsic = "llvm.x86.sse41.pmaxsd";
-         }
-      }
    } else if (util_cpu_caps.has_altivec) {
      intr_size = 128;
      if (type.width == 8) {
@@ -1816,16 +1723,7 @@ lp_build_abs(struct lp_build_context *bld,
       return a;
 
    if(type.floating) {
-      if (0x0306 <= HAVE_LLVM && HAVE_LLVM < 0x0309) {
-         /* Workaround llvm.org/PR27332 */
-         LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
-         unsigned long long absMask = ~(1ULL << (type.width - 1));
-         LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, ((unsigned long long) absMask));
-         a = LLVMBuildBitCast(builder, a, int_vec_type, "");
-         a = LLVMBuildAnd(builder, a, mask, "");
-         a = LLVMBuildBitCast(builder, a, vec_type, "");
-         return a;
-      } else {
+      {
          char intrinsic[32];
          lp_format_intrinsic(intrinsic, sizeof intrinsic, "llvm.fabs", vec_type);
          return lp_build_intrinsic_unary(builder, intrinsic, vec_type, a);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
index 23ada3d0433..2ffceddd75f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
@@ -71,20 +71,11 @@ lp_check_alignment(const void *ptr, unsigned alignment)
 extern "C" void
 lp_debug_dump_value(LLVMValueRef value)
 {
-#if HAVE_LLVM >= 0x0304
    char *str = LLVMPrintValueToString(value);
    if (str) {
       os_log_message(str);
       LLVMDisposeMessage(str);
    }
-#elif defined(PIPE_OS_WINDOWS) || defined(PIPE_OS_EMBEDDED)
-   std::string str;
-   llvm::raw_string_ostream os(str);
-   llvm::unwrap(value)->print(os);
-   os_log_message(str.c_str());
-#else
-   LLVMDumpValue(value);
-#endif
 }
 
 
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.c b/src/gallium/auxiliary/gallivm/lp_bld_gather.c
index 8cabe9ef01e..c6196073a12 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_gather.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.c
@@ -302,8 +302,8 @@ lp_build_gather_avx2(struct gallivm_state *gallivm,
 
    if (0) {
       /*
-       * XXX: This will cause LLVM pre 3.7 to hang; it works on LLVM 3.8 but
-       * will not use the AVX2 gather instrinsics (even with llvm 4.0), at
+       * XXX: Check with LLVM 5.0 and later
+       * XXX: This will not use the AVX2 gather instrinsics with llvm 4.0, at
        * least with Haswell. See
        * http://lists.llvm.org/pipermail/llvm-dev/2016-January/094448.html
        * And the generated code doing the emulation is quite a bit worse
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index e8bca5bc3af..2bf43e36b90 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -46,19 +46,6 @@
 #include <llvm-c/BitWriter.h>
 
 
-/* Only MCJIT is available as of LLVM SVN r216982 */
-#if HAVE_LLVM >= 0x0306
-#  define USE_MCJIT 1
-#elif defined(PIPE_ARCH_PPC_64) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_ARM) || defined(PIPE_ARCH_AARCH64)
-#  define USE_MCJIT 1
-#endif
-
-#if defined(USE_MCJIT)
-static const bool use_mcjit = USE_MCJIT;
-#else
-static bool use_mcjit = FALSE;
-#endif
-
 unsigned gallivm_perf = 0;
 
 static const struct debug_named_value lp_bld_perf_flags[] = {
@@ -130,11 +117,6 @@ create_pass_manager(struct gallivm_state *gallivm)
     * simple, or constant propagation into them, etc.
     */
 
-#if HAVE_LLVM < 0x0309
-   // Old versions of LLVM get the DataLayout from the pass manager.
-   LLVMAddTargetData(gallivm->target, gallivm->passmgr);
-#endif
-
    {
       char *td_str;
       // New ones from the Module.
@@ -201,13 +183,8 @@ gallivm_free_ir(struct gallivm_state *gallivm)
 
    FREE(gallivm->module_name);
 
-   if (!use_mcjit) {
-      /* Don't free the TargetData, it's owned by the exec engine */
-   } else {
-      if (gallivm->target) {
-         LLVMDisposeTargetData(gallivm->target);
-      }
-   }
+   if (gallivm->target)
+      LLVMDisposeTargetData(gallivm->target);
 
    if (gallivm->builder)
       LLVMDisposeBuilder(gallivm->builder);
@@ -259,7 +236,6 @@ init_gallivm_engine(struct gallivm_state *gallivm)
                                                     gallivm->module,
                                                     gallivm->memorymgr,
                                                     (unsigned) optlevel,
-                                                    use_mcjit,
                                                     &error);
       if (ret) {
          _debug_printf("%s\n", error);
@@ -268,11 +244,7 @@ init_gallivm_engine(struct gallivm_state *gallivm)
       }
    }
 
-   if (!use_mcjit) {
-      gallivm->target = LLVMGetExecutionEngineTargetData(gallivm->engine);
-      if (!gallivm->target)
-         goto fail;
-   } else {
+   {
       if (0) {
           /*
            * Dump the data layout strings.
@@ -347,11 +319,8 @@ init_gallivm_state(struct gallivm_state *gallivm, const char *name,
     * complete when MC-JIT is created. So defer the MC-JIT engine creation for
     * now.
     */
-   if (!use_mcjit) {
-      if (!init_gallivm_engine(gallivm)) {
-         goto fail;
-      }
-   } else {
+   // XXX: nuke above comment?
+   {
       /*
        * MC-JIT engine compiles the module immediately on creation, so we can't
        * obtain the target data from it.  Instead we create a target data layout
@@ -406,22 +375,7 @@ lp_build_init(void)
    if (gallivm_initialized)
       return TRUE;
 
-
-   /* LLVMLinkIn* are no-ops at runtime.  They just ensure the respective
-    * component is linked at buildtime, which is sufficient for its static
-    * constructors to be called at load time.
-    */
-#if defined(USE_MCJIT)
-#  if USE_MCJIT
-      LLVMLinkInMCJIT();
-#  else
-      LLVMLinkInJIT();
-#  endif
-#else
-   use_mcjit = debug_get_bool_option("GALLIVM_MCJIT", FALSE);
-   LLVMLinkInJIT();
    LLVMLinkInMCJIT();
-#endif
 
 #ifdef DEBUG
    gallivm_debug = debug_get_option_gallivm_debug();
@@ -481,11 +435,6 @@ lp_build_init(void)
       util_cpu_caps.has_f16c = 0;
       util_cpu_caps.has_fma = 0;
    }
-   if (HAVE_LLVM < 0x0304 || !use_mcjit) {
-      /* AVX2 support has only been tested with LLVM 3.4, and it requires
-       * MCJIT. */
-      util_cpu_caps.has_avx2 = 0;
-   }
 
 #ifdef PIPE_ARCH_PPC_64
    /* Set the NJ bit in VSCR to 0 so denormalized values are handled as
@@ -602,7 +551,7 @@ gallivm_compile_module(struct gallivm_state *gallivm)
                    "-sroa -early-cse -simplifycfg -reassociate "
                    "-mem2reg -constprop -instcombine -gvn",
                    filename, gallivm_debug & GALLIVM_PERF_NO_OPT ? 0 : 2,
-                   (HAVE_LLVM >= 0x0305) ? "[-mcpu=<-mcpu option>] " : "",
+                   "[-mcpu=<-mcpu option>] ",
                    "[-mattr=<-mattr option(s)>]");
    }
 
@@ -619,8 +568,7 @@ gallivm_compile_module(struct gallivm_state *gallivm)
 
    /* Disable frame pointer omission on debug/profile builds */
    /* XXX: And workaround http://llvm.org/PR21435 */
-#if HAVE_LLVM >= 0x0307 && \
-    (defined(DEBUG) || defined(PROFILE) || \
+#if (defined(DEBUG) || defined(PROFILE) || \
      defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
       LLVMAddTargetDependentFunctionAttr(func, "no-frame-pointer-elim", "true");
       LLVMAddTargetDependentFunctionAttr(func, "no-frame-pointer-elim-non-leaf", "true");
@@ -639,7 +587,7 @@ gallivm_compile_module(struct gallivm_state *gallivm)
                    gallivm->module_name, time_msec);
    }
 
-   if (use_mcjit) {
+   {
       /* Setting the module's DataLayout to an empty string will cause the
        * ExecutionEngine to copy to the DataLayout string from its target
        * machine to the module.  As of LLVM 3.8 the module and the execution
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.c b/src/gallium/auxiliary/gallivm/lp_bld_intr.c
index 74ed16f33f0..3fb8d73a114 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_intr.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.c
@@ -121,24 +121,6 @@ lp_declare_intrinsic(LLVMModuleRef module,
 }
 
 
-#if HAVE_LLVM < 0x0400
-static LLVMAttribute lp_attr_to_llvm_attr(enum lp_func_attr attr)
-{
-   switch (attr) {
-   case LP_FUNC_ATTR_ALWAYSINLINE: return LLVMAlwaysInlineAttribute;
-   case LP_FUNC_ATTR_INREG: return LLVMInRegAttribute;
-   case LP_FUNC_ATTR_NOALIAS: return LLVMNoAliasAttribute;
-   case LP_FUNC_ATTR_NOUNWIND: return LLVMNoUnwindAttribute;
-   case LP_FUNC_ATTR_READNONE: return LLVMReadNoneAttribute;
-   case LP_FUNC_ATTR_READONLY: return LLVMReadOnlyAttribute;
-   default:
-      _debug_printf("Unhandled function attribute: %x\n", attr);
-      return 0;
-   }
-}
-
-#else
-
 static const char *attr_to_str(enum lp_func_attr attr)
 {
    switch (attr) {
@@ -157,26 +139,10 @@ static const char *attr_to_str(enum lp_func_attr attr)
    }
 }
 
-#endif
-
 void
 lp_add_function_attr(LLVMValueRef function_or_call,
                      int attr_idx, enum lp_func_attr attr)
 {
-
-#if HAVE_LLVM < 0x0400
-   LLVMAttribute llvm_attr = lp_attr_to_llvm_attr(attr);
-   if (LLVMIsAFunction(function_or_call)) {
-      if (attr_idx == -1) {
-         LLVMAddFunctionAttr(function_or_call, llvm_attr);
-      } else {
-         LLVMAddAttribute(LLVMGetParam(function_or_call, attr_idx - 1), llvm_attr);
-      }
-   } else {
-      LLVMAddInstrAttribute(function_or_call, attr_idx, llvm_attr);
-   }
-#else
-
    LLVMModuleRef module;
    if (LLVMIsAFunction(function_or_call)) {
       module = LLVMGetGlobalParent(function_or_call);
@@ -196,7 +162,6 @@ lp_add_function_attr(LLVMValueRef function_or_call,
       LLVMAddAttributeAtIndex(function_or_call, attr_idx, llvm_attr);
    else
       LLVMAddCallSiteAttribute(function_or_call, attr_idx, llvm_attr);
-#endif
 }
 
 static void
@@ -224,8 +189,7 @@ lp_build_intrinsic(LLVMBuilderRef builder,
 {
    LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
    LLVMValueRef function, call;
-   bool set_callsite_attrs = HAVE_LLVM >= 0x0400 &&
-                             !(attr_mask & LP_FUNC_ATTR_LEGACY);
+   bool set_callsite_attrs = !(attr_mask & LP_FUNC_ATTR_LEGACY);
 
    function = LLVMGetNamedFunction(module, name);
    if(!function) {
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h
index bf8143df87d..00dbc40e0be 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h
@@ -53,9 +53,9 @@ enum lp_func_attr {
    LP_FUNC_ATTR_NOUNWIND     = (1 << 4),
    LP_FUNC_ATTR_READNONE     = (1 << 5),
    LP_FUNC_ATTR_READONLY     = (1 << 6),
-   LP_FUNC_ATTR_WRITEONLY    = HAVE_LLVM >= 0x0400 ? (1 << 7) : 0,
-   LP_FUNC_ATTR_INACCESSIBLE_MEM_ONLY = HAVE_LLVM >= 0x0400 ? (1 << 8) : 0,
-   LP_FUNC_ATTR_CONVERGENT   = HAVE_LLVM >= 0x0400 ? (1 << 9) : 0,
+   LP_FUNC_ATTR_WRITEONLY    = (1 << 7),
+   LP_FUNC_ATTR_INACCESSIBLE_MEM_ONLY = (1 << 8),
+   LP_FUNC_ATTR_CONVERGENT   = (1 << 9),
 
    /* Legacy intrinsic that needs attributes on function declarations
     * and they must match the internal LLVM definition exactly, otherwise
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
index 524917abe27..92915372098 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
@@ -317,9 +317,8 @@ lp_build_select(struct lp_build_context *bld,
       mask = LLVMBuildTrunc(builder, mask, LLVMInt1TypeInContext(lc), "");
       res = LLVMBuildSelect(builder, mask, a, b, "");
    }
-   else if (!(HAVE_LLVM == 0x0307) &&
-            (LLVMIsConstant(mask) ||
-             LLVMGetInstructionOpcode(mask) == LLVMSExt)) {
+   else if (LLVMIsConstant(mask) ||
+             LLVMGetInstructionOpcode(mask) == LLVMSExt) {
       /* Generate a vector select.
        *
        * Using vector selects should avoid emitting intrinsics hence avoid
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index fcbdd5050fe..212f5010221 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -43,38 +43,24 @@
 #include <stddef.h>
 
 // Workaround http://llvm.org/PR23628
-#if HAVE_LLVM >= 0x0307
 #  pragma push_macro("DEBUG")
 #  undef DEBUG
-#endif
 
 #include <llvm-c/Core.h>
-#if HAVE_LLVM >= 0x0306
 #include <llvm-c/Support.h>
-#endif
 #include <llvm-c/ExecutionEngine.h>
 #include <llvm/Target/TargetOptions.h>
 #include <llvm/ExecutionEngine/ExecutionEngine.h>
 #include <llvm/ADT/Triple.h>
-#if HAVE_LLVM >= 0x0307
 #include <llvm/Analysis/TargetLibraryInfo.h>
-#else
-#include <llvm/Target/TargetLibraryInfo.h>
-#endif
-#if HAVE_LLVM < 0x0306
-#include <llvm/ExecutionEngine/JITMemoryManager.h>
-#else
 #include <llvm/ExecutionEngine/SectionMemoryManager.h>
-#endif
 #include <llvm/Support/CommandLine.h>
 #include <llvm/Support/Host.h>
 #include <llvm/Support/PrettyStackTrace.h>
 
 #include <llvm/Support/TargetSelect.h>
 
-#if HAVE_LLVM >= 0x0305
 #include <llvm/IR/CallSite.h>
-#endif
 #include <llvm/IR/IRBuilder.h>
 #include <llvm/IR/Module.h>
 #include <llvm/Support/CBindingWrapping.h>
@@ -85,9 +71,7 @@
 #endif
 
 // Workaround http://llvm.org/PR23628
-#if HAVE_LLVM >= 0x0307
 #  pragma pop_macro("DEBUG")
-#endif
 
 #include "c11/threads.h"
 #include "os/os_thread.h"
@@ -125,7 +109,7 @@ static void init_native_targets()
    llvm::InitializeNativeTargetAsmPrinter();
 
    llvm::InitializeNativeTargetDisassembler();
-#if DEBUG && HAVE_LLVM >= 0x0306
+#if DEBUG
    {
       char *env_llc_options = getenv("GALLIVM_LLC_OPTIONS");
       if (env_llc_options) {
@@ -150,15 +134,6 @@ static void init_native_targets()
 extern "C" void
 lp_set_target_options(void)
 {
-#if HAVE_LLVM < 0x0304
-   /*
-    * By default LLVM adds a signal handler to output a pretty stack trace.
-    * This signal handler is never removed, causing problems when unloading the
-    * shared object where the gallium driver resides.
-    */
-   llvm::DisablePrettyStackTrace = true;
-#endif
-
    /* The llvm target registry is not thread-safe, so drivers and state-trackers
     * that want to initialize targets should use the lp_set_target_options()
     * function to safely initialize targets.
@@ -174,56 +149,18 @@ LLVMTargetLibraryInfoRef
 gallivm_create_target_library_info(const char *triple)
 {
    return reinterpret_cast<LLVMTargetLibraryInfoRef>(
-#if HAVE_LLVM < 0x0307
-   new llvm::TargetLibraryInfo(
-#else
-   new llvm::TargetLibraryInfoImpl(
-#endif
-   llvm::Triple(triple)));
+   new llvm::TargetLibraryInfoImpl(llvm::Triple(triple)));
 }
 
 extern "C"
 void
 gallivm_dispose_target_library_info(LLVMTargetLibraryInfoRef library_info)
 {
-   delete reinterpret_cast<
-#if HAVE_LLVM < 0x0307
-   llvm::TargetLibraryInfo
-#else
-   llvm::TargetLibraryInfoImpl
-#endif
-   *>(library_info);
-}
-
-
-#if HAVE_LLVM < 0x0304
-
-extern "C"
-void
-LLVMSetAlignmentBackport(LLVMValueRef V,
-                         unsigned Bytes)
-{
-   switch (LLVMGetInstructionOpcode(V)) {
-   case LLVMLoad:
-      llvm::unwrap<llvm::LoadInst>(V)->setAlignment(Bytes);
-      break;
-   case LLVMStore:
-      llvm::unwrap<llvm::StoreInst>(V)->setAlignment(Bytes);
-      break;
-   default:
-      assert(0);
-      break;
-   }
+   delete reinterpret_cast<llvm::TargetLibraryInfoImpl*>(library_info);
 }
 
-#endif
-
 
-#if HAVE_LLVM < 0x0306
-typedef llvm::JITMemoryManager BaseMemoryManager;
-#else
 typedef llvm::RTDyldMemoryManager BaseMemoryManager;
-#endif
 
 
 /*
@@ -237,96 +174,10 @@ class DelegatingJITMemoryManager : public BaseMemoryManager {
       virtual BaseMemoryManager *mgr() const = 0;
 
    public:
-#if HAVE_LLVM < 0x0306
-      /*
-       * From JITMemoryManager
-       */
-      virtual void setMemoryWritable() {
-         mgr()->setMemoryWritable();
-      }
-      virtual void setMemoryExecutable() {
-         mgr()->setMemoryExecutable();
-      }
-      virtual void setPoisonMemory(bool poison) {
-         mgr()->setPoisonMemory(poison);
-      }
-      virtual void AllocateGOT() {
-         mgr()->AllocateGOT();
-         /*
-          * isManagingGOT() is not virtual in base class so we can't delegate.
-          * Instead we mirror the value of HasGOT in our instance.
-          */
-         HasGOT = mgr()->isManagingGOT();
-      }
-      virtual uint8_t *getGOTBase() const {
-         return mgr()->getGOTBase();
-      }
-      virtual uint8_t *startFunctionBody(const llvm::Function *F,
-                                         uintptr_t &ActualSize) {
-         return mgr()->startFunctionBody(F, ActualSize);
-      }
-      virtual uint8_t *allocateStub(const llvm::GlobalValue *F,
-                                    unsigned StubSize,
-                                    unsigned Alignment) {
-         return mgr()->allocateStub(F, StubSize, Alignment);
-      }
-      virtual void endFunctionBody(const llvm::Function *F,
-                                   uint8_t *FunctionStart,
-                                   uint8_t *FunctionEnd) {
-         mgr()->endFunctionBody(F, FunctionStart, FunctionEnd);
-      }
-      virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
-         return mgr()->allocateSpace(Size, Alignment);
-      }
-      virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) {
-         return mgr()->allocateGlobal(Size, Alignment);
-      }
-      virtual void deallocateFunctionBody(void *Body) {
-         mgr()->deallocateFunctionBody(Body);
-      }
-#if HAVE_LLVM < 0x0304
-      virtual uint8_t *startExceptionTable(const llvm::Function *F,
-                                           uintptr_t &ActualSize) {
-         return mgr()->startExceptionTable(F, ActualSize);
-      }
-      virtual void endExceptionTable(const llvm::Function *F,
-                                     uint8_t *TableStart,
-                                     uint8_t *TableEnd,
-                                     uint8_t *FrameRegister) {
-         mgr()->endExceptionTable(F, TableStart, TableEnd,
-                                  FrameRegister);
-      }
-      virtual void deallocateExceptionTable(void *ET) {
-         mgr()->deallocateExceptionTable(ET);
-      }
-#endif
-      virtual bool CheckInvariants(std::string &s) {
-         return mgr()->CheckInvariants(s);
-      }
-      virtual size_t GetDefaultCodeSlabSize() {
-         return mgr()->GetDefaultCodeSlabSize();
-      }
-      virtual size_t GetDefaultDataSlabSize() {
-         return mgr()->GetDefaultDataSlabSize();
-      }
-      virtual size_t GetDefaultStubSlabSize() {
-         return mgr()->GetDefaultStubSlabSize();
-      }
-      virtual unsigned GetNumCodeSlabs() {
-         return mgr()->GetNumCodeSlabs();
-      }
-      virtual unsigned GetNumDataSlabs() {
-         return mgr()->GetNumDataSlabs();
-      }
-      virtual unsigned GetNumStubSlabs() {
-         return mgr()->GetNumStubSlabs();
-      }
-#endif
 
       /*
        * From RTDyldMemoryManager
        */
-#if HAVE_LLVM >= 0x0304
       virtual uint8_t *allocateCodeSection(uintptr_t Size,
                                            unsigned Alignment,
                                            unsigned SectionID,
@@ -334,57 +185,28 @@ class DelegatingJITMemoryManager : public BaseMemoryManager {
          return mgr()->allocateCodeSection(Size, Alignment, SectionID,
                                            SectionName);
       }
-#else
-      virtual uint8_t *allocateCodeSection(uintptr_t Size,
-                                           unsigned Alignment,
-                                           unsigned SectionID) {
-         return mgr()->allocateCodeSection(Size, Alignment, SectionID);
-      }
-#endif
       virtual uint8_t *allocateDataSection(uintptr_t Size,
                                            unsigned Alignment,
                                            unsigned SectionID,
-#if HAVE_LLVM >= 0x0304
                                            llvm::StringRef SectionName,
-#endif
                                            bool IsReadOnly) {
          return mgr()->allocateDataSection(Size, Alignment, SectionID,
-#if HAVE_LLVM >= 0x0304
                                            SectionName,
-#endif
                                            IsReadOnly);
       }
-#if HAVE_LLVM >= 0x0304
       virtual void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) {
          mgr()->registerEHFrames(Addr, LoadAddr, Size);
       }
-#else
-      virtual void registerEHFrames(llvm::StringRef SectionData) {
-         mgr()->registerEHFrames(SectionData);
-      }
-#endif
-#if HAVE_LLVM >= 0x0500
       virtual void deregisterEHFrames() {
          mgr()->deregisterEHFrames();
       }
-#elif HAVE_LLVM >= 0x0304
-      virtual void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) {
-         mgr()->deregisterEHFrames(Addr, LoadAddr, Size);
-      }
-#endif
       virtual void *getPointerToNamedFunction(const std::string &Name,
                                               bool AbortOnFailure=true) {
          return mgr()->getPointerToNamedFunction(Name, AbortOnFailure);
       }
-#if HAVE_LLVM <= 0x0303
-      virtual bool applyPermissions(std::string *ErrMsg = 0) {
-         return mgr()->applyPermissions(ErrMsg);
-      }
-#else
       virtual bool finalizeMemory(std::string *ErrMsg = 0) {
          return mgr()->finalizeMemory(ErrMsg);
       }
-#endif
 };
 
 
@@ -413,21 +235,7 @@ class ShaderMemoryManager : public DelegatingJITMemoryManager {
       }
 
       ~GeneratedCode() {
-         /*
-          * Deallocate things as previously requested and
-          * free shared manager when no longer used.
-          */
-#if HAVE_LLVM < 0x0306
-         Vec::iterator i;
-
-         assert(TheMM);
-         for ( i = FunctionBody.begin(); i != FunctionBody.end(); ++i )
-            TheMM->deallocateFunctionBody(*i);
-#if HAVE_LLVM < 0x0304
-         for ( i = ExceptionTable.begin(); i != ExceptionTable.end(); ++i )
-            TheMM->deallocateExceptionTable(*i);
-#endif /* HAVE_LLVM < 0x0304 */
-#endif /* HAVE_LLVM < 0x0306 */
+         /* No op */
       }
    };
 
@@ -459,13 +267,6 @@ class ShaderMemoryManager : public DelegatingJITMemoryManager {
          delete (GeneratedCode *) code;
       }
 
-#if HAVE_LLVM < 0x0304
-      virtual void deallocateExceptionTable(void *ET) {
-         // remember for later deallocation
-         code->ExceptionTable.push_back(ET);
-      }
-#endif
-
       virtual void deallocateFunctionBody(void *Body) {
          // remember for later deallocation
          code->FunctionBody.push_back(Body);
@@ -490,43 +291,16 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
                                         LLVMModuleRef M,
                                         LLVMMCJITMemoryManagerRef CMM,
                                         unsigned OptLevel,
-                                        int useMCJIT,
                                         char **OutError)
 {
    using namespace llvm;
 
    std::string Error;
-#if HAVE_LLVM >= 0x0306
    EngineBuilder builder(std::unique_ptr<Module>(unwrap(M)));
-#else
-   EngineBuilder builder(unwrap(M));
-#endif
 
-   /**
-    * 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;
-#if HAVE_LLVM < 0x0304
-   options.RealignStack = true;
-#endif
-#endif
-
-#if defined(DEBUG) && HAVE_LLVM < 0x0307
-   options.JITEmitDebugInfo = true;
-#endif
-
-   /* XXX: Workaround http://llvm.org/PR21435 */
-#if defined(DEBUG) || defined(PROFILE) || \
-    (HAVE_LLVM >= 0x0303 && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)))
-#if HAVE_LLVM < 0x0304
-   options.NoFramePointerElimNonLeaf = true;
-#endif
-#if HAVE_LLVM < 0x0307
-   options.NoFramePointerElim = true;
-#endif
 #endif
 
    builder.setEngineKind(EngineKind::JIT)
@@ -534,10 +308,7 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
           .setTargetOptions(options)
           .setOptLevel((CodeGenOpt::Level)OptLevel);
 
-   if (useMCJIT) {
-#if HAVE_LLVM < 0x0306
-       builder.setUseMCJIT(true);
-#endif
+   if (1) {
 #ifdef _WIN32
        /*
         * MCJIT works on Windows, but currently only through ELF object format.
@@ -557,7 +328,6 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
    llvm::SmallVector<std::string, 16> MAttrs;
 
 #if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
-#if HAVE_LLVM >= 0x0400
    /* llvm-3.7+ implements sys::getHostCPUFeatures for x86,
     * which allows us to enable/disable code generation based
     * on the results of cpuid.
@@ -570,79 +340,10 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
         ++f) {
       MAttrs.push_back(((*f).second ? "+" : "-") + (*f).first().str());
    }
-#else
-   /*
-    * We need to unset attributes because sometimes LLVM mistakenly assumes
-    * certain features are present given the processor name.
-    *
-    * https://bugs.freedesktop.org/show_bug.cgi?id=92214
-    * http://llvm.org/PR25021
-    * http://llvm.org/PR19429
-    * http://llvm.org/PR16721
-    */
-   MAttrs.push_back(util_cpu_caps.has_sse    ? "+sse"    : "-sse"   );
-   MAttrs.push_back(util_cpu_caps.has_sse2   ? "+sse2"   : "-sse2"  );
-   MAttrs.push_back(util_cpu_caps.has_sse3   ? "+sse3"   : "-sse3"  );
-   MAttrs.push_back(util_cpu_caps.has_ssse3  ? "+ssse3"  : "-ssse3" );
-#if HAVE_LLVM >= 0x0304
-   MAttrs.push_back(util_cpu_caps.has_sse4_1 ? "+sse4.1" : "-sse4.1");
-#else
-   MAttrs.push_back(util_cpu_caps.has_sse4_1 ? "+sse41"  : "-sse41" );
-#endif
-#if HAVE_LLVM >= 0x0304
-   MAttrs.push_back(util_cpu_caps.has_sse4_2 ? "+sse4.2" : "-sse4.2");
-#else
-   MAttrs.push_back(util_cpu_caps.has_sse4_2 ? "+sse42"  : "-sse42" );
-#endif
-   /*
-    * 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. 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(util_cpu_caps.has_avx  ? "+avx"  : "-avx");
-   MAttrs.push_back(util_cpu_caps.has_f16c ? "+f16c" : "-f16c");
-   if (HAVE_LLVM >= 0x0304) {
-      MAttrs.push_back(util_cpu_caps.has_fma  ? "+fma"  : "-fma");
-   } else {
-      /*
-       * The old JIT in LLVM 3.3 has a bug encoding llvm.fmuladd.f32 and
-       * llvm.fmuladd.v2f32 intrinsics when FMA is available.
-       */
-      MAttrs.push_back("-fma");
-   }
-   MAttrs.push_back(util_cpu_caps.has_avx2 ? "+avx2" : "-avx2");
-   /* disable avx512 and all subvariants */
-#if HAVE_LLVM >= 0x0304
-   MAttrs.push_back("-avx512cd");
-   MAttrs.push_back("-avx512er");
-   MAttrs.push_back("-avx512f");
-   MAttrs.push_back("-avx512pf");
-#endif
-#if HAVE_LLVM >= 0x0305
-   MAttrs.push_back("-avx512bw");
-   MAttrs.push_back("-avx512dq");
-   MAttrs.push_back("-avx512vl");
-#endif
-#endif
 #endif
 
 #if defined(PIPE_ARCH_PPC)
    MAttrs.push_back(util_cpu_caps.has_altivec ? "+altivec" : "-altivec");
-#if (HAVE_LLVM >= 0x0304)
-#if (HAVE_LLVM < 0x0400)
-   /*
-    * Make sure VSX instructions are disabled
-    * See LLVM bugs:
-    * https://llvm.org/bugs/show_bug.cgi?id=25503#c7 (fixed in 3.8.1)
-    * https://llvm.org/bugs/show_bug.cgi?id=26775 (fixed in 3.8.1)
-    * https://llvm.org/bugs/show_bug.cgi?id=33531 (fixed in 4.0)
-    * https://llvm.org/bugs/show_bug.cgi?id=34647 (llc performance on certain unusual shader IR; intro'd in 4.0, pending as of 5.0)
-    */
-   if (util_cpu_caps.has_altivec) {
-      MAttrs.push_back("-vsx");
-   }
-#else
    /*
     * Bug 25503 is fixed, by the same fix that fixed
     * bug 26775, in versions of LLVM later than 3.8 (starting with 3.8.1).
@@ -656,8 +357,6 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
    if (util_cpu_caps.has_altivec) {
       MAttrs.push_back(util_cpu_caps.has_vsx ? "+vsx" : "-vsx");
    }
-#endif
-#endif
 #endif
 
    builder.setMAttrs(MAttrs);
@@ -672,7 +371,6 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
       }
    }
 
-#if HAVE_LLVM >= 0x0305
    StringRef MCPU = llvm::sys::getHostCPUName();
    /*
     * The cpu bits are no longer set automatically, so need to set mcpu manually.
@@ -698,37 +396,21 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
     */
    if (MCPU == "generic")
       MCPU = "pwr8";
+   // XXX: nuke the above workaround?
 #endif
    builder.setMCPU(MCPU);
    if (gallivm_debug & (GALLIVM_DEBUG_IR | GALLIVM_DEBUG_ASM | GALLIVM_DEBUG_DUMP_BC)) {
       debug_printf("llc -mcpu option: %s\n", MCPU.str().c_str());
    }
-#endif
 
    ShaderMemoryManager *MM = NULL;
-   if (useMCJIT) {
+   {
        BaseMemoryManager* JMM = reinterpret_cast<BaseMemoryManager*>(CMM);
        MM = new ShaderMemoryManager(JMM);
        *OutCode = MM->getGeneratedCode();
 
-#if HAVE_LLVM >= 0x0306
        builder.setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager>(MM));
        MM = NULL; // ownership taken by std::unique_ptr
-#elif HAVE_LLVM > 0x0303
-       builder.setMCJITMemoryManager(MM);
-#else
-       builder.setJITMemoryManager(MM);
-#endif
-   } else {
-#if HAVE_LLVM < 0x0306
-       BaseMemoryManager* JMM = reinterpret_cast<BaseMemoryManager*>(CMM);
-       MM = new ShaderMemoryManager(JMM);
-       *OutCode = MM->getGeneratedCode();
-
-       builder.setJITMemoryManager(MM);
-#else
-       assert(0);
-#endif
    }
 
    ExecutionEngine *JIT;
@@ -762,11 +444,7 @@ LLVMMCJITMemoryManagerRef
 lp_get_default_memory_manager()
 {
    BaseMemoryManager *mm;
-#if HAVE_LLVM < 0x0306
-   mm = llvm::JITMemoryManager::CreateDefaultMemManager();
-#else
    mm = new llvm::SectionMemoryManager();
-#endif
    return reinterpret_cast<LLVMMCJITMemoryManagerRef>(mm);
 }
 
@@ -780,21 +458,11 @@ lp_free_memory_manager(LLVMMCJITMemoryManagerRef memorymgr)
 extern "C" LLVMValueRef
 lp_get_called_value(LLVMValueRef call)
 {
-#if HAVE_LLVM >= 0x0309
 	return LLVMGetCalledValue(call);
-#elif HAVE_LLVM >= 0x0305
-	return llvm::wrap(llvm::CallSite(llvm::unwrap<llvm::Instruction>(call)).getCalledValue());
-#else
-	return NULL; /* radeonsi doesn't support so old LLVM. */
-#endif
 }
 
 extern "C" bool
 lp_is_function(LLVMValueRef v)
 {
-#if HAVE_LLVM >= 0x0309
 	return LLVMGetValueKind(v) == LLVMFunctionValueKind;
-#else
-	return llvm::isa<llvm::Function>(llvm::unwrap(v));
-#endif
 }
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
index ca5ba5c44f2..2b2e866ae99 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.h
@@ -58,7 +58,6 @@ lp_build_create_jit_compiler_for_module(LLVMExecutionEngineRef *OutJIT,
                                         LLVMModuleRef M,
                                         LLVMMCJITMemoryManagerRef MM,
                                         unsigned OptLevel,
-                                        int useMCJIT,
                                         char **OutError);
 
 extern void
-- 
2.19.1



More information about the mesa-dev mailing list