diff --git a/docs/envvars.rst b/docs/envvars.rst index 44ed848b98c..4d1048daacf 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -1063,6 +1063,7 @@ clc environment variables a comma-separated list of debug channels to enable. + - ``dump_llvm`` Dumps all generated LLVM IRs - ``dump_spirv`` Dumps all compiled, linked and specialized SPIR-Vs - ``verbose`` Enable debug logging of clc code diff --git a/src/compiler/clc/clc.c b/src/compiler/clc/clc.c index b8d78865f9e..bd2b28fc68c 100644 --- a/src/compiler/clc/clc.c +++ b/src/compiler/clc/clc.c @@ -35,6 +35,7 @@ static const struct debug_named_value clc_debug_options[] = { { "dump_spirv", CLC_DEBUG_DUMP_SPIRV, "Dump spirv blobs" }, + { "dump_llvm", CLC_DEBUG_DUMP_LLVM, "Dump LLVM blobs" }, { "verbose", CLC_DEBUG_VERBOSE, NULL }, DEBUG_NAMED_VALUE_END }; diff --git a/src/compiler/clc/clc.h b/src/compiler/clc/clc.h index 1a1ef2cd85d..2e7542b3caf 100644 --- a/src/compiler/clc/clc.h +++ b/src/compiler/clc/clc.h @@ -269,7 +269,8 @@ clc_specialize_spirv(const struct clc_binary *in_spirv, enum clc_debug_flags { CLC_DEBUG_DUMP_SPIRV = 1 << 0, - CLC_DEBUG_VERBOSE = 1 << 1, + CLC_DEBUG_DUMP_LLVM = 1 << 1, + CLC_DEBUG_VERBOSE = 1 << 2, }; uint64_t clc_debug_flags(void); diff --git a/src/compiler/clc/clc_helpers.cpp b/src/compiler/clc/clc_helpers.cpp index 55287f22683..d2742eca8ea 100644 --- a/src/compiler/clc/clc_helpers.cpp +++ b/src/compiler/clc/clc_helpers.cpp @@ -79,6 +79,9 @@ using ::llvm::Module; using ::llvm::raw_string_ostream; using ::clang::driver::Driver; +static void +clc_dump_llvm(const llvm::Module *mod, FILE *f); + static void llvm_log_handler(const ::llvm::DiagnosticInfo &di, void *data) { const clc_logger *logger = static_cast(data); @@ -968,7 +971,12 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx, return {}; } - return act.takeModule(); + auto mod = act.takeModule(); + + if (clc_debug_flags() & CLC_DEBUG_DUMP_LLVM) + clc_dump_llvm(mod.get(), stdout); + + return mod; } static SPIRV::VersionNumber @@ -1252,6 +1260,18 @@ clc_spirv_specialize(const struct clc_binary *in_spirv, return true; } +static void +clc_dump_llvm(const llvm::Module *mod, FILE *f) +{ + std::string out; + raw_string_ostream os(out); + + mod->print(os, nullptr); + os.flush(); + + fwrite(out.c_str(), out.size(), 1, f); +} + void clc_dump_spirv(const struct clc_binary *spvbin, FILE *f) {