private static bool PropagatePhi(PhiNode phi) { // If all phi sources are the same, we can propagate it and remove the phi. Operand firstSrc = phi.GetSource(0); for (int index = 1; index < phi.SourcesCount; index++) { if (!IsSameOperand(firstSrc, phi.GetSource(index))) { return(false); } } // All sources are equal, we can propagate the value. Operand dest = phi.Dest; INode[] uses = dest.UseOps.ToArray(); foreach (INode useNode in uses) { for (int index = 0; index < useNode.SourcesCount; index++) { if (useNode.GetSource(index) == dest) { useNode.SetSource(index, firstSrc); } } } return(true); }
private static void AddPhi(BasicBlock block, PhiNode phi) { LinkedListNode <INode> node = block.Operations.First; if (node != null) { while (node.Next?.Value is PhiNode) { node = node.Next; } } if (node?.Value is PhiNode) { block.Operations.AddAfter(node, phi); } else { block.Operations.AddFirst(phi); } }
private static void AddPhi(BasicBlock block, PhiNode phi) { Node node = block.Operations.First; if (node != null) { while (node.ListNext is PhiNode) { node = node.ListNext; } } if (node is PhiNode) { block.Operations.AddAfter(node, phi); } else { block.Operations.AddFirst(phi); } }
private static Operand InsertPhi(DefMap[] globalDefs, BasicBlock block, Register reg) { // This block has a Phi that has not been materialized yet, but that // would define a new version of the variable we're looking for. We need // to materialize the Phi, add all the block/operand pairs into the Phi, and // then use the definition from that Phi. Operand local = Local(); PhiNode phi = new PhiNode(local); AddPhi(block, phi); globalDefs[block.Index].TryAddOperand(reg, local); foreach (BasicBlock predecessor in block.Predecessors) { Definition def = FindDefinition(globalDefs, predecessor, reg); phi.AddSource(def.Block, def.Local); } return(local); }
private static Operand InsertPhi(DefMap[] globalDefs, BasicBlock block, Operand operand) { // This block has a Phi that has not been materialized yet, but that // would define a new version of the variable we're looking for. We need // to materialize the Phi, add all the block/operand pairs into the Phi, and // then use the definition from that Phi. Operand local = Local(operand.Type); PhiNode phi = new PhiNode(local, block.Predecessors.Count); AddPhi(block, phi); globalDefs[block.Index].TryAddOperand(operand.GetRegister(), local); for (int index = 0; index < block.Predecessors.Count; index++) { BasicBlock predecessor = block.Predecessors[index]; phi.SetBlock(index, predecessor); phi.SetSource(index, FindDefOnPred(globalDefs, predecessor, operand)); } return(local); }