diff options
author | Daniel Wirtz <dcode@dcode.io> | 2018-01-17 18:25:49 +0100 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2018-01-17 09:25:49 -0800 |
commit | 01b23987405d8d7b2f13e40ef906169163ac2a5f (patch) | |
tree | 7b76946e0392eb65ad773cbb6524ad0fdbddde38 /src/binaryen-c.cpp | |
parent | 3d8358f8e10a01869ef59189539ab1d17d52cb10 (diff) | |
download | binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.tar.gz binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.tar.bz2 binaryen-01b23987405d8d7b2f13e40ef906169163ac2a5f.zip |
Add optimize, shrink level and debug info options to C/JS (#1357)
* Add optimize, shrink level and debug info options to C/JS
* Add instantiate functionality for creating additional unique instances of the API
* Use a workaround when running tests in node
Tests misuse a module as a script by concatenating, so instead of catching this case in the library, catch it there
* Update sieve test
Seems optimized output changed due to running with optimize levels 2/1 now
* Use the options with all pass runners
* Update relooper-fuzz C-API test
* Share defaults between tools and the C-API
* Add a test for optimize levels
* Unify node test support in check.by and auto_update_tests.py
* Also add getters for optimize levels and test them
* Also test debugInfo
* Add debug info to C tests that used it as well
* Fix missing NODEJS import in auto_update_tests
* Detect node.js version (WASM support)
* Update hello-world JS test (now also runs with node)
* feature-test WebAssembly in node instead
* Document that these options apply globally, and where
* Make sure hello-world.js output doesn't differ between mozjs/node
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r-- | src/binaryen-c.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 0c687c249..b13c0a11e 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -33,6 +33,7 @@ #include "cfg/Relooper.h" #include "ir/utils.h" #include "shell-interface.h" +#include "support/defaults.h" using namespace wasm; @@ -70,6 +71,11 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) { 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; + // Tracing support static int tracing = 0; @@ -2007,10 +2013,61 @@ void BinaryenModuleOptimize(BinaryenModuleRef module) { Module* wasm = (Module*)module; PassRunner passRunner(wasm); + passRunner.options.optimizeLevel = optimizeLevel; + passRunner.options.shrinkLevel = shrinkLevel; + passRunner.options.debugInfo = debugInfo; passRunner.addDefaultOptimizationPasses(); passRunner.run(); } +int BinaryenGetOptimizeLevel() { + if (tracing) { + std::cout << " BinaryenGetOptimizeLevel();\n"; + } + + return optimizeLevel; +} + +void BinaryenSetOptimizeLevel(int level) { + if (tracing) { + std::cout << " BinaryenSetOptimizeLevel(" << level << ");\n"; + } + + optimizeLevel = level; +} + +int BinaryenGetShrinkLevel() { + if (tracing) { + std::cout << " BinaryenGetShrinkLevel();\n"; + } + + return shrinkLevel; +} + +void BinaryenSetShrinkLevel(int level) { + if (tracing) { + std::cout << " BinaryenSetShrinkLevel(" << level << ");\n"; + } + + shrinkLevel = level; +} + +int BinaryenGetDebugInfo() { + if (tracing) { + std::cout << " BinaryenGetDebugInfo();\n"; + } + + return debugInfo; +} + +void BinaryenSetDebugInfo(int on) { + if (tracing) { + std::cout << " BinaryenSetDebugInfo(" << on << ");\n"; + } + + debugInfo = bool(on); +} + void BinaryenModuleRunPasses(BinaryenModuleRef module, const char **passes, BinaryenIndex numPasses) { if (tracing) { std::cout << " {\n"; @@ -2026,6 +2083,9 @@ 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; for (BinaryenIndex i = 0; i < numPasses; i++) { passRunner.add(passes[i]); } @@ -2039,6 +2099,7 @@ void BinaryenModuleAutoDrop(BinaryenModuleRef module) { Module* wasm = (Module*)module; PassRunner passRunner(wasm); + passRunner.options.debugInfo = debugInfo; passRunner.add<AutoDrop>(); passRunner.run(); } @@ -2051,6 +2112,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.write(); size_t bytes = std::min(buffer.size(), outputSize); std::copy_n(buffer.begin(), bytes, output); @@ -2192,6 +2254,9 @@ 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.addDefaultOptimizationPasses(); passRunner.runOnFunction((Function*)func); } @@ -2210,6 +2275,9 @@ 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; for (BinaryenIndex i = 0; i < numPasses; i++) { passRunner.add(passes[i]); } |