Add PPTC support

This commit is contained in:
FICTURE7 2021-04-09 20:55:24 +04:00
parent 1803b9fef9
commit 4478a32114
4 changed files with 44 additions and 33 deletions

View file

@ -141,7 +141,7 @@ namespace ARMeilleure.Translation
if (Ptc.State == PtcState.Enabled)
{
Debug.Assert(_funcs.Count == 0);
Ptc.LoadTranslations(_funcs, _memory, _jumpTable);
Ptc.LoadTranslations(_funcs, _memory, _jumpTable, CountTable);
Ptc.MakeAndSaveTranslations(_funcs, _memory, _jumpTable, CountTable);
}
@ -256,9 +256,11 @@ namespace ARMeilleure.Translation
Logger.StartPass(PassName.Translation);
Counter counter = null;
if (!context.HighCq)
{
EmitRejitCheck(context);
EmitRejitCheck(context, out counter);
}
EmitSynchronization(context);
@ -303,7 +305,7 @@ namespace ARMeilleure.Translation
Ptc.WriteInfoCodeRelocUnwindInfo(address, funcSize, highCq, ptcInfo);
}
return new TranslatedFunction(func, funcSize, highCq);
return new TranslatedFunction(func, counter, funcSize, highCq);
}
internal static void PreparePool(int groupId = 0)
@ -413,9 +415,9 @@ namespace ARMeilleure.Translation
return context.GetControlFlowGraph();
}
internal static void EmitRejitCheck(ArmEmitterContext context)
internal static void EmitRejitCheck(ArmEmitterContext context, out Counter counter)
{
if (!context.CountTable.TryAllocate(out int index))
if (!Counter.TryCreate(context.CountTable, out counter))
{
return;
}
@ -424,8 +426,7 @@ namespace ARMeilleure.Translation
Operand lblAdd = Label();
Operand lblEnd = Label();
// TODO: PPTC.
Operand address = Const(ref context.CountTable.GetValue(index));
Operand address = Const(ref counter.Value, Ptc.CountTableIndex);
Operand count = context.Load8(address);
context.BranchIf(lblAdd, count, Const(100), Comparison.LessUI);
context.BranchIf(lblRejit, count, Const(100), Comparison.Equal);
@ -511,9 +512,9 @@ namespace ARMeilleure.Translation
{
while (_backgroundStack.TryPop(out var request))
{
if (_funcs.TryGetValue(request.Address, out var func))
if (_funcs.TryGetValue(request.Address, out var func) && func.CallCounter != null)
{
func.ResetCallCount();
Volatile.Write(ref func.CallCounter.Value, 0);
}
_backgroundSet.TryRemove(request.Address, out _);