mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Supporting proper lowering for CRepr int-sized structs
This commit is contained in:
parent
610d472b66
commit
07fd22f9e0
3 changed files with 43 additions and 15 deletions
|
@ -4627,7 +4627,20 @@ BfTypedValue BfExprEvaluator::CreateCall(BfMethodInstance* methodInstance, BfIRV
|
|||
if (sret != NULL)
|
||||
result = *sret;
|
||||
else if (hasResult)
|
||||
result = BfTypedValue(callInst, methodInstance->mReturnType);
|
||||
{
|
||||
if (methodInstance->mReturnType->GetLoweredType() != BfTypeCode_None)
|
||||
{
|
||||
auto loweredType = mModule->GetPrimitiveType(methodInstance->mReturnType->GetLoweredType());
|
||||
auto loweredPtrType = mModule->CreatePointerType(loweredType);
|
||||
|
||||
auto retVal = mModule->CreateAlloca(methodInstance->mReturnType);
|
||||
auto castedRetVal = mModule->mBfIRBuilder->CreateBitCast(retVal, mModule->mBfIRBuilder->MapType(loweredPtrType));
|
||||
mModule->mBfIRBuilder->CreateStore(callInst, castedRetVal);
|
||||
result = BfTypedValue(retVal, methodInstance->mReturnType, BfTypedValueKind_TempAddr);
|
||||
}
|
||||
else
|
||||
result = BfTypedValue(callInst, methodInstance->mReturnType);
|
||||
}
|
||||
else
|
||||
result = mModule->GetFakeTypedValue(methodInstance->mReturnType);
|
||||
if (result.mType->IsRef())
|
||||
|
|
|
@ -12888,7 +12888,7 @@ void BfModule::MarkScopeLeft(BfScopeData* scopeData)
|
|||
|
||||
void BfModule::CreateReturn(BfIRValue val)
|
||||
{
|
||||
if (mCurMethodInstance->mReturnType->IsComposite())
|
||||
if (mCurMethodInstance->HasStructRet())
|
||||
{
|
||||
// Store to sret
|
||||
BF_ASSERT(val);
|
||||
|
@ -12901,6 +12901,17 @@ void BfModule::CreateReturn(BfIRValue val)
|
|||
{
|
||||
mBfIRBuilder->CreateRetVoid();
|
||||
}
|
||||
else if (mCurMethodInstance->mReturnType->IsStruct())
|
||||
{
|
||||
auto loweredType = GetPrimitiveType(mCurMethodInstance->mReturnType->GetLoweredType());
|
||||
auto ptrReturnType = CreatePointerType(mCurMethodInstance->mReturnType);
|
||||
auto ptrLoweredValue = CreateAlloca(loweredType);
|
||||
auto ptrReturnValue = mBfIRBuilder->CreateBitCast(ptrLoweredValue, mBfIRBuilder->MapType(ptrReturnType));
|
||||
mBfIRBuilder->CreateStore(val, ptrReturnValue);
|
||||
|
||||
auto loadedLoweredValue = mBfIRBuilder->CreateLoad(ptrLoweredValue);
|
||||
mBfIRBuilder->CreateRet(loadedLoweredValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
BF_ASSERT(val);
|
||||
|
@ -13121,11 +13132,6 @@ void BfModule::CreateDelegateInvokeMethod()
|
|||
callingConv = BfIRCallingConv_CDecl;
|
||||
if (callingConv != BfIRCallingConv_CDecl)
|
||||
mBfIRBuilder->SetCallCallingConv(staticResult, callingConv);
|
||||
// if (!mSystem->IsCompatibleCallingConvention(BfCallingConvention_Unspecified, mCurMethodInstance->mMethodDef->mCallingConvention))
|
||||
// {
|
||||
// if (mCurMethodInstance->mMethodDef->mCallingConvention == BfCallingConvention_Stdcall)
|
||||
//
|
||||
// }
|
||||
mCurMethodState->SetHadReturn(false);
|
||||
mCurMethodState->mLeftBlockUncond = false;
|
||||
mCurMethodState->mLeftBlockCond = false;
|
||||
|
@ -13140,9 +13146,12 @@ void BfModule::CreateDelegateInvokeMethod()
|
|||
}
|
||||
else
|
||||
{
|
||||
auto phi = mBfIRBuilder->CreatePhi(mBfIRBuilder->MapType(mCurMethodInstance->mReturnType), 2);
|
||||
auto loweredReturnType = mCurMethodInstance->mReturnType;
|
||||
if (loweredReturnType->GetLoweredType() != BfTypeCode_None)
|
||||
loweredReturnType = GetPrimitiveType(loweredReturnType->GetLoweredType());
|
||||
auto phi = mBfIRBuilder->CreatePhi(mBfIRBuilder->MapType(loweredReturnType), 2);
|
||||
mBfIRBuilder->AddPhiIncoming(phi, nonStaticResult, trueBB);
|
||||
mBfIRBuilder->AddPhiIncoming(phi, staticResult, falseBB);
|
||||
mBfIRBuilder->AddPhiIncoming(phi, staticResult, falseBB);
|
||||
mBfIRBuilder->CreateRet(phi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -607,7 +607,7 @@ bool BfMethodInstance::HasParamsArray()
|
|||
|
||||
bool BfMethodInstance::HasStructRet()
|
||||
{
|
||||
return (mReturnType->IsComposite()) && (!mReturnType->IsValuelessType());
|
||||
return (mReturnType->IsComposite()) && (!mReturnType->IsValuelessType()) && (mReturnType->GetLoweredType() == BfTypeCode_None);
|
||||
}
|
||||
|
||||
bool BfMethodInstance::HasSelf()
|
||||
|
@ -864,29 +864,35 @@ int BfMethodInstance::DbgGetVirtualMethodNum()
|
|||
void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, SizedArrayImpl<BfIRType>& paramTypes, bool forceStatic)
|
||||
{
|
||||
module->PopulateType(mReturnType);
|
||||
if (mReturnType->IsValuelessType())
|
||||
|
||||
BfType* loweredReturnType = mReturnType;
|
||||
auto loweredReturnTypeCode = mReturnType->GetLoweredType();
|
||||
if (loweredReturnTypeCode != BfTypeCode_None)
|
||||
loweredReturnType = module->GetPrimitiveType(loweredReturnTypeCode);
|
||||
|
||||
if (loweredReturnType->IsValuelessType())
|
||||
{
|
||||
auto voidType = module->GetPrimitiveType(BfTypeCode_None);
|
||||
returnType = module->mBfIRBuilder->MapType(voidType);
|
||||
}
|
||||
else if (mReturnType->IsComposite())
|
||||
else if (loweredReturnType->IsComposite())
|
||||
{
|
||||
auto voidType = module->GetPrimitiveType(BfTypeCode_None);
|
||||
returnType = module->mBfIRBuilder->MapType(voidType);
|
||||
auto typeInst = mReturnType->ToTypeInstance();
|
||||
auto typeInst = loweredReturnType->ToTypeInstance();
|
||||
if (typeInst != NULL)
|
||||
{
|
||||
paramTypes.push_back(module->mBfIRBuilder->MapTypeInstPtr(typeInst));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto ptrType = module->CreatePointerType(mReturnType);
|
||||
auto ptrType = module->CreatePointerType(loweredReturnType);
|
||||
paramTypes.push_back(module->mBfIRBuilder->MapType(ptrType));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnType = module->mBfIRBuilder->MapType(mReturnType);
|
||||
returnType = module->mBfIRBuilder->MapType(loweredReturnType);
|
||||
}
|
||||
|
||||
for (int paramIdx = -1; paramIdx < GetParamCount(); paramIdx++)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue