1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Better fix for direct autprop optimization

This commit is contained in:
Brian Fiete 2021-01-20 08:53:43 -08:00
parent b5aa92ff33
commit 3fddd4f396
6 changed files with 31 additions and 13 deletions

View file

@ -557,6 +557,7 @@ public:
enum BfTypedValueKind
{
BfTypedValueKind_Addr,
BfTypedValueKind_CopyOnMutateAddr,
BfTypedValueKind_ReadOnlyAddr,
BfTypedValueKind_TempAddr,
BfTypedValueKind_RestrictedTempAddr,
@ -674,6 +675,11 @@ public:
return ((mKind == BfTypedValueKind_ReadOnlyTempAddr) || (mKind == BfTypedValueKind_RestrictedTempAddr) || (mKind == BfTypedValueKind_TempAddr));
}
bool IsCopyOnMutate() const
{
return (mKind == BfTypedValueKind_CopyOnMutateAddr);
}
bool IsReadOnly() const
{
switch (mKind)

View file

@ -4573,6 +4573,9 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
target = BfTypedValue(allocaInst, primStructType, true);
}
if (target.IsCopyOnMutate())
target = mModule->CopyValue(target);
BfTypedValue targetValue;
if ((isBaseLookup) && (!target.IsSplat()))
{
@ -4848,12 +4851,8 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
}
}
if (needsCopy)
{
result = mModule->LoadValue(result);
result = mModule->MakeAddressable(result);
result = mModule->RemoveReadOnly(result);
}
if (result.mKind == BfTypedValueKind_Addr)
result.mKind = BfTypedValueKind_CopyOnMutateAddr;
mPropDef = NULL;
mPropSrc = NULL;
@ -16978,8 +16977,11 @@ bool BfExprEvaluator::CheckIsBase(BfAstNode* checkNode)
return true;
}
bool BfExprEvaluator::CheckModifyResult(BfTypedValue typedVal, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut, bool emitWarning)
bool BfExprEvaluator::CheckModifyResult(BfTypedValue typedVal, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut, bool emitWarning, bool skipCopyOnMutate)
{
if ((!skipCopyOnMutate) && (typedVal.IsCopyOnMutate()))
typedVal = mModule->CopyValue(typedVal);
BfLocalVariable* localVar = NULL;
bool isCapturedLocal = false;
if (mResultLocalVar != NULL)
@ -17581,11 +17583,11 @@ void BfExprEvaluator::PerformAssignment(BfAssignmentExpression* assignExpr, bool
}
ResolveGenericType();
auto ptr = mResult;
auto ptr = mResult;
mResult = BfTypedValue();
if (mPropDef == NULL)
{
if (!CheckModifyResult(ptr, assignExpr->mOpToken, "assign to"))
if (!CheckModifyResult(ptr, assignExpr->mOpToken, "assign to", false, false, true))
{
if (assignExpr->mRight != NULL)
mModule->CreateValueFromExpression(assignExpr->mRight, ptr.mType, BfEvalExprFlags_NoCast);

View file

@ -414,7 +414,7 @@ public:
void MarkResultAssigned();
void MakeResultAsValue();
bool CheckIsBase(BfAstNode* checkNode);
bool CheckModifyResult(BfTypedValue typeValue, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut = false, bool emitWarning = false);
bool CheckModifyResult(BfTypedValue typeValue, BfAstNode* refNode, const char* modifyType, bool onlyNeedsMut = false, bool emitWarning = false, bool skipCopyOnMutate = false);
bool CheckGenericCtor(BfGenericParamType* genericParamType, BfResolvedArgs& argValues, BfAstNode* targetSrc);
BfTypedValue LookupField(BfAstNode* targetSrc, BfTypedValue target, const StringImpl& fieldName, BfLookupFieldFlags flags = BfLookupFieldFlag_None);
void CheckObjectCreateTypeRef(BfType* expectingType, BfAstNode* afterNode);

View file

@ -11754,7 +11754,7 @@ void BfModule::AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal
checkTypeLambda(typedValue.mType, addrVal);
}
BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal)
BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable)
{
bool wasReadOnly = typedVal.IsReadOnly();
@ -11775,6 +11775,9 @@ BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal)
else
mBfIRBuilder->CreateAlignedStore(typedVal.mValue, tempVar, type->mAlign);
if (forceMutable)
wasReadOnly = false;
return BfTypedValue(tempVar, type,
typedVal.IsThis() ?
(wasReadOnly ? BfTypedValueKind_ReadOnlyThisAddr : BfTypedValueKind_ThisAddr) :
@ -11790,6 +11793,11 @@ BfTypedValue BfModule::RemoveReadOnly(BfTypedValue typedValue)
return typedValue;
}
BfTypedValue BfModule::CopyValue(const BfTypedValue& typedValue)
{
return MakeAddressable(LoadValue(typedValue), true);
}
BfIRValue BfModule::ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType, bool* isAddr)
{
BF_ASSERT(!mIsComptimeModule);

View file

@ -1632,8 +1632,9 @@ public:
BfTypedValue PrepareConst(BfTypedValue& typedValue);
void AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal);
BfTypedValue AggregateSplat(BfTypedValue typedValue, BfIRValue* valueArrPtr = NULL);
BfTypedValue MakeAddressable(BfTypedValue typedValue);
BfTypedValue MakeAddressable(BfTypedValue typedValue, bool forceMutable = false);
BfTypedValue RemoveReadOnly(BfTypedValue typedValue);
BfTypedValue CopyValue(const BfTypedValue& typedValue);
BfIRValue ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType = NULL, bool* isAddr = NULL);
BfTypedValue ExtractValue(BfTypedValue typedValue, BfFieldInstance* fieldInst, int fieldIdx);
BfIRValue ExtractValue(BfTypedValue typedValue, int dataIdx);
@ -1765,7 +1766,7 @@ public:
BfMethodRefType* CreateMethodRefType(BfMethodInstance* methodInstance, bool mustAlreadyExist = false);
BfType* FixIntUnknown(BfType* type);
void FixIntUnknown(BfTypedValue& typedVal, BfType* matchType = NULL);
void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs);
void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs);
void FixValueActualization(BfTypedValue& typedVal);
bool TypeEquals(BfTypedValue& val, BfType* type);
BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);

View file

@ -29,6 +29,7 @@ namespace Tests
public this()
{
B = .();
B.mA += 1000;
}
}