Skip to content

Keep power activity annotations across scan_replace and cluster_flops - #12025

Merged
maliberty merged 9 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:or_sta_power_analysis_phase1-bugfix
Nov 3, 2026
Merged

maliberty merged 9 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:or_sta_power_analysis_phase1-bugfix

Conversation

@dsengupta0628

@dsengupta0628 dsengupta0628 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

User activity annotations (set_power_activity -pins/-input_ports, read_saif, read_vcd) were lost or corrupted by netlist edits:

  • scan_replace erased every pin annotation in the design, including pins it never touched.
  • Pins deleted by cluster_flops and other edits left stale entries behind:
    • report_activity_annotation counted them;
    • -report_annotated could crash on them;
    • new pins created later could inherit their activity.
  • The pins that replace a cell (the new scan flop, the multi-bit tray) started without the annotation of the pins they replaced, so their power fell back to the propagated estimate.

The OpenSTA side is already in upstream OpenSTA and in src/sta on master: Power keeps pin annotations across networkChangedNonSdc(), drops an annotation when its pin is deleted, and Power::hasUserActivity()/userActivity() are public.

This PR adds dbSta::copyUserActivity(from, to) and calls it before the old cell is destroyed:

  • dft utils::ReplaceCell (scan_replace and its rollback): each old pin's annotation is copied to the new pin given by the port mapping. ReplaceCell now takes the dbSta.
  • gpl MBFF::ModifyPinConnections (cluster_flops): each flop's D and Q/QN annotation is copied to the tray pin it is reconnected to.

New pins without a counterpart (scan in/enable) and shared tray pins (clock, scan enable, preset, clear) keep the default activity, as before.

Why copy the annotation

The new D/Q/QN pins carry the same signal on the same net as the pins they replace, so the measured activity still applies. Resizing (swapMaster) already keeps annotations, because the pins stay the same. After cluster_flops the original instance names no longer exist, so re-reading the SAIF cannot re-annotate the tray. Copying is the only way to keep the data.

Effect on the reported case

Step Before After
scan_replace All annotations erased Untouched pins keep theirs; the replaced flop's pins get theirs copied
cluster_flops Tray outputs fall back to the propagated estimate; annotation count includes deleted pins Tray D/Q/QN pins get the flops' annotations; count is correct
New cells after clustering New pins inherit stale activity from deleted pins New pins get their normal propagated activity
report_activity_annotation -report_annotated Could crash after a delete Lists only existing pins

Testing

  • New dft/test/scan_replace_activity_sky130:
    • annotates ff1/Q, runs scan_replace;
    • checks that ff1/Q on the new scan cell keeps 0.05 with origin user.
  • New gpl/test/mbff_activity:
    • annotates D and QN of four flops with distinct values, runs cluster_flops into a 4-bit tray;
    • checks that every tray D/QN pin carries the value of the flop placed in that slot.

Not covered

  • A deleted top-level port (dbStaCbk::inDbBTermDestroy only disconnects it) still leaves a stale annotation.
  • When rsz rejects a move and restores the netlist, re-created pins do not get their annotations back.
  • Other transforms that change logic, nets or polarity (e.g. buffer to inverter pairs, restructuring) intentionally do not copy annotations.
  • SDC constraints on clustered or replaced flops are not carried over (exceptions drop the deleted pins).

…y when pin deleted

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>

# Conflicts:
#	src/sta
scan_replace and cluster_flops replace cells by creating new instances
and deleting the old ones. Since OpenSTA drops the activity annotation
of a deleted pin, the user/SAIF/VCD activity on the replaced flop pins
was lost and their power fell back to the propagated estimate, even
though the new pins carry the same signals on the same nets. After
cluster_flops the original instance names no longer exist, so
re-reading the SAIF cannot recover it.

Add dbSta::copyUserActivity(from, to) and call it before the old cell
is destroyed:
- dft utils::ReplaceCell (scan_replace and its rollback): copy each
  old pin to the new pin given by the port mapping. ReplaceCell now
  takes the dbSta.
- gpl MBFF::ModifyPinConnections (cluster_flops): copy each flop's
  D and Q/QN pin to the tray pin it is reconnected to.

New pins without a counterpart (scan in/enable) and shared tray pins
(clock, scan enable, preset, clear) keep the default activity.

Add dft scan_replace_activity_sky130 and gpl mbff_activity.

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
dbSta::copyUserActivity uses Power::hasUserActivity()/userActivity(),
which are public only in the OpenROAD fork of OpenSTA. Guard it with
STA_OPENROAD_FORK so OpenROAD still builds with stock OpenSTA, where
the annotation is not copied. CMake now defines STA_OPENROAD_FORK for
dbSta_lib in C++ as well as swig; Bazel gets it from opensta_lib.

Bump src/sta for the opensta_lib define.

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
@dsengupta0628 dsengupta0628 self-assigned this Oct 27, 2026
@dsengupta0628
dsengupta0628 marked this pull request as ready for review October 27, 2026 21:10
@dsengupta0628
dsengupta0628 requested review from a team as code owners October 27, 2026 21:10

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces functionality to preserve user, SAIF, and VCD activity annotations on pins during netlist edits, such as cell replacement and flop clustering. It implements copyUserActivity in dbSta and integrates it into the DFT cell replacement and GPL multi-bit flip-flop clustering flows, accompanied by new tests. The review feedback recommends adding defensive null checks for the input terms and their corresponding STA pins in copyUserActivity, as well as checking if the sta pointer is null in ReplaceCell before dereferencing it.

Comment thread src/dbSta/src/dbSta.cc Resolved
Comment thread src/dft/src/utils/Utils.cpp Resolved
@dsengupta0628

Copy link
Copy Markdown
Contributor Author

The OpenSTA change will come from upstream (I merged there), so needs to be pulled in 1st before this can be merged

@dsengupta0628 dsengupta0628 changed the title Keep power activity annotations across scan_replace and cluster_flops DO NOT MERGE Keep power activity annotations across scan_replace and cluster_flops Oct 28, 2026
…ions correctly

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
…is_phase1-bugfix

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>

# Conflicts:
#	src/dbSta/src/CMakeLists.txt
Power::hasUserActivity()/userActivity() are public in upstream OpenSTA
now, so the copy no longer needs the fork-only guard. Bazel does not
define STA_OPENROAD_FORK for C++, so the guard turned
copyUserActivity into a no-op.

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
Master now picks sdfstp_1 instead of sdfsbp_1 for this design, as in
one_cell_sky130. The activity lines are unchanged.

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
@dsengupta0628 dsengupta0628 changed the title DO NOT MERGE Keep power activity annotations across scan_replace and cluster_flops Keep power activity annotations across scan_replace and cluster_flops Nov 2, 2026
@maliberty
maliberty merged commit 1bcacf7 into The-OpenROAD-Project:master Nov 3, 2026
20 checks passed
@maliberty
maliberty deleted the or_sta_power_analysis_phase1-bugfix branch November 3, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants