diff options
Diffstat (limited to 'src/passes/RelooperJumpThreading.cpp')
-rw-r--r-- | src/passes/RelooperJumpThreading.cpp | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/src/passes/RelooperJumpThreading.cpp b/src/passes/RelooperJumpThreading.cpp index 9a6d82e0e..d3fd1844f 100644 --- a/src/passes/RelooperJumpThreading.cpp +++ b/src/passes/RelooperJumpThreading.cpp @@ -27,25 +27,13 @@ namespace wasm { static Name LABEL("label"); -// We need to use new label names, which we cannot create in parallel, so pre-create them - -const Index MAX_NAME_INDEX = 10000; - -std::vector<Name>* innerNames = nullptr; -std::vector<Name>* outerNames = nullptr; +static Name getInnerName(int i) { + return Name(std::string("__rjti$") + std::to_string(i)); +} -struct NameEnsurer { - NameEnsurer() { - assert(!innerNames); - assert(!outerNames); - innerNames = new std::vector<Name>; - outerNames = new std::vector<Name>; - for (Index i = 0; i < MAX_NAME_INDEX; i++) { - innerNames->push_back(Name(std::string("__rjti$") + std::to_string(i))); - outerNames->push_back(Name(std::string("__rjto$") + std::to_string(i))); - } - } -}; +static Name getOuterName(int i) { + return Name(std::string("__rjto$") + std::to_string(i)); +} static If* isLabelCheckingIf(Expression* curr, Index labelIndex) { if (!curr) return nullptr; @@ -99,10 +87,6 @@ struct RelooperJumpThreading : public WalkerPass<ExpressionStackWalker<RelooperJ Pass* create() override { return new RelooperJumpThreading; } - void prepareToRun(PassRunner* runner, Module* module) override { - static NameEnsurer ensurer; - } - std::map<Index, Index> labelChecks; std::map<Index, Index> labelSets; @@ -208,17 +192,13 @@ private: // * iff is the if void optimizeJumpsToLabelCheck(Expression*& origin, If* iff) { Index nameCounter = newNameCounter++; - if (nameCounter >= MAX_NAME_INDEX) { - std::cerr << "too many names in RelooperJumpThreading :(\n"; - return; - } Index num = getCheckedLabelValue(iff); // create a new block for this jump target Builder builder(*getModule()); // origin is where all jumps to this target must come from - the element right before this if // we break out of inner to reach the target. instead of flowing out of normally, we break out of the outer, so we skip the target. - auto innerName = innerNames->at(nameCounter); - auto outerName = outerNames->at(nameCounter); + auto innerName = getInnerName(nameCounter); + auto outerName = getOuterName(nameCounter); auto* ifFalse = iff->ifFalse; // all assignments of label to the target can be replaced with breaks to the target, via innerName struct JumpUpdater : public PostWalker<JumpUpdater> { |