buildSsa method
Builds SSA form for a CFG.
parameters is an optional list of function parameters that should be
initialized with version 0 in the entry block. This ensures SSA invariant
(single definition per variable) is maintained for parameters.
Implementation
ControlFlowGraph buildSsa(ControlFlowGraph cfg, [List<Variable>? parameters]) {
// Initialize parameters in entry block with version 0
// This ensures parameters have proper SSA versioning for Def-Use chains
if (parameters != null) {
for (final param in parameters) {
final versioned = param.withVersion(0);
writeVariable(param, cfg.entry, VariableValue(versioned));
}
}
// Process blocks in reverse postorder
for (final block in cfg.reversePostOrder) {
_processBlock(block);
}
// Seal all blocks
for (final block in cfg.blocks) {
sealBlock(block);
}
// Insert phi instructions into blocks
_insertPhisIntoBlocks(cfg);
return cfg;
}