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.h62
1 files changed, 37 insertions, 25 deletions
diff --git a/src/ir/branch-utils.h b/src/ir/branch-utils.h
index b9448e590..f62941e15 100644
--- a/src/ir/branch-utils.h
+++ b/src/ir/branch-utils.h
@@ -17,23 +17,24 @@
#ifndef wasm_ir_branch_h
#define wasm_ir_branch_h
-#include "wasm.h"
#include "wasm-traversal.h"
+#include "wasm.h"
namespace wasm {
namespace BranchUtils {
-// Some branches are obviously not actually reachable (e.g. (br $out (unreachable)))
+// Some branches are obviously not actually reachable (e.g. (br $out
+// (unreachable)))
inline bool isBranchReachable(Break* br) {
- return !(br->value && br->value->type == unreachable) &&
+ return !(br->value && br->value->type == unreachable) &&
!(br->condition && br->condition->type == unreachable);
}
inline bool isBranchReachable(Switch* sw) {
- return !(sw->value && sw->value->type == unreachable) &&
- sw->condition->type != unreachable;
+ return !(sw->value && sw->value->type == unreachable) &&
+ sw->condition->type != unreachable;
}
inline bool isBranchReachable(Expression* expr) {
@@ -91,9 +92,7 @@ inline std::set<Name> getExitingBranches(Expression* ast) {
struct Scanner : public PostWalker<Scanner> {
std::set<Name> targets;
- void visitBreak(Break* curr) {
- targets.insert(curr->name);
- }
+ void visitBreak(Break* curr) { targets.insert(curr->name); }
void visitSwitch(Switch* curr) {
for (auto target : curr->targets) {
targets.insert(target);
@@ -156,36 +155,47 @@ struct BranchSeeker : public PostWalker<BranchSeeker> {
void noteFound(Expression* value) {
found++;
- if (found == 1) valueType = unreachable;
- if (!value) valueType = none;
- else if (value->type != unreachable) valueType = value->type;
+ if (found == 1)
+ valueType = unreachable;
+ if (!value)
+ valueType = none;
+ else if (value->type != unreachable)
+ valueType = value->type;
}
- void visitBreak(Break *curr) {
+ void visitBreak(Break* curr) {
if (!named) {
// ignore an unreachable break
- if (curr->condition && curr->condition->type == unreachable) return;
- if (curr->value && curr->value->type == unreachable) return;
+ if (curr->condition && curr->condition->type == unreachable)
+ return;
+ if (curr->value && curr->value->type == unreachable)
+ return;
}
// check the break
- if (curr->name == target) noteFound(curr->value);
+ if (curr->name == target)
+ noteFound(curr->value);
}
- void visitSwitch(Switch *curr) {
+ void visitSwitch(Switch* curr) {
if (!named) {
// ignore an unreachable switch
- if (curr->condition->type == unreachable) return;
- if (curr->value && curr->value->type == unreachable) return;
+ if (curr->condition->type == unreachable)
+ return;
+ if (curr->value && curr->value->type == unreachable)
+ return;
}
// check the switch
for (auto name : curr->targets) {
- if (name == target) noteFound(curr->value);
+ if (name == target)
+ noteFound(curr->value);
}
- if (curr->default_ == target) noteFound(curr->value);
+ if (curr->default_ == target)
+ noteFound(curr->value);
}
static bool hasReachable(Expression* tree, Name target) {
- if (!target.is()) return false;
+ if (!target.is())
+ return false;
BranchSeeker seeker(target);
seeker.named = false;
seeker.walk(tree);
@@ -193,7 +203,8 @@ struct BranchSeeker : public PostWalker<BranchSeeker> {
}
static Index countReachable(Expression* tree, Name target) {
- if (!target.is()) return 0;
+ if (!target.is())
+ return 0;
BranchSeeker seeker(target);
seeker.named = false;
seeker.walk(tree);
@@ -201,14 +212,16 @@ struct BranchSeeker : public PostWalker<BranchSeeker> {
}
static bool hasNamed(Expression* tree, Name target) {
- if (!target.is()) return false;
+ if (!target.is())
+ return false;
BranchSeeker seeker(target);
seeker.walk(tree);
return seeker.found > 0;
}
static Index countNamed(Expression* tree, Name target) {
- if (!target.is()) return 0;
+ if (!target.is())
+ return 0;
BranchSeeker seeker(target);
seeker.walk(tree);
return seeker.found;
@@ -220,4 +233,3 @@ struct BranchSeeker : public PostWalker<BranchSeeker> {
} // namespace wasm
#endif // wasm_ir_branch_h
-