aco: fix a couple of value numbering issues
[mesa.git] / src / amd / compiler / aco_interface.cpp
index 6adb911e4b396e82050339d289b8e6a5d0ce1fde..802adcefb1bee6bab2d7c91104bee1899db67ff1 100644 (file)
@@ -24,6 +24,7 @@
 #include "aco_interface.h"
 #include "aco_ir.h"
 #include "vulkan/radv_shader.h"
+#include "vulkan/radv_shader_args.h"
 #include "c11/threads.h"
 #include "util/debug.h"
 
@@ -56,8 +57,7 @@ static void init()
 void aco_compile_shader(unsigned shader_count,
                         struct nir_shader *const *shaders,
                         struct radv_shader_binary **binary,
-                        struct radv_shader_info *info,
-                        struct radv_nir_compiler_options *options)
+                        struct radv_shader_args *args)
 {
    call_once(&aco::init_once_flag, aco::init);
 
@@ -65,8 +65,8 @@ void aco_compile_shader(unsigned shader_count,
    std::unique_ptr<aco::Program> program{new aco::Program};
 
    /* Instruction Selection */
-   aco::select_program(program.get(), shader_count, shaders, &config, info, options);
-   if (options->dump_preoptir) {
+   aco::select_program(program.get(), shader_count, shaders, &config, args);
+   if (args->options->dump_preoptir) {
       std::cerr << "After Instruction Selection:\n";
       aco_print_program(program.get(), stderr);
    }
@@ -88,21 +88,36 @@ void aco_compile_shader(unsigned shader_count,
    aco::insert_exec_mask(program.get());
    aco::validate(program.get(), stderr);
 
-   aco::live live_vars = aco::live_var_analysis(program.get(), options);
-   aco::spill(program.get(), live_vars, options);
+   aco::live live_vars = aco::live_var_analysis(program.get(), args->options);
+   aco::spill(program.get(), live_vars, args->options);
 
    //std::cerr << "Before Schedule:\n";
    //aco_print_program(program.get(), stderr);
    aco::schedule_program(program.get(), live_vars);
 
+   std::string llvm_ir;
+   if (args->options->record_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) {
+   if (args->options->dump_shader) {
       std::cerr << "After RA:\n";
       aco_print_program(program.get(), stderr);
    }
 
-   if (aco::validate_ra(program.get(), options, stderr)) {
+   if (aco::validate_ra(program.get(), args->options, stderr)) {
       std::cerr << "Program after RA validation failure:\n";
       aco_print_program(program.get(), stderr);
       abort();
@@ -125,17 +140,14 @@ void aco_compile_shader(unsigned shader_count,
    std::vector<uint32_t> code;
    unsigned exec_size = aco::emit_program(program.get(), code);
 
-   bool get_disasm = options->dump_shader;
-#ifndef NDEBUG
-   get_disasm |= options->record_llvm_ir;
-#endif
+   bool get_disasm = args->options->dump_shader || args->options->record_ir;
 
-   size_t size = 0;
+   size_t size = llvm_ir.size();
 
    std::string disasm;
    if (get_disasm) {
       std::ostringstream stream;
-      aco::print_asm(program.get(), code, exec_size / 4u, options->family, stream);
+      aco::print_asm(program.get(), code, exec_size / 4u, stream);
       stream << '\0';
       disasm = stream.str();
       size += disasm.size();
@@ -155,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->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;