egl/main: Stop using EGLNative types internally
[mesa.git] / src / glsl / opt_dead_code.cpp
index cb500d2d105b41f983c13cc59d6e2351daff81ff..af53d94fdea63c16a01ab4c54b615dd46498b19d 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;
 
@@ -42,15 +43,16 @@ static bool debug = false;
  * for usage on an unlinked instruction stream.
  */
 bool
-do_dead_code(exec_list *instructions)
+do_dead_code(exec_list *instructions, bool uniform_locations_assigned)
 {
    ir_variable_refcount_visitor v;
    bool progress = false;
 
    v.run(instructions);
 
-   foreach_iter(exec_list_iterator, iter, v.variable_list) {
-      variable_entry *entry = (variable_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,
@@ -75,11 +77,11 @@ do_dead_code(exec_list *instructions)
 
       if (entry->assign) {
         /* Remove a single dead assignment to the variable we found.
-         * Don't do so if it's a shader output, though.
+         * Don't do so if it's a shader or function output, though.
          */
-        if (entry->var->mode != ir_var_out &&
-            entry->var->mode != ir_var_inout &&
-            !ir_has_call(entry->assign)) {
+        if (entry->var->data.mode != ir_var_function_out &&
+            entry->var->data.mode != ir_var_function_inout &&
+             entry->var->data.mode != ir_var_shader_out) {
            entry->assign->remove();
            progress = true;
 
@@ -94,10 +96,12 @@ do_dead_code(exec_list *instructions)
          */
 
         /* uniform initializers are precious, and could get used by another
-         * stage.
+         * stage.  Also, once uniform locations have been assigned, the
+         * declaration cannot be deleted.
          */
-        if (entry->var->mode == ir_var_uniform &&
-            entry->var->constant_value)
+        if (entry->var->data.mode == ir_var_uniform &&
+            (uniform_locations_assigned ||
+             entry->var->constant_value))
            continue;
 
         entry->var->remove();
@@ -125,14 +129,18 @@ do_dead_code_unlinked(exec_list *instructions)
 {
    bool progress = false;
 
-   foreach_iter(exec_list_iterator, iter, *instructions) {
-      ir_instruction *ir = (ir_instruction *)iter.get();
+   foreach_list(n, instructions) {
+      ir_instruction *ir = (ir_instruction *) n;
       ir_function *f = ir->as_function();
       if (f) {
-        foreach_iter(exec_list_iterator, sigiter, *f) {
-           ir_function_signature *sig =
-              (ir_function_signature *) sigiter.get();
-           if (do_dead_code(&sig->body))
+        foreach_list(signode, &f->signatures) {
+           ir_function_signature *sig = (ir_function_signature *) signode;
+           /* The setting of the uniform_locations_assigned flag here is
+            * irrelevent.  If there is a uniform declaration encountered
+            * inside the body of the function, something has already gone
+            * terribly, terribly wrong.
+            */
+           if (do_dead_code(&sig->body, false))
               progress = true;
         }
       }