SsaDeconstruction.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using ARMeilleure.IntermediateRepresentation;
  2. using static ARMeilleure.IntermediateRepresentation.OperandHelper;
  3. using static ARMeilleure.IntermediateRepresentation.OperationHelper;
  4. namespace ARMeilleure.Translation
  5. {
  6. static partial class Ssa
  7. {
  8. public static void Deconstruct(ControlFlowGraph cfg)
  9. {
  10. for (BasicBlock block = cfg.Blocks.First; block != null; block = block.ListNext)
  11. {
  12. Node node = block.Operations.First;
  13. while (node is PhiNode phi)
  14. {
  15. Node nextNode = node.ListNext;
  16. Operand local = Local(phi.Destination.Type);
  17. for (int index = 0; index < phi.SourcesCount; index++)
  18. {
  19. BasicBlock predecessor = phi.GetBlock(index);
  20. Operand source = phi.GetSource(index);
  21. predecessor.Append(Operation(Instruction.Copy, local, source));
  22. phi.SetSource(index, null);
  23. }
  24. Operation copyOp = Operation(Instruction.Copy, phi.Destination, local);
  25. block.Operations.AddBefore(node, copyOp);
  26. phi.Destination = null;
  27. block.Operations.Remove(node);
  28. node = nextNode;
  29. }
  30. }
  31. }
  32. }
  33. }