From: Jason Ekstrand Date: Wed, 12 Nov 2014 19:05:51 +0000 (-0800) Subject: i965/fs_nir: Use an array rather than a hash table for register lookup X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e0aa4c6272851ed418dfa18ee6014f40b0e266c2;p=mesa.git i965/fs_nir: Use an array rather than a hash table for register lookup Reviewed-by: Connor Abbott --- diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h index d9388c585e4..e589c9646b5 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.h +++ b/src/mesa/drivers/dri/i965/brw_fs.h @@ -572,7 +572,6 @@ public: void nir_setup_inputs(nir_shader *shader); void nir_setup_outputs(nir_shader *shader); void nir_setup_uniforms(nir_shader *shader); - void nir_setup_registers(exec_list *regs); void nir_setup_uniform(nir_variable *var); void nir_setup_builtin_uniform(nir_variable *var); void nir_emit_impl(nir_function_impl *impl); @@ -698,7 +697,8 @@ public: fs_reg *fp_temp_regs; fs_reg *fp_input_regs; - struct hash_table *nir_reg_ht; + fs_reg *nir_locals; + fs_reg *nir_globals; fs_reg nir_inputs; fs_reg nir_outputs; fs_reg nir_uniforms; diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp index 2ca2e738b9f..3ec2fa66be6 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp @@ -98,7 +98,13 @@ fs_visitor::emit_nir_code() nir_setup_uniforms(nir); } - nir_setup_registers(&nir->registers); + nir_globals = ralloc_array(mem_ctx, fs_reg, nir->reg_alloc); + foreach_list_typed(nir_register, reg, node, &nir->registers) { + unsigned array_elems = + reg->num_array_elems == 0 ? 1 : reg->num_array_elems; + unsigned size = array_elems * reg->num_components; + nir_globals[reg->index] = fs_reg(GRF, virtual_grf_alloc(size)); + } /* get the main function and emit it */ nir_foreach_overload(nir, overload) { @@ -276,21 +282,16 @@ fs_visitor::nir_setup_builtin_uniform(nir_variable *var) } void -fs_visitor::nir_setup_registers(exec_list *list) +fs_visitor::nir_emit_impl(nir_function_impl *impl) { - foreach_list_typed(nir_register, nir_reg, node, list) { + nir_locals = reralloc(mem_ctx, nir_locals, fs_reg, impl->reg_alloc); + foreach_list_typed(nir_register, reg, node, &impl->registers) { unsigned array_elems = - nir_reg->num_array_elems == 0 ? 1 : nir_reg->num_array_elems; - unsigned size = array_elems * nir_reg->num_components; - fs_reg *reg = new(mem_ctx) fs_reg(GRF, virtual_grf_alloc(size)); - _mesa_hash_table_insert(this->nir_reg_ht, nir_reg, reg); + reg->num_array_elems == 0 ? 1 : reg->num_array_elems; + unsigned size = array_elems * reg->num_components; + nir_locals[reg->index] = fs_reg(GRF, virtual_grf_alloc(size)); } -} -void -fs_visitor::nir_emit_impl(nir_function_impl *impl) -{ - nir_setup_registers(&impl->registers); nir_emit_cf_list(&impl->body); } @@ -980,9 +981,12 @@ fs_visitor::nir_emit_alu(nir_alu_instr *instr) fs_reg fs_visitor::get_nir_src(nir_src src) { - struct hash_entry *entry = - _mesa_hash_table_search(this->nir_reg_ht, src.reg.reg); - fs_reg reg = *((fs_reg *) entry->data); + fs_reg reg; + if (src.reg.reg->is_global) + reg = nir_globals[src.reg.reg->index]; + else + reg = nir_locals[src.reg.reg->index]; + /* to avoid floating-point denorm flushing problems, set the type by * default to D - instructions that need floating point semantics will set * this to F if they need to @@ -1040,9 +1044,12 @@ fs_visitor::get_nir_alu_src(nir_alu_instr *instr, unsigned src) fs_reg fs_visitor::get_nir_dest(nir_dest dest) { - struct hash_entry *entry = - _mesa_hash_table_search(this->nir_reg_ht, dest.reg.reg); - fs_reg reg = *((fs_reg *) entry->data); + fs_reg reg; + if (dest.reg.reg->is_global) + reg = nir_globals[dest.reg.reg->index]; + else + reg = nir_locals[dest.reg.reg->index]; + reg.reg_offset = dest.reg.base_offset; if (dest.reg.indirect) { reg.reladdr = new(mem_ctx) fs_reg(); diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp index a9d32547122..6ddb267cc19 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp @@ -3824,8 +3824,9 @@ fs_visitor::init() this->variable_ht = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare); - this->nir_reg_ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer, - _mesa_key_pointer_equal); + + this->nir_locals = NULL; + this->nir_globals = NULL; memset(&this->payload, 0, sizeof(this->payload)); memset(this->outputs, 0, sizeof(this->outputs)); @@ -3861,5 +3862,4 @@ fs_visitor::init() fs_visitor::~fs_visitor() { hash_table_dtor(this->variable_ht); - _mesa_hash_table_destroy(this->nir_reg_ht, NULL); }