-
Couldn't load subscription status.
- Fork 819
Implement directed inlining / BinaryenForceInline #1898
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
Conversation
|
While trying this out I noticed that there is an issue with block names not being unique. That'll need a fix. |
|
Overall this looks somewhat inefficient due to traversing the entire function body twice (replacing the call + making unique labels), hmm... |
|
What do you mean by "creation time" here?
What do you think about my suggestion from earlier to make the API "force-inline function X" which would then inline X into all functions that call it? If that works for your use case, it seems like a nicer API, and it would be a lot faster. |
The ideal API for my use case would be to simply call
Yeah, that'd most likely make the most sense here. My thinking was that doing it on a per-call basis would make it as general as possible to cover all cases, even those we haven't thought about yet where a function is inlined only sometimes for example. Unfortunately, I just figured that there's another issue with doing inlining as an afterthought, that comes from not being able to precompute expressions that include an inlined helper (we use these like macros in C++), because precompute doesn't traverse into called functions (inlined bodies, as we did before manually, could simply be precomputed). This is pretty much a showstopper and I haven't yet come up with a solution. |
|
So, I figured that we are relying on inlining so much, for example we need ad-hoc precompute on inlined code for our macros to work, that doing inlining after everything else actually raises more concerns than it solves. I made my peace with it now and improved this on our side. Hope that I didn't waste too much of your time, and thanks for helping me out, as always! :) [took a while for me to figure this out, sorry] |
|
Thanks for the clarification about creation time, now I see. About the precompute issue, it sounds like doing inlining early, before running the optimizer, would be best for you? Are you saying you don't need binaryen to inline in that case? |
|
That is, it seems like using this PR (or an improved version of it) to inline first thing, and then optimize, would get what you want? |
To me it appears that the amount of work to implement what's necessary simply isn't worth it. Let me try to give an example: @inline function GET_SIZE<T>(): usize {
if (isReference<T>()) return offsetof<T>();
return sizeof<T>();
}That's a simplified example of a macro (everything in its body is actually constant, load<i32>(somePtr, GET_SIZE<f64>());Here, the second argument to the That's why it appears to me that a |
|
I see, thanks. I guess those inlined functions are special - simple enough that simple precomputation turns them into a constant? So they don't have locals, for example? Overall, it seems like that's a special case that the AssemblyScript compiler would maybe have to handle itself - those functions being inlined are really like compiler intrinsics, that is, special functions the compiler controls and is aware of. |
|
Closing this in favor of an eventual improved solution, that is if someone else or myself happens to have a fitting use case again. Thanks for all your feedback! |
As a follow-up to #1889, this PR implements the proposed
BinaryenForceInlineC-API. It refactors the core inlining logic tosrc/ir/inlining.has suggested and reuses it in the C-API to replace a specific call within a caller with an inlined block.Some issues / notes:
BinaryenCallInlinehelper that'd do this at creation time of the function. The function doesn't yet exist at that time so we can't add necessary locals to it. A Builder-like API that first creates the function and then adds to it seems like too big a change to me at this point, though.You''ll probably have some comments on possible improvements :)