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

Cranelift: emit_stackmaps should avoid walking the IR if the function doesn't use r32 or r64 #1883

Closed
fitzgen opened this issue Jun 15, 2020 · 3 comments
Labels
cranelift Issues related to the Cranelift code generator

Comments

@fitzgen
Copy link
Member

fitzgen commented Jun 15, 2020

Enabling stack maps and GC safepoints adds another pass over the IR (emit_stackmaps) regardless whether the function in question actually uses reference types at all. One could imagine (especially with wasm-bindgen's "switch reference types into table indices at the boundaries" approach, that seems likely to be copied by C/C++) that many functions in a module don't use reference types. For these functions, that extra pass over the IR is a waste of time.

We could have a flag on functions that gets set if it uses reference types in any way (and then never gets unset when a particular reference type-using instruction is removed, so we don't have to precisely count them) and in emit_stackmaps, only walk the IR if the flag is set (and probably debug_assert! that it doesn't have any uses of reference types if the flag is not set).

This came up in #1832 (comment) for Wasmtime.

@fitzgen fitzgen added the cranelift Issues related to the Cranelift code generator label Jun 15, 2020
@github-actions
Copy link

Subscribe to Label Action

cc @bnjbvr

This issue or pull request has been labeled: "cranelift"

Thus the following users have been cc'd because of the following labels:

  • bnjbvr: cranelift

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@bnjbvr
Copy link
Member

bnjbvr commented Jun 17, 2020

Thanks for opening an issue! Do you have any numbers on how much relative time is spent going over the IR, for a large module? This would help quantifying how urgent an issue it is. In any case, agreed that not doing wasteful work is generally good, of course.

The idea of using a flag on the function sounds good. Not sure where to put it, since as far as i can tell it's the first usage of a flag in a Function; could be directly there, or DataFlowGraph, etc.

@fitzgen
Copy link
Member Author

fitzgen commented Jun 17, 2020

Not sure how much time is spent doing the pass when there aren't any reference types used, it just came up during review.

fitzgen added a commit to fitzgen/wasmtime that referenced this issue Aug 7, 2020
…ce types

This fix avoids a small slow down in scenarios where reference types are enabled
but a given function doesn't actually use them.

Fixes bytecodealliance#1883
fitzgen added a commit to fitzgen/wasmtime that referenced this issue Aug 7, 2020
…ce types

This fix avoids a small slow down in scenarios where reference types are enabled
but a given function doesn't actually use them.

Fixes bytecodealliance#1883
fitzgen added a commit to fitzgen/wasmtime that referenced this issue Aug 7, 2020
…ce types

This fix avoids a small slow down in scenarios where reference types are enabled
but a given function doesn't actually use them.

Fixes bytecodealliance#1883
@fitzgen fitzgen closed this as completed in 5af47dc Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

No branches or pull requests

2 participants