feat: 管线接入 liveness/精确DCE/RegAlloc + --no-regalloc flag(D-17/D-18)

This commit is contained in:
2026-08-06 17:56:55 +08:00
parent 08f061dfd3
commit d3385bc838
6 changed files with 53 additions and 17 deletions
+8 -7
View File
@@ -13,7 +13,13 @@ use crate::IRFunction;
/// IRFunction → CompiledModule。错误消息与现状(退役前 compiler.rs)逐字一致。
pub fn lower(f: &IRFunction) -> Result<CompiledModule, String> {
// 溢出检查 1:寄存器(仅 Operand::Reg 变体;This/NewTarget 是语义操作数,映射 254/255 合法)
// 溢出检查 1:常量池(先于寄存器——超大常量池伴生的海量 vreg 会使后续检查的
// 稠密 bitset 表示爆内存;常量池超限是更基础的失效,先报它)
if f.const_overflow || f.constants.len() > u16::MAX as usize {
return Err("RangeError: too many constants".into());
}
// 溢出检查 2:寄存器(仅 Operand::Reg 变体;This/NewTarget 是语义操作数,映射 254/255 合法)
for inst in &f.insts {
for o in [&inst.rd, &inst.a, &inst.b] {
if let Operand::Reg(r) = o {
@@ -24,18 +30,13 @@ pub fn lower(f: &IRFunction) -> Result<CompiledModule, String> {
}
}
// 溢出检查 1b:n_registers(u32 → CompiledModule u8 前的显式截断检查)。
// 溢出检查 2b:n_registers(u32 → CompiledModule u8 前的显式截断检查)。
// n_registers = max_regs = 最高分配号 + 1,合法上限 254(reg 0..253)。
// 纯参数/空体函数可能无指令引用最高号寄存器,逐指令检查漏掉,计数检查兜底防 u8 静默截断。
if f.n_registers > 254 {
return Err("RangeError: function body uses too many registers (max 253)".into());
}
// 溢出检查 2:常量池
if f.const_overflow || f.constants.len() > u16::MAX as usize {
return Err("RangeError: too many constants".into());
}
let mut instrs: Vec<u32> = Vec::new();
let mut inst_to_instr: Vec<usize> = Vec::with_capacity(f.insts.len());
// (当前指令的起始 Instr index, label id)