i965/fs_nir: Use an array rather than a hash table for register lookup
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 12 Nov 2014 19:05:51 +0000 (11:05 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 15 Jan 2015 15:19:01 +0000 (07:19 -0800)
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_nir.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp

index d9388c585e42ed68ed5b7c954fca15f071d53cd4..e589c9646b5b4be8795aec2aa60c08bb213f07b2 100644 (file)
@@ -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;
index 2ca2e738b9fbfd4652554d629b64cdbfcb6c7ec7..3ec2fa66be642a2d29ea069ea2234ac6231e8ebd 100644 (file)
@@ -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();
index a9d32547122219e11248ed5990010d2520e28006..6ddb267cc192f023be48f5b2368c26bad9c35e8c 100644 (file)
@@ -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);
 }