Move solution and projects to src
This commit is contained in:
48
src/ARMeilleure/Translation/SsaDeconstruction.cs
Normal file
48
src/ARMeilleure/Translation/SsaDeconstruction.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user