summaryrefslogtreecommitdiff
path: root/src/ir/branch-utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/branch-utils.h')
-rw-r--r--src/ir/branch-utils.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/ir/branch-utils.h b/src/ir/branch-utils.h
index f2fa43f18..57bad2fb9 100644
--- a/src/ir/branch-utils.h
+++ b/src/ir/branch-utils.h
@@ -238,6 +238,28 @@ inline NameSet getBranchTargets(Expression* ast) {
return scanner.targets;
}
+// Check if an expression defines a particular name as a branch target anywhere
+// inside it.
+inline bool hasBranchTarget(Expression* ast, Name target) {
+ struct Scanner
+ : public PostWalker<Scanner, UnifiedExpressionVisitor<Scanner>> {
+ Name target;
+ bool has = false;
+
+ void visitExpression(Expression* curr) {
+ operateOnScopeNameDefs(curr, [&](Name& name) {
+ if (name == target) {
+ has = true;
+ }
+ });
+ }
+ };
+ Scanner scanner;
+ scanner.target = target;
+ scanner.walk(ast);
+ return scanner.has;
+}
+
// Get the name of the branch target that is defined in the expression, or an
// empty name if there is none.
inline Name getDefinedName(Expression* curr) {