diff options
-rw-r--r-- | src/binaryen-shell.cpp | 1 | ||||
-rw-r--r-- | src/pass.cpp | 16 | ||||
-rw-r--r-- | src/pass.h | 6 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp index 8f99d1295..6e3cc8af2 100644 --- a/src/binaryen-shell.cpp +++ b/src/binaryen-shell.cpp @@ -227,6 +227,7 @@ int main(int argc, const char* argv[]) { if (passes.size() > 0) { if (options.debug) std::cerr << "running passes...\n"; PassRunner passRunner(&moreModuleAllocations); + if (options.debug) passRunner.setDebug(true); for (auto& passName : passes) { if (passName == "O") { passRunner.addDefaultOptimizationPasses(); diff --git a/src/pass.cpp b/src/pass.cpp index a85643efa..b0d4a316e 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include <chrono> + #include <pass.h> namespace wasm { @@ -35,7 +37,9 @@ void PassRegistry::registerPass(const char* name, const char *description, Creat Pass* PassRegistry::createPass(std::string name) { if (passInfos.find(name) == passInfos.end()) return nullptr; - return passInfos[name].create(); + auto ret = passInfos[name].create(); + ret->name = name; + return ret; } std::vector<std::string> PassRegistry::getRegisteredNames() { @@ -66,7 +70,17 @@ void PassRunner::addDefaultOptimizationPasses() { void PassRunner::run(Module* module) { for (auto pass : passes) { currPass = pass; + std::chrono::high_resolution_clock::time_point before; + if (debug) { + std::cerr << "[PassRunner] running pass: " << pass->name << std::endl; + before = std::chrono::high_resolution_clock::now(); + } pass->run(this, module); + if (debug) { + auto after = std::chrono::high_resolution_clock::now(); + std::chrono::duration<double> diff = after - before; + std::cerr << "[PassRunner] pass took " << diff.count() << " seconds." << std::endl; + } } } diff --git a/src/pass.h b/src/pass.h index 503c164f9..2c3a09ae6 100644 --- a/src/pass.h +++ b/src/pass.h @@ -69,9 +69,12 @@ struct PassRunner { MixedArena* allocator; std::vector<Pass*> passes; Pass* currPass; + bool debug = false; PassRunner(MixedArena* allocator) : allocator(allocator) {} + void setDebug(bool debug_) { debug = debug_; } + void add(std::string passName) { auto pass = PassRegistry::get()->createPass(passName); assert(pass); @@ -112,6 +115,9 @@ public: virtual void run(PassRunner* runner, Module* module) = 0; // Override this to perform finalization work after the pass runs. virtual void finalize(PassRunner* runner, Module* module) {} + + std::string name; + protected: Pass() {} Pass(Pass &) {} |