diff options
-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: |