feat: 新增 IR 层常量传播与折叠 pass

This commit is contained in:
2026-10-12 14:43:58 +00:00
parent b7b6d43d05
commit 66e240ad00
10 changed files with 1044 additions and 21 deletions
+1
View File
@@ -17,6 +17,7 @@ oxide_liveness = { path = "../oxide_liveness" }
oxide_regalloc = { path = "../oxide_regalloc" }
oxide_ir.workspace = true
oxide_emit.workspace = true
oxide_fold.workspace = true
serde.workspace = true
serde_json.workspace = true
rustc-hash.workspace = true
+3
View File
@@ -98,6 +98,9 @@ impl Compiler {
/// 零删除返回 `live_reusable`(免第二轮 CFG/活集重建)。
fn compile_ir(&self, mut ir: oxide_ir::IRFunction) -> Result<CompiledModule, String> {
crate::compiler_debug!("compile_ir: after emit {} insts", ir.insts.len());
// 常量折叠:单向前扫常量传播加就地改写,接在 emit 与 DCE 之间。
// 不删指令、不重映射 label,改写造成的 CFG 失效由 DCE 自身的 build_cfg 吸收。
oxide_fold::fold(&mut ir);
// DCE 零删除时返回 Pass A CFG 供 liveness 复用;有删除或 DCE 关闭时为 None(须重建)。
let dce_cfg: Option<oxide_cfg::Cfg> = if self.enable_dce {
let cfg = oxide_dce::dce(&mut ir); // 顶层函数;nested 不递归