refactor(phase62): Delete phi_input_collector.rs (-384 lines)
Phase 62前倒し: PhiInputCollectorの物理削除 Changes: - Delete src/mir/phi_core/phi_input_collector.rs (-384 lines) - Inline PhiInputCollector logic in json_v0_bridge/lowering/loop_.rs - sanitize: BTreeMap dedup + sort - optimize_same_value: check all inputs for same value - Remove mod declaration in phi_core/mod.rs Rationale: - PhiInputCollector already inlined in Phase 59 (loopform_builder.rs) - Last remaining usage was in JSON v0 Bridge - Simple inline preserves exact behavior Impact: - -384 lines (Box + tests) - No behavior change (inline equivalent) - Build & test pass ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -25,7 +25,6 @@ use super::super::ast::StmtV0;
|
||||
use super::{lower_stmt_list_with_vars, new_block, BridgeEnv, LoopContext};
|
||||
use crate::ast::Span;
|
||||
use crate::mir::phi_core::loopform_builder::{LoopFormBuilder, LoopFormOps};
|
||||
use crate::mir::phi_core::phi_input_collector::PhiInputCollector;
|
||||
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@ -355,28 +354,42 @@ pub(super) fn lower_loop_stmt(
|
||||
}
|
||||
|
||||
// 6-2) continue_merge_bb に必要な PHI を生成しつつ、merged_snapshot を作る
|
||||
// Phase 26-B-3: Use PhiInputCollector
|
||||
// Phase 62: PhiInputCollector インライン化
|
||||
let mut merged_snapshot: BTreeMap<String, ValueId> = BTreeMap::new();
|
||||
for (name, inputs) in all_inputs {
|
||||
let mut collector = PhiInputCollector::new();
|
||||
collector.add_snapshot(&inputs);
|
||||
collector.sanitize();
|
||||
// Inline PhiInputCollector logic
|
||||
// 1. Sanitize: remove duplicates and sort
|
||||
let mut seen: BTreeMap<BasicBlockId, ValueId> = BTreeMap::new();
|
||||
for (bb, val) in inputs.iter() {
|
||||
seen.insert(*bb, *val);
|
||||
}
|
||||
let mut sanitized_inputs: Vec<(BasicBlockId, ValueId)> = seen.into_iter().collect();
|
||||
sanitized_inputs.sort_by_key(|(bb, _)| bb.0);
|
||||
|
||||
let value = if let Some(same_val) = collector.optimize_same_value() {
|
||||
// 全て同じ値 or 単一入力 → PHI 不要
|
||||
same_val
|
||||
// 2. Optimize: check if all inputs have the same value
|
||||
let value = if sanitized_inputs.is_empty() {
|
||||
// Should not happen, but handle gracefully
|
||||
continue;
|
||||
} else if sanitized_inputs.len() == 1 {
|
||||
// Single input - no PHI needed
|
||||
sanitized_inputs[0].1
|
||||
} else {
|
||||
// 異なる値を持つ場合は PHI ノードを continue_merge_bb に生成
|
||||
let final_inputs = collector.finalize();
|
||||
let phi_id = ops.f.next_value_id();
|
||||
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
|
||||
ops.f,
|
||||
continue_merge_bb,
|
||||
phi_id,
|
||||
final_inputs,
|
||||
Span::unknown(),
|
||||
);
|
||||
phi_id
|
||||
let first_val = sanitized_inputs[0].1;
|
||||
if sanitized_inputs.iter().all(|(_, val)| *val == first_val) {
|
||||
// All same value - no PHI needed
|
||||
first_val
|
||||
} else {
|
||||
// Different values - PHI required
|
||||
let phi_id = ops.f.next_value_id();
|
||||
crate::mir::ssot::cf_common::insert_phi_at_head_spanned(
|
||||
ops.f,
|
||||
continue_merge_bb,
|
||||
phi_id,
|
||||
sanitized_inputs,
|
||||
Span::unknown(),
|
||||
);
|
||||
phi_id
|
||||
}
|
||||
};
|
||||
merged_snapshot.insert(name, value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user