You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否不执行hierarchy命令生成Yosys的Graphviz设计图?

问题:能否跳过Yosys的hierarchy命令直接输出Graphviz可视化文件?

我用Yosys读取门级Verilog文件,然后输出Graphviz的dot文件做可视化。统计命令耗时发现,解析成AST的速度远快于生成层级结构的速度:

  • 针对9.3MB的小型Verilog设计:
    • read_verilog -defer耗时465ms
    • hierarchy -auto-top耗时42,961ms

在更大的实际工程中,hierarchy命令运行2小时还没结束。我想知道能不能不运行hierarchy就输出Graphviz格式的设计图?试过调整read_verilog和hierarchy的选项来排除不必要操作,但没找到加速hierarchy的设置。

我的Tcl脚本

# source file
set time_parse_start [clock clicks -milliseconds]
yosys read_verilog -defer $::env(YOSYS_INPUT_VERILOG)
set time_taken [expr [clock clicks -milliseconds] - $time_parse_start]
puts "Time taken to parse: $time_taken ms"

set time_hier_start [clock clicks -milliseconds]
yosys hierarchy -auto-top
set time_taken [expr [clock clicks -milliseconds] - $time_hier_start]
puts "Time taken to derive hierarchy: $time_taken ms"

set time_output_start [clock clicks -milliseconds]
yosys show -viewer none -format dot -prefix $::env(YOSYS_OUTPUT_DOTPREFIX)
set time_taken [expr [clock clicks -milliseconds] - $time_output_start]
set total_time_taken [expr [clock clicks -milliseconds] - $time_parse_start]
puts "Time taken to output .dot file: $time_taken ms"
puts "Total time taken: $total_time_taken ms"

执行命令

YOSYS_INPUT_VERILOG=c10_default.vqm YOSYS_OUTPUT_DOTPREFIX=c10_default yosys test.tcl

输出结果

Yosys 0.34 (git sha1 4a1b5599258, clang 14.0.0 -fPIC -Os)

1. Executing Verilog-2005 frontend: c10_default.vqm
Parsing Verilog input from `c10_default.vqm' to AST representation.
Storing AST representation for module `$abstract\eight_bit_uc'.
Successfully finished Verilog frontend.
Time taken to parse: 507 ms

2. Executing HIERARCHY pass (managing design hierarchy).

2.1. Finding top of design hierarchy..
root of   0 design levels: $abstract\eight_bit_uc
Automatically selected $abstract\eight_bit_uc as design top module.

2.2. Executing AST frontend in derive mode using pre-parsed AST for module `\eight_bit_uc'.
Generating RTLIL representation for module `\eight_bit_uc'.

2.3. Analyzing design hierarchy..
Top module:  \eight_bit_uc

2.4. Analyzing design hierarchy..
Top module:  \eight_bit_uc
Removing unused module `$abstract\eight_bit_uc'.
Removed 1 unused modules.
Time taken to derive hierarchy: 44377 ms

3. Generating Graphviz representation of design.
Writing dot description to `c10_default.dot'.
Dumping module eight_bit_uc to page 1.
Time taken to output .dot file: 431 ms
Total time taken: 45315 ms

End of script. Logfile hash: aed24130cb, CPU: user 45.01s system 0.23s
Yosys 0.34 (git sha1 4a1b5599258, clang 14.0.0 -fPIC -Os)
Time spent: 97% 1x hierarchy (44 sec), 1% 2x read_verilog (0 sec), ...

回答

1. 能否跳过hierarchy命令?

不行。Yosys的show命令依赖RTLIL格式的设计数据,而read_verilog -defer仅生成AST,不会转换为RTLIL。hierarchy命令的核心工作之一就是把AST转换成RTLIL,这也是它耗时久的核心原因——尤其是门级设计,模块实例化和连线数量大,转换过程开销极高。

2. 加速hierarchy命令的可行方案

(1)指定明确的顶层模块,避免自动探测

hierarchy -auto-top会遍历所有模块寻找顶层,大设计里这个过程非常耗时。如果你已知顶层模块名,直接指定:

yosys hierarchy -top <你的顶层模块名>

跳过自动探测步骤能节省大量时间。

(2)关闭不必要的层级优化

默认hierarchy会执行移除未使用模块等优化操作,若不需要这些,可以用-keep参数保留所有模块,减少分析开销:

yosys hierarchy -top <顶层模块名> -keep

(3)拆分hierarchy工作流程

hierarchy的耗时主要集中在AST转RTLIL和层级分析两部分,可以分步执行,只做必要转换不做额外优化:

# 仅转换AST到RTLIL,跳过标准库处理和模块排序
yosys hierarchy -top <顶层模块名> -nolib -nosort

-nolib跳过标准库处理,-nosort跳过模块排序,能进一步降低耗时。

(4)门级设计特殊优化

门级Verilog通常包含大量重复单元,可尝试启用-fast参数(部分Yosys版本支持),或先运行轻量综合减少复杂度:

# 轻量综合,仅做基础转换不做逻辑优化
yosys synth -noabc

注意:该操作会改变设计结构,若需严格保留原始门级结构请谨慎使用。

3. 替代方案:绕开Yosys层级流程

如果完全不想走Yosys的RTLIL流程,可以用第三方工具直接生成可视化:

  • Verilator:用verilator --dot命令,解析Verilog后直接输出层级dot图,速度远快于Yosys的hierarchy,适合大型门级设计。
  • 自定义脚本:用Python的pyverilog库解析Verilog,提取模块实例化关系生成dot文件,仅保留层级结构,速度最快。

内容的提问来源于stack exchange,提问作者bagelfire

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 08:03:20