[Mesa-dev] [PATCH v2 2/2] mesa: Use the new hash table for the variable refcount visitor.

Jordan Justen jordan.l.justen at intel.com
Thu Dec 6 17:51:56 PST 2012


From: Eric Anholt <eric at anholt.net>

Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>
[jordan.l.justen at intel.com: open_hash_table => hash_table]
Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/glsl/Makefile.am                   |    2 ++
 src/glsl/SConscript                    |    4 ++++
 src/glsl/builtin_compiler/Makefile.am  |    1 +
 src/glsl/ir_variable_refcount.cpp      |   35 +++++++++++++++++++++++++-------
 src/glsl/ir_variable_refcount.h        |   17 ++++------------
 src/glsl/opt_dead_code.cpp             |    6 ++++--
 src/mesa/Android.libmesa_glsl_utils.mk |    2 ++
 7 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am
index 2ba439c..aff1559 100644
--- a/src/glsl/Makefile.am
+++ b/src/glsl/Makefile.am
@@ -49,6 +49,7 @@ libglsl_la_LIBADD = glcpp/libglcpp.la
 libglsl_la_LDFLAGS =
 
 glsl_compiler_SOURCES = \
+	$(top_srcdir)/src/mesa/main/hash_table.c \
 	$(top_srcdir)/src/mesa/program/prog_hash_table.c \
 	$(top_srcdir)/src/mesa/program/symbol_table.c \
 	$(GLSL_COMPILER_CXX_FILES)
@@ -56,6 +57,7 @@ glsl_compiler_SOURCES = \
 glsl_compiler_LDADD = libglsl.la
 
 glsl_test_SOURCES = \
+	$(top_srcdir)/src/mesa/main/hash_table.c \
 	$(top_srcdir)/src/mesa/program/prog_hash_table.c \
 	$(top_srcdir)/src/mesa/program/symbol_table.c \
 	$(GLSL_SRCDIR)/standalone_scaffolding.cpp \
diff --git a/src/glsl/SConscript b/src/glsl/SConscript
index 38de60d..6abba2a 100644
--- a/src/glsl/SConscript
+++ b/src/glsl/SConscript
@@ -57,6 +57,9 @@ if env['crosscompile'] and not env['embedded']:
     Import('builtin_glsl_function')
 else:
     # Copy these files to avoid generation object files into src/mesa/program
+    env.Prepend(CPPPATH = ['#src/mesa/main'])
+    env.Command('hash_table.c', '#src/mesa/main/hash_table.c', Copy('$TARGET', '$SOURCE'))
+    # Copy these files to avoid generation object files into src/mesa/program
     env.Prepend(CPPPATH = ['#src/mesa/program'])
     env.Command('prog_hash_table.c', '#src/mesa/program/prog_hash_table.c', Copy('$TARGET', '$SOURCE'))
     env.Command('symbol_table.c', '#src/mesa/program/symbol_table.c', Copy('$TARGET', '$SOURCE'))
@@ -64,6 +67,7 @@ else:
     compiler_objs = env.StaticObject(source_lists['GLSL_COMPILER_CXX_FILES'])
 
     mesa_objs = env.StaticObject([
+        'hash_table.c',
         'prog_hash_table.c',
         'symbol_table.c',
     ])
diff --git a/src/glsl/builtin_compiler/Makefile.am b/src/glsl/builtin_compiler/Makefile.am
index 5fad35d..d27aca5 100644
--- a/src/glsl/builtin_compiler/Makefile.am
+++ b/src/glsl/builtin_compiler/Makefile.am
@@ -55,6 +55,7 @@ builtin_compiler_SOURCES = \
 	$(GLSL_BUILDDIR)/glsl_parser.cc \
 	$(LIBGLSL_FILES) \
 	$(LIBGLSL_CXX_FILES) \
+	$(top_srcdir)/src/mesa/main/hash_table.c \
 	$(top_srcdir)/src/mesa/program/prog_hash_table.c \
 	$(top_srcdir)/src/mesa/program/symbol_table.c \
 	$(GLSL_COMPILER_CXX_FILES) \
diff --git a/src/glsl/ir_variable_refcount.cpp b/src/glsl/ir_variable_refcount.cpp
index 1633a73..923eb1a 100644
--- a/src/glsl/ir_variable_refcount.cpp
+++ b/src/glsl/ir_variable_refcount.cpp
@@ -33,7 +33,26 @@
 #include "ir_visitor.h"
 #include "ir_variable_refcount.h"
 #include "glsl_types.h"
+#include "main/hash_table.h"
 
+ir_variable_refcount_visitor::ir_variable_refcount_visitor()
+{
+   this->mem_ctx = ralloc_context(NULL);
+   this->ht = _mesa_hash_table_create(NULL, _mesa_key_pointer_equal);
+}
+
+static void
+free_entry(struct hash_entry *entry)
+{
+   ir_variable_refcount_entry *ivre = (ir_variable_refcount_entry *) entry->data;
+   delete ivre;
+}
+
+ir_variable_refcount_visitor::~ir_variable_refcount_visitor()
+{
+   ralloc_free(this->mem_ctx);
+   _mesa_hash_table_destroy(this->ht, free_entry);
+}
 
 // constructor
 ir_variable_refcount_entry::ir_variable_refcount_entry(ir_variable *var)
@@ -50,15 +69,17 @@ ir_variable_refcount_entry *
 ir_variable_refcount_visitor::get_variable_entry(ir_variable *var)
 {
    assert(var);
-   foreach_iter(exec_list_iterator, iter, this->variable_list) {
-      ir_variable_refcount_entry *entry = (ir_variable_refcount_entry *)iter.get();
-      if (entry->var == var)
-	 return entry;
-   }
 
-   ir_variable_refcount_entry *entry = new(mem_ctx) ir_variable_refcount_entry(var);
+   struct hash_entry *e = _mesa_hash_table_search(this->ht,
+						    _mesa_hash_pointer(var),
+						    var);
+   if (e)
+      return (ir_variable_refcount_entry *)e->data;
+
+   ir_variable_refcount_entry *entry = new ir_variable_refcount_entry(var);
    assert(entry->referenced_count == 0);
-   this->variable_list.push_tail(entry);
+   _mesa_hash_table_insert(this->ht, _mesa_hash_pointer(var), var, entry);
+
    return entry;
 }
 
diff --git a/src/glsl/ir_variable_refcount.h b/src/glsl/ir_variable_refcount.h
index 51a4945..c15e811 100644
--- a/src/glsl/ir_variable_refcount.h
+++ b/src/glsl/ir_variable_refcount.h
@@ -33,7 +33,7 @@
 #include "ir_visitor.h"
 #include "glsl_types.h"
 
-class ir_variable_refcount_entry : public exec_node
+class ir_variable_refcount_entry
 {
 public:
    ir_variable_refcount_entry(ir_variable *var);
@@ -52,16 +52,8 @@ public:
 
 class ir_variable_refcount_visitor : public ir_hierarchical_visitor {
 public:
-   ir_variable_refcount_visitor(void)
-   {
-      this->mem_ctx = ralloc_context(NULL);
-      this->variable_list.make_empty();
-   }
-
-   ~ir_variable_refcount_visitor(void)
-   {
-      ralloc_free(this->mem_ctx);
-   }
+   ir_variable_refcount_visitor(void);
+   ~ir_variable_refcount_visitor(void);
 
    virtual ir_visitor_status visit(ir_variable *);
    virtual ir_visitor_status visit(ir_dereference_variable *);
@@ -71,8 +63,7 @@ public:
 
    ir_variable_refcount_entry *get_variable_entry(ir_variable *var);
 
-   /* List of ir_variable_refcount_entry */
-   exec_list variable_list;
+   struct hash_table *ht;
 
    void *mem_ctx;
 };
diff --git a/src/glsl/opt_dead_code.cpp b/src/glsl/opt_dead_code.cpp
index de8475f..47247e2 100644
--- a/src/glsl/opt_dead_code.cpp
+++ b/src/glsl/opt_dead_code.cpp
@@ -31,6 +31,7 @@
 #include "ir_visitor.h"
 #include "ir_variable_refcount.h"
 #include "glsl_types.h"
+#include "main/hash_table.h"
 
 static bool debug = false;
 
@@ -49,8 +50,9 @@ do_dead_code(exec_list *instructions, bool uniform_locations_assigned)
 
    v.run(instructions);
 
-   foreach_iter(exec_list_iterator, iter, v.variable_list) {
-      ir_variable_refcount_entry *entry = (ir_variable_refcount_entry *)iter.get();
+   struct hash_entry *e;
+   hash_table_foreach(v.ht, e) {
+      ir_variable_refcount_entry *entry = (ir_variable_refcount_entry *)e->data;
 
       /* Since each assignment is a reference, the refereneced count must be
        * greater than or equal to the assignment count.  If they are equal,
diff --git a/src/mesa/Android.libmesa_glsl_utils.mk b/src/mesa/Android.libmesa_glsl_utils.mk
index 5ae946f..9beeda5 100644
--- a/src/mesa/Android.libmesa_glsl_utils.mk
+++ b/src/mesa/Android.libmesa_glsl_utils.mk
@@ -36,6 +36,7 @@ include $(CLEAR_VARS)
 LOCAL_MODULE := libmesa_glsl_utils
 
 LOCAL_SRC_FILES := \
+	main/hash_table.c \
 	program/prog_hash_table.c \
 	program/symbol_table.c
 
@@ -52,6 +53,7 @@ LOCAL_MODULE := libmesa_glsl_utils
 LOCAL_IS_HOST_MODULE := true
 
 LOCAL_SRC_FILES := \
+	main/hash_table.c \
 	program/prog_hash_table.c \
 	program/symbol_table.c
 
-- 
1.7.10.4



More information about the mesa-dev mailing list