Skip to content

Commit 76073c9

Browse files
committed
synth: add canonicalization step before synthesis
This saves hours on larger designs when unecessary macro rebuilds are avoided and makes the build scripts less brittle. this will clean out unused modules and produce the a canonical $(RESULTS_DIR)/1_synth.json file. This file will not change hash when unrelated changes to the design changes, such as when non-synthesis(simulation) files are mixed into VERILOG_FILES. This is particularly useful when doing synthesis on macros out of a folder of Verilog files and you don't want to carefully groom the list of VERILOG_FILES. This also allows bazel-orfs to handle actual dependencies for a folder of .v/.sv files in much the same fashion that CMake can figure out dependencies given a list of .cpp and header files. Signed-off-by: Øyvind Harboe <[email protected]>
1 parent 0bd1102 commit 76073c9

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

flow/Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ export SYNTH_MEMORY_MAX_BITS ?= 4096
483483

484484
$(SYNTH_STOP_MODULE_SCRIPT):
485485
mkdir -p $(RESULTS_DIR) $(LOG_DIR) $(REPORTS_DIR)
486-
($(TIME_CMD) $(YOSYS_CMD) $(YOSYS_FLAGS) -c $(HIER_REPORT_SCRIPT)) 2>&1 | tee $(LOG_DIR)/1_1_yosys_hier_report.log
486+
(export VERILOG_FILES=$(RESULTS_DIR)/1_synth.json; \
487+
$(TIME_CMD) $(YOSYS_CMD) $(YOSYS_FLAGS) -c $(HIER_REPORT_SCRIPT)) 2>&1 | tee $(LOG_DIR)/1_1_yosys_hier_report.log
487488

488489
ifeq ($(SYNTH_HIERARCHICAL), 1)
489490
do-yosys: $(SYNTH_STOP_MODULE_SCRIPT)
@@ -499,11 +500,20 @@ $(SDC_FILE_CLOCK_PERIOD): $(SDC_FILE)
499500
yosys-dependencies: $(DONT_USE_LIBS) $(WRAPPED_LIBS) $(DONT_USE_SC_LIB) $(DFF_LIB_FILE) $(VERILOG_FILES) $(CACHED_NETLIST) $(LATCH_MAP_FILE) $(ADDER_MAP_FILE)
500501

501502
.PHONY: do-yosys
502-
do-yosys: yosys-dependencies
503+
do-yosys:
503504
mkdir -p $(RESULTS_DIR) $(LOG_DIR) $(REPORTS_DIR) $(OBJECTS_DIR)
504-
($(TIME_CMD) $(YOSYS_CMD) $(YOSYS_FLAGS) -c $(SYNTH_SCRIPT)) 2>&1 | tee $(LOG_DIR)/1_1_yosys.log
505+
(export VERILOG_FILES=$(RESULTS_DIR)/1_synth.json; \
506+
$(TIME_CMD) $(YOSYS_CMD) $(YOSYS_FLAGS) -c $(SYNTH_SCRIPT)) 2>&1 | tee -a $(LOG_DIR)/1_1_yosys.log
505507

506-
$(RESULTS_DIR)/1_1_yosys.v: $(SDC_FILE_CLOCK_PERIOD)
508+
.PHONY: do-yosys-canonicalize
509+
do-yosys-canonicalize: yosys-dependencies
510+
mkdir -p $(RESULTS_DIR) $(LOG_DIR) $(REPORTS_DIR) $(OBJECTS_DIR)
511+
($(TIME_CMD) $(YOSYS_CMD) $(YOSYS_FLAGS) -c $(SCRIPTS_DIR)/synth_canonicalize.tcl) 2>&1 | tee $(LOG_DIR)/1_1_yosys.log
512+
513+
$(RESULTS_DIR)/1_synth.json: $(RESULTS_DIR)/1_1_yosys.v $(SDC_FILE_CLOCK_PERIOD)
514+
$(UNSET_AND_MAKE) do-yosys-canonicalize
515+
516+
$(RESULTS_DIR)/1_1_yosys.v: $(RESULTS_DIR)/1_synth.json $(SDC_FILE_CLOCK_PERIOD)
507517
$(UNSET_AND_MAKE) do-yosys
508518

509519
$(RESULTS_DIR)/1_synth.sdc: $(SDC_FILE)
@@ -520,7 +530,7 @@ $(RESULTS_DIR)/1_synth.v: $(RESULTS_DIR)/1_1_yosys.v
520530

521531
.PHONY: clean_synth
522532
clean_synth:
523-
rm -f $(RESULTS_DIR)/1_*.v $(RESULTS_DIR)/1_synth.sdc $(RESULTS_DIR)/mem.json
533+
rm -f $(RESULTS_DIR)/1_* $(RESULTS_DIR)/mem.json
524534
rm -f $(REPORTS_DIR)/synth_*
525535
rm -f $(LOG_DIR)/1_*
526536
rm -f $(SYNTH_STOP_MODULE_SCRIPT)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source $::env(SCRIPTS_DIR)/synth_preamble.tcl
2+
hierarchy -check -top $::env(DESIGN_NAME)
3+
procs
4+
# Get rid of unused modules
5+
clean
6+
# The hash of this file will not change if files not part of synthesis do not change
7+
json -o $::env(RESULTS_DIR)/1_synth.json

flow/scripts/synth_preamble.tcl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ close $constr
106106
proc synthesize_check {synth_args} {
107107
# Generic synthesis
108108
log_cmd synth -top $::env(DESIGN_NAME) -run :fine {*}$synth_args
109-
# Get rid of unused modules
110-
clean
111109
json -o $::env(RESULTS_DIR)/mem.json
112110
# Run report and check here so as to fail early if this synthesis run is doomed
113111
exec -- python3 $::env(SCRIPTS_DIR)/mem_dump.py --max-bits $::env(SYNTH_MEMORY_MAX_BITS) $::env(RESULTS_DIR)/mem.json

0 commit comments

Comments
 (0)