Skip to content

Sort blocks

SortBlocks dataclass

SortBlocks(cfg: CFG)

Bases: RewriteRule


              flowchart TD
              kirin.rewrite.sort_blocks.SortBlocks[SortBlocks]
              kirin.rewrite.abc.RewriteRule[RewriteRule]

                              kirin.rewrite.abc.RewriteRule --> kirin.rewrite.sort_blocks.SortBlocks
                


              click kirin.rewrite.sort_blocks.SortBlocks href "" "kirin.rewrite.sort_blocks.SortBlocks"
              click kirin.rewrite.abc.RewriteRule href "" "kirin.rewrite.abc.RewriteRule"
            

Reorder blocks in a region to reverse post-order of the CFG.

RPO guarantees that in well-formed SSA, a block's dominator is visited before the block itself, so statement results appear before their uses in block-list order. This is required for correct Region.clone() and benefits any pass that iterates blocks sequentially.