summaryrefslogtreecommitdiff
path: root/src/pass.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-09-14 21:28:43 -0700
committerGitHub <noreply@github.com>2016-09-14 21:28:43 -0700
commite567fa8675831e79f855cea2181fa58beb107e42 (patch)
tree14f1e37d27244b349e8ee34939119002f742748d /src/pass.h
parent63b499e3ec9bbdf4e79ab6d9dc198299516e8aec (diff)
parentaf3bea2786fe62070522b7fd7add4290a4cb4e6d (diff)
downloadbinaryen-e567fa8675831e79f855cea2181fa58beb107e42.tar.gz
binaryen-e567fa8675831e79f855cea2181fa58beb107e42.tar.bz2
binaryen-e567fa8675831e79f855cea2181fa58beb107e42.zip
Merge pull request #695 from WebAssembly/opts
Get optimizer on par with emscripten asm.js optimizer
Diffstat (limited to 'src/pass.h')
-rw-r--r--src/pass.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/pass.h b/src/pass.h
index 0ad8d8c1d..e237b8a98 100644
--- a/src/pass.h
+++ b/src/pass.h
@@ -72,17 +72,17 @@ struct PassRunner {
void add(std::string passName) {
auto pass = PassRegistry::get()->createPass(passName);
if (!pass) Fatal() << "Could not find pass: " << passName << "\n";
- passes.push_back(pass);
+ doAdd(pass);
}
template<class P>
void add() {
- passes.push_back(new P());
+ doAdd(new P());
}
template<class P, class Arg>
void add(Arg arg){
- passes.push_back(new P(arg));
+ doAdd(new P(arg));
}
// Adds the default set of optimization passes; this is
@@ -110,6 +110,8 @@ struct PassRunner {
~PassRunner();
private:
+ void doAdd(Pass* pass);
+
void runPassOnFunction(Pass* pass, Function* func);
};
@@ -121,12 +123,13 @@ public:
virtual ~Pass() {};
// Override this to perform preparation work before the pass runs.
- virtual void prepare(PassRunner* runner, Module* module) {}
+ // This will be called before the pass is run on a module.
+ virtual void prepareToRun(PassRunner* runner, Module* module) {}
+
+ // Implement this with code to run the pass on the whole module
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) {}
- // Run on a single function. This has no prepare/finalize calls.
+ // Implement this with code to run the pass on a single function
virtual void runFunction(PassRunner* runner, Module* module, Function* function) {
WASM_UNREACHABLE(); // by default, passes cannot be run this way
}
@@ -166,9 +169,7 @@ template <typename WalkerType>
class WalkerPass : public Pass, public WalkerType {
public:
void run(PassRunner* runner, Module* module) override {
- prepare(runner, module);
WalkerType::walkModule(module);
- finalize(runner, module);
}
void runFunction(PassRunner* runner, Module* module, Function* func) override {