From 66d4c65ee2c311ea0c71c39a28456d0c11798d6b Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 27 Jul 2010 11:28:26 -0700 Subject: [PATCH] glsl2: Make the dead code handler make its own talloc context. This way, we don't need to pass in a parse state, and the context doesn't grow with the number of passes through optimization. --- src/glsl/ir_dead_code.cpp | 12 ++++++------ src/glsl/ir_optimization.h | 6 ++---- src/glsl/main.cpp | 2 +- src/mesa/program/ir_to_mesa.cpp | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/glsl/ir_dead_code.cpp b/src/glsl/ir_dead_code.cpp index ea78107f493..4804407bdc3 100644 --- a/src/glsl/ir_dead_code.cpp +++ b/src/glsl/ir_dead_code.cpp @@ -146,13 +146,12 @@ ir_dead_code_visitor::visit_leave(ir_assignment *ir) * for usage on an unlinked instruction stream. */ bool -do_dead_code(struct _mesa_glsl_parse_state *state, - exec_list *instructions) +do_dead_code(exec_list *instructions) { ir_dead_code_visitor v; bool progress = false; - v.mem_ctx = state; + v.mem_ctx = talloc_new(NULL); v.run(instructions); foreach_iter(exec_list_iterator, iter, v.variable_list) { @@ -188,6 +187,8 @@ do_dead_code(struct _mesa_glsl_parse_state *state, progress = true; } } + talloc_free(v.mem_ctx); + return progress; } @@ -199,8 +200,7 @@ do_dead_code(struct _mesa_glsl_parse_state *state, * with global scope. */ bool -do_dead_code_unlinked(struct _mesa_glsl_parse_state *state, - exec_list *instructions) +do_dead_code_unlinked(exec_list *instructions) { bool progress = false; @@ -211,7 +211,7 @@ do_dead_code_unlinked(struct _mesa_glsl_parse_state *state, foreach_iter(exec_list_iterator, sigiter, *f) { ir_function_signature *sig = (ir_function_signature *) sigiter.get(); - if (do_dead_code(state, &sig->body)) + if (do_dead_code(&sig->body)) progress = true; } } diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h index 4f39565e5f1..5dbb025d357 100644 --- a/src/glsl/ir_optimization.h +++ b/src/glsl/ir_optimization.h @@ -33,11 +33,9 @@ bool do_constant_folding(exec_list *instructions); bool do_constant_variable(exec_list *instructions); bool do_constant_variable_unlinked(exec_list *instructions); bool do_copy_propagation(exec_list *instructions); -bool do_dead_code(struct _mesa_glsl_parse_state *state, - exec_list *instructions); +bool do_dead_code(exec_list *instructions); bool do_dead_code_local(exec_list *instructions); -bool do_dead_code_unlinked(struct _mesa_glsl_parse_state *state, - exec_list *instructions); +bool do_dead_code_unlinked(exec_list *instructions); bool do_div_to_mul_rcp(exec_list *instructions); bool do_function_inlining(exec_list *instructions); bool do_if_return(exec_list *instructions); diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp index b62902278c4..08b133f124e 100644 --- a/src/glsl/main.cpp +++ b/src/glsl/main.cpp @@ -162,7 +162,7 @@ compile_shader(struct gl_shader *shader) progress = do_if_simplification(shader->ir) || progress; progress = do_copy_propagation(shader->ir) || progress; progress = do_dead_code_local(shader->ir) || progress; - progress = do_dead_code_unlinked(state, shader->ir) || progress; + progress = do_dead_code_unlinked(shader->ir) || progress; progress = do_constant_variable_unlinked(shader->ir) || progress; progress = do_constant_folding(shader->ir) || progress; progress = do_algebraic(shader->ir) || progress; diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 5cc999c2e35..409b6d72881 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -2237,7 +2237,7 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader) progress = do_if_simplification(shader->ir) || progress; progress = do_copy_propagation(shader->ir) || progress; progress = do_dead_code_local(shader->ir) || progress; - progress = do_dead_code_unlinked(state, shader->ir) || progress; + progress = do_dead_code_unlinked(shader->ir) || progress; progress = do_constant_variable_unlinked(shader->ir) || progress; progress = do_constant_folding(shader->ir) || progress; progress = do_algebraic(shader->ir) || progress; -- 2.30.2