feat(mir): Phase 25.1h完了 - ControlForm統合実装

**実装内容**:
-  If PHI統合: merge_modified_with_control() 経由に切り替え
-  Exit PHI統合: build_exit_phis_for_control() 経由に切り替え
-  ControlForm構築を呼び出し前に移動(重複削除)

**変更箇所**:
- src/mir/loop_builder.rs line 1184-1202: If PHI統合
  - IfShape/ControlForm構築を前に移動
  - merge_modified_at_merge_with → merge_modified_with_control
- src/mir/loop_builder.rs line 371-411: Exit PHI統合
  - LoopShape/ControlForm構築を前に移動
  - loopform.build_exit_phis → build_exit_phis_for_control

**テスト結果(全グリーン維持)**:
-  mir_stage1_using_resolver_min_fragment_verifies
-  mir_stage1_using_resolver_full_collect_entries_verifies
-  mir_stageb_loop_break_continue (2 tests)
-  mir_loopform_exit_phi (4 tests)

**技術的成果**:
- 挙動変更なし: wrapper関数が既存実装に委譲するため完全互換
- コード整理: ControlForm構築の重複削除でクリーンアップ
- 観測レイヤー活用: debug_dump()が統合後も正常動作

**Phase 25.1 完了**: ControlForm導線追加(25.1g)+ 統合実装(25.1h)

🤖 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-18 19:21:26 +09:00
parent 67ee87be80
commit 5987ccf986

View File

@ -368,42 +368,46 @@ impl<'a> LoopBuilder<'a> {
// Exit block
self.set_current_block(exit_id)?;
// NOTE(25.1g+): ControlForm 統合後は build_exit_phis_for_control(...) 経由で
// LoopShape から exit_id/branch_source_block を決める導線に寄せる予定。
// 現在は既存実装のまま(挙動変更なし)。
// Phase 25.1h: ControlForm統合版に切り替え
// continue / break のターゲットブロックをユニーク化して収集
use std::collections::HashSet;
let mut cont_set: HashSet<BasicBlockId> = HashSet::new();
let mut break_set: HashSet<BasicBlockId> = HashSet::new();
for (bb, _) in &self.continue_snapshots {
cont_set.insert(*bb);
}
for (bb, _) in &self.exit_snapshots {
break_set.insert(*bb);
}
let continue_targets: Vec<BasicBlockId> = cont_set.into_iter().collect();
let break_targets: Vec<BasicBlockId> = break_set.into_iter().collect();
// Build exit PHIs for break statements
let loop_shape = LoopShape {
preheader: preheader_id,
header: header_id,
body: body_id,
latch: latch_id,
exit: exit_id,
continue_targets,
break_targets,
};
let form = ControlForm::from_loop(loop_shape.clone());
// Build exit PHIs for break statements using ControlForm wrapper
let exit_snaps = self.exit_snapshots.clone();
loopform.build_exit_phis(self, exit_id, branch_source_block, &exit_snaps)?;
crate::mir::phi_core::loopform_builder::build_exit_phis_for_control(
&loopform,
self,
&form,
&exit_snaps,
branch_source_block,
)?;
// Pop loop context
crate::mir::builder::loops::pop_loop_context(self.parent_builder);
// ControlForm 観測: 環境フラグ未設定時は既定ONのとき LoopShape をダンプ
if is_control_form_trace_on() {
// continue / break のターゲットブロックをユニーク化して収集
use std::collections::HashSet;
let mut cont_set: HashSet<BasicBlockId> = HashSet::new();
let mut break_set: HashSet<BasicBlockId> = HashSet::new();
for (bb, _) in &self.continue_snapshots {
cont_set.insert(*bb);
}
for (bb, _) in &self.exit_snapshots {
break_set.insert(*bb);
}
let continue_targets: Vec<BasicBlockId> = cont_set.into_iter().collect();
let break_targets: Vec<BasicBlockId> = break_set.into_iter().collect();
let loop_shape = LoopShape {
preheader: preheader_id,
header: header_id,
body: body_id,
latch: latch_id,
exit: exit_id,
continue_targets,
break_targets,
};
let form = ControlForm::from_loop(loop_shape.clone());
form.debug_dump();
#[cfg(debug_assertions)]
if let Some(ref func) = self.parent_builder.current_function {
@ -1181,31 +1185,28 @@ impl<'a> LoopBuilder<'a> {
self.parent_builder.variable_map = pre_if_var_map.clone();
let mut ops = Ops(self);
// TODO(25.1g+): ControlForm 統合版に切り替えるときは、
// IfShape から ControlForm を渡して merge_modified_with_control() を呼ぶ。
// 現在は既存実装のまま(挙動変更なし)。
crate::mir::phi_core::if_phi::merge_modified_at_merge_with(
// Phase 25.1h: ControlForm統合版に切り替え
let if_shape = IfShape {
cond_block: pre_branch_bb,
then_block: then_bb,
else_block: Some(else_bb),
merge_block: merge_bb,
};
let form = ControlForm::from_if(if_shape.clone());
crate::mir::phi_core::if_phi::merge_modified_with_control(
&mut ops,
merge_bb,
then_bb,
else_bb,
then_pred_to_merge,
else_pred_to_merge,
&form,
&pre_if_var_map,
&then_var_map_end,
&else_var_map_end_opt,
None,
then_pred_to_merge,
else_pred_to_merge,
)?;
// ControlForm 観測: 環境フラグ未設定時は既定ONのとき IfShape をダンプ
if is_control_form_trace_on() {
let if_shape = IfShape {
cond_block: pre_branch_bb,
then_block: then_bb,
else_block: Some(else_bb),
merge_block: merge_bb,
};
let form = ControlForm::from_if(if_shape.clone());
form.debug_dump();
#[cfg(debug_assertions)]
if let Some(ref func) = self.parent_builder.current_function {