From 8e388b95813da4cc8dabce0aa2518590abc6b712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Fri, 22 May 2026 10:02:36 +0200 Subject: [PATCH 01/11] flow: add OpenROAD built-in synth as _syn variant of every flat design MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds OpenROAD's integrated synthesizer (sv_elaborate + synthesize, OpenROAD #10473) as a universal "_syn" variant of every flat design driven by design() in flow/designs/design.bzl. Relocates and generalises the throwaway smoke target from OpenROAD #10479, which explicitly said the proper home for this was bazel-orfs / ORFS, not OpenROAD's test tree. Purely additive: no existing Makefile recipe, bazel rule, design, or target's behaviour is altered. Pieces: - flow/scripts/synth_syn.tcl (new) -- povik's driver. Reads LEF/Liberty/SDC via the ORFS env vars and writes 1_synth.odb + 1_synth.sdc directly, bypassing the Yosys 1_2_yosys.v -> synth_odb.tcl chain. - flow/Makefile gains one new phony target do-syn-synth that invokes openroad on synth_syn.tcl. No existing recipe touched. - patches/bazel-orfs/0002-...patch adds a parallel orfs_openroad_synth_rule + orfs_openroad_synth macro in bazel-orfs. OrfsInfo shape matches orfs_synth_rule, so orfs_flow(previous_stage = {"floorplan": ":_syn_synth"}) chains downstream stages unchanged. Vendored here until the integrated syn tool stabilises and this lands upstream. - flow/designs/design.bzl -- design() now also emits the _syn chain for every flat design via a DESIGNS lookup + helper. Hierarchical designs (blocks non-empty) are skipped -- the built-in synthesizer doesn't handle BLOCKS yet. All _syn targets are tagged manual so bazel build //... is unaffected. End state for every flat design: bazelisk build //flow/designs/asap7/gcd:gcd_syn_synth # OpenROAD synth bazelisk build //flow/designs/asap7/gcd:gcd_synth # Yosys (unchanged) Co-Authored-By: Claude Opus 4.7 (1M context) Signed-off-by: Øyvind Harboe --- MODULE.bazel | 1 + flow/Makefile | 12 + flow/designs/design.bzl | 61 +++- flow/scripts/synth_syn.tcl | 74 +++++ ...d-orfs_openroad_synth-rule-and-macro.patch | 265 ++++++++++++++++++ 5 files changed, 412 insertions(+), 1 deletion(-) create mode 100644 flow/scripts/synth_syn.tcl create mode 100644 patches/bazel-orfs/0002-add-orfs_openroad_synth-rule-and-macro.patch diff --git a/MODULE.bazel b/MODULE.bazel index 126de82d6f..fea29ce83f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -52,6 +52,7 @@ git_override( patch_strip = 1, patches = [ "//patches/bazel-orfs:0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch", + "//patches/bazel-orfs:0002-add-orfs_openroad_synth-rule-and-macro.patch", ], remote = BAZEL_ORFS_REMOTE, ) diff --git a/flow/Makefile b/flow/Makefile index 1bb45047a4..f06faa51ab 100644 --- a/flow/Makefile +++ b/flow/Makefile @@ -283,6 +283,18 @@ clean_synth: rm -f $(SYNTH_STATS) rm -f $(SDC_FILE_CLOCK_PERIOD) +# Run Synthesis using OpenROAD's integrated synthesizer (sv_elaborate + +# synthesize, OpenROAD #10473). Drives `synth_syn.tcl`, which reads +# LEF/Liberty/SDC straight from the ORFS env vars and writes 1_synth.odb +# + 1_synth.sdc directly -- bypassing the Yosys + synth_odb chain. Used +# by the bazel-orfs `orfs_openroad_synth_rule` for the `_syn` flow +# variant. Independent of the Yosys recipes above; either path can run. +.PHONY: do-syn-synth +do-syn-synth: + @mkdir -p $(RESULTS_DIR) $(LOG_DIR) $(REPORTS_DIR) + $(RUN_CMD) --log $(abspath $(LOG_DIR)/1_synth.log) --tee -- \ + $(OPENROAD_CMD) $(SCRIPTS_DIR)/synth_syn.tcl + # ============================================================================== # _____ _ ___ ___ ____ ____ _ _ _ _ # | ___| | / _ \ / _ \| _ \| _ \| | / \ | \ | | diff --git a/flow/designs/design.bzl b/flow/designs/design.bzl index b4efc0b1d0..cc1fa5abd0 100644 --- a/flow/designs/design.bzl +++ b/flow/designs/design.bzl @@ -1,6 +1,7 @@ """BUILD boilerplate for flow/designs/.""" -load("@orfs_designs//:designs.bzl", "orfs_design") +load("@bazel-orfs//:openroad.bzl", "orfs_flow", "orfs_openroad_synth") +load("@orfs_designs//:designs.bzl", "DESIGNS", "orfs_design") # Per filegroup target: extensions included in the filegroup. # bazel-orfs's config_mk_parser produces these target names from @@ -76,6 +77,7 @@ def design(config = "config.mk", user_arguments = [], user_sources = [], local_a local_arguments = local_arguments, blender = True, ) + _emit_syn_variant(DESIGNS.get(_design_key())) def files(group, extra_srcs = None): """Named filegroup over conventional extensions. @@ -94,3 +96,60 @@ def files(group, extra_srcs = None): visibility = ["//visibility:public"], ) _export_design_files() + +def _design_key(): + """Map this BUILD package to its DESIGNS key. + + `native.package_name()` looks like `flow/designs//`; + the DESIGNS dict is keyed by `/` (bazel-orfs's + config_mk_parser also indexes by directory name when it differs + from the nickname). Returns "" for packages outside that layout + so the lookup misses cleanly. + """ + parts = native.package_name().split("/") + if len(parts) < 2: + return "" + return "{}/{}".format(parts[-2], parts[-1]) + +def _emit_syn_variant(entry): + """Emit the `_syn` variant chain for `entry` from DESIGNS. + + Adds `_syn_synth` (built-in OpenROAD synth, driven by + flow/scripts/synth_syn.tcl) plus the downstream `_syn_*` chain + via `orfs_flow(variant = "syn", previous_stage = {...})`. + + No-op for hierarchical designs (`entry["blocks"]` non-empty); the + built-in synthesizer doesn't handle BLOCKS yet and those would + just fail. Flat designs pick the variant up for free. + + All emitted targets are tagged `manual` so `bazel build //...` + does not pick them up while the OpenROAD synth tool (PR #10473) + matures. + """ + if entry == None or entry.get("blocks"): + return + name = entry["name"] + pdk = "//flow:" + entry["platform"] + syn_args = dict(entry["arguments"]) + syn_synth = name + "_syn_synth" + orfs_openroad_synth( + name = syn_synth, + module_top = name, + verilog_files = entry["verilog_files"], + sources = entry["sources"], + arguments = syn_args, + pdk = pdk, + variant = "syn", + tags = ["manual"], + ) + orfs_flow( + name = name, + variant = "syn", + verilog_files = entry["verilog_files"], + sources = entry["sources"], + arguments = syn_args, + pdk = pdk, + previous_stage = {"floorplan": ":" + syn_synth}, + tags = ["manual"], + test_kwargs = {"tags": ["orfs", "manual"]}, + ) diff --git a/flow/scripts/synth_syn.tcl b/flow/scripts/synth_syn.tcl new file mode 100644 index 0000000000..a7516024c0 --- /dev/null +++ b/flow/scripts/synth_syn.tcl @@ -0,0 +1,74 @@ +utl::set_metrics_stage "synthesis__{}" +source $::env(SCRIPTS_DIR)/load.tcl +erase_non_stage_variables synth + +source_env_var_if_exists PLATFORM_TCL +source $::env(SCRIPTS_DIR)/read_liberty.tcl + +read_lef $::env(TECH_LEF) +read_lef $::env(SC_LEF) +if { [env_var_exists_and_non_empty ADDITIONAL_LEFS] } { + foreach lef $::env(ADDITIONAL_LEFS) { + read_lef $lef + } +} +set_dont_use $::env(DONT_USE_CELLS) + +# Setup verilog include directories +set vIdirsArgs "" +if { [env_var_exists_and_non_empty VERILOG_INCLUDE_DIRS] } { + foreach dir $::env(VERILOG_INCLUDE_DIRS) { + lappend vIdirsArgs "-I$dir" + } + set vIdirsArgs [join $vIdirsArgs] +} + +set elaborate_args [list \ + -D SYNTHESIS --compat=vcs --ignore-assertions --no-implicit-memories --top $::env(DESIGN_NAME) \ + {*}$vIdirsArgs {*}[env_var_or_empty VERILOG_DEFINES]] + +lappend elaborate_args {*}$::env(VERILOG_FILES) + +# Apply top-level parameters +dict for {key value} [env_var_or_empty VERILOG_TOP_PARAMS] { + lappend elaborate_args -G "$key=$value" +} + +# Apply module blackboxing based on module names as they appear +# in the input, that is before any module name mangling done +# by elaboration and synthesis +if { [env_var_exists_and_non_empty SYNTH_BLACKBOXES] } { + foreach m $::env(SYNTH_BLACKBOXES) { + lappend elaborate_args --blackboxed-module "$m" + } +} + +lappend elaborate_args {*}$::env(SYNTH_SLANG_ARGS) + +# If the sources are solely .v files, enable Verilog compatibility +set has_non_v_files false +foreach fn $::env(VERILOG_FILES) { + if { [file extension [string trim $fn]] != ".v" } { + set has_non_v_files true + } +} +if { !$has_non_v_files } { + lappend elaborate_args --std=1364-2005 +} + +sv_elaborate {*}$elaborate_args +syn::stats + +if {$::env(DESIGN_NAME) == "cva6"} { + syn::remove_ports rvfi_probes_o +} +synthesize + +read_sdc $::env(SDC_FILE) + +orfs_write_db $::env(RESULTS_DIR)/1_synth.odb +# Canonicalize 1_synth.sdc. The original SDC_FILE provided by +# the user could have dependencies, such as sourcing util.tcl, +# which are read in here and a canonicalized version is written +# out by OpenSTA that has no dependencies. +orfs_write_sdc $::env(RESULTS_DIR)/1_synth.sdc diff --git a/patches/bazel-orfs/0002-add-orfs_openroad_synth-rule-and-macro.patch b/patches/bazel-orfs/0002-add-orfs_openroad_synth-rule-and-macro.patch new file mode 100644 index 0000000000..dfbfe6530c --- /dev/null +++ b/patches/bazel-orfs/0002-add-orfs_openroad_synth-rule-and-macro.patch @@ -0,0 +1,265 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=98yvind=20Harboe?= +Date: Fri, 22 May 2026 00:00:00 +0200 +Subject: [PATCH] flow: orfs_openroad_synth_rule + macro for OpenROAD-driven + synthesis + +Adds a parallel synth rule that drives OpenROAD's integrated +synthesizer (sv_elaborate + synthesize, OpenROAD #10473) via the ORFS +Makefile target `do-syn-synth`. The new `flow/scripts/synth_syn.tcl` +script reads LEF/Liberty/SDC straight from the ORFS env vars and +writes `1_synth.odb` + `1_synth.sdc` directly -- bypassing the Yosys ++ synth_odb chain entirely. + +OrfsInfo shape matches `orfs_synth_rule`, so +`orfs_flow(previous_stage = {"floorplan": ":_syn_synth"})` +chains downstream stages unchanged. Used by ORFS's `design()` wrapper +to emit a `_syn` variant alongside every flat design. + +`orfs_synth`, `orfs_synth_rule` and every other existing symbol are +untouched. Vendored here until the integrated syn tool stabilises and +this lands upstream in bazel-orfs. +--- + openroad.bzl | 2 + + private/flow.bzl | 14 ++++ + private/rules.bzl | 178 ++++++++++++++++++++++++++++++++++++++++++ + 3 files changed, 194 insertions(+) + +diff --git a/openroad.bzl b/openroad.bzl +--- a/openroad.bzl ++++ b/openroad.bzl +@@ -19,6 +19,7 @@ + load( + "//private:flow.bzl", + _orfs_flow = "orfs_flow", ++ _orfs_openroad_synth = "orfs_openroad_synth", + _orfs_synth = "orfs_synth", + _orfs_update = "orfs_update", + ) +@@ -133,6 +134,7 @@ + orfs_blender = _orfs_blender + orfs_flow = _orfs_flow + orfs_synth = _orfs_synth ++orfs_openroad_synth = _orfs_openroad_synth + orfs_update = _orfs_update + + # Design config macros +diff --git a/private/flow.bzl b/private/flow.bzl +--- a/private/flow.bzl ++++ b/private/flow.bzl +@@ -18,6 +18,7 @@ + "orfs_run", + "orfs_squashed", + "orfs_synth_rule", ++ "orfs_openroad_synth_rule", + ) + load( + "//private:stages.bzl", +@@ -165,6 +166,19 @@ + orfs_synth_rule(**_filter_stage_args("synth", **kwargs)) + _create_deps_tar(kwargs.get("name"), **kwargs) + ++def orfs_openroad_synth(**kwargs): ++ """Parallel to `orfs_synth`, but drives OpenROAD's integrated ++ synthesizer (`sv_elaborate` + `synthesize`, OpenROAD #10473) via ++ the ORFS Makefile target `do-syn-synth`. The script ++ `flow/scripts/synth_syn.tcl` writes `1_synth.odb` and ++ `1_synth.sdc` directly; no Yosys, no `synth_odb.tcl`. ++ ++ The rule's OrfsInfo shape is identical to `orfs_synth_rule`'s, so ++ `orfs_flow(previous_stage = {"floorplan": ":_syn_synth"})` ++ chains downstream stages unchanged. ++ """ ++ orfs_openroad_synth_rule(**_filter_stage_args("synth", **kwargs)) ++ + def _step_name(name, variant, stage): + if variant: + name += "_" + variant +diff --git a/private/rules.bzl b/private/rules.bzl +--- a/private/rules.bzl ++++ b/private/rules.bzl +@@ -1480,6 +1480,184 @@ + executable = True, + ) + ++# --- OpenROAD integrated-synth implementation --- ++# ++# Mirrors _yosys_impl but drives OpenROAD's built-in synthesizer ++# (sv_elaborate + synthesize, OpenROAD #10473) via the ORFS Makefile ++# target `do-syn-synth`. The script `flow/scripts/synth_syn.tcl` ++# writes `1_synth.odb` and `1_synth.sdc` directly, so this rule does ++# not run Yosys, does not declare `1_2_yosys.v`, and does not invoke ++# `synth_odb.tcl` -- it is a single make-shell action. ++# ++# Provider shape matches `orfs_synth_rule` so that ++# `orfs_flow(previous_stage = {"floorplan": ":_syn_synth"})` ++# chains downstream stages unchanged. ++ ++def _openroad_synth_impl(ctx): ++ all_arguments = merge_arguments( ++ data_arguments(ctx) | required_arguments(ctx), ++ orfs_additional_arguments( ++ [dep[OrfsInfo] for dep in ctx.attr.deps], ++ use_pre_layout = True, ++ ), ++ ) ++ config = declare_artifact(ctx, "results", "1_synth.mk") ++ ctx.actions.write( ++ output = config, ++ content = config_content( ++ ctx, ++ all_arguments, ++ [file.path for file in ctx.files.extra_configs], ++ ), ++ ) ++ ++ synth_logs = declare_artifacts(ctx, "logs", ["1_synth.log"]) ++ synth_odb = declare_artifact(ctx, "results", "1_synth.odb") ++ synth_sdc = declare_artifact(ctx, "results", "1_synth.sdc") ++ synth_outputs = [synth_odb, synth_sdc] ++ ++ commands = [_make_cmd(ctx)] + generation_commands(synth_logs + synth_outputs) ++ ++ ctx.actions.run_shell( ++ arguments = [ ++ "--file", ++ ctx.file._makefile.path, ++ "do-syn-synth", ++ ], ++ command = EXPAND_VERILOG_DIRS + " && ".join(commands), ++ env = config_overrides( ++ ctx, ++ verilog_arguments(ctx.files.verilog_files) | ++ flow_environment(ctx) | ++ config_environment(config), ++ ), ++ inputs = depset( ++ [config] + ctx.files.verilog_files + ctx.files.extra_configs, ++ transitive = [ ++ data_inputs(ctx), ++ pdk_inputs(ctx), ++ deps_inputs(ctx), ++ ], ++ ), ++ outputs = synth_outputs + synth_logs, ++ tools = flow_inputs(ctx), ++ ) ++ ++ # data_arguments → JSON for downstream OrfsInfo.arguments propagation ++ # (same role the Yosys path uses 1_synth.args.json for). ++ synth_args_json = declare_artifact(ctx, "results", "1_synth.args.json") ++ ctx.actions.write( ++ output = synth_args_json, ++ content = json.encode( ++ data_arguments(ctx) | verilog_arguments(ctx.files.verilog_files), ++ ), ++ ) ++ ++ config_short = declare_artifact(ctx, "results", "1_synth.short.mk") ++ ctx.actions.write( ++ output = config_short, ++ content = config_content( ++ ctx, ++ arguments = hack_away_prefix( ++ arguments = merge_arguments( ++ data_arguments(ctx) | required_arguments(ctx), ++ orfs_additional_arguments([dep[OrfsInfo] for dep in ctx.attr.deps]), ++ ) | verilog_arguments(ctx.files.verilog_files), ++ prefix = config_short.root.path, ++ ), ++ paths = [file.short_path for file in ctx.files.extra_configs], ++ ), ++ ) ++ ++ outputs = synth_outputs ++ ++ runfiles = ctx.runfiles( ++ [config_short] + outputs + synth_logs + ctx.files.extra_configs, ++ transitive_files = depset( ++ transitive = [ ++ flow_inputs(ctx), ++ deps_inputs(ctx), ++ pdk_inputs(ctx), ++ ], ++ ), ++ ) ++ ++ return [ ++ DefaultInfo( ++ files = depset(outputs), ++ runfiles = runfiles, ++ ), ++ OutputGroupInfo( ++ logs = depset(synth_logs), ++ reports = depset([]), ++ **{f.basename: depset([f]) for f in [config] + outputs} ++ ), ++ OrfsDepInfo( ++ make = config_short, ++ config = config_short, ++ renames = [], ++ files = depset( ++ [config_short] + ctx.files.verilog_files + ctx.files.extra_configs, ++ ), ++ runfiles = runfiles, ++ ), ++ OrfsInfo( ++ stage = "1_synth", ++ config = config, ++ variant = ctx.attr.variant, ++ odb = synth_odb, ++ gds = None, ++ lef = None, ++ lib = None, ++ lib_pre_layout = None, ++ additional_gds = depset( ++ [dep[OrfsInfo].gds for dep in ctx.attr.deps if dep[OrfsInfo].gds], ++ ), ++ additional_lefs = depset( ++ [dep[OrfsInfo].lef for dep in ctx.attr.deps if dep[OrfsInfo].lef], ++ ), ++ additional_libs = depset( ++ [dep[OrfsInfo].lib for dep in ctx.attr.deps if dep[OrfsInfo].lib], ++ ), ++ additional_libs_pre_layout = depset( ++ [ ++ (dep[OrfsInfo].lib_pre_layout or dep[OrfsInfo].lib) ++ for dep in ctx.attr.deps ++ if (dep[OrfsInfo].lib_pre_layout or dep[OrfsInfo].lib) ++ ], ++ ), ++ arguments = depset([synth_args_json]), ++ ), ++ ctx.attr.pdk[PdkInfo], ++ TopInfo( ++ module_top = ctx.attr.module_top, ++ ), ++ LoggingInfo( ++ logs = depset(synth_logs), ++ reports = depset([]), ++ drcs = depset([]), ++ jsons = depset([]), ++ ), ++ ] ++ ++orfs_openroad_synth_rule = rule( ++ implementation = _openroad_synth_impl, ++ attrs = flow_attrs() | synth_attrs() | { ++ "_stage": attr.string( ++ default = "synth", ++ ), ++ }, ++ provides = [ ++ DefaultInfo, ++ OutputGroupInfo, ++ OrfsDepInfo, ++ OrfsInfo, ++ PdkInfo, ++ TopInfo, ++ LoggingInfo, ++ ], ++) ++ + # --- Make-based stage implementation --- + + _PRE_LAYOUT_STAGES = ("2_floorplan", "3_place") From c4a8cea1378b10ebabee55ad089b530588951185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Fri, 22 May 2026 14:24:04 +0200 Subject: [PATCH 02/11] flow: apply tclfmt to synth_syn.tcl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reformat with tclfmt 0.7.0 — normalize line endings, replace tab indentation with two spaces, and add spaces inside the `if { ... }` brace expression. Pure formatting; no behavior change. Fixes the Tclint CI job on PR #4253. Signed-off-by: Øyvind Harboe --- flow/scripts/synth_syn.tcl | 148 ++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/flow/scripts/synth_syn.tcl b/flow/scripts/synth_syn.tcl index a7516024c0..e6fc590c15 100644 --- a/flow/scripts/synth_syn.tcl +++ b/flow/scripts/synth_syn.tcl @@ -1,74 +1,74 @@ -utl::set_metrics_stage "synthesis__{}" -source $::env(SCRIPTS_DIR)/load.tcl -erase_non_stage_variables synth - -source_env_var_if_exists PLATFORM_TCL -source $::env(SCRIPTS_DIR)/read_liberty.tcl - -read_lef $::env(TECH_LEF) -read_lef $::env(SC_LEF) -if { [env_var_exists_and_non_empty ADDITIONAL_LEFS] } { - foreach lef $::env(ADDITIONAL_LEFS) { - read_lef $lef - } -} -set_dont_use $::env(DONT_USE_CELLS) - -# Setup verilog include directories -set vIdirsArgs "" -if { [env_var_exists_and_non_empty VERILOG_INCLUDE_DIRS] } { - foreach dir $::env(VERILOG_INCLUDE_DIRS) { - lappend vIdirsArgs "-I$dir" - } - set vIdirsArgs [join $vIdirsArgs] -} - -set elaborate_args [list \ - -D SYNTHESIS --compat=vcs --ignore-assertions --no-implicit-memories --top $::env(DESIGN_NAME) \ - {*}$vIdirsArgs {*}[env_var_or_empty VERILOG_DEFINES]] - -lappend elaborate_args {*}$::env(VERILOG_FILES) - -# Apply top-level parameters -dict for {key value} [env_var_or_empty VERILOG_TOP_PARAMS] { - lappend elaborate_args -G "$key=$value" -} - -# Apply module blackboxing based on module names as they appear -# in the input, that is before any module name mangling done -# by elaboration and synthesis -if { [env_var_exists_and_non_empty SYNTH_BLACKBOXES] } { - foreach m $::env(SYNTH_BLACKBOXES) { - lappend elaborate_args --blackboxed-module "$m" - } -} - -lappend elaborate_args {*}$::env(SYNTH_SLANG_ARGS) - -# If the sources are solely .v files, enable Verilog compatibility -set has_non_v_files false -foreach fn $::env(VERILOG_FILES) { - if { [file extension [string trim $fn]] != ".v" } { - set has_non_v_files true - } -} -if { !$has_non_v_files } { - lappend elaborate_args --std=1364-2005 -} - -sv_elaborate {*}$elaborate_args -syn::stats - -if {$::env(DESIGN_NAME) == "cva6"} { - syn::remove_ports rvfi_probes_o -} -synthesize - -read_sdc $::env(SDC_FILE) - -orfs_write_db $::env(RESULTS_DIR)/1_synth.odb -# Canonicalize 1_synth.sdc. The original SDC_FILE provided by -# the user could have dependencies, such as sourcing util.tcl, -# which are read in here and a canonicalized version is written -# out by OpenSTA that has no dependencies. -orfs_write_sdc $::env(RESULTS_DIR)/1_synth.sdc +utl::set_metrics_stage "synthesis__{}" +source $::env(SCRIPTS_DIR)/load.tcl +erase_non_stage_variables synth + +source_env_var_if_exists PLATFORM_TCL +source $::env(SCRIPTS_DIR)/read_liberty.tcl + +read_lef $::env(TECH_LEF) +read_lef $::env(SC_LEF) +if { [env_var_exists_and_non_empty ADDITIONAL_LEFS] } { + foreach lef $::env(ADDITIONAL_LEFS) { + read_lef $lef + } +} +set_dont_use $::env(DONT_USE_CELLS) + +# Setup verilog include directories +set vIdirsArgs "" +if { [env_var_exists_and_non_empty VERILOG_INCLUDE_DIRS] } { + foreach dir $::env(VERILOG_INCLUDE_DIRS) { + lappend vIdirsArgs "-I$dir" + } + set vIdirsArgs [join $vIdirsArgs] +} + +set elaborate_args [list \ + -D SYNTHESIS --compat=vcs --ignore-assertions --no-implicit-memories --top $::env(DESIGN_NAME) \ + {*}$vIdirsArgs {*}[env_var_or_empty VERILOG_DEFINES]] + +lappend elaborate_args {*}$::env(VERILOG_FILES) + +# Apply top-level parameters +dict for {key value} [env_var_or_empty VERILOG_TOP_PARAMS] { + lappend elaborate_args -G "$key=$value" +} + +# Apply module blackboxing based on module names as they appear +# in the input, that is before any module name mangling done +# by elaboration and synthesis +if { [env_var_exists_and_non_empty SYNTH_BLACKBOXES] } { + foreach m $::env(SYNTH_BLACKBOXES) { + lappend elaborate_args --blackboxed-module "$m" + } +} + +lappend elaborate_args {*}$::env(SYNTH_SLANG_ARGS) + +# If the sources are solely .v files, enable Verilog compatibility +set has_non_v_files false +foreach fn $::env(VERILOG_FILES) { + if { [file extension [string trim $fn]] != ".v" } { + set has_non_v_files true + } +} +if { !$has_non_v_files } { + lappend elaborate_args --std=1364-2005 +} + +sv_elaborate {*}$elaborate_args +syn::stats + +if { $::env(DESIGN_NAME) == "cva6" } { + syn::remove_ports rvfi_probes_o +} +synthesize + +read_sdc $::env(SDC_FILE) + +orfs_write_db $::env(RESULTS_DIR)/1_synth.odb +# Canonicalize 1_synth.sdc. The original SDC_FILE provided by +# the user could have dependencies, such as sourcing util.tcl, +# which are read in here and a canonicalized version is written +# out by OpenSTA that has no dependencies. +orfs_write_sdc $::env(RESULTS_DIR)/1_synth.sdc From 658c2b2173d73407e3aa76284a515061ee8b72d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Fri, 22 May 2026 14:25:31 +0200 Subject: [PATCH 03/11] flow: keep vIdirsArgs as a list in synth_syn.tcl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build vIdirsArgs with `[list]` + `lappend` and let `{*}` expand it directly into elaborate_args. The previous code joined the list into a space-separated string and re-expanded it, which would corrupt any include directory path containing whitespace. Signed-off-by: Øyvind Harboe --- flow/scripts/synth_syn.tcl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flow/scripts/synth_syn.tcl b/flow/scripts/synth_syn.tcl index e6fc590c15..0e582585a0 100644 --- a/flow/scripts/synth_syn.tcl +++ b/flow/scripts/synth_syn.tcl @@ -15,12 +15,11 @@ if { [env_var_exists_and_non_empty ADDITIONAL_LEFS] } { set_dont_use $::env(DONT_USE_CELLS) # Setup verilog include directories -set vIdirsArgs "" +set vIdirsArgs [list] if { [env_var_exists_and_non_empty VERILOG_INCLUDE_DIRS] } { foreach dir $::env(VERILOG_INCLUDE_DIRS) { lappend vIdirsArgs "-I$dir" } - set vIdirsArgs [join $vIdirsArgs] } set elaborate_args [list \ From 8ff6fcbb1272aedca1369c31267f32fff4fde750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Mon, 6 Jul 2026 23:23:51 +0200 Subject: [PATCH 04/11] bazel: hermetic-llvm toolchain, bazel-orfs bump, kepler-formal LEC modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tools/OpenROAD -> OpenROAD#10812 head (hermetic-llvm toolchain swap); ORFS root mirrors it: toolchains_llvm 20.1.8 -> BCR module llvm 0.8.11. - Mirror tools/OpenROAD's root-only single_version_overrides (abc, bison, boost.icl, gawk, tcl_lang) plus m4/sed fix releases for the same gnulib libc-header class; override patches must live in the main repo, so they are copied to patches/openroad-deps/. - Mirror the rules_pycross 3.13 environments workaround (root-honored only). - bazelisk run @bazel-orfs//:bump: 3a5ddd7 -> 970ff81; drop patch 0001 (landed upstream as bazel-orfs bfd3a1d). - Pin kepler-formal (hermetic-llvm bazel build, keplertech main) via git_override and consume bazel-orfs's lec module as bazel-orfs-lec. - Carry two new bazel-orfs patches: orfs_canon_verilog (pre-synthesis Verilog from the canonicalize RTLIL checkpoint) and the lec module expansion (build-time lec_check + instant lec_status_test + stage netlist extraction script). Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Øyvind Harboe --- MODULE.bazel | 120 +++- ..._CONFIGS-not-gdsii_use_custom_config.patch | 49 -- .../0003-add-orfs_canon_verilog-rule.patch | 59 ++ ...ime-lec-check-and-netlist-extraction.patch | 482 +++++++++++++++ ...ib-wrapper-headers-use-I-not-isystem.patch | 61 ++ ...ompt-and-handle-eof-without-readline.patch | 62 ++ ...or-interval-lookup-operations-icl-54.patch | 582 ++++++++++++++++++ ...ude-vendored-minizip-crypt.h-by-path.patch | 20 + patches/openroad-deps/BUILD.bazel | 10 + tools/OpenROAD | 2 +- 10 files changed, 1385 insertions(+), 62 deletions(-) delete mode 100644 patches/bazel-orfs/0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch create mode 100644 patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch create mode 100644 patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch create mode 100644 patches/openroad-deps/0001-gnulib-wrapper-headers-use-I-not-isystem.patch create mode 100644 patches/openroad-deps/0001-mainUtils-flush-prompt-and-handle-eof-without-readline.patch create mode 100644 patches/openroad-deps/0001-refactor-interval-lookup-operations-icl-54.patch create mode 100644 patches/openroad-deps/0001-tclZipfs-include-vendored-minizip-crypt.h-by-path.patch create mode 100644 patches/openroad-deps/BUILD.bazel diff --git a/MODULE.bazel b/MODULE.bazel index fea29ce83f..245bd25f94 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -19,13 +19,79 @@ bazel_dep(name = "rules_shell", version = "0.6.1") # our MODULE.bazel doesn't need to be patched at non-root consumption # time. -bazel_dep(name = "toolchains_llvm", version = "1.5.0", dev_dependency = True) +# Hermetic zero-sysroot LLVM toolchain (hermetic-llvm, BCR module "llvm"): +# statically linked LLVM binaries and a cc_toolchain with no host compiler, +# linker, headers or libraries involved. Mirrors tools/OpenROAD (which marks +# it dev_dependency and documents that root modules bring their own C++ +# toolchain). +bazel_dep(name = "llvm", version = "0.8.11", dev_dependency = True) bazel_dep(name = "openroad", dev_dependency = True) local_path_override( module_name = "openroad", path = "tools/OpenROAD", ) +# single_version_override is only honored in the root module, so the +# fixes tools/OpenROAD carries for its own root builds must be mirrored +# here. The patch files are copied into //patches/openroad-deps because +# override patches must live in the main repository (see the comments in +# tools/OpenROAD/MODULE.bazel for each): +# - abc: flush prompt/handle EOF without readline (yosys coprocess hang) +# - bison: gnulib wrapper-header precedence under hermetic-llvm +# - boost.icl: interval_set subtraction bug (boostorg/icl#54) +# - gawk: libc-header shadowing fix release +# - tcl_lang: tclZipfs crypt.h include under zero-sysroot toolchain +single_version_override( + module_name = "abc", + patch_strip = 1, + patches = [ + "//patches/openroad-deps:0001-mainUtils-flush-prompt-and-handle-eof-without-readline.patch", + ], +) + +single_version_override( + module_name = "bison", + patch_strip = 1, + patches = [ + "//patches/openroad-deps:0001-gnulib-wrapper-headers-use-I-not-isystem.patch", + ], + version = "3.8.2.bcr.7", +) + +single_version_override( + module_name = "boost.icl", + patch_strip = 1, + patches = [ + "//patches/openroad-deps:0001-refactor-interval-lookup-operations-icl-54.patch", + ], +) + +single_version_override( + module_name = "gawk", + version = "5.3.2.bcr.7", +) + +# m4 and sed: same gnulib libc-header shadowing class as gawk/bison +# under hermetic-llvm (BCR #7642); these releases carry the fixes +# (sed via BCR #7915). +single_version_override( + module_name = "m4", + version = "1.4.21.bcr.4", +) + +single_version_override( + module_name = "sed", + version = "4.9.bcr.5", +) + +single_version_override( + module_name = "tcl_lang", + patch_strip = 1, + patches = [ + "//patches/openroad-deps:0001-tclZipfs-include-vendored-minizip-crypt.h-by-path.patch", + ], +) + bazel_dep(name = "qt-bazel", dev_dependency = True) git_override( module_name = "qt-bazel", @@ -36,7 +102,7 @@ git_override( bazel_dep(name = "bazel-orfs", dev_dependency = True) bazel_dep(name = "bazel-orfs-verilog", dev_dependency = True) -BAZEL_ORFS_COMMIT = "3a5ddd7eb48c363717e65903ae4573d528327fd3" +BAZEL_ORFS_COMMIT = "970ff81f19dc602b44bb017f97dcdbc70f58fd89" BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git" @@ -51,8 +117,8 @@ git_override( commit = BAZEL_ORFS_COMMIT, patch_strip = 1, patches = [ - "//patches/bazel-orfs:0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch", "//patches/bazel-orfs:0002-add-orfs_openroad_synth-rule-and-macro.patch", + "//patches/bazel-orfs:0003-add-orfs_canon_verilog-rule.patch", ], remote = BAZEL_ORFS_REMOTE, ) @@ -64,6 +130,32 @@ git_override( strip_prefix = "verilog", ) +# LEC (logic equivalence checking) rules wrapping kepler-formal. The +# expansion patch (build-time lec_check + instant status test + stage +# netlist extraction) is carried here until upstreamed to bazel-orfs. +bazel_dep(name = "bazel-orfs-lec", dev_dependency = True) +git_override( + module_name = "bazel-orfs-lec", + commit = BAZEL_ORFS_COMMIT, + patch_strip = 1, + patches = [ + "//patches/bazel-orfs:lec-0001-build-time-lec-check-and-netlist-extraction.patch", + ], + remote = BAZEL_ORFS_REMOTE, + strip_prefix = "lec", +) + +# kepler-formal is not on BCR yet (see its docs/bcr-roadmap.md). The lec +# module's own kepler-formal override points at a CI mock and is a no-op +# when it is not the root module, so the real, hermetically built (llvm +# zero-sysroot toolchain) kepler-formal is pinned here. +bazel_dep(name = "kepler-formal", dev_dependency = True) +git_override( + module_name = "kepler-formal", + commit = "6af0212097e737a2d843eedd524023f49bd77945", + remote = "https://github.com/keplertech/kepler-formal.git", +) + # yosys-slang is not on BCR. Pin to a commit on povik/yosys-slang master # that has the upstream Bazel build (povik/yosys-slang#310) and the # slang.so visibility fix (povik/yosys-slang#311). Submodules pull in @@ -78,20 +170,24 @@ git_override( # --- Extensions --- -llvm = use_extension( - "@toolchains_llvm//toolchain/extensions:llvm.bzl", - "llvm", +register_toolchains( + "@llvm//toolchain:all", dev_dependency = True, ) -llvm.toolchain( - llvm_version = "20.1.8", -) -use_repo(llvm, "llvm_toolchain") -register_toolchains( - "@llvm_toolchain//:all", +# sv-lang (via tools/OpenROAD) pulls in rules_pycross, whose toolchain +# extension fails on Python 3.8 (transitively registered via or-tools -> +# pybind11_abseil, dropped from rules_python 2.0.0's MINOR_MAPPING). +# pycross.configure_environments is root-honored only, so the workaround +# must be mirrored here from tools/OpenROAD/MODULE.bazel. +bazel_dep(name = "rules_pycross", version = "0.8.1", dev_dependency = True) + +pycross = use_extension( + "@rules_pycross//pycross/extensions:pycross.bzl", + "pycross", dev_dependency = True, ) +pycross.configure_environments(python_versions = ["3.13"]) python = use_extension("@rules_python//python/extensions:python.bzl", "python") python.toolchain( diff --git a/patches/bazel-orfs/0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch b/patches/bazel-orfs/0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch deleted file mode 100644 index c67b99cffa..0000000000 --- a/patches/bazel-orfs/0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 0010e181efa28210dbf7839e6e6131139cc705bd Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?=C3=98yvind=20Harboe?= -Date: Mon, 18 May 2026 00:06:14 +0200 -Subject: [PATCH] render_gds: monkey-patch PDK_CONFIGS instead of - gdsii_use_custom_config - -The addon's gdsii_use_custom_config=True branch in import_gdsii skips -initialising pdk_info and addon_dir, both of which are still used a -few lines later to resolve color_path -- so any non-default -layerstack YAML trips UnboundLocalError inside the addon. - -Patch the addon's PDK_CONFIGS dict at runtime instead, pointing the -selected PDK's config_path entry at our trimmed YAML. The else -branch then fires normally, pdk_info is set, color_path resolves, -and Path's absolute-RHS semantic makes addon_dir / Path(abs_path) -evaluate to the absolute path. ---- - tools/blendergds/render_gds.py | 12 ++++++++++-- - 1 file changed, 10 insertions(+), 2 deletions(-) - -diff --git a/tools/blendergds/render_gds.py b/tools/blendergds/render_gds.py -index cbe116c..b53da1e 100644 ---- a/tools/blendergds/render_gds.py -+++ b/tools/blendergds/render_gds.py -@@ -289,11 +289,19 @@ def main(): - # in seconds rather than 5-7 minutes + 16 GB RSS. No-op for - # PDKs without a preset and for designs whose full stack is - # already small enough. -+ # We can't go through the addon's `gdsii_use_custom_config = True` -+ # path: that branch in `import_gdsii` skips initialising -+ # `pdk_info` and `addon_dir`, both of which are still used -+ # afterwards to resolve `color_path` -- so a custom YAML trips -+ # `UnboundLocalError: pdk_info` inside the addon. Instead, -+ # monkey-patch PDK_CONFIGS[pdk]['config_path'] to point at the -+ # trimmed YAML (absolute path -- `addon_dir / Path("/abs")` -+ # evaluates to the absolute path in pathlib, so the else branch -+ # in the addon picks it up correctly). - trimmed = _trim_layerstack(addon, addon_root, args.pdk, tmp) - if trimmed is not None: - yaml_path, kept_layers, missing = trimmed -- bpy.context.scene.gdsii_use_custom_config = True -- bpy.context.scene.gdsii_config_path = str(yaml_path) -+ addon.PDK_CONFIGS.setdefault(args.pdk, {})["config_path"] = str(yaml_path) - _log_phase( - "layerstack-trimmed", - extra=( --- -2.51.0 - diff --git a/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch b/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch new file mode 100644 index 0000000000..9975649676 --- /dev/null +++ b/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch @@ -0,0 +1,59 @@ +diff --git a/canon_verilog.bzl b/canon_verilog.bzl +new file mode 100644 +index 000000000000..7e4446f9a47f +--- /dev/null ++++ b/canon_verilog.bzl +@@ -0,0 +1,53 @@ ++"""orfs_canon_verilog: pre-synthesis Verilog from the canonicalize RTLIL. ++ ++The synthesis canonicalize step (synth_canonicalize.tcl) writes ++1_1_yosys_canonicalize.rtlil: the design after elaboration and ++hierarchy/opt_clean, before any synthesis. Converting that checkpoint ++to Verilog gives a pre-synthesis gold netlist for LEC/SEC that has ++already been chewed through yosys' frontend — kepler-formal never sees ++the raw (System)Verilog edge cases, so an equivalence failure against ++the synthesized netlist implicates synthesis, not canonicalization. ++ ++`proc` and `memory_collect` only lower processes/memories to forms ++write_verilog can emit; they do not synthesize. ++""" ++ ++load("//private:attrs.bzl", "yosys_attrs") ++load("//private:environment.bzl", "yosys_environment", "yosys_inputs") ++ ++CANON_RTLIL = "1_1_yosys_canonicalize.rtlil" ++ ++def _canon_verilog_impl(ctx): ++ groups = ctx.attr.src[OutputGroupInfo] ++ if not hasattr(groups, CANON_RTLIL): ++ fail("{} does not provide a '{}' output group; src must be an orfs synth target".format( ++ ctx.attr.src.label, ++ CANON_RTLIL, ++ )) ++ rtlil = getattr(groups, CANON_RTLIL).to_list()[0] ++ ++ out = ctx.actions.declare_file("{}/{}".format(ctx.attr.name, "1_1_canonicalize.v")) ++ ctx.actions.run_shell( ++ command = '"$1" -q -p "read_rtlil $2; proc; memory_collect; write_verilog -noattr $3"', ++ arguments = [ctx.executable.yosys.path, rtlil.path, out.path], ++ env = yosys_environment(ctx), ++ inputs = depset([rtlil]), ++ outputs = [out], ++ tools = yosys_inputs(ctx), ++ mnemonic = "CanonVerilog", ++ progress_message = "Writing pre-synthesis Verilog %{label}", ++ ) ++ ++ return [DefaultInfo(files = depset([out]))] ++ ++orfs_canon_verilog = rule( ++ implementation = _canon_verilog_impl, ++ doc = """Converts an orfs synth target's canonicalize RTLIL checkpoint ++ to pre-synthesis Verilog (results in /1_1_canonicalize.v).""", ++ attrs = yosys_attrs() | { ++ "src": attr.label( ++ doc = "An orfs synth target (provides the {} output group).".format(CANON_RTLIL), ++ mandatory = True, ++ ), ++ }, ++) diff --git a/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch b/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch new file mode 100644 index 0000000000..d88a10e9ae --- /dev/null +++ b/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch @@ -0,0 +1,482 @@ +diff --git a/BUILD b/BUILD +index a235249896f2..dcceb93a6532 100644 +--- a/BUILD ++++ b/BUILD +@@ -1 +1,4 @@ +-exports_files(["lec.yaml.tpl"]) ++exports_files([ ++ "lec.yaml.tpl", ++ "write_netlist.tcl", ++]) +diff --git a/README.md b/README.md +index b8c5b27f5e08..fa2f19820db2 100644 +--- a/README.md ++++ b/README.md +@@ -1,13 +1,33 @@ + # Logic equivalence checking with kepler-formal + +-The `lec_test` rule wraps [kepler-formal](https://github.com/nicedayzhu/kepler-formal) +-for combinational logic equivalence checking (LEC) between gold (reference) and +-gate (modified) Verilog netlists. ++Rules wrapping [kepler-formal](https://github.com/keplertech/kepler-formal) ++for logic equivalence checking (LEC) between gold (reference) and gate ++(modified) Verilog netlists. + +-## Quick start ++## Quick start — build-time check + instant test (preferred) + + ```starlark +-load("//lec:lec.bzl", "lec_test") ++load("@bazel-orfs-lec//:lec.bzl", "lec") ++ ++lec( ++ name = "my_lec", ++ gold_verilog_files = [":canonicalized.v"], ++ gate_verilog_files = [":synth.v"], ++ liberty_files = ["//lib:cells.lib"], ++ verification = "sec", # RTL gold vs gate netlist ++) ++``` ++ ++`bazelisk build :my_lec` runs kepler-formal as a build action and records ++the verdict in `my_lec.status` (plus the full log). `bazelisk test ++:my_lec_test` only asserts the recorded verdict — instant, cached, immune ++to test timeouts on long SAT runs. Build the checks first (throttled with ++`--jobs=N`; SAT solving is memory-hungry), then run the tests. ++ ++## Quick start — test-time run ++ ++```starlark ++load("@bazel-orfs-lec//:lec.bzl", "lec_test") + + lec_test( + name = "my_lec_test", +@@ -16,10 +36,6 @@ lec_test( + ) + ``` + +-Run: +- +- bazelisk test :my_lec_test +- + ## Attributes + + | Attribute | Default | Description | +@@ -27,17 +43,44 @@ Run: + | `gold_verilog_files` | required | Gold (reference) Verilog files | + | `gate_verilog_files` | required | Gate (modified) Verilog files | + | `liberty_files` | `[]` | Liberty (.lib) files for cell definitions. Optional for RTL-to-RTL checks, required for post-synthesis gate netlists. | ++| `verification` | `"lec"` | `lec` (combinational) or `sec` (sequential; accepts pre-synthesis RTL gold vs gate netlist). `lec()`/`lec_check` only. | ++| `extra_config` | `[]` | Extra raw YAML lines appended to the kepler-formal config (e.g. `sec_engine: pdr`). `lec()`/`lec_check` only. | + | `log_level` | `"info"` | Log verbosity: `debug`, `info`, `warning`, `error` | + ++## Stage netlist extraction ++ ++`write_netlist.tcl` extracts a LEC-comparable Verilog netlist from an ORFS ++stage `.odb` (physical-only masters removed). Wire it with `orfs_run`: ++ ++```starlark ++load("@bazel-orfs//:openroad.bzl", "orfs_run") ++ ++orfs_run( ++ name = "gcd_floorplan_lec_v", ++ src = ":gcd_floorplan", ++ script = "@bazel-orfs-lec//:write_netlist.tcl", ++ outs = ["results/asap7/gcd/base/2_floorplan_lec.v"], ++) ++``` ++ ++The output is written as `_lec.v` in the stage's results ++directory. Hierarchical designs (`OPENROAD_HIERARCHICAL=1`) are read with ++`-hier` and produce hierarchical netlists. ++ + ## Requirements + +-kepler-formal operates on Verilog netlists and checks combinational ++With `verification = "lec"` (default), kepler-formal checks combinational + equivalence. The gold and gate netlists must satisfy: + + - **No sequential boundary changes** between gold and gate + - **No name changes** for hierarchical instances, sequential instances, or + top-level ports + ++`verification = "sec"` compares sequential behaviour through extracted ++transition systems and accepts pre-synthesis (RTL) Verilog for gold — ++internal names are not used as equivalence assumptions, but top terminal ++names must match. ++ + ## Temporary home + + This directory is hosted in bazel-orfs temporarily until the kepler-formal +diff --git a/lec.bzl b/lec.bzl +index f603baf15ea0..8294aa34bb20 100644 +--- a/lec.bzl ++++ b/lec.bzl +@@ -1,17 +1,231 @@ + """Rules for kepler-formal LEC (Logic Equivalence Checking). + +-Generates a config file from template, runs kepler-formal, and +-reports pass/fail as a Bazel test. ++Two usage styles: + +-kepler-formal operates on Verilog netlists and checks combinational +-equivalence. Sequential boundary changes are not supported. ++1. `lec_test`: runs kepler-formal at test time. Simple, but the ++ (potentially very long) SAT run re-executes whenever the test ++ re-runs and is subject to test timeouts. + +-Requirements for the input Verilog: ++2. `lec(name, ...)` macro: emits a build-time `lec_check` action that ++ runs kepler-formal during `bazel build`, records the verdict in ++ `.status` (plus the full log), and a `_test` ++ `lec_status_test` that only asserts the recorded verdict. The ++ expensive work caches like any other build artifact and the test is ++ instant, so wide `bazel test` sweeps do not time out. ++ ++kepler-formal operates on Verilog netlists. The default `lec` ++verification checks combinational equivalence: + - No change of sequential boundaries between gold and gate. + - No change in names of hierarchical instances, sequential instances, + and top terminals. ++`verification = "sec"` selects sequential equivalence checking, which ++also accepts pre-synthesis (RTL) Verilog for gold, compared against a ++gate netlist (RTL-vs-gate). + """ + ++LecInfo = provider( ++ "Recorded verdict of a build-time kepler-formal run.", ++ fields = { ++ "status": "File: one-line PASS/FAIL verdict", ++ "log": "File: full kepler-formal stdout/stderr", ++ "miter_log": "File: kepler-formal miter log (YAML log_file)", ++ }, ++) ++ ++def _lec_config(ctx, miter_log): ++ """Build the kepler-formal YAML config content.""" ++ lines = ["format: verilog"] ++ if ctx.attr.verification != "lec": ++ lines.append("verification: " + ctx.attr.verification) ++ lines.append("input_paths:") ++ lines.append( ++ " - [" + ", ".join([f.path for f in ctx.files.gold_verilog_files]) + "]", ++ ) ++ lines.append( ++ " - [" + ", ".join([f.path for f in ctx.files.gate_verilog_files]) + "]", ++ ) ++ if ctx.files.liberty_files: ++ lines.append("liberty_files:") ++ lines += [" - " + f.path for f in ctx.files.liberty_files] ++ lines.append("log_level: " + ctx.attr.log_level) ++ lines.append("log_file: " + miter_log.path) ++ lines += ctx.attr.extra_config ++ return "\n".join(lines) + "\n" ++ ++def _lec_check_impl(ctx): ++ config = ctx.actions.declare_file(ctx.attr.name + ".yaml") ++ log = ctx.actions.declare_file(ctx.attr.name + ".log") ++ miter_log = ctx.actions.declare_file(ctx.attr.name + ".miter.log") ++ status = ctx.actions.declare_file(ctx.attr.name + ".status") ++ ++ ctx.actions.write(config, _lec_config(ctx, miter_log)) ++ ++ # The action itself always succeeds: the kepler-formal verdict ++ # (exit code, or "Found difference" in the logs) is captured in the ++ # .status file so that failures are cached build artifacts asserted ++ # by lec_status_test, not build errors. ++ ctx.actions.run_shell( ++ command = """ ++set -u ++rc=0 ++"$1" --config "$2" > "$3" 2>&1 || rc=$? ++touch "$4" ++if [ "$rc" -eq 0 ] && ! grep -q "Found difference" "$3" "$4"; then ++ echo "PASS" > "$5" ++else ++ echo "FAIL (kepler-formal exit=$rc)" > "$5" ++fi ++""", ++ arguments = [ ++ ctx.executable._kepler_formal.path, ++ config.path, ++ log.path, ++ miter_log.path, ++ status.path, ++ ], ++ inputs = depset( ++ [config] + ++ ctx.files.gold_verilog_files + ++ ctx.files.gate_verilog_files + ++ ctx.files.liberty_files, ++ ), ++ outputs = [log, miter_log, status], ++ tools = [ctx.attr._kepler_formal[DefaultInfo].files_to_run], ++ mnemonic = "KeplerFormal", ++ progress_message = "LEC (kepler-formal) %{label}", ++ ) ++ ++ return [ ++ DefaultInfo(files = depset([status, log, miter_log, config])), ++ LecInfo(status = status, log = log, miter_log = miter_log), ++ ] ++ ++_LEC_IO_ATTRS = { ++ "gold_verilog_files": attr.label_list( ++ doc = "Gold (reference) Verilog files.", ++ allow_files = True, ++ providers = [DefaultInfo], ++ ), ++ "gate_verilog_files": attr.label_list( ++ doc = "Gate (modified) Verilog files.", ++ allow_files = True, ++ providers = [DefaultInfo], ++ ), ++ "liberty_files": attr.label_list( ++ doc = "Liberty (.lib) files for cell definitions. Optional for RTL-to-RTL checks.", ++ allow_files = True, ++ providers = [DefaultInfo], ++ default = [], ++ ), ++ "log_level": attr.string( ++ doc = "Log verbosity: debug, info, warning, error.", ++ default = "info", ++ ), ++ "_kepler_formal": attr.label( ++ doc = "kepler-formal binary.", ++ executable = True, ++ allow_files = True, ++ cfg = "exec", ++ default = Label("@kepler-formal//src/bin:kepler-formal"), ++ ), ++} ++ ++lec_check = rule( ++ implementation = _lec_check_impl, ++ doc = """Build-time logic equivalence check using kepler-formal. ++ ++ Runs kepler-formal as a (cacheable) build action and records the ++ verdict in `.status` alongside the full log. Pair with ++ lec_status_test (or use the lec() macro) to surface the verdict as ++ a test. ++ """, ++ attrs = _LEC_IO_ATTRS | { ++ "verification": attr.string( ++ doc = "Verification mode: lec (combinational) or sec (sequential; accepts RTL gold).", ++ default = "lec", ++ values = ["lec", "sec"], ++ ), ++ "extra_config": attr.string_list( ++ doc = "Extra raw YAML config lines appended to the generated kepler-formal " + ++ "config (e.g. 'sec_engine: pdr', 'solver: kissat').", ++ default = [], ++ ), ++ }, ++) ++ ++def _lec_status_test_impl(ctx): ++ info = ctx.attr.check[LecInfo] ++ script = ctx.actions.declare_file(ctx.attr.name + ".sh") ++ ctx.actions.write( ++ script, ++ """#!/bin/sh ++status="$(cat "{status}")" ++echo "{check}: $status" ++if [ "$status" = "PASS" ]; then ++ exit 0 ++fi ++echo "--- kepler-formal log (last 200 lines) ---" ++tail -n 200 "{log}" ++exit 1 ++""".format( ++ check = str(ctx.attr.check.label), ++ status = info.status.short_path, ++ log = info.log.short_path, ++ ), ++ is_executable = True, ++ ) ++ return [ ++ DefaultInfo( ++ executable = script, ++ runfiles = ctx.runfiles(files = [info.status, info.log]), ++ ), ++ ] ++ ++lec_status_test = rule( ++ implementation = _lec_status_test_impl, ++ doc = """Asserts that a lec_check recorded PASS. ++ ++ Instant: only reads the verdict recorded at build time, so LEC ++ results stay cached and wide test sweeps cannot time out on SAT ++ runtimes. ++ """, ++ attrs = { ++ "check": attr.label( ++ doc = "The lec_check whose verdict to assert.", ++ mandatory = True, ++ providers = [LecInfo], ++ ), ++ }, ++ test = True, ++) ++ ++def lec(name, tags = [], visibility = None, **kwargs): ++ """Build-time LEC with an instant verdict test. ++ ++ Emits `` (lec_check build target running kepler-formal) and ++ `_test` (lec_status_test asserting the recorded verdict). ++ ++ Args: ++ name: base name for the check/test pair. ++ tags: applied to both targets. ++ visibility: applied to both targets. ++ **kwargs: forwarded to lec_check (gold_verilog_files, ++ gate_verilog_files, liberty_files, verification, ++ extra_config, log_level). ++ """ ++ lec_check( ++ name = name, ++ tags = tags, ++ visibility = visibility, ++ **kwargs ++ ) ++ lec_status_test( ++ name = name + "_test", ++ check = ":" + name, ++ tags = tags, ++ visibility = visibility, ++ ) ++ + def _lec_test_impl(ctx): + # Generate kepler-formal YAML config + config = ctx.actions.declare_file(ctx.attr.name + ".yaml") +@@ -91,35 +305,10 @@ lec_test = rule( + + Compares gold (reference) and gate (modified) Verilog netlists for + combinational equivalence. Fails the test if any mismatch is found. ++ Runs kepler-formal at test time; prefer the lec() macro for ++ expensive checks so the SAT run caches as a build action. + """, +- attrs = { +- "gold_verilog_files": attr.label_list( +- doc = "Gold (reference) Verilog files.", +- allow_files = True, +- providers = [DefaultInfo], +- ), +- "gate_verilog_files": attr.label_list( +- doc = "Gate (modified) Verilog files.", +- allow_files = True, +- providers = [DefaultInfo], +- ), +- "liberty_files": attr.label_list( +- doc = "Liberty (.lib) files for cell definitions. Optional for RTL-to-RTL checks.", +- allow_files = True, +- providers = [DefaultInfo], +- default = [], +- ), +- "log_level": attr.string( +- doc = "Log verbosity: debug, info, warning, error.", +- default = "info", +- ), +- "_kepler_formal": attr.label( +- doc = "kepler-formal binary.", +- executable = True, +- allow_files = True, +- cfg = "exec", +- default = Label("@kepler-formal//src/bin:kepler-formal"), +- ), ++ attrs = _LEC_IO_ATTRS | { + "_config_template": attr.label( + default = "//:lec.yaml.tpl", + allow_single_file = True, +diff --git a/test/BUILD b/test/BUILD +new file mode 100644 +index 000000000000..3904dc6d9178 +--- /dev/null ++++ b/test/BUILD +@@ -0,0 +1,33 @@ ++"""lec module self-tests. ++ ++Run from the lec module root (`cd lec && bazelisk test //test/...`). ++With no kepler-formal override in play these exercise the rule wiring ++against the CI mock (../mock/kepler-formal), which always reports ++equivalence; point the kepler-formal module at a real checkout to turn ++them into true LEC runs. ++""" ++ ++load("//:lec.bzl", "lec", "lec_test") ++ ++# Test-time rule: kepler-formal runs inside the test action. ++lec_test( ++ name = "fixture_runtime_lec_test", ++ gate_verilog_files = ["gate.v"], ++ gold_verilog_files = ["gold.v"], ++) ++ ++# Build-time check + instant verdict test pairs: ++# fixture_lec/_test and fixture_sec/_test. ++lec( ++ name = "fixture_lec", ++ gate_verilog_files = ["gate.v"], ++ gold_verilog_files = ["gold.v"], ++) ++ ++lec( ++ name = "fixture_sec", ++ extra_config = ["sec_engine: pdr"], ++ gate_verilog_files = ["gate.v"], ++ gold_verilog_files = ["gold.v"], ++ verification = "sec", ++) +diff --git a/test/gate.v b/test/gate.v +new file mode 100644 +index 000000000000..74c71d152180 +--- /dev/null ++++ b/test/gate.v +@@ -0,0 +1,11 @@ ++// Equivalent gate fixture: same function, restructured expression. ++module top ( ++ input clk, ++ input a, ++ input b, ++ output reg y ++); ++ wire n1; ++ assign n1 = ~(~a | ~b); ++ always @(posedge clk) y <= n1; ++endmodule +diff --git a/test/gold.v b/test/gold.v +new file mode 100644 +index 000000000000..7586da2809cc +--- /dev/null ++++ b/test/gold.v +@@ -0,0 +1,9 @@ ++// Trivial gold netlist fixture: y = a & b, registered. ++module top ( ++ input clk, ++ input a, ++ input b, ++ output reg y ++); ++ always @(posedge clk) y <= a & b; ++endmodule +diff --git a/write_netlist.tcl b/write_netlist.tcl +new file mode 100644 +index 000000000000..f7a107aada09 +--- /dev/null ++++ b/write_netlist.tcl +@@ -0,0 +1,15 @@ ++# Writes a LEC-comparable Verilog netlist for an ORFS stage .odb. ++# ++# For use with bazel-orfs orfs_run(src = , script = this, ++# outs = ["results////_lec.v"]): open.tcl ++# reads $::env(ODB_FILE) (honouring OPENROAD_HIERARCHICAL via ++# hier_options), liberty is read so physical-only master detection can ++# tell filler/tap/decap cells from logic, and the netlist is written ++# with those masters removed so kepler-formal only sees logic. ++source $::env(SCRIPTS_DIR)/util.tcl ++source $::env(SCRIPTS_DIR)/read_liberty.tcl ++source $::env(SCRIPTS_DIR)/open.tcl ++ ++set stem [file rootname [file tail $::env(ODB_FILE)]] ++write_verilog -remove_cells [find_physical_only_masters] \ ++ $::env(RESULTS_DIR)/${stem}_lec.v diff --git a/patches/openroad-deps/0001-gnulib-wrapper-headers-use-I-not-isystem.patch b/patches/openroad-deps/0001-gnulib-wrapper-headers-use-I-not-isystem.patch new file mode 100644 index 0000000000..01d22abe77 --- /dev/null +++ b/patches/openroad-deps/0001-gnulib-wrapper-headers-use-I-not-isystem.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Oyvind Harboe +Date: Mon, 6 Jul 2026 00:00:00 +0000 +Subject: [PATCH] BUILD: let gnulib wrapper headers shadow libc via -I + +Gnulib generates wrapper headers (lib/stdio.h, lib/fcntl.h, ...) that +must be found before the libc ones; they forward with #include_next and +add gnulib decorations (_GL_ATTRIBUTE_DEALLOC etc.) that lib/*-safer.h +and src/*.c rely on. The overlay's 'includes = ["lib"]' emits -isystem, +which loses to toolchains that inject libc headers as earlier -isystem +entries (e.g. the zero-sysroot hermetic-llvm BCR toolchain), and a dir +listed as both -I and -isystem is kept as -isystem, so the -I must +replace it, not merely accompany it. + +Plain -I outranks every -isystem, restoring autotools' AM_CPPFLAGS = +-I./lib ordering. $(BINDIR) covers the generated wrappers, the source +path the checked-in ones. + +Same class of fix as sed@4.9.bcr.5 (BCR #7915) and gawk@5.3.2.bcr.7 +(BCR #7989); to be proposed upstream as bison@3.8.2.bcr.8. +--- +diff --git a/BUILD.bazel b/BUILD.bazel +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -711,7 +711,19 @@ + tags = ["manual"], + ) + +-BISON_COPTS = select({ ++# Gnulib's wrapper headers (generated lib/stdio.h, lib/fcntl.h, ... plus ++# the checked-in lib/*-safer.h helpers) must shadow the libc headers: they ++# forward via #include_next and add gnulib decorations ++# (_GL_ATTRIBUTE_DEALLOC etc.) that lib/ and src/ sources rely on. ++# `includes = ["lib"]` emits -isystem, which loses against toolchains that ++# inject libc headers as earlier -isystem entries (e.g. the zero-sysroot ++# hermetic-llvm BCR toolchain). Plain -I outranks every -isystem (and a dir ++# listed as both -I and -isystem stays -isystem, so the -isystem form must ++# go entirely). This restores autotools' AM_CPPFLAGS = -I./lib ordering. ++BISON_COPTS = [ ++ "-Iexternal/bison+/lib", ++ "-I$(BINDIR)/external/bison+/lib", ++] + select({ + "@rules_cc//cc/compiler:clang": [ + "-w", + "-std=c11", +@@ -813,7 +825,6 @@ + "src/scan-skel.c", + ":configmake_h_src", + ], +- includes = ["lib"], + textual_hdrs = [ + "lib/timevar.def", + "lib/printf-frexp.c", +@@ -997,6 +1008,7 @@ + "lib/main.c", + "lib/yyerror.c", + ], ++ copts = BISON_COPTS, + implementation_deps = [":headers"], + local_defines = LOCAL_DEFINES, + ) diff --git a/patches/openroad-deps/0001-mainUtils-flush-prompt-and-handle-eof-without-readline.patch b/patches/openroad-deps/0001-mainUtils-flush-prompt-and-handle-eof-without-readline.patch new file mode 100644 index 0000000000..03eb776d36 --- /dev/null +++ b/patches/openroad-deps/0001-mainUtils-flush-prompt-and-handle-eof-without-readline.patch @@ -0,0 +1,62 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Matt Liberty +Date: Fri, 30 May 2026 00:00:00 +0000 +Subject: [PATCH] mainUtils: match readline behavior when ABC_USE_READLINE is + undefined + +The non-readline branch of Abc_UtilsGetUsersInput has three behavioral +gaps versus the readline branch that break callers driving abc as a +coprocess over a pipe (e.g. yosys's techmap/abc.cc, which waits for the +"abc NN> " prompt with the source command echoed back via +read_until_abc_done()): + + 1. The prompt is written with fprintf() but never flushed. With stdout + fully buffered (pipe), the prompt never reaches the reader; the + reader waits for the prompt, abc waits in fgets(), deadlock. + + 2. There is no echo of the line read from stdin. readline() displays + each character as it is typed (and on a pipe, readline's stream + handling still emits the line + newline to its output). Without + that, yosys never sees the "abc NN> source ..." pattern it requires + to advance state. + + 3. EOF on stdin is silently ignored: fgets() returns NULL, the + function returns a stale Prompt buffer, and the caller loops. The + readline branch exits(0) when readline() returns NULL. + +Fix all three. Echo only when stdin is not a tty -- on a tty the kernel +already echoes typed characters, and double-echo would be visible. + +Upstreaming to YosysHQ/abc and berkeley-abc/abc. + +Signed-off-by: Matt Liberty +--- + src/base/main/mainUtils.c | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/src/base/main/mainUtils.c b/src/base/main/mainUtils.c +--- a/src/base/main/mainUtils.c ++++ b/src/base/main/mainUtils.c +@@ -18,6 +18,8 @@ + + ***********************************************************************/ + ++#include ++ + #include "base/abc/abc.h" + #include "mainInt.h" + +@@ -91,7 +93,13 @@ + { + char * pRetValue; + fprintf( pAbc->Out, "%s", Prompt ); ++ fflush( pAbc->Out ); + pRetValue = fgets( Prompt, 5000, stdin ); ++ if ( pRetValue == NULL ) { exit(0); } ++ if ( !isatty( fileno(stdin) ) ) { ++ fputs( Prompt, pAbc->Out ); ++ fflush( pAbc->Out ); ++ } + return Prompt; + } + #endif diff --git a/patches/openroad-deps/0001-refactor-interval-lookup-operations-icl-54.patch b/patches/openroad-deps/0001-refactor-interval-lookup-operations-icl-54.patch new file mode 100644 index 0000000000..0923bba655 --- /dev/null +++ b/patches/openroad-deps/0001-refactor-interval-lookup-operations-icl-54.patch @@ -0,0 +1,582 @@ +boost::icl's exclusive_less_than comparator violates strict weak +ordering (boostorg/icl#51), which libc++'s std::map exposes: +interval_set::operator-= subtracts only the first overlapping interval +and leaves phantom coverage (boostorg/icl#55). This is upstream commit +boostorg/icl@7de3f55655 ("Refactored interval lookup operations", #54), +merged after boost 1.90, trimmed to include/. Drop this patch when a +boost.icl release containing it lands in BCR. + +diff --git a/include/boost/icl/concept/element_associator.hpp b/include/boost/icl/concept/element_associator.hpp +index 98280ece..7c4cbfd3 100644 +--- a/include/boost/icl/concept/element_associator.hpp ++++ b/include/boost/icl/concept/element_associator.hpp +@@ -143,7 +143,7 @@ is_element_equal(const Type& left, const Type& right) + { return left == right; } + + +-/* Strict weak less ordering which is given by the Compare order */ ++/* Strict partial less ordering which is given by the Compare order */ + template + inline typename enable_if, bool>::type + operator < (const Type& left, const Type& right) +diff --git a/include/boost/icl/concept/interval.hpp b/include/boost/icl/concept/interval.hpp +index fab7dd99..3a1e69f9 100644 +--- a/include/boost/icl/concept/interval.hpp ++++ b/include/boost/icl/concept/interval.hpp +@@ -565,8 +565,10 @@ template + typename boost::enable_if, bool>::type + is_empty(const Type& object) + { +- return domain_less_equal(upper(object), lower(object) ) +- || domain_less_equal(upper(object), domain_next(lower(object))); ++ // we use ternary operator instead of || to prevent a codegen bug with GCC 10-11 ++ return domain_less_equal(upper(object), lower(object))? ++ true: ++ domain_less_equal(upper(object), domain_next(lower(object))); + } + + template +@@ -576,8 +578,10 @@ is_empty(const Type& object) + if(object.bounds() == interval_bounds::closed()) + return domain_less(upper(object), lower(object)); + else if(object.bounds() == interval_bounds::open()) +- return domain_less_equal(upper(object), lower(object) ) +- || domain_less_equal(upper(object), domain_next(lower(object))); ++ // we use ternary operator instead of || to prevent a codegen bug with GCC 10-11 ++ return domain_less_equal(upper(object), lower(object))? ++ true: ++ domain_less_equal(upper(object), domain_next(lower(object))); + else + return domain_less_equal(upper(object), lower(object)); + } +diff --git a/include/boost/icl/detail/assoc_container_adaptor.hpp b/include/boost/icl/detail/assoc_container_adaptor.hpp +new file mode 100644 +index 00000000..63e4975f +--- /dev/null ++++ b/include/boost/icl/detail/assoc_container_adaptor.hpp +@@ -0,0 +1,187 @@ ++/*-----------------------------------------------------------------------------+ ++Copyright (c) 2026: Joaquin M Lopez Munoz +++------------------------------------------------------------------------------+ ++ Distributed under the Boost Software License, Version 1.0. ++ (See accompanying file LICENCE.txt or copy at ++ http://www.boost.org/LICENSE_1_0.txt) +++-----------------------------------------------------------------------------*/ ++#ifndef BOOST_ICL_DETAIL_ASSOC_CONTAINER_ADAPTOR_HPP_JMLM_260320 ++#define BOOST_ICL_DETAIL_ASSOC_CONTAINER_ADAPTOR_HPP_JMLM_260320 ++ ++#include ++#include ++#include ++#include ++ ++namespace boost{namespace icl{namespace detail ++{ ++ ++/*-----------------------------------------------------------------------------+ ++| Interval comparison is generally a partial order rather than a strict weak | ++| order (SWO). This does not pose any problem with associative containers as | ++| long as the intervals in the container are disjoint, since the induced order | ++| restricted to those is a SWO (indeed, a total order). A difficulty may arise | ++| when doing a lookup operation for an interval k that overlaps with | ++| E = elements(container), as the induced order over {k} U E may not be a SWO. | ++| All stdlib implementations support this case except libc++ v22 or higher: | ++| https://github.com/llvm/llvm-project/issues/183189 | ++| https://github.com/boostorg/icl/issues/51 . | ++| Whether libc++'s behavior is conformant or not is contested, see | ++| https://github.com/llvm/llvm-project/issues/187667 , | ++| but, regardless, we can solve the problem by resorting to heterogeneous | ++| lookup. When k is of a type other than key_type and the compare predicate is | ++| transparent, lookup operations on k are defined by the standard in terms of | ++| elements being _partitioned_ by k, without any reference to SWO compliance. | ++| | ++| assoc_container_adaptor, in combination with transparent_compare, forces | ++| lookup operations on the adapted container to be routed through its | ++| heterogeneous lookup overloads, and does nothing for C++11 containers | ++| without het lookup. This circumvents libc++'s singular behavior except when | ++| in C++11 mode: in this case, we use Boost.Container, which supports het | ++| lookup even in C++11 (see impl_config.hpp). Insert functions are also | ++| provided that prevent UB when the element would violate SWO (this is UB | ++| regardless of the resolution of libc++'s issue). | ++| | ++| Additionally, Boost.ICL interval find functions are documented to return the | ++| _first_ eligible element, which is not guaranteed by std::(set|map)::find; | ++| assoc_container_adaptor fixes that. +++-----------------------------------------------------------------------------*/ ++ ++template ++struct transparent_compare: Compare ++{ ++ using is_transparent = void; ++ using super = Compare; ++ ++ using super::super; ++}; ++ ++template ++using assoc_container_is_set = std::is_same< ++ typename AssocContainer::key_type, typename AssocContainer::value_type>; ++ ++template ++using assoc_container_enable_if_is_input_iterator_t = ++ typename std::enable_if< ++ std::is_convertible< ++ typename std::iterator_traits::iterator_category, ++ std::input_iterator_tag ++ >::value ++ >::type; ++ ++template ++struct assoc_container_adaptor: AssocContainer ++{ ++ using key_type = typename AssocContainer::key_type; ++ using value_type = typename AssocContainer::value_type; ++ using size_type = typename AssocContainer::size_type; ++ using key_compare = typename AssocContainer::key_compare::super; ++ using iterator = typename AssocContainer::iterator; ++ using const_iterator = typename AssocContainer::const_iterator; ++ ++ using AssocContainer::AssocContainer; ++ ++ template< ++ typename InputIterator, ++ typename = assoc_container_enable_if_is_input_iterator_t ++ > ++ void insert(InputIterator first, InputIterator last) ++ { ++ while(first != last) insert(*first++); ++ } ++ ++ std::pair insert(const value_type& x) ++ { ++ auto it = lower_bound(key_from_value(x)); ++ if(it == AssocContainer::end() || AssocContainer::value_comp()(x, *it)) { ++ return {AssocContainer::insert(it, x), true}; ++ } ++ else { ++ return {it, false}; ++ } ++ } ++ ++ iterator insert(const_iterator pos, const value_type& x) ++ { ++ if((pos == AssocContainer::end() || AssocContainer::value_comp()(x, *pos)) && ++ (pos == AssocContainer::begin() || AssocContainer::value_comp()(*std::prev(pos), x))){ ++ return AssocContainer::insert(pos, x); ++ } ++ return insert(x).first; ++ } ++ ++ size_type count(const key_type& key) ++ { ++ return AssocContainer::count(std::cref(key)); ++ } ++ ++ size_type count(const key_type& key) const ++ { ++ return AssocContainer::count(std::cref(key)); ++ } ++ ++ iterator find(const key_type& key) ++ { ++ auto it = AssocContainer::lower_bound(std::cref(key)); ++ return ++ it == AssocContainer::end() || ++ AssocContainer::key_comp()(key, key_from_value(*it))? ++ AssocContainer::end(): it; ++ } ++ ++ const_iterator find(const key_type& key) const ++ { ++ return const_cast(this)->find(key); ++ } ++ ++ std::pair equal_range(const key_type& key) ++ { ++ return AssocContainer::equal_range(std::cref(key)); ++ } ++ ++ std::pair equal_range(const key_type& key) const ++ { ++ return AssocContainer::equal_range(std::cref(key)); ++ } ++ ++ iterator lower_bound(const key_type& key) ++ { ++ return AssocContainer::lower_bound(std::cref(key)); ++ } ++ ++ const_iterator lower_bound(const key_type& key) const ++ { ++ return AssocContainer::lower_bound(std::cref(key)); ++ } ++ ++ iterator upper_bound(const key_type& key) ++ { ++ return AssocContainer::upper_bound(std::cref(key)); ++ } ++ ++ const_iterator upper_bound(const key_type& key) const ++ { ++ return AssocContainer::upper_bound(std::cref(key)); ++ } ++ ++private: ++ template< ++ class IsSet = assoc_container_is_set, ++ typename std::enable_if::type* = nullptr> ++ static const key_type& key_from_value(const value_type& x) ++ { ++ return x; ++ } ++ ++ template< ++ class IsSet = assoc_container_is_set, ++ typename std::enable_if::type* = nullptr> ++ static const key_type& key_from_value(const value_type& x) ++ { ++ return x.first; ++ } ++}; ++ ++}}} // namespace detail icl boost ++ ++#endif +diff --git a/include/boost/icl/detail/element_iterator.hpp b/include/boost/icl/detail/element_iterator.hpp +index 6c06f494..d1f3c9e9 100644 +--- a/include/boost/icl/detail/element_iterator.hpp ++++ b/include/boost/icl/detail/element_iterator.hpp +@@ -8,11 +8,22 @@ Copyright (c) 2009-2009: Joachim Faulhaber + #ifndef BOOST_ICL_DETAIL_ELEMENT_ITERATOR_HPP_JOFA_091104 + #define BOOST_ICL_DETAIL_ELEMENT_ITERATOR_HPP_JOFA_091104 + ++#include + #include + #include + #include + #include + ++#if BOOST_CXX_VERSION >= 202002L ++#include ++#endif ++ ++namespace boost{namespace movelib{ ++ ++template class reverse_iterator; ++ ++}} // namespace movelib boost ++ + namespace boost{namespace icl + { + +@@ -62,6 +73,13 @@ struct is_reverse > + BOOST_STATIC_CONSTANT(bool, value = true); + }; + ++template ++struct is_reverse > ++{ ++ typedef is_reverse > type; ++ BOOST_STATIC_CONSTANT(bool, value = true); ++}; ++ + template + struct is_reverse > + { +@@ -333,6 +351,32 @@ class element_iterator + + }} // namespace icl boost + ++#if BOOST_CXX_VERSION >= 202002L ++// std::iter_value_t falls back to std::indirectly_readable_traits::value_type when ++// std::iterator_traits is not specialized, but std::indirectly_readable_traits is ++// ill-defined if It::value_type and It::element_type _both_ exist and are _not_ the same, which ++// is precisely the case for element_iterator. ++// Workaround is to specialize std::iterator_traits>. We do this ++// by deriving from std::iterator_traits>> so ++// that we don't have to revisit this ever even if more typedefs are added to std::iterator_traits ++// in future versions of the C++ standard. ++ ++namespace boost{namespace icl{namespace detail{ ++ ++template struct derived_wrapper: Class {}; ++ ++}}} // namespace detail icl boost ++ ++namespace std{ ++ ++template ++struct iterator_traits< ::boost::icl::element_iterator> : ++ iterator_traits< ::boost::icl::detail::derived_wrapper< ::boost::icl::element_iterator>> ++{}; ++ ++} // namespace std ++#endif ++ + #endif // BOOST_ICL_DETAIL_ELEMENT_ITERATOR_HPP_JOFA_091104 + + +diff --git a/include/boost/icl/detail/exclusive_less_than.hpp b/include/boost/icl/detail/exclusive_less_than.hpp +index 3a4aa650..fbdaa5f9 100644 +--- a/include/boost/icl/detail/exclusive_less_than.hpp ++++ b/include/boost/icl/detail/exclusive_less_than.hpp +@@ -17,7 +17,7 @@ namespace boost{ namespace icl + template + struct exclusive_less_than + { +- /** Operator operator() implements a strict weak ordering on intervals. */ ++ /** Operator operator() implements a strict partial ordering on intervals. */ + bool operator()(const IntervalT& left, const IntervalT& right)const + { + return icl::non_empty::exclusive_less(left, right); +diff --git a/include/boost/icl/detail/map_adaptor.hpp b/include/boost/icl/detail/map_adaptor.hpp +new file mode 100644 +index 00000000..790490ed +--- /dev/null ++++ b/include/boost/icl/detail/map_adaptor.hpp +@@ -0,0 +1,29 @@ ++/*-----------------------------------------------------------------------------+ ++Copyright (c) 2026: Joaquin M Lopez Munoz +++------------------------------------------------------------------------------+ ++ Distributed under the Boost Software License, Version 1.0. ++ (See accompanying file LICENCE.txt or copy at ++ http://www.boost.org/LICENSE_1_0.txt) +++-----------------------------------------------------------------------------*/ ++#ifndef BOOST_ICL_DETAIL_MAP_ADAPTOR_HPP_JMLM_260321 ++#define BOOST_ICL_DETAIL_MAP_ADAPTOR_HPP_JMLM_260321 ++ ++#include ++ ++#include ICL_IMPL_PATH(map) ++ ++// let boostdep know about this potential dependency hidden by ICL_IMPL_PATH ++#if 0 ++#include ++#endif ++ ++namespace boost{namespace icl{namespace detail ++{ ++ ++template ++using map_adaptor = assoc_container_adaptor< ++ ICL_IMPL_SPACE::map, Allocator>>; ++ ++}}} // namespace detail icl boost ++ ++#endif +diff --git a/include/boost/icl/detail/mapped_reference.hpp b/include/boost/icl/detail/mapped_reference.hpp +index 67f7d041..212059cb 100644 +--- a/include/boost/icl/detail/mapped_reference.hpp ++++ b/include/boost/icl/detail/mapped_reference.hpp +@@ -134,7 +134,7 @@ inline typename enable_if, bool>::type + operator == ( const StdPairT& left, + const mapped_reference& right) + { +- return right == left; ++ return right.operator ==(left); + } + + template +@@ -142,7 +142,7 @@ inline typename enable_if, bool>::type + operator != ( const StdPairT& left, + const mapped_reference& right) + { +- return !(right == left); ++ return !(right.operator ==(left)); + } + + //------------------------------------------------------------------------------ +diff --git a/include/boost/icl/detail/set_adaptor.hpp b/include/boost/icl/detail/set_adaptor.hpp +new file mode 100644 +index 00000000..2a44b8a5 +--- /dev/null ++++ b/include/boost/icl/detail/set_adaptor.hpp +@@ -0,0 +1,44 @@ ++/*-----------------------------------------------------------------------------+ ++Copyright (c) 2026: Joaquin M Lopez Munoz +++------------------------------------------------------------------------------+ ++ Distributed under the Boost Software License, Version 1.0. ++ (See accompanying file LICENCE.txt or copy at ++ http://www.boost.org/LICENSE_1_0.txt) +++-----------------------------------------------------------------------------*/ ++#ifndef BOOST_ICL_DETAIL_SET_ADAPTOR_HPP_JMLM_260321 ++#define BOOST_ICL_DETAIL_SET_ADAPTOR_HPP_JMLM_260321 ++ ++#include ++ ++#include ICL_IMPL_PATH(set) ++ ++// let boostdep know about this potential dependency hidden by ICL_IMPL_PATH ++#if 0 ++#include ++#endif ++ ++namespace boost{namespace icl{namespace detail ++{ ++ ++template ++struct set_adaptor: assoc_container_adaptor< ++ ICL_IMPL_SPACE::set, Allocator>> ++{ ++ using super = assoc_container_adaptor< ++ ICL_IMPL_SPACE::set, Allocator>>; ++ ++ using super::super; ++ ++ // Boost.ICL assumes set::iterator is the same type as set::const_iterator, ++ // which is not guaranteed generally and is certainly not the case for ++ // boost::container::set. We extend to reverse_iterator out of sympathy. ++ ++ using const_iterator = typename super::const_iterator; ++ using iterator = const_iterator; ++ using const_reverse_iterator = typename super::const_reverse_iterator; ++ using reverse_iterator = const_reverse_iterator; ++}; ++ ++}}} // namespace detail icl boost ++ ++#endif +diff --git a/include/boost/icl/impl_config.hpp b/include/boost/icl/impl_config.hpp +index 55297396..601d4bcc 100644 +--- a/include/boost/icl/impl_config.hpp ++++ b/include/boost/icl/impl_config.hpp +@@ -32,14 +32,19 @@ Copyright (c) 2009-2011: Joachim Faulhaber + | | + | NOTE: ICL_USE_BOOST_INTERPROCESS_IMPLEMENTATION: This define has been | + | available until boost version 1.48.0 and is no longer supported. | ++| | ++| NOTE: With libc++ v22 or higher in C++11, boost::container is used | ++| regardless of user indications. See assoc_container_adaptor.hpp for | ++| the rationale. | + +-----------------------------------------------------------------------------*/ + +-#if defined(ICL_USE_BOOST_MOVE_IMPLEMENTATION) ++#if defined(ICL_USE_BOOST_MOVE_IMPLEMENTATION) ||\ ++ (BOOST_CXX_VERSION < 201402L && defined(_LIBCPP_VERSION) && _LIBCPP_VERSION > 220000) + # define ICL_IMPL_SPACE boost::container +-#elif defined(ICL_USE_STD_IMPLEMENTATION) +-# define ICL_IMPL_SPACE std ++# define ICL_IMPL_PATH(header) + #else + # define ICL_IMPL_SPACE std ++# define ICL_IMPL_PATH(header)
+ #endif + + /*-----------------------------------------------------------------------------+ +diff --git a/include/boost/icl/interval_base_map.hpp b/include/boost/icl/interval_base_map.hpp +index f464a6a4..89555c7c 100644 +--- a/include/boost/icl/interval_base_map.hpp ++++ b/include/boost/icl/interval_base_map.hpp +@@ -19,6 +19,7 @@ Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin + #include + #include + #include ++#include + + #include + +@@ -145,8 +146,7 @@ class interval_base_map + allocator_type; + + /// Container type for the implementation +- typedef ICL_IMPL_SPACE::map ImplMapT; ++ typedef detail::map_adaptor ImplMapT; + + /// key type of the implementing container + typedef typename ImplMapT::key_type key_type; +diff --git a/include/boost/icl/interval_base_set.hpp b/include/boost/icl/interval_base_set.hpp +index d693bd43..a0b3968d 100644 +--- a/include/boost/icl/interval_base_set.hpp ++++ b/include/boost/icl/interval_base_set.hpp +@@ -11,14 +11,6 @@ Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin + + #include + +-#if defined(ICL_USE_BOOST_MOVE_IMPLEMENTATION) +-# include +-#elif defined(ICL_USE_STD_IMPLEMENTATION) +-# include +-#else // Default for implementing containers +-# include +-#endif +- + #include + #include + #include +@@ -30,6 +22,7 @@ Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin + #include + #include + #include ++#include + + #include + #include +@@ -116,7 +109,7 @@ class interval_base_set + typedef Alloc domain_allocator_type; + + /// Container type for the implementation +- typedef typename ICL_IMPL_SPACE::set ImplSetT; ++ typedef detail::set_adaptor ImplSetT; + + /// key type of the implementing container + typedef typename ImplSetT::key_type key_type; +diff --git a/include/boost/icl/map.hpp b/include/boost/icl/map.hpp +index 3877745d..8d67de1e 100644 +--- a/include/boost/icl/map.hpp ++++ b/include/boost/icl/map.hpp +@@ -10,16 +10,8 @@ Copyright (c) 2007-2011: Joachim Faulhaber + + #include + +-#if defined(ICL_USE_BOOST_MOVE_IMPLEMENTATION) +-# include +-# include +-#elif defined(ICL_USE_STD_IMPLEMENTATION) +-# include +-# include +-#else // Default for implementing containers +-# include +-# include +-#endif ++#include ++#include ICL_IMPL_PATH(set) + + #include + #include +@@ -89,14 +81,14 @@ template + ICL_SECTION Section = ICL_SECTION_INSTANCE(icl::inter_section, CodomainT), + ICL_ALLOC Alloc = std::allocator + > +-class map: private ICL_IMPL_SPACE::map > > + { + public: + typedef Alloc > allocator_type; + + typedef typename icl::map type; +- typedef typename ICL_IMPL_SPACE::map base_type; + + typedef Traits traits; +diff --git a/include/boost/icl/set.hpp b/include/boost/icl/set.hpp +index db44b5e8..aa1a68ed 100644 +--- a/include/boost/icl/set.hpp ++++ b/include/boost/icl/set.hpp +@@ -10,13 +10,7 @@ Copyright (c) 2007-2011: Joachim Faulhaber + + #include + +-#if defined(ICL_USE_BOOST_MOVE_IMPLEMENTATION) +-# include +-#elif defined(ICL_USE_STD_IMPLEMENTATION) +-# include +-#else +-# include +-#endif ++#include ICL_IMPL_PATH(set) + + #include + #include diff --git a/patches/openroad-deps/0001-tclZipfs-include-vendored-minizip-crypt.h-by-path.patch b/patches/openroad-deps/0001-tclZipfs-include-vendored-minizip-crypt.h-by-path.patch new file mode 100644 index 0000000000..11bf1388c8 --- /dev/null +++ b/patches/openroad-deps/0001-tclZipfs-include-vendored-minizip-crypt.h-by-path.patch @@ -0,0 +1,20 @@ +tclZipfs.c includes the vendored minizip crypt.h as #include "crypt.h", +relying on compat/zlib/contrib/minizip preceding any system directory +that also has a crypt.h. Hermetic toolchains that provide glibc headers +as explicit -isystem directories (e.g. the hermetic-llvm cc_toolchain) +search glibc's crypt.h (Unix password hashing) first, and the build +fails with implicit declarations of init_keys/decrypt_byte/zencode. +Include the intended header by its unambiguous path relative to the +compat/zlib include root instead. + +--- a/generic/tclZipfs.c ++++ b/generic/tclZipfs.c +@@ -75,7 +75,7 @@ + } while (0) + + #include "zlib.h" +-#include "crypt.h" ++#include "contrib/minizip/crypt.h" + #include "zutil.h" + #include "crc32.h" + diff --git a/patches/openroad-deps/BUILD.bazel b/patches/openroad-deps/BUILD.bazel new file mode 100644 index 0000000000..5591bbb098 --- /dev/null +++ b/patches/openroad-deps/BUILD.bazel @@ -0,0 +1,10 @@ +"""Mirrors of tools/OpenROAD/bazel/*-patches for single_version_override. + +single_version_override is only honored in the root module, and its +patches= labels must live in the main repository — so the dependency +fixes tools/OpenROAD carries for its own root builds are copied here +verbatim. Keep in sync with the submodule; drop each file when the fix +lands in a BCR release. +""" + +exports_files(glob(["*.patch"])) diff --git a/tools/OpenROAD b/tools/OpenROAD index d088e2269e..473d4b316a 160000 --- a/tools/OpenROAD +++ b/tools/OpenROAD @@ -1 +1 @@ -Subproject commit d088e2269e9530105882a6caad7b7a7f73f82c98 +Subproject commit 473d4b316a2f438894d13246a2795ca88d691094 From e62ae73a33ab76e89fa3071f4575da8abfab209d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Mon, 6 Jul 2026 23:23:51 +0200 Subject: [PATCH 05/11] flow: variables.yaml + design BUILD fixes for new bazel-orfs validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bazel-orfs bump validates orfs_flow sources= against variables.yaml and my LEC aggregates force-load every design package, surfacing latent gaps: - Declare IO_{NORTH,SOUTH,EAST,WEST}_PINS (ihp-sg13g2 pad.tcl) and ADDITIONAL_{FAST,SLOW,TYP}_LIBS (flow/Makefile corner libs) in variables.yaml; regenerate variables.json. - gf180/aes{,-hybrid}: DESIGN_TYPE (private-PDK DRC hook) via user_arguments; BC/TC/WC_ADDITIONAL_LIB_FILES make helpers via local_arguments. - microwatt, chameleon: VERILOG_FILES_BLACKBOX is source-typed, route through user_sources instead of local_arguments. Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Øyvind Harboe --- flow/designs/gf180/aes-hybrid/BUILD | 14 +++++++++- flow/designs/gf180/aes/BUILD | 7 ++++- flow/designs/sky130hd/chameleon/BUILD | 8 +++--- flow/designs/sky130hd/microwatt/BUILD | 12 ++++++--- flow/scripts/variables.json | 33 +++++++++++++++++++++++ flow/scripts/variables.yaml | 39 +++++++++++++++++++++++++++ 6 files changed, 104 insertions(+), 9 deletions(-) diff --git a/flow/designs/gf180/aes-hybrid/BUILD b/flow/designs/gf180/aes-hybrid/BUILD index 527d6542e1..4ff848a087 100644 --- a/flow/designs/gf180/aes-hybrid/BUILD +++ b/flow/designs/gf180/aes-hybrid/BUILD @@ -1,3 +1,15 @@ load("//flow/designs:design.bzl", "design") -design(config = "config.mk") +design( + config = "config.mk", + # BC/TC/WC_ADDITIONAL_LIB_FILES are pure make helpers expanded via + # $($(CORNER)_ADDITIONAL_LIB_FILES) within this config.mk only. + local_arguments = [ + "BC_ADDITIONAL_LIB_FILES", + "TC_ADDITIONAL_LIB_FILES", + "WC_ADDITIONAL_LIB_FILES", + ], + # DESIGN_TYPE is exported for private-PDK (gf12) DRC scripts and is + # not an ORFS flow variable; bypass variables.yaml validation. + user_arguments = ["DESIGN_TYPE"], +) diff --git a/flow/designs/gf180/aes/BUILD b/flow/designs/gf180/aes/BUILD index 527d6542e1..2585b0915d 100644 --- a/flow/designs/gf180/aes/BUILD +++ b/flow/designs/gf180/aes/BUILD @@ -1,3 +1,8 @@ load("//flow/designs:design.bzl", "design") -design(config = "config.mk") +design( + config = "config.mk", + # DESIGN_TYPE is exported for private-PDK (gf12) DRC scripts and is + # not an ORFS flow variable; bypass variables.yaml validation. + user_arguments = ["DESIGN_TYPE"], +) diff --git a/flow/designs/sky130hd/chameleon/BUILD b/flow/designs/sky130hd/chameleon/BUILD index 414ad64d62..c67c5a9d3d 100644 --- a/flow/designs/sky130hd/chameleon/BUILD +++ b/flow/designs/sky130hd/chameleon/BUILD @@ -4,13 +4,15 @@ load("//flow/designs:design.bzl", "design") # by ORFS itself — route them through user_arguments so the validator # doesn't reject them as unknown ORFS variables. # -# VERILOG_FILES_BLACKBOX is a config.mk-local helper: only used via -# $(VERILOG_FILES_BLACKBOX) expansion inside VERILOG_FILES. +# VERILOG_FILES_BLACKBOX is a config.mk-local, source-typed helper: +# only used via $(VERILOG_FILES_BLACKBOX) expansion inside +# VERILOG_FILES. The new bazel-orfs validates sources too, so route it +# through user_sources. design( config = "config.mk", user_arguments = [ "FP_PDN_RAIL_OFFSET", "FP_PDN_RAIL_WIDTH", ], - local_arguments = ["VERILOG_FILES_BLACKBOX"], + user_sources = ["VERILOG_FILES_BLACKBOX"], ) diff --git a/flow/designs/sky130hd/microwatt/BUILD b/flow/designs/sky130hd/microwatt/BUILD index a375309357..a26ba222f7 100644 --- a/flow/designs/sky130hd/microwatt/BUILD +++ b/flow/designs/sky130hd/microwatt/BUILD @@ -1,6 +1,10 @@ load("//flow/designs:design.bzl", "design") -# VERILOG_FILES_BLACKBOX is a config.mk-local helper: only used via -# $(VERILOG_FILES_BLACKBOX) expansion inside VERILOG_FILES. Not read by -# ORFS or by any user .tcl/.mk — drop it so it never reaches orfs_flow. -design(config = "config.mk", local_arguments = ["VERILOG_FILES_BLACKBOX"]) +# VERILOG_FILES_BLACKBOX is a config.mk-local, source-typed helper: +# only used via $(VERILOG_FILES_BLACKBOX) expansion inside +# VERILOG_FILES. The new bazel-orfs validates sources too, so route it +# through user_sources. +design( + config = "config.mk", + user_sources = ["VERILOG_FILES_BLACKBOX"], +) diff --git a/flow/scripts/variables.json b/flow/scripts/variables.json index 369ed53179..b5d98e2da9 100644 --- a/flow/scripts/variables.json +++ b/flow/scripts/variables.json @@ -36,6 +36,9 @@ "synth" ] }, + "ADDITIONAL_FAST_LIBS": { + "description": "Fast-corner counterparts of ADDITIONAL_LIBS, appended to the FC corner's LIB_FILES (see flow/Makefile and e.g. the ihp-sg13g2 platform config.mk).\n" + }, "ADDITIONAL_FILES": { "description": "Additional files to be added to `make issue` archive.\n" }, @@ -57,6 +60,12 @@ "floorplan" ] }, + "ADDITIONAL_SLOW_LIBS": { + "description": "Slow-corner counterparts of ADDITIONAL_LIBS, appended to the WC corner's LIB_FILES (see flow/Makefile and e.g. the ihp-sg13g2 platform config.mk).\n" + }, + "ADDITIONAL_TYP_LIBS": { + "description": "Typical-corner counterparts of ADDITIONAL_LIBS, appended to the TC corner's LIB_FILES (see flow/Makefile and e.g. the ihp-sg13g2 platform config.mk).\n" + }, "ASAP7_USE_VT": { "default": "RVT", "description": "A space separated list of VT options to use with the ASAP7 standard cell library: RVT, LVT, SLVT.\n", @@ -432,6 +441,18 @@ "floorplan" ] }, + "IO_EAST_PINS": { + "description": "Pad instance names placed on the east (IO_EAST) pad row by platform pad-ring scripts (e.g. ihp-sg13g2 pad.tcl via place_pads).\n", + "stages": [ + "floorplan" + ] + }, + "IO_NORTH_PINS": { + "description": "Pad instance names placed on the north (IO_NORTH) pad row by platform pad-ring scripts (e.g. ihp-sg13g2 pad.tcl via place_pads).\n", + "stages": [ + "floorplan" + ] + }, "IO_PLACER_H": { "description": "A list of metal layers on which the I/O pins are placed horizontally (top and bottom of the die).\n", "stages": [ @@ -444,6 +465,18 @@ "place" ] }, + "IO_SOUTH_PINS": { + "description": "Pad instance names placed on the south (IO_SOUTH) pad row by platform pad-ring scripts (e.g. ihp-sg13g2 pad.tcl via place_pads).\n", + "stages": [ + "floorplan" + ] + }, + "IO_WEST_PINS": { + "description": "Pad instance names placed on the west (IO_WEST) pad row by platform pad-ring scripts (e.g. ihp-sg13g2 pad.tcl via place_pads).\n", + "stages": [ + "floorplan" + ] + }, "IR_DROP_LAYER": { "description": "Default metal layer to report IR drop.\n" }, diff --git a/flow/scripts/variables.yaml b/flow/scripts/variables.yaml index 6eee57b4c2..43937f7e52 100644 --- a/flow/scripts/variables.yaml +++ b/flow/scripts/variables.yaml @@ -949,6 +949,21 @@ ADDITIONAL_LIBS: description: > Hardened macro library files listed here. The library information is immutable and used throughout all stages. Not stored in the .odb file. +ADDITIONAL_FAST_LIBS: + description: > + Fast-corner counterparts of ADDITIONAL_LIBS, appended to the FC + corner's LIB_FILES (see flow/Makefile and e.g. the ihp-sg13g2 + platform config.mk). +ADDITIONAL_SLOW_LIBS: + description: > + Slow-corner counterparts of ADDITIONAL_LIBS, appended to the WC + corner's LIB_FILES (see flow/Makefile and e.g. the ihp-sg13g2 + platform config.mk). +ADDITIONAL_TYP_LIBS: + description: > + Typical-corner counterparts of ADDITIONAL_LIBS, appended to the TC + corner's LIB_FILES (see flow/Makefile and e.g. the ihp-sg13g2 + platform config.mk). ADDITIONAL_GDS: description: | Hardened macro GDS files listed here. @@ -1467,6 +1482,30 @@ FOOTPRINT_TCL: Specifies a Tcl script with custom footprint-related commands for floorplan setup. stages: - floorplan +IO_NORTH_PINS: + description: > + Pad instance names placed on the north (IO_NORTH) pad row by + platform pad-ring scripts (e.g. ihp-sg13g2 pad.tcl via place_pads). + stages: + - floorplan +IO_SOUTH_PINS: + description: > + Pad instance names placed on the south (IO_SOUTH) pad row by + platform pad-ring scripts (e.g. ihp-sg13g2 pad.tcl via place_pads). + stages: + - floorplan +IO_EAST_PINS: + description: > + Pad instance names placed on the east (IO_EAST) pad row by + platform pad-ring scripts (e.g. ihp-sg13g2 pad.tcl via place_pads). + stages: + - floorplan +IO_WEST_PINS: + description: > + Pad instance names placed on the west (IO_WEST) pad row by + platform pad-ring scripts (e.g. ihp-sg13g2 pad.tcl via place_pads). + stages: + - floorplan FLOW_VARIANT: description: > Flow variant to use, used in the flow variant directory name. From 3a2efd665b63ac1e8622003feac20d554121f276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Mon, 6 Jul 2026 23:23:51 +0200 Subject: [PATCH 06/11] flow: per-design, per-stage kepler-formal LEC targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every design gets manual-tagged equivalence checks that run at build time (cached lec_check actions) with instant verdict tests: - _lec_synth: canonicalized RTL (yosys canonicalize checkpoint -> _canon_v) vs the yosys netlist, SEC via kepler-formal's pre-synthesis .v support. kepler-formal never parses raw (System)Verilog, so a failure implicates synthesis, not canonicalization. - _lec_: adjacent-pair gate-level LEC synth<->floorplan<-> place<->cts<->route<->final on netlists written from each stage odb (physical-only cells removed; -hier for OPENROAD_HIERARCHICAL). - _syn_lec_synth (flat designs): OpenROAD built-in synth netlist vs the same canonicalized RTL. - //flow:lec_check + //flow:lec_test aggregates; single-corner _lec_libs liberty sets; README documents build-then-test and --jobs throttling. - _emit_syn_variant: split user/local config.mk vars out of DESIGNS entries so variables.yaml validation only sees ORFS variables. Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Øyvind Harboe --- flow/BUILD | 40 ++++++++ flow/README.md | 27 ++++++ flow/designs/design.bzl | 203 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 264 insertions(+), 6 deletions(-) diff --git a/flow/BUILD b/flow/BUILD index c3f0599758..49ec7f0bcd 100644 --- a/flow/BUILD +++ b/flow/BUILD @@ -1,4 +1,5 @@ load("@bazel-orfs//:openroad.bzl", "orfs_pdk") +load("//flow/designs:design.bzl", "lec_check_targets", "lec_test_targets") # Expose every individual file under platforms/ as a public source-file # target, so designs in other packages can refer to e.g. @@ -173,3 +174,42 @@ filegroup( "sky130hd", "sky130hs", ]] + +# Single-corner (typical) liberty sets per platform for kepler-formal +# LEC: kepler-formal needs cell definitions, not timing corners, and +# feeding it the same cells at several corners would double-define +# them. Design-specific macro libs come in via ADDITIONAL_LIBS (see +# lec_liberty in flow/designs/design.bzl). +[filegroup( + name = pdk + "_lec_libs", + srcs = glob(patterns), + visibility = ["//visibility:public"], +) for pdk, patterns in { + "asap7": ["platforms/asap7/lib/NLDM/*_TT_*.lib*"], + "gf180": ["platforms/gf180/lib/*__tt_025C_5v00.lib.gz"], + "ihp-sg13g2": ["platforms/ihp-sg13g2/lib/*_typ_*.lib"], + "nangate45": ["platforms/nangate45/lib/*.lib"], + "sky130hd": ["platforms/sky130hd/lib/*.lib"], + "sky130hs": ["platforms/sky130hs/lib/*tt_025C_1v80.lib"], +}.items()] + +# LEC (kepler-formal) aggregates over every design and stage; all +# constituents are tagged `manual` so wildcards skip them. Build the +# checks first (this is where the SAT solving happens; throttle with +# --jobs=N), then run the instant verdict tests: +# +# bazelisk build //flow:lec_check --jobs=4 +# bazelisk test //flow:lec_test +filegroup( + name = "lec_check", + srcs = lec_check_targets(), + tags = ["manual"], + visibility = ["//visibility:public"], +) + +test_suite( + name = "lec_test", + tags = ["manual"], + tests = lec_test_targets(), + visibility = ["//visibility:public"], +) diff --git a/flow/README.md b/flow/README.md index 9c4f2ff678..934d101bab 100644 --- a/flow/README.md +++ b/flow/README.md @@ -56,3 +56,30 @@ the generated targets get `tags = ["manual"]`. Each OpenROAD invocation takes `-threads `. A wildcard `bazelisk test` runs designs in parallel and overcommits the host. Cap with `--jobs=N`. + +## Logic equivalence checking (LEC) + +Every design gets per-stage +[kepler-formal](https://github.com/keplertech/kepler-formal) +equivalence checks, all tagged `manual`: + +| Target | Checks | +|---|---| +| `_lec_synth` | Canonicalized RTL (`_canon_v`, written from the yosys canonicalize checkpoint) vs the yosys synthesis netlist — SEC, using kepler-formal's pre-synthesis `.v` support. A failure implicates synthesis, not canonicalization. | +| `_lec_` | Adjacent-pair gate-level LEC along the flow: synth↔floorplan, floorplan↔place, place↔cts, cts↔route, route↔final, on netlists written from each stage's `.odb` (physical-only cells removed). | +| `_syn_lec_synth` | Flat designs only: the OpenROAD built-in synth (`_syn` variant) netlist vs the same canonicalized RTL. | + +Each check runs kepler-formal at **build** time (`lec_check`; the +verdict and log are cached build artifacts) and pairs with an instant +`_test` that only asserts the recorded verdict, so `bazelisk +test` sweeps never time out on SAT runtimes. Build first — SAT solving +is memory-hungry, so cap parallelism per the section above — then run +the tests: + +```bash +bazelisk build //flow:lec_check --jobs=4 # or individual _lec_* targets +bazelisk test //flow:lec_test +``` + +Hierarchical designs (`OPENROAD_HIERARCHICAL=1`) are read with `-hier` +and produce hierarchical netlists. diff --git a/flow/designs/design.bzl b/flow/designs/design.bzl index cc1fa5abd0..a9e93556cb 100644 --- a/flow/designs/design.bzl +++ b/flow/designs/design.bzl @@ -1,6 +1,8 @@ """BUILD boilerplate for flow/designs/.""" -load("@bazel-orfs//:openroad.bzl", "orfs_flow", "orfs_openroad_synth") +load("@bazel-orfs//:canon_verilog.bzl", "orfs_canon_verilog") +load("@bazel-orfs//:openroad.bzl", "orfs_flow", "orfs_openroad_synth", "orfs_run") +load("@bazel-orfs-lec//:lec.bzl", "lec") load("@orfs_designs//:designs.bzl", "DESIGNS", "orfs_design") # Per filegroup target: extensions included in the filegroup. @@ -77,7 +79,13 @@ def design(config = "config.mk", user_arguments = [], user_sources = [], local_a local_arguments = local_arguments, blender = True, ) - _emit_syn_variant(DESIGNS.get(_design_key())) + _emit_lec(DESIGNS.get(_design_key())) + _emit_syn_variant( + DESIGNS.get(_design_key()), + user_arguments, + user_sources, + local_arguments, + ) def files(group, extra_srcs = None): """Named filegroup over conventional extensions. @@ -111,7 +119,143 @@ def _design_key(): return "" return "{}/{}".format(parts[-2], parts[-1]) -def _emit_syn_variant(entry): +# Stages whose .odb gets a LEC netlist extracted, with the .odb stem. +# Adjacent pairs are compared: synth<->floorplan, floorplan<->place, ... +LEC_STAGES = [ + ("synth", "1_synth"), + ("floorplan", "2_floorplan"), + ("place", "3_place"), + ("cts", "4_cts"), + ("route", "5_route"), + ("final", "6_final"), +] + +def lec_liberty(entry): + """Liberty inputs for kepler-formal: one-corner PDK libs + design macros.""" + return ["//flow:{}_lec_libs".format(entry["platform"])] + \ + entry["sources"].get("ADDITIONAL_LIBS", []) + +def _lec_design_keys(): + """DESIGNS keys that correspond to design packages. + + Filters out + - BLOCKS sub-flow entries (`_`), which live in + the parent's package, and + - nickname aliases: config_mk_parser indexes a design both by + directory name and by DESIGN_NICKNAME when they differ (e.g. + nangate45/black_parrot vs nangate45/bp). The entries are + identical, only the directory key is a real bazel package; of + each identical pair the longer key is the directory one + (nicknames abbreviate). + - designs without VERILOG_FILES (e.g. asap7/minimal), whose BUILD + files skip design() so no flow targets exist. + """ + skip = {} + for key, entry in DESIGNS.items(): + if not entry.get("verilog_files"): + skip[key] = True + for key, entry in DESIGNS.items(): + for block in entry.get("blocks", []): + skip[key + "_" + block] = True + for key, entry in DESIGNS.items(): + if key in skip: + continue + for other, other_entry in DESIGNS.items(): + if other == key or other in skip: + continue + if entry == other_entry and len(other) > len(key): + skip[key] = True + break + return [key for key in DESIGNS.keys() if key not in skip] + +def lec_check_targets(): + """Labels of all per-design lec_check targets (//flow:lec_check).""" + labels = [] + for key in _lec_design_keys(): + entry = DESIGNS[key] + package = "//flow/designs/" + key + name = entry["name"] + labels.append("{}:{}_lec_synth".format(package, name)) + for stage, _ in LEC_STAGES[1:]: + labels.append("{}:{}_lec_{}".format(package, name, stage)) + if not entry.get("blocks"): + labels.append("{}:{}_syn_lec_synth".format(package, name)) + return labels + +def lec_test_targets(): + """Labels of all per-design LEC verdict tests (//flow:lec_test).""" + return [label + "_test" for label in lec_check_targets()] + +def _emit_lec(entry): + """Emit kepler-formal LEC targets for `entry` from DESIGNS. + + Per design (all tagged `manual`; see flow/README.md): + - `_canon_v`: pre-synthesis Verilog written from the yosys + canonicalize RTLIL checkpoint. Using the post-canonicalization + netlist as SEC gold means kepler-formal never parses the raw + (System)Verilog sources — a failure implicates synthesis, not + canonicalization. + - `_lec_synth` + `_test`: SEC of canonicalized RTL vs the + yosys synthesis netlist (kepler-formal pre-synthesis .v + support). + - `__lec_v`: per-stage netlist written by OpenROAD from + the stage .odb (physical-only cells removed; hierarchical for + OPENROAD_HIERARCHICAL designs). + - `_lec_` + `_test` for floorplan/place/cts/route/final: + adjacent-pair gate-level LEC along the flow. + + LEC runs at `bazel build` time (cacheable lec_check actions); the + `_test` targets only assert the recorded verdict. + """ + if entry == None: + return + name = entry["name"] + liberty = lec_liberty(entry) + results_dir = "results/{}/{}/base".format(entry["platform"], name) + + orfs_canon_verilog( + name = name + "_canon_v", + src = ":" + name + "_synth", + tags = ["manual"], + visibility = ["//visibility:public"], + ) + native.filegroup( + name = name + "_yosys_v", + srcs = [":" + name + "_synth"], + output_group = "1_2_yosys.v", + tags = ["manual"], + ) + lec( + name = name + "_lec_synth", + gate_verilog_files = [":" + name + "_yosys_v"], + gold_verilog_files = [":" + name + "_canon_v"], + liberty_files = liberty, + tags = ["manual"], + verification = "sec", + visibility = ["//visibility:public"], + ) + + previous = None + for stage, stem in LEC_STAGES: + orfs_run( + name = "{}_{}_lec_v".format(name, stage), + src = ":{}_{}".format(name, stage), + script = "@bazel-orfs-lec//:write_netlist.tcl", + outs = ["{}/{}_lec.v".format(results_dir, stem)], + tags = ["manual"], + ) + if previous: + lec( + name = "{}_lec_{}".format(name, stage), + gate_verilog_files = [":{}_{}_lec_v".format(name, stage)], + gold_verilog_files = [":{}_{}_lec_v".format(name, previous)], + liberty_files = liberty, + tags = ["manual"], + visibility = ["//visibility:public"], + ) + previous = stage + +def _emit_syn_variant(entry, user_arguments = [], user_sources = [], local_arguments = []): """Emit the `_syn` variant chain for `entry` from DESIGNS. Adds `_syn_synth` (built-in OpenROAD synth, driven by @@ -122,6 +266,11 @@ def _emit_syn_variant(entry): built-in synthesizer doesn't handle BLOCKS yet and those would just fail. Flat designs pick the variant up for free. + Project-specific config.mk vars (design()'s user_arguments / + user_sources / local_arguments) are split out of the DESIGNS entry + the same way orfs_design does, so orfs_flow's variables.yaml + validation only sees real ORFS variables. + All emitted targets are tagged `manual` so `bazel build //...` does not pick them up while the OpenROAD synth tool (PR #10473) matures. @@ -130,14 +279,33 @@ def _emit_syn_variant(entry): return name = entry["name"] pdk = "//flow:" + entry["platform"] - syn_args = dict(entry["arguments"]) + syn_args = { + k: v + for k, v in entry["arguments"].items() + if k not in user_arguments and k not in local_arguments + } + syn_user_args = { + k: v + for k, v in entry["arguments"].items() + if k in user_arguments + } + syn_sources = { + k: v + for k, v in entry["sources"].items() + if k not in user_sources and k not in local_arguments + } + syn_user_sources = { + k: v + for k, v in entry["sources"].items() + if k in user_sources + } syn_synth = name + "_syn_synth" orfs_openroad_synth( name = syn_synth, module_top = name, verilog_files = entry["verilog_files"], sources = entry["sources"], - arguments = syn_args, + arguments = syn_args | syn_user_args, pdk = pdk, variant = "syn", tags = ["manual"], @@ -146,10 +314,33 @@ def _emit_syn_variant(entry): name = name, variant = "syn", verilog_files = entry["verilog_files"], - sources = entry["sources"], + sources = syn_sources, + user_sources = syn_user_sources, arguments = syn_args, + user_arguments = syn_user_args, pdk = pdk, previous_stage = {"floorplan": ":" + syn_synth}, tags = ["manual"], test_kwargs = {"tags": ["orfs", "manual"]}, ) + + # Pre-synthesis SEC of the built-in synth netlist against the yosys + # canonicalized RTL (`_canon_v` from _emit_lec): both synthesizers + # are checked against the same canonicalization, so a `_syn` failure + # with a passing `_lec_synth` implicates the built-in synthesis. + orfs_run( + name = name + "_syn_synth_lec_v", + src = ":" + syn_synth, + script = "@bazel-orfs-lec//:write_netlist.tcl", + outs = ["results/{}/{}/syn/1_synth_lec.v".format(entry["platform"], name)], + tags = ["manual"], + ) + lec( + name = name + "_syn_lec_synth", + gate_verilog_files = [":" + name + "_syn_synth_lec_v"], + gold_verilog_files = [":" + name + "_canon_v"], + liberty_files = lec_liberty(entry), + tags = ["manual"], + verification = "sec", + visibility = ["//visibility:public"], + ) From 5b60907b034c71c086b1dcb4b48fcef70fe1f754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 7 Jul 2026 00:12:48 +0200 Subject: [PATCH 07/11] flow: sv2v format + pmuxtree for pre-synthesis LEC gold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First real kepler-formal runs on gcd/asap7 surfaced two issues with the canonicalized-RTL gold: - format: verilog uses naja's structural netlist parser, which rejects behavioral constructs (reg declarations, always blocks). Add a format attr to lec_check and use sv2v for the pre-synthesis checks: gold goes through the SystemVerilog (slang) frontend, gate through the netlist parser. - yosys write_verilog renders $pmux as a Verilog function, which naja's lowering rejects in continuous assigns. pmuxtree in orfs_canon_verilog lowers $pmux to plain mux trees first. With these, gcd pre-synthesis SEC passes: 'No difference was found. SEC proved equivalence at k = 3', 100% checked-output coverage. Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Øyvind Harboe --- flow/designs/design.bzl | 5 +++++ .../0003-add-orfs_canon_verilog-rule.patch | 13 ++++++++----- ...ld-time-lec-check-and-netlist-extraction.patch | 15 +++++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/flow/designs/design.bzl b/flow/designs/design.bzl index a9e93556cb..f09bf730e1 100644 --- a/flow/designs/design.bzl +++ b/flow/designs/design.bzl @@ -227,6 +227,10 @@ def _emit_lec(entry): ) lec( name = name + "_lec_synth", + # sv2v: the behavioral canonicalized gold goes through the + # SystemVerilog frontend, the gate netlist through the Verilog + # netlist parser. + format = "sv2v", gate_verilog_files = [":" + name + "_yosys_v"], gold_verilog_files = [":" + name + "_canon_v"], liberty_files = liberty, @@ -337,6 +341,7 @@ def _emit_syn_variant(entry, user_arguments = [], user_sources = [], local_argum ) lec( name = name + "_syn_lec_synth", + format = "sv2v", gate_verilog_files = [":" + name + "_syn_synth_lec_v"], gold_verilog_files = [":" + name + "_canon_v"], liberty_files = lec_liberty(entry), diff --git a/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch b/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch index 9975649676..42718f2489 100644 --- a/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch +++ b/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch @@ -1,9 +1,9 @@ diff --git a/canon_verilog.bzl b/canon_verilog.bzl new file mode 100644 -index 000000000000..7e4446f9a47f +index 000000000000..41abf4d610ae --- /dev/null +++ b/canon_verilog.bzl -@@ -0,0 +1,53 @@ +@@ -0,0 +1,56 @@ +"""orfs_canon_verilog: pre-synthesis Verilog from the canonicalize RTLIL. + +The synthesis canonicalize step (synth_canonicalize.tcl) writes @@ -14,8 +14,11 @@ index 000000000000..7e4446f9a47f +the raw (System)Verilog edge cases, so an equivalence failure against +the synthesized netlist implicates synthesis, not canonicalization. + -+`proc` and `memory_collect` only lower processes/memories to forms -+write_verilog can emit; they do not synthesize. ++proc/pmuxtree/memory_collect only lower processes, parallel muxes ++and memories to forms write_verilog can emit (and kepler-formal's ++SystemVerilog frontend can lower: $pmux would be written as a Verilog ++function, which naja does not support in continuous assigns); they do ++not synthesize. +""" + +load("//private:attrs.bzl", "yosys_attrs") @@ -34,7 +37,7 @@ index 000000000000..7e4446f9a47f + + out = ctx.actions.declare_file("{}/{}".format(ctx.attr.name, "1_1_canonicalize.v")) + ctx.actions.run_shell( -+ command = '"$1" -q -p "read_rtlil $2; proc; memory_collect; write_verilog -noattr $3"', ++ command = '"$1" -q -p "read_rtlil $2; proc; pmuxtree; memory_collect; write_verilog -noattr $3"', + arguments = [ctx.executable.yosys.path, rtlil.path, out.path], + env = yosys_environment(ctx), + inputs = depset([rtlil]), diff --git a/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch b/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch index d88a10e9ae..736ae6cfee 100644 --- a/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch +++ b/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch @@ -109,10 +109,10 @@ index b8c5b27f5e08..fa2f19820db2 100644 This directory is hosted in bazel-orfs temporarily until the kepler-formal diff --git a/lec.bzl b/lec.bzl -index f603baf15ea0..8294aa34bb20 100644 +index f603baf15ea0..93fa1287b34c 100644 --- a/lec.bzl +++ b/lec.bzl -@@ -1,17 +1,231 @@ +@@ -1,17 +1,238 @@ """Rules for kepler-formal LEC (Logic Equivalence Checking). -Generates a config file from template, runs kepler-formal, and @@ -154,7 +154,7 @@ index f603baf15ea0..8294aa34bb20 100644 + +def _lec_config(ctx, miter_log): + """Build the kepler-formal YAML config content.""" -+ lines = ["format: verilog"] ++ lines = ["format: " + ctx.attr.format] + if ctx.attr.verification != "lec": + lines.append("verification: " + ctx.attr.verification) + lines.append("input_paths:") @@ -265,6 +265,13 @@ index f603baf15ea0..8294aa34bb20 100644 + default = "lec", + values = ["lec", "sec"], + ), ++ "format": attr.string( ++ doc = "Input format: verilog (netlist parser both sides), sv2v (gold through " + ++ "the SystemVerilog frontend, gate as Verilog netlist; required for " + ++ "behavioral/pre-synthesis gold and implies sec), or systemverilog.", ++ default = "verilog", ++ values = ["verilog", "sv2v", "systemverilog"], ++ ), + "extra_config": attr.string_list( + doc = "Extra raw YAML config lines appended to the generated kepler-formal " + + "config (e.g. 'sec_engine: pdr', 'solver: kissat').", @@ -349,7 +356,7 @@ index f603baf15ea0..8294aa34bb20 100644 def _lec_test_impl(ctx): # Generate kepler-formal YAML config config = ctx.actions.declare_file(ctx.attr.name + ".yaml") -@@ -91,35 +305,10 @@ lec_test = rule( +@@ -91,35 +312,10 @@ lec_test = rule( Compares gold (reference) and gate (modified) Verilog netlists for combinational equivalence. Fails the test if any mismatch is found. From c732be49b053035176a7d13e1305216778dda231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 7 Jul 2026 00:51:56 +0200 Subject: [PATCH 08/11] flow: default pre-synthesis SEC to the pdr engine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The legacy engine was inconclusive on uart after 28 minutes at k=32; pdr proves the same check at k=1 in seconds. Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Øyvind Harboe --- flow/designs/design.bzl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flow/designs/design.bzl b/flow/designs/design.bzl index f09bf730e1..37f88ffc75 100644 --- a/flow/designs/design.bzl +++ b/flow/designs/design.bzl @@ -227,6 +227,9 @@ def _emit_lec(entry): ) lec( name = name + "_lec_synth", + # pdr: the default (legacy) SEC engine was inconclusive on uart + # after 28min at k=32; pdr proves it at k=1 in seconds. + extra_config = ["sec_engine: pdr"], # sv2v: the behavioral canonicalized gold goes through the # SystemVerilog frontend, the gate netlist through the Verilog # netlist parser. @@ -341,6 +344,7 @@ def _emit_syn_variant(entry, user_arguments = [], user_sources = [], local_argum ) lec( name = name + "_syn_lec_synth", + extra_config = ["sec_engine: pdr"], format = "sv2v", gate_verilog_files = [":" + name + "_syn_synth_lec_v"], gold_verilog_files = [":" + name + "_canon_v"], From 4792f895a0ca6d980f5b4a945f2229d2991f5334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 7 Jul 2026 01:12:26 +0200 Subject: [PATCH 09/11] flow: memory_map in orfs_canon_verilog so ROM/memory init survives naja MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit yosys write_verilog emits memory/ROM init as 'initial' blocks, which kepler-formal's naja lowering rejects (aes sbox/rcon ROMs, ibex decoder table). memory_map lowers ROMs to logic and memories to FF arrays — the same fate synthesis gives them — so the pre-synthesis gold stays within the supported subset. Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Øyvind Harboe --- .../0003-add-orfs_canon_verilog-rule.patch | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch b/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch index 42718f2489..ebe4c41056 100644 --- a/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch +++ b/patches/bazel-orfs/0003-add-orfs_canon_verilog-rule.patch @@ -1,9 +1,9 @@ diff --git a/canon_verilog.bzl b/canon_verilog.bzl new file mode 100644 -index 000000000000..41abf4d610ae +index 000000000000..29bb6e786ccf --- /dev/null +++ b/canon_verilog.bzl -@@ -0,0 +1,56 @@ +@@ -0,0 +1,60 @@ +"""orfs_canon_verilog: pre-synthesis Verilog from the canonicalize RTLIL. + +The synthesis canonicalize step (synth_canonicalize.tcl) writes @@ -14,11 +14,15 @@ index 000000000000..41abf4d610ae +the raw (System)Verilog edge cases, so an equivalence failure against +the synthesized netlist implicates synthesis, not canonicalization. + -+proc/pmuxtree/memory_collect only lower processes, parallel muxes -+and memories to forms write_verilog can emit (and kepler-formal's -+SystemVerilog frontend can lower: $pmux would be written as a Verilog -+function, which naja does not support in continuous assigns); they do -+not synthesize. ++proc/pmuxtree/memory_collect/memory_map only lower processes, ++parallel muxes and memories to forms write_verilog can emit and ++kepler-formal's SystemVerilog frontend can lower; they do not ++synthesize: ++ - $pmux would be written as a Verilog function, which naja does not ++ support in continuous assigns (pmuxtree). ++ - memory/ROM init would be written as 'initial' blocks, which naja ++ does not lower (memory_map turns ROMs into logic and memories into ++ FF arrays, matching what synthesis does to them). +""" + +load("//private:attrs.bzl", "yosys_attrs") @@ -37,7 +41,7 @@ index 000000000000..41abf4d610ae + + out = ctx.actions.declare_file("{}/{}".format(ctx.attr.name, "1_1_canonicalize.v")) + ctx.actions.run_shell( -+ command = '"$1" -q -p "read_rtlil $2; proc; pmuxtree; memory_collect; write_verilog -noattr $3"', ++ command = '"$1" -q -p "read_rtlil $2; proc; pmuxtree; memory_collect; memory_map; write_verilog -noattr $3"', + arguments = [ctx.executable.yosys.path, rtlil.path, out.path], + env = yosys_environment(ctx), + inputs = depset([rtlil]), From 6d8fbf194ba98f41b9ce5c06f43c28a87f2c9796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 7 Jul 2026 01:24:41 +0200 Subject: [PATCH 10/11] flow: gate side of pre-synthesis SEC from 1_synth.odb, not 1_2_yosys.v MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SYNTH_WRAPPED_OPERATORS keeps unused adder-architecture modules in the yosys netlist, leaving kepler-formal's top inference with multiple roots ('No top design was found' on ibex, mock-alu). The OpenROAD-written netlist from 1_synth.odb has only the linked design, also covers the ODB import, and matches every later stage's gate side. With this, mock-alu pre-synthesis SEC passes. Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Øyvind Harboe --- flow/designs/design.bzl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/flow/designs/design.bzl b/flow/designs/design.bzl index 37f88ffc75..4d4d88b052 100644 --- a/flow/designs/design.bzl +++ b/flow/designs/design.bzl @@ -219,12 +219,6 @@ def _emit_lec(entry): tags = ["manual"], visibility = ["//visibility:public"], ) - native.filegroup( - name = name + "_yosys_v", - srcs = [":" + name + "_synth"], - output_group = "1_2_yosys.v", - tags = ["manual"], - ) lec( name = name + "_lec_synth", # pdr: the default (legacy) SEC engine was inconclusive on uart @@ -234,7 +228,12 @@ def _emit_lec(entry): # SystemVerilog frontend, the gate netlist through the Verilog # netlist parser. format = "sv2v", - gate_verilog_files = [":" + name + "_yosys_v"], + # The gate side is the OpenROAD-written netlist from 1_synth.odb + # rather than 1_2_yosys.v: linking drops unused modules (e.g. + # SYNTH_WRAPPED_OPERATORS adder variants), which would otherwise + # leave kepler-formal's top inference with multiple roots. It + # also covers the ODB import, and matches every later stage. + gate_verilog_files = [":" + name + "_synth_lec_v"], gold_verilog_files = [":" + name + "_canon_v"], liberty_files = liberty, tags = ["manual"], From 7ff1f96248acbd12918f68f2dc1158acf911fe8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 7 Jul 2026 01:26:18 +0200 Subject: [PATCH 11/11] flow: record SEC checked-output coverage next to the LEC verdict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit aes proved 'equivalence' with 0.78% output coverage (128/129 outputs skipped as design0 multi-driver connectivity) — a PASS that skips most outputs is much weaker than a full proof, so lec_check now records the coverage line in the .status artifact and lec_status_test accepts the annotated verdict. Co-Authored-By: Claude Opus 4.8 (1M context) Signed-off-by: Øyvind Harboe --- ...ime-lec-check-and-netlist-extraction.patch | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch b/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch index 736ae6cfee..39a954ccc7 100644 --- a/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch +++ b/patches/bazel-orfs/lec-0001-build-time-lec-check-and-netlist-extraction.patch @@ -109,10 +109,10 @@ index b8c5b27f5e08..fa2f19820db2 100644 This directory is hosted in bazel-orfs temporarily until the kepler-formal diff --git a/lec.bzl b/lec.bzl -index f603baf15ea0..93fa1287b34c 100644 +index f603baf15ea0..5cad3a02e8f6 100644 --- a/lec.bzl +++ b/lec.bzl -@@ -1,17 +1,238 @@ +@@ -1,17 +1,244 @@ """Rules for kepler-formal LEC (Logic Equivalence Checking). -Generates a config file from template, runs kepler-formal, and @@ -190,10 +190,14 @@ index f603baf15ea0..93fa1287b34c 100644 +rc=0 +"$1" --config "$2" > "$3" 2>&1 || rc=$? +touch "$4" ++# SEC reports checked-output coverage; a PASS that skipped most ++# outputs is much weaker than a full proof, so record it next to the ++# verdict. ++cov="$(grep -o "checked-output coverage: [0-9.]*% ([0-9/]* covered/existing outputs)" "$3" | tail -n 1)" +if [ "$rc" -eq 0 ] && ! grep -q "Found difference" "$3" "$4"; then -+ echo "PASS" > "$5" ++ echo "PASS${cov:+ ($cov)}" > "$5" +else -+ echo "FAIL (kepler-formal exit=$rc)" > "$5" ++ echo "FAIL (kepler-formal exit=$rc)${cov:+ ($cov)}" > "$5" +fi +""", + arguments = [ @@ -288,9 +292,11 @@ index f603baf15ea0..93fa1287b34c 100644 + """#!/bin/sh +status="$(cat "{status}")" +echo "{check}: $status" -+if [ "$status" = "PASS" ]; then ++case "$status" in ++PASS*) + exit 0 -+fi ++ ;; ++esac +echo "--- kepler-formal log (last 200 lines) ---" +tail -n 200 "{log}" +exit 1 @@ -356,7 +362,7 @@ index f603baf15ea0..93fa1287b34c 100644 def _lec_test_impl(ctx): # Generate kepler-formal YAML config config = ctx.actions.declare_file(ctx.attr.name + ".yaml") -@@ -91,35 +312,10 @@ lec_test = rule( +@@ -91,35 +318,10 @@ lec_test = rule( Compares gold (reference) and gate (modified) Verilog netlists for combinational equivalence. Fails the test if any mismatch is found.