diff --git a/src/mir/GreedyAlloc.cpp b/src/mir/GreedyAlloc.cpp index eef77987..803c9e38 100644 --- a/src/mir/GreedyAlloc.cpp +++ b/src/mir/GreedyAlloc.cpp @@ -52,10 +52,8 @@ struct SpillWeightCmp const auto& lb = intervals[b]; if (la.generation != lb.generation) return la.generation > lb.generation; - // 新 vreg 按 FirstUsePos 升序:确保处理顺序与指令顺序一致, - // 这样当 vreg B 被分配时,更早的 vreg A 已在 reg_assignments_ 中 if (la.deferred_count == 0 && lb.deferred_count == 0) - return la.FirstUsePos() > lb.FirstUsePos(); + return la.Length() > lb.Length(); return la.spill_weight < lb.spill_weight; } }; @@ -534,7 +532,6 @@ static void AllocateRegistersForFunction(MachineFunction &function) // ---- 阶段 0:活跃分析 + 预处理 ---- auto raw = ComputeInstLiveness(function); auto intervals = EnhanceIntervals(raw, function); - intervals.reserve(function.GetNumVRegs() * 16); auto &blocks = function.GetBlocks(); std::vector pos_to_block; @@ -552,7 +549,7 @@ static void AllocateRegistersForFunction(MachineFunction &function) auto block_depth = AnalyzeLoopDepth(function); ComputeSpillWeights(intervals, block_depth, pos_to_block); PropagateCopyHints(intervals, function); - intervals.reserve(function.GetNumVRegs() * 16); + intervals.reserve(function.GetNumVRegs() * 4); // LLVM 风格:全局 cascade 计数器 int global_cascade = 1; @@ -664,7 +661,6 @@ static void AllocateRegistersForFunction(MachineFunction &function) // ---- 重新分析活跃 ---- raw = ComputeInstLiveness(function); intervals = EnhanceIntervals(raw, function); - intervals.reserve(function.GetNumVRegs() * 16); // ---- 重建位置映射 ---- pos_to_block.clear();