mesa: Use the new hash table for the variable refcount visitor.
authorEric Anholt <eric@anholt.net>
Wed, 17 Oct 2012 22:20:09 +0000 (15:20 -0700)
committerJordan Justen <jordan.l.justen@intel.com>
Fri, 7 Dec 2012 22:46:18 +0000 (14:46 -0800)
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
[jordan.l.justen@intel.com: open_hash_table => hash_table]
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/Makefile.am
src/glsl/SConscript
src/glsl/builtin_compiler/Makefile.am
src/glsl/ir_variable_refcount.cpp
src/glsl/ir_variable_refcount.h
src/glsl/opt_dead_code.cpp
src/mesa/Android.libmesa_glsl_utils.mk

index 2ba439c77cc5eb94f7617298f303ac5e7b6dd3cb..aff1559e0f12d289ac0e1190460e0af59cc20b7f 100644 (file)
@@ -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 \
index 38de60ded33c4a5739b29e46c8422d35173e1e11..6abba2a240f662fdcd1e21f86be454c38811432b 100644 (file)
@@ -56,6 +56,9 @@ if env['msvc']:
 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'))
@@ -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',
     ])
index 5fad35d50e78bf49671d1d55a9d8fd13881185a9..d27aca5550e2b50e7c1d35133a776ab2c8a97b5e 100644 (file)
@@ -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) \
index 1633a735744126207d478b03dec5789f061a67e8..923eb1a82749e8f71e2e2cf368f35f34e0d51b7a 100644 (file)
 #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;
 }
 
index 51a4945a135289f23d4cefa7b12a301507844344..c15e8110d04a98bc6b0f0d1eba20faa5f55c496a 100644 (file)
@@ -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;
 };
index de8475f956eb3fd0a3ad8a515862086c78790753..47247e20d9f41f6e6276d8fccb73d72e710a9d1a 100644 (file)
@@ -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,
index 5ae946fd8dc0d5812b032f7e74d77af53a36754f..9beeda57f5565e3cfd32610255e64c88367605d5 100644 (file)
@@ -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