From dbff242b3bc1fdaec15140cc48a537d7a497fb48 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 11 Sep 2020 09:09:15 -0700 Subject: 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 --- src/passes/PostEmscripten.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/passes/PostEmscripten.cpp') 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 -- cgit v1.2.3