Avoid buffer allocations in CodeGenContext.GetCode(). Avoid stream allocations in PTC.PtcInfo.

Refactoring/nits.
This commit is contained in:
LDj3SNuD 2021-01-30 04:32:53 +01:00
parent b767d1a6b0
commit f44271a617
6 changed files with 78 additions and 90 deletions

View file

@ -86,51 +86,50 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
{
NumberLocals(cfg);
using (AllocationContext context = new AllocationContext(stackAlloc, regMasks, _intervals.Count))
using AllocationContext context = new AllocationContext(stackAlloc, regMasks, _intervals.Count);
BuildIntervals(cfg, context);
for (int index = 0; index < _intervals.Count; index++)
{
BuildIntervals(cfg, context);
LiveInterval current = _intervals[index];
for (int index = 0; index < _intervals.Count; index++)
if (current.IsEmpty)
{
LiveInterval current = _intervals[index];
if (current.IsEmpty)
{
continue;
}
if (current.IsFixed)
{
context.Active.Set(index);
if (current.Register.Type == RegisterType.Integer)
{
context.IntUsedRegisters |= 1 << current.Register.Index;
}
else /* if (interval.Register.Type == RegisterType.Vector) */
{
context.VecUsedRegisters |= 1 << current.Register.Index;
}
continue;
}
AllocateInterval(context, current, index);
continue;
}
for (int index = RegistersCount * 2; index < _intervals.Count; index++)
if (current.IsFixed)
{
if (!_intervals[index].IsSpilled)
context.Active.Set(index);
if (current.Register.Type == RegisterType.Integer)
{
ReplaceLocalWithRegister(_intervals[index]);
context.IntUsedRegisters |= 1 << current.Register.Index;
}
else /* if (interval.Register.Type == RegisterType.Vector) */
{
context.VecUsedRegisters |= 1 << current.Register.Index;
}
continue;
}
InsertSplitCopies();
InsertSplitCopiesAtEdges(cfg);
return new AllocationResult(context.IntUsedRegisters, context.VecUsedRegisters, context.StackAlloc.TotalSize);
AllocateInterval(context, current, index);
}
for (int index = RegistersCount * 2; index < _intervals.Count; index++)
{
if (!_intervals[index].IsSpilled)
{
ReplaceLocalWithRegister(_intervals[index]);
}
}
InsertSplitCopies();
InsertSplitCopiesAtEdges(cfg);
return new AllocationResult(context.IntUsedRegisters, context.VecUsedRegisters, context.StackAlloc.TotalSize);
}
private void AllocateInterval(AllocationContext context, LiveInterval current, int cIndex)

View file

@ -302,13 +302,11 @@ namespace ARMeilleure.CodeGen.X86
{
Assembler assembler = new Assembler(codeStream, _ptcInfo);
Span<byte> buffer;
for (int index = 0; index < _jumps.Count; index++)
{
Jump jump = _jumps[index];
buffer = new byte[jump.JumpPosition - _stream.Position];
Span<byte> buffer = new byte[jump.JumpPosition - _stream.Position];
_stream.Read(buffer);
_stream.Seek(_ptcDisabled ? ReservedBytesForJump : jump.InstSize, SeekOrigin.Current);
@ -325,13 +323,7 @@ namespace ARMeilleure.CodeGen.X86
}
}
buffer = new byte[_stream.Length - _stream.Position];
_stream.Read(buffer);
codeStream.Write(buffer);
_ptcInfo?.WriteCode(codeStream);
_stream.CopyTo(codeStream);
return codeStream.ToArray();
}

View file

@ -190,6 +190,11 @@ namespace ARMeilleure.CodeGen.X86
byte[] code = context.GetCode();
if (ptcInfo != null)
{
ptcInfo.Code = code;
}
Logger.EndPass(PassName.CodeGeneration);
return new CompiledFunction(code, unwindInfo);