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:
parent
b5aa92ff33
commit
3fddd4f396
6 changed files with 31 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
@ -17585,7 +17587,7 @@ void BfExprEvaluator::PerformAssignment(BfAssignmentExpression* assignExpr, bool
|
|||
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace Tests
|
|||
public this()
|
||||
{
|
||||
B = .();
|
||||
B.mA += 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue