summaryrefslogtreecommitdiff
path: root/src/ast/branch-utils.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-09-06 10:00:57 -0700
committerGitHub <noreply@github.com>2017-09-06 10:00:57 -0700
commit192b59a8bc8e5376ca120dc592d5abad7c654230 (patch)
tree26bb4ab92728c2e0640bfddde962248b37fa54f3 /src/ast/branch-utils.h
parentc0f21e10a1166829afd34c4fb06366d7430802bb (diff)
downloadbinaryen-192b59a8bc8e5376ca120dc592d5abad7c654230.tar.gz
binaryen-192b59a8bc8e5376ca120dc592d5abad7c654230.tar.bz2
binaryen-192b59a8bc8e5376ca120dc592d5abad7c654230.zip
clean up untaken => unreachable, as well as unnecessary named stuff in validation that was from when we differentiated reachable from unreachable breaks (#1166)
Diffstat (limited to 'src/ast/branch-utils.h')
-rw-r--r--src/ast/branch-utils.h22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/ast/branch-utils.h b/src/ast/branch-utils.h
index 05ead8571..d574945ef 100644
--- a/src/ast/branch-utils.h
+++ b/src/ast/branch-utils.h
@@ -24,24 +24,23 @@ namespace wasm {
namespace BranchUtils {
-// branches not actually taken (e.g. (br $out (unreachable)))
-// are trivially ignored in our type system
+// Some branches are obviously not actually reachable (e.g. (br $out (unreachable)))
-inline bool isBranchTaken(Break* br) {
+inline bool isBranchReachable(Break* br) {
return !(br->value && br->value->type == unreachable) &&
!(br->condition && br->condition->type == unreachable);
}
-inline bool isBranchTaken(Switch* sw) {
+inline bool isBranchReachable(Switch* sw) {
return !(sw->value && sw->value->type == unreachable) &&
sw->condition->type != unreachable;
}
-inline bool isBranchTaken(Expression* expr) {
+inline bool isBranchReachable(Expression* expr) {
if (auto* br = expr->dynCast<Break>()) {
- return isBranchTaken(br);
+ return isBranchReachable(br);
} else if (auto* sw = expr->dynCast<Switch>()) {
- return isBranchTaken(sw);
+ return isBranchReachable(sw);
}
WASM_UNREACHABLE();
}
@@ -103,8 +102,9 @@ inline std::set<Name> getBranchTargets(Expression* ast) {
// Finds if there are branches targeting a name. Note that since names are
// unique in our IR, we just need to look for the name, and do not need
// to analyze scoping.
-// By default we consider untaken branches (so any named use). You can unset named to
-// avoid that (and only note branches that are not obviously unreachable)
+// By default we consider all branches, so any place there is a branch that
+// names the target. You can unset 'named' to only note branches that appear
+// reachable (i.e., are not obviously unreachable).
struct BranchSeeker : public PostWalker<BranchSeeker> {
Name target;
bool named = true;
@@ -144,7 +144,7 @@ struct BranchSeeker : public PostWalker<BranchSeeker> {
if (curr->default_ == target) noteFound(curr->value);
}
- static bool hasTaken(Expression* tree, Name target) {
+ static bool hasReachable(Expression* tree, Name target) {
if (!target.is()) return false;
BranchSeeker seeker(target);
seeker.named = false;
@@ -152,7 +152,7 @@ struct BranchSeeker : public PostWalker<BranchSeeker> {
return seeker.found > 0;
}
- static Index countTaken(Expression* tree, Name target) {
+ static Index countReachable(Expression* tree, Name target) {
if (!target.is()) return 0;
BranchSeeker seeker(target);
seeker.named = false;