mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
32-bit consteval fixes
This commit is contained in:
parent
31c89ab8e1
commit
e4fa6776a8
4 changed files with 91 additions and 38 deletions
|
@ -1018,6 +1018,7 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
mBeContext = new BeContext();
|
mBeContext = new BeContext();
|
||||||
mBeModule = new BeModule(moduleName, mBeContext);
|
mBeModule = new BeModule(moduleName, mBeContext);
|
||||||
mBeModule->mBeIRCodeGen = this;
|
mBeModule->mBeIRCodeGen = this;
|
||||||
|
mBeContext->mPointerSize = ptrSize;
|
||||||
|
|
||||||
for (auto constInt : mConfigConsts)
|
for (auto constInt : mConfigConsts)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19437,7 +19437,10 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
||||||
// If we hot swap, we want to make sure at least one method refers to this extern method so it gets pulled in
|
// If we hot swap, we want to make sure at least one method refers to this extern method so it gets pulled in
|
||||||
// incase it gets called later by some hot-loaded coded
|
// incase it gets called later by some hot-loaded coded
|
||||||
if ((mCompiler->mOptions.mAllowHotSwapping) && (mCurMethodInstance->mIRFunction) && (!mCurMethodInstance->mIRFunction.IsFake()) && (mCurTypeInstance != mContext->mBfObjectType))
|
if ((mCompiler->mOptions.mAllowHotSwapping) && (mCurMethodInstance->mIRFunction) && (!mCurMethodInstance->mIRFunction.IsFake()) && (mCurTypeInstance != mContext->mBfObjectType))
|
||||||
CreateFakeCallerMethod(mangledName);
|
{
|
||||||
|
if (!mCurMethodInstance->mMethodDef->mName.StartsWith("ConstEval_"))
|
||||||
|
CreateFakeCallerMethod(mangledName);
|
||||||
|
}
|
||||||
mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction);
|
mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction);
|
||||||
}
|
}
|
||||||
else if ((methodInstance->GetImportKind() == BfImportKind_Import_Dynamic) && (!mCompiler->IsHotCompile()))
|
else if ((methodInstance->GetImportKind() == BfImportKind_Import_Dynamic) && (!mCompiler->IsHotCompile()))
|
||||||
|
|
|
@ -208,6 +208,7 @@ static_assert(BF_ARRAY_COUNT(gOpInfo) == (int)CeOp_COUNT, "gOpName incorrect siz
|
||||||
|
|
||||||
CeFunction::~CeFunction()
|
CeFunction::~CeFunction()
|
||||||
{
|
{
|
||||||
|
BF_ASSERT(mId == -1);
|
||||||
for (auto innerFunc : mInnerFunctions)
|
for (auto innerFunc : mInnerFunctions)
|
||||||
delete innerFunc;
|
delete innerFunc;
|
||||||
}
|
}
|
||||||
|
@ -586,6 +587,7 @@ void CeBuilder::EmitSizedOp(CeOp baseOp, const CeOperand& operand, CeOperand* ou
|
||||||
{
|
{
|
||||||
bool isStdSize = true;
|
bool isStdSize = true;
|
||||||
CeOp op = CeOp_InvalidOp;
|
CeOp op = CeOp_InvalidOp;
|
||||||
|
|
||||||
if (operand.mType->mSize == 1)
|
if (operand.mType->mSize == 1)
|
||||||
op = baseOp;
|
op = baseOp;
|
||||||
else if (operand.mType->mSize == 2)
|
else if (operand.mType->mSize == 2)
|
||||||
|
@ -1201,6 +1203,7 @@ void CeBuilder::Build()
|
||||||
innerFunction->mCeInnerFunctionInfo->mOwner = mCeFunction;
|
innerFunction->mCeInnerFunctionInfo->mOwner = mCeFunction;
|
||||||
mInnerFunctionMap[beFunction] = (int)mCeFunction->mInnerFunctions.size();
|
mInnerFunctionMap[beFunction] = (int)mCeFunction->mInnerFunctions.size();
|
||||||
mCeFunction->mInnerFunctions.Add(innerFunction);
|
mCeFunction->mInnerFunctions.Add(innerFunction);
|
||||||
|
mCeMachine->MapFunctionId(innerFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (int globalVarIdx = startGlobalVariableCount; globalVarIdx < (int)beModule->mGlobalVariables.size(); globalVarIdx++)
|
// for (int globalVarIdx = startGlobalVariableCount; globalVarIdx < (int)beModule->mGlobalVariables.size(); globalVarIdx++)
|
||||||
|
@ -2601,6 +2604,7 @@ CeMachine::CeMachine(BfCompiler* compiler)
|
||||||
mCeModule = NULL;
|
mCeModule = NULL;
|
||||||
mRevision = 0;
|
mRevision = 0;
|
||||||
mExecuteId = 0;
|
mExecuteId = 0;
|
||||||
|
mCurFunctionId = 0;
|
||||||
mRevisionExecuteTime = 0;
|
mRevisionExecuteTime = 0;
|
||||||
mCurTargetSrc = NULL;
|
mCurTargetSrc = NULL;
|
||||||
mCurModule = NULL;
|
mCurModule = NULL;
|
||||||
|
@ -2620,6 +2624,14 @@ CeMachine::~CeMachine()
|
||||||
for (auto kv : mFunctions)
|
for (auto kv : mFunctions)
|
||||||
{
|
{
|
||||||
auto functionInfo = kv.mValue;
|
auto functionInfo = kv.mValue;
|
||||||
|
if (functionInfo->mCeFunction != NULL)
|
||||||
|
{
|
||||||
|
// We don't need to actually unmap it at this point
|
||||||
|
functionInfo->mCeFunction->mId = -1;
|
||||||
|
for (auto innerFunction : functionInfo->mCeFunction->mInnerFunctions)
|
||||||
|
innerFunction->mId = -1;
|
||||||
|
}
|
||||||
|
|
||||||
delete functionInfo;
|
delete functionInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2967,6 +2979,17 @@ void CeMachine::RemoveMethod(BfMethodInstance* methodInstance)
|
||||||
if (callEntry.mFunctionInfo != NULL)
|
if (callEntry.mFunctionInfo != NULL)
|
||||||
DerefMethodInfo(callEntry.mFunctionInfo);
|
DerefMethodInfo(callEntry.mFunctionInfo);
|
||||||
}
|
}
|
||||||
|
if (ceFunction->mId != -1)
|
||||||
|
{
|
||||||
|
mFunctionIdMap.Remove(ceFunction->mId);
|
||||||
|
ceFunction->mId = -1;
|
||||||
|
for (auto innerFunction : ceFunction->mInnerFunctions)
|
||||||
|
{
|
||||||
|
mFunctionIdMap.Remove(innerFunction->mId);
|
||||||
|
innerFunction->mId = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete ceFunction;
|
delete ceFunction;
|
||||||
ceFunctionInfo->mCeFunction = NULL;
|
ceFunctionInfo->mCeFunction = NULL;
|
||||||
ceFunctionInfo->mMethodInstance = NULL;
|
ceFunctionInfo->mMethodInstance = NULL;
|
||||||
|
@ -2986,8 +3009,6 @@ void CeMachine::RemoveMethod(BfMethodInstance* methodInstance)
|
||||||
|
|
||||||
mFunctions.Remove(itr);
|
mFunctions.Remove(itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckFunctions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#define CE_GETC(T) *((T*)(addr += sizeof(T)) - 1)
|
//#define CE_GETC(T) *((T*)(addr += sizeof(T)) - 1)
|
||||||
|
@ -3733,9 +3754,11 @@ bool CeMachine::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
uint8* instPtr = (ceFunction->mCode.IsEmpty()) ? NULL : &ceFunction->mCode[0];
|
uint8* instPtr = (ceFunction->mCode.IsEmpty()) ? NULL : &ceFunction->mCode[0];
|
||||||
uint8* stackPtr = startStackPtr;
|
uint8* stackPtr = startStackPtr;
|
||||||
uint8* framePtr = startFramePtr;
|
uint8* framePtr = startFramePtr;
|
||||||
|
bool needsFunctionIds = mCeModule->mSystem->mPtrSize != 8;
|
||||||
|
|
||||||
volatile bool* cancelPtr = &mCompiler->mCanceling;
|
volatile bool* cancelPtr = &mCompiler->mCanceling;
|
||||||
|
|
||||||
|
|
||||||
auto _GetCurFrame = [&]()
|
auto _GetCurFrame = [&]()
|
||||||
{
|
{
|
||||||
CeFrame ceFrame;
|
CeFrame ceFrame;
|
||||||
|
@ -4196,6 +4219,13 @@ bool CeMachine::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
memcpy(memStart + destAddr, memStart + srcAddr, size);
|
memcpy(memStart + destAddr, memStart + srcAddr, size);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CeOp_FrameAddr_32:
|
||||||
|
{
|
||||||
|
auto& result = CE_GETFRAME(int32);
|
||||||
|
auto addr = &CE_GETFRAME(uint8);
|
||||||
|
result = addr - memStart;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case CeOp_FrameAddr_64:
|
case CeOp_FrameAddr_64:
|
||||||
{
|
{
|
||||||
auto& result = CE_GETFRAME(int64);
|
auto& result = CE_GETFRAME(int64);
|
||||||
|
@ -4492,7 +4522,7 @@ bool CeMachine::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
{
|
{
|
||||||
BF_ASSERT(memStart == mMemory.mVals);
|
BF_ASSERT(memStart == mMemory.mVals);
|
||||||
|
|
||||||
auto& result = CE_GETFRAME(CeFunction*);
|
auto resultFrameIdx = CE_GETINST(int32);
|
||||||
int32 callIdx = CE_GETINST(int32);
|
int32 callIdx = CE_GETINST(int32);
|
||||||
auto& callEntry = ceFunction->mCallTable[callIdx];
|
auto& callEntry = ceFunction->mCallTable[callIdx];
|
||||||
if (callEntry.mBindRevision != mRevision)
|
if (callEntry.mBindRevision != mRevision)
|
||||||
|
@ -4535,29 +4565,31 @@ bool CeMachine::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
}
|
}
|
||||||
|
|
||||||
BF_ASSERT(memStart == mMemory.mVals);
|
BF_ASSERT(memStart == mMemory.mVals);
|
||||||
result = callEntry.mFunction;
|
auto callFunction = callEntry.mFunction;
|
||||||
// if (callEntry.mFunction->mName.Contains("__static_dump"))
|
if (needsFunctionIds)
|
||||||
// {
|
*(int32*)(framePtr + resultFrameIdx) = callFunction->mId;
|
||||||
// int32 val = *(int32*)(stackPtr);
|
else
|
||||||
// OutputDebugStrF("__static_dump: %d\n", val);
|
*(CeFunction**)(framePtr + resultFrameIdx) = callFunction;
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CeOp_GetMethod_Inner:
|
case CeOp_GetMethod_Inner:
|
||||||
{
|
{
|
||||||
auto& result = CE_GETFRAME(CeFunction*);
|
auto resultFrameIdx = CE_GETINST(int32);
|
||||||
int32 innerIdx = CE_GETINST(int32);
|
int32 innerIdx = CE_GETINST(int32);
|
||||||
|
|
||||||
auto outerFunction = ceFunction;
|
auto outerFunction = ceFunction;
|
||||||
if (outerFunction->mCeInnerFunctionInfo != NULL)
|
if (outerFunction->mCeInnerFunctionInfo != NULL)
|
||||||
outerFunction = outerFunction->mCeInnerFunctionInfo->mOwner;
|
outerFunction = outerFunction->mCeInnerFunctionInfo->mOwner;
|
||||||
auto& callEntry = outerFunction->mInnerFunctions[innerIdx];
|
auto callFunction = outerFunction->mInnerFunctions[innerIdx];
|
||||||
result = callEntry;
|
if (needsFunctionIds)
|
||||||
|
*(int32*)(framePtr + resultFrameIdx) = callFunction->mId;
|
||||||
|
else
|
||||||
|
*(CeFunction**)(framePtr + resultFrameIdx) = callFunction;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CeOp_GetMethod_Virt:
|
case CeOp_GetMethod_Virt:
|
||||||
{
|
{
|
||||||
auto& result = CE_GETFRAME(CeFunction*);
|
auto resultFrameIdx = CE_GETINST(int32);
|
||||||
auto valueAddr = CE_GETFRAME(addr_ce);
|
auto valueAddr = CE_GETFRAME(addr_ce);
|
||||||
int32 virtualIdx = CE_GETINST(int32);
|
int32 virtualIdx = CE_GETINST(int32);
|
||||||
|
|
||||||
|
@ -4569,12 +4601,15 @@ bool CeMachine::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
auto methodInstance = (BfMethodInstance*)valueType->mVirtualMethodTable[virtualIdx].mImplementingMethod;
|
auto methodInstance = (BfMethodInstance*)valueType->mVirtualMethodTable[virtualIdx].mImplementingMethod;
|
||||||
|
|
||||||
auto callFunction = GetPreparedFunction(methodInstance);
|
auto callFunction = GetPreparedFunction(methodInstance);
|
||||||
result = callFunction;
|
if (needsFunctionIds)
|
||||||
|
*(int32*)(framePtr + resultFrameIdx) = callFunction->mId;
|
||||||
|
else
|
||||||
|
*(CeFunction**)(framePtr + resultFrameIdx) = callFunction;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CeOp_GetMethod_IFace:
|
case CeOp_GetMethod_IFace:
|
||||||
{
|
{
|
||||||
auto& result = CE_GETFRAME(CeFunction*);
|
auto resultFrameIdx = CE_GETINST(int32);
|
||||||
auto valueAddr = CE_GETFRAME(addr_ce);
|
auto valueAddr = CE_GETFRAME(addr_ce);
|
||||||
int32 ifaceId = CE_GETINST(int32);
|
int32 ifaceId = CE_GETINST(int32);
|
||||||
int32 methodIdx = CE_GETINST(int32);
|
int32 methodIdx = CE_GETINST(int32);
|
||||||
|
@ -4610,13 +4645,23 @@ bool CeMachine::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
|
||||||
}
|
}
|
||||||
|
|
||||||
auto callFunction = GetPreparedFunction(methodInstance);
|
auto callFunction = GetPreparedFunction(methodInstance);
|
||||||
result = callFunction;
|
if (needsFunctionIds)
|
||||||
|
*(int32*)(framePtr + resultFrameIdx) = callFunction->mId;
|
||||||
|
else
|
||||||
|
*(CeFunction**)(framePtr + resultFrameIdx) = callFunction;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CeOp_Call:
|
case CeOp_Call:
|
||||||
{
|
{
|
||||||
callCount++;
|
callCount++;
|
||||||
auto callFunction = CE_GETFRAME(CeFunction*);
|
CeFunction* callFunction;
|
||||||
|
if (needsFunctionIds)
|
||||||
|
{
|
||||||
|
int32 functionId = CE_GETFRAME(int32);
|
||||||
|
callFunction = mFunctionIdMap[functionId];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
callFunction = CE_GETFRAME(CeFunction*);
|
||||||
|
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
if (!_CheckFunction(callFunction, handled))
|
if (!_CheckFunction(callFunction, handled))
|
||||||
|
@ -5247,7 +5292,7 @@ void CeMachine::PrepareFunction(CeFunction* ceFunction, CeBuilder* parentBuilder
|
||||||
ceBuilder.mCeFunction = ceFunction;
|
ceBuilder.mCeFunction = ceFunction;
|
||||||
ceBuilder.Build();
|
ceBuilder.Build();
|
||||||
|
|
||||||
/*if (!ceFunction->mCode.IsEmpty())
|
if (!ceFunction->mCode.IsEmpty())
|
||||||
{
|
{
|
||||||
CeDumpContext dumpCtx;
|
CeDumpContext dumpCtx;
|
||||||
dumpCtx.mCeFunction = ceFunction;
|
dumpCtx.mCeFunction = ceFunction;
|
||||||
|
@ -5257,15 +5302,15 @@ void CeMachine::PrepareFunction(CeFunction* ceFunction, CeBuilder* parentBuilder
|
||||||
dumpCtx.Dump();
|
dumpCtx.Dump();
|
||||||
|
|
||||||
OutputDebugStrF("Code for %s:\n%s\n", ceBuilder.mBeFunction->mName.c_str(), dumpCtx.mStr.c_str());
|
OutputDebugStrF("Code for %s:\n%s\n", ceBuilder.mBeFunction->mName.c_str(), dumpCtx.mStr.c_str());
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CeMachine::CheckFunctions()
|
void CeMachine::MapFunctionId(CeFunction* ceFunction)
|
||||||
{
|
{
|
||||||
for (auto kv : mFunctions)
|
if (mCeModule->mSystem->mPtrSize == 8)
|
||||||
{
|
return;
|
||||||
BF_ASSERT((((intptr)(void*)kv.mKey->mMethodDef) & 0xFF) != 0xDD);
|
ceFunction->mId = ++mCurFunctionId;
|
||||||
}
|
mFunctionIdMap[ceFunction->mId] = ceFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue func, bool& added)
|
CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue func, bool& added)
|
||||||
|
@ -5276,8 +5321,6 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckFunctions();
|
|
||||||
|
|
||||||
CeFunctionInfo** functionInfoPtr = NULL;
|
CeFunctionInfo** functionInfoPtr = NULL;
|
||||||
CeFunctionInfo* ceFunctionInfo = NULL;
|
CeFunctionInfo* ceFunctionInfo = NULL;
|
||||||
CeFunction* ceFunction = NULL;
|
CeFunction* ceFunction = NULL;
|
||||||
|
@ -5337,6 +5380,7 @@ CeFunction* CeMachine::GetFunction(BfMethodInstance* methodInstance, BfIRValue f
|
||||||
|
|
||||||
ceFunctionInfo->mMethodInstance = methodInstance;
|
ceFunctionInfo->mMethodInstance = methodInstance;
|
||||||
ceFunctionInfo->mCeFunction = ceFunction;
|
ceFunctionInfo->mCeFunction = ceFunction;
|
||||||
|
MapFunctionId(ceFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -344,6 +344,7 @@ public:
|
||||||
Array<CeFunction*> mInnerFunctions;
|
Array<CeFunction*> mInnerFunctions;
|
||||||
String mGenError;
|
String mGenError;
|
||||||
int mFrameSize;
|
int mFrameSize;
|
||||||
|
int mId;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CeFunction()
|
CeFunction()
|
||||||
|
@ -355,6 +356,7 @@ public:
|
||||||
mMethodInstance = NULL;
|
mMethodInstance = NULL;
|
||||||
mFailed = false;
|
mFailed = false;
|
||||||
mFrameSize = 0;
|
mFrameSize = 0;
|
||||||
|
mId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
~CeFunction();
|
~CeFunction();
|
||||||
|
@ -595,12 +597,14 @@ class CeMachine
|
||||||
public:
|
public:
|
||||||
Dictionary<BfMethodInstance*, CeFunctionInfo*> mFunctions;
|
Dictionary<BfMethodInstance*, CeFunctionInfo*> mFunctions;
|
||||||
Dictionary<String, CeFunctionInfo*> mNamedFunctionMap;
|
Dictionary<String, CeFunctionInfo*> mNamedFunctionMap;
|
||||||
|
Dictionary<int, CeFunction*> mFunctionIdMap; // Only used for 32-bit
|
||||||
|
|
||||||
BfCompiler* mCompiler;
|
BfCompiler* mCompiler;
|
||||||
BfModule* mCeModule;
|
BfModule* mCeModule;
|
||||||
int mRevision;
|
int mRevision;
|
||||||
int mRevisionExecuteTime;
|
int mRevisionExecuteTime;
|
||||||
int mExecuteId;
|
int mExecuteId;
|
||||||
|
int mCurFunctionId;
|
||||||
|
|
||||||
// These are only valid for the current execution
|
// These are only valid for the current execution
|
||||||
ContiguousHeap* mHeap;
|
ContiguousHeap* mHeap;
|
||||||
|
@ -647,6 +651,7 @@ public:
|
||||||
bool Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* startFramePtr);
|
bool Execute(CeFunction* startFunction, uint8* startStackPtr, uint8* startFramePtr);
|
||||||
|
|
||||||
void PrepareFunction(CeFunction* methodInstance, CeBuilder* parentBuilder);
|
void PrepareFunction(CeFunction* methodInstance, CeBuilder* parentBuilder);
|
||||||
|
void MapFunctionId(CeFunction* ceFunction);
|
||||||
|
|
||||||
void CheckFunctions();
|
void CheckFunctions();
|
||||||
CeFunction* GetFunction(BfMethodInstance* methodInstance, BfIRValue func, bool& added);
|
CeFunction* GetFunction(BfMethodInstance* methodInstance, BfIRValue func, bool& added);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue