Skip to content

Clean node retention implementation with extended coverage#4

Open
robtaylor wants to merge 14 commits intoSilimate:yosys-experimentalfrom
robtaylor:node_retention
Open

Clean node retention implementation with extended coverage#4
robtaylor wants to merge 14 commits intoSilimate:yosys-experimentalfrom
robtaylor:node_retention

Conversation

@robtaylor
Copy link

Summary

This PR provides a clean, restructured implementation of the node retention feature, based on the original work by @AdvaySingh1. The key changes:

  • Cleaned up history: The original 103 WIP commits have been reorganized into 11 logical, bisectable commits grouped by subsystem (core data structures, lifecycle, classic Ntk ops, AIG/GIA conversion, GIA optimization passes, I/O integration, tests)
  • Extended retention coverage: Propagation has been added to many operations that were previously missing, covering both the classic abc and abc9 synthesis pipelines end-to-end
  • CI: Full test coverage across Posix (make), Posix (CMake), and Windows builds with retention validation scripts
  • New &write_retention command: Dumps GIA retention map for debugging/validation

New retention propagation (not in original branch)

Area Functions
CEC/SAT sweeping Cec4_ManStartNew, sweep loops, Gia_ManLocalRehash
DCH Dch_DeriveTotalAig, Dch_ManSweep
GIA sweep Gia_ManDupWithBoxes, Gia_ManFraigCreateGia, Gia_ManFraigReduceGia
GIA script Gia_ManDupFromBarBufs, Gia_ManDupToBarBufs
Correlation Gia_ManCorrReduce
Classic strash Abc_NtkRestrash
Classic balance Abc_NodeBalance_rec
Classic Dar Abc_NtkFromDar, Abc_NtkFromDarChoices
Classic If (LUT mapping) Abc_NtkToIf, Abc_NodeFromIf_rec
Classic Ntk dup Abc_NtkDup
Netlist conversion Abc_NtkAigToLogicSop

Validated with Yosys integration

This ABC branch is used by two Yosys PRs that preserve \src attributes through synthesis:

Both pass CI with test fixtures including Amaranth-style and SpinalHDL-style Verilog designs.

Test plan

  • All ABC CI passing (Posix make, Posix CMake, Windows)
  • Node retention integration tests (get_and_put, v3, full pipeline)
  • GIA retention validation (&write_retention output verified)
  • Yosys classic abc src retention tests passing
  • Yosys abc9 src retention tests passing
  • Tested with i10.aig benchmark (smoke test + CEC equivalence check)

cc @AdvaySingh1

@greptile-apps
Copy link

greptile-apps bot commented Feb 20, 2026

Greptile Summary

This PR implements a comprehensive node retention system for tracking source node origins through ABC synthesis transformations, enabling Yosys to preserve \src attributes through both classic abc and abc9 passes.

Key Changes

  • Core infrastructure: Added Nr_Man_t hash table-based retention manager to Abc_Ntk_t, Aig_Man_t, and Gia_Man_t structures
  • Retention propagation: Extended coverage to 30+ operations across classic ABC (strash, balance, Dar, If mapping) and GIA subsystems (dup, hash, sweep, CEC, DCH)
  • New &write_retention command: Outputs GIA retention map with CI position mappings for Yosys integration
  • Comprehensive testing: Unit tests, integration scripts, and CI validation across Posix (make/CMake) and Windows builds

Issues Found

  • Critical logic error in src/base/abci/abcDar.c:303-307 - missing braces cause retention call to execute unconditionally for all latches instead of only Init1 latches
  • Minor cleanup needed: duplicate commented include in abc.h, TODO comment and duplicate declaration in mainInt.h

The implementation is well-structured with proper memory management, validation functions, and thorough test coverage. The retention manager uses dynamic hash table resizing and provides comprehensive debugging/profiling capabilities.

Confidence Score: 3/5

  • Safe to merge after fixing the critical logic error in abcDar.c latch handling
  • Score reflects one critical logic bug (missing braces in latch retention propagation) that could cause incorrect retention tracking for Init1 latches. The core implementation is solid with good test coverage, but this bug needs fixing before merge. All other changes appear correct and well-tested.
  • src/base/abci/abcDar.c requires immediate attention for the brace error at lines 303-307

Important Files Changed

Filename Overview
src/base/abc/node_retention.c Core retention manager implementation - hash table-based tracking system with proper memory management and validation
src/base/abc/node_retention.h Header defines retention manager API and data structures for tracking node origins through transformations
src/base/abci/abcDar.c Dar conversion with retention propagation - contains logic error in latch handling (line 306 outside if block)
src/proof/cec/cecSatG2.c CEC/SAT sweeping operations with retention propagation for both CI/CO and internal AND nodes
src/aig/gia/giaDup.c GIA duplication operations properly propagate retention through various dup functions
src/base/abci/abc.c Added &write_retention command and self-origin seeding in &r - well documented
src/base/abc/abc.h Added pNodeRetention field to Abc_Ntk_t structure with duplicate comment line
src/base/main/mainInt.h Added vNodeRetention global vector - has commented duplicate declaration and TODO

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TB
    subgraph Input["Input Stage"]
        READ["read/&r command"]
        SEED["Self-origin seeding<br/>(CI and AND nodes)"]
    end
    
    subgraph Core["Core Data Structures"]
        ABC_NTK["Abc_Ntk_t<br/>pNodeRetention"]
        AIG_MAN["Aig_Man_t<br/>pNodeRetention"]
        GIA_MAN["Gia_Man_t<br/>pNodeRetention"]
        NR_MAN["Nr_Man_t<br/>(hash table)"]
    end
    
    subgraph Transforms["Transformation Layer"]
        direction LR
        CLASSIC["Classic ABC<br/>- Strash<br/>- Balance<br/>- Dar<br/>- If mapping"]
        GIA_OPS["GIA Ops<br/>- Dup<br/>- Hash<br/>- Sweep<br/>- Script"]
        CEC["CEC/SAT<br/>- Sweeping<br/>- Correlation"]
    end
    
    subgraph Output["Output Stage"]
        WRITE_BLIF["write_blif<br/>(retention map)"]
        WRITE_RET["&write_retention<br/>(GIA retention)"]
    end
    
    READ --> SEED
    SEED --> ABC_NTK
    SEED --> GIA_MAN
    
    ABC_NTK --> NR_MAN
    AIG_MAN --> NR_MAN
    GIA_MAN --> NR_MAN
    
    NR_MAN --> CLASSIC
    NR_MAN --> GIA_OPS
    NR_MAN --> CEC
    
    CLASSIC --> |Nr_ManCopyOrigins| NR_MAN
    GIA_OPS --> |Nr_ManCopyOrigins| NR_MAN
    CEC --> |Nr_ManCopyOrigins| NR_MAN
    
    NR_MAN --> WRITE_BLIF
    NR_MAN --> WRITE_RET
    
    WRITE_BLIF --> YOSYS["Yosys integration<br/>(classic abc pass)"]
    WRITE_RET --> YOSYS2["Yosys integration<br/>(abc9 pass)"]
Loading

Last reviewed commit: 0163b34

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

56 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

robtaylor added a commit to robtaylor/abc that referenced this pull request Feb 20, 2026
Fix bug in Abc_NtkToDar where Nr_ManCopyOrigins for latches used a
potentially complemented pointer (for Init1 latches) and was redundant
with the CI loop that already tracks all latch CIs. Remove the
duplicate commented-out include in abc.h and dead declaration in
mainInt.h.

Found by Greptile review on Silimate#4.

Co-developed-by: Claude Code v2.1.49 (claude-opus-4-6)
robtaylor added a commit to robtaylor/abc that referenced this pull request Feb 21, 2026
Fix bug in Abc_NtkToDar where Nr_ManCopyOrigins for latches used a
potentially complemented pointer (for Init1 latches) and was redundant
with the CI loop that already tracks all latch CIs. Remove the
duplicate commented-out include in abc.h and dead declaration in
mainInt.h.

Found by Greptile review on Silimate#4.

Co-developed-by: Claude Code v2.1.49 (claude-opus-4-6)
- Use stdatomic.h on MinGW instead of MSVC Interlocked functions.
  MinGW defines _WIN32 but has <stdatomic.h> unlike MSVC. Fix guards
  in utilPth.c and sswPart.c.
- Exclude -ldl and -lrt from link libraries on MINGW/MSYS platforms,
  as these Unix-only libraries don't exist on MinGW.
- Add -lshlwapi on MINGW/MSYS for PathMatchSpec used in sclLiberty.c.

Co-developed-by: Claude Code v2.1.50 (claude-opus-4-6)
- Replace ancient .dsw project upgrade approach with CMake + MSYS2/MinGW
  on Windows, using the same CMake build system as posix builds
- Use MSYS2 with mingw-w64 toolchain for reliable GNU make + GCC support
- Use ABC_USE_STDINT_H=1 and -DWIN32 -DWIN32_NO_DLL to handle MinGW
  platform quirks (32-bit long on 64-bit Windows, missing WIN32 macro)
- Update Windows runner from windows-2019 to windows-latest
- Restrict push triggers to main/master branches only across all
  workflows, keeping pull_request triggers for all branches

Co-developed-by: Claude Code v2.1.50 (claude-opus-4-6)
Introduce Nr_Man_t and Nr_Entry_t types for tracking AIG node
retention IDs across logic optimization passes. Add node retention
manager (node_retention.c/h) with create/free/copy/validate/print
operations. Add pNodeRetention pointer to Abc_Ntk_t, Aig_Man_t,
Gia_Man_t, If_Man_t, and Abc_Frame_t data structures.

Co-developed-by: Claude Code v2.1.45 (claude-opus-4-6)
Hook Nr_ManCreate/Nr_ManFree into allocation and deallocation paths
for Abc_Ntk_t, Aig_Man_t, Gia_Man_t, If_Man_t, and Abc_Frame_t.
Ensures retention managers are properly initialized and cleaned up
throughout their lifecycle.

Co-developed-by: Claude Code v2.1.45 (claude-opus-4-6)
Propagate node retention IDs through Abc_Ntk object creation,
utility operations, netlist conversion, strashing, and AIG/Abc
conversion paths. Ensures retention IDs survive network
transformations in the classic representation.

Co-developed-by: Claude Code v2.1.45 (claude-opus-4-6)
Propagate retention IDs through AIG duplication (aigDup.c),
AIG-to-GIA and GIA-to-AIG conversions (giaAig.c), GIA duplication
(giaDup.c), GIA hashing (giaHash.c), MUX extraction/insertion
(giaMuxes.c), and equivalence operations (giaEquiv.c).

Co-developed-by: Claude Code v2.1.45 (claude-opus-4-6)
Propagate retention IDs through balance (giaBalAig.c), LUT mapping
(giaIf.c, giaLf.c), timing (giaTim.c), synthesis scripts
(giaScript.c), DAR balance/rewrite/refactor (darBalance.c,
darCore.c, darRefact.c, darScript.c), DAU GIA construction
(dauGia.c), and DCH choice computation (dchChoice.c).

Co-developed-by: Claude Code v2.1.45 (claude-opus-4-6)
Add &read_retention and &write_retention commands for loading and
outputting node retention data. Integrate retention propagation into
BLIF write paths and I/O utility functions. Register node retention
commands in the command processor.

Co-developed-by: Claude Code v2.1.45 (claude-opus-4-6)
- Fix ctest step to use --test-dir build
- Add CI steps running get_and_put, v3, and abc.script tests
- Add ci_validate.sh to verify output BLIF files are produced

Co-developed-by: Claude Code v2.1.44 (claude-opus-4-6)
Implements Phase 2 of the \src attribute preservation plan:

- New `&write_retention <file>` command writes GIA retention map
  containing CI position-to-GIA-ID mapping and AND/CO node origin
  tracking, enabling Yosys to recover source location attributes
  through ABC9 synthesis

- New `Nr_ManPrintRetentionMapGia()` function in node_retention.c
  that outputs retention data using GIA object IDs directly
  (no name resolution needed - Yosys handles via sym file)

- Seed retention with self-origins in `&read` command so all CI
  and AND objects establish baseline tracking before synthesis

- Fix missing retention propagation in `Gia_ManFromIfLogic()`
  (the default `&if` extraction path was not copying origins
  from If_Man_t back to the new GIA)

- Add GTest unit tests for GIA retention API
- Add integration test script and CI validation for &write_retention

Output format:
  .gia_retention_begin
  CI <ci_position> <gia_object_id>
  <gia_id> SRC <origin_gia_id_1> <origin_gia_id_2> ...
  .gia_retention_end

Co-developed-by: Claude Code v2.1.44 (claude-opus-4-6)
The &fraig -x command (Cec4_ManStartNew in cecSatG2.c) was creating new
GIA managers without propagating node retention data, causing all
retention information to be lost during SAT sweeping. This was the root
cause of empty retention sections when running the abc9 synthesis
pipeline.

Fixed retention propagation in:
- cecSatG2.c: Cec4_ManStartNew (CIs), sweep loops (ANDs), CO
  finalization, Gia_ManLocalRehash
- cecCorr.c: Gia_ManCorrReduce and Gia_ManCorrReduce_rec (scorr path)
- giaSweep.c: Gia_ManDupWithBoxes, Gia_ManFraigCreateGia,
  Gia_ManFraigReduceGia
- giaScript.c: Gia_ManDupFromBarBufs, Gia_ManDupToBarBufs (&dch path)
- dchAig.c: Dch_DeriveTotalAig_rec, Dch_DeriveTotalAig (dch -f path)
- dchSweep.c: Dch_ManSweep CI and AND node propagation

Co-developed-by: Claude Code v2.1.47 (claude-opus-4-6)
Internal nodes were losing retention data through the classic abc
synthesis commands (strash, dc2, balance, dch -f, if, write_blif).
The root cause was missing Nr_ManCopyOrigins calls in several
Abc_Ntk_t transformation functions.

Fixed retention propagation in:
- abcDar.c: Abc_NtkFromDar (Aig->Ntk for dc2/scorr/etc),
  Abc_NtkFromDarChoices (dch -f output)
- abcStrash.c: Abc_NtkRestrash (strash command AND nodes)
- abcBalance.c: Abc_NodeBalance_rec (balance command)
- abcNtk.c: Abc_NtkDup (strash and non-strash branches)
- abcIf.c: Abc_NtkToIf (Ntk->If CIs and ANDs),
  Abc_NodeFromIf_rec (If->Ntk mapped nodes)
- abcNetlist.c: Abc_NtkAigToLogicSop (AIG->logic for write_blif)

Co-developed-by: Claude Code v2.1.47 (claude-opus-4-6)
Add self-contained test scripts for node retention CI tests that use
i10.aig (already in repo) instead of the removed Silimate-specific
BLIF fixtures. Also add node_retention.c/.h to abclib.dsp so the
Windows Visual Studio build can link the retention symbols.

Co-developed-by: Claude Code v2.1.49 (claude-opus-4-6)
Fix bug in Abc_NtkToDar where Nr_ManCopyOrigins for latches used a
potentially complemented pointer (for Init1 latches) and was redundant
with the CI loop that already tracks all latch CIs. Remove the
duplicate commented-out include in abc.h and dead declaration in
mainInt.h.

Found by Greptile review on Silimate#4.

Co-developed-by: Claude Code v2.1.49 (claude-opus-4-6)
robtaylor added a commit to robtaylor/abc that referenced this pull request Feb 24, 2026
Fix bug in Abc_NtkToDar where Nr_ManCopyOrigins for latches used a
potentially complemented pointer (for Init1 latches) and was redundant
with the CI loop that already tracks all latch CIs. Remove the
duplicate commented-out include in abc.h and dead declaration in
mainInt.h.

Found by Greptile review on Silimate#4.

Co-developed-by: Claude Code v2.1.49 (claude-opus-4-6)
@akashlevy
Copy link

Hey @robtaylor sorry I missed this! This looks awesome. I'll test this out and give some feedback soon.

@akashlevy
Copy link

In the meantime, can you take a look at the conflicts?

@robtaylor
Copy link
Author

robtaylor commented Mar 7, 2026 via email

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.

2 participants