|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?=C3=98yvind=20Harboe?= <oyvind.harboe@zylin.com> |
| 3 | +Date: Thu, 16 Jul 2026 16:14:51 +0200 |
| 4 | +Subject: [PATCH 1/4] synth: support OpenROAD-SYN engine (SYNTH_USE_SYN=1) and |
| 5 | + declare 1_synth.json |
| 6 | + |
| 7 | +SYNTH_USE_SYN=1 in the merged arguments switches the synthesis stage from |
| 8 | +the yosys flow to OpenROAD's built-in synthesizer: a single do-1_synth |
| 9 | +action (synth_syn.tcl) consuming the staged Verilog sources directly. |
| 10 | +Yosys canonicalization outputs are stubbed (lint-mode precedent) so the |
| 11 | +provider tail is engine-agnostic. Parallel/hierarchical yosys synthesis |
| 12 | +vars are ignored in SYN mode, matching the Makefile. |
| 13 | + |
| 14 | +Also declare logs/1_synth.json (written by flow.sh's openroad -metrics) |
| 15 | +in both engine modes and surface it via LoggingInfo.jsons: without it, |
| 16 | +generate_metadata never saw any synth__* metrics and metadata-check |
| 17 | +failed on rules-base.json's synth rules. |
| 18 | + |
| 19 | +orfs_test: honor the existing cmd attr instead of hardcoding |
| 20 | +metadata-check. |
| 21 | + |
| 22 | +Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> |
| 23 | +--- |
| 24 | + private/rules.bzl | 176 ++++++++++++++++++++++++++++++++++------------ |
| 25 | + 1 file changed, 131 insertions(+), 45 deletions(-) |
| 26 | + |
| 27 | +diff --git a/private/rules.bzl b/private/rules.bzl |
| 28 | +index 2c77c53..00925d4 100644 |
| 29 | +--- a/private/rules.bzl |
| 30 | ++++ b/private/rules.bzl |
| 31 | +@@ -573,8 +573,9 @@ if [ ! -e external ]; then |
| 32 | + # Needed as of Bazel >= 8 |
| 33 | + ln -sf $(realpath $(pwd)/..) external |
| 34 | + fi |
| 35 | +-{make} --file {makefile} {moreargs} metadata-check |
| 36 | ++{make} --file {makefile} {moreargs} {cmd} |
| 37 | + """.format( |
| 38 | ++ cmd = ctx.attr.cmd, |
| 39 | + make = ctx.executable._make.short_path, |
| 40 | + makefile = ctx.file._makefile.path, |
| 41 | + moreargs = environment_string( |
| 42 | +@@ -744,9 +745,14 @@ orfs_run_executable = rule( |
| 43 | + |
| 44 | + CANON_OUTPUT = "1_1_yosys_canonicalize.rtlil" |
| 45 | + SYNTH_OUTPUTS = ["1_2_yosys.v", "1_2_yosys.sdc", "1_synth.sdc", "mem.json"] |
| 46 | ++ |
| 47 | ++# Outputs of the OpenROAD-SYN synthesis flow (SYNTH_USE_SYN=1). synth_syn.tcl |
| 48 | ++# always writes the ODB, the canonicalized SDC and a gate-level Verilog |
| 49 | ++# netlist (LEC input); none of the yosys-flow files exist in this mode. |
| 50 | ++SYN_OUTPUTS = ["1_synth.odb", "1_synth.sdc", "1_synth.v"] |
| 51 | + SYNTH_REPORTS = ["synth_stat.txt", "synth_mocked_memories.txt"] |
| 52 | + |
| 53 | +-def _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, synth_reports, num_partitions, save_odb, all_arguments = {}): |
| 54 | ++def _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, synth_jsons, synth_reports, num_partitions, save_odb, all_arguments = {}): |
| 55 | + """Parallel synthesis: keep → kept-json → N partitions → merge. |
| 56 | + |
| 57 | + Yosys is not deterministic when using host threads, so SYNTH_NUM_PARTITIONS |
| 58 | +@@ -1101,7 +1107,12 @@ def _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, |
| 59 | + if save_odb: |
| 60 | + odb_commands = [_make_cmd(ctx)] + generation_commands( |
| 61 | + [synth_outputs["1_synth.odb"]], |
| 62 | +- ) |
| 63 | ++ ) + [ |
| 64 | ++ # flow.sh writes logs/1_synth.json during do-1_synth; guarantee a |
| 65 | ++ # parseable declared output either way (genMetrics json.load()s it). |
| 66 | ++ "[ -s {p} ] || echo '{{}}' > {p}".format(p = f.path) |
| 67 | ++ for f in synth_jsons |
| 68 | ++ ] |
| 69 | + ctx.actions.run_shell( |
| 70 | + arguments = [ |
| 71 | + "--file", |
| 72 | +@@ -1123,7 +1134,7 @@ def _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, |
| 73 | + deps_inputs(ctx), |
| 74 | + ], |
| 75 | + ), |
| 76 | +- outputs = [synth_outputs["1_synth.odb"], synth_outputs["1_synth.sdc"]], |
| 77 | ++ outputs = [synth_outputs["1_synth.odb"], synth_outputs["1_synth.sdc"]] + synth_jsons, |
| 78 | + tools = yosys_and_flow_tools, |
| 79 | + ) |
| 80 | + |
| 81 | +@@ -1152,41 +1163,55 @@ def _yosys_impl(ctx): |
| 82 | + ), |
| 83 | + ) |
| 84 | + |
| 85 | ++ # Engine selection: SYNTH_USE_SYN=1 in the merged arguments switches the |
| 86 | ++ # synthesis stage from the yosys flow to OpenROAD's built-in synthesizer |
| 87 | ++ # (the Makefile's synth_syn path). Analysis-time only: the value must |
| 88 | ++ # come through arguments/stage_arguments, not extra_arguments .json files. |
| 89 | ++ use_syn = all_arguments.get("SYNTH_USE_SYN") == "1" |
| 90 | ++ |
| 91 | + canon_logs = declare_artifacts(ctx, "logs", ["1_1_yosys_canonicalize.log"]) |
| 92 | + |
| 93 | + canon_output = declare_artifact(ctx, "results", CANON_OUTPUT) |
| 94 | + |
| 95 | +- # SYNTH_NETLIST_FILES will not create an .rtlil file or reports, so we need |
| 96 | +- # an empty placeholder in that case. |
| 97 | +- commands = [_make_cmd(ctx)] + generation_commands( |
| 98 | +- canon_logs + [canon_output], |
| 99 | +- ) |
| 100 | ++ if use_syn: |
| 101 | ++ # OpenROAD-SYN has no yosys canonicalization; stub its outputs |
| 102 | ++ # (lint-mode precedent) so the provider/deploy tail below is |
| 103 | ++ # identical in both engine modes. genMetrics.py treats the empty |
| 104 | ++ # RTLIL like a missing file when hashing. |
| 105 | ++ for f in canon_logs + [canon_output]: |
| 106 | ++ ctx.actions.write(output = f, content = "") |
| 107 | ++ else: |
| 108 | ++ # SYNTH_NETLIST_FILES will not create an .rtlil file or reports, so we need |
| 109 | ++ # an empty placeholder in that case. |
| 110 | ++ commands = [_make_cmd(ctx)] + generation_commands( |
| 111 | ++ canon_logs + [canon_output], |
| 112 | ++ ) |
| 113 | + |
| 114 | +- ctx.actions.run_shell( |
| 115 | +- arguments = [ |
| 116 | +- "--file", |
| 117 | +- ctx.file._makefile_yosys.path, |
| 118 | +- "yosys-dependencies", |
| 119 | +- "do-yosys-canonicalize", |
| 120 | +- ], |
| 121 | +- command = EXPAND_VERILOG_DIRS + " && ".join(commands), |
| 122 | +- env = config_overrides( |
| 123 | +- ctx, |
| 124 | +- verilog_arguments(ctx.files.verilog_files) | |
| 125 | +- yosys_environment(ctx) | |
| 126 | +- config_environment(config), |
| 127 | +- ), |
| 128 | +- inputs = depset( |
| 129 | +- [config] + ctx.files.verilog_files + ctx.files.extra_configs, |
| 130 | +- transitive = [ |
| 131 | +- data_inputs(ctx), |
| 132 | +- pdk_inputs(ctx), |
| 133 | +- deps_inputs(ctx), |
| 134 | ++ ctx.actions.run_shell( |
| 135 | ++ arguments = [ |
| 136 | ++ "--file", |
| 137 | ++ ctx.file._makefile_yosys.path, |
| 138 | ++ "yosys-dependencies", |
| 139 | ++ "do-yosys-canonicalize", |
| 140 | + ], |
| 141 | +- ), |
| 142 | +- outputs = [canon_output] + canon_logs, |
| 143 | +- tools = yosys_inputs(ctx), |
| 144 | +- ) |
| 145 | ++ command = EXPAND_VERILOG_DIRS + " && ".join(commands), |
| 146 | ++ env = config_overrides( |
| 147 | ++ ctx, |
| 148 | ++ verilog_arguments(ctx.files.verilog_files) | |
| 149 | ++ yosys_environment(ctx) | |
| 150 | ++ config_environment(config), |
| 151 | ++ ), |
| 152 | ++ inputs = depset( |
| 153 | ++ [config] + ctx.files.verilog_files + ctx.files.extra_configs, |
| 154 | ++ transitive = [ |
| 155 | ++ data_inputs(ctx), |
| 156 | ++ pdk_inputs(ctx), |
| 157 | ++ deps_inputs(ctx), |
| 158 | ++ ], |
| 159 | ++ ), |
| 160 | ++ outputs = [canon_output] + canon_logs, |
| 161 | ++ tools = yosys_inputs(ctx), |
| 162 | ++ ) |
| 163 | + |
| 164 | + num_partitions = int(all_arguments.get("SYNTH_NUM_PARTITIONS", "0")) |
| 165 | + if num_partitions == 0 and all_arguments.get("SYNTH_KEEP_MODULES"): |
| 166 | +@@ -1194,31 +1219,92 @@ def _yosys_impl(ctx): |
| 167 | + # when NUM_CPUS-based auto-detection hasn't run (direct orfs_synth call). |
| 168 | + kept_count = len(all_arguments["SYNTH_KEEP_MODULES"].split(" ")) |
| 169 | + num_partitions = max(1, kept_count) |
| 170 | ++ if use_syn: |
| 171 | ++ # Parallel/hierarchical synthesis is a yosys-flow concept; the |
| 172 | ++ # Makefile's SYNTH_USE_SYN path ignores SYNTH_KEEP_MODULES and |
| 173 | ++ # SYNTH_NUM_PARTITIONS (e.g. asap7/swerv_wrapper carries both |
| 174 | ++ # with SYNTH_USE_SYN=1), so never take the partitioned branch. |
| 175 | ++ num_partitions = 0 |
| 176 | + |
| 177 | + save_odb = ctx.attr.save_odb |
| 178 | +- |
| 179 | +- synth_logs = declare_artifacts(ctx, "logs", ["1_2_yosys.log", "1_2_yosys_metrics.log"] + (["1_synth.log"] if save_odb else [])) |
| 180 | +- |
| 181 | +- synth_outputs = {} |
| 182 | +- for output in SYNTH_OUTPUTS + (["1_synth.odb"] if save_odb else []): |
| 183 | +- synth_outputs[output] = declare_artifact(ctx, "results", output) |
| 184 | ++ if use_syn and not save_odb: |
| 185 | ++ fail("SYNTH_USE_SYN=1 always writes 1_synth.odb; save_odb=False is " + |
| 186 | ++ "not supported in " + str(ctx.label)) |
| 187 | ++ |
| 188 | ++ # logs/1_synth.json: metrics that flow.sh's `openroad -metrics` writes |
| 189 | ++ # during do-1_synth. Declared so generate_metadata (which merges |
| 190 | ++ # logs/1_*.json via genMetrics.py) sees the synth__* metrics. |
| 191 | ++ if use_syn: |
| 192 | ++ synth_logs = declare_artifacts(ctx, "logs", ["1_synth.log"]) |
| 193 | ++ synth_jsons = declare_artifacts(ctx, "logs", ["1_synth.json"]) |
| 194 | ++ synth_outputs = {o: declare_artifact(ctx, "results", o) for o in SYN_OUTPUTS} |
| 195 | ++ else: |
| 196 | ++ synth_logs = declare_artifacts(ctx, "logs", ["1_2_yosys.log", "1_2_yosys_metrics.log"] + (["1_synth.log"] if save_odb else [])) |
| 197 | ++ synth_jsons = declare_artifacts(ctx, "logs", ["1_synth.json"] if save_odb else []) |
| 198 | ++ synth_outputs = {} |
| 199 | ++ for output in SYNTH_OUTPUTS + (["1_synth.odb"] if save_odb else []): |
| 200 | ++ synth_outputs[output] = declare_artifact(ctx, "results", output) |
| 201 | + |
| 202 | + synth_reports = declare_artifacts(ctx, "reports", SYNTH_REPORTS) |
| 203 | + |
| 204 | + variables = declare_artifact(ctx, "results", "1_synth.vars") |
| 205 | + |
| 206 | ++ # Ensure declared metrics .json outputs exist and are parseable even if |
| 207 | ++ # make did not write them; genMetrics.py json.load()s every 1_*.json, so |
| 208 | ++ # the fallback must be "{}" rather than a touched empty file. |
| 209 | ++ json_fallback = [ |
| 210 | ++ "[ -s {p} ] || echo '{{}}' > {p}".format(p = f.path) |
| 211 | ++ for f in synth_jsons |
| 212 | ++ ] |
| 213 | ++ |
| 214 | + if ctx.attr.lint: |
| 215 | + # Lint mode: only canonicalization runs; stub remaining synth outputs. |
| 216 | + for f in synth_outputs.values() + synth_logs + synth_reports + [variables]: |
| 217 | + ctx.actions.write(output = f, content = "") |
| 218 | ++ for f in synth_jsons: |
| 219 | ++ ctx.actions.write(output = f, content = "{}") |
| 220 | ++ elif use_syn: |
| 221 | ++ # OpenROAD-SYN synthesis: one openroad invocation (synth_syn.tcl via |
| 222 | ++ # do-1_synth) consumes the staged Verilog sources directly, so |
| 223 | ++ # VERILOG_FILES is set from ctx.files.verilog_files exactly like the |
| 224 | ++ # yosys canonicalize action does. Uses the full flow makefile |
| 225 | ++ # filegroup (synth_syn.tcl sources load.tcl etc.), no yosys tools. |
| 226 | ++ commands = [_make_cmd(ctx)] + generation_commands( |
| 227 | ++ synth_logs + synth_reports, |
| 228 | ++ ) + json_fallback |
| 229 | ++ ctx.actions.run_shell( |
| 230 | ++ arguments = [ |
| 231 | ++ "--file", |
| 232 | ++ ctx.file._makefile.path, |
| 233 | ++ "do-1_synth", |
| 234 | ++ ], |
| 235 | ++ command = EXPAND_VERILOG_DIRS + " && ".join(commands), |
| 236 | ++ env = config_overrides( |
| 237 | ++ ctx, |
| 238 | ++ verilog_arguments(ctx.files.verilog_files) | |
| 239 | ++ flow_environment(ctx) | |
| 240 | ++ config_environment(config), |
| 241 | ++ ), |
| 242 | ++ inputs = depset( |
| 243 | ++ [config] + ctx.files.verilog_files + ctx.files.extra_configs, |
| 244 | ++ transitive = [ |
| 245 | ++ data_inputs(ctx), |
| 246 | ++ pdk_inputs(ctx), |
| 247 | ++ deps_inputs(ctx), |
| 248 | ++ ], |
| 249 | ++ ), |
| 250 | ++ outputs = synth_outputs.values() + synth_logs + synth_jsons + synth_reports, |
| 251 | ++ tools = flow_inputs(ctx), |
| 252 | ++ progress_message = "OpenROAD-SYN synthesis for %s" % module_top(ctx), |
| 253 | ++ ) |
| 254 | + elif num_partitions > 0: |
| 255 | +- _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, synth_reports, num_partitions, save_odb, all_arguments) |
| 256 | ++ _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, synth_jsons, synth_reports, num_partitions, save_odb, all_arguments) |
| 257 | + else: |
| 258 | + # SYNTH_NETLIST_FILES will not create an .rtlil file or reports, so we need |
| 259 | + # an empty placeholder in that case. |
| 260 | + commands = [_make_cmd(ctx)] + generation_commands( |
| 261 | + synth_logs + synth_outputs.values() + synth_reports, |
| 262 | +- ) |
| 263 | ++ ) + json_fallback |
| 264 | + ctx.actions.run_shell( |
| 265 | + arguments = [ |
| 266 | + "--file", |
| 267 | +@@ -1242,7 +1328,7 @@ def _yosys_impl(ctx): |
| 268 | + deps_inputs(ctx), |
| 269 | + ], |
| 270 | + ), |
| 271 | +- outputs = synth_outputs.values() + synth_logs + synth_reports, |
| 272 | ++ outputs = synth_outputs.values() + synth_logs + synth_jsons + synth_reports, |
| 273 | + tools = depset(transitive = [yosys_inputs(ctx), flow_inputs(ctx)]), |
| 274 | + ) |
| 275 | + |
| 276 | +@@ -1324,7 +1410,7 @@ def _yosys_impl(ctx): |
| 277 | + exe, |
| 278 | + config = config_short, |
| 279 | + make = make, |
| 280 | +- genfiles = [config_short] + outputs + canon_logs + synth_logs, |
| 281 | ++ genfiles = [config_short] + outputs + canon_logs + synth_logs + synth_jsons, |
| 282 | + ) |
| 283 | + |
| 284 | + # Collect all files needed for deployment (tools, PDK, stage inputs). |
| 285 | +@@ -1364,7 +1450,7 @@ def _yosys_impl(ctx): |
| 286 | + name = ctx.attr.name + "_deps", |
| 287 | + ) |
| 288 | + |
| 289 | +- _runfiles_files = [config_short, make] + outputs + canon_logs + synth_logs + ctx.files.extra_configs |
| 290 | ++ _runfiles_files = [config_short, make] + outputs + canon_logs + synth_logs + synth_jsons + ctx.files.extra_configs |
| 291 | + _runfiles_common = depset( |
| 292 | + transitive = [ |
| 293 | + deps_inputs(ctx), |
| 294 | +@@ -1444,7 +1530,7 @@ def _yosys_impl(ctx): |
| 295 | + logs = depset(canon_logs + synth_logs), |
| 296 | + reports = depset(synth_reports), |
| 297 | + drcs = depset([]), |
| 298 | +- jsons = depset([]), |
| 299 | ++ jsons = depset(synth_jsons), |
| 300 | + ), |
| 301 | + ] |
| 302 | + |
0 commit comments