summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-c.cpp38
-rw-r--r--src/binaryen-c.h1
-rw-r--r--src/pass.h12
-rw-r--r--src/support/defaults.h24
-rw-r--r--src/tools/optimization-options.h4
5 files changed, 27 insertions, 52 deletions
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<AutoDrop>();
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]);
}
diff --git a/src/binaryen-c.h b/src/binaryen-c.h
index b17715a4b..b91689c3f 100644
--- a/src/binaryen-c.h
+++ b/src/binaryen-c.h
@@ -48,7 +48,6 @@
#include <stdint.h>
#include "compiler-support.h"
-#include "support/defaults.h"
#ifdef __cplusplus
extern "C" {
diff --git a/src/pass.h b/src/pass.h
index cc8261731..59f0d3dcb 100644
--- a/src/pass.h
+++ b/src/pass.h
@@ -63,6 +63,18 @@ struct PassOptions {
bool ignoreImplicitTraps = false; // optimize assuming things like div by 0, bad load/store, will not trap
bool debugInfo = false; // whether to try to preserve debug info through, which are special calls
FeatureSet features = Feature::MVP; // Which wasm features to accept, and be allowed to use
+
+ void setDefaultOptimizationOptions() {
+ // -Os is our default
+ optimizeLevel = 2;
+ shrinkLevel = 1;
+ }
+
+ static PassOptions getWithDefaultOptimizationOptions() {
+ PassOptions ret;
+ ret.setDefaultOptimizationOptions();
+ return ret;
+ }
};
//
diff --git a/src/support/defaults.h b/src/support/defaults.h
deleted file mode 100644
index 0b9ca3f6d..000000000
--- a/src/support/defaults.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
-* Copyright 2016 WebAssembly Community Group participants
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-// Default optimization level used by tools and the C/JS APIs
-#define BINARYEN_DEFAULT_OPTIMIZE_LEVEL 2
-
-// Default shrink level used by tools and the C/JS APIs
-#define BINARYEN_DEFAULT_SHRINK_LEVEL 1
-
-// Default debug info setting used by tools and the C/JS APIs
-#define BINARYEN_DEFAULT_DEBUG_INFO 0
diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h
index 7ef3f9fa6..265f072c7 100644
--- a/src/tools/optimization-options.h
+++ b/src/tools/optimization-options.h
@@ -15,7 +15,6 @@
*/
#include "support/command-line.h"
-#include "support/defaults.h"
//
// Shared optimization options for commandline tools
@@ -34,8 +33,7 @@ struct OptimizationOptions : public Options {
(*this).add("", "-O", "execute default optimization passes",
Options::Arguments::Zero,
[this](Options*, const std::string&) {
- passOptions.optimizeLevel = BINARYEN_DEFAULT_OPTIMIZE_LEVEL;
- passOptions.shrinkLevel = BINARYEN_DEFAULT_SHRINK_LEVEL;
+ passOptions.setDefaultOptimizationOptions();
passes.push_back(DEFAULT_OPT_PASSES);
})
.add("", "-O0", "execute no optimization passes",