summaryrefslogtreecommitdiff
path: root/src/passes/Precompute.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/Precompute.cpp')
-rw-r--r--src/passes/Precompute.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp
index 2e8c8fe31..a7edb54c9 100644
--- a/src/passes/Precompute.cpp
+++ b/src/passes/Precompute.cpp
@@ -41,6 +41,12 @@ namespace wasm {
static const Name NOTPRECOMPUTABLE_FLOW("Binaryen|notprecomputable");
+// Limit evaluation depth for 2 reasons: first, it is highly unlikely
+// that we can do anything useful to precompute a hugely nested expression
+// (we should succed at smaller parts of it first). Second, a low limit is
+// helpful to avoid platform differences in native stack sizes.
+static const Index MAX_DEPTH = 50;
+
typedef std::unordered_map<LocalGet*, Literal> GetValues;
// Precomputes an expression. Errors if we hit anything that can't be
@@ -63,8 +69,8 @@ public:
PrecomputingExpressionRunner(Module* module,
GetValues& getValues,
bool replaceExpression)
- : module(module), getValues(getValues),
- replaceExpression(replaceExpression) {}
+ : ExpressionRunner<PrecomputingExpressionRunner>(MAX_DEPTH), module(module),
+ getValues(getValues), replaceExpression(replaceExpression) {}
struct NonstandaloneException {
}; // TODO: use a flow with a special name, as this is likely very slow