From 2bb26cc01d016e1f5317213bca930c3de7ce00d1 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Mon, 5 Jun 2023 23:31:17 -0700 Subject: [PATCH] intel/compiler: Refactor dump_instruction(s) Delete unnecessary virtual functions, we need just two. Refactor code so the 'default behavior' logic (stderr and/or creating file) is not duplicated. Rename the virtuals so overrides don't hide the common convenience functions. Finally, provide a variant of dump_instructions() with a `FILE *` parameter. Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/compiler/brw_fs.cpp | 27 ++------------------------- src/intel/compiler/brw_fs.h | 6 ++---- src/intel/compiler/brw_shader.cpp | 20 ++++++++++---------- src/intel/compiler/brw_shader.h | 12 ++++++++---- src/intel/compiler/brw_vec4.cpp | 8 +------- src/intel/compiler/brw_vec4.h | 3 +-- 6 files changed, 24 insertions(+), 52 deletions(-) diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp index 119045ab633..e12e36a53d0 100644 --- a/src/intel/compiler/brw_fs.cpp +++ b/src/intel/compiler/brw_fs.cpp @@ -5693,21 +5693,8 @@ fs_visitor::lower_find_live_channel() } void -fs_visitor::dump_instructions() const +fs_visitor::dump_instructions_to_file(FILE *file) const { - dump_instructions(NULL); -} - -void -fs_visitor::dump_instructions(const char *name) const -{ - FILE *file = stderr; - if (name && geteuid() != 0) { - file = fopen(name, "w"); - if (!file) - file = stderr; - } - if (cfg) { const register_pressure &rp = regpressure_analysis.require(); unsigned ip = 0, max_pressure = 0; @@ -5725,20 +5712,10 @@ fs_visitor::dump_instructions(const char *name) const dump_instruction(inst, file); } } - - if (file != stderr) { - fclose(file); - } } void -fs_visitor::dump_instruction(const backend_instruction *be_inst) const -{ - dump_instruction(be_inst, stderr); -} - -void -fs_visitor::dump_instruction(const backend_instruction *be_inst, FILE *file) const +fs_visitor::dump_instruction_to_file(const backend_instruction *be_inst, FILE *file) const { const fs_inst *inst = (const fs_inst *)be_inst; diff --git a/src/intel/compiler/brw_fs.h b/src/intel/compiler/brw_fs.h index f34b1910671..557827be704 100644 --- a/src/intel/compiler/brw_fs.h +++ b/src/intel/compiler/brw_fs.h @@ -439,10 +439,8 @@ public: fs_reg interp_reg(int location, int channel); fs_reg per_primitive_reg(int location); - virtual void dump_instructions() const; - virtual void dump_instructions(const char *name) const; - void dump_instruction(const backend_instruction *inst) const; - void dump_instruction(const backend_instruction *inst, FILE *file) const; + virtual void dump_instruction_to_file(const backend_instruction *inst, FILE *file) const; + virtual void dump_instructions_to_file(FILE *file) const; const brw_base_prog_key *const key; const struct brw_sampler_prog_key_data *key_tex; diff --git a/src/intel/compiler/brw_shader.cpp b/src/intel/compiler/brw_shader.cpp index 32bf07b3dde..5e67b60b028 100644 --- a/src/intel/compiler/brw_shader.cpp +++ b/src/intel/compiler/brw_shader.cpp @@ -1235,12 +1235,6 @@ backend_instruction::remove(bblock_t *block, bool defer_later_block_ip_updates) exec_node::remove(); } -void -backend_shader::dump_instructions() const -{ - dump_instructions(NULL); -} - void backend_shader::dump_instructions(const char *name) const { @@ -1251,6 +1245,16 @@ backend_shader::dump_instructions(const char *name) const file = stderr; } + dump_instructions_to_file(file); + + if (file != stderr) { + fclose(file); + } +} + +void +backend_shader::dump_instructions_to_file(FILE *file) const +{ if (cfg) { int ip = 0; foreach_block_and_inst(block, backend_instruction, inst, cfg) { @@ -1266,10 +1270,6 @@ backend_shader::dump_instructions(const char *name) const dump_instruction(inst, file); } } - - if (file != stderr) { - fclose(file); - } } void diff --git a/src/intel/compiler/brw_shader.h b/src/intel/compiler/brw_shader.h index cea8c0f3e9e..63f82329aa4 100644 --- a/src/intel/compiler/brw_shader.h +++ b/src/intel/compiler/brw_shader.h @@ -82,10 +82,14 @@ public: brw::simple_allocator alloc; - virtual void dump_instruction(const backend_instruction *inst) const = 0; - virtual void dump_instruction(const backend_instruction *inst, FILE *file) const = 0; - virtual void dump_instructions() const; - virtual void dump_instructions(const char *name) const; + virtual void dump_instruction_to_file(const backend_instruction *inst, FILE *file) const = 0; + virtual void dump_instructions_to_file(FILE *file) const; + + /* Convenience functions based on the above. */ + void dump_instruction(const backend_instruction *inst, FILE *file = stderr) const { + dump_instruction_to_file(inst, file); + } + void dump_instructions(const char *name = nullptr) const; void calculate_cfg(); diff --git a/src/intel/compiler/brw_vec4.cpp b/src/intel/compiler/brw_vec4.cpp index 7725007da6d..990c7e23576 100644 --- a/src/intel/compiler/brw_vec4.cpp +++ b/src/intel/compiler/brw_vec4.cpp @@ -1309,13 +1309,7 @@ vec4_visitor::split_virtual_grfs() } void -vec4_visitor::dump_instruction(const backend_instruction *be_inst) const -{ - dump_instruction(be_inst, stderr); -} - -void -vec4_visitor::dump_instruction(const backend_instruction *be_inst, FILE *file) const +vec4_visitor::dump_instruction_to_file(const backend_instruction *be_inst, FILE *file) const { const vec4_instruction *inst = (const vec4_instruction *)be_inst; diff --git a/src/intel/compiler/brw_vec4.h b/src/intel/compiler/brw_vec4.h index 1b568176b19..aff1c2348cf 100644 --- a/src/intel/compiler/brw_vec4.h +++ b/src/intel/compiler/brw_vec4.h @@ -282,8 +282,7 @@ public: src_reg get_timestamp(); - void dump_instruction(const backend_instruction *inst) const; - void dump_instruction(const backend_instruction *inst, FILE *file) const; + virtual void dump_instruction_to_file(const backend_instruction *inst, FILE *file) const; bool optimize_predicate(nir_alu_instr *instr, enum brw_predicate *predicate);