[code-reflection] RFR: Partial evaluator transform

Hannes Greule hgreule at openjdk.org
Fri Jun 6 22:58:28 UTC 2025


On Tue, 20 May 2025 23:08:45 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

> This test contains an experimental partial evaluator transformer, which takes as input a model and a predicate function that can identify if an operation's result is to be considered as constant, evaluates the constant operations, returns output model containing the evaluated results.
> 
> The transformer processes the model by traversing blocks and operations, operations in sequence and blocks in reserve post order. If an operation result is constant, or the operation uses operands that are all constant and therefore its result is also constant, then the operation is evaluated (interpreted) and is replaced with a constant operation whose constant value is the result of the evaluation. Otherwise, the operation is copied.
> 
> For forward control flow constant branches are replaced with direct branches, and constant arguments replace associated block parameters.
> 
> For loops we peel loop iterations until the iteration is not constant or the loop ends. A constant loop iteration is one whose arguments input to the loop header are constant and there is a constant branch to the loop header. Care needs to be taken when branching back to the loop header. In such cases associated state needs to be reset to peel the next iteration and determine if peeling should then continue. Supporting loops require that they are identified (the loop header, loop latches, loop body, and loop exits), including loops with multiple ways break out and continue.

I guess that's completely out of scope for now, but I wonder if we could leverage the insights of https://dl.acm.org/doi/10.1145/3656392 to build a common framework that can be re-used with appropriate abstract domains for stuff like that. I have to admit that this is out of my comfort zone, but it feels like we already have a lot of "almost abstract interpretation but more specific" implementations around.

-------------

PR Comment: https://git.openjdk.org/babylon/pull/431#issuecomment-2937087194


More information about the babylon-dev mailing list