sass2mlir / Manual

CFG, SSA & liveness

Read the recovered control flow, definitions, liveness and uniformity before writing a transformation.

Analysis

Start with the dependencies

A pass needs to know which value an instruction reads, which paths reach it, and how long the value must remain available. sass2mlir keeps two connected views: PSIR retains physical instruction evidence and control flow; MLIR expresses recovered values as SSA results and block arguments. Analyses of an edited function must use its current IR.

Start with a cubin from the capture walkthrough. These commands need an MLIR-enabled build:

build/sass-mlir inspect kernel.cubin
build/sass-mlir research analyze kernel.cubin \
  --defuse --reaching --liveness --uniformity
build/sass-mlir lift kernel.cubin --out ir

research analyze reads cubins, lifts them internally, and prints the requested diagnostics. It also checks the explicit MLIR liveness projection against PSIR. It does not write a transformed image. There are no separate cfg, defuse, liveness or uniform commands.

Reading the result

What each analysis tells a pass

ViewQuestion it answersBoundary
Control flowWhich blocks and direct edges can execute?Unknown indirect targets and reconvergence need additional contracts.
--defuseWhich physical register fields does an operation define or use?Explicit operands are not a complete model of every implicit effect.
--reachingWhich SSA definitions reach a block argument or use?Recovered dependencies do not establish an arbitrary arithmetic rewrite.
--livenessWhich register values must survive each block boundary?Allocation also needs instruction widths and asynchronous lifetimes.
--uniformityWhich current SSA values are proven equal across lanes?Unproved values remain potentially varying.

At a join, MLIR block arguments merge incoming definitions. A loop backedge passes the next iteration’s values to those arguments. A predicated definition also depends on its previous destination when the write does not happen; that applies even to @!PT. Dropping that old value can make an apparently valid recoloring overwrite live data.

The backend distinguishes explicit and physical register effects. The physical view adds modeled matrix groups, wide memory operands and other implicit spans. It remains a bounded model: preserving an unknown instruction’s bytes does not prove that a pass can move code across it.

Using the result

Make the proof as narrow as the edit

For a register rename, follow allocation. For instruction motion, also check memory effects, guards, ordinary completion and any matrix or shared-stage ownership. Refresh analyses after changing instructions, edges or physical placement. The scheduling guide explains the separate completion and control-code challenges.

The implementation is in dialect/lib/SassAnalyses.cpp, with the machine-to-SSA boundary described in docs/development/ssa-projection.md and the additional effects in docs/development/physical-register-liveness.md. The existing host-liveness, host-physical-liveness and host-uniformity tests exercise these boundaries. Continue with writing a pass.