Skip to content

Commit 3fbe63e

Browse files
oharboeclaude
andcommitted
synth_syn: write 1_synth.v and add opt-in pre/post-synthesis LEC
synth_syn.tcl now always writes a gate-level 1_synth.v (via write_lec_verilog: physical-only masters removed, LEC_AUX_VERILOG_FILES honored) — the Bazel synthesis action declares it as an output and it is the post-synthesis side of LEC. lec_check.tcl: factor the kepler-formal run/verdict out of run_lec_test into run_lec_config, and add an RTL-vs-netlist synthesis LEC (run_synth_lec_test): the input RTL goes through kepler-formal's experimental slang/SystemVerilog frontend via a generated flist (VERILOG_FILES, +incdir+, defines, -G top params, SYNTH_SLANG_ARGS) and is compared against 1_synth.v + LIB_FILES. Gated by a new SYNTH_LEC_CHECK variable (default 0) rather than LEC_CHECK: LEC_CHECK auto-enables when kepler-formal is installed (flow/settings.mk), and kepler's SV frontend does not yet support all RTL constructs — e.g. gcd's RegEn sequential block fails lowering ('fallback currently supports only multi-LHS reset branches') — so riding the auto-enable would break make synth for every SYNTH_USE_SYN design on developer machines. CTS-stage LEC is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 05761af commit 3fbe63e

4 files changed

Lines changed: 115 additions & 4 deletions

File tree

‎flow/scripts/lec_check.tcl‎

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ proc lec_check_enabled { } {
66
}]
77
}
88

9+
# Synthesis (RTL vs netlist) LEC is a separate opt-in: the RTL side needs
10+
# kepler-formal's experimental SystemVerilog frontend, which does not yet
11+
# support all RTL constructs, so it must not ride LEC_CHECK's
12+
# auto-enable-when-installed behavior (flow/settings.mk).
13+
proc synth_lec_check_enabled { } {
14+
return [expr {
15+
[env_var_equals SYNTH_LEC_CHECK 1]
16+
&& [info exists ::env(KEPLER_FORMAL_EXE)]
17+
&& [file executable $::env(KEPLER_FORMAL_EXE)]
18+
}]
19+
}
20+
921
proc write_lec_verilog { filename } {
1022
set remove_cells [find_physical_only_masters]
1123
if { [env_var_exists_and_non_empty REMOVE_CELLS_FOR_LEC] } {
@@ -46,8 +58,9 @@ proc write_lec_script { step file1 file2 } {
4658
close $outfile
4759
}
4860

49-
proc run_lec_test { step file1 file2 } {
50-
write_lec_script $step $file1 $file2
61+
# Run kepler-formal on a previously written ${step}_lec_test.yml and
62+
# fail with a message naming `what` if the log reports a difference.
63+
proc run_lec_config { step what } {
5164
# tclint-disable-next-line command-args
5265
eval exec $::env(KEPLER_FORMAL_EXE) --config $::env(OBJECTS_DIR)/${step}_lec_test.yml
5366
try {
@@ -57,8 +70,72 @@ proc run_lec_test { step file1 file2 } {
5770
set count 0
5871
}
5972
if { $count > 0 } {
60-
error "Repair timing output failed lec test"
73+
error "$what failed lec test"
6174
} else {
62-
puts "Repair timing output passed lec test"
75+
puts "$what passed lec test"
6376
}
6477
}
78+
79+
proc run_lec_test { step file1 file2 } {
80+
write_lec_script $step $file1 $file2
81+
run_lec_config $step "Repair timing output"
82+
}
83+
84+
# Write a slang command file describing the design RTL exactly as
85+
# synth_syn.tcl elaborates it, so kepler-formal's SystemVerilog frontend
86+
# sees the same design. Not replicated (slang defaults differ):
87+
# --compat=vcs, --ignore-assertions, --no-implicit-memories, --std;
88+
# designs that depend on those may fail LEC for frontend reasons.
89+
proc write_sv_rtl_flist { path } {
90+
set out [open $path w]
91+
puts $out "-D SYNTHESIS"
92+
if { [env_var_exists_and_non_empty VERILOG_DEFINES] } {
93+
# Flag/value token stream (e.g. "-D NAME"); keep on one line.
94+
puts $out $::env(VERILOG_DEFINES)
95+
}
96+
if { [env_var_exists_and_non_empty VERILOG_INCLUDE_DIRS] } {
97+
foreach dir $::env(VERILOG_INCLUDE_DIRS) {
98+
puts $out "+incdir+$dir"
99+
}
100+
}
101+
dict for {key value} [env_var_or_empty VERILOG_TOP_PARAMS] {
102+
puts $out "-G $key=$value"
103+
}
104+
if { [env_var_exists_and_non_empty SYNTH_SLANG_ARGS] } {
105+
puts $out $::env(SYNTH_SLANG_ARGS)
106+
}
107+
foreach fn $::env(VERILOG_FILES) {
108+
puts $out [string trim $fn]
109+
}
110+
close $out
111+
}
112+
113+
# YAML config comparing the input RTL (slang frontend) against a
114+
# gate-level netlist + liberty models.
115+
proc write_sv_lec_script { step rtl_flist gate_flist } {
116+
set outfile [open "$::env(OBJECTS_DIR)/${step}_lec_test.yml" w]
117+
puts $outfile "format: systemverilog"
118+
puts $outfile "sv_design1_flist: $rtl_flist"
119+
puts $outfile "sv_design1_top: $::env(DESIGN_NAME)"
120+
puts $outfile "sv_design2_flist: $gate_flist"
121+
puts $outfile "sv_design2_top: $::env(DESIGN_NAME)"
122+
puts $outfile "liberty_files:"
123+
foreach libFile $::env(LIB_FILES) {
124+
puts $outfile " - $libFile"
125+
}
126+
puts $outfile "log_file: $::env(LOG_DIR)/${step}_lec_check.log"
127+
close $outfile
128+
}
129+
130+
# Pre- vs post-synthesis LEC: input RTL against the 1_synth.v netlist
131+
# written by synth_syn.tcl. Caller guards with lec_check_enabled.
132+
proc run_synth_lec_test { } {
133+
set rtl_flist $::env(OBJECTS_DIR)/1_synth_rtl.f
134+
set gate_flist $::env(OBJECTS_DIR)/1_synth_gate.f
135+
write_sv_rtl_flist $rtl_flist
136+
set out [open $gate_flist w]
137+
puts $out "$::env(RESULTS_DIR)/1_synth.v"
138+
close $out
139+
write_sv_lec_script 1_synth $rtl_flist $gate_flist
140+
run_lec_config 1_synth "Synthesis output"
141+
}

‎flow/scripts/synth_syn.tcl‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,17 @@ orfs_write_db $::env(RESULTS_DIR)/1_synth.odb
7575
# out by OpenSTA that has no dependencies. Sole writer of
7676
# 1_synth.sdc.
7777
orfs_write_sdc $::env(RESULTS_DIR)/1_synth.sdc
78+
79+
# Gate-level netlist for LEC (kepler-formal compares it against the input
80+
# RTL) and any other netlist consumer. The Bazel synthesis action declares
81+
# this file as an output, so it must be written unconditionally.
82+
source $::env(SCRIPTS_DIR)/lec_check.tcl
83+
write_lec_verilog 1_synth.v
84+
85+
# Pre- vs post-synthesis LEC. Explicit opt-in via SYNTH_LEC_CHECK=1 —
86+
# unlike the CTS-stage LEC it does not auto-enable when kepler-formal is
87+
# installed, because the RTL side depends on kepler's experimental
88+
# SystemVerilog frontend.
89+
if { [synth_lec_check_enabled] } {
90+
run_synth_lec_test
91+
}

‎flow/scripts/variables.json‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flow/scripts/variables.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,12 +1579,24 @@ LEC_CHECK:
15791579
default: 0
15801580
stages:
15811581
- cts
1582+
SYNTH_LEC_CHECK:
1583+
description: >
1584+
Run a formal equivalence check between the input RTL and the
1585+
OpenROAD-SYN synthesis netlist (1_synth.v). The RTL side goes through
1586+
kepler-formal's experimental SystemVerilog frontend, which does not
1587+
yet support all RTL constructs, so this is a separate opt-in from
1588+
LEC_CHECK (which auto-enables when kepler-formal is installed and
1589+
compares gate-level netlists only). Requires KEPLER_FORMAL_EXE.
1590+
default: 0
1591+
stages:
1592+
- synth
15821593
LEC_AUX_VERILOG_FILES:
15831594
description: >
15841595
Additional Verilog files (e.g. blackbox stubs) to include in LEC
15851596
equivalence checks. Appended to the generated Verilog netlist before
15861597
running the formal equivalence check.
15871598
stages:
1599+
- synth
15881600
- cts
15891601
REMOVE_CELLS_FOR_LEC:
15901602
description: >

0 commit comments

Comments
 (0)