diff options
author | Alon Zakai <azakai@google.com> | 2021-03-22 16:33:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-22 16:33:37 -0700 |
commit | 418804035056bcd133ff5e292bf645d5d26d8d0d (patch) | |
tree | 3c6f60a0a07e35cf0d15cd669d93413ff72f5bb3 /src | |
parent | 8dddd9f3a3060d831af48387165703e1d8efcc63 (diff) | |
download | binaryen-418804035056bcd133ff5e292bf645d5d26d8d0d.tar.gz binaryen-418804035056bcd133ff5e292bf645d5d26d8d0d.tar.bz2 binaryen-418804035056bcd133ff5e292bf645d5d26d8d0d.zip |
wasm-emscripten-finalize: Do not skip the start function body (#3714)
When we can skip function bodies, we still need to parse the start function
for the pthreads case, see details in the comments. This still gives us 99%
of the speedup as the start function is just 1 function and it's not that big,
so with this we return to full speed after the reversion in #3705
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm-emscripten-finalize.cpp | 9 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 9 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index b2f28dca0..38a55e5cb 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -220,9 +220,12 @@ int main(int argc, const char* argv[]) { // If we are not writing the output then all we are doing is simple parsing // of metadata from global parts of the wasm such as imports and exports. In // that case, it is unnecessary to parse function contents which are the - // great bulk of the work, and we can skip all that. However, the one - // exception is pthreads, which does require scanning the code, and so for - // now we cannot do reader.setSkipFunctionBodies(true); here yet. + // great bulk of the work, and we can skip all that. + // Note that the one case we do need function bodies for, pthreads + EM_ASM + // parsing, requires special handling. The start function has code that we + // parse in order to find the EM_ASMs, and for that reason the binary reader + // will still parse the start function even in this mode. + reader.setSkipFunctionBodies(true); } try { reader.read(infile, wasm, inputSourceMapFilename); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 37fa1ab78..6cb837296 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2141,7 +2141,14 @@ void WasmBinaryBuilder::readFunctions() { assert(controlFlowStack.empty()); assert(letStack.empty()); assert(depth == 0); - if (!skipFunctionBodies) { + // Even if we are skipping function bodies we need to not skip the start + // function. That contains important code for wasm-emscripten-finalize in + // the form of pthread-related segment initializations. As this is just + // one function, it doesn't add significant time, so the optimization of + // skipping bodies is still very useful. + auto currFunctionIndex = functionImports.size() + functions.size(); + bool isStart = startIndex == currFunctionIndex; + if (!skipFunctionBodies || isStart) { func->body = getBlockOrSingleton(func->sig.results); } else { // When skipping the function body we need to put something valid in |