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
blockitself computes values for, in increasing handle order. - expressions_
used π - Return the expressions of
functionthat the code generated forblockandextra_rootswill 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
expressionis the result of a statement.