mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Fixed some 'var' handling cases where module hasn't failed
This commit is contained in:
parent
7b29a4facb
commit
f830e23c52
3 changed files with 200 additions and 191 deletions
|
@ -2160,71 +2160,71 @@ BeMCOperand BeMCContext::GetOperand(BeValue* value, bool allowMetaResult, bool a
|
||||||
switch (value->GetTypeId())
|
switch (value->GetTypeId())
|
||||||
{
|
{
|
||||||
case BeGlobalVariable::TypeId:
|
case BeGlobalVariable::TypeId:
|
||||||
{
|
|
||||||
auto globalVar = (BeGlobalVariable*)value;
|
|
||||||
if ((globalVar->mIsTLS) && (mTLSVRegIdx == -1))
|
|
||||||
{
|
{
|
||||||
auto tlsVReg = AllocVirtualReg(mNativeIntType);
|
auto globalVar = (BeGlobalVariable*)value;
|
||||||
auto vregInfo = GetVRegInfo(tlsVReg);
|
if ((globalVar->mIsTLS) && (mTLSVRegIdx == -1))
|
||||||
vregInfo->mMustExist = true;
|
{
|
||||||
vregInfo->mForceReg = true;
|
auto tlsVReg = AllocVirtualReg(mNativeIntType);
|
||||||
vregInfo->mDisableR12 = true;
|
auto vregInfo = GetVRegInfo(tlsVReg);
|
||||||
vregInfo->mDisableR13 = true;
|
vregInfo->mMustExist = true;
|
||||||
mTLSVRegIdx = tlsVReg.mVRegIdx;
|
vregInfo->mForceReg = true;
|
||||||
}
|
vregInfo->mDisableR12 = true;
|
||||||
|
vregInfo->mDisableR13 = true;
|
||||||
|
mTLSVRegIdx = tlsVReg.mVRegIdx;
|
||||||
|
}
|
||||||
|
|
||||||
auto sym = mCOFFObject->GetSymbol(globalVar);
|
auto sym = mCOFFObject->GetSymbol(globalVar);
|
||||||
if (sym != NULL)
|
if (sym != NULL)
|
||||||
{
|
{
|
||||||
BeMCOperand mcOperand;
|
BeMCOperand mcOperand;
|
||||||
mcOperand.mKind = BeMCOperandKind_SymbolAddr;
|
mcOperand.mKind = BeMCOperandKind_SymbolAddr;
|
||||||
mcOperand.mSymbolIdx = sym->mIdx;
|
mcOperand.mSymbolIdx = sym->mIdx;
|
||||||
return mcOperand;
|
return mcOperand;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
case BeCastConstant::TypeId:
|
case BeCastConstant::TypeId:
|
||||||
{
|
|
||||||
auto constant = (BeCastConstant*)value;
|
|
||||||
|
|
||||||
BeMCOperand mcOperand;
|
|
||||||
auto relTo = GetOperand(constant->mTarget);
|
|
||||||
if (relTo.mKind == BeMCOperandKind_Immediate_Null)
|
|
||||||
{
|
{
|
||||||
mcOperand.mKind = BeMCOperandKind_Immediate_Null;
|
auto constant = (BeCastConstant*)value;
|
||||||
mcOperand.mType = constant->mType;
|
|
||||||
|
BeMCOperand mcOperand;
|
||||||
|
auto relTo = GetOperand(constant->mTarget);
|
||||||
|
if (relTo.mKind == BeMCOperandKind_Immediate_Null)
|
||||||
|
{
|
||||||
|
mcOperand.mKind = BeMCOperandKind_Immediate_Null;
|
||||||
|
mcOperand.mType = constant->mType;
|
||||||
|
return mcOperand;
|
||||||
|
}
|
||||||
|
|
||||||
|
mcOperand = AllocVirtualReg(constant->mType);
|
||||||
|
auto vregInfo = GetVRegInfo(mcOperand);
|
||||||
|
vregInfo->mDefOnFirstUse = true;
|
||||||
|
vregInfo->mRelTo = relTo;
|
||||||
|
vregInfo->mIsExpr = true;
|
||||||
|
|
||||||
return mcOperand;
|
return mcOperand;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
mcOperand = AllocVirtualReg(constant->mType);
|
|
||||||
auto vregInfo = GetVRegInfo(mcOperand);
|
|
||||||
vregInfo->mDefOnFirstUse = true;
|
|
||||||
vregInfo->mRelTo = relTo;
|
|
||||||
vregInfo->mIsExpr = true;
|
|
||||||
|
|
||||||
return mcOperand;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BeConstant::TypeId:
|
case BeConstant::TypeId:
|
||||||
{
|
|
||||||
auto constant = (BeConstant*)value;
|
|
||||||
BeMCOperand mcOperand;
|
|
||||||
switch (constant->mType->mTypeCode)
|
|
||||||
{
|
{
|
||||||
case BeTypeCode_Boolean:
|
auto constant = (BeConstant*)value;
|
||||||
case BeTypeCode_Int8: mcOperand.mKind = BeMCOperandKind_Immediate_i8; break;
|
BeMCOperand mcOperand;
|
||||||
case BeTypeCode_Int16: mcOperand.mKind = BeMCOperandKind_Immediate_i16; break;
|
switch (constant->mType->mTypeCode)
|
||||||
case BeTypeCode_Int32: mcOperand.mKind = BeMCOperandKind_Immediate_i32; break;
|
{
|
||||||
case BeTypeCode_Int64: mcOperand.mKind = BeMCOperandKind_Immediate_i64; break;
|
case BeTypeCode_Boolean:
|
||||||
case BeTypeCode_Float:
|
case BeTypeCode_Int8: mcOperand.mKind = BeMCOperandKind_Immediate_i8; break;
|
||||||
mcOperand.mImmF32 = constant->mDouble;
|
case BeTypeCode_Int16: mcOperand.mKind = BeMCOperandKind_Immediate_i16; break;
|
||||||
mcOperand.mKind = BeMCOperandKind_Immediate_f32;
|
case BeTypeCode_Int32: mcOperand.mKind = BeMCOperandKind_Immediate_i32; break;
|
||||||
return mcOperand;
|
case BeTypeCode_Int64: mcOperand.mKind = BeMCOperandKind_Immediate_i64; break;
|
||||||
case BeTypeCode_Double:
|
case BeTypeCode_Float:
|
||||||
mcOperand.mImmF64 = constant->mDouble;
|
mcOperand.mImmF32 = constant->mDouble;
|
||||||
mcOperand.mKind = BeMCOperandKind_Immediate_f64;
|
mcOperand.mKind = BeMCOperandKind_Immediate_f32;
|
||||||
return mcOperand;
|
return mcOperand;
|
||||||
case BeTypeCode_Pointer:
|
case BeTypeCode_Double:
|
||||||
|
mcOperand.mImmF64 = constant->mDouble;
|
||||||
|
mcOperand.mKind = BeMCOperandKind_Immediate_f64;
|
||||||
|
return mcOperand;
|
||||||
|
case BeTypeCode_Pointer:
|
||||||
{
|
{
|
||||||
if (constant->mTarget == NULL)
|
if (constant->mTarget == NULL)
|
||||||
{
|
{
|
||||||
|
@ -2253,140 +2253,151 @@ BeMCOperand BeMCContext::GetOperand(BeValue* value, bool allowMetaResult, bool a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BeTypeCode_Struct:
|
case BeTypeCode_Struct:
|
||||||
case BeTypeCode_SizedArray:
|
case BeTypeCode_SizedArray:
|
||||||
case BeTypeCode_Vector:
|
case BeTypeCode_Vector:
|
||||||
|
mcOperand.mImmediate = constant->mInt64;
|
||||||
|
mcOperand.mKind = BeMCOperandKind_Immediate_i64;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Fail("Unhandled constant type");
|
||||||
|
}
|
||||||
mcOperand.mImmediate = constant->mInt64;
|
mcOperand.mImmediate = constant->mInt64;
|
||||||
mcOperand.mKind = BeMCOperandKind_Immediate_i64;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Fail("Unhandled constant type");
|
|
||||||
}
|
|
||||||
mcOperand.mImmediate = constant->mInt64;
|
|
||||||
return mcOperand;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BeStructConstant::TypeId:
|
|
||||||
{
|
|
||||||
auto structConstant = (BeStructConstant*)value;
|
|
||||||
|
|
||||||
BeMCOperand mcOperand;
|
|
||||||
mcOperand.mKind = BeMCOperandKind_ConstAgg;
|
|
||||||
mcOperand.mConstant = structConstant;
|
|
||||||
|
|
||||||
return mcOperand;
|
|
||||||
}
|
|
||||||
case BeGEP1Constant::TypeId:
|
|
||||||
{
|
|
||||||
auto gepConstant = (BeGEP1Constant*)value;
|
|
||||||
|
|
||||||
auto mcVal = GetOperand(gepConstant->mTarget);
|
|
||||||
|
|
||||||
BePointerType* ptrType = (BePointerType*)GetType(mcVal);
|
|
||||||
BEMC_ASSERT(ptrType->mTypeCode == BeTypeCode_Pointer);
|
|
||||||
|
|
||||||
auto result = mcVal;
|
|
||||||
|
|
||||||
// We assume we never do both an idx0 and idx1 at once. Fix if we change that.
|
|
||||||
int byteOffset = 0;
|
|
||||||
BeType* elementType = ptrType->mElementType;
|
|
||||||
byteOffset += gepConstant->mIdx0 * ptrType->mElementType->GetStride();
|
|
||||||
|
|
||||||
result = AllocRelativeVirtualReg(ptrType, result, GetImmediate(byteOffset), 1);
|
|
||||||
// The def is primary to create a single 'master location' for the GEP vreg to become legalized before use
|
|
||||||
auto vregInfo = GetVRegInfo(result);
|
|
||||||
vregInfo->mDefOnFirstUse = true;
|
|
||||||
result.mKind = BeMCOperandKind_VReg;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BeGEP2Constant::TypeId:
|
|
||||||
{
|
|
||||||
auto gepConstant = (BeGEP2Constant*)value;
|
|
||||||
|
|
||||||
auto mcVal = GetOperand(gepConstant->mTarget);
|
|
||||||
|
|
||||||
BePointerType* ptrType = (BePointerType*)GetType(mcVal);
|
|
||||||
BEMC_ASSERT(ptrType->mTypeCode == BeTypeCode_Pointer);
|
|
||||||
|
|
||||||
auto result = mcVal;
|
|
||||||
|
|
||||||
// We assume we never do both an idx0 and idx1 at once. Fix if we change that.
|
|
||||||
int byteOffset = 0;
|
|
||||||
BeType* elementType = NULL;
|
|
||||||
byteOffset += gepConstant->mIdx0 * ptrType->mElementType->GetStride();
|
|
||||||
|
|
||||||
if (ptrType->mElementType->mTypeCode == BeTypeCode_Struct)
|
|
||||||
{
|
|
||||||
BeStructType* structType = (BeStructType*)ptrType->mElementType;
|
|
||||||
auto& structMember = structType->mMembers[gepConstant->mIdx1];
|
|
||||||
elementType = structMember.mType;
|
|
||||||
byteOffset = structMember.mByteOffset;
|
|
||||||
}
|
|
||||||
else if (ptrType->mElementType->mTypeCode == BeTypeCode_SizedArray)
|
|
||||||
{
|
|
||||||
BEMC_ASSERT(ptrType->mElementType->mTypeCode == BeTypeCode_SizedArray);
|
|
||||||
auto arrayType = (BeSizedArrayType*)ptrType->mElementType;
|
|
||||||
elementType = arrayType->mElementType;
|
|
||||||
byteOffset = gepConstant->mIdx1 * elementType->GetStride();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BEMC_ASSERT(ptrType->mElementType->mTypeCode == BeTypeCode_Vector);
|
|
||||||
auto arrayType = (BeVectorType*)ptrType->mElementType;
|
|
||||||
elementType = arrayType->mElementType;
|
|
||||||
byteOffset = gepConstant->mIdx1 * elementType->GetStride();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto elementPtrType = mModule->mContext->GetPointerTo(elementType);
|
|
||||||
result = AllocRelativeVirtualReg(elementPtrType, result, GetImmediate(byteOffset), 1);
|
|
||||||
// The def is primary to create a single 'master location' for the GEP vreg to become legalized before use
|
|
||||||
auto vregInfo = GetVRegInfo(result);
|
|
||||||
vregInfo->mDefOnFirstUse = true;
|
|
||||||
result.mKind = BeMCOperandKind_VReg;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BeExtractValueConstant::TypeId:
|
|
||||||
{
|
|
||||||
// Note: this only handles zero-aggregates
|
|
||||||
auto extractConstant = (BeExtractValueConstant*)value;
|
|
||||||
auto elementType = extractConstant->GetType();
|
|
||||||
|
|
||||||
auto mcVal = GetOperand(extractConstant->mTarget);
|
|
||||||
auto valType = GetType(mcVal);
|
|
||||||
|
|
||||||
BeConstant beConstant;
|
|
||||||
beConstant.mType = elementType;
|
|
||||||
beConstant.mUInt64 = 0;
|
|
||||||
return GetOperand(&beConstant);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BeFunction::TypeId:
|
|
||||||
{
|
|
||||||
auto sym = mCOFFObject->GetSymbol(value);
|
|
||||||
BEMC_ASSERT(sym != NULL);
|
|
||||||
if (sym != NULL)
|
|
||||||
{
|
|
||||||
BeMCOperand mcOperand;
|
|
||||||
mcOperand.mKind = BeMCOperandKind_SymbolAddr;
|
|
||||||
mcOperand.mSymbolIdx = sym->mIdx;
|
|
||||||
return mcOperand;
|
return mcOperand;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case BeStructConstant::TypeId:
|
||||||
|
{
|
||||||
|
auto structConstant = (BeStructConstant*)value;
|
||||||
|
|
||||||
|
BeMCOperand mcOperand;
|
||||||
|
mcOperand.mKind = BeMCOperandKind_ConstAgg;
|
||||||
|
mcOperand.mConstant = structConstant;
|
||||||
|
|
||||||
|
return mcOperand;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BeGEP1Constant::TypeId:
|
||||||
|
{
|
||||||
|
auto gepConstant = (BeGEP1Constant*)value;
|
||||||
|
|
||||||
|
auto mcVal = GetOperand(gepConstant->mTarget);
|
||||||
|
|
||||||
|
BePointerType* ptrType = (BePointerType*)GetType(mcVal);
|
||||||
|
BEMC_ASSERT(ptrType->mTypeCode == BeTypeCode_Pointer);
|
||||||
|
|
||||||
|
auto result = mcVal;
|
||||||
|
|
||||||
|
// We assume we never do both an idx0 and idx1 at once. Fix if we change that.
|
||||||
|
int byteOffset = 0;
|
||||||
|
BeType* elementType = ptrType->mElementType;
|
||||||
|
byteOffset += gepConstant->mIdx0 * ptrType->mElementType->GetStride();
|
||||||
|
|
||||||
|
result = AllocRelativeVirtualReg(ptrType, result, GetImmediate(byteOffset), 1);
|
||||||
|
// The def is primary to create a single 'master location' for the GEP vreg to become legalized before use
|
||||||
|
auto vregInfo = GetVRegInfo(result);
|
||||||
|
vregInfo->mDefOnFirstUse = true;
|
||||||
|
result.mKind = BeMCOperandKind_VReg;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BeGEP2Constant::TypeId:
|
||||||
|
{
|
||||||
|
auto gepConstant = (BeGEP2Constant*)value;
|
||||||
|
|
||||||
|
auto mcVal = GetOperand(gepConstant->mTarget);
|
||||||
|
|
||||||
|
BePointerType* ptrType = (BePointerType*)GetType(mcVal);
|
||||||
|
BEMC_ASSERT(ptrType->mTypeCode == BeTypeCode_Pointer);
|
||||||
|
|
||||||
|
auto result = mcVal;
|
||||||
|
|
||||||
|
// We assume we never do both an idx0 and idx1 at once. Fix if we change that.
|
||||||
|
int byteOffset = 0;
|
||||||
|
BeType* elementType = NULL;
|
||||||
|
byteOffset += gepConstant->mIdx0 * ptrType->mElementType->GetStride();
|
||||||
|
|
||||||
|
if (ptrType->mElementType->mTypeCode == BeTypeCode_Struct)
|
||||||
|
{
|
||||||
|
BeStructType* structType = (BeStructType*)ptrType->mElementType;
|
||||||
|
auto& structMember = structType->mMembers[gepConstant->mIdx1];
|
||||||
|
elementType = structMember.mType;
|
||||||
|
byteOffset = structMember.mByteOffset;
|
||||||
|
}
|
||||||
|
else if (ptrType->mElementType->mTypeCode == BeTypeCode_SizedArray)
|
||||||
|
{
|
||||||
|
BEMC_ASSERT(ptrType->mElementType->mTypeCode == BeTypeCode_SizedArray);
|
||||||
|
auto arrayType = (BeSizedArrayType*)ptrType->mElementType;
|
||||||
|
elementType = arrayType->mElementType;
|
||||||
|
byteOffset = gepConstant->mIdx1 * elementType->GetStride();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BEMC_ASSERT(ptrType->mElementType->mTypeCode == BeTypeCode_Vector);
|
||||||
|
auto arrayType = (BeVectorType*)ptrType->mElementType;
|
||||||
|
elementType = arrayType->mElementType;
|
||||||
|
byteOffset = gepConstant->mIdx1 * elementType->GetStride();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto elementPtrType = mModule->mContext->GetPointerTo(elementType);
|
||||||
|
result = AllocRelativeVirtualReg(elementPtrType, result, GetImmediate(byteOffset), 1);
|
||||||
|
// The def is primary to create a single 'master location' for the GEP vreg to become legalized before use
|
||||||
|
auto vregInfo = GetVRegInfo(result);
|
||||||
|
vregInfo->mDefOnFirstUse = true;
|
||||||
|
result.mKind = BeMCOperandKind_VReg;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BeExtractValueConstant::TypeId:
|
||||||
|
{
|
||||||
|
// Note: this only handles zero-aggregates
|
||||||
|
auto extractConstant = (BeExtractValueConstant*)value;
|
||||||
|
auto elementType = extractConstant->GetType();
|
||||||
|
|
||||||
|
auto mcVal = GetOperand(extractConstant->mTarget);
|
||||||
|
auto valType = GetType(mcVal);
|
||||||
|
|
||||||
|
BeConstant beConstant;
|
||||||
|
beConstant.mType = elementType;
|
||||||
|
beConstant.mUInt64 = 0;
|
||||||
|
return GetOperand(&beConstant);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BeUndefConstant::TypeId:
|
||||||
|
{
|
||||||
|
auto undefConstant = (BeUndefConstant*)value;
|
||||||
|
BeConstant beConstant;
|
||||||
|
beConstant.mType = undefConstant->mType;
|
||||||
|
beConstant.mUInt64 = 0;
|
||||||
|
return GetOperand(&beConstant);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BeFunction::TypeId:
|
||||||
|
{
|
||||||
|
auto sym = mCOFFObject->GetSymbol(value);
|
||||||
|
BEMC_ASSERT(sym != NULL);
|
||||||
|
if (sym != NULL)
|
||||||
|
{
|
||||||
|
BeMCOperand mcOperand;
|
||||||
|
mcOperand.mKind = BeMCOperandKind_SymbolAddr;
|
||||||
|
mcOperand.mSymbolIdx = sym->mIdx;
|
||||||
|
return mcOperand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case BeCallInst::TypeId:
|
case BeCallInst::TypeId:
|
||||||
{
|
{
|
||||||
auto callInst = (BeCallInst*)value;
|
auto callInst = (BeCallInst*)value;
|
||||||
if (callInst->mInlineResult != NULL)
|
if (callInst->mInlineResult != NULL)
|
||||||
return GetOperand(callInst->mInlineResult);
|
return GetOperand(callInst->mInlineResult);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BeDbgVariable::TypeId:
|
case BeDbgVariable::TypeId:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
BeMCOperand* operandPtr = NULL;
|
BeMCOperand* operandPtr = NULL;
|
||||||
|
|
|
@ -2344,7 +2344,8 @@ void BfIRCodeGen::HandleNextCmd()
|
||||||
{
|
{
|
||||||
CMD_PARAM_NOTRANS(llvm::Value*, val);
|
CMD_PARAM_NOTRANS(llvm::Value*, val);
|
||||||
CMD_PARAM(String, name);
|
CMD_PARAM(String, name);
|
||||||
val->setName(name.c_str());
|
if (!val->getType()->isVoidTy())
|
||||||
|
val->setName(name.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BfIRCmd_CreateUndefValue:
|
case BfIRCmd_CreateUndefValue:
|
||||||
|
|
|
@ -9097,11 +9097,8 @@ BfTypedValue BfModule::FlushNullConditional(BfTypedValue result, bool ignoreNull
|
||||||
{
|
{
|
||||||
auto pendingNullCond = mCurMethodState->mPendingNullConditional;
|
auto pendingNullCond = mCurMethodState->mPendingNullConditional;
|
||||||
|
|
||||||
if ((result) && (!ignoreNullable))
|
if ((result) && (!result.mType->IsVar()) && (!ignoreNullable))
|
||||||
{
|
{
|
||||||
if (result.mType->IsVar())
|
|
||||||
return result;
|
|
||||||
|
|
||||||
auto notNullBB = mBfIRBuilder->GetInsertBlock();
|
auto notNullBB = mBfIRBuilder->GetInsertBlock();
|
||||||
|
|
||||||
//TODO: Make this work, needed for 'void' and such
|
//TODO: Make this work, needed for 'void' and such
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue