From 215c74fe0ba1e88a9bca5f9aa7abd5e1117aed31 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Mon, 12 Oct 2026 12:05:33 +0000 Subject: [PATCH] =?UTF-8?q?perf:=20liveness=20=E5=BC=82=E5=B8=B8=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E5=9D=97=E5=88=A4=E5=AE=9A=E6=94=B9=20O(E)=20?= =?UTF-8?q?=E9=A2=84=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 40 +++++++++++++-------------- Cargo.toml | 2 +- crates/oxide_liveness/src/dataflow.rs | 21 ++++++++++---- crates/oxide_liveness/src/ranges.rs | 9 ++---- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 457d46c5..60439341 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1160,7 +1160,7 @@ dependencies = [ [[package]] name = "oxide_builtins" -version = "0.16.12" +version = "0.16.13" dependencies = [ "chrono", "fast-float", @@ -1185,7 +1185,7 @@ dependencies = [ [[package]] name = "oxide_bytecode" -version = "0.16.12" +version = "0.16.13" dependencies = [ "num-bigint", "oxide_log", @@ -1193,7 +1193,7 @@ dependencies = [ [[package]] name = "oxide_cfg" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxide_bytecode", "oxide_emit", @@ -1204,7 +1204,7 @@ dependencies = [ [[package]] name = "oxide_cli" -version = "0.16.12" +version = "0.16.13" dependencies = [ "ansi_term", "bumpalo", @@ -1228,7 +1228,7 @@ dependencies = [ [[package]] name = "oxide_code_cache" -version = "0.16.12" +version = "0.16.13" dependencies = [ "lru", "oxide_bytecode", @@ -1237,7 +1237,7 @@ dependencies = [ [[package]] name = "oxide_compiler" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1257,7 +1257,7 @@ dependencies = [ [[package]] name = "oxide_dce" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1271,7 +1271,7 @@ dependencies = [ [[package]] name = "oxide_emit" -version = "0.16.12" +version = "0.16.13" dependencies = [ "num-bigint", "oxc_allocator", @@ -1286,7 +1286,7 @@ dependencies = [ [[package]] name = "oxide_engine" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxide_bytecode", "oxide_compiler", @@ -1298,7 +1298,7 @@ dependencies = [ [[package]] name = "oxide_ir" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxide_bytecode", "oxide_log", @@ -1307,7 +1307,7 @@ dependencies = [ [[package]] name = "oxide_kernel" -version = "0.16.12" +version = "0.16.13" dependencies = [ "bumpalo", "dashmap", @@ -1321,7 +1321,7 @@ dependencies = [ [[package]] name = "oxide_liveness" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1333,7 +1333,7 @@ dependencies = [ [[package]] name = "oxide_log" -version = "0.16.12" +version = "0.16.13" dependencies = [ "tracing", "tracing-appender", @@ -1342,11 +1342,11 @@ dependencies = [ [[package]] name = "oxide_net" -version = "0.16.12" +version = "0.16.13" [[package]] name = "oxide_parser" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1361,7 +1361,7 @@ dependencies = [ [[package]] name = "oxide_regalloc" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1377,7 +1377,7 @@ dependencies = [ [[package]] name = "oxide_runtime_api" -version = "0.16.12" +version = "0.16.13" dependencies = [ "num-bigint", "num-traits", @@ -1390,7 +1390,7 @@ dependencies = [ [[package]] name = "oxide_test262" -version = "0.16.12" +version = "0.16.13" dependencies = [ "oxide_bytecode", "oxide_compiler", @@ -1410,7 +1410,7 @@ dependencies = [ [[package]] name = "oxide_types" -version = "0.16.12" +version = "0.16.13" dependencies = [ "bumpalo", "dashmap", @@ -1423,7 +1423,7 @@ dependencies = [ [[package]] name = "oxide_vm" -version = "0.16.12" +version = "0.16.13" dependencies = [ "bumpalo", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 5e3d26de..e4bed476 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ members = [ ] [workspace.package] -version = "0.16.12" +version = "0.16.13" edition = "2021" license = "MIT" rust-version = "1.80" diff --git a/crates/oxide_liveness/src/dataflow.rs b/crates/oxide_liveness/src/dataflow.rs index 3508f03e..58c3f02d 100644 --- a/crates/oxide_liveness/src/dataflow.rs +++ b/crates/oxide_liveness/src/dataflow.rs @@ -33,6 +33,7 @@ pub(super) fn block_liveness(f: &IRFunction, cfg: &Cfg) -> (Vec>, Vec> = vec![vec![0u64; words]; n]; let mut kill: Vec> = vec![vec![0u64; words]; n]; + let exc_targets = exception_target_blocks(cfg); for (b, block) in cfg.blocks.iter().enumerate() { // gen:块内反向扫描,kill 先于 gen(`live = (live − def) ∪ use`)。 // 顺序理由:COMPOUND_ADD 等读-写同寄存器指令的 uses 含 Rd(见 oxide_ir::contract 的 def/use 约定), @@ -58,11 +59,7 @@ pub(super) fn block_liveness(f: &IRFunction, cfg: &Cfg) -> (Vec>, Vec(无 EdgeKind),须从源块 succs 侧检测 Exception 边。 - let is_exception_target = cfg - .blocks - .iter() - .any(|src| src.succs.iter().any(|&(dst, k)| dst == b && k == EdgeKind::Exception)); - if is_exception_target { + if exc_targets[b] { bitset_clear(&mut gen[b], 0); bitset_set(&mut kill[b], 0); } @@ -108,6 +105,20 @@ pub(super) fn block_liveness(f: &IRFunction, cfg: &Cfg) -> (Vec>, Vec Vec { + let mut targets = vec![false; cfg.blocks.len()]; + for block in &cfg.blocks { + for &(dst, kind) in &block.succs { + if kind == EdgeKind::Exception { + targets[dst] = true; + } + } + } + targets +} + /// 从 entry 出发 DFS 沿 succs 存储序(确定序)收集 postorder 后反转; /// 不可达块按升序追加在末尾。纯 Vec + visited 位图,保证确定性。 fn reverse_postorder(cfg: &Cfg) -> Vec { diff --git a/crates/oxide_liveness/src/ranges.rs b/crates/oxide_liveness/src/ranges.rs index cfdc8048..3b9c57dc 100644 --- a/crates/oxide_liveness/src/ranges.rs +++ b/crates/oxide_liveness/src/ranges.rs @@ -8,7 +8,7 @@ //! //! 位集为 `u64` 压缩(与 dataflow 同 words 布局),逐指令集经 `copy_from_slice` 落地。 -use oxide_cfg::{Cfg, EdgeKind}; +use oxide_cfg::Cfg; use oxide_ir::IRFunction; use crate::live_info::{bitset_clear, bitset_set}; @@ -20,6 +20,7 @@ pub(super) fn inst_liveness( let words = (reg_count + 1).div_ceil(64); let mut before = vec![vec![0u64; words]; f.insts.len()]; let mut after = vec![vec![0u64; words]; f.insts.len()]; + let exc_targets = crate::dataflow::exception_target_blocks(cfg); for (b, block) in cfg.blocks.iter().enumerate() { let mut live = block_live_out[b].clone(); // 从块级 liveOut 出发(非 liveIn) for i in block.inst_range.clone().rev() { @@ -36,11 +37,7 @@ pub(super) fn inst_liveness( } // Exception 目标块:入口 reg 0 隐式 def(异常展开写 regs[0])截断无 def use。 // preds 是 Vec(无 EdgeKind),从源块 succs 侧检测 Exception 边。 - let is_exception_target = cfg - .blocks - .iter() - .any(|src| src.succs.iter().any(|&(dst, k)| dst == b && k == EdgeKind::Exception)); - if is_exception_target { + if exc_targets[b] { bitset_clear(&mut live, 0); } debug_assert_eq!(live, block_live_in[b], "ranges 反向扫描与 dataflow liveIn 不一致,块 {b}");