refactor(phi): Phase 59b PhiInputCollector inline in loop_builder.rs
Inline PhiInputCollector usage in loop_builder.rs continue merge logic. This is the last remaining callsite of PhiInputCollector. Changes: - Inline sanitize pattern (BTreeMap for dedup and sort) - Inline optimize_same_value logic - Comment out use statement This completes the PhiInputCollector usage elimination from: - loopform_builder.rs (Phase 59) - loop_builder.rs (Phase 59b) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -24,7 +24,8 @@ use super::{BasicBlockId, ConstValue, MirInstruction, ValueId};
|
||||
use crate::ast::ASTNode;
|
||||
use crate::mir::control_form::{is_control_form_trace_on, ControlForm, IfShape, LoopShape};
|
||||
use crate::mir::phi_core::loopform_builder::{LoopFormBuilder, LoopFormOps};
|
||||
use crate::mir::phi_core::phi_input_collector::PhiInputCollector;
|
||||
// Phase 59b: PhiInputCollector は loop_builder.rs 内にインライン化済み
|
||||
// use crate::mir::phi_core::phi_input_collector::PhiInputCollector;
|
||||
use std::collections::{BTreeMap, BTreeSet}; // Phase 25.1: 決定性確保
|
||||
|
||||
// Phase 15 段階的根治戦略:制御フローユーティリティ
|
||||
@ -517,22 +518,39 @@ impl<'a> LoopBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
// 各変数について PHI ノードを生成(Phase 26-B-3: PhiInputCollector使用)
|
||||
// 各変数について PHI ノードを生成
|
||||
// ========================================
|
||||
// Phase 59b: PhiInputCollector インライン化
|
||||
// ========================================
|
||||
let mut merged = BTreeMap::new();
|
||||
for (var_name, inputs) in all_vars {
|
||||
// Phase 26-B-3: Use PhiInputCollector
|
||||
let mut collector = PhiInputCollector::new();
|
||||
collector.add_snapshot(&inputs);
|
||||
collector.sanitize();
|
||||
// Step 1: sanitize (BTreeMap で重複削除&ソート)
|
||||
let mut sanitized: BTreeMap<BasicBlockId, ValueId> = BTreeMap::new();
|
||||
for (bb, val) in &inputs {
|
||||
sanitized.insert(*bb, *val);
|
||||
}
|
||||
let final_inputs: Vec<(BasicBlockId, ValueId)> = sanitized.into_iter().collect();
|
||||
|
||||
// Phase 25.2: optimize_same_value() で最適化判定
|
||||
let result_value = if let Some(same_val) = collector.optimize_same_value() {
|
||||
// Step 2: optimize_same_value
|
||||
let same_value = if final_inputs.is_empty() {
|
||||
None
|
||||
} else if final_inputs.len() == 1 {
|
||||
Some(final_inputs[0].1)
|
||||
} else {
|
||||
let first_val = final_inputs[0].1;
|
||||
if final_inputs.iter().all(|(_, val)| *val == first_val) {
|
||||
Some(first_val)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// Step 3: PHI 生成 or 同一値を使用
|
||||
let result_value = if let Some(same_val) = same_value {
|
||||
// 全て同じ値 or 単一入力 → PHI 不要
|
||||
same_val
|
||||
} else {
|
||||
// 異なる値を持つ場合は PHI ノードを生成
|
||||
let final_inputs = collector.finalize();
|
||||
|
||||
let phi_id = self.new_value();
|
||||
|
||||
if let Some(ref mut func) = self.parent_builder.current_function {
|
||||
|
||||
Reference in New Issue
Block a user