Repository navigation
Running passes on a single function in binaryen-c/.js - #1295
Conversation
|
How about adding a new function for this, Btw, is this enough for your use case of optimizing just an expression? We can add that too, but it requires work inside binaryen to add it first. I can do that if you want. |
|
Also would be nice to add |
|
Thought to add an additional parameter because the function requires the module as a parameter anyhow. In terms of a nice API, Regarding my use case: Somewhat. I'd then use the initializer expression I'd like to precompute as the body of a new function, optimize that, obtain a reference to the updated body (here: On |
|
It's true the implementation is almost the same since the function version needs the module anyhow, good point. Maybe internally they can use a shared helper function. For the external API, that's a good question about those options. I guess it depends on whether we expect to have more About the second paragraph, I think that's a general enough thing that I'd like a binaryen utility for it. It should also handle locals etc. properly, so it's not as simple as your use case, but feasible. If that makes sense I can do that later today (unless you want to). |
Sounds good.
That'd be great, I'm not too familiar with the internals yet. |
|
One thing about splitting up module and function entrypoints ( I see two ways to deal with that: 1) Simply accept that the JS-API differs and keep |
|
About the general optimize-an-expression thing, as I was writing it I realized it can't be efficient, at least if it tries to handle the general case (you need to do a bunch of copying and scanning, stuff you don't need when you optimize a whole function). So I'm starting to think it's not worth it. Do you have enough for your use case without it? About the C and JS APIs, I think it's best to let each make sense on its own, they don't need to be a perfect parallel. As you said in the past, we may have other APIs built on top of the C API eventually anyhow. |
|
The latest commit adds the following JS-API as well:
I also added the minimum required utility functions to make a test case from my specific use case (see binaryen.js/functions.js):
|
| return Module['_BinaryenModuleOptimize'](module); | ||
| }; | ||
| this['optimizeFunction'] = function(func) { | ||
| if (typeof func === "string") func = this['getFunction'](func); |
There was a problem hiding this comment.
this overloading could also work in removeFunction? Could be nice there too as a followup maybe.
There was a problem hiding this comment.
Not yet because, unlike BinaryenFunctionOptimize, BinaryenRemoveFunction expects a name, not a reference. What I'm trying to establish, though, is using names in BinaryenAddSomething-style functions, and Something-references in BinaryenSomethingAdd-style ones. Here, that'd be BinaryenFunctionRemove (note: doesn't fit well to the C++ API because wasm->removeFunction expects a name).
There was a problem hiding this comment.
Hmm, yeah. But we could eventually do the reverse, maybe: the C API expects a name, so if JS receives a name, pass that through. And if you get a number (a pointer), you can call FunctionGetName (which returns the name, parallel to GetBody), and use that.
There was a problem hiding this comment.
When doing the reverse, that is optionally resolving a reference to its name everywhere, we'll end up decoding and encoding even more strings :(
As an alternative to #1294, instead of adding a more specific API, this PR adds an additional optional argument to
BinaryenModuleRunPasses(breaks the C-API, but RunPasses is relatively new and this can be transparently handled in JS) to run passes on a single function only.