Signed-off-by: Pierre Moreau <pierre.mor...@free.fr> --- v6: Update Makefile.am to add to libclllvm its new llvm-spirv dependency. (Karol Herbst)
src/gallium/state_trackers/clover/Makefile.am | 6 ++++- .../state_trackers/clover/llvm/invocation.cpp | 29 ++++++++++++++++++++++ .../state_trackers/clover/llvm/invocation.hpp | 6 +++++ src/gallium/state_trackers/clover/meson.build | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/gallium/state_trackers/clover/Makefile.am b/src/gallium/state_trackers/clover/Makefile.am index 35ee092f3f..5e4c1a65ae 100644 --- a/src/gallium/state_trackers/clover/Makefile.am +++ b/src/gallium/state_trackers/clover/Makefile.am @@ -39,10 +39,14 @@ libclllvm_la_CXXFLAGS = \ $(LIBELF_CFLAGS) \ -DLIBCLC_INCLUDEDIR=\"$(LIBCLC_INCLUDEDIR)/\" \ -DLIBCLC_LIBEXECDIR=\"$(LIBCLC_LIBEXECDIR)/\" \ - -DCLANG_RESOURCE_DIR=\"$(CLANG_RESOURCE_DIR)\" + -DCLANG_RESOURCE_DIR=\"$(CLANG_RESOURCE_DIR)\" \ + $(LLVM_SPIRV_CFLAGS) libclllvm_la_SOURCES = $(LLVM_SOURCES) +libclllvm_la_LDFLAGS = \ + $(LLVM_SPIRV_LIBS) + libclover_la_CXXFLAGS = \ $(CXX11_CXXFLAGS) \ $(CLOVER_STD_OVERRIDE) \ diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp index b2c64bc48f..4933d018ae 100644 --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp @@ -24,12 +24,17 @@ // OTHER DEALINGS IN THE SOFTWARE. // +#include <sstream> + #include <llvm/IR/DiagnosticPrinter.h> #include <llvm/IR/DiagnosticInfo.h> #include <llvm/IR/LLVMContext.h> #include <llvm/Support/raw_ostream.h> #include <llvm/Transforms/IPO/PassManagerBuilder.h> #include <llvm-c/Target.h> +#ifdef CLOVER_ALLOW_SPIRV +#include <llvm-spirv/SPIRV.h> +#endif #include <clang/CodeGen/CodeGenAction.h> #include <clang/Lex/PreprocessorOptions.h> @@ -392,3 +397,27 @@ clover::llvm::link_program(const std::vector<module> &modules, unreachable("Unsupported IR."); } } + +#ifdef CLOVER_ALLOW_SPIRV +module +clover::llvm::compile_from_spirv(const std::vector<char> &binary, + const device &dev, + std::string &r_log) { + auto ctx = create_context(r_log); + + ::llvm::Module *unsafe_mod; + std::string error_msg; + std::istringstream input({ binary.begin(), binary.end() }, std::ios_base::binary); + if (!::llvm::readSPIRV(*ctx, input, unsafe_mod, error_msg)) { + r_log += "Failed to convert SPIR-V to LLVM IR: " + error_msg + ".\n"; + throw error(CL_INVALID_VALUE); + } + + std::unique_ptr<::llvm::Module> mod(unsafe_mod); + + if (has_flag(debug::llvm)) + debug::log(".ll", print_module_bitcode(*mod)); + + return build_module_library(*mod, module::section::text_intermediate); +} +#endif diff --git a/src/gallium/state_trackers/clover/llvm/invocation.hpp b/src/gallium/state_trackers/clover/llvm/invocation.hpp index ff9caa457c..85b16f6c90 100644 --- a/src/gallium/state_trackers/clover/llvm/invocation.hpp +++ b/src/gallium/state_trackers/clover/llvm/invocation.hpp @@ -40,6 +40,12 @@ namespace clover { const device &device, const std::string &opts, std::string &r_log); + +#ifdef CLOVER_ALLOW_SPIRV + module compile_from_spirv(const std::vector<char> &binary, + const device &dev, + std::string &r_log); +#endif } } diff --git a/src/gallium/state_trackers/clover/meson.build b/src/gallium/state_trackers/clover/meson.build index c52f0faa40..bffd0df11d 100644 --- a/src/gallium/state_trackers/clover/meson.build +++ b/src/gallium/state_trackers/clover/meson.build @@ -48,7 +48,7 @@ libclllvm = static_library( dep_llvm.get_configtool_variable('version'), 'include', )), ], - dependencies : [dep_llvm, dep_elf], + dependencies : [dep_llvm, dep_elf, dep_llvm_spirv], ) clover_files = files( -- 2.16.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev