summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/SimplifyGlobals.cpp19
-rw-r--r--src/passes/pass.cpp3
-rw-r--r--src/passes/passes.h1
3 files changed, 21 insertions, 2 deletions
diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp
index 323ebd6a7..d4a6e1f3b 100644
--- a/src/passes/SimplifyGlobals.cpp
+++ b/src/passes/SimplifyGlobals.cpp
@@ -673,11 +673,12 @@ struct SimplifyGlobals : public Pass {
// go, as well as applying them where possible.
for (auto& global : module->globals) {
if (!global->imported()) {
+ // Apply globals to this value, which may turn it into a constant we can
+ // further propagate, or it may already have been one.
+ applyGlobals(global->init);
if (Properties::isConstantExpression(global->init)) {
constantGlobals[global->name] =
getLiteralsFromConstExpression(global->init);
- } else {
- applyGlobals(global->init);
}
}
}
@@ -762,10 +763,24 @@ struct SimplifyGlobals : public Pass {
}
};
+// A pass mainly useful for testing that only performs the operation to
+// propagate constant values between globals.
+struct PropagateGlobalsGlobally : public SimplifyGlobals {
+ void run(Module* module_) override {
+ module = module_;
+
+ propagateConstantsToGlobals();
+ }
+};
+
Pass* createSimplifyGlobalsPass() { return new SimplifyGlobals(false); }
Pass* createSimplifyGlobalsOptimizingPass() {
return new SimplifyGlobals(true);
}
+Pass* createPropagateGlobalsGloballyPass() {
+ return new PropagateGlobalsGlobally();
+}
+
} // namespace wasm
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index c00a5e706..1fe81cbfc 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -369,6 +369,9 @@ void PassRegistry::registerPasses() {
registerPass("print-stack-ir",
"print out Stack IR (useful for internal debugging)",
createPrintStackIRPass);
+ registerPass("propagate-globals-globally",
+ "propagate global values to other globals (useful for tests)",
+ createPropagateGlobalsGloballyPass);
registerPass("remove-non-js-ops",
"removes operations incompatible with js",
createRemoveNonJSOpsPass);
diff --git a/src/passes/passes.h b/src/passes/passes.h
index 3f8b3fe6b..c3ab7773f 100644
--- a/src/passes/passes.h
+++ b/src/passes/passes.h
@@ -123,6 +123,7 @@ Pass* createPrintCallGraphPass();
Pass* createPrintFeaturesPass();
Pass* createPrintFunctionMapPass();
Pass* createPrintStackIRPass();
+Pass* createPropagateGlobalsGloballyPass();
Pass* createRemoveNonJSOpsPass();
Pass* createRemoveImportsPass();
Pass* createRemoveMemoryPass();