Skip to main content

luaur_bytecode/methods/
bytecode_graph_parser_add_to_phi.rs

1use crate::enums::bc_op_kind::BcOpKind;
2use crate::records::bc_function::BcFunction;
3use crate::records::bc_op::BcOp;
4use crate::records::bc_phi::BcPhi;
5use luaur_common::macros::luau_assert::LUAU_ASSERT;
6use luaur_common::records::small_vector::SmallVector;
7
8impl<'a> crate::records::bytecode_graph_parser::BytecodeGraphParser<'a> {
9    pub fn add_to_phi(&mut self, op: BcOp, proj: BcOp) -> BcOp {
10        if op.kind == BcOpKind::Phi {
11            let phi = self.func.phi_op(op);
12            for &p in &phi.ops {
13                if p == proj {
14                    return op;
15                }
16            }
17            phi.ops.push_back(proj);
18            op
19        } else {
20            let res = self.func.add_phi();
21            let phi = self.func.phi_op(res);
22            phi.ops = SmallVector::from_iter([op, proj]);
23            res
24        }
25    }
26}