Two codegen improvements that eliminate all non-@start `alloc`
instructions from the emitted QBE IR. Both are prerequisite work for
the self-hosting fixpoint (currently being debugged).
(1) Short-circuit boolean operators now use QBE phi instead of alloc4.
Previously `A and B` / `A or B` emitted:
%slot =l alloc4 1 <- dynamic alloc, grows stack per execution
storew %L, %slot
jnz %L, @rhs, @end
@rhs storew %R, %slot jmp @end
@end %T =w loadw %slot
The slot was allocated in whichever basic block the expression appeared
in. QBE emits a runtime `sub $16, %rsp` for every alloc outside @start
— inside a while-condition this ran on every loop iteration, growing the
stack by 16 bytes per iteration indefinitely.
New form uses a phi node at the join block:
jnz %L, @rhs, @end
@rhs (evaluate R) jmp @end
@end %T =w phi @lhs %L, @rhs %R
No alloc needed; %T is always well-defined at @end by SSA.
FCurrentBlockLabel tracks the current basic block name so the phi can
correctly name its predecessors.
(2) Exception frames pre-allocated at @start via EmitExcFrameAllocs.
Previously EmitTryFinallyStmt / EmitTryExceptStmt emitted `alloc16 512`
inline at the point of the try statement. Inside a loop (e.g. `for I
:= 0 to N-1 do begin try ... finally ... end end`), each iteration
allocated 512 bytes of stack that was never released until the function
returned. Over hundreds of iterations this drifted the stack pointer
into parent exception frame territory, corrupting the exc-frame chain.
New approach: CountTryStmts recursively counts all try blocks in the
function body, EmitExcFrameAllocs pre-allocates %_exc_frame_0 …
%_exc_frame_N at @start (QBE hoists these to the static prologue sub),
and EmitTryFinallyStmt/Except index into the pool via FExcFrameNext.
Result: zero alloc instructions outside @start blocks in the emitted IR.
All 1242 tests pass. Stage-1 IR and stage-2 IR are now byte-for-byte
identical (md5 verified) — the fixpoint is correct at the IR level.
The stage-2 BINARY still crashes during stage-3 generation; this is
under active investigation and may be a QBE vs FPC code-generation
quality issue for the same IR.