Skip to content

Commit

Permalink
更新ILRuntime至寄存器版本 2021/5/6 21:58:24
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxiongbin committed May 7, 2021
1 parent b5c462e commit 94e3c5f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
17 changes: 9 additions & 8 deletions Assets/XIL/ILSource/ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if USE_HOT
#if USE_HOT
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -1917,9 +1917,9 @@ public object Run(ILMethod method, object instance, object[] p)
{
ExceptionHandler eh = null;

int addr = ip->TokenInteger;
int addr = (int)(ip - ptr);
var sql = from e in ehs
where addr == e.HandlerEnd + 1 && e.HandlerType == ExceptionHandlerType.Finally || e.HandlerType == ExceptionHandlerType.Fault
where addr >= e.TryStart && addr <=e.TryEnd && e.HandlerType == ExceptionHandlerType.Finally || e.HandlerType == ExceptionHandlerType.Fault
select e;
eh = sql.FirstOrDefault();
if (eh != null)
Expand Down Expand Up @@ -4563,11 +4563,12 @@ void CloneStackValueType(StackObject* src, StackObject* dst, IList<object> mStac
}
}

static bool CanCastTo(StackObject* src, StackObject* dst)
bool CanCastTo(StackObject* src, StackObject* dst)
{
if (src->Value == dst->Value)
return true;
return false;
var sType = AppDomain.GetType(src->Value);
var dType = AppDomain.GetType(dst->Value);

return sType.CanAssignTo(dType);
}

bool CanCopyStackValueType(StackObject* src, StackObject* dst)
Expand All @@ -4582,7 +4583,7 @@ bool CanCopyStackValueType(StackObject* src, StackObject* dst)
return false;
}

public static void CopyStackValueType(StackObject* src, StackObject* dst, IList<object> mStack)
public void CopyStackValueType(StackObject* src, StackObject* dst, IList<object> mStack)
{
StackObject* descriptor = ILIntepreter.ResolveReference(src);
StackObject* dstDescriptor = ILIntepreter.ResolveReference(dst);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if USE_HOT
#if USE_HOT
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -2707,9 +2707,9 @@ public unsafe partial class ILIntepreter
{
ExceptionHandler eh = null;

int addr = ip->Operand;
int addr = (int)(ip - ptr);
var sql = from e in ehs
where addr == e.HandlerEnd + 1 && e.HandlerType == ExceptionHandlerType.Finally || e.HandlerType == ExceptionHandlerType.Fault
where addr >= e.TryStart && addr <=e.TryEnd && e.HandlerType == ExceptionHandlerType.Finally || e.HandlerType == ExceptionHandlerType.Fault
select e;
eh = sql.FirstOrDefault();
if (eh != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if USE_HOT
#if USE_HOT
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -155,15 +155,23 @@ public OpCodeR[] Compile(out int stackRegisterCnt, out Dictionary<int, int[]> sw
for (short r = locVarRegStart; r < locVarRegStart + body.Variables.Count; r++)
{
visitedBlocks.Clear();
if (CheckNeedInitObj(first, r, method.ReturnType != method.AppDomain.VoidType, visitedBlocks))
foreach (var b in blocks)
{
OpCodeR code = new OpCodeR();
code.Code = OpCodeREnum.Initobj;
code.Register1 = r;
code.Operand = method.GetTypeTokenHashCode(body.Variables[idx].VariableType);
code.Operand2 = 1;
first.FinalInstructions.Insert(appendIdx++, code);
if (b.PreviousBlocks.Count == 0)
{
if (CheckNeedInitObj(b, r, method.ReturnType != method.AppDomain.VoidType, visitedBlocks))
{
OpCodeR code = new OpCodeR();
code.Code = OpCodeREnum.Initobj;
code.Register1 = r;
code.Operand = method.GetTypeTokenHashCode(body.Variables[idx].VariableType);
code.Operand2 = 1;
first.FinalInstructions.Insert(appendIdx++, code);
break;
}
}
}

idx++;
}
for (idx = first.FinalInstructions.Count - 1; idx >= 0; idx--)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if USE_HOT
#if USE_HOT
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -57,7 +57,7 @@ public static void EliminateConstantLoad(List<CodeBasicBlock> blocks, bool hasRe
}
short r1, r2, r3;
GetOpcodeSourceRegister(ref Y, hasReturn, out r1, out r2, out r3);
if (r1 == xDst || r2 == xDst)
if (r1 == xDst || r2 == xDst || r3 == xDst)
{
if (SupportIntemediateValue(Y.Code))
{
Expand Down Expand Up @@ -96,6 +96,10 @@ public static void EliminateConstantLoad(List<CodeBasicBlock> blocks, bool hasRe
}
break;
}
short yDst;
GetOpcodeDestRegister(ref Y, out yDst);
if (yDst == xDst)
break;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/XIL/ILSource/ILRuntime/Runtime/Stack/RuntimeStack.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if USE_HOT
#if USE_HOT
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -308,7 +308,7 @@ public void AllocValueTypeAndCopy(StackObject* ptr, StackObject* src)
*(long*)&ptr->Value = (long)dst;
int managedIdx = alloc.ManagedIndex;
InitializeValueTypeObject(type, dst, true, ref managedIdx);
ILIntepreter.CopyStackValueType(src, ptr, managedStack);
intepreter.CopyStackValueType(src, ptr, managedStack);
FreeValueTypeObject(src);
}
else
Expand Down

0 comments on commit 94e3c5f

Please sign in to comment.