clover: Restore support for LLVM <= 3.9.
authorVedran Miletić <vedran@miletic.net>
Tue, 22 Nov 2016 19:25:34 +0000 (20:25 +0100)
committerFrancisco Jerez <currojerez@riseup.net>
Fri, 25 Nov 2016 00:40:29 +0000 (16:40 -0800)
The commit 8e430ff8b060b4e8e922bae24b3c57837da6ea77 broke support for
LLVM 3.9 and older versions in Clover. This patch restores it and
refactors the support using Clover compatibility layer for LLVM.

v2: merged #ifdef blocks
v3: added support for LLVM 3.6-3.8
v4: add missing #ifdef around <memory>
v5: simplify using templates and lambda

Signed-off-by: Vedran Miletić <vedran@miletic.net>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=98740
Tested-by[v4]: Pierre Moreau <pierre.morrow@free.fr>
Tested-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Reviewed-by: Jan Vesely <jan.vesely@rutgers.edu>
src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
src/gallium/state_trackers/clover/llvm/compat.hpp

index 5dcc4f8a48c9793b42fa6f43d9239a9edfc4f305..d09207b946a2420ee9158be87992caffe7b3acc7 100644 (file)
@@ -32,6 +32,7 @@
 ///
 
 #include "llvm/codegen.hpp"
+#include "llvm/compat.hpp"
 #include "llvm/metadata.hpp"
 #include "core/error.hpp"
 #include "util/algorithm.hpp"
@@ -99,13 +100,9 @@ clover::llvm::parse_module_library(const module &m, ::llvm::LLVMContext &ctx,
    auto mod = ::llvm::parseBitcodeFile(::llvm::MemoryBufferRef(
                                         as_string(m.secs[0].data), " "), ctx);
 
-   if (::llvm::Error err = mod.takeError()) {
-      std::string msg;
-      ::llvm::handleAllErrors(std::move(err), [&](::llvm::ErrorInfoBase &EIB) {
-         msg = EIB.message();
-         fail(r_log, error(CL_INVALID_PROGRAM), msg.c_str());
+   compat::handle_module_error(mod, [&](const std::string &s) {
+         fail(r_log, error(CL_INVALID_PROGRAM), s);
       });
-   }
 
    return std::unique_ptr<::llvm::Module>(std::move(*mod));
 }
index a963cffa827900d261bf014ac1db785baae2228a..81592ce7021762892ac1f9e1c134e8785d324970 100644 (file)
 #include <llvm/Linker/Linker.h>
 #include <llvm/Transforms/IPO.h>
 #include <llvm/Target/TargetMachine.h>
+#if HAVE_LLVM >= 0x0400
+#include <llvm/Support/Error.h>
+#else
+#include <llvm/Support/ErrorOr.h>
+#endif
 
 #if HAVE_LLVM >= 0x0307
 #include <llvm/IR/LegacyPassManager.h>
@@ -158,6 +163,19 @@ namespace clover {
 #else
          const auto default_reloc_model = ::llvm::Reloc::Default;
 #endif
+
+         template<typename M, typename F> void
+         handle_module_error(M &mod, const F &f) {
+#if HAVE_LLVM >= 0x0400
+            if (::llvm::Error err = mod.takeError())
+               ::llvm::handleAllErrors(std::move(err), [&](::llvm::ErrorInfoBase &eib) {
+                     f(eib.message());
+                  });
+#else
+            if (!mod)
+               f(mod.getError().message());
+#endif
+         }
       }
    }
 }