Skip to content

Commit 09a27cf

Browse files
committed
flow: bisect bazel-vs-make yosys drift with a pre-ABC hash
`synth__canonical_netlist__hash` (1_1_yosys_canonicalize.rtlil, post-front-end) and `synth__netlist__hash` (1_2_yosys.v, post-ABC) already exist as warning-level entries in `rules-base.json`. On asap7/uart both already DIFFER between bazel-pinned yosys and make-pulled `tools/install` yosys (`cff062a8…` vs `6e8e16e4…`, and `ab8b0b69…` vs `95652d90…` respectively), so the post-ABC hash on its own can't tell us whether the drift is yosys-internal non-determinism (read_verilog / hierarchy / opt_clean / techmap / dfflibmap) or an ABC version mismatch. Add a third fingerprint immediately before the main `abc` call in synth.tcl: [WARN] synth__canonical_netlist__hash differs ... # front-end snapshot [WARN] synth__preabc_netlist__hash differs ... # mid-level synth [WARN] synth__netlist__hash differs ... # post-ABC The pre-ABC snapshot is computed by `write_rtlil` to a temp path, `exec sha1sum`, file delete, then `puts` of the hash to the yosys log. The full RTLIL is never shipped as a bazel artifact — only the 40-char SHA in `1_2_yosys.log`, which is already collected by the synth action. `extractTagFromFile` in `genMetrics.py` regex- greps the line; the corresponding `level: warning` rule entry lives alongside the other two in `genRuleFile.py`. `flow/designs/asap7/uart/rules-base.json` is regenerated via `make … metadata update_rules` so the third field is populated from make-yosys. Re-running `bazelisk test //flow/designs/asap7/uart: uart_test` then surfaces three warnings: `71b3e9b0…` vs `4ab7b670…` for the new pre-ABC bucket, confirming drift is already present mid-yosys (i.e., not only ABC). Two supporting plumbing changes ride along: * `MODULE.bazel` gains `patches =` on the bazel-orfs `git_override`, pointing at the new `patches/bazel-orfs/` directory. The first vendored patch teaches `orfs_generate_metadata` to pull synth's outputs in via `data =` — without it the post-ABC `synth__netlist__hash` lands as `N/A` because `1_2_yosys.v` isn't otherwise in the metadata action's sandbox. Vendoring here keeps small bazel-orfs fixes in this PR while we iterate; when the patch lands upstream, drop the entry and bump `BAZEL_ORFS_COMMIT`. * `flow/README.md` "Triaging a failing `_test`" bucket #2 is rewritten to document the three-way bisection. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 0d94e4d commit 09a27cf

8 files changed

Lines changed: 140 additions & 16 deletions

File tree

‎MODULE.bazel‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,19 @@ BAZEL_ORFS_COMMIT = "c000cb3fa5c756841de0411f848a211c360468c2"
4141
BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git"
4242

4343
# To bump version, run: bazelisk run @bazel-orfs//:bump
44+
#
45+
# `patches =` keeps small bazel-orfs fixes vendored in this repo
46+
# while we iterate, instead of round-tripping every change through a
47+
# bazel-orfs PR + pin bump. When a patch lands upstream, drop the
48+
# entry here and bump BAZEL_ORFS_COMMIT.
4449
git_override(
4550
module_name = "bazel-orfs",
4651
commit = BAZEL_ORFS_COMMIT,
4752
remote = BAZEL_ORFS_REMOTE,
53+
patch_strip = 1,
54+
patches = [
55+
"//patches/bazel-orfs:0001-flow.bzl-pull-synth-into-generate_metadata-data-deps.patch",
56+
],
4857
)
4958

5059
git_override(

‎flow/README.md‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,21 @@ For each failing `<design>_test`, decide which bucket it falls into:
101101
bazel-orfs validates against.
102102

103103
2. **Yosys-environment false positive (OpenROAD is idempotent given
104-
the same netlist).** `rules-base.json` carries SHA-1 fingerprints
105-
of `1_1_yosys_canonicalize.rtlil` and `1_2_yosys.v`
106-
(`synth__canonical_netlist__hash` / `synth__netlist__hash`) at
107-
warning level, so a bazel-yosys vs make-yosys netlist drift
108-
surfaces in `checkMetadata.py` as:
109-
110-
[WARN] synth__canonical_netlist__hash differs test: <bazel-sha> == <make-sha>
111-
[WARN] synth__netlist__hash differs test: <bazel-sha> == <make-sha>
112-
113-
A QoR threshold breaking together with that warning is almost
114-
always yosys-env drift. Confirm with the per-stage `.odb` SHA
104+
the same netlist).** `rules-base.json` carries three SHA-1
105+
fingerprints of yosys' internal state at warning level so a
106+
bazel-yosys vs make-yosys drift surfaces in `checkMetadata.py`
107+
as three buckets:
108+
109+
[WARN] synth__canonical_netlist__hash differs test: <bazel> == <make> # front-end + opt_clean
110+
[WARN] synth__preabc_netlist__hash differs test: <bazel> == <make> # mid-level synth, immediately pre-ABC
111+
[WARN] synth__netlist__hash differs test: <bazel> == <make> # post-ABC `1_2_yosys.v`
112+
113+
The bucket(s) that DIFFER bisect where drift entered: front-end
114+
already differing means iteration-order non-determinism is firing
115+
in `read_design_sources`/`hierarchy`/`opt_clean`; pre-ABC matching
116+
but post-ABC diverging means the bazel-pinned vs make-pulled ABC
117+
are different revisions. A QoR threshold breaking together with
118+
any of these is almost always yosys-env drift. Confirm with the per-stage `.odb` SHA
115119
matrix from `@bazel-orfs//:make-yosys-netlist` (feeds make's
116120
netlist into bazel) or its reverse-direction sibling
117121
`@bazel-orfs//:yosys-check` (bazel's netlist into make):

‎flow/designs/asap7/uart/rules-base.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"compare": "==",
55
"level": "warning"
66
},
7+
"synth__preabc_netlist__hash": {
8+
"value": "4ab7b6700d9ca14e2ee4531aceb79b339aabca73",
9+
"compare": "==",
10+
"level": "warning"
11+
},
712
"synth__netlist__hash": {
813
"value": "95652d905a7cf9bc9c935a58e01a76e65327c8b3",
914
"compare": "==",

‎flow/scripts/synth.tcl‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ opt
248248
# Replace undef values with defined constants
249249
setundef -zero
250250

251+
# Fingerprint the design state immediately before ABC runs so the
252+
# `synth__preabc_netlist__hash` rules-base.json check can isolate
253+
# mid-level-yosys drift from ABC drift. Combined with
254+
# `synth__canonical_netlist__hash` (front-end + opt_clean snapshot)
255+
# and `synth__netlist__hash` (post-ABC `1_2_yosys.v`), this gives a
256+
# three-way bisection: front-end vs mid-level synth vs ABC.
257+
#
258+
# The RTLIL itself is written to a temp path, hashed, and deleted —
259+
# we only ship the SHA in the yosys log so we don't burden bazel's
260+
# action outputs with another large netlist artifact. See
261+
# flow/util/genMetrics.py for the matching log-extraction.
262+
set preabc_tmp $::env(RESULTS_DIR)/1_2_yosys_preabc.rtlil
263+
write_rtlil $preabc_tmp
264+
set preabc_sha [lindex [split [exec sha1sum $preabc_tmp]] 0]
265+
file delete $preabc_tmp
266+
puts "synth__preabc_netlist__hash: $preabc_sha"
267+
251268
if {
252269
![env_var_exists_and_non_empty SYNTH_WRAPPED_OPERATORS] &&
253270
![env_var_exists_and_non_empty SWAP_ARITH_OPERATORS]

‎flow/util/genMetrics.py‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,30 @@ def extract_metrics(
262262
rptPath + "/synth_stat.txt",
263263
)
264264

265-
# Netlist hashes: fingerprints of the canonical RTLIL (pre-ABC) and
266-
# the final post-synthesis Verilog so the rules-base.json check
267-
# (level=warning) flags when bazel-built vs make-built yosys
268-
# disagree for the same RTL. See flow/README.md "Triaging a failing
269-
# _test" → "Yosys-environment false positive" for context.
265+
# Netlist hashes: front-end / mid-level / post-ABC fingerprints
266+
# so the rules-base.json check (level=warning) flags where bazel-
267+
# built vs make-built yosys diverge. See flow/README.md "Triaging
268+
# a failing _test" → "Yosys-environment false positive".
269+
#
270+
# canonical = after `read_design_sources` + `hierarchy -check` +
271+
# `opt_clean -purge` (front-end snapshot)
272+
# preabc = immediately before the main `abc` call (after
273+
# techmap, dfflibmap, setundef etc.)
274+
# netlist = `1_2_yosys.v`, post-ABC
270275
metrics_dict["synth__canonical_netlist__hash"] = file_sha1(
271276
resultPath + "/1_1_yosys_canonicalize.rtlil"
272277
)
278+
# `synth__preabc_netlist__hash` is emitted by synth.tcl as a
279+
# `synth__preabc_netlist__hash: <sha>` line in 1_2_yosys.log so we
280+
# don't have to ship the full pre-ABC RTLIL as a bazel artifact.
281+
extractTagFromFile(
282+
"synth__preabc_netlist__hash",
283+
metrics_dict,
284+
r"^synth__preabc_netlist__hash:\s+([0-9a-f]{40})\s*$",
285+
logPath + "/1_2_yosys.log",
286+
t=str,
287+
required=False,
288+
)
273289
metrics_dict["synth__netlist__hash"] = file_sha1(resultPath + "/1_2_yosys.v")
274290

275291
# Clocks

‎flow/util/genRuleFile.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def gen_rule_file(
8484
"compare": "==",
8585
"level": "warning",
8686
},
87+
"synth__preabc_netlist__hash": {
88+
"mode": "literal",
89+
"compare": "==",
90+
"level": "warning",
91+
},
8792
"synth__netlist__hash": {
8893
"mode": "literal",
8994
"compare": "==",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
From fbed7c49ffe59cd66e7587c8692dd41c4c498dcd Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?=C3=98yvind=20Harboe?= <oyvind.harboe@zylin.com>
3+
Date: Fri, 15 May 2026 14:52:56 +0200
4+
Subject: [PATCH] flow.bzl: pull synth into generate_metadata data deps
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
9+
`orfs_generate_metadata`'s action only sees files that reach it via
10+
the floorplan→cts forwarding chain (`forwarded_names = [CANON_OUTPUT]`)
11+
plus whatever's passed in `data =`. The chain forwards
12+
`1_1_yosys_canonicalize.rtlil` but not the post-ABC netlist, so
13+
`genMetrics.py` reads `1_2_yosys.v` from a path that does not exist
14+
in the sandbox and `synth__netlist__hash` lands in `metadata.json`
15+
as `N/A`.
16+
17+
The metadata test rule then surfaces:
18+
19+
[WARN] synth__netlist__hash differs test: N/A == <make-sha>
20+
21+
— a useful tell only by accident, since any non-match yields N/A.
22+
23+
Add the synth step as a data dependency to the metadata step;
24+
synth's DefaultInfo already exposes every result file (canon RTLIL,
25+
`1_2_yosys.v`, `1_2_yosys.sdc`, `1_synth.sdc`, …) so this one line
26+
is enough. Touching every downstream stage's `forwarded_names` to
27+
thread the netlist through floorplan→final would work too but is
28+
considerably more invasive.
29+
30+
Verified on `//flow/designs/asap7/uart:uart_test`: bazel-side hash
31+
moves from `N/A` to `ab8b0b69a2897be911f6f1bd7d0de1649160bc2a`
32+
(make-side baseline `95652d905a7cf9bc9c935a58e01a76e65327c8b3`).
33+
34+
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
35+
---
36+
private/flow.bzl | 8 ++++++++
37+
1 file changed, 8 insertions(+)
38+
39+
diff --git a/private/flow.bzl b/private/flow.bzl
40+
index b59d059..1519eb8 100644
41+
--- a/private/flow.bzl
42+
+++ b/private/flow.bzl
43+
@@ -769,6 +769,14 @@ def _orfs_pass(
44+
data = [
45+
# Need 2_floorplan.sdc
46+
_step_name(name, variant, "floorplan"),
47+
+ # Need 1_2_yosys.v for `synth__netlist__hash` and any
48+
+ # other genMetrics.py field that reads synth results
49+
+ # past the canonicalize RTLIL. Only canonicalize is
50+
+ # threaded through `forwarded_names = [CANON_OUTPUT]`
51+
+ # along the floorplan→cts chain; the post-ABC netlist
52+
+ # is not. Pulling synth's outputs in via `data =`
53+
+ # gives metadata access without touching every stage.
54+
+ _step_name(name, variant, "synth"),
55+
],
56+
kwargs = kwargs,
57+
)
58+
--
59+
2.51.0
60+

‎patches/bazel-orfs/BUILD.bazel‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Vendored patches applied on top of the bazel-orfs git_override pin.
2+
3+
These are small fixes we keep here to reduce churn while iterating;
4+
when they land upstream, drop the entry from MODULE.bazel and bump
5+
BAZEL_ORFS_COMMIT instead.
6+
"""
7+
8+
exports_files(glob(["*.patch"]))

0 commit comments

Comments
 (0)