summaryrefslogtreecommitdiff
path: root/ir_basic_block.cpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-05-14 14:11:06 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-05-17 12:03:13 -0700
commit77dd4f3536905f1b3a5c33b3758dc7e230332b38 (patch)
treedfa68bd9d2b48803170c514d5b6d644b9076d17a /ir_basic_block.cpp
parenta0b4f3d631cefa6ee3f341461e4754ef6462f89b (diff)
Reimplement has_call_callback using ir_hierarchical_vistor
This has the added advantage that it will stop traversing the tree as soon as the first call is found. The output of all test cases was verified to be the same using diff.
Diffstat (limited to 'ir_basic_block.cpp')
-rw-r--r--ir_basic_block.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/ir_basic_block.cpp b/ir_basic_block.cpp
index 455398e499..2cf3704605 100644
--- a/ir_basic_block.cpp
+++ b/ir_basic_block.cpp
@@ -30,17 +30,25 @@
#include <stdio.h>
#include "ir.h"
#include "ir_visitor.h"
-#include "ir_visit_tree.h"
#include "ir_basic_block.h"
#include "glsl_types.h"
-static void
-has_call_callback(ir_instruction *ir, void *data)
-{
- bool *has_call = (bool *)data;
+class ir_has_call_visitor : public ir_hierarchical_visitor {
+public:
+ ir_has_call_visitor()
+ {
+ has_call = false;
+ }
- *has_call = *has_call || ir->as_call();
-}
+ virtual ir_visitor_status visit_enter(ir_call *ir)
+ {
+ (void) ir;
+ has_call = true;
+ return visit_stop;
+ }
+
+ bool has_call;
+};
/**
* Calls a user function for every basic block in the instruction stream.
@@ -108,7 +116,7 @@ void call_for_basic_blocks(exec_list *instructions,
call_for_basic_blocks(&ir_sig->body, callback, data);
}
} else if (ir->as_assignment()) {
- bool has_call = false;
+ ir_has_call_visitor v;
/* If there's a call in the expression tree being assigned,
* then that ends the BB too.
@@ -123,9 +131,8 @@ void call_for_basic_blocks(exec_list *instructions,
* expression flattener may be useful before using the basic
* block finder to get more maximal basic blocks out.
*/
- ir_visit_tree(ir, has_call_callback, &has_call);
-
- if (has_call) {
+ ir->accept(&v);
+ if (v.has_call) {
callback(leader, ir, data);
leader = NULL;
}