Skip to main content

Module precise_liveness

Module precise_liveness 

Source
Expand description

Computes the points where each local must have a distinct allocation.

The result is a SparseIntervalMatrix with one row per local. Two locals may share the same address only if their rows are disjoint. To model MIR statements where a source operand and destination place may share an address, each statement and terminator is split into an early point, where operands are read, and a late point, where destinations are written.

A local live range starts at the late point of any statement or terminator that writes to it without a Deref projection. It ends at StorageLive or StorageDead, or at the early point of a whole-local move operand or the last use of that local on a control-flow path (only for locals whose address is never observed). This happens at StorageLive because it resets a local to an uninitialized state.

Call terminators are handled specially: move operands are kept live through the late point of the terminator so they conflict with each other and with the destination place. This matches the runtime behavior where the place is donated to the callee for the duration of the call.

The analysis consists of three passes:

  1. A backward value-liveness analysis which identifies the last point at which each local is directly used in each control flow path. This is used to shorten the lifetime of unborrowed locals to their last use.
  2. A forward allocation-liveness analysis which uses that information together with writes, moves, and storage markers to compute which allocations may be live on entry to each block.
  3. A final walk using those entry states which constructs the matrix and distinguishes whether each effect happens at the early or late point of a statement or terminator.

StructsΒ§

KillPoints πŸ”’
KillPointsVisitor πŸ”’
MatrixBuilder πŸ”’
Helper type to construct a SparseIntervalMatrix.
PreciseLiveness πŸ”’
SplitPointIndex
A PointIndex with the lower bit encoding early/late inside a statement.
VisitAllocatedLocalsWith
Visits locals that are implicitly allocated by a statement or terminator as part of destination place evaluation.
VisitDeallocatedLocalsWith
Visits locals that are implicitly freed by being evaluated as a bare-local move operand or through a storage statement.

EnumsΒ§

SplitPointEffect
Different β€œphases” of a single MIR statement, used to describe how overlapping operands are handled.

FunctionsΒ§

dump_liveness_matrix
liveness_matrix