mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Cache ConstExpr ToString, fix const arg int comparison in cast
This commit is contained in:
parent
337a94b8b5
commit
d341104a57
5 changed files with 27 additions and 11 deletions
|
@ -2193,9 +2193,14 @@ void BfContext::UpdateRevisedTypes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebuild all types
|
// Rebuild all types
|
||||||
|
Array<BfType*> allTypes;
|
||||||
for (auto type : mResolvedTypes)
|
for (auto type : mResolvedTypes)
|
||||||
|
allTypes.Add(type);
|
||||||
|
|
||||||
|
for (auto type : allTypes)
|
||||||
{
|
{
|
||||||
RebuildType(type);
|
if (!type->IsDeleting())
|
||||||
|
RebuildType(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -466,6 +466,11 @@ void BfIRConstHolder::pv(const BfIRValue& irValue)
|
||||||
|
|
||||||
void BfIRConstHolder::FixTypeCode(BfTypeCode& typeCode)
|
void BfIRConstHolder::FixTypeCode(BfTypeCode& typeCode)
|
||||||
{
|
{
|
||||||
|
if (typeCode == BfTypeCode_IntUnknown)
|
||||||
|
typeCode = BfTypeCode_Int64;
|
||||||
|
if (typeCode == BfTypeCode_UIntUnknown)
|
||||||
|
typeCode = BfTypeCode_UInt64;
|
||||||
|
|
||||||
if (typeCode == BfTypeCode_IntPtr)
|
if (typeCode == BfTypeCode_IntPtr)
|
||||||
{
|
{
|
||||||
if (mModule->mSystem->mPtrSize == 4)
|
if (mModule->mSystem->mPtrSize == 4)
|
||||||
|
@ -740,11 +745,6 @@ BfIRType BfIRConstHolder::GetSizedArrayType(BfIRType elementType, int length)
|
||||||
|
|
||||||
BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, uint64 val)
|
BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, uint64 val)
|
||||||
{
|
{
|
||||||
if (typeCode == BfTypeCode_IntUnknown)
|
|
||||||
typeCode = BfTypeCode_Int64;
|
|
||||||
else if (typeCode == BfTypeCode_UIntUnknown)
|
|
||||||
typeCode = BfTypeCode_UInt64;
|
|
||||||
|
|
||||||
FixTypeCode(typeCode);
|
FixTypeCode(typeCode);
|
||||||
BfConstant* constant = mTempAlloc.Alloc<BfConstant>();
|
BfConstant* constant = mTempAlloc.Alloc<BfConstant>();
|
||||||
constant->mTypeCode = typeCode;
|
constant->mTypeCode = typeCode;
|
||||||
|
@ -2720,7 +2720,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine)
|
void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine)
|
||||||
{
|
{
|
||||||
auto populateModule = mModule->mContext->mUnreifiedModule;
|
auto populateModule = mModule->mContext->mUnreifiedModule;
|
||||||
auto typeInstance = type->ToTypeInstance();
|
auto typeInstance = type->ToTypeInstance();
|
||||||
if ((typeInstance != NULL) && (typeInstance->mModule != NULL))
|
if ((typeInstance != NULL) && (typeInstance->mModule != NULL))
|
||||||
|
@ -3112,7 +3112,7 @@ void BfIRBuilder::CreateTypeDeclaration(BfType* type, bool forceDbgDefine)
|
||||||
{
|
{
|
||||||
irType = GetPrimitiveType(BfTypeCode_None);
|
irType = GetPrimitiveType(BfTypeCode_None);
|
||||||
if (wantDIData)
|
if (wantDIData)
|
||||||
diType = DbgCreateBasicType("void", 0, 0, llvm::dwarf::DW_ATE_address);
|
diType = DbgCreateBasicType("void", 0, 0, llvm::dwarf::DW_ATE_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (irType)
|
if (irType)
|
||||||
|
|
|
@ -12842,6 +12842,13 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue&
|
||||||
case BfTypeCode_Char32:
|
case BfTypeCode_Char32:
|
||||||
case BfTypeCode_StringId:
|
case BfTypeCode_StringId:
|
||||||
variant.mTypeCode = constant->mTypeCode;
|
variant.mTypeCode = constant->mTypeCode;
|
||||||
|
if (((variant.mTypeCode == BfTypeCode_Int64) || (variant.mTypeCode == BfTypeCode_UInt64)) &&
|
||||||
|
(primType->mSize > 0) && (primType->mSize < 8) &&
|
||||||
|
(mBfIRBuilder->IsIntable(primType->GetTypeCode())))
|
||||||
|
{
|
||||||
|
// We may have an 'int unknown' that we need to downsize
|
||||||
|
variant.mTypeCode = primType->GetTypeCode();
|
||||||
|
}
|
||||||
variant.mInt64 = constant->mInt64;
|
variant.mInt64 = constant->mInt64;
|
||||||
break;
|
break;
|
||||||
case BfTypeCode_Float:
|
case BfTypeCode_Float:
|
||||||
|
|
|
@ -13786,7 +13786,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
auto variantVal = TypedValueToVariant(srcNode, typedVal, true);
|
auto variantVal = TypedValueToVariant(srcNode, typedVal, true);
|
||||||
if ((mBfIRBuilder->IsIntable(variantVal.mTypeCode)) && (mBfIRBuilder->IsIntable(toConstExprValueType->mValue.mTypeCode)))
|
if ((mBfIRBuilder->IsIntable(variantVal.mTypeCode)) && (mBfIRBuilder->IsIntable(toConstExprValueType->mValue.mTypeCode)))
|
||||||
{
|
{
|
||||||
if (variantVal == toConstExprValueType->mValue)
|
if (variantVal.mUInt64 == toConstExprValueType->mValue.mUInt64)
|
||||||
return typedVal.mValue;
|
return typedVal.mValue;
|
||||||
}
|
}
|
||||||
else if ((mBfIRBuilder->IsFloat(variantVal.mTypeCode)) && (mBfIRBuilder->IsFloat(toConstExprValueType->mValue.mTypeCode)))
|
else if ((mBfIRBuilder->IsFloat(variantVal.mTypeCode)) && (mBfIRBuilder->IsFloat(toConstExprValueType->mValue.mTypeCode)))
|
||||||
|
@ -16210,7 +16210,10 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VariantToString(str, constExprValueType->mValue, constExprValueType->mType);
|
if (constExprValueType->mValueString.IsEmpty())
|
||||||
|
VariantToString(constExprValueType->mValueString, constExprValueType->mValue, constExprValueType->mType);
|
||||||
|
|
||||||
|
str += constExprValueType->mValueString;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2611,6 +2611,7 @@ class BfConstExprValueType : public BfDependedType
|
||||||
public:
|
public:
|
||||||
BfType* mType;
|
BfType* mType;
|
||||||
BfVariant mValue;
|
BfVariant mValue;
|
||||||
|
String mValueString;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~BfConstExprValueType();
|
~BfConstExprValueType();
|
||||||
|
@ -2827,7 +2828,7 @@ public:
|
||||||
|
|
||||||
// checkEntry->mType can be NULL if we're in the process of filling it in (and this Insert is from an element type)
|
// checkEntry->mType can be NULL if we're in the process of filling it in (and this Insert is from an element type)
|
||||||
// OR if the type resolution failed after node insertion
|
// OR if the type resolution failed after node insertion
|
||||||
if ((checkEntry->mValue != NULL) && (hashVal == checkEntry->mHashCode) && (Equals(checkEntry->mValue, findType, ctx)))
|
if ((checkEntry->mValue != NULL) && (hashVal == checkEntry->mHashCode) && (Equals(checkEntry->mValue, findType, ctx)))
|
||||||
{
|
{
|
||||||
*entryPtr = EntryRef(this, checkEntryIdx);
|
*entryPtr = EntryRef(this, checkEntryIdx);
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue