Skip to content
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

Minimal JS legalization #1824

Merged
merged 5 commits into from
Dec 15, 2018
Merged

Minimal JS legalization #1824

merged 5 commits into from
Dec 15, 2018

Conversation

kripken
Copy link
Member

@kripken kripken commented Dec 14, 2018

Even when we don't want to fully legalize code for JS, we should still legalize things that only JS cares about. In particular, dynCall_* methods are used from JS to call into the wasm table, and if they exist they are only for JS, so we should only legalize them.

The use case motivating this is that in dynamic linking you may want to disable legalization, so that wasm=>wasm module calls are fast even with i64s, but you do still need dynCalls to be legalized even in that case, otherwise an invoke with an i64 parameter would fail.

@kripken
Copy link
Member Author

kripken commented Dec 14, 2018

cc @awtcode

#include "wasm.h"

namespace wasm {

Copy link
Member

Choose a reason for hiding this comment

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

Is it the convention to add these extra newlines between namespace declaration? If not I've remove them.

Copy link
Member Author

Choose a reason for hiding this comment

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

grep indicates they are the norm in this codebase. all places but one, in fact, I'll fix that.

@kripken kripken merged commit 6cc5984 into master Dec 15, 2018
@kripken kripken deleted the legalize-partial branch December 15, 2018 01:27
@awtcode
Copy link

awtcode commented Dec 17, 2018

Thanks for doing this @kripken :) Really appreciate it. What build flags should I use to ensure that only dynCalls are legalized?

In my case, I believe the i64 exported functions are not called from JS as well so is there a way to turn off legalization for these functions? Thanks for your help.

Copy link
Member

@dschuff dschuff left a comment

Choose a reason for hiding this comment

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

sorry i realized I started a review last friday and didn't finish it...


namespace ABI {

enum LegalizationLevel {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be enum class so externally it has to be spelled ABI::LegalizationLevel::Full instead of just ABI::Full? Or alternatively rename Full to FullLegalization just for clarity?

@@ -118,6 +131,11 @@ struct LegalizeJSInterface : public Pass {
return false;
}

bool isRelevant(Export* ex, Function* func) {
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 naming this shouldLegalize or something like that?

@kripken
Copy link
Member Author

kripken commented Dec 17, 2018

@awtcode LEGALIZE_JS_FFI=0, but see emscripten-core/emscripten#7679

In my case, I believe the i64 exported functions are not called from JS as well so is there a way to turn off legalization for these functions? Thanks for your help.

I don't understand - what does "as well" refer to? (what else could call them aside from JS, that legalization matters for?)

@dschuff sounds good, followups for your comments are in #1832

@awtcode
Copy link

awtcode commented Dec 18, 2018

Sorry for the confusion @kripken. I was thinking about i64 functions that we export explicitly e.g. EMSCRIPTEN_KEEPALIVE and -s EXPORTED_FUNCTIONS. Since I won't be calling them from JS but only Wasm, will they still be legalized with LEGALIZE_JS_FFI=0? From what I understand, only dynCalls need to be legalized at this point in time.

But I am fine with all explicitly exported functions being legalized at this point in time as the number is not large. Let me know if I need to provide more clarifications.

@kripken
Copy link
Member Author

kripken commented Dec 18, 2018

@awtcode I understand, thanks. There's nothing special about exports. So if you build with legalization off, it will not legalize those (it will just legalize dynCalls, if there are any).

@awtcode
Copy link

awtcode commented Dec 19, 2018

Thanks for the clarification @kripken.

@awtcode
Copy link

awtcode commented Jan 3, 2019

@kripken , will you be releasing a new version of emsdk that contains this PR?

@kripken
Copy link
Member Author

kripken commented Jan 3, 2019

Probably soon, there is current work on some ABI issues which will include this emscripten-core/emscripten-fastcomp#249 etc.

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.

4 participants