CodeGen Optimisations (LSRA and Translator) (#978)

* Start of JIT garbage collection improvements

- thread static pool for Operand, MemoryOperand, Operation
- Operands and Operations are always to be constructed via their static
helper classes, so they can be pooled.
- removing LinkedList from Node for sources/destinations (replaced with
List<>s for now, but probably could do arrays since size is bounded)
- removing params constructors from Node
- LinkedList<> to List<> with Clear() for Operand assignments/uses
- ThreadStaticPool is very simple and basically just exists for the
purpose of our specific translation allocation problem. Right now it
will stay at the worst case allocation count for that thread (so far) -
the pool can never shrink.

- Still some cases of Operand[] that haven't been removed yet. Will need
to evaluate them (eg. is there a reasonable max number of params for
Calls?)

* ConcurrentStack instead of ConcurrentQueue for Rejit

* Optimize some parts of LSRA

- BitMap now operates on 64-bit int rather than 32-bit
- BitMap is now pooled in a ThreadStatic pool (within lrsa)
- BitMap now is now its own iterator. Marginally speeds up iterating
through the bits.
- A few cases where enumerators were generated have been converted to
forms that generate less garbage.
- New data structure for sorting _usePositions in LiveIntervals. Much
faster split, NextUseAfter, initial insertion. Random insertion is
slightly slower.
- That last one is WIP since you need to insert the values backwards. It
would be ideal if it just flipped it for you, uncomplicating things on
the caller side.

* Use a static pool of thread static pools. (yes.)

Prevents each execution thread creating its own lowCq pool and making me cry.

* Move constant value to top, change naming convention.

* Fix iteration of memory operands.

* Increase max thread count.

* Address Feedback
This commit is contained in:
riperiperi 2020-03-18 11:44:32 +00:00 committed by GitHub
parent 7475e180b4
commit 8226997bc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 868 additions and 347 deletions

View file

@ -1,3 +1,4 @@
using ARMeilleure.Common;
using ARMeilleure.IntermediateRepresentation;
using System;
using System.Collections.Generic;
@ -12,7 +13,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
private LiveInterval _parent;
private SortedSet<int> _usePositions;
private SortedIntegerList _usePositions;
public int UsesCount => _usePositions.Count;
@ -38,7 +39,7 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
Local = local;
_parent = parent ?? this;
_usePositions = new SortedSet<int>();
_usePositions = new SortedIntegerList();
_ranges = new List<LiveRange>();
@ -196,7 +197,9 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
public void AddUsePosition(int position)
{
_usePositions.Add(position);
// Inserts are in descending order, but ascending is faster for SortedIntegerList<>.
// We flip the ordering, then iterate backwards when using the final list.
_usePositions.Add(-position);
}
public bool Overlaps(int position)
@ -247,9 +250,9 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
return _childs.Values;
}
public IEnumerable<int> UsePositions()
public IList<int> UsePositions()
{
return _usePositions;
return _usePositions.GetList();
}
public int FirstUse()
@ -259,20 +262,19 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
return NotFound;
}
return _usePositions.First();
return -_usePositions.Last();
}
public int NextUseAfter(int position)
{
foreach (int usePosition in _usePositions)
{
if (usePosition >= position)
{
return usePosition;
}
}
int index = _usePositions.FindLessEqualIndex(-position);
return (index >= 0) ? -_usePositions[index] : NotFound;
}
return NotFound;
public void RemoveAfter(int position)
{
int index = _usePositions.FindLessEqualIndex(-position);
_usePositions.RemoveRange(0, index + 1);
}
public LiveInterval Split(int position)
@ -311,12 +313,14 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
_ranges.RemoveRange(splitIndex, count);
}
foreach (int usePosition in _usePositions.Where(x => x >= position))
int addAfter = _usePositions.FindLessEqualIndex(-position);
for (int index = addAfter; index >= 0; index--)
{
int usePosition = _usePositions[index];
right._usePositions.Add(usePosition);
}
_usePositions.RemoveWhere(x => x >= position);
RemoveAfter(position);
Debug.Assert(_ranges.Count != 0, "Left interval is empty after split.");