aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/CodeGen/Optimizations/BlockPlacement.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 /ARMeilleure/CodeGen/Optimizations/BlockPlacement.cs
parentcd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff)
Move solution and projects to src
Diffstat (limited to 'ARMeilleure/CodeGen/Optimizations/BlockPlacement.cs')
-rw-r--r--ARMeilleure/CodeGen/Optimizations/BlockPlacement.cs72
1 files changed, 0 insertions, 72 deletions
diff --git a/ARMeilleure/CodeGen/Optimizations/BlockPlacement.cs b/ARMeilleure/CodeGen/Optimizations/BlockPlacement.cs
deleted file mode 100644
index 9e243d37..00000000
--- a/ARMeilleure/CodeGen/Optimizations/BlockPlacement.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using ARMeilleure.IntermediateRepresentation;
-using ARMeilleure.Translation;
-using System.Diagnostics;
-using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
-
-namespace ARMeilleure.CodeGen.Optimizations
-{
- static class BlockPlacement
- {
- public static void RunPass(ControlFlowGraph cfg)
- {
- bool update = false;
-
- BasicBlock block;
- BasicBlock nextBlock;
-
- BasicBlock lastBlock = cfg.Blocks.Last;
-
- // Move cold blocks at the end of the list, so that they are emitted away from hot code.
- for (block = cfg.Blocks.First; block != null; block = nextBlock)
- {
- nextBlock = block.ListNext;
-
- if (block.Frequency == BasicBlockFrequency.Cold)
- {
- cfg.Blocks.Remove(block);
- cfg.Blocks.AddLast(block);
- }
-
- if (block == lastBlock)
- {
- break;
- }
- }
-
- for (block = cfg.Blocks.First; block != null; block = nextBlock)
- {
- nextBlock = block.ListNext;
-
- if (block.SuccessorsCount == 2)
- {
- Operation branchOp = block.Operations.Last;
-
- Debug.Assert(branchOp.Instruction == Instruction.BranchIf);
-
- BasicBlock falseSucc = block.GetSuccessor(0);
- BasicBlock trueSucc = block.GetSuccessor(1);
-
- // If true successor is next block in list, invert the condition. We avoid extra branching by
- // making the true side the fallthrough (i.e, convert it to the false side).
- if (trueSucc == block.ListNext)
- {
- Comparison comp = (Comparison)branchOp.GetSource(2).AsInt32();
- Comparison compInv = comp.Invert();
-
- branchOp.SetSource(2, Const((int)compInv));
-
- block.SetSuccessor(0, trueSucc);
- block.SetSuccessor(1, falseSucc);
-
- update = true;
- }
- }
- }
-
- if (update)
- {
- cfg.Update();
- }
- }
- }
-}