name: verilog-dead-code-root-cause
description: Use this skill when the user provides Verilog/SystemVerilog source files or a source directory plus a top module, and wants a concise Chinese JSON diagnosis for unreachable procedural branches, static dead-code conditions, or logic that disappears before/after Yosys proc/opt, especially cases where for-loop unfolding or constant loop variables make if/case branches impossible. license: MIT
metadata:
author: zk
version: "1.1"
Verilog Dead Code Root Cause
When to Use
The user asks whether a Verilog branch, assignment, signal, or block is dead code.
The design has procedural
alwaysblocks,forloops,if/else, orcasestatements.The suspected issue is like
for (k = 0; k < 3; ...)with conditions such asif (k == 3)orif (k > 3).The user wants to know whether before/after RTLIL diff is enough to recover the dead-code root.
The user wants the final diagnosis saved as a concise Chinese JSON report.
Key Rule
Do not rely only on raw_proc.il -> opt_proc.il diff for procedural dead-code diagnosis.
Yosys may eliminate unreachable branches during Verilog elaboration or process lowering before the standard proc output. In those cases:
pre_proc.ilmay still containprocessandswitch 1'0/switch 1'1with source locations.raw_proc.ilmay already have lost the unreachable branch.opt_proc.ilmay only show later cleanup, such as unused registers or internal logic being purged.
Workflow
1. Generate evidence files
Run from the lint_agent project root:
python skills/verilog-dead-code-root-cause/scripts/run_dead_code_trace.py --top <top_module> <source_or_dir> [more_sources...]
The script writes a new directory under reports/dead_code_<YYYYMMDD_HHMMSS>/ relative to the project root containing:
dead_code_artifacts.jsonpre_proc.ilraw_proc.ilraw_proc_ifx_noopt.ilopt_proc.il
Read ARTIFACTS_PATH=... from the script output and open dead_code_artifacts.json first.
2. Diagnose in this order
Read the source around the suspicious
always,for,if, orcase.Read
pre_proc.iland search for the source line,process,switch 1'0, andswitch 1'1.Read
raw_proc.ilto see what remains afterproc.Read
opt_proc.ilonly to confirm additional cleanup after optimization.Use
raw_proc_ifx_noopt.ilas a sanity check when you suspect defaultprocpasses are hiding information.
3. What Counts as a Strong Dead-Code Finding
Report a likely real dead-code condition when several of these hold:
Source has a statically impossible condition, such as loop variable ranges that cannot satisfy the branch.
pre_proc.ilshows a constant switch condition, especiallyswitch 1'0for an unreachable branch.The source location on the
switchpoints back to the suspiciousiforcase.Signals assigned only inside the unreachable branch become unused or disappear later.
raw_proc.ilno longer contains a corresponding mux/comparator/assignment for the branch.
4. What Not to Claim
Do not claim
raw_proc -> opt_procalone proves the original dead condition. It may only prove later cleanup.Do not treat every removed register as dead code; it may be removed because the module has no observable outputs.
Do not report a branch as dead unless source-level ranges or
pre_proc.ilconstant switches support it.
5. Write the final Chinese JSON diagnosis
- Write the final diagnosis to the report directory printed by the wrapper:
<REPORT_DIR>/dead_code_diagnosis.json
- The final assistant response should be brief and in Chinese: state the JSON report path and the number of dead-code findings. Do not duplicate the full report in prose unless the user asks.
- The JSON report must contain only core content:
{
"summary": {
"top_module": "top",
"input_paths": ["rtl"],
"artifact_dir": "reports/dead_code_20260428_153000",
"dead_code_count": 1,
"output_path": "reports/dead_code_20260428_153000/dead_code_diagnosis.json"
},
"findings": [
{
"id": "DC_001",
"file": "rtl/top.sv",
"line": 58,
"condition": "if (k == 3)",
"category": "源码级死代码",
"root_cause": "for 循环中 k 的取值范围为 0 到 2,因此 k == 3 永远不成立。",
"evidence": {
"source_evidence": "源码中的循环范围与条件互斥",
"pre_proc_evidence": "pre_proc.il 中对应分支表现为 switch 1'0",
"raw_proc_evidence": "raw_proc.il 中已不存在该分支对应的 mux 或赋值",
"opt_proc_evidence": "opt_proc.il 中仅保留后续清理结果"
},
"diagnosis": "该分支为静态不可达分支,应删除或修正循环范围/条件。",
"fix_hint": "如果 k==3 是有效场景,应调整循环边界;否则删除该不可达分支。"
}
]
}
Field rules:
- Keep JSON keys stable in English, but write all diagnosis text in Chinese.
summarymust contain only top module, inputs, artifact directory, count, and output path.findingsmust contain one entry per confirmed dead-code condition.- Use
categoryvalues源码级死代码or优化清理. root_cause,diagnosis, andfix_hintmust be concise and evidence-based.evidencemust cite only facts from source code,pre_proc.il,raw_proc.il,raw_proc_ifx_noopt.il, andopt_proc.il.- Do not include broad Yosys background or generic dead-code explanation.
- If no dead code is confirmed, write
"findings": []and setdead_code_countto0.