diff options
author | Alon Zakai <azakai@google.com> | 2020-09-11 09:09:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-11 09:09:15 -0700 |
commit | dbff242b3bc1fdaec15140cc48a537d7a497fb48 (patch) | |
tree | 74a6913ddd2d4e8676a839c2b1d8179b14fc4637 /src/passes/PostEmscripten.cpp | |
parent | 95c0b44f88e733307c0cc3fd2f5efcff579d95b4 (diff) | |
download | binaryen-dbff242b3bc1fdaec15140cc48a537d7a497fb48.tar.gz binaryen-dbff242b3bc1fdaec15140cc48a537d7a497fb48.tar.bz2 binaryen-dbff242b3bc1fdaec15140cc48a537d7a497fb48.zip |
Stop renaming longjmp in wasm-emscripten-finalize (#3111)
Instead of finalize renaming emscripten_longjmp_jmpbuf to emscripten_longjmp,
do nothing in finalize. But in the optional --post-emscripten pass, rename it there if
both exist, so that we don't end up using two imports (other optimization passes
can then remove an unneeded import).
Depends on emscripten-core/emscripten#12157 to land first so that emscripten
can handle both names, and it is just an optimization to have one or the other.
See https://github.com/WebAssembly/binaryen/issues/3043
Diffstat (limited to 'src/passes/PostEmscripten.cpp')
-rw-r--r-- | src/passes/PostEmscripten.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index 2397284c3..aa6c90977 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -130,6 +130,9 @@ struct PostEmscripten : public Pass { } } + // Optimize imports + optimizeImports(runner, module); + // Optimize calls OptimizeCalls().run(runner, module); @@ -137,6 +140,21 @@ struct PostEmscripten : public Pass { optimizeExceptions(runner, module); } + void optimizeImports(PassRunner* runner, Module* module) { + // Calling emscripten_longjmp_jmpbuf is the same as emscripten_longjmp. + Name EMSCRIPTEN_LONGJMP("emscripten_longjmp"); + Name EMSCRIPTEN_LONGJMP_JMPBUF("emscripten_longjmp_jmpbuf"); + ImportInfo info(*module); + auto* emscripten_longjmp = + info.getImportedFunction(ENV, EMSCRIPTEN_LONGJMP); + auto* emscripten_longjmp_jmpbuf = + info.getImportedFunction(ENV, EMSCRIPTEN_LONGJMP_JMPBUF); + if (emscripten_longjmp && emscripten_longjmp_jmpbuf) { + // Both exist, so it is worth renaming so that we have only one. + emscripten_longjmp_jmpbuf->base = EMSCRIPTEN_LONGJMP; + } + } + // Optimize exceptions (and setjmp) by removing unnecessary invoke* calls. // An invoke is a call to JS with a function pointer; JS does a try-catch // and calls the pointer, catching and reporting any error. If we know no |