Add per-object origin tracking (vOrigins) to Gia_Man_t#487
Add per-object origin tracking (vOrigins) to Gia_Man_t#487robtaylor wants to merge 4 commits intoberkeley-abc:masterfrom
Conversation
Add lightweight origin tracking that propagates source-location provenance through ABC's optimization passes. This enables the Yosys abc9 flow to preserve \src attributes on LUT cells after technology mapping, achieving ~100% coverage on tested designs with negligible overhead (~0.6% time, ~3% memory on picorv32). Changes: - Add Vec_Int_t *vOrigins field to Gia_Man_t with inline accessors - Read/write origins via AIGER "y" extension (sentinel -1 for unmapped) - Propagate through all Gia_ManDup* variants via Gia_ManOriginsDup() - Propagate through structural hashing (AND/XOR/MUX) in giaHash.c - Recover origins after GIA→AIG→GIA round-trips (&dc2, &dch) via Gia_ManOriginsAfterRoundTrip() using CO driver + top-down propagation - Propagate through IF mapper using iCopy correspondence - Instrument giaEquiv, giaMuxes, giaTim, giaBalAig, dauGia Co-developed-by: Claude Code v2.1.44 (claude-opus-4-6)
ABC now propagates origin mappings natively through optimization passes via vOrigins (berkeley-abc/abc#487), so we no longer need to run &verify -y and rewrite the output to reconstruct the mapping. Keep &verify for correctness checking but without -y flag. Co-developed-by: Claude Code v2.1.44 (claude-opus-4-6)
|
Adding @alanminko's response here from email for my context:
I'm now working on adding propagation into the engines, as advised. |
Extend origin tracking to cover the complete abc9 optimization pipeline. Add Gia_ManOriginsDupVec for functions that use Vec_Int_t copy vectors instead of the Value field. Engines instrumented: - &dc2, &dch: Already had round-trip recovery (giaAig.c) - &if: iCopy-based propagation in SopBalance/DsdBalance (giaIf.c) - &syn2, &synch2: Sub-operations (Jf/Lf mappers) + round-trip recovery in Gia_ManAigSynch2Choices (giaScript.c) - &sweep: Gia_ManFraigReduceGia, Gia_ManDupWithBoxes (giaSweep.c) - &scorr: Gia_ManCorrReduce (cecCorr.c) - &mfs: Custom propagation via vMfs2Old/vMfs2Gia (giaMfs.c) - Supporting functions: Gia_ManDupCollapse (giaTim.c), Gia_ManEquivToChoices (giaEquiv.c) Tested: origins survive read → engine → write for all engines including chained pipelines (&dc2; &synch2; &if; &mfs). Co-developed-by: Claude Code v2.1.58 (claude-opus-4-6)
|
Following up on Alan's feedback — this new commit propagates Engines now instrumented:
New helper added: Supporting functions also instrumented: Testing: Origins survive through all individual engines and chained pipelines ( |
When a GIA is grown after vOrigins is created (e.g., AreaBalance adds new nodes), object IDs can exceed Vec_IntSize(vOrigins). Add bounds checks in Gia_ObjOrigin, Gia_ManOriginsDup, OriginsAfterRoundTrip, and IF mapper propagation to prevent Vec_IntEntry assertions. Co-developed-by: Claude Code v2.1.58 (claude-opus-4-6)
|
can we not with the ai slop? |
would you like to actually check the code first? Already discussed with @alanminko as this is the sort of change where AI helps. |
Performance BenchmarkBenchmarked origin propagation overhead on i10.aig (2675 ANDs, 257 inputs, 224 outputs) — same circuit with and without origins loaded, 20 iterations each:
All overhead is within measurement noise (~1%). The full Methodology: Same circuit loaded with ( |
… DupWithAttributes Gia_ObjSetOrigin lacked the bounds check that Gia_ObjOrigin already had — if iObj exceeded Vec_IntSize(vOrigins) (e.g., after GIA growth), Vec_IntWriteEntry would assert. Add matching guard. Gia_ManDupWithAttributes copies all optional GIA attributes but was missing vOrigins. Not on the abc9 hot path (only used by &save/&load), but completes the attribute set for correctness. Co-developed-by: Claude Code v2.1.58 (claude-opus-4-6)
Summary
This adds lightweight per-object origin tracking to
Gia_Man_t, enabling the Yosysabc9flow to preserve\src(source-location) attributes on LUT cells through ABC's optimization passes.Motivation
We are working on preserving
\src(source-location) attributes through the Yosysabc9synthesis flow. The approach uses the XAIGER "y" extension to pass an object-to-source mapping through ABC — Yosys writes the mapping on&read, ABC preserves it during optimization, and Yosys reads it back on&writeto annotate the resulting LUT cells.We initially prototyped a
&verify -yapproach that uses combinational equivalence checking to reconstruct the mapping after optimization, but this only achieves 17-57% coverage on non-trivial designs and doesn't work for sequential circuits. This PR takes a different approach — propagating origins during optimization — which achieves ~100% coverage.Approach
Add a single
Vec_Int_t *vOriginsvector toGia_Man_tthat maps each object to its "origin" input-side object ID:&read(AIGER reader)&write(AIGER writer)Three propagation helpers handle different transformation patterns:
Gia_ManOriginsDup()— for standard dup operations that use theValuefield for old→new mappingGia_ManOriginsDupVec()— for functions usingVec_Int_tcopy vectors (e.g., Jf/Lf mappers)Gia_ManOriginsAfterRoundTrip()— for GIA→AIG→GIA round-trips (&dc2,&dch,&synch2) where per-object data is lost; recovers origins via CI/CO correspondence + top-down fanin propagationEngine Coverage
Origins are propagated through all major ABC9 engines:
&dc2Gia_ManCompress2&dchGia_ManPerformDch&ifSopBalance/DsdBalanceiCopycorrespondence&syn2OriginsDupVec&synch2AigSynch2ChoicesOriginsDupVec+ round-trip recovery&sweepFraigReduceGia,DupWithBoxesOriginsDup&scorrGia_ManCorrReduceOriginsDup&mfsGia_ManInsertMfsvMfs2Old/vMfs2Gia&nfNf_ManDeriveMappingPerformance
Benchmarked on picorv32 (4-LUT mapping via
abc9):The overhead is negligible — approximately 4 bytes per GIA object for the
vOriginsvector, with O(1) propagation per node creation.Coverage
With this change,
\srcretention on LUT cells afterabc9mapping improves from 17-57% to 100% on all tested designs (simple combinational, Amaranth-style, and larger multi-output designs with 54 LUTs).Files changed
src/aig/gia/gia.hvOriginsfield + inline accessors + helper declarationssrc/aig/gia/giaMan.cvOriginsinGia_ManStopsrc/aig/gia/giaAiger.cvOriginsvia "y" extensionsrc/aig/gia/giaDup.cGia_ManOriginsDup+Gia_ManOriginsDupVec+Gia_ManOriginsAfterRoundTrip; instrument allGia_ManDup*variantssrc/aig/gia/giaHash.cGia_ManHashAnd,Gia_ManHashXorReal,Gia_ManHashMuxReal,Gia_ManRehashsrc/aig/gia/giaAig.cGia_ManCompress2(&dc2) andGia_ManPerformDch(&dch)src/aig/gia/giaIf.ciCopy+SopBalance/DsdBalancesrc/aig/gia/giaJf.cJf_ManDeriveGiaandJf_ManDeriveMappingGiaviaOriginsDupVecsrc/aig/gia/giaLf.cLf_ManDeriveMappingCoarseandLf_ManDeriveMappingGiasrc/aig/gia/giaMfs.cGia_ManInsertMfsvia MFS ID correspondencesrc/aig/gia/giaScript.cGia_ManAigSynch2Choicessrc/aig/gia/giaSweep.cGia_ManFraigReduceGiaandGia_ManDupWithBoxessrc/aig/gia/giaEquiv.cGia_ManEquivReduceandGia_ManEquivToChoicessrc/aig/gia/giaMuxes.cGia_ManDupMuxes/Gia_ManDupNoMuxessrc/aig/gia/giaTim.cGia_ManDupNormalize/Gia_ManDupUnnormalize/Gia_ManDupCollapsesrc/aig/gia/giaBalAig.csrc/opt/dau/dauGia.cDsm_ManDeriveGiasrc/proof/cec/cecCorr.cGia_ManCorrReduceContext
This is part of work on YosysHQ/yosys#5712 to improve
\srcattribute retention through theabc9flow.cc @alanminko @Ravenslofty — would appreciate your thoughts on this approach.