aboutsummaryrefslogtreecommitdiff
path: root/src/ARMeilleure/Translation/SsaDeconstruction.cs
diff options
context:
space:
mode:
authorTSR Berry <20988865+TSRBerry@users.noreply.github.com>2023-04-08 01:22:00 +0200
committerMary <thog@protonmail.com>2023-04-27 23:51:14 +0200
commitcee712105850ac3385cd0091a923438167433f9f (patch)
tree4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /src/ARMeilleure/Translation/SsaDeconstruction.cs
parentcd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff)
Move solution and projects to src
Diffstat (limited to 'src/ARMeilleure/Translation/SsaDeconstruction.cs')
-rw-r--r--src/ARMeilleure/Translation/SsaDeconstruction.cs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/ARMeilleure/Translation/SsaDeconstruction.cs b/src/ARMeilleure/Translation/SsaDeconstruction.cs
new file mode 100644
index 00000000..cd6bcca1
--- /dev/null
+++ b/src/ARMeilleure/Translation/SsaDeconstruction.cs
@@ -0,0 +1,48 @@
+using ARMeilleure.IntermediateRepresentation;
+
+using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
+using static ARMeilleure.IntermediateRepresentation.Operation.Factory;
+
+namespace ARMeilleure.Translation
+{
+ static partial class Ssa
+ {
+ public static void Deconstruct(ControlFlowGraph cfg)
+ {
+ for (BasicBlock block = cfg.Blocks.First; block != null; block = block.ListNext)
+ {
+ Operation operation = block.Operations.First;
+
+ while (operation != default && operation.Instruction == Instruction.Phi)
+ {
+ Operation nextNode = operation.ListNext;
+
+ Operand local = Local(operation.Destination.Type);
+
+ PhiOperation phi = operation.AsPhi();
+
+ for (int index = 0; index < phi.SourcesCount; index++)
+ {
+ BasicBlock predecessor = phi.GetBlock(cfg, index);
+
+ Operand source = phi.GetSource(index);
+
+ predecessor.Append(Operation(Instruction.Copy, local, source));
+
+ phi.SetSource(index, default);
+ }
+
+ Operation copyOp = Operation(Instruction.Copy, operation.Destination, local);
+
+ block.Operations.AddBefore(operation, copyOp);
+
+ operation.Destination = default;
+
+ block.Operations.Remove(operation);
+
+ operation = nextNode;
+ }
+ }
+ }
+ }
+} \ No newline at end of file