refactor(phi): Phase 26-B-3 - loop_builder.rs and json_v0_bridge PhiInputCollector integration

- loop_builder.rs: Replace LoopSnapshotMergeBox calls with PhiInputCollector for continue-merge PHI generation
- json_v0_bridge/lowering/loop_.rs: Replace LoopSnapshotMergeBox calls with PhiInputCollector for continue_merge_bb PHI generation
- Unified PHI input handling across all loop builders (loopform_builder, loop_builder, json_v0_bridge)
- Tests: mir_loopform_exit_phi all passed (4/4)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-20 18:07:11 +09:00
parent 059533876e
commit 26288b5451
2 changed files with 21 additions and 12 deletions

View File

@ -9,6 +9,7 @@ use super::{BasicBlockId, ConstValue, MirInstruction, ValueId};
use crate::mir::control_form::{ControlForm, IfShape, LoopShape, is_control_form_trace_on};
use crate::mir::phi_core::loopform_builder::{LoopFormBuilder, LoopFormOps};
use crate::mir::phi_core::loop_snapshot_merge::LoopSnapshotMergeBox;
use crate::mir::phi_core::phi_input_collector::PhiInputCollector;
use crate::ast::ASTNode;
use std::collections::HashMap;
@ -431,17 +432,21 @@ impl<'a> LoopBuilder<'a> {
}
}
// 各変数について PHI ノードを生成(LoopSnapshotMergeBox の最適化を使用)
// 各変数について PHI ノードを生成(Phase 26-B-3: PhiInputCollector使用)
let mut merged = HashMap::new();
for (var_name, mut inputs) in all_vars {
for (var_name, inputs) in all_vars {
// Phase 26-B-3: Use PhiInputCollector
let mut collector = PhiInputCollector::new();
collector.add_snapshot(&inputs);
collector.sanitize();
// Phase 25.2: optimize_same_value() で最適化判定
let result_value = if let Some(same_val) = LoopSnapshotMergeBox::optimize_same_value(&inputs) {
let result_value = if let Some(same_val) = collector.optimize_same_value() {
// 全て同じ値 or 単一入力 → PHI 不要
same_val
} else {
// 異なる値を持つ場合は PHI ノードを生成
// Phase 25.2: sanitize_inputs() で入力を正規化
LoopSnapshotMergeBox::sanitize_inputs(&mut inputs);
let final_inputs = collector.finalize();
let phi_id = self.new_value();
@ -449,7 +454,7 @@ impl<'a> LoopBuilder<'a> {
if let Some(merge_block) = func.blocks.get_mut(&continue_merge_id) {
merge_block.add_instruction(MirInstruction::Phi {
dst: phi_id,
inputs,
inputs: final_inputs,
});
}
}