[Mesa-dev] [PATCH] clover: restore support for LLVM <= 3.9

Jan Vesely jan.vesely at rutgers.edu
Tue Nov 15 07:48:38 UTC 2016


On Tue, 2016-11-15 at 05:32 +0100, Vedran Miletić wrote:
> The commit 8e430ff8b060b4e8e922bae24b3c57837da6ea77 broke 3.9 and older
> versions of LLVM for Clover. This patch restores it and refactors the
> support using Clover compatibility layer for LLVM.
> 
> Signed-off-by: Vedran Miletić <vedran at miletic.net>
> ---
>  .../state_trackers/clover/llvm/codegen/bitcode.cpp |  9 ++-----
>  src/gallium/state_trackers/clover/llvm/compat.hpp  | 30 ++++++++++++++++++++++
>  2 files changed, 32 insertions(+), 7 deletions(-)
> 
> diff --git a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
> index 5dcc4f8..4b4ae41 100644
> --- a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
> +++ b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp
> @@ -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,7 @@ 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, r_log);
>  
>     return std::unique_ptr<::llvm::Module>(std::move(*mod));
>  }
> diff --git a/src/gallium/state_trackers/clover/llvm/compat.hpp b/src/gallium/state_trackers/clover/llvm/compat.hpp
> index a963cff..83b3a74 100644
> --- a/src/gallium/state_trackers/clover/llvm/compat.hpp
> +++ b/src/gallium/state_trackers/clover/llvm/compat.hpp
> @@ -39,6 +39,10 @@
>  #include <llvm/Linker/Linker.h>
>  #include <llvm/Transforms/IPO.h>
>  #include <llvm/Target/TargetMachine.h>
> +#include <llvm/Support/Error.h>
> +#if HAVE_LLVM < 0x0400
> +#include <llvm/Support/ErrorOr.h>
> +#endif
>  
>  #if HAVE_LLVM >= 0x0307
>  #include <llvm/IR/LegacyPassManager.h>
> @@ -53,6 +57,12 @@
>  #include <clang/Frontend/CodeGenOptions.h>
>  #include <clang/Frontend/CompilerInstance.h>
>  
> +#include <memory>
> +
> +namespace llvm {
> +   class Module;
> +}
> +
>  namespace clover {
>     namespace llvm {
>        namespace compat {
> @@ -158,6 +168,26 @@ namespace clover {
>  #else
>           const auto default_reloc_model = ::llvm::Reloc::Default;
>  #endif
> +         inline void
> +#if HAVE_LLVM >= 0x0400
> +         handle_module_error(::llvm::Expected<std::unique_ptr<::llvm::Module>> &mod,
> +#else
> +         handle_module_error(::llvm::ErrorOr<std::unique_ptr<::llvm::Module>> &mod,
> +#endif
> +                             std::string &r_log) {

can you merge the ifdef blocks? sharing one line of code is not worth
the hit in readability.

Jan

> +#if HAVE_LLVM >= 0x0400
> +            if (::llvm::Error err = mod.takeError()) {
> +               ::llvm::handleAllErrors(std::move(err), [&](::llvm::ErrorInfoBase &EIB) {
> +                  fail(r_log, error(CL_INVALID_PROGRAM), EIB.message().c_str());
> +               });
> +            }
> +#else
> +            if (!mod)
> +               fail(r_log, error(CL_INVALID_PROGRAM), mod.getError().message());
> +#endif
> +         }
> +
> +
>        }
>     }
>  }

-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161115/b9603b2e/attachment.sig>


More information about the mesa-dev mailing list