clover: Cleanup compat code for llvm < 3.9
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu> Reviewed-By: Aaron Watry <awatry@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
@@ -95,19 +82,6 @@ namespace clover {
|
||||
const clang::LangStandard::Kind lang_opencl10 = clang::LangStandard::lang_opencl;
|
||||
#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) {
|
||||
@@ -118,78 +92,8 @@ namespace clover {
|
||||
F.PropagateAttrs = true;
|
||||
F.LinkFlags = ::llvm::Linker::Flags::None;
|
||||
opts.LinkBitcodeFiles.emplace_back(F);
|
||||
#elif HAVE_LLVM >= 0x0308
|
||||
#else
|
||||
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();
|
||||
#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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user