diff options
author | Jan Vesely <[email protected]> | 2018-05-22 18:27:39 -0400 |
---|---|---|
committer | Jan Vesely <[email protected]> | 2018-05-29 17:36:16 -0400 |
commit | 41b878e1bd9e6215f57722d61b158f6b428a0d78 (patch) | |
tree | fb8605aa1fa65a7aa0ce7cef0258994e4f78dbbf /src/gallium/state_trackers/clover | |
parent | d424be0feda503307692db8447f5989fa8e4a843 (diff) |
clover: Cleanup compat code for llvm < 3.9
Signed-off-by: Jan Vesely <[email protected]>
Reviewed-By: Aaron Watry <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/clover')
-rw-r--r-- | src/gallium/state_trackers/clover/llvm/codegen/native.cpp | 7 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/llvm/compat.hpp | 109 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/llvm/invocation.cpp | 25 |
3 files changed, 20 insertions, 121 deletions
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp index 21f6c8c88a8..b8ed01c7289 100644 --- a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp +++ b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp @@ -114,8 +114,7 @@ namespace { std::unique_ptr<TargetMachine> tm { t->createTargetMachine(target.triple, target.cpu, "", {}, - compat::default_reloc_model, - compat::default_code_model, + ::llvm::None, compat::default_code_model, ::llvm::CodeGenOpt::Default) }; if (!tm) fail(r_log, build_error(), @@ -124,10 +123,10 @@ namespace { ::llvm::SmallVector<char, 1024> data; { - compat::pass_manager pm; + ::llvm::legacy::PassManager pm; ::llvm::raw_svector_ostream os { data }; - mod.setDataLayout(compat::get_data_layout(*tm)); + mod.setDataLayout(tm->createDataLayout()); tm->Options.MCOptions.AsmVerbose = (ft == TargetMachine::CGFT_AssemblyFile); diff --git a/src/gallium/state_trackers/clover/llvm/compat.hpp b/src/gallium/state_trackers/clover/llvm/compat.hpp index 42a671b7fa3..60270d15293 100644 --- a/src/gallium/state_trackers/clover/llvm/compat.hpp +++ b/src/gallium/state_trackers/clover/llvm/compat.hpp @@ -54,15 +54,8 @@ #include <llvm/Support/ErrorOr.h> #endif -#if HAVE_LLVM >= 0x0307 #include <llvm/IR/LegacyPassManager.h> #include <llvm/Analysis/TargetLibraryInfo.h> -#else -#include <llvm/PassManager.h> -#include <llvm/Target/TargetLibraryInfo.h> -#include <llvm/Target/TargetSubtargetInfo.h> -#include <llvm/Support/FormattedStream.h> -#endif #include <clang/Basic/TargetInfo.h> #include <clang/Frontend/CodeGenOptions.h> @@ -71,12 +64,6 @@ namespace clover { namespace llvm { namespace compat { -#if HAVE_LLVM >= 0x0307 - typedef ::llvm::TargetLibraryInfoImpl target_library_info; -#else - typedef ::llvm::TargetLibraryInfo target_library_info; -#endif - template<typename T, typename AS> unsigned target_address_space(const T &target, const AS lang_as) { const auto &map = target.getAddressSpaceMap(); @@ -96,19 +83,6 @@ namespace clover { #endif inline void - set_lang_defaults(clang::CompilerInvocation &inv, - clang::LangOptions &lopts, clang::InputKind ik, - const ::llvm::Triple &t, - clang::PreprocessorOptions &ppopts, - clang::LangStandard::Kind std) { -#if HAVE_LLVM >= 0x0309 - inv.setLangDefaults(lopts, ik, t, ppopts, std); -#else - inv.setLangDefaults(lopts, ik, std); -#endif - } - - inline void add_link_bitcode_file(clang::CodeGenOptions &opts, const std::string &path) { #if HAVE_LLVM >= 0x0500 @@ -118,78 +92,8 @@ namespace clover { F.PropagateAttrs = true; F.LinkFlags = ::llvm::Linker::Flags::None; opts.LinkBitcodeFiles.emplace_back(F); -#elif HAVE_LLVM >= 0x0308 - opts.LinkBitcodeFiles.emplace_back(::llvm::Linker::Flags::None, path); -#else - opts.LinkBitcodeFile = path; -#endif - } - -#if HAVE_LLVM >= 0x0307 - typedef ::llvm::legacy::PassManager pass_manager; -#else - typedef ::llvm::PassManager pass_manager; -#endif - - inline void - add_data_layout_pass(pass_manager &pm) { -#if HAVE_LLVM < 0x0307 - pm.add(new ::llvm::DataLayoutPass()); -#endif - } - - inline void - add_internalize_pass(pass_manager &pm, - const std::vector<std::string> &names) { -#if HAVE_LLVM >= 0x0309 - pm.add(::llvm::createInternalizePass( - [=](const ::llvm::GlobalValue &gv) { - return std::find(names.begin(), names.end(), - gv.getName()) != names.end(); - })); #else - pm.add(::llvm::createInternalizePass(std::vector<const char *>( - map(std::mem_fn(&std::string::data), names)))); -#endif - } - - inline std::unique_ptr< ::llvm::Linker> - create_linker(::llvm::Module &mod) { -#if HAVE_LLVM >= 0x0308 - return std::unique_ptr< ::llvm::Linker>(new ::llvm::Linker(mod)); -#else - return std::unique_ptr< ::llvm::Linker>(new ::llvm::Linker(&mod)); -#endif - } - - inline bool - link_in_module(::llvm::Linker &linker, - std::unique_ptr< ::llvm::Module> mod) { -#if HAVE_LLVM >= 0x0308 - return linker.linkInModule(std::move(mod)); -#else - return linker.linkInModule(mod.get()); -#endif - } - -#if HAVE_LLVM >= 0x0307 - typedef ::llvm::raw_svector_ostream &raw_ostream_to_emit_file; -#else - typedef ::llvm::formatted_raw_ostream raw_ostream_to_emit_file; -#endif - -#if HAVE_LLVM >= 0x0307 - typedef ::llvm::DataLayout data_layout; -#else - typedef const ::llvm::DataLayout *data_layout; -#endif - - inline data_layout - get_data_layout(::llvm::TargetMachine &tm) { -#if HAVE_LLVM >= 0x0307 - return tm.createDataLayout(); -#else - return tm.getSubtargetImpl()->getDataLayout(); + opts.LinkBitcodeFiles.emplace_back(::llvm::Linker::Flags::None, path); #endif } @@ -199,12 +103,6 @@ namespace clover { const auto default_code_model = ::llvm::CodeModel::Default; #endif -#if HAVE_LLVM >= 0x0309 - const auto default_reloc_model = ::llvm::None; -#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 @@ -251,11 +149,10 @@ namespace clover { template<typename TM, typename PM, typename OS, typename FT> bool add_passes_to_emit_file(TM &tm, PM &pm, OS &os, FT &ft) { - compat::raw_ostream_to_emit_file fos(os); #if HAVE_LLVM >= 0x0700 - return tm.addPassesToEmitFile(pm, fos, nullptr, ft); + return tm.addPassesToEmitFile(pm, os, nullptr, ft); #else - return tm.addPassesToEmitFile(pm, fos, ft); + return tm.addPassesToEmitFile(pm, os, ft); #endif } } diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp index b2c64bc48f8..0a677ce2eaa 100644 --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp @@ -216,7 +216,7 @@ namespace { // http://www.llvm.org/bugs/show_bug.cgi?id=19735 c->getDiagnosticOpts().ShowCarets = false; - compat::set_lang_defaults(c->getInvocation(), c->getLangOpts(), + c->getInvocation().setLangDefaults(c->getLangOpts(), compat::ik_opencl, ::llvm::Triple(target.triple), c->getPreprocessorOpts(), get_language_version(opts, device_clc_version)); @@ -314,9 +314,7 @@ namespace { void optimize(Module &mod, unsigned optimization_level, bool internalize_symbols) { - compat::pass_manager pm; - - compat::add_data_layout_pass(pm); + ::llvm::legacy::PassManager pm; // By default, the function internalizer pass will look for a function // called "main" and then mark all other functions as internal. Marking @@ -330,13 +328,19 @@ namespace { // list of kernel functions to the internalizer. The internalizer will // treat the functions in the list as "main" functions and internalize // all of the other functions. - if (internalize_symbols) - compat::add_internalize_pass(pm, map(std::mem_fn(&Function::getName), - get_kernels(mod))); + if (internalize_symbols) { + std::vector<std::string> names = + map(std::mem_fn(&Function::getName), get_kernels(mod)); + pm.add(::llvm::createInternalizePass( + [=](const ::llvm::GlobalValue &gv) { + return std::find(names.begin(), names.end(), + gv.getName()) != names.end(); + })); + } ::llvm::PassManagerBuilder pmb; pmb.OptLevel = optimization_level; - pmb.LibraryInfo = new compat::target_library_info( + pmb.LibraryInfo = new ::llvm::TargetLibraryInfoImpl( ::llvm::Triple(mod.getTargetTriple())); pmb.populateModulePassManager(pm); pm.run(mod); @@ -346,11 +350,10 @@ namespace { link(LLVMContext &ctx, const clang::CompilerInstance &c, const std::vector<module> &modules, std::string &r_log) { std::unique_ptr<Module> mod { new Module("link", ctx) }; - auto linker = compat::create_linker(*mod); + std::unique_ptr< ::llvm::Linker> linker { new ::llvm::Linker(*mod) }; for (auto &m : modules) { - if (compat::link_in_module(*linker, - parse_module_library(m, ctx, r_log))) + if (linker->linkInModule(parse_module_library(m, ctx, r_log))) throw build_error(); } |