From c24b9f9f6af61abd9ef124837bee41cbba35a8f2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 7 Sep 2016 10:38:49 -0700 Subject: ensure we create the OptimizeInstructions database on demand, avoiding global ctors --- src/passes/OptimizeInstructions.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/passes/OptimizeInstructions.cpp') diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 9fa059327..2a5e7b8c4 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace wasm { @@ -71,7 +72,16 @@ struct PatternDatabase { }; }; -static PatternDatabase database; +static PatternDatabase* database = nullptr; + +static void ensureDatabase() { + if (!database) { + // we must only ever create one database + static OnlyOnce onlyOnce; + onlyOnce.verify(); + database = new PatternDatabase; + } +} // Check for matches and apply them struct Match { @@ -151,11 +161,15 @@ struct OptimizeInstructions : public WalkerPass_id); - if (iter == database.patternMap.end()) return; + auto iter = database->patternMap.find(curr->_id); + if (iter == database->patternMap.end()) return; auto& patterns = iter->second; bool more = false; for (auto& pattern : patterns) { -- cgit v1.2.3