class SyntaxTree::YARV::SeaOfNodes::Compiler
def cleanup_phi_nodes
some mess we left. Ideally we wouldn't create these problems in the
We don't always build things in an optimal way. Go back and fix up
def cleanup_phi_nodes nodes.dup.each do |node| # dup because we're mutating next unless node.is_a?(PhiNode) if node.inputs.size == 1 # Remove phi nodes with a single input. connect_over(node) remove(node) elsif node.inputs.map(&:from).uniq.size == 1 # Remove phi nodes where all inputs are the same. producer_edge = node.inputs.first consumer_edge = node.outputs.find { |e| !e.to.is_a?(MergeNode) } connect( producer_edge.from, consumer_edge.to, :data, consumer_edge.label ) remove(node) end end end