Files
OxideJS-New/crates/oxide_dce/src/lib.rs
T
pjh123 b0ba874844 feat: 新建 oxide_dce crate 骨架并接入 workspace
- workspace.members 在 oxide_cfg 后追加 crates/oxide_dce
- Cargo.toml 骨架照抄 oxide_cfg(oxide_ir + oxide_cfg 依赖,dev-deps parser/emit/vm)
- lib.rs 中文文档头 + pub fn dce 入口(空函数退化先例,非空路径 Task 2/3 骨架)
2026-08-06 11:27:44 +08:00

21 lines
1.3 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! DCE 改写 pass:IRFunction → 死代码消除后 compact 重建。
//!
//! 改写 pass(D-09):`&mut IRFunction` 就地 compact(D-06 方案 A 索引关联保证无借用冲突),
//! 三 Pass——Pass A 块级可达性(消费 `oxide_cfg::build_cfg`,Exception 边保守,D-07/Pitfall 4)、
//! Pass B 全函数 use 计数迭代删除死指令到不动点(D-01/D-02 连锁语义)、
//! Pass C mark-sweep 一次性重建 insts + label_pos 重映射(D-13,不用就地逐删平移)。
//! 本 pass 不碰 nested(D-03 不递归)、常量池(D-14 不清理)、n_registers(D-04 不收缩)、
//! label_count(D-13 不读不改)。中间产物(keep/use_count)用局部 Vec 显式传参,
//! 不做 struct 状态持有(无共享可变状态约定)。零 unsafe。
use oxide_ir::IRFunction;
/// 死代码消除:块级不可达删除 + 全函数 use 计数迭代删除到不动点 + mark-sweep 重建。
pub fn dce(f: &mut IRFunction) {
// 空 IRFunction 退化形态:无指令可删(照 oxide_cfg empty_function 先例)。
// 非空路径为 Task 2/3 骨架占位:Pass A 可达性 + Pass B use 计数迭代 + Pass C mark-sweep。
if !f.insts.is_empty() {
// TODO(Task 2/3):Pass A/B/C 实现(当前骨架 no-op,等价于不改写)。
}
}