cfallin / waffle

60 stars 6 forks source link

Prevent const prop of const op #9

Closed primoly closed 4 months ago

primoly commented 4 months ago

The changes introduced in https://github.com/cfallin/waffle/commit/bde62867daa022165fb289a8b510b5102f1118e8 lead to an endless loop when constant propagation is enabled. This is because an already constant value will be “transformed” into itself and the changed flag set to true. This PR fixes this by setting const_val to None if the existing op already is a constant. It works but may not be the prettiest way to prevent a const to const propagation. There are other places where that check can be performed, for example on the value itself rather than the op, maybe using the value_is_const function. If you know a better place to do this just tell me and I’ll update the PR. ^-^

cfallin commented 4 months ago

I'll go ahead and make a new release with this. Out of curiosity, how are you using waffle currently? Happy to see actual users, just curious where I'm picking them up and what considerations to keep in mind in the future :-)

cfallin commented 4 months ago

(just published v0.0.36)

primoly commented 4 months ago

I originally found Waffle a couple months back when I searched for a tool to write a Wasm to C++ compiler. Not a professional attempt, just a little coding project. Waffle’s properties that made it stand out: usable as a Rust library and I don’t have to deal with the stacky nature of Wasm myself. That project never got anywhere.

Now I see great potential in Waffle for optimisation, particularly profile guided. Especially with the Wasm Component Model and the Canonical ABI which allows one to predict a lot about the nature of data in memory and the input/output values of functions.

One additional great property of Waffle I want to highlight: It compiles to Wasm itself and doesn’t have any mandatory dependencies on OS features such as the filesystem and CLI. I really appreciate that.

cfallin commented 4 months ago

Neat! I certainly hope waffle can be used for building out additional tooling for such optimization. In that context its codegen is still fairly non-great, IMHO (mostly to do with the "treeification" / use of the operand stack) but that will hopefully improve with time. Happy to talk further if you run into any missing functionality or other issues!