From a44229bee704afcfcf386f4e7a0a08b57dd2e7ba Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Sun, 27 Sep 2026 16:59:57 +0000 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=9F=93=E8=89=B2=E5=9B=BE=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=8C=89=E6=B4=BB=E7=82=B9=E9=A2=84=E5=88=86=E7=BB=84?= =?UTF-8?q?=20fresh=EF=BC=8C=E6=B6=88=E9=99=A4=E9=80=90=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=85=A8=E6=89=AB=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_regalloc/src/graph.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/oxide_regalloc/src/graph.rs b/crates/oxide_regalloc/src/graph.rs index f3d84eb3..529619d0 100644 --- a/crates/oxide_regalloc/src/graph.rs +++ b/crates/oxide_regalloc/src/graph.rs @@ -250,6 +250,13 @@ pub(super) fn build( for &v in &node_ids { adj_sets.entry(v).or_default(); } + // fresh 按 at(活点指令下标)预分组:逐指令查 fresh 由 O(fresh) 降为 O(1), + // 避免 O(inst × fresh) 全扫描(长活 vreg 被 spill 时 fresh 可达指令数量级)。 + // 同 at 的 id 保持插入序,逐指令并入顺序与原线性扫描逐字节一致(确定性不漂移)。 + let mut fresh_by_at: BTreeMap> = BTreeMap::new(); + for fr in fresh { + fresh_by_at.entry(fr.at).or_default().push(fr.id); + } for i in 0..inst_count { // 只遍历该指令活集中置位的 vreg(u64 位集逐字 trailing_zeros 升序), // 替代逐 node 全扫描——活集小(典型 2-4)时每指令从 O(nodes) 降到 O(live)。 @@ -267,10 +274,8 @@ pub(super) fn build( bits &= bits - 1; } } - for fr in fresh { - if fr.at == i { - at_i.push(fr.id); - } + if let Some(ids) = fresh_by_at.get(&i) { + at_i.extend_from_slice(ids); } // 两两加边(基于 live_before:约束 use/def 与执行前存活值) for a in 0..at_i.len() {