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
|
enum BfTypedValueKind
|
||||||
{
|
{
|
||||||
BfTypedValueKind_Addr,
|
BfTypedValueKind_Addr,
|
||||||
|
BfTypedValueKind_CopyOnMutateAddr,
|
||||||
BfTypedValueKind_ReadOnlyAddr,
|
BfTypedValueKind_ReadOnlyAddr,
|
||||||
BfTypedValueKind_TempAddr,
|
BfTypedValueKind_TempAddr,
|
||||||
BfTypedValueKind_RestrictedTempAddr,
|
BfTypedValueKind_RestrictedTempAddr,
|
||||||
|
@ -674,6 +675,11 @@ public:
|
||||||
return ((mKind == BfTypedValueKind_ReadOnlyTempAddr) || (mKind == BfTypedValueKind_RestrictedTempAddr) || (mKind == BfTypedValueKind_TempAddr));
|
return ((mKind == BfTypedValueKind_ReadOnlyTempAddr) || (mKind == BfTypedValueKind_RestrictedTempAddr) || (mKind == BfTypedValueKind_TempAddr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsCopyOnMutate() const
|
||||||
|
{
|
||||||
|
return (mKind == BfTypedValueKind_CopyOnMutateAddr);
|
||||||
|
}
|
||||||
|
|
||||||
bool IsReadOnly() const
|
bool IsReadOnly() const
|
||||||
{
|
{
|
||||||
switch (mKind)
|
switch (mKind)
|
||||||
|
|
|
@ -4573,6 +4573,9 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
target = BfTypedValue(allocaInst, primStructType, true);
|
target = BfTypedValue(allocaInst, primStructType, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target.IsCopyOnMutate())
|
||||||
|
target = mModule->CopyValue(target);
|
||||||
|
|
||||||
BfTypedValue targetValue;
|
BfTypedValue targetValue;
|
||||||
if ((isBaseLookup) && (!target.IsSplat()))
|
if ((isBaseLookup) && (!target.IsSplat()))
|
||||||
{
|
{
|
||||||
|
@ -4848,12 +4851,8 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needsCopy)
|
if (result.mKind == BfTypedValueKind_Addr)
|
||||||
{
|
result.mKind = BfTypedValueKind_CopyOnMutateAddr;
|
||||||
result = mModule->LoadValue(result);
|
|
||||||
result = mModule->MakeAddressable(result);
|
|
||||||
result = mModule->RemoveReadOnly(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
mPropDef = NULL;
|
mPropDef = NULL;
|
||||||
mPropSrc = NULL;
|
mPropSrc = NULL;
|
||||||
|
@ -16978,8 +16977,11 @@ bool BfExprEvaluator::CheckIsBase(BfAstNode* checkNode)
|
||||||
return true;
|
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;
|
BfLocalVariable* localVar = NULL;
|
||||||
bool isCapturedLocal = false;
|
bool isCapturedLocal = false;
|
||||||
if (mResultLocalVar != NULL)
|
if (mResultLocalVar != NULL)
|
||||||
|
@ -17581,11 +17583,11 @@ void BfExprEvaluator::PerformAssignment(BfAssignmentExpression* assignExpr, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolveGenericType();
|
ResolveGenericType();
|
||||||
auto ptr = mResult;
|
auto ptr = mResult;
|
||||||
mResult = BfTypedValue();
|
mResult = BfTypedValue();
|
||||||
if (mPropDef == NULL)
|
if (mPropDef == NULL)
|
||||||
{
|
{
|
||||||
if (!CheckModifyResult(ptr, assignExpr->mOpToken, "assign to"))
|
if (!CheckModifyResult(ptr, assignExpr->mOpToken, "assign to", false, false, true))
|
||||||
{
|
{
|
||||||
if (assignExpr->mRight != NULL)
|
if (assignExpr->mRight != NULL)
|
||||||
mModule->CreateValueFromExpression(assignExpr->mRight, ptr.mType, BfEvalExprFlags_NoCast);
|
mModule->CreateValueFromExpression(assignExpr->mRight, ptr.mType, BfEvalExprFlags_NoCast);
|
||||||
|
|
|
@ -414,7 +414,7 @@ public:
|
||||||
void MarkResultAssigned();
|
void MarkResultAssigned();
|
||||||
void MakeResultAsValue();
|
void MakeResultAsValue();
|
||||||
bool CheckIsBase(BfAstNode* checkNode);
|
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);
|
bool CheckGenericCtor(BfGenericParamType* genericParamType, BfResolvedArgs& argValues, BfAstNode* targetSrc);
|
||||||
BfTypedValue LookupField(BfAstNode* targetSrc, BfTypedValue target, const StringImpl& fieldName, BfLookupFieldFlags flags = BfLookupFieldFlag_None);
|
BfTypedValue LookupField(BfAstNode* targetSrc, BfTypedValue target, const StringImpl& fieldName, BfLookupFieldFlags flags = BfLookupFieldFlag_None);
|
||||||
void CheckObjectCreateTypeRef(BfType* expectingType, BfAstNode* afterNode);
|
void CheckObjectCreateTypeRef(BfType* expectingType, BfAstNode* afterNode);
|
||||||
|
|
|
@ -11754,7 +11754,7 @@ void BfModule::AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal
|
||||||
checkTypeLambda(typedValue.mType, addrVal);
|
checkTypeLambda(typedValue.mType, addrVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal)
|
BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable)
|
||||||
{
|
{
|
||||||
bool wasReadOnly = typedVal.IsReadOnly();
|
bool wasReadOnly = typedVal.IsReadOnly();
|
||||||
|
|
||||||
|
@ -11775,6 +11775,9 @@ BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal)
|
||||||
else
|
else
|
||||||
mBfIRBuilder->CreateAlignedStore(typedVal.mValue, tempVar, type->mAlign);
|
mBfIRBuilder->CreateAlignedStore(typedVal.mValue, tempVar, type->mAlign);
|
||||||
|
|
||||||
|
if (forceMutable)
|
||||||
|
wasReadOnly = false;
|
||||||
|
|
||||||
return BfTypedValue(tempVar, type,
|
return BfTypedValue(tempVar, type,
|
||||||
typedVal.IsThis() ?
|
typedVal.IsThis() ?
|
||||||
(wasReadOnly ? BfTypedValueKind_ReadOnlyThisAddr : BfTypedValueKind_ThisAddr) :
|
(wasReadOnly ? BfTypedValueKind_ReadOnlyThisAddr : BfTypedValueKind_ThisAddr) :
|
||||||
|
@ -11790,6 +11793,11 @@ BfTypedValue BfModule::RemoveReadOnly(BfTypedValue typedValue)
|
||||||
return 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)
|
BfIRValue BfModule::ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType, bool* isAddr)
|
||||||
{
|
{
|
||||||
BF_ASSERT(!mIsComptimeModule);
|
BF_ASSERT(!mIsComptimeModule);
|
||||||
|
|
|
@ -1632,8 +1632,9 @@ public:
|
||||||
BfTypedValue PrepareConst(BfTypedValue& typedValue);
|
BfTypedValue PrepareConst(BfTypedValue& typedValue);
|
||||||
void AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal);
|
void AggregateSplatIntoAddr(BfTypedValue typedValue, BfIRValue addrVal);
|
||||||
BfTypedValue AggregateSplat(BfTypedValue typedValue, BfIRValue* valueArrPtr = NULL);
|
BfTypedValue AggregateSplat(BfTypedValue typedValue, BfIRValue* valueArrPtr = NULL);
|
||||||
BfTypedValue MakeAddressable(BfTypedValue typedValue);
|
BfTypedValue MakeAddressable(BfTypedValue typedValue, bool forceMutable = false);
|
||||||
BfTypedValue RemoveReadOnly(BfTypedValue typedValue);
|
BfTypedValue RemoveReadOnly(BfTypedValue typedValue);
|
||||||
|
BfTypedValue CopyValue(const BfTypedValue& typedValue);
|
||||||
BfIRValue ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType = NULL, bool* isAddr = NULL);
|
BfIRValue ExtractSplatValue(BfTypedValue typedValue, int componentIdx, BfType* wantType = NULL, bool* isAddr = NULL);
|
||||||
BfTypedValue ExtractValue(BfTypedValue typedValue, BfFieldInstance* fieldInst, int fieldIdx);
|
BfTypedValue ExtractValue(BfTypedValue typedValue, BfFieldInstance* fieldInst, int fieldIdx);
|
||||||
BfIRValue ExtractValue(BfTypedValue typedValue, int dataIdx);
|
BfIRValue ExtractValue(BfTypedValue typedValue, int dataIdx);
|
||||||
|
@ -1765,7 +1766,7 @@ public:
|
||||||
BfMethodRefType* CreateMethodRefType(BfMethodInstance* methodInstance, bool mustAlreadyExist = false);
|
BfMethodRefType* CreateMethodRefType(BfMethodInstance* methodInstance, bool mustAlreadyExist = false);
|
||||||
BfType* FixIntUnknown(BfType* type);
|
BfType* FixIntUnknown(BfType* type);
|
||||||
void FixIntUnknown(BfTypedValue& typedVal, BfType* matchType = NULL);
|
void FixIntUnknown(BfTypedValue& typedVal, BfType* matchType = NULL);
|
||||||
void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs);
|
void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs);
|
||||||
void FixValueActualization(BfTypedValue& typedVal);
|
void FixValueActualization(BfTypedValue& typedVal);
|
||||||
bool TypeEquals(BfTypedValue& val, BfType* type);
|
bool TypeEquals(BfTypedValue& val, BfType* type);
|
||||||
BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
|
BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace Tests
|
||||||
public this()
|
public this()
|
||||||
{
|
{
|
||||||
B = .();
|
B = .();
|
||||||
|
B.mA += 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue