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
🟡 Missing name in examples — The text says every pass defines a stable name, but neither PeepholeOptimizer nor LICM shows one. Add e.g. name = "peephole" to each class so the docs are self-consistent.
🟡 Ambiguous --optimize alias — “Compatibility alias” is unclear. Does --optimize take a value (--optimize all) or is it a legacy boolean flag? If the latter, specify what it maps to (e.g. --optimize == --opt-level all).
🟡 LICM example is still a skeleton — The snippet returns hoisted_count but never increments it; the actual hoisting logic is still comments. Label it as “skeleton/pseudocode” or add concrete increment examples, otherwise readers may copy it and get an always-zero report.
💭 CLI flag name collision — A separate numeric --opt-level for the LLVM tool is easy to confuse with the main CLI’s string --opt-level. Consider naming it --llvm-opt-level or explicitly warning that the two are not interchangeable.
💭 Terminology consistency — “non-negative number of transformations” is fine, but “number of changes” is simpler and matches the total_changes field used elsewhere.
📁 docs/topics/04-IR优化器框架.md
🔴 不一致的 name 属性定义 — 父类 OptimizationPass 将 name 定义为 @property 抽象方法,但子类示例 ConstantFolder 却用类属性 name = "constant-folding" 实现。Python 中 property 是数据描述符,优先级高于子类类属性,因此子类类属性不会覆盖父类的 property,导致子类实例访问 name 时仍会触发父类 property 的 getter(返回 ...),而非子类赋值的字符串。建议统一为一种风格:要么所有子类都实现 @property 方法,要么父类只定义 name 为类属性(甚至去掉 @property),让子类直接覆盖。
💭 Language inconsistency — The new note (lines 221-223) is in Chinese, but the rest of the document (including the changed commands) is in English.
Suggestion: Keep documentation language consistent. If the document is English, translate the note to English.
Example: --optimize all remains a compatibility alias; prefer the canonical form --opt-level all in new documentation.
🟡 Potential confusion about the alias — The note says --optimize all is an alias, but the original command used --optimize without arguments. If --optimize (no value) is also an alias, clarify. If it's deprecated, mention that.
Suggestion: Update the note to clearly state the relationship:
--optimize (alias for --opt-level default? Or --optimize all is the alias for --opt-level all?).
Ensure the command examples are consistent with the actual CLI behavior.
💭 Missing consistency check — The diff only updates two occurrences of --optimize. If the file or other docs still use --optimize elsewhere, they should be updated too.
Suggestion: Search the entire repository for remaining uses of --optimize and update them to the canonical form.
📁 examples/end_to_end_pipeline.py
🔴 确认 run 的修改语义 — 第二个 hunk 中 create_optimization_pass_manager("all").run(program2) 之后直接 LLVMCodegen(program2)。如果 run() 返回的是新 IR 而不是原地修改 program2,codegen 会生成未优化代码。同理第一个 hunk 后续也继续使用 program。请确认 API 行为,必要时改为 program2 = manager.run(program2) 或把返回值传给 codegen。
🔴 Bug: KeyError if pass names differ — The code assumes report.executions contains exactly "constant-folding" and "dead-code-elim". If the pass manager names are different (e.g., "constant_folding" or "dce"), this will crash with KeyError. Check the actual pass names or use .get() with a fallback.
🔴 Bug: "basic" pass manager may not run both passes — If create_optimization_pass_manager("basic") doesn't include both constant folding and DCE, the lookup will fail. Verify the pass configuration includes both, or specify a more explicit pass list.
🟡 Suggestion: Handle empty/missing report — If report.executions is empty or the pass manager doesn't record executions, the dict comprehension will succeed but the lookups will fail. Add a guard:
if"constant-folding"notinchanges_by_nameor"dead-code-elim"notinchanges_by_name:
raiseRuntimeError("Pass manager did not execute expected passes")
🟡 Suggestion: Use next with default for clarity — Instead of building a dict, consider:
This avoids dict allocation and makes the assumed pass names explicit.
💭 Nit: Duplicate names — If two executions share the same name, the dict comprehension silently keeps the last. Use a list or check for duplicates if order matters.
💭 Nit: Verify changes type — The old code returned counts from .run(). The report's changes field might be a list of changed nodes or a count. Confirm it's an integer for the print statement.
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.
内容
OptimizationPass.optimize(program) -> int抽象接口。PassManager:按注册顺序执行、记录逐 Pass 变更数与耗时、支持空/重复管线,并在异常或非法计数时立即停止。none/basic/all管线工厂,统一 CompilerDriver 与 benchmark 的优化级别映射。_PassAdapter;不修改其优化算法。--opt-level,保留--optimize兼容别名。范围
本 PR 仅实现课题 4 的 W2「统一 Pass 接口与 PassManager」。没有提前实现 W3–W9 的常量折叠、不动点、use-def、规则引擎、融合或 LICM 算法增强。
验证
git diff --check通过