You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🔴 Potential Wrong Timing for "none" — _optimize now calls manager.run(program).elapsed_seconds even for the empty pipeline. The docstring claims the value is exactly 0.0, but if run() measures wall time around an empty pass list, it will be a small non-zero number that breaks baseline comparisons.
Suggestion: keep an early if level == "none": return 0.0, or make sure create_optimization_pass_manager("none").run() itself hardcodes 0.0.
🟡 API contract for unknown levels — The old code accepted any non-"none" level by running constant folding + DCE, and "all" added extra passes. If create_optimization_pass_manager rejects previously accepted values (e.g. "base" or any typo), this is a behavior break.
Suggestion: confirm every level supported by the CLI is handled by the new manager, and ideally validate the level at argument parsing rather than deep inside _optimize.
🟡 Redundant IR count for "none" — Removing the if optimize_level != "none" guard means _count_ir now runs twice for the no-op case. It is not timed, so it only adds benchmark-loop overhead, but keeping an early return for "none" would preserve the previous, leaner path.
💭 Verify time source — elapsed_seconds should match the previous time.perf_counter() semantics (wall time). If the pass manager measures with time.process_time or includes pipeline construction time, results won’t be comparable to historical runs. Worth a quick check in create_optimization_pass_manager.
🔴 文档与示例不一致 — 新增段声称所有 pass 都定义 name 且实现 OptimizationPass.optimize(...),但后面的 PeepholeOptimizer/LICM 示例既没有 name 属性,也没有继承或注册到 OptimizationPass。建议在示例中补上 name = "peephole" 等常量,或说明基类仅作接口约定、实际类可以独立存在。
🟡 --optimize 描述容易误解 — “remains an alias for the option name” 中的 “the option name” 指代不清,建议直接写 “alias for --opt-level”。同时可以补充一句:--opt-level 是带值选项,所以裸写 --optimize 才会无效;否则读者可能误以为 --optimize 是布尔开关被移除了。
🟡 Potential KeyError on pass-name lookup — Lines ~65-68: changes_by_name["constant-folding"] and changes_by_name["dead-code-elim"] will crash if the "basic" pipeline changes execution names (e.g., "constant_folding" or a renamed pass). Consider using changes_by_name.get("constant-folding", 0) or, better, add a lookup method to report if one doesn’t already exist.
🟡 Verify the in-place/return contract — The comment says run() optimizes program in place and returns a report, but a pass manager commonly returns a new module. If the actual API does not mutate program, the later LLVM generation step will operate on the unoptimized program. Double-check the API and, if safe, assign the optimized program back or use the report’s program reference.
💭 Stringly-typed pass names — The pass names in the dict lookup are hardcoded magic strings. Defining constants (e.g., PASS_CONSTANT_FOLDING) or using an API-provided enum would make typos compile-time detectable and keep the example aligned with the library’s public surface.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
内容
DeadCodeEliminator改为单基本块 use-def mark-and-sweep:建立dest.name → Instruction定义索引,从可观察根递归回溯生产者,再稳定顺序 sweep。STORE、RETURN、BR、BR_IF、FOR、ENDFOR、ALLOCA及所有 dest-less 指令,并完整保留其 operand 依赖链。phi_nodes在 W5 保守 no-op,避免提前进行不安全的跨块删除。范围
本 PR 基于并依赖 #48(W2 统一 Pass 接口与 PassManager)。本分支直接从 W2 基线创建,不依赖 #50 的 W3 ConstantFolder 内容。
本 PR 仅实现课题 4 的 W5「DCE use-def 回溯」。没有实现 W6 的跨基本块分析、CFG 数据流或不动点迭代,也没有修改
Value/Instruction、IRBuilder、前端、后端、PassManager 配置或其他优化算法。验证
git diff --check通过