From c525785edc33d36bbb906d3004be213d25b9467b Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 2 Oct 2019 17:11:48 -0400 Subject: [PATCH] glsl/hierarchical_visitor: Call leave_callback on leaf nodes Previously for leaf ir_instructions only the enter callback was called. This makes it a bit difficult to make a pass that wants to visit every instruction using a stack. Making it call the leave callback as well makes it behave less surprisingly. Reviewed-by: Kristian H. Kristensen Acked-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/ir_hierarchical_visitor.cpp | 26 ++++++++++--------- src/compiler/glsl/ir_hierarchical_visitor.h | 6 +++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/compiler/glsl/ir_hierarchical_visitor.cpp b/src/compiler/glsl/ir_hierarchical_visitor.cpp index 8fcf48e2bb4..9c126044eb3 100644 --- a/src/compiler/glsl/ir_hierarchical_visitor.cpp +++ b/src/compiler/glsl/ir_hierarchical_visitor.cpp @@ -37,8 +37,7 @@ ir_hierarchical_visitor::ir_hierarchical_visitor() ir_visitor_status ir_hierarchical_visitor::visit(ir_rvalue *ir) { - if (this->callback_enter != NULL) - this->callback_enter(ir, this->data_enter); + call_enter_leave_callbacks(ir); return visit_continue; } @@ -46,8 +45,7 @@ ir_hierarchical_visitor::visit(ir_rvalue *ir) ir_visitor_status ir_hierarchical_visitor::visit(ir_variable *ir) { - if (this->callback_enter != NULL) - this->callback_enter(ir, this->data_enter); + call_enter_leave_callbacks(ir); return visit_continue; } @@ -55,8 +53,7 @@ ir_hierarchical_visitor::visit(ir_variable *ir) ir_visitor_status ir_hierarchical_visitor::visit(ir_constant *ir) { - if (this->callback_enter != NULL) - this->callback_enter(ir, this->data_enter); + call_enter_leave_callbacks(ir); return visit_continue; } @@ -64,8 +61,7 @@ ir_hierarchical_visitor::visit(ir_constant *ir) ir_visitor_status ir_hierarchical_visitor::visit(ir_loop_jump *ir) { - if (this->callback_enter != NULL) - this->callback_enter(ir, this->data_enter); + call_enter_leave_callbacks(ir); return visit_continue; } @@ -73,8 +69,7 @@ ir_hierarchical_visitor::visit(ir_loop_jump *ir) ir_visitor_status ir_hierarchical_visitor::visit(ir_dereference_variable *ir) { - if (this->callback_enter != NULL) - this->callback_enter(ir, this->data_enter); + call_enter_leave_callbacks(ir); return visit_continue; } @@ -82,8 +77,7 @@ ir_hierarchical_visitor::visit(ir_dereference_variable *ir) ir_visitor_status ir_hierarchical_visitor::visit(ir_barrier *ir) { - if (this->callback_enter != NULL) - this->callback_enter(ir, this->data_enter); + call_enter_leave_callbacks(ir); return visit_continue; } @@ -382,6 +376,14 @@ ir_hierarchical_visitor::run(exec_list *instructions) visit_list_elements(this, instructions); } +void +ir_hierarchical_visitor::call_enter_leave_callbacks(class ir_instruction *ir) +{ + if (this->callback_enter != NULL) + this->callback_enter(ir, this->data_enter); + if (this->callback_leave != NULL) + this->callback_leave(ir, this->data_leave); +} void visit_tree(ir_instruction *ir, diff --git a/src/compiler/glsl/ir_hierarchical_visitor.h b/src/compiler/glsl/ir_hierarchical_visitor.h index e10bb7c60db..dff6a39a6a4 100644 --- a/src/compiler/glsl/ir_hierarchical_visitor.h +++ b/src/compiler/glsl/ir_hierarchical_visitor.h @@ -149,6 +149,12 @@ public: */ void run(struct exec_list *instructions); + /** + * Utility function to call both the leave and enter callback functions. + * This is used for leaf nodes. + */ + void call_enter_leave_callbacks(class ir_instruction *ir); + /* Some visitors may need to insert new variable declarations and * assignments for portions of a subtree, which means they need a * pointer to the current instruction in the stream, not just their -- 2.30.2