Skip to main content

Module hoist

Module hoist 

Source
Expand description

Finding temporaries that must be declared outside a loop.

Naga IR’s Loop statement runs its continuing block after its body, but MSL has no equivalent construct, so Writer::put_block emits the continuing block at the top of a while loop, skipped on the first iteration:

β“˜
bool loop_init = true;
while(true) {
    if (!loop_init) {
        <continuing>
        if (<break_if>) { break; }
    }
    loop_init = false;
    <body>
}

Expressions emitted in body are in scope in continuing, but the temporaries holding their values are declared below the generated continuing code, so they can’t be named there. Re-evaluating such an expression in place would use the state at the end of the loop iteration, which may have changed from the state at the original position.

So when a loop has a continuing block, we declare the temporaries the continuing block needs ahead of the while loop, and have the body merely assign to them.

FunctionsΒ§

definitions πŸ”’
Return the expressions that block itself computes values for, in increasing handle order.
expressions_used πŸ”’
Return the expressions of function that the code generated for block and extra_roots will refer to, directly or indirectly.
fits_in_temporary πŸ”’
Whether a value of handle’s type can be held in a default-initialized local temporary.
is_statement_result πŸ”’
Whether expression is the result of a statement.