Implement block placement (#1549)

* Implement block placement

Implement a simple pass which re-orders cold blocks at the end of the
list of blocks in the CFG.

* Set PPTC version

* Use Array.Resize

Address gdkchan's feedback
This commit is contained in:
FICTURE7 2020-09-20 03:00:24 +04:00 committed by GitHub
parent 1eea35554c
commit f60033e0aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 136 additions and 31 deletions

View file

@ -7,26 +7,37 @@ namespace ARMeilleure.Translation
{
class ControlFlowGraph
{
private BasicBlock[] _postOrderBlocks;
private int[] _postOrderMap;
public BasicBlock Entry { get; }
public IntrusiveList<BasicBlock> Blocks { get; }
public BasicBlock[] PostOrderBlocks { get; }
public int[] PostOrderMap { get; }
public BasicBlock[] PostOrderBlocks => _postOrderBlocks;
public int[] PostOrderMap => _postOrderMap;
public ControlFlowGraph(BasicBlock entry, IntrusiveList<BasicBlock> blocks)
{
Entry = entry;
Blocks = blocks;
RemoveUnreachableBlocks(blocks);
Update(removeUnreachableBlocks: true);
}
public void Update(bool removeUnreachableBlocks)
{
if (removeUnreachableBlocks)
{
RemoveUnreachableBlocks(Blocks);
}
var visited = new HashSet<BasicBlock>();
var blockStack = new Stack<BasicBlock>();
PostOrderBlocks = new BasicBlock[blocks.Count];
PostOrderMap = new int[blocks.Count];
Array.Resize(ref _postOrderBlocks, Blocks.Count);
Array.Resize(ref _postOrderMap, Blocks.Count);
visited.Add(entry);
blockStack.Push(entry);
visited.Add(Entry);
blockStack.Push(Entry);
int index = 0;