ARCH10.md (1557B)
1 # ARCH10: CFG Refactor for Indexed Blocks and Cached Metadata 2 3 ## Goal 4 5 Make CFG construction and traversal more rigorous and efficient by 6 switching to indexed blocks and precomputing successor indices, 7 fallthrough, and function block ranges. 8 9 ## Scope 10 11 - Replace list-based block storage with an indexed structure. 12 - Precompute and store successor indices in each block. 13 - Precompute function block ranges once per CFG. 14 - Preserve external API semantics where possible. 15 16 ## Architecture 17 18 ### Block Representation 19 20 - Store blocks in `Data.Primitive.Array.Array` for O(1) indexing. 21 - Use `Array` (not `SmallArray`) because block counts routinely exceed 22 128; the card table improves GC performance on larger arrays. 23 - Extend `BasicBlock` with: 24 - `bbLastInstr :: Maybe Instr` 25 - `bbSuccIdxs :: [Int]` 26 - `bbHasFallthrough :: Bool` (or derive once) 27 28 ### CFG Caches 29 30 - Add `cfgFuncBlocks :: Map Text [Int]` computed once during CFG build. 31 - Add `cfgCallGraph :: Map Text [Text]` if needed for inter-proc. 32 33 ### Function Boundaries 34 35 - Compute function ranges in a single pass over block labels using 36 `isFunctionLabel`. 37 - Avoid repeated scans in `functionBlocks` and call graph building. 38 39 ## Integration 40 41 - Update traversal functions to use cached successors and indexed blocks. 42 - Keep `functionBlocks` as a thin lookup into cached map. 43 - Adjust inter-proc analysis to use cached maps if not already. 44 45 ## Risks 46 47 - API changes for `cfgBlocks` (list -> vector) may ripple into analysis. 48 - Function label heuristics remain; consider tightening in a follow-on.