radv: record LLVM IR when debugging shaders
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 14 Mar 2018 09:34:13 +0000 (10:34 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 15 Mar 2018 16:20:03 +0000 (17:20 +0100)
If AMD_shader_info or RADV_TRACE_FILE is used we might need to
keep trace of LLVM IR.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_nir_to_llvm.c
src/amd/vulkan/radv_shader.c
src/amd/vulkan/radv_shader.h

index 298150b8092e5a00867e972874543b5957794afe..8c3169592809e8e0f40b807bcf4fb3826e1e94a8 100644 (file)
@@ -3229,6 +3229,13 @@ static void ac_compile_llvm_module(LLVMTargetMachineRef tm,
                ac_dump_module(llvm_module);
 
        memset(binary, 0, sizeof(*binary));
+
+       if (options->record_llvm_ir) {
+               char *llvm_ir = LLVMPrintModuleToString(llvm_module);
+               binary->llvm_ir_string = strdup(llvm_ir);
+               LLVMDisposeMessage(llvm_ir);
+       }
+
        int v = ac_llvm_compile(llvm_module, binary, tm);
        if (v) {
                fprintf(stderr, "compile failed\n");
index 8a6928e7ccd85e09f1cae34135c7ef37771e3605..89875a56a0242a2e2207c00ce428ec91000e4a5a 100644 (file)
@@ -462,6 +462,7 @@ shader_variant_create(struct radv_device *device,
        options->dump_shader = radv_can_dump_shader(device, module);
        options->dump_preoptir = options->dump_shader &&
                                 device->instance->debug_flags & RADV_DEBUG_PREOPTIR;
+       options->record_llvm_ir = device->keep_shader_info;
 
        if (options->supports_spill)
                tm_options |= AC_TM_SUPPORTS_SPILL;
@@ -497,6 +498,7 @@ shader_variant_create(struct radv_device *device,
 
        if (device->keep_shader_info) {
                variant->disasm_string = binary.disasm_string;
+               variant->llvm_ir_string = binary.llvm_ir_string;
                if (!gs_copy_shader && !module->nir) {
                        variant->nir = *shaders;
                        variant->spirv = (uint32_t *)module->data;
@@ -560,6 +562,7 @@ radv_shader_variant_destroy(struct radv_device *device,
 
        ralloc_free(variant->nir);
        free(variant->disasm_string);
+       free(variant->llvm_ir_string);
        free(variant);
 }
 
index 6550c7da1d6bb2d1eed5f9e74ef23fd7e805f605..5c3f0ff6c442ecd296e154a1afd9462696226a7e 100644 (file)
@@ -99,6 +99,7 @@ struct radv_nir_compiler_options {
        bool clamp_shadow_reference;
        bool dump_shader;
        bool dump_preoptir;
+       bool record_llvm_ir;
        enum radeon_family family;
        enum chip_class chip_class;
 };
@@ -261,6 +262,7 @@ struct radv_shader_variant {
        uint32_t spirv_size;
        struct nir_shader *nir;
        char *disasm_string;
+       char *llvm_ir_string;
 
        struct list_head slab_list;
 };