[debug][firrtl] Add source-level type debug info: dbg.enumdef/subfiel…#1
Open
[debug][firrtl] Add source-level type debug info: dbg.enumdef/subfiel…#1
Conversation
c8c672f to
3fe530f
Compare
14 tasks
3fe530f to
3b66b1c
Compare
Extends the `dbg` dialect and `firrtl-lower-intrinsics` to propagate
Chisel type names, enum definitions, and constructor parameters into
MLIR so downstream consumers (Tywaves, HGDB) can access them.
- New `dbg` ops: `dbg.enumdef`, `dbg.subfield`, `dbg.moduleinfo`.
`dbg.variable` gets optional `typeName` / `params` / `enumDef`.
- Frontend intrinsics `circt_debug_{var,subfield,enumdef,moduleinfo}`
are lowered in two phases: a pre-scan collects enumdefs and leaf
metadata into `DebugIntrinsicPreScan`, then `CirctDebugVarConverter`
walks each aggregate into `dbg.struct` / `dbg.array`, wrapping every
leaf and intermediate aggregate in `dbg.subfield` with its typeName.
- Non-passive root aggregates are emitted with 0 SSA operands;
the converter looks up the matching port/wire by name.
- `MaterializeDebugInfo` skips names already covered by `circt_debug_var`
to avoid duplicate `dbg.variable`.
- Tests in `test/Dialect/Debug/` and `test/Dialect/FIRRTL/lower-intrinsics-debug.mlir`.
Signed-off-by: fkhaidari <khaidari.fg@gmail.com>
3b66b1c to
054212b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…d/moduleinfo + FIRRTL intrinsic lowering
Extends the
dbgdialect and thefirrtl-lower-intrinsicspass to carry Chisel-level source types, enum definitions, and constructor parameters through the CIRCT pipeline, making them available to downstream consumers (Tywaves, HGDB, hw-debug-info exporters).dbgdialect changes:dbg.enumdefop: declares an enumeration type by name, FQN, and aDictionaryAttrvariant map (Int → String). Produces an!dbg.enumdefSSA token consumed bydbg.variableanddbg.subfield.dbg.subfieldop: likedbg.variablebut for aggregate fields; carries optionaltypeName,params(ArrayAttr of DictionaryAttr), andenumDefoperand. Returns!dbg.subfield.dbg.moduleinfoop: records the Chisel class name and constructor params for the enclosing module.dbg.variablewith optionaltypeName,params, andenumDefoperand (AttrSizedOperandSegments).EnumDefTypeandSubFieldTypetype definitions toDebugTypes.td.EnumDefDeduplicationcanonicalization pattern: collapses duplicatedbg.enumdefops with identical FQN and variant map within a block.FIRRTL intrinsic lowering:
DebugIntrinsicPreScan(new headerFIRRTLDebugPreScan.h): a pre-pass struct populated bybuildDebugPreScan()beforeapplyPartialConversionruns. Performs three ordered walks:circt_debug_enumdef→ emitdbg.enumdef, populateenumDefMap.circt_debug_typetag(leaf, non-emptyparent) → collectLeafMeta(typeName, params, enumDefVal) intoleafMetaMap; erase leaf ops.circt_debug_typenode(PreOrder) → emitdbg.scope, populatescopeMapkeyed by FQN; erase typenode ops.CirctDebugTypeTagConverter: lowers rootcirct_debug_typetagops todbg.variable. For aggregate signals, recursively buildsdbg.struct/dbg.arrayviabuildDebugAggregateWithMeta, wrapping annotated leaf fields indbg.subfieldwith enum/type metadata.CirctDebugModuleInfoConverter: lowerscirct_debug_moduleinfotodbg.moduleinfo, parsing thectorParamsJSON string toArrayAttr.CirctDebugTypeNodeConverter: fallback converter (should be unreachable after pre-scan); emits an error and erases the op.CirctDebugTypeDefConverter: no-op eraser forcirct_debug_typedef.ElideScopeTokenNodeconversion pattern: removesfirrtl.nodeops whose result type converts to!dbg.scope(zero-width UInt → ScopeType).populateDebugLowerings()intoLowerIntrinsicsPass::runOnOperationafter the pre-scan step.dependentDialects = ["debug::DebugDialect"]toLowerIntrinsicspass.CIRCTDebugintoCIRCTFIRRTLCMake target.MaterializeDebugInfopass:circt_debug_typetagintrinsic, preventing duplicatedbg.variableops.materializeVariablecall site for the newdbg.variableoperand signature (typeName,params,enumRefall null).DebugInfoanalysis:enumDefvalue fromdbg.variableintoDIVariable.FIR parser:
cmem/smemwith a clear diagnostic (behavioral memory element type must be passive).LowerCHIRRTLpass:visitInvalidOpto visit non-FIRRTL ops (e.g.dbg.variable) so their operands are updated when they reference CHIRRTL memory port values.Tests:
test/Dialect/Debug/ops.mlir: parse/print round-trip for new ops.test/Dialect/Debug/enumdef-ssa-roundtrip.mlir:dbg.enumdef+dbg.variableSSA round-trip.test/Dialect/Debug/enumdef-canonicalize.mlir: deduplication of identical/divergingdbg.enumdefops.test/Dialect/Debug/subfield-enumdef-ssa.mlir:dbg.subfieldwith enum SSA round-trip.test/Dialect/Debug/variable-enumdef-ssa.mlir:dbg.variablewithenumDefoperand.test/Dialect/FIRRTL/lower-intrinsics-debug.mlir: end-to-end lowering of moduleinfo, enumdef, scalar/bundle/vec typetag, typenode hierarchy, and bundle-with-enum-field cases throughfirrtl-lower-intrinsics.