clover: set LLVM min version to 8.0.1
authorSerge Martin <edb@sigluy.net>
Sun, 23 Aug 2020 05:57:12 +0000 (07:57 +0200)
committerSerge Martin <edb@sigluy.net>
Sat, 26 Sep 2020 09:06:42 +0000 (11:06 +0200)
It also bump from 8.0.0 to .1 for AMD gallium and VK

Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6336>

.gitlab-ci.yml
meson.build
src/gallium/frontends/clover/llvm/codegen/bitcode.cpp
src/gallium/frontends/clover/llvm/codegen/common.cpp
src/gallium/frontends/clover/llvm/codegen/native.cpp
src/gallium/frontends/clover/llvm/compat.hpp
src/gallium/frontends/clover/llvm/invocation.cpp

index 2af0ee8..0f2b55a 100644 (file)
@@ -787,25 +787,6 @@ meson-clover:
     - .gitlab-ci/meson-build.sh
     - LLVM_VERSION=8 .gitlab-ci/meson-build.sh
 
-meson-clover-old-llvm:
-  extends:
-    - meson-clover
-    - .use-x86_build_old
-  variables:
-    UNWIND: "disabled"
-    DRI_LOADERS: >
-      -D glx=disabled
-      -D egl=disabled
-      -D gbm=disabled
-      -D platforms=[]
-    GALLIUM_DRIVERS: "i915,r600"
-  script:
-    - LLVM_VERSION=3.9 .gitlab-ci/meson-build.sh
-    - LLVM_VERSION=4.0 .gitlab-ci/meson-build.sh
-    - LLVM_VERSION=5.0 .gitlab-ci/meson-build.sh
-    - LLVM_VERSION=6.0 .gitlab-ci/meson-build.sh
-    - LLVM_VERSION=7 .gitlab-ci/meson-build.sh
-
 meson-vulkan:
   extends: .meson-build
   variables:
index 50e105e..76f72a9 100644 (file)
@@ -1450,8 +1450,7 @@ if with_gallium_opencl
   ]
 endif
 
-with_opencl_spirv = _opencl != 'disabled' and get_option('opencl-spirv')
-if with_amd_vk or with_gallium_radeonsi or with_opencl_spirv
+if with_amd_vk or with_gallium_radeonsi or with_gallium_opencl
   _llvm_version = '>= 8.0.0'
 elif with_gallium_swr
   _llvm_version = '>= 6.0.0'
@@ -1545,6 +1544,7 @@ elif with_gallium_opencl
   error('The OpenCL "Clover" state tracker requires LLVM, but LLVM is disabled.')
 endif
 
+with_opencl_spirv = _opencl != 'disabled' and get_option('opencl-spirv')
 if with_opencl_spirv
   chosen_llvm_version_array = dep_llvm.version().split('.')
   chosen_llvm_version_major = chosen_llvm_version_array[0].to_int()
index 7434e8c..413f110 100644 (file)
@@ -55,7 +55,7 @@ namespace {
    emit_code(const ::llvm::Module &mod) {
       ::llvm::SmallVector<char, 1024> data;
       ::llvm::raw_svector_ostream os { data };
-      compat::write_bitcode_to_file(mod, os);
+      ::llvm::WriteBitcodeToFile(mod, os);
       return { os.str().begin(), os.str().end() };
    }
 }
@@ -83,9 +83,11 @@ clover::llvm::parse_module_library(const module &m, ::llvm::LLVMContext &ctx,
    auto mod = ::llvm::parseBitcodeFile(::llvm::MemoryBufferRef(
                                         as_string(m.secs[0].data), " "), ctx);
 
-   compat::handle_module_error(mod, [&](const std::string &s) {
-         fail(r_log, error(CL_INVALID_PROGRAM), s);
+   if (::llvm::Error err = mod.takeError()) {
+      ::llvm::handleAllErrors(std::move(err), [&](::llvm::ErrorInfoBase &eib) {
+         fail(r_log, error(CL_INVALID_PROGRAM), eib.message());
       });
+   }
 
    return std::unique_ptr< ::llvm::Module>(std::move(*mod));
 }
index 730ba5a..3404087 100644 (file)
@@ -82,12 +82,10 @@ namespace {
          // type that is not a power of two bytes in size must be
          // aligned to the next larger power of two.
          // This rule applies to built-in types only, not structs or unions."
-         const unsigned arg_store_size = dl.getTypeStoreSize(arg_type);
          const unsigned arg_api_size = dl.getTypeAllocSize(arg_type);
 
-         const auto target_type = compat::get_abi_type(arg_type, mod);
-         const unsigned target_size = dl.getTypeStoreSize(target_type);
-         const unsigned target_align = dl.getABITypeAlignment(target_type);
+         const unsigned target_size = dl.getTypeStoreSize(arg_type);
+         const unsigned target_align = dl.getABITypeAlignment(arg_type);
 
          const auto type_name = get_argument_metadata(f, arg,
                                                       "kernel_arg_type");
@@ -97,7 +95,7 @@ namespace {
             const auto access_qual = get_argument_metadata(
                f, arg, "kernel_arg_access_qual");
             args.emplace_back(get_image_type(type_name, access_qual),
-                              arg_store_size, target_size,
+                              target_size, target_size,
                               target_align, module::argument::zero_ext);
 
          } else if (type_name == "__llvm_image_size") {
@@ -126,8 +124,10 @@ namespace {
                const unsigned address_space =
                   cast< ::llvm::PointerType>(actual_type)->getAddressSpace();
 
-               if (address_space == compat::target_address_space(
-                                  c.getTarget(), clang::LangAS::opencl_local)) {
+               const auto &map = c.getTarget().getAddressSpaceMap();
+               const auto offset =
+                           static_cast<unsigned>(clang::LangAS::opencl_local);
+               if (address_space == map[offset]) {
                   args.emplace_back(module::argument::local, arg_api_size,
                                     target_size, target_align,
                                     module::argument::zero_ext);
index 5234613..bc07fc3 100644 (file)
@@ -114,7 +114,7 @@ namespace {
 
       std::unique_ptr<TargetMachine> tm {
          t->createTargetMachine(target.triple, target.cpu, "", {},
-                                ::llvm::None, compat::default_code_model,
+                                ::llvm::None, ::llvm::None,
                                 ::llvm::CodeGenOpt::Default) };
       if (!tm)
          fail(r_log, build_error(),
@@ -130,7 +130,7 @@ namespace {
          tm->Options.MCOptions.AsmVerbose =
             (ft == compat::CGFT_AssemblyFile);
 
-         if (compat::add_passes_to_emit_file(*tm, pm, os, ft))
+         if (tm->addPassesToEmitFile(pm, os, nullptr, ft))
             fail(r_log, build_error(), "TargetMachine can't emit this file");
 
          pm.run(mod);
@@ -154,7 +154,7 @@ clover::llvm::print_module_native(const ::llvm::Module &mod,
                                   const target &target) {
    std::string log;
    try {
-      std::unique_ptr< ::llvm::Module> cmod { compat::clone_module(mod) };
+      std::unique_ptr< ::llvm::Module> cmod { ::llvm::CloneModule(mod) };
       return as_string(emit_code(*cmod, target,
                                  compat::CGFT_AssemblyFile, log));
    } catch (...) {
index 5190273..78eb8c9 100644 (file)
 #include "util/algorithm.hpp"
 
 #include <llvm/Config/llvm-config.h>
-#if LLVM_VERSION_MAJOR < 4
-#include <llvm/Bitcode/ReaderWriter.h>
-#else
-#include <llvm/Bitcode/BitcodeReader.h>
-#include <llvm/Bitcode/BitcodeWriter.h>
-#endif
 
 #include <llvm/IR/LLVMContext.h>
 #include <llvm/Linker/Linker.h>
 #include <llvm/Transforms/IPO.h>
 #include <llvm/Transforms/Utils/Cloning.h>
 #include <llvm/Target/TargetMachine.h>
-#if LLVM_VERSION_MAJOR >= 4
-#include <llvm/Support/Error.h>
-#else
-#include <llvm/Support/ErrorOr.h>
-#endif
 
 #include <llvm/IR/LegacyPassManager.h>
 #include <llvm/Analysis/TargetLibraryInfo.h>
 #include <clang/Basic/TargetInfo.h>
 #include <clang/Frontend/CompilerInstance.h>
 
-#if LLVM_VERSION_MAJOR >= 8
-#include <clang/Basic/CodeGenOptions.h>
-#else
-#include <clang/Frontend/CodeGenOptions.h>
-#endif
-
 #if LLVM_VERSION_MAJOR >= 10
 #include <llvm/Support/CodeGen.h>
 #endif
@@ -86,103 +69,11 @@ namespace clover {
          typedef ::llvm::TargetMachine::CodeGenFileType CodeGenFileType;
 #endif
 
-         template<typename T, typename AS>
-         unsigned target_address_space(const T &target, const AS lang_as) {
-            const auto &map = target.getAddressSpaceMap();
-#if LLVM_VERSION_MAJOR >= 5
-            return map[static_cast<unsigned>(lang_as)];
-#else
-            return map[lang_as - clang::LangAS::Offset];
-#endif
-         }
-
 #if LLVM_VERSION_MAJOR >= 10
          const clang::InputKind ik_opencl = clang::Language::OpenCL;
-#elif LLVM_VERSION_MAJOR >= 5
-         const clang::InputKind ik_opencl = clang::InputKind::OpenCL;
-#else
-         const clang::InputKind ik_opencl = clang::IK_OpenCL;
-#endif
-
-#if LLVM_VERSION_MAJOR >= 5
-         const clang::LangStandard::Kind lang_opencl10 = clang::LangStandard::lang_opencl10;
-#else
-         const clang::LangStandard::Kind lang_opencl10 = clang::LangStandard::lang_opencl;
-#endif
-
-         inline void
-         add_link_bitcode_file(clang::CodeGenOptions &opts,
-                               const std::string &path) {
-#if LLVM_VERSION_MAJOR >= 5
-            clang::CodeGenOptions::BitcodeFileToLink F;
-
-            F.Filename = path;
-            F.PropagateAttrs = true;
-            F.LinkFlags = ::llvm::Linker::Flags::None;
-            opts.LinkBitcodeFiles.emplace_back(F);
-#else
-            opts.LinkBitcodeFiles.emplace_back(::llvm::Linker::Flags::None, path);
-#endif
-         }
-
-#if LLVM_VERSION_MAJOR >= 6
-         const auto default_code_model = ::llvm::None;
-#else
-         const auto default_code_model = ::llvm::CodeModel::Default;
-#endif
-
-         template<typename M, typename F> void
-         handle_module_error(M &mod, const F &f) {
-#if LLVM_VERSION_MAJOR >= 4
-            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
-         }
-
-         template<typename T> void
-         set_diagnostic_handler(::llvm::LLVMContext &ctx,
-                                T *diagnostic_handler, void *data) {
-#if LLVM_VERSION_MAJOR >= 6
-            ctx.setDiagnosticHandlerCallBack(diagnostic_handler, data);
-#else
-            ctx.setDiagnosticHandler(diagnostic_handler, data);
-#endif
-         }
-
-         inline std::unique_ptr< ::llvm::Module>
-         clone_module(const ::llvm::Module &mod)
-         {
-#if LLVM_VERSION_MAJOR >= 7
-            return ::llvm::CloneModule(mod);
-#else
-            return ::llvm::CloneModule(&mod);
-#endif
-         }
-
-         template<typename T> void
-         write_bitcode_to_file(const ::llvm::Module &mod, T &os)
-         {
-#if LLVM_VERSION_MAJOR >= 7
-            ::llvm::WriteBitcodeToFile(mod, os);
-#else
-            ::llvm::WriteBitcodeToFile(&mod, os);
-#endif
-         }
-
-         template<typename TM, typename PM, typename OS, typename FT>
-         bool add_passes_to_emit_file(TM &tm, PM &pm, OS &os, FT &ft)
-         {
-#if LLVM_VERSION_MAJOR >= 7
-            return tm.addPassesToEmitFile(pm, os, nullptr, ft);
-#else
-            return tm.addPassesToEmitFile(pm, os, ft);
+         const clang::InputKind ik_opencl = clang::InputKind::OpenCL;
 #endif
-         }
 
          template<typename T> inline bool
          create_compiler_invocation_from_args(clang::CompilerInvocation &cinv,
@@ -197,18 +88,6 @@ namespace clover {
                cinv, copts.data(), copts.data() + copts.size(), diag);
 #endif
          }
-
-         template<typename T, typename M>
-         T get_abi_type(const T &arg_type, const M &mod) {
-#if LLVM_VERSION_MAJOR >= 7
-            return arg_type;
-#else
-            ::llvm::DataLayout dl(&mod);
-            const unsigned arg_store_size = dl.getTypeStoreSize(arg_type);
-            return !arg_type->isIntegerTy() ? arg_type :
-               dl.getSmallestLegalIntType(mod.getContext(), arg_store_size * 8);
-#endif
-         }
       }
    }
 }
index 173894f..2516de0 100644 (file)
@@ -91,7 +91,7 @@ namespace {
     };
 
     const clc_version_lang_std cl_version_lang_stds[] = {
-       { 100, compat::lang_opencl10},
+       { 100, clang::LangStandard::lang_opencl10},
        { 110, clang::LangStandard::lang_opencl11},
        { 120, clang::LangStandard::lang_opencl12},
        { 200, clang::LangStandard::lang_opencl20},
@@ -124,7 +124,8 @@ namespace {
    create_context(std::string &r_log) {
       init_targets();
       std::unique_ptr<LLVMContext> ctx { new LLVMContext };
-      compat::set_diagnostic_handler(*ctx, diagnostic_handler, &r_log);
+
+      ctx->setDiagnosticHandlerCallBack(diagnostic_handler, &r_log);
       return ctx;
    }
 
@@ -296,9 +297,14 @@ namespace {
       // attribute will prevent Clang from creating illegal uses of
       // barrier() (e.g. Moving barrier() inside a conditional that is
       // no executed by all threads) during its optimizaton passes.
-      if (use_libclc)
-         compat::add_link_bitcode_file(c.getCodeGenOpts(),
-                                       LIBCLC_LIBEXECDIR + dev.ir_target() + ".bc");
+      if (use_libclc) {
+         clang::CodeGenOptions::BitcodeFileToLink F;
+
+         F.Filename = LIBCLC_LIBEXECDIR + dev.ir_target() + ".bc";
+         F.PropagateAttrs = true;
+         F.LinkFlags = ::llvm::Linker::Flags::None;
+         c.getCodeGenOpts().LinkBitcodeFiles.emplace_back(F);
+      }
 
       // undefine __IMAGE_SUPPORT__ for device without image support
       if (!dev.image_support())