Skip to main content

luaur_code_gen/functions/
find_common_dominator.rs

1use crate::records::block_ordering::BlockOrdering;
2
3pub fn find_common_dominator(
4    idoms: &Vec<u32>,
5    data: &Vec<BlockOrdering>,
6    mut a: u32,
7    mut b: u32,
8) -> u32 {
9    while a != b {
10        while data[a as usize].postOrder < data[b as usize].postOrder {
11            a = idoms[a as usize];
12            if a == !0u32 {
13                // Keep behavior native-only assertion without relying on CODEGEN_ASSERT.
14                panic!("CODEGEN_ASSERT failed: a != !0u32");
15            }
16        }
17
18        while data[b as usize].postOrder < data[a as usize].postOrder {
19            b = idoms[b as usize];
20            if b == !0u32 {
21                // Keep behavior native-only assertion without relying on CODEGEN_ASSERT.
22                panic!("CODEGEN_ASSERT failed: b != !0u32");
23            }
24        }
25    }
26
27    a
28}