glsl/hierarchical_visitor: Call leave_callback on leaf nodes
authorNeil Roberts <nroberts@igalia.com>
Wed, 2 Oct 2019 21:11:48 +0000 (17:11 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 24 Mar 2020 23:21:21 +0000 (23:21 +0000)
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 <hoegsberg@google.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3885>

src/compiler/glsl/ir_hierarchical_visitor.cpp
src/compiler/glsl/ir_hierarchical_visitor.h

index 8fcf48e2bb418543e4764911027809818c726574..9c126044eb37423babcf82d81e42734dcbf716df 100644 (file)
@@ -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,
index e10bb7c60db57491d2b18ca45ec5466f8b3f3046..dff6a39a6a43db18ca423226deda2495245b1a94 100644 (file)
@@ -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