diff options
| author | gdk <gab.dark.100@gmail.com> | 2019-10-13 03:02:07 -0300 |
|---|---|---|
| committer | Thog <thog@protonmail.com> | 2020-01-09 02:13:00 +0100 |
| commit | 1876b346fea647e8284a66bb6d62c38801035cff (patch) | |
| tree | 6eeff094298cda84d1613dc5ec0691e51d7b35f1 /Ryujinx.Graphics/Shader/Translation/ControlFlowGraph.cs | |
| parent | f617fb542a0e3d36012d77a4b5acbde7b08902f2 (diff) | |
Initial work
Diffstat (limited to 'Ryujinx.Graphics/Shader/Translation/ControlFlowGraph.cs')
| -rw-r--r-- | Ryujinx.Graphics/Shader/Translation/ControlFlowGraph.cs | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/Ryujinx.Graphics/Shader/Translation/ControlFlowGraph.cs b/Ryujinx.Graphics/Shader/Translation/ControlFlowGraph.cs deleted file mode 100644 index e2ca74a4..00000000 --- a/Ryujinx.Graphics/Shader/Translation/ControlFlowGraph.cs +++ /dev/null @@ -1,108 +0,0 @@ -using Ryujinx.Graphics.Shader.IntermediateRepresentation; -using System.Collections.Generic; - -namespace Ryujinx.Graphics.Shader.Translation -{ - static class ControlFlowGraph - { - public static BasicBlock[] MakeCfg(Operation[] operations) - { - Dictionary<Operand, BasicBlock> labels = new Dictionary<Operand, BasicBlock>(); - - List<BasicBlock> blocks = new List<BasicBlock>(); - - BasicBlock currentBlock = null; - - void NextBlock(BasicBlock nextBlock) - { - if (currentBlock != null && !EndsWithUnconditionalInst(currentBlock.GetLastOp())) - { - currentBlock.Next = nextBlock; - } - - currentBlock = nextBlock; - } - - void NewNextBlock() - { - BasicBlock block = new BasicBlock(blocks.Count); - - blocks.Add(block); - - NextBlock(block); - } - - bool needsNewBlock = true; - - for (int index = 0; index < operations.Length; index++) - { - Operation operation = operations[index]; - - if (operation.Inst == Instruction.MarkLabel) - { - Operand label = operation.Dest; - - if (labels.TryGetValue(label, out BasicBlock nextBlock)) - { - nextBlock.Index = blocks.Count; - - blocks.Add(nextBlock); - - NextBlock(nextBlock); - } - else - { - NewNextBlock(); - - labels.Add(label, currentBlock); - } - } - else - { - if (needsNewBlock) - { - NewNextBlock(); - } - - currentBlock.Operations.AddLast(operation); - } - - needsNewBlock = operation.Inst == Instruction.Branch || - operation.Inst == Instruction.BranchIfTrue || - operation.Inst == Instruction.BranchIfFalse; - - if (needsNewBlock) - { - Operand label = operation.Dest; - - if (!labels.TryGetValue(label, out BasicBlock branchBlock)) - { - branchBlock = new BasicBlock(); - - labels.Add(label, branchBlock); - } - - currentBlock.Branch = branchBlock; - } - } - - return blocks.ToArray(); - } - - private static bool EndsWithUnconditionalInst(INode node) - { - if (node is Operation operation) - { - switch (operation.Inst) - { - case Instruction.Branch: - case Instruction.Discard: - case Instruction.Return: - return true; - } - } - - return false; - } - } -}
\ No newline at end of file |
