Skip to content

Rename Emscripten EHSjLj functions in wasm backend #3191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 11, 2020

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Oct 1, 2020

Now that we are renaming invoke wrappers and emscripten_longjmp_jmpbuf
in the wasm backend, this deletes all related renaming routines and
relevant tests. Depends on #3192.

Addresses: #3043 and #3081

Companions:
https://reviews.llvm.org/D88697
emscripten-core/emscripten#12399

Now that we are renaming invoke wrappers and `emscripten_longjmp_jmpbuf`
in the wasm backend, this deletes all related renaming routines and
relevant tests. But we still need to generate dynCalls for invokes; for
that this adds dynCall generations for invokes in `GenerateDynCalls`
pass, and moves related functions from wasm-emscripten.cpp to
GenerateDynCalls.cpp, given that now they are only used there.

Addresses: WebAssembly#3043 and WebAssembly#3081
@aheejin aheejin requested review from kripken and sbc100 October 1, 2020 20:37
(local.get $1)
(local.get $fptr)
)
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These dynCalls are generated because the input file contains invoke_ functions. Before they were not targets for dynCall generations because EmscriptenGlueGenerator looked for the format generated by the LLVM backend, like __invoke_void_i32, and not invoke_vi.

wasm->addFunction(f);
exportFunction(*wasm, f->name, true);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making this its own PR that would be NFC? Seems like it might be nice intermediate step?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #3192. Will rebase this PR on top of that. It's inconvenient that Github doesn't support dependent PRs... (We can emulate it if I used branches in this repo and not my own fork though..)

}
}
}

void visitFunction(Function* func) {
// Generate dynCalls for invokes
if (func->imported() && func->base.startsWith("invoke_")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check also that func->module == ENV

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@aheejin
Copy link
Member Author

aheejin commented Oct 6, 2020

I incorporated invoke wrapper renaming we discussed in the meeting this morning here; I thought about doing it as a separate patch but it will take three more patches, each from LLVM, Binaryen, and Emscripten, and rolling them will be a pain, so... Also edited the PR description reflecting this.

@aheejin
Copy link
Member Author

aheejin commented Oct 6, 2020

Sorry for changing things again; I reverted the invoke format changing part (two leading underscore thing). Renaming this turns out to change a lot of things in Emscripten side, which I think is really better be a separate patch.

Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, can the llvm change land before this on its own?

It seems like it should be possible .. it would just mean the fixInvokeFunctionNames would becoming inactive.. and then change to roll after?

@@ -55,7 +55,8 @@ struct GenerateDynCalls : public WalkerPass<PostWalker<GenerateDynCalls>> {

void visitFunction(Function* func) {
// Generate dynCalls for invokes
if (func->imported() && func->base.startsWith("invoke_")) {
if (func->imported() && func->module == ENV &&
func->base.startsWith("invoke_")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like maybe unneeded/unrelated?

If you do want to make this change you you should change the logic in src/wasm/wasm-emscripten.cpp which seems do duplicate this when generating invokeFuncs mabye?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was suggested in #3191 (comment), and yeah, I think the condition in wasm/wasm-emscripten.cpp should be the same. Should I duplicate the condition there? @kripken

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the same condition in wasm-emscripten.cpp.

@aheejin
Copy link
Member Author

aheejin commented Oct 6, 2020

I'm curious, can the llvm change land before this on its own?

It seems like it should be possible .. it would just mean the fixInvokeFunctionNames would becoming inactive.. and then change to roll after?

Yeah I think llvm change can land on its own; maybe I was not clear when I was asking for the double roll thing.. What I meant was, Emscripten CI will pass only after both the LLVM and Binaryen patches land. But landing those two will break the roller because Emscripten patch hasn't landed.

aheejin added a commit to aheejin/emscripten that referenced this pull request Oct 7, 2020
This was going to be a part of emscripten-core#12399, but commiting this single line
first will enable rolling of the corresponding LLVM
(https://reviews.llvm.org/D88697) and Binaryen
(WebAssembly/binaryen#3191) patches successfully without us needing to
disable any Emscripten tests or do a double rolling.
aheejin added a commit to emscripten-core/emscripten that referenced this pull request Oct 7, 2020
This was going to be a part of #12399, but commiting this single line
first will enable rolling of the corresponding LLVM
(https://reviews.llvm.org/D88697) and Binaryen
(WebAssembly/binaryen#3191) patches successfully without us needing to
disable any Emscripten tests or do a special rolling.
aheejin added a commit to llvm/llvm-project that referenced this pull request Oct 7, 2020
Renaming for some Emscripten EH functions has so far been done in
wasm-emscripten-finalize tool in Binaryen. But recently we decided to
make a compilation/linking path that does not rely on
wasm-emscripten-finalize for modifications, so here we move that
functionality to LLVM.

Invoke wrappers are generated in LowerEmscriptenEHSjLj pass, but final
wasm types are not available in the IR pass, we need to rename them at
the end of the pipeline.

This patch also removes uses of `emscripten_longjmp_jmpbuf` in
LowerEmscriptenEHSjLj pass, replacing that with `emscripten_longjmp`.
`emscripten_longjmp_jmpbuf` is lowered to `emscripten_longjmp`, but
previously we generated calls to `emscripten_longjmp_jmpbuf` in
LowerEmscriptenEHSjLj pass because it takes `jmp_buf*` instead of `i32`.
But we were able use `ptrtoint` to make it use `emscripten_longjmp`
directly here.

Addresses:
WebAssembly/binaryen#3043
WebAssembly/binaryen#3081

Companions:
WebAssembly/binaryen#3191
emscripten-core/emscripten#12399

Reviewed By: dschuff, tlively, sbc100

Differential Revision: https://reviews.llvm.org/D88697
@aheejin aheejin merged commit f4d074f into WebAssembly:master Oct 11, 2020
@aheejin aheejin deleted the emeh branch October 11, 2020 03:01
aheejin added a commit to emscripten-core/emscripten that referenced this pull request Oct 11, 2020
Now that we are renaming invoke wrappers and `emscripten_longjmp_jmpbuf`
in the wasm backend, using Emscripten EH or SjLj does not need
Binaryen's postprocessing. This makes Emscripten not enable Binaryen
postprocessing using wasm-emscripten-finalize when we are using them,
and deletes all special handling for `emscripten_longjmp_jmpbuf`, given
that Emscripten will not see it.

Addresses:
WebAssembly/binaryen#3043
WebAssembly/binaryen#3081

Companions:
https://reviews.llvm.org/D88697
WebAssembly/binaryen#3191
arichardson pushed a commit to arichardson/llvm-project that referenced this pull request Mar 24, 2021
Renaming for some Emscripten EH functions has so far been done in
wasm-emscripten-finalize tool in Binaryen. But recently we decided to
make a compilation/linking path that does not rely on
wasm-emscripten-finalize for modifications, so here we move that
functionality to LLVM.

Invoke wrappers are generated in LowerEmscriptenEHSjLj pass, but final
wasm types are not available in the IR pass, we need to rename them at
the end of the pipeline.

This patch also removes uses of `emscripten_longjmp_jmpbuf` in
LowerEmscriptenEHSjLj pass, replacing that with `emscripten_longjmp`.
`emscripten_longjmp_jmpbuf` is lowered to `emscripten_longjmp`, but
previously we generated calls to `emscripten_longjmp_jmpbuf` in
LowerEmscriptenEHSjLj pass because it takes `jmp_buf*` instead of `i32`.
But we were able use `ptrtoint` to make it use `emscripten_longjmp`
directly here.

Addresses:
WebAssembly/binaryen#3043
WebAssembly/binaryen#3081

Companions:
WebAssembly/binaryen#3191
emscripten-core/emscripten#12399

Reviewed By: dschuff, tlively, sbc100

Differential Revision: https://reviews.llvm.org/D88697
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this pull request Oct 7, 2022
Renaming for some Emscripten EH functions has so far been done in
wasm-emscripten-finalize tool in Binaryen. But recently we decided to
make a compilation/linking path that does not rely on
wasm-emscripten-finalize for modifications, so here we move that
functionality to LLVM.

Invoke wrappers are generated in LowerEmscriptenEHSjLj pass, but final
wasm types are not available in the IR pass, we need to rename them at
the end of the pipeline.

This patch also removes uses of `emscripten_longjmp_jmpbuf` in
LowerEmscriptenEHSjLj pass, replacing that with `emscripten_longjmp`.
`emscripten_longjmp_jmpbuf` is lowered to `emscripten_longjmp`, but
previously we generated calls to `emscripten_longjmp_jmpbuf` in
LowerEmscriptenEHSjLj pass because it takes `jmp_buf*` instead of `i32`.
But we were able use `ptrtoint` to make it use `emscripten_longjmp`
directly here.

Addresses:
WebAssembly/binaryen#3043
WebAssembly/binaryen#3081

Companions:
WebAssembly/binaryen#3191
emscripten-core/emscripten#12399

Reviewed By: dschuff, tlively, sbc100

Differential Revision: https://reviews.llvm.org/D88697
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants