From ff9757dd827f16e132fdab16bc615ba29f07b415 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 12 Sep 2016 10:12:55 -0700 Subject: clean up database-ensuring code using the new prepareToRun method --- src/passes/OptimizeInstructions.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/passes/OptimizeInstructions.cpp') diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 8381a0e1f..669a19b89 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -51,7 +51,6 @@ struct PatternDatabase { std::map> patternMap; // root expression id => list of all patterns for it TODO optimize more PatternDatabase() { - // TODO: do this on first use, with a lock, to avoid startup pause // generate module input = strdup( #include "OptimizeInstructions.wast.processed" @@ -75,14 +74,12 @@ struct PatternDatabase { static PatternDatabase* database = nullptr; -static void ensureDatabase() { - if (!database) { - // we must only ever create one database - static OnlyOnce onlyOnce; - onlyOnce.verify(); +struct DatabaseEnsurer { + DatabaseEnsurer() { + assert(!database); database = new PatternDatabase; } -} +}; // Check for matches and apply them struct Match { @@ -162,8 +159,8 @@ struct OptimizeInstructions : public WalkerPass