summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2016-06-13 01:41:05 -0700
committerFrancisco Jerez <[email protected]>2016-07-11 20:34:34 -0700
commit9de3f4a59f2f588368a5994a9fe49d4136393852 (patch)
tree48ba7635a1f29c81c146569f707da83dd0e9e3cf
parent132b6ccd4f81eac3cad5bef42325319708498240 (diff)
clover/llvm: Implement linkage of multiple clover modules.
Reviewed-by: Serge Martin <[email protected]> Tested-by: Jan Vesely <[email protected]>
-rw-r--r--src/gallium/state_trackers/clover/llvm/compat.hpp19
-rw-r--r--src/gallium/state_trackers/clover/llvm/invocation.cpp19
2 files changed, 35 insertions, 3 deletions
diff --git a/src/gallium/state_trackers/clover/llvm/compat.hpp b/src/gallium/state_trackers/clover/llvm/compat.hpp
index 82dd649837c..a963cffa827 100644
--- a/src/gallium/state_trackers/clover/llvm/compat.hpp
+++ b/src/gallium/state_trackers/clover/llvm/compat.hpp
@@ -113,6 +113,25 @@ namespace clover {
#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
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index 3bb7d72a4f4..6560b89d1f5 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -229,6 +229,21 @@ namespace {
pmb.populateModulePassManager(pm);
pm.run(mod);
}
+
+ std::unique_ptr<Module>
+ 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);
+
+ for (auto &m : modules) {
+ if (compat::link_in_module(*linker,
+ parse_module_library(m, ctx, r_log)))
+ throw compile_error();
+ }
+
+ return std::move(mod);
+ }
}
module
@@ -238,9 +253,7 @@ clover::llvm::link_program(const std::vector<module> &modules,
std::vector<std::string> options = tokenize(opts + " input.cl");
auto ctx = create_context(r_log);
auto c = create_compiler_instance(target, options, r_log);
- // XXX - Implement linkage of multiple clover modules.
- assert(modules.size() == 1);
- auto mod = parse_module_library(modules[0], *ctx, r_log);
+ auto mod = link(*ctx, *c, modules, r_log);
optimize(*mod, c->getCodeGenOpts().OptimizationLevel);