[Mesa-dev] [PATCH 12/24] glsl: Add predicate to determine if an IR node has side effects.
Francisco Jerez
currojerez at riseup.net
Sun Sep 15 00:10:38 PDT 2013
And fix the dead code elimination pass so atomic writes aren't
optimized out in cases where the return value isn't used by the
program.
---
src/glsl/ir.h | 16 ++++++++++++++++
src/glsl/opt_dead_code.cpp | 3 ++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index c4b4677..4f506a3 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -139,6 +139,17 @@ public:
virtual class ir_jump * as_jump() { return NULL; }
/*@}*/
+ /**
+ * Determine if an IR instruction has side effects other than its
+ * returned value(s). Optimization passes are expected to be
+ * especially careful with reordering or removing these, unless
+ * they know what they are doing.
+ */
+ virtual bool has_side_effects() const
+ {
+ return false;
+ }
+
protected:
ir_instruction()
{
@@ -2120,6 +2131,11 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+ virtual bool has_side_effects() const
+ {
+ return true;
+ }
+
/** Kind of atomic instruction. */
enum ir_atomic_opcode op;
diff --git a/src/glsl/opt_dead_code.cpp b/src/glsl/opt_dead_code.cpp
index b65e5c2..fd05034 100644
--- a/src/glsl/opt_dead_code.cpp
+++ b/src/glsl/opt_dead_code.cpp
@@ -81,7 +81,8 @@ do_dead_code(exec_list *instructions, bool uniform_locations_assigned)
*/
if (entry->var->mode != ir_var_function_out &&
entry->var->mode != ir_var_function_inout &&
- entry->var->mode != ir_var_shader_out) {
+ entry->var->mode != ir_var_shader_out &&
+ !entry->assign->rhs->has_side_effects()) {
entry->assign->remove();
progress = true;
--
1.8.3.4
More information about the mesa-dev
mailing list