-
Right now, void optimize(std::string& infile, std::string& outfile) {
// binaryen exports are namespaced under "wasm"
wasm::Module wasm;
wasm.features.enable(wasm::FeatureSet::Default);
wasm.features.disable(wasm::FeatureSet::None);
wasm::ModuleReader reader;
reader.setDWARF(false);
reader.setProfile(wasm::IRProfile::Normal);
std::string inputSourceMapFilename;
reader.read(infile, wasm, inputSourceMapFilename);
auto passRunner = wasm::PassRunner(&wasm, wasm::PassOptions::getWithDefaultOptimizationOptions());
passRunner.options.shrinkLevel = 2;
passRunner.options.optimizeLevel = 2;
passRunner.options.debugInfo = false;
passRunner.addDefaultOptimizationPasses();
passRunner.run();
wasm::ModuleWriter writer;
writer.setBinary(true);
writer.setDebugInfo(false);
writer.write(wasm, outfile);
} Even with this, the outputs are not the same. The binary does definitely shrink, but not as drastically as it does with What part of the API is missing here? After looking through the codebase for quite a while I feel like I could be missing a small part of the API that enables the default behavior of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
I don't see anything obviously missing. Though you might want to experiment with changing the opt level to 3, and the shrink level to 1 or 0 (as 2 or 1 disable much inlining, which can have a large impact). Otherwise, they way I would debug this is to run that code and the commandline tool with the same intended optimizations and with |
Beta Was this translation helpful? Give feedback.
Ah, if it is a DWARF section that CMake does in fact affect that. That's not an optimization issue but a matter of debug support. Makes sense now.
About the line tables, Binaryen's DWARF support is somewhat limited so it's possible you're hitting a limitation or bug. In general it should work when few optimizations are run, however.