Download chips/openroad_flow_scripts/flow/scripts/synth.tcl from STAR-future/Trinity-SciData: direct link, hf CLI and curl.
- Browser
- Download file 12.6 kB
-
https://huggingface.co/datasets/STAR-future/Trinity-SciData/resolve/ce57c19fa3a1f3c8613811aebfbd5e960b6a86ab/chips/openroad_flow_scripts/flow/scripts/synth.tcl
- Command line
-
hf download hf://datasets/STAR-future/Trinity-SciData@ce57c19fa3a1f3c8613811aebfbd5e960b6a86ab/chips/openroad_flow_scripts/flow/scripts/synth.tcl
-
curl -L -o synth.tcl https://huggingface.co/datasets/STAR-future/Trinity-SciData/resolve/ce57c19fa3a1f3c8613811aebfbd5e960b6a86ab/chips/openroad_flow_scripts/flow/scripts/synth.tcl
12.6 kB
| # | |
| # Extracts and returns module names from Verilog file | |
| # | |
| proc get_module_names { file_path } { | |
| set module_list [list] | |
| if { [catch { set fid [open $file_path r] } err] } { | |
| error "Failed to open file $file_path: $err" | |
| } | |
| set regex {^[ \t]*module[ \t]+([A-Za-z_$][A-Za-z0-9_$]*)} | |
| while { [gets $fid line] >= 0 } { | |
| if { [regexp -nocase $regex $line match_all module_name] } { | |
| lappend module_list $module_name | |
| } | |
| } | |
| close $fid | |
| return $module_list | |
| } | |
| # | |
| # Builds dfflegalize arg list | |
| # | |
| proc get_dfflegalize_args { file_path } { | |
| set legalize_args [list] | |
| set module_names [get_module_names $file_path] | |
| foreach module_name $module_names { | |
| lappend legalize_args -cell $module_name x | |
| } | |
| return $legalize_args | |
| } | |
| source $::env(SCRIPTS_DIR)/synth_preamble.tcl | |
| if { [env_var_exists_and_non_empty SYNTH_CHECKPOINT] } { | |
| read_checkpoint $::env(SYNTH_CHECKPOINT) | |
| } else { | |
| read_checkpoint $::env(RESULTS_DIR)/1_1_yosys_canonicalize.rtlil | |
| } | |
| # When this synthesis run is one partition of a parallel split (driven by | |
| # an external orchestrator), `SYNTH_BLACKBOXES` lists modules outside this | |
| # partition. Blackboxing them before the hierarchy check lets each | |
| # partition load the same canonical RTLIL checkpoint while only synthesising | |
| # its own subhierarchy. Names not present in the loaded design are skipped | |
| # silently so the same list can be passed to every partition. | |
| # | |
| # This deliberately differs from the SYNTH_BLACKBOXES handling in | |
| # synth_preamble.tcl's `read_design_sources`, and the difference is correct | |
| # in both places — do not "harmonise" the two: | |
| # * Order: here the design is already elaborated (read from RTLIL), so | |
| # `blackbox` operates on resolved modules and must run before the | |
| # hierarchy check. In synth_preamble.tcl the verilog frontend uses | |
| # `read_verilog -defer`, so `hierarchy -check -top` must run first to | |
| # elaborate from the top before `blackbox` sees a populated module table. | |
| # * Catch: here a missing name is expected because the same list is | |
| # reused across partitions, and only this partition's portion exists in | |
| # the checkpoint. In synth_preamble.tcl a single design is being | |
| # synthesised, so an unknown name is almost certainly a user typo and | |
| # should fail loudly — `blackbox $m` without `catch` is intentional. | |
| # | |
| # An orchestrator with thousands of kept modules gives the list in a file | |
| # instead, SYNTH_BLACKBOXES_FILE, one name per line: Linux caps one | |
| # environment string at 128 KiB, and 2,250 names are 206 KB. | |
| set synth_blackboxes [env_var_or_empty SYNTH_BLACKBOXES] | |
| if { [env_var_exists_and_non_empty SYNTH_BLACKBOXES_FILE] } { | |
| set fid [open $::env(SYNTH_BLACKBOXES_FILE) r] | |
| while { [gets $fid line] >= 0 } { | |
| set m [string trim $line] | |
| if { $m ne "" } { | |
| lappend synth_blackboxes $m | |
| } | |
| } | |
| close $fid | |
| } | |
| foreach m $synth_blackboxes { | |
| catch { blackbox $m } | |
| } | |
| hierarchy -check -top $::env(DESIGN_NAME) | |
| if { $::env(SYNTH_GUT) } { | |
| # /deletes all cells at the top level, which will quickly optimize away | |
| # everything else, including macros. | |
| delete $::env(DESIGN_NAME)/c:* | |
| } | |
| if { [env_var_exists_and_non_empty SYNTH_KEEP_MODULES] } { | |
| foreach module $::env(SYNTH_KEEP_MODULES) { | |
| # Two patterns so both frontends work: | |
| # - `$module` matches the bare name produced by verilog. | |
| # - `$module\$*` matches the `$`-suffixed canonical names the | |
| # slang frontend generates for parameterized instances | |
| # (e.g. `\foo$1`); yosys's match_ids retries the pattern with | |
| # the id's leading `\` stripped, so no `\`-prefix is needed | |
| # here -- see tools/yosys/passes/cmds/select.cc match_ids(). | |
| # Multiple patterns on one `select` are unioned at the end of the | |
| # command (select.cc: `while (work_stack.size() > 1) union`), so | |
| # when a pattern matches nothing it degrades to a warning and the | |
| # other pattern still applies -- no regression for non-slang. | |
| # `-module <name>` would error if the module doesn't exist, which | |
| # is why we use bare patterns instead. | |
| select "$module" "$module\\\$*" | |
| # In a partition (SYNTH_CHECKPOINT set) a kept module of another | |
| # partition is not in this partition's checkpoint: the selection is | |
| # empty and setattr below marks nothing. | |
| if { | |
| ![env_var_exists_and_non_empty SYNTH_CHECKPOINT] | |
| && [string trim [tee -q -s result.string select -list]] eq "" | |
| } { | |
| error "SYNTH_KEEP_MODULES: no module $module in the design" | |
| } | |
| setattr -mod -set keep_hierarchy 1 | |
| select -clear | |
| } | |
| } | |
| if { [env_var_exists_and_non_empty SYNTH_HIER_SEPARATOR] } { | |
| scratchpad -set flatten.separator $::env(SYNTH_HIER_SEPARATOR) | |
| } | |
| set synth_full_args [env_var_or_empty SYNTH_ARGS] | |
| if { [env_var_exists_and_non_empty SYNTH_OPERATIONS_ARGS] } { | |
| set synth_full_args [concat $synth_full_args $::env(SYNTH_OPERATIONS_ARGS)] | |
| } else { | |
| set synth_full_args [concat $synth_full_args \ | |
| "-extra-map $::env(FLOW_HOME)/platforms/common/lcu_kogge_stone.v"] | |
| } | |
| if { [env_var_equals SYNTH_OPT_HIER 1] } { | |
| set synth_full_args [concat $synth_full_args -hieropt] | |
| } | |
| if { | |
| [env_var_exists_and_non_empty SYNTH_CHECKPOINT] && | |
| $::env(SYNTH_SKIP_KEEP) | |
| } { | |
| # Partition mode where the checkpoint is still canonical RTLIL (the keep | |
| # decision for this partition is driven externally). Run the full | |
| # coarse+fine synthesis, flattened. | |
| synth -flatten -run :fine {*}$synth_full_args | |
| } elseif { [env_var_exists_and_non_empty SYNTH_CHECKPOINT] } { | |
| # Partition mode where the checkpoint already holds coarse synth + | |
| # keep_hierarchy output. Just flatten and continue from coarse. | |
| synth -flatten -run coarse:fine {*}$synth_full_args | |
| } elseif { !$::env(SYNTH_HIERARCHICAL) } { | |
| # Perform standard coarse-level synthesis script, flatten right away | |
| synth -flatten -run :fine {*}$synth_full_args | |
| } else { | |
| # Perform standard coarse-level synthesis script, | |
| # defer flattening until we have decided what hierarchy to keep | |
| synth -run :fine | |
| if { [env_var_exists_and_non_empty SYNTH_MINIMUM_KEEP_SIZE] } { | |
| set ungroup_threshold $::env(SYNTH_MINIMUM_KEEP_SIZE) | |
| puts "Keep modules above estimated size of | |
| $ungroup_threshold gate equivalents" | |
| convert_liberty_areas | |
| keep_hierarchy -min_cost $ungroup_threshold | |
| } else { | |
| keep_hierarchy | |
| } | |
| # Re-run coarse-level script, this time do pass -flatten | |
| synth -flatten -run coarse:fine {*}$synth_full_args | |
| } | |
| # Resolve internal tristates left by the slang frontend --- | |
| if { [env_var_equals SYNTH_HDL_FRONTEND slang] } { | |
| tribuf -logic | |
| opt_clean | |
| } | |
| # Fail early if this synthesis run is doomed | |
| set mocked [synth_memory_max_bits $::env(SYNTH_MEMORY_MAX_BITS) \ | |
| $::env(SYNTH_MOCK_LARGE_MEMORIES) $::env(SYNTH_KEEP_MOCKED_MEMORIES)] | |
| if { $::env(SYNTH_MOCK_LARGE_MEMORIES) } { | |
| set report_file [open $::env(REPORTS_DIR)/synth_mocked_memories.txt "w"] | |
| foreach memory $mocked { | |
| lassign $memory module width size | |
| puts -nonewline $report_file "$module:\n width: $width\n size: $size\n" | |
| } | |
| close $report_file | |
| } | |
| # A yosys backend sorts the design by name before it writes, and the passes | |
| # below depend on that order; json -o mem.json did it here. The sort stays, | |
| # the file goes: dropping the sort changes results and is its own change. | |
| write_json /dev/null | |
| if { [env_var_exists_and_non_empty SYNTH_RETIME_MODULES] } { | |
| select {*}$::env(SYNTH_RETIME_MODULES) | |
| opt -fast -full | |
| memory_map | |
| opt -full | |
| techmap | |
| abc -dff -script $::env(SCRIPTS_DIR)/abc_retime.script | |
| select -clear | |
| } | |
| if { | |
| [env_var_equals SYNTH_WRAPPED_OPERATORS 1] || | |
| [env_var_equals SWAP_ARITH_OPERATORS 1] | |
| } { | |
| log_cmd source $::env(SCRIPTS_DIR)/synth_wrap_operators.tcl | |
| } else { | |
| synth -top $::env(DESIGN_NAME) -run fine: -noabc {*}$synth_full_args | |
| } | |
| # Get rid of indigestibles | |
| chformal -remove | |
| delete t:\$print | |
| # rename registers to have the verilog register name in its name | |
| # of the form \regName$_DFF_P_. We should fix yosys to make it the reg name. | |
| # At least this is predictable. | |
| renames -wire | |
| # Optimize the design | |
| opt -purge | |
| # Technology mapping of adders | |
| if { | |
| [env_var_exists_and_non_empty ADDER_MAP_FILE] && | |
| ( | |
| (![env_var_equals SYNTH_WRAPPED_OPERATORS 1] && | |
| ![env_var_equals SWAP_ARITH_OPERATORS 1]) || | |
| (([env_var_equals SYNTH_WRAPPED_OPERATORS 1] || | |
| [env_var_equals SWAP_ARITH_OPERATORS 1]) && | |
| ![design_has_extracted_operators]) | |
| ) | |
| } { | |
| # extract the full adders | |
| extract_fa | |
| # map full adders | |
| techmap -map $::env(ADDER_MAP_FILE) | |
| techmap | |
| # Quick optimization | |
| opt -fast -purge | |
| } | |
| # Technology mapping of latches | |
| if { [env_var_exists_and_non_empty LATCH_MAP_FILE] } { | |
| # Legalize async set/reset latches into the latches this map file provides | |
| # (soft-logic emulation); the trailing selection keeps dfflegalize off FFs. | |
| dfflegalize {*}[get_dfflegalize_args $::env(LATCH_MAP_FILE)] {t:$_DLATCH_*} | |
| techmap -map $::env(LATCH_MAP_FILE) | |
| } | |
| # Clock gate inference. | |
| if { [env_var_equals INFER_CLKGATES 1] } { | |
| set clkgate_args {} | |
| if { | |
| [env_var_exists_and_non_empty POS_CLKGATE_AND_PORTS] || | |
| [env_var_exists_and_non_empty NEG_CLKGATE_AND_PORTS] | |
| } { | |
| if { [env_var_exists_and_non_empty POS_CLKGATE_AND_PORTS] } { | |
| lappend clkgate_args "-pos" | |
| lappend clkgate_args {*}$::env(POS_CLKGATE_AND_PORTS) | |
| } | |
| if { [env_var_exists_and_non_empty NEG_CLKGATE_AND_PORTS] } { | |
| lappend clkgate_args "-neg" | |
| lappend clkgate_args {*}$::env(NEG_CLKGATE_AND_PORTS) | |
| } | |
| } else { | |
| # Let yosys decide on which clock gating cell to use | |
| lappend clkgate_args {*}$lib_args | |
| } | |
| if { [env_var_exists_and_non_empty INFER_CLKGATES_MIN_NET_SIZE] } { | |
| lappend clkgate_args -min_net_size $::env(INFER_CLKGATES_MIN_NET_SIZE) | |
| } | |
| if { [env_var_exists_and_non_empty INFER_CLKGATES_EXCLUDE] } { | |
| lappend clkgate_args * | |
| foreach pattern $::env(INFER_CLKGATES_EXCLUDE) { | |
| lappend clkgate_args $pattern %d | |
| } | |
| } | |
| log_cmd clockgate {*}$clkgate_args | |
| } | |
| # Technology mapping of flip-flops | |
| # dfflibmap only supports one liberty file | |
| if { [env_var_exists_and_non_empty DFF_LIB_FILE] } { | |
| dfflibmap -liberty $::env(DFF_LIB_FILE) {*}$lib_dont_use_args | |
| } elseif { [env_var_exists_and_non_empty DFF_MAP_FILE] } { | |
| set legalize_args [get_dfflegalize_args $::env(DFF_MAP_FILE)] | |
| dfflegalize {*}$legalize_args | |
| techmap -map $::env(DFF_MAP_FILE) | |
| } else { | |
| dfflibmap {*}$lib_args {*}$lib_dont_use_args | |
| } | |
| opt | |
| # Replace undef values with defined constants | |
| setundef -zero | |
| if { | |
| ![env_var_equals SYNTH_WRAPPED_OPERATORS 1] && | |
| ![env_var_equals SWAP_ARITH_OPERATORS 1] | |
| } { | |
| log_cmd abc {*}$abc_args | |
| } else { | |
| # Not dead code: abc_new mistakes the "-script" in /OpenROAD-flow-scripts/... | |
| # paths for a given -script and drops its default (YosysHQ/yosys#6320). | |
| scratchpad -set abc9.script $::env(SCRIPTS_DIR)/abc_speed_gia_only.script | |
| # abc_new maps each arithmetic operator module with the abc9_script | |
| # attribute synth_wrap_operators.tcl sets on it, and every other module | |
| # with the script above. An explicit -script overrides both, so it is | |
| # cropped from the arguments and ABC_SCRIPT does not apply here. | |
| set abc_args [lrange $abc_args 2 end] | |
| log_cmd abc_new {*}$abc_args | |
| delete {t:$specify*} | |
| } | |
| # Splitting nets resolves unwanted compound assign statements in | |
| # netlist (assign {..} = {..}) | |
| splitnets | |
| # Remove unused cells and wires | |
| opt_clean -purge | |
| # Technology mapping of constant hi- and/or lo-drivers | |
| hilomap -singleton \ | |
| -hicell {*}$::env(TIEHI_CELL_AND_PORT) \ | |
| -locell {*}$::env(TIELO_CELL_AND_PORT) | |
| if { $::env(SYNTH_INSBUF) } { | |
| # Insert buffer cells for pass through wires | |
| insbuf -buf {*}$::env(MIN_BUF_CELL_AND_PORTS) | |
| } | |
| # Reports | |
| tee -o $::env(REPORTS_DIR)/synth_check.txt check | |
| tee -o $::env(REPORTS_DIR)/synth_stat.txt stat -hierarchy {*}$lib_args | |
| # check the design is composed exclusively of target cells, and | |
| # check for other problems | |
| if { | |
| ![env_var_equals SYNTH_WRAPPED_OPERATORS 1] && | |
| ![env_var_equals SWAP_ARITH_OPERATORS 1] | |
| } { | |
| check -assert -mapped | |
| } else { | |
| # Wrapped operator synthesis leaves around $buf cells which `check -mapped` | |
| # gets confused by, once Yosys#4931 is merged we can remove this branch and | |
| # always run `check -assert -mapped` | |
| check -assert | |
| } | |
| if { $::env(SYNTH_REPEATABLE_BUILD) } { | |
| # techmap re-attaches src attributes that point into the techmap library, | |
| # after synth_canonicalize.tcl stripped them; strip again so the netlist | |
| # carries no build paths. | |
| setattr -unset src * | |
| setattr -mod -unset src * | |
| } | |
| # Write synthesized design | |
| write_verilog -nohex -nodec $::env(RESULTS_DIR)/1_2_yosys.v | |