From 692069c6eef63754c27e815fd948fea6185d7619 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 17 Jan 2018 20:26:04 -0800 Subject: Refactor optimization defaults (#1366) Followup to #1357. This moves the optimization settings into pass.h, and uses it from there in the various places. This also splits up huge lines from the tracing code, which put all block children (whose number can be arbitrarily large) on one line. This seems to have caused random errors on the bots, I suspect from overflowing a buffer. Anyhow, it's much more clear to split the lines at a reasonable length. --- src/binaryen-c.cpp | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'src/binaryen-c.cpp') diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index b13c0a11e..a2b40714d 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -33,7 +33,6 @@ #include "cfg/Relooper.h" #include "ir/utils.h" #include "shell-interface.h" -#include "support/defaults.h" using namespace wasm; @@ -72,9 +71,7 @@ static std::mutex BinaryenFunctionMutex; static std::mutex BinaryenFunctionTypeMutex; // Optimization options -static int optimizeLevel = BINARYEN_DEFAULT_OPTIMIZE_LEVEL; -static int shrinkLevel = BINARYEN_DEFAULT_SHRINK_LEVEL; -static bool debugInfo = BINARYEN_DEFAULT_DEBUG_INFO; +static PassOptions globalPassOptions = PassOptions::getWithDefaultOptimizationOptions(); // Tracing support @@ -385,6 +382,7 @@ BinaryenExpressionRef BinaryenBlock(BinaryenModuleRef module, const char* name, std::cout << " BinaryenExpressionRef children[] = { "; for (BinaryenIndex i = 0; i < numChildren; i++) { if (i > 0) std::cout << ", "; + if (i % 6 == 5) std::cout << "\n "; // don't create hugely long lines std::cout << "expressions[" << expressions[children[i]] << "]"; } if (numChildren == 0) std::cout << "0"; // ensure the array is not empty, otherwise a compiler error on VS @@ -2013,9 +2011,7 @@ void BinaryenModuleOptimize(BinaryenModuleRef module) { Module* wasm = (Module*)module; PassRunner passRunner(wasm); - passRunner.options.optimizeLevel = optimizeLevel; - passRunner.options.shrinkLevel = shrinkLevel; - passRunner.options.debugInfo = debugInfo; + passRunner.options = globalPassOptions; passRunner.addDefaultOptimizationPasses(); passRunner.run(); } @@ -2025,7 +2021,7 @@ int BinaryenGetOptimizeLevel() { std::cout << " BinaryenGetOptimizeLevel();\n"; } - return optimizeLevel; + return globalPassOptions.optimizeLevel; } void BinaryenSetOptimizeLevel(int level) { @@ -2033,7 +2029,7 @@ void BinaryenSetOptimizeLevel(int level) { std::cout << " BinaryenSetOptimizeLevel(" << level << ");\n"; } - optimizeLevel = level; + globalPassOptions.optimizeLevel = level; } int BinaryenGetShrinkLevel() { @@ -2041,7 +2037,7 @@ int BinaryenGetShrinkLevel() { std::cout << " BinaryenGetShrinkLevel();\n"; } - return shrinkLevel; + return globalPassOptions.shrinkLevel; } void BinaryenSetShrinkLevel(int level) { @@ -2049,7 +2045,7 @@ void BinaryenSetShrinkLevel(int level) { std::cout << " BinaryenSetShrinkLevel(" << level << ");\n"; } - shrinkLevel = level; + globalPassOptions.shrinkLevel = level; } int BinaryenGetDebugInfo() { @@ -2057,7 +2053,7 @@ int BinaryenGetDebugInfo() { std::cout << " BinaryenGetDebugInfo();\n"; } - return debugInfo; + return globalPassOptions.debugInfo; } void BinaryenSetDebugInfo(int on) { @@ -2065,7 +2061,7 @@ void BinaryenSetDebugInfo(int on) { std::cout << " BinaryenSetDebugInfo(" << on << ");\n"; } - debugInfo = bool(on); + globalPassOptions.debugInfo = bool(on); } void BinaryenModuleRunPasses(BinaryenModuleRef module, const char **passes, BinaryenIndex numPasses) { @@ -2083,9 +2079,7 @@ void BinaryenModuleRunPasses(BinaryenModuleRef module, const char **passes, Bina Module* wasm = (Module*)module; PassRunner passRunner(wasm); - passRunner.options.optimizeLevel = optimizeLevel; - passRunner.options.shrinkLevel = shrinkLevel; - passRunner.options.debugInfo = debugInfo; + passRunner.options = globalPassOptions; for (BinaryenIndex i = 0; i < numPasses; i++) { passRunner.add(passes[i]); } @@ -2099,7 +2093,7 @@ void BinaryenModuleAutoDrop(BinaryenModuleRef module) { Module* wasm = (Module*)module; PassRunner passRunner(wasm); - passRunner.options.debugInfo = debugInfo; + passRunner.options = globalPassOptions; passRunner.add(); passRunner.run(); } @@ -2112,7 +2106,7 @@ size_t BinaryenModuleWrite(BinaryenModuleRef module, char* output, size_t output Module* wasm = (Module*)module; BufferWithRandomAccess buffer(false); WasmBinaryWriter writer(wasm, buffer, false); - writer.setNamesSection(debugInfo); + writer.setNamesSection(globalPassOptions.debugInfo); writer.write(); size_t bytes = std::min(buffer.size(), outputSize); std::copy_n(buffer.begin(), bytes, output); @@ -2254,9 +2248,7 @@ void BinaryenFunctionOptimize(BinaryenFunctionRef func, BinaryenModuleRef module Module* wasm = (Module*)module; PassRunner passRunner(wasm); - passRunner.options.optimizeLevel = optimizeLevel; - passRunner.options.shrinkLevel = shrinkLevel; - passRunner.options.debugInfo = debugInfo; + passRunner.options = globalPassOptions; passRunner.addDefaultOptimizationPasses(); passRunner.runOnFunction((Function*)func); } @@ -2275,9 +2267,7 @@ void BinaryenFunctionRunPasses(BinaryenFunctionRef func, BinaryenModuleRef modul Module* wasm = (Module*)module; PassRunner passRunner(wasm); - passRunner.options.optimizeLevel = optimizeLevel; - passRunner.options.shrinkLevel = shrinkLevel; - passRunner.options.debugInfo = debugInfo; + passRunner.options = globalPassOptions; for (BinaryenIndex i = 0; i < numPasses; i++) { passRunner.add(passes[i]); } -- cgit v1.2.3