Improve performance by caching CFG building
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -10,11 +10,19 @@ namespace Spa
|
|||||||
|
|
||||||
structure Program where
|
structure Program where
|
||||||
rootStmt : Stmt
|
rootStmt : Stmt
|
||||||
|
/-- A memoized copy of the control-flow graph. This field is an
|
||||||
|
implementation detail to avoid re-computing `Graph.wrap` and `Stmt.cfg`
|
||||||
|
every time the program's control flow graph is needed -/
|
||||||
|
cfgCache : Thunk Graph := Thunk.mk fun _ => Graph.wrap rootStmt.cfg
|
||||||
|
|
||||||
namespace Program
|
namespace Program
|
||||||
|
|
||||||
variable (p : Program)
|
variable (p : Program)
|
||||||
|
|
||||||
|
-- Runtime implementation of `cfg`: read the memoized graph.
|
||||||
|
private def cfgImpl : Graph := p.cfgCache.get
|
||||||
|
|
||||||
|
@[implemented_by cfgImpl]
|
||||||
def cfg : Graph := Graph.wrap p.rootStmt.cfg
|
def cfg : Graph := Graph.wrap p.rootStmt.cfg
|
||||||
|
|
||||||
abbrev State : Type := p.cfg.Index
|
abbrev State : Type := p.cfg.Index
|
||||||
|
|||||||
Reference in New Issue
Block a user