Mesa (10.0): glsl: Teach ir_variable_refcount about ir_loop:: counter variables.
Carl Worth
cworth at kemper.freedesktop.org
Fri Jan 3 01:45:56 UTC 2014
Module: Mesa
Branch: 10.0
Commit: 8eee788bd69ad510de8b405848428feba6c3d972
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8eee788bd69ad510de8b405848428feba6c3d972
Author: Paul Berry <stereotype441 at gmail.com>
Date: Tue Nov 26 14:37:57 2013 -0800
glsl: Teach ir_variable_refcount about ir_loop::counter variables.
If an ir_loop has a non-null "counter" field, the variable referred to
by this field is implicitly read and written by the loop. We need to
account for this in ir_variable_refcount, otherwise there is a danger
we will try to dead-code-eliminate the loop counter variable.
Note: at the moment the dead code elimination bug doesn't occur due to
a bug in ir_hierarchical_visitor: it doesn't visit the "counter"
field, so dead code elimination doesn't treat it as a candidate for
elimination. But the patch to follow will fix that bug, so we need to
fix ir_variable_refcount first in order to avoid breaking dead code
elimination.
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
(cherry picked from commit 9d2951ea0acdcd219ad28831ac9e7112737d9ca3)
---
src/glsl/ir_variable_refcount.cpp | 21 +++++++++++++++++++++
src/glsl/ir_variable_refcount.h | 1 +
2 files changed, 22 insertions(+)
diff --git a/src/glsl/ir_variable_refcount.cpp b/src/glsl/ir_variable_refcount.cpp
index 923eb1a..425ed81 100644
--- a/src/glsl/ir_variable_refcount.cpp
+++ b/src/glsl/ir_variable_refcount.cpp
@@ -132,3 +132,24 @@ ir_variable_refcount_visitor::visit_leave(ir_assignment *ir)
return visit_continue;
}
+
+
+ir_visitor_status
+ir_variable_refcount_visitor::visit_leave(ir_loop *ir)
+{
+ /* If the loop has a counter variable, it is implicitly referenced and
+ * assigned to. Note that since the LHS of an assignment is counted as a
+ * reference, we actually have to increment referenced_count by 2 so that
+ * later code will know that the variable isn't just assigned to.
+ */
+ if (ir->counter != NULL) {
+ ir_variable_refcount_entry *entry =
+ this->get_variable_entry(ir->counter);
+ if (entry) {
+ entry->referenced_count += 2;
+ entry->assigned_count++;
+ }
+ }
+
+ return visit_continue;
+}
diff --git a/src/glsl/ir_variable_refcount.h b/src/glsl/ir_variable_refcount.h
index c15e811..03fa7b5 100644
--- a/src/glsl/ir_variable_refcount.h
+++ b/src/glsl/ir_variable_refcount.h
@@ -60,6 +60,7 @@ public:
virtual ir_visitor_status visit_enter(ir_function_signature *);
virtual ir_visitor_status visit_leave(ir_assignment *);
+ virtual ir_visitor_status visit_leave(ir_loop *);
ir_variable_refcount_entry *get_variable_entry(ir_variable *var);
More information about the mesa-commit
mailing list