diff options
author | Max Graey <maxgraey@gmail.com> | 2020-08-25 00:06:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-24 14:06:06 -0700 |
commit | 21a08f751bd641f9658455cbf44ecadbf895f5b2 (patch) | |
tree | e23086a4b1ef857247c15f35b160f941a2c32d9c /src | |
parent | 429b2611f3a159efe3b27f99be34d7aebe9bf45f (diff) | |
download | binaryen-21a08f751bd641f9658455cbf44ecadbf895f5b2.tar.gz binaryen-21a08f751bd641f9658455cbf44ecadbf895f5b2.tar.bz2 binaryen-21a08f751bd641f9658455cbf44ecadbf895f5b2.zip |
Avoid wasted work when there are no locals (#3060)
Adds early returns to local optimizations passes in cases where there are no locals to optimize.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/RedundantSetElimination.cpp | 3 | ||||
-rw-r--r-- | src/passes/ReorderLocals.cpp | 9 | ||||
-rw-r--r-- | src/passes/SimplifyLocals.cpp | 3 |
3 files changed, 11 insertions, 4 deletions
diff --git a/src/passes/RedundantSetElimination.cpp b/src/passes/RedundantSetElimination.cpp index a891653df..e36cefc9e 100644 --- a/src/passes/RedundantSetElimination.cpp +++ b/src/passes/RedundantSetElimination.cpp @@ -81,6 +81,9 @@ struct RedundantSetElimination void doWalkFunction(Function* func) { numLocals = func->getNumLocals(); + if (numLocals == 0) { + return; // nothing to do + } // create the CFG by walking the IR CFGWalker<RedundantSetElimination, Visitor<RedundantSetElimination>, Info>:: doWalkFunction(func); diff --git a/src/passes/ReorderLocals.cpp b/src/passes/ReorderLocals.cpp index 7b4c99e78..8d7c0f1d9 100644 --- a/src/passes/ReorderLocals.cpp +++ b/src/passes/ReorderLocals.cpp @@ -46,6 +46,9 @@ struct ReorderLocals : public WalkerPass<PostWalker<ReorderLocals>> { enum { Unseen = 0 }; void doWalkFunction(Function* curr) { + if (curr->getNumVars() == 0) { + return; // nothing to do. All locals are parameters + } Index num = curr->getNumLocals(); counts.resize(num); std::fill(counts.begin(), counts.end(), 0); @@ -54,9 +57,9 @@ struct ReorderLocals : public WalkerPass<PostWalker<ReorderLocals>> { // Gather information about local usages. walk(curr->body); // Use the information about local usages. - std::vector<Index> newToOld; + std::vector<Index> newToOld(num); for (size_t i = 0; i < num; i++) { - newToOld.push_back(i); + newToOld[i] = i; } // sort, keeping params in front (where they will not be moved) sort( @@ -82,8 +85,6 @@ struct ReorderLocals : public WalkerPass<PostWalker<ReorderLocals>> { size_t numParams = curr->sig.params.size(); for (size_t i = 0; i < numParams; i++) { assert(newToOld[i] < numParams); - } - for (size_t i = 0; i < numParams; i++) { newToOld[i] = i; } // sort vars, and drop unused ones diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp index ca3d714f4..9c831a551 100644 --- a/src/passes/SimplifyLocals.cpp +++ b/src/passes/SimplifyLocals.cpp @@ -811,6 +811,9 @@ struct SimplifyLocals } void doWalkFunction(Function* func) { + if (func->getNumLocals() == 0) { + return; // nothing to do + } // scan local.gets getCounter.analyze(func); // multiple passes may be required per function, consider this: |