Skip to content

[ImportVerilog] Capture analysis should skip reprocessing identical module instances#10338

Open
rocallahan wants to merge 2 commits intollvm:mainfrom
rocallahan:capture-analysis-canonical-bodies
Open

[ImportVerilog] Capture analysis should skip reprocessing identical module instances#10338
rocallahan wants to merge 2 commits intollvm:mainfrom
rocallahan:capture-analysis-canonical-bodies

Conversation

@rocallahan
Copy link
Copy Markdown

@rocallahan rocallahan commented Apr 28, 2026

Currently capture analysis unconditionally descends into all module instance bodies. This forces slang to instantiate complete ASTs for all module instances, transitively. For large designs this does not scale. For example with one 7M LOC Verilog example, ImportVerilog consumes more than 200GB of memory before crashing with OOM.

Slang lets clients avoid this problem via "canonical instance bodies" that express deduplication. Setting VisitCanonical to true in the ASTVisitor template causes the InstanceBodySymbol visit to use the deduplicated canonical instance body (when available). For this analysis we don't need to re-analyze duplicate instance so we can just keep track of which bodies we've visited and avoid descending into already-visited bodies.

To make this work correctly we have to also ensure that MLIR generation uses the same canonical module bodies, so e.g. the SubroutineSymbols encountered during MLIR generation are the same SubroutineSymbols that CaptureAnalysis recorded. Currently the importer does its own module deduplication which might choose different slang AST module bodies. So, replace the importer's deduplication with slang's canonical module bodies.

rocallahan added a commit to rocallahan/circt that referenced this pull request Apr 28, 2026
…odule instances (llvm#10338)

Currently capture analysis unconditionally descends into all module instance
bodies. This forces slang to instantiate complete ASTs for all module
instances, transitively. For large designs this does not scale. For example
with one 7M LOC Verilog example, ImportVerilog consumes more than 200GB of
memory before crashing with OOM.

Slang lets clients avoid this problem via "canonical instance bodies"
that express deduplication. Setting `VisitCanonical` to true in the
`ASTVisitor` template causes the `InstanceBodySymbol` visit to use
the deduplicated canonical instance body (when available). For this
analysis we don't need to re-analyze duplicate instance so we can
just keep track of which bodies we've visited and avoid descending
into already-visited bodies.
@rocallahan rocallahan force-pushed the capture-analysis-canonical-bodies branch from 37701f3 to e9d6aed Compare April 28, 2026 00:34
@uenoku uenoku requested review from TaoBi22 and fabianschuiki April 28, 2026 01:04
slang already provides this for us. We should just use it.

Also, by using slang's canonical module bodies, analysis passes that
walk the slang AST can produce results that refer to specific
slang AST objects in canonical module bodies, and we know those
are the exact AST objects we're going to use to generate MLIR.
…odule instances (llvm#10338)

Currently capture analysis unconditionally descends into all module instance
bodies. This forces slang to instantiate complete ASTs for all module
instances, transitively. For large designs this does not scale. For example
with one 7M LOC Verilog example, ImportVerilog consumes more than 200GB of
memory before crashing with OOM.

Slang lets clients avoid this problem via "canonical instance bodies"
that express deduplication. Setting `VisitCanonical` to true in the
`ASTVisitor` template causes the `InstanceBodySymbol` visit to use
the deduplicated canonical instance body (when available). For this
analysis we don't need to re-analyze duplicate instance so we can
just keep track of which bodies we've visited and avoid descending
into already-visited bodies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant