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

@ -24,6 +24,7 @@ use super::{lower_stmt_list_with_vars, new_block, BridgeEnv, LoopContext};
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
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 std::collections::HashMap;
use super::super::ast::StmtV0;
use super::super::ast::ExprV0;
@ -337,22 +338,25 @@ pub(super) fn lower_loop_stmt(
}
// 6-2) continue_merge_bb に必要な PHI を生成しつつ、merged_snapshot を作る
// Phase 26-B-3: Use PhiInputCollector
let mut merged_snapshot: HashMap<String, ValueId> = HashMap::new();
for (name, mut inputs) in all_inputs {
let value = if let Some(same_val) =
LoopSnapshotMergeBox::optimize_same_value(&inputs)
{
for (name, inputs) in all_inputs {
let mut collector = PhiInputCollector::new();
collector.add_snapshot(&inputs);
collector.sanitize();
let value = if let Some(same_val) = collector.optimize_same_value() {
// 全て同じ値 or 単一入力 → PHI 不要
same_val
} else {
// 異なる値を持つ場合は PHI ノードを continue_merge_bb に生成
LoopSnapshotMergeBox::sanitize_inputs(&mut inputs);
let final_inputs = collector.finalize();
let phi_id = ops.f.next_value_id();
crate::mir::ssot::cf_common::insert_phi_at_head(
ops.f,
continue_merge_bb,
phi_id,
inputs,
final_inputs,
);
phi_id
};