From 01f5eb8cf7d280e12985e628041ba57f9f8402d1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 20 Jul 2023 12:46:28 -0700 Subject: [NFC] Avoid using ControlFlowWalker in CFGWalker (#5827) ControlFlowWalker builds a stack of control flow items and allows finding the target of a branch using it. But the only use CFGWalker made of that was to map a block or a loop to its branches. We can just use the name of the block or loop in the map, and avoid the extra overhead. --- src/cfg/cfg-traversal.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/cfg/cfg-traversal.h b/src/cfg/cfg-traversal.h index 344c6b8ba..739e10e45 100644 --- a/src/cfg/cfg-traversal.h +++ b/src/cfg/cfg-traversal.h @@ -37,7 +37,7 @@ namespace wasm { template -struct CFGWalker : public ControlFlowWalker { +struct CFGWalker : public PostWalker { // public interface @@ -87,7 +87,7 @@ struct CFGWalker : public ControlFlowWalker { // analysis on the CFG once it is constructed). BasicBlock* currBasicBlock; // a block or loop => its branches - std::map> branches; + std::map> branches; // stack of the last blocks of if conditions + the last blocks of if true // bodies std::vector ifStack; @@ -142,7 +142,7 @@ struct CFGWalker : public ControlFlowWalker { if (!curr->name.is()) { return; } - auto iter = self->branches.find(curr); + auto iter = self->branches.find(curr->name); if (iter == self->branches.end()) { return; } @@ -158,7 +158,7 @@ struct CFGWalker : public ControlFlowWalker { for (auto* origin : origins) { self->link(origin, self->currBasicBlock); } - self->branches.erase(curr); + self->branches.erase(curr->name); } static void doStartIfTrue(SubType* self, Expression** currp) { @@ -206,11 +206,11 @@ struct CFGWalker : public ControlFlowWalker { // branches to the top of the loop if (curr->name.is()) { auto* loopStart = self->loopStack.back(); - auto& origins = self->branches[curr]; + auto& origins = self->branches[curr->name]; for (auto* origin : origins) { self->link(origin, loopStart); } - self->branches.erase(curr); + self->branches.erase(curr->name); } self->loopStack.pop_back(); } @@ -220,8 +220,7 @@ struct CFGWalker : public ControlFlowWalker { auto branchTargets = BranchUtils::getUniqueTargets(curr); // Add branches to the targets. for (auto target : branchTargets) { - self->branches[self->findBreakTarget(target)].push_back( - self->currBasicBlock); + self->branches[target].push_back(self->currBasicBlock); } if (curr->type != Type::unreachable) { auto* last = self->currBasicBlock; @@ -424,7 +423,7 @@ struct CFGWalker : public ControlFlowWalker { } } - ControlFlowWalker::scan(self, currp); + PostWalker::scan(self, currp); switch (curr->_id) { case Expression::Id::LoopId: { @@ -441,7 +440,7 @@ struct CFGWalker : public ControlFlowWalker { startBasicBlock(); entry = currBasicBlock; - ControlFlowWalker::doWalkFunction(func); + PostWalker::doWalkFunction(func); exit = currBasicBlock; assert(branches.size() == 0); -- cgit v1.2.3