From: Rhys Perry Date: Tue, 24 Sep 2019 14:23:46 +0000 (+0100) Subject: aco: store printed backend IR in binary X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=15ea1c5cff1dad6b8cf065774aaf3b41aa36de69;p=mesa.git aco: store printed backend IR in binary Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Reviewed-by: Bas Nieuwenhuizen --- diff --git a/src/amd/compiler/aco_interface.cpp b/src/amd/compiler/aco_interface.cpp index 5a6556f8fad..2a1986357ca 100644 --- a/src/amd/compiler/aco_interface.cpp +++ b/src/amd/compiler/aco_interface.cpp @@ -95,6 +95,21 @@ void aco_compile_shader(unsigned shader_count, //aco_print_program(program.get(), stderr); aco::schedule_program(program.get(), live_vars); + std::string llvm_ir; + if (options->record_llvm_ir) { + char *data = NULL; + size_t size = 0; + FILE *f = open_memstream(&data, &size); + if (f) { + aco_print_program(program.get(), f); + fputc(0, f); + fclose(f); + } + + llvm_ir = std::string(data, data + size); + free(data); + } + /* Register Allocation */ aco::register_allocation(program.get(), live_vars.live_out); if (options->dump_shader) { @@ -127,7 +142,7 @@ void aco_compile_shader(unsigned shader_count, bool get_disasm = options->dump_shader || options->record_llvm_ir; - size_t size = 0; + size_t size = llvm_ir.size(); std::string disasm; if (get_disasm) { @@ -152,11 +167,13 @@ void aco_compile_shader(unsigned shader_count, legacy_binary->config = config; legacy_binary->disasm_size = 0; - legacy_binary->llvm_ir_size = 0; + legacy_binary->llvm_ir_size = llvm_ir.size(); + + llvm_ir.copy((char*) legacy_binary->data + legacy_binary->code_size, llvm_ir.size()); if (get_disasm) { - disasm.copy((char*) legacy_binary->data + legacy_binary->code_size, disasm.size()); - legacy_binary->disasm_size = disasm.size() - 1; + disasm.copy((char*) legacy_binary->data + legacy_binary->code_size + llvm_ir.size(), disasm.size()); + legacy_binary->disasm_size = disasm.size(); } *binary = (radv_shader_binary*) legacy_binary;