From dce1b9442592ea4d7402db36fbc4c961a5091fa1 Mon Sep 17 00:00:00 2001 From: "@evian_hill" Date: Thu, 29 Apr 2021 20:38:48 +0800 Subject: [PATCH] union address-type-fields for agg copy --- src/mapleall/maple_me/include/alias_class.h | 3 +- src/mapleall/maple_me/src/alias_class.cpp | 56 ++++++++++++++++++--- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/mapleall/maple_me/include/alias_class.h b/src/mapleall/maple_me/include/alias_class.h index 85bfd8dec1..1edb5810d0 100644 --- a/src/mapleall/maple_me/include/alias_class.h +++ b/src/mapleall/maple_me/include/alias_class.h @@ -187,7 +187,8 @@ class AliasClass : public AnalysisResult { void SetPtrOpndNextLevNADS(const BaseNode &opnd, AliasElem *aliasElem, bool hasNoPrivateDefEffect); void SetPtrOpndsNextLevNADS(unsigned int start, unsigned int end, MapleVector &opnds, bool hasNoPrivateDefEffect); - void ApplyUnionForDassignCopy(const AliasElem &lhsAe, const AliasElem *rhsAe, const BaseNode &rhs); + void ApplyUnionForAggDassign(AliasElem *lhsAe, AliasElem *rhsAe); + void ApplyUnionForDassignCopy(AliasElem *lhsAe, AliasElem *rhsAe, const BaseNode &rhs); void CreateMirroringAliasElems(const OriginalSt *ost1, OriginalSt *ost2); AliasElem *FindOrCreateDummyNADSAe(); bool IsPointedTo(OriginalSt &oSt); diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index fa0aeb1082..a1406aa187 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -276,7 +276,7 @@ AliasInfo AliasClass::CreateAliasElemsExpr(BaseNode &expr) { if (ainfo2.ae == nullptr) { return ainfo; } - ApplyUnionForDassignCopy(*ainfo.ae, ainfo2.ae, *expr.Opnd(2)); + ApplyUnionForDassignCopy(ainfo.ae, ainfo2.ae, *expr.Opnd(2)); return ainfo; } case OP_intrinsicop: { @@ -306,19 +306,59 @@ void AliasClass::SetNotAllDefsSeenForMustDefs(const StmtNode &callas) { } } -void AliasClass::ApplyUnionForDassignCopy(const AliasElem &lhsAe, const AliasElem *rhsAe, const BaseNode &rhs) { +void AliasClass::ApplyUnionForAggDassign(AliasElem *lhsAe, AliasElem *rhsAe) { + auto &lhsOst = lhsAe->GetOriginalSt(); + auto &rhsOst = rhsAe->GetOriginalSt(); + if (lhsOst.GetTyIdx() != rhsOst.GetTyIdx()) { + return; + } + + auto *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(lhsOst.GetTyIdx()); + if (mirType->GetKind() != kTypeStruct && mirType->GetKind() != kTypeUnion && mirType->GetKind() != kTypeClass) { + return; + } + + uint32 fieldNum = static_cast(mirType)->NumberOfFieldIDs(); + for (uint32 fieldId = 1; fieldId <= fieldNum; ++fieldId) { + auto *fieldType = static_cast(mirType)->GetFieldType(fieldId); + if (!IsPotentialAddress(fieldType->GetPrimType(), &mirModule)) { + continue; + } + + auto *ostOfLHSField = ssaTab.FindOrCreateSymbolOriginalSt(*lhsOst.GetMIRSymbol(), lhsOst.GetPuIdx(), fieldId); + if (ostOfLHSField->GetIndex() == osym2Elem.size()) { + osym2Elem.push_back(nullptr); + ssaTab.GetVersionStTable.CreateZeroVersionSt(ostOfLHSField); + } + AliasElem *aeOfLHSField = FindOrCreateAliasElem(*ostOfLHSField); + + auto *ostOfRHSField = ssaTab.FindOrCreateSymbolOriginalSt(*rhsOst.GetMIRSymbol(), rhsOst.GetPuIdx(), fieldId); + if (ostOfRHSField->GetIndex() == osym2Elem.size()) { + osym2Elem.push_back(nullptr); + ssaTab.GetVersionStTable.CreateZeroVersionSt(ostOfRHSField); + } + AliasElem *aeOfRHSField = FindOrCreateAliasElem(*ostOfRHSField); + + unionFind.Union(aeOfLHSField->id, aeOfRHSField->id); + } +} + +void AliasClass::ApplyUnionForDassignCopy(AliasElem *lhsAe, AliasElem *rhsAe, const BaseNode &rhs) { if (rhsAe == nullptr || rhsAe->GetOriginalSt().GetIndirectLev() > 0 || rhsAe->IsNotAllDefsSeen()) { - AliasElem *aliasElem = FindAliasElem(lhsAe.GetOriginalSt()); + AliasElem *aliasElem = FindAliasElem(lhsAe->GetOriginalSt()); aliasElem->SetNextLevNotAllDefsSeen(true); return; } - if (!IsPotentialAddress(rhs.GetPrimType(), &mirModule) || - kOpcodeInfo.NotPure(rhs.GetOpCode()) || + if (!IsPotentialAddress(rhs.GetPrimType(), &mirModule)) { + ApplyUnionForAggDassign(lhsAe, rhsAe); + return; + } + if (kOpcodeInfo.NotPure(rhs.GetOpCode()) || HasMallocOpnd(&rhs) || (rhs.GetOpCode() == OP_addrof && IsReadOnlyOst(rhsAe->GetOriginalSt()))) { return; } - unionFind.Union(lhsAe.GetClassID(), rhsAe->GetClassID()); + unionFind.Union(lhsAe->GetClassID(), rhsAe->GetClassID()); } void AliasClass::SetPtrOpndNextLevNADS(const BaseNode &opnd, AliasElem *aliasElem, bool hasNoPrivateDefEffect) { @@ -378,7 +418,7 @@ void AliasClass::ApplyUnionForCopies(StmtNode &stmt) { AliasElem *lhsAe = FindOrCreateAliasElem(*ost); ASSERT_NOT_NULL(lhsAe); - ApplyUnionForDassignCopy(*lhsAe, rhsAinfo.ae, *stmt.Opnd(0)); + ApplyUnionForDassignCopy(lhsAe, rhsAinfo.ae, *stmt.Opnd(0)); // at p = x, if the next level of either side exists, create other // side's next level if (mirModule.IsCModule() && rhsAinfo.ae && @@ -394,7 +434,7 @@ void AliasClass::ApplyUnionForCopies(StmtNode &stmt) { AliasElem *lhsAliasElem = FindOrCreateExtraLevAliasElem(*iassignNode.Opnd(0), iassignNode.GetTyIdx(), iassignNode.GetFieldID()); if (lhsAliasElem != nullptr) { - ApplyUnionForDassignCopy(*lhsAliasElem, rhsAinfo.ae, *iassignNode.Opnd(1)); + ApplyUnionForDassignCopy(lhsAliasElem, rhsAinfo.ae, *iassignNode.Opnd(1)); } return; } -- Gitee