Inferring local-register bounds from structured code #
Stmt.regBound counts the register slots actually named by a statement, including
call destinations and argument expressions. It does not constrain callees or
assign an execution cost. Together with parameter and result-field bounds it
lets a compiler infer a function's local frame from its emitted syntax.
One past every register read or written by the actual statement syntax.
Equations
- Ram.Stmt.skip.regBound = 0
- (Ram.Stmt.assign dst value).regBound = max (dst + 1) value.varBound
- (Ram.Stmt.store address value).regBound = max address.varBound value.varBound
- (first.seq second).regBound = max first.regBound second.regBound
- (Ram.Stmt.ite condition yes no).regBound = max condition.varBound (max yes.regBound no.regBound)
- (Ram.Stmt.while condition body).regBound = max condition.varBound body.regBound
- (Ram.Stmt.read dst).regBound = dst + 1
- (Ram.Stmt.write value).regBound = value.varBound
- (Ram.Stmt.call dsts fn args).regBound = max (List.foldr (fun (dst rest : Nat) => max (dst + 1) rest) 0 dsts) (List.foldr (fun (arg : Ram.Expr) (rest : Nat) => max arg.varBound rest) 0 args)
Instances For
theorem
Ram.Stmt.wellFormed_of_regBound_le
{stmt : Stmt}
{locals : Nat}
(bound : stmt.regBound ≤ locals)
:
stmt.WellFormed locals
Any allowance covering the inferred bound covers every local operand. Function existence, arity and dynamic safety remain separate obligations.
The inferred bound is sufficient for the statement that produced it.