refactor(mir): phase260 p0 edge-args plumbing (strangler) + ssot api + docs

This commit is contained in:
2025-12-21 04:34:22 +09:00
parent 4496b6243d
commit 4dfe3349bf
42 changed files with 1044 additions and 187 deletions

View File

@ -30,17 +30,19 @@ mod tests {
// Entry block (bb0): branch on cond
let mut entry = BasicBlock::new(BasicBlockId::new(0));
entry.terminator = Some(MirInstruction::Branch {
entry.set_terminator(MirInstruction::Branch {
condition: ValueId(0), // cond parameter
then_bb: BasicBlockId::new(1),
else_bb: BasicBlockId::new(2),
then_edge_args: None,
else_edge_args: None,
});
blocks.insert(BasicBlockId::new(0), entry);
// Then block (bb1): return 10
// NOTE: Pattern matcher expects empty blocks (Return only)
let mut then_block = BasicBlock::new(BasicBlockId::new(1));
then_block.terminator = Some(MirInstruction::Return {
then_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(1)), // Assumes ValueId(1) is const 10
});
blocks.insert(BasicBlockId::new(1), then_block);
@ -48,7 +50,7 @@ mod tests {
// Else block (bb2): return 20
// NOTE: Pattern matcher expects empty blocks (Return only)
let mut else_block = BasicBlock::new(BasicBlockId::new(2));
else_block.terminator = Some(MirInstruction::Return {
else_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(2)), // Assumes ValueId(2) is const 20
});
blocks.insert(BasicBlockId::new(2), else_block);
@ -78,10 +80,12 @@ mod tests {
// Entry block (bb0): branch on cond
let mut entry = BasicBlock::new(BasicBlockId::new(0));
entry.terminator = Some(MirInstruction::Branch {
entry.set_terminator(MirInstruction::Branch {
condition: ValueId(0), // cond
then_bb: BasicBlockId::new(1),
else_bb: BasicBlockId::new(2),
then_edge_args: None,
else_edge_args: None,
});
blocks.insert(BasicBlockId::new(0), entry);
@ -92,8 +96,9 @@ mod tests {
dst: ValueId(3), // x
src: ValueId(10), // Assumes ValueId(10) is const 100
});
then_block.terminator = Some(MirInstruction::Jump {
then_block.set_terminator(MirInstruction::Jump {
target: BasicBlockId::new(3),
edge_args: None,
});
blocks.insert(BasicBlockId::new(1), then_block);
@ -104,14 +109,15 @@ mod tests {
dst: ValueId(3), // x
src: ValueId(20), // Assumes ValueId(20) is const 200
});
else_block.terminator = Some(MirInstruction::Jump {
else_block.set_terminator(MirInstruction::Jump {
target: BasicBlockId::new(3),
edge_args: None,
});
blocks.insert(BasicBlockId::new(2), else_block);
// Merge block (bb3): return x
let mut merge_block = BasicBlock::new(BasicBlockId::new(3));
merge_block.terminator = Some(MirInstruction::Return {
merge_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(3)),
});
blocks.insert(BasicBlockId::new(3), merge_block);
@ -408,10 +414,12 @@ mod tests {
// Entry block (bb0): branch on cond
let mut entry = BasicBlock::new(BasicBlockId::new(0));
entry.terminator = Some(MirInstruction::Branch {
entry.set_terminator(MirInstruction::Branch {
condition: ValueId(0), // cond
then_bb: BasicBlockId::new(1),
else_bb: BasicBlockId::new(2),
then_edge_args: None,
else_edge_args: None,
});
blocks.insert(BasicBlockId::new(0), entry);
@ -425,7 +433,7 @@ mod tests {
dst: ValueId(4), // y = 2
value: crate::mir::ConstValue::Integer(2),
});
then_block.terminator = Some(MirInstruction::Return {
then_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(10)), // result (x + y computed elsewhere)
});
blocks.insert(BasicBlockId::new(1), then_block);
@ -440,7 +448,7 @@ mod tests {
dst: ValueId(4), // y = 4 (same dst as then!)
value: crate::mir::ConstValue::Integer(4),
});
else_block.terminator = Some(MirInstruction::Return {
else_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(20)), // result (x + y computed elsewhere)
});
blocks.insert(BasicBlockId::new(2), else_block);
@ -470,10 +478,12 @@ mod tests {
// Entry block (bb0): branch on cond
let mut entry = BasicBlock::new(BasicBlockId::new(0));
entry.terminator = Some(MirInstruction::Branch {
entry.set_terminator(MirInstruction::Branch {
condition: ValueId(0), // cond
then_bb: BasicBlockId::new(1),
else_bb: BasicBlockId::new(2),
then_edge_args: None,
else_edge_args: None,
});
blocks.insert(BasicBlockId::new(0), entry);
@ -491,7 +501,7 @@ mod tests {
dst: ValueId(5), // z = 30
value: crate::mir::ConstValue::Integer(30),
});
then_block.terminator = Some(MirInstruction::Return {
then_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(10)), // result (x + y + z computed elsewhere)
});
blocks.insert(BasicBlockId::new(1), then_block);
@ -510,7 +520,7 @@ mod tests {
dst: ValueId(5), // z = 60 (same dst as then!)
value: crate::mir::ConstValue::Integer(60),
});
else_block.terminator = Some(MirInstruction::Return {
else_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(20)), // result (x + y + z computed elsewhere)
});
blocks.insert(BasicBlockId::new(2), else_block);
@ -632,23 +642,25 @@ mod tests {
dst: ValueId(2),
value: crate::mir::ConstValue::Integer(20),
});
entry.terminator = Some(MirInstruction::Branch {
entry.set_terminator(MirInstruction::Branch {
condition: ValueId(0), // cond parameter
then_bb: BasicBlockId::new(1),
else_bb: BasicBlockId::new(2),
then_edge_args: None,
else_edge_args: None,
});
blocks.insert(BasicBlockId::new(0), entry);
// Then block (bb1): return 10
let mut then_block = BasicBlock::new(BasicBlockId::new(1));
then_block.terminator = Some(MirInstruction::Return {
then_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(1)), // const 10
});
blocks.insert(BasicBlockId::new(1), then_block);
// Else block (bb2): return 20
let mut else_block = BasicBlock::new(BasicBlockId::new(2));
else_block.terminator = Some(MirInstruction::Return {
else_block.set_terminator(MirInstruction::Return {
value: Some(ValueId(2)), // const 20
});
blocks.insert(BasicBlockId::new(2), else_block);

View File

@ -95,10 +95,12 @@ fn phase67_ab_test_resolve_from_phi_equivalence() {
dst: cond,
value: ConstValue::Bool(true),
});
f.get_block_mut(entry).unwrap().terminator = Some(MirInstruction::Branch {
f.get_block_mut(entry).unwrap().set_terminator(MirInstruction::Branch {
condition: cond,
then_bb,
else_bb,
then_edge_args: None,
else_edge_args: None,
});
// Then: v2 = 42
@ -109,7 +111,10 @@ fn phase67_ab_test_resolve_from_phi_equivalence() {
dst: v2,
value: ConstValue::Integer(42),
});
f.get_block_mut(then_bb).unwrap().terminator = Some(MirInstruction::Jump { target: merge_bb });
f.get_block_mut(then_bb).unwrap().set_terminator(MirInstruction::Jump {
target: merge_bb,
edge_args: None,
});
// Else: v3 = 0
let v3 = f.next_value_id();
@ -119,7 +124,10 @@ fn phase67_ab_test_resolve_from_phi_equivalence() {
dst: v3,
value: ConstValue::Integer(0),
});
f.get_block_mut(else_bb).unwrap().terminator = Some(MirInstruction::Jump { target: merge_bb });
f.get_block_mut(else_bb).unwrap().set_terminator(MirInstruction::Jump {
target: merge_bb,
edge_args: None,
});
// Merge: v4 = phi(v2 from then, v3 from else)
let v4 = f.next_value_id();