diff options
author | Francisco Jerez <[email protected]> | 2016-05-17 16:02:57 +0200 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2016-07-11 20:34:33 -0700 |
commit | f0721020ad6ba20110705cb1d927de09e0e25edc (patch) | |
tree | 76037bc940cd60ced1ee9582c8a3b4a1778cad8e /src/gallium | |
parent | 1d042adc0a0a47e343ce29c15ac6767c824a8e9c (diff) |
clover/llvm: Split native codegen and assembly print-out into separate functions.
Reviewed-by: Serge Martin <[email protected]>
Tested-by: Jan Vesely <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/state_trackers/clover/llvm/invocation.cpp | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp index f0f1b7a5f43..d4c8addeea3 100644 --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp @@ -471,19 +471,6 @@ namespace { return { data.begin(), data.end() }; } - std::vector<char> - compile_native(llvm::Module *mod, const target &target, - std::string &r_log) { - if (has_flag(debug::native)) { - std::unique_ptr<llvm::Module> cmod { CloneModule(mod) }; - debug::log(".asm", as_string( - emit_code(*cmod, target, - TargetMachine::CGFT_AssemblyFile, r_log))); - } - - return emit_code(*mod, target, TargetMachine::CGFT_ObjectFile, r_log); - } - namespace elf { std::unique_ptr<Elf, int (*)(Elf *)> get(const std::vector<char> &code) { @@ -545,12 +532,24 @@ namespace { } module - build_module_native(llvm::Module *mod, const target &target, + build_module_native(::llvm::Module &mod, const target &target, const clang::CompilerInstance &c, std::string &r_log) { - const auto code = compile_native(mod, target, r_log); - return build_module_common(*mod, code, - get_symbol_offsets(code, r_log), c); + const auto code = emit_code(mod, target, + TargetMachine::CGFT_ObjectFile, r_log); + return build_module_common(mod, code, get_symbol_offsets(code, r_log), c); + } + + std::string + print_module_native(const ::llvm::Module &mod, const target &target) { + std::string log; + try { + std::unique_ptr<llvm::Module> cmod { CloneModule(&mod) }; + return as_string(emit_code(*cmod, target, + TargetMachine::CGFT_AssemblyFile, log)); + } catch (...) { + return "Couldn't output native disassembly: " + log; + } } } // End anonymous namespace @@ -594,7 +593,10 @@ clover::compile_program_llvm(const std::string &source, m = build_module_bitcode(*mod, *c); break; case PIPE_SHADER_IR_NATIVE: - m = build_module_native(&*mod, target, *c, r_log); + if (has_flag(debug::native)) + debug::log(".asm", print_module_native(*mod, target)); + + m = build_module_native(*mod, target, *c, r_log); break; } |