Skip to content

Add precompute utility to binaryen-c/.js - #1294

Closed
dcodeIO wants to merge 3 commits into
WebAssembly:masterfrom
dcodeIO:js-expression-precompute
Closed

dcodeIO wants to merge 3 commits into
WebAssembly:masterfrom
dcodeIO:js-expression-precompute

Conversation

@dcodeIO

@dcodeIO dcodeIO commented Nov 16, 2017

Copy link
Copy Markdown
Contributor

As a follow-up to #1288, this PR adds some precompute utility that can be used from the C- and JS-API.

Adds the following function to the C-API:

  • BinaryenExpressionPrecomputeValue

Respectively, the following to the JS-API:

  • precomputeValue
  • Module#precomputeValue (substitutes module with the current instance)

There is just a simple test for now showing that it's basically working. Though, it seems that the precompute pass does not traverse through constant globals when used in this way. Appreciating any hints.

@dcodeIO
dcodeIO force-pushed the js-expression-precompute branch from 0abd87f to 5314ff8 Compare November 16, 2017 15:39
@dcodeIO
dcodeIO force-pushed the js-expression-precompute branch from 5314ff8 to ea35973 Compare November 16, 2017 15:47
@kripken

kripken commented Nov 16, 2017

Copy link
Copy Markdown
Member

API-wise, I think this might make sense, but as in the previous discussion, I think there are competing API concerns. On the one hand a more minimal API is better, and adding a piece of a specific optimization suggests we may want to add many more. (For comparison, I don't think the LLVM C API provides stuff like this.) But on the other hand, maybe this is a common-enough operation, I'm not sure.

If we generalize this I'd be a lot more confident. We currently have a way to optimize a module, and maybe we should have a way to optimize an expression by itself, something like

// Run optimization passes on an expression by itself (only things
// we can optimize without the context of the module or function).
void BinaryenExpressionOptimize(BinaryenModuleRef module);

That would include precompute and a few other passes that are truly independent of the module and the function (like optimize-instructions). Would that work for your use case?

@dcodeIO

dcodeIO commented Nov 16, 2017 •

Copy link
Copy Markdown
Contributor Author

Sure, going to investigate. Now that there's BinaryenModuleRunPasses, something like BinaryenExpressionRunPasses and, maybe as a companion, BinaryenFunctionRunPasses could be even more general.

Might need a way to set some options then, i.e. Precompute with propagate on/off for example.

@dcodeIO

dcodeIO commented Nov 21, 2017

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1295.

@dcodeIO dcodeIO closed this Nov 21, 2017
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.

2 participants