diff options
author | Francisco Jerez <[email protected]> | 2016-05-17 16:03:03 +0200 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2016-07-11 20:34:34 -0700 |
commit | 1a7d11aa3dc65e89f0d801707951afc32cbaa6ee (patch) | |
tree | 6e4649b8f73d0332a778c70eb6c8cb7bd7700a0d | |
parent | 86100e13abc6182d2dd51eeb491b113d5a070fa1 (diff) |
clover/llvm: Implement library bitcode codegen.
Reviewed-by: Serge Martin <[email protected]>
Tested-by: Jan Vesely <[email protected]>
-rw-r--r-- | src/gallium/state_trackers/clover/llvm/codegen.hpp | 7 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp | 25 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/gallium/state_trackers/clover/llvm/codegen.hpp b/src/gallium/state_trackers/clover/llvm/codegen.hpp index c4d4997dfed..e0e990190d2 100644 --- a/src/gallium/state_trackers/clover/llvm/codegen.hpp +++ b/src/gallium/state_trackers/clover/llvm/codegen.hpp @@ -46,6 +46,13 @@ namespace clover { print_module_bitcode(const ::llvm::Module &mod); module + build_module_library(const ::llvm::Module &mod); + + std::unique_ptr<::llvm::Module> + parse_module_library(const module &m, ::llvm::LLVMContext &ctx, + std::string &r_log); + + module build_module_native(::llvm::Module &mod, const target &target, const clang::CompilerInstance &c, std::string &r_log); diff --git a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp index d2baa07fdf9..658cce923c9 100644 --- a/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp +++ b/src/gallium/state_trackers/clover/llvm/codegen/bitcode.cpp @@ -24,7 +24,11 @@ /// /// \file /// Trivial codegen back-end that simply passes through the existing LLVM IR -/// and formats it so it can be consumed by pipe drivers. +/// and either formats it so it can be consumed by pipe drivers (if +/// build_module_bitcode() is used) or serializes so it can be deserialized at +/// a later point and passed to the actual codegen back-end (if +/// build_module_library() / parse_module_library() is used), potentially +/// after linking against other bitcode object files. /// #include "llvm/codegen.hpp" @@ -74,3 +78,22 @@ clover::llvm::print_module_bitcode(const ::llvm::Module &mod) { mod.print(os, NULL); return os.str(); } + +module +clover::llvm::build_module_library(const ::llvm::Module &mod) { + module m; + const auto code = emit_code(mod); + m.secs.emplace_back(0, module::section::text, code.size(), code); + return m; +} + +std::unique_ptr<::llvm::Module> +clover::llvm::parse_module_library(const module &m, ::llvm::LLVMContext &ctx, + std::string &r_log) { + auto mod = ::llvm::parseBitcodeFile(::llvm::MemoryBufferRef( + as_string(m.secs[0].data), " "), ctx); + if (!mod) + fail(r_log, error(CL_INVALID_PROGRAM), mod.getError().message()); + + return std::unique_ptr<::llvm::Module>(std::move(*mod)); +} |