diff --git a/src/mapleall/maple_me/include/alias_class.h b/src/mapleall/maple_me/include/alias_class.h index 8257766244cbb416a7f5fba4391ec229c364748a..a93314af0f1342b0ceef22165cbc7bb54ee3bff9 100644 --- a/src/mapleall/maple_me/include/alias_class.h +++ b/src/mapleall/maple_me/include/alias_class.h @@ -220,6 +220,7 @@ class AliasClass : public AnalysisResult { void UpdateNextLevelNodes(std::vector &nextLevelOsts, const AliasElem &aliasElem); void UnionNodes(std::vector &nextLevelOsts); int GetOffset(const Klass &super, const Klass &base) const; + void UnionAllNodes(MapleVector *nextLevOsts); MemPool &acMemPool; MapleAllocator acAlloc; diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index 5f381bb1846ec1f4c59426172e7928be4d51ec54..93c286a34d8bf68cca21be439d5b6e6f3ba46b06 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -38,29 +38,29 @@ inline bool IsPotentialAddress(PrimType primType, MIRModule *mirModule) { // return true if this expression opcode can result in a valid address static bool OpCanFormAddress(Opcode op) { switch (op) { - case OP_dread: - case OP_regread: - case OP_iread: - case OP_ireadoff: - case OP_ireadfpoff: - case OP_ireadpcoff: - case OP_addrof: - case OP_addroffunc: - case OP_addroflabel: - case OP_addroffpc: - case OP_iaddrof: - case OP_constval: - case OP_conststr: - case OP_conststr16: - case OP_alloca: - case OP_malloc: - case OP_add: - case OP_sub: - case OP_select: - case OP_array: - case OP_intrinsicop: - return true; - default: ; + case OP_dread: + case OP_regread: + case OP_iread: + case OP_ireadoff: + case OP_ireadfpoff: + case OP_ireadpcoff: + case OP_addrof: + case OP_addroffunc: + case OP_addroflabel: + case OP_addroffpc: + case OP_iaddrof: + case OP_constval: + case OP_conststr: + case OP_conststr16: + case OP_alloca: + case OP_malloc: + case OP_add: + case OP_sub: + case OP_select: + case OP_array: + case OP_intrinsicop: + return true; + default: ; } return false; } @@ -147,7 +147,6 @@ AliasElem *AliasClass::FindOrCreateAliasElem(OriginalSt &ost) { } if (ost.GetIndirectLev() > 1) { aliasElem->SetNotAllDefsSeen(true); - aliasElem->SetNextLevNotAllDefsSeen(true); } id2Elem.push_back(aliasElem); osym2Elem[ostIdx] = aliasElem; @@ -600,28 +599,51 @@ AliasElem *AliasClass::FindOrCreateDummyNADSAe() { return osym2Elem[dummyOst->GetIndex()]; } +void AliasClass::UnionAllNodes(MapleVector *nextLevOsts) { + if (nextLevOsts->size() < 2) { + return; + } + + auto it = nextLevOsts->begin(); + OriginalSt *ostA = *it; + AliasElem *aeA = FindAliasElem(*ostA); + ++it; + for (; it != nextLevOsts->end(); ++it) { + OriginalSt *ostB = *it; + AliasElem *aeB = FindAliasElem(*ostB); + unionFind.Union(aeA->GetClassID(), aeB->GetClassID()); + } +} + // This is applicable only for C language. For each ost that is a struct, // union all fields within the same struct void AliasClass::ApplyUnionForStorageOverlaps() { // iterate through all the alias elems for (AliasElem *ae : id2Elem) { OriginalSt *ost = &ae->GetOriginalSt(); - OriginalSt *prevLevOst = GetAliasAnalysisTable()->GetPrevLevelNode(*ost); - if (prevLevOst == nullptr) { + MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ost->GetTyIdx()); + if (mirType->GetKind() != kTypePointer) { continue; } - MIRType *prevLevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(prevLevOst->GetTyIdx()); - if (prevLevType->GetKind() != kTypePointer) { + auto nextLevOsts = GetAliasAnalysisTable()->GetNextLevelNodes(*ost); + if (nextLevOsts == nullptr) { continue; } - MIRType *prevLevPointedType = static_cast(prevLevType)->GetPointedType(); - MIRType *ostType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ost->GetTyIdx()); - if (!ostType->HasFields() && prevLevPointedType->GetKind() != kTypeUnion) { + + MIRType *pointedType = static_cast(mirType)->GetPointedType(); + if (pointedType->GetKind() == kTypeUnion) { + // union all fields of union + UnionAllNodes(nextLevOsts); continue; } - for (OriginalSt *sameLevOst : *GetAliasAnalysisTable()->GetNextLevelNodes(*prevLevOst)) { - AliasElem *ae1 = FindAliasElem(*sameLevOst); - unionFind.Union(ae->GetClassID(), ae1->GetClassID()); + + for (auto *nextLevOst : *nextLevOsts) { + MIRType *nextLevType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(nextLevOst->GetTyIdx()); + if (nextLevType->HasFields()) { + // union all fields if one next-level-ost has fields + UnionAllNodes(nextLevOsts); + break; + } } } } @@ -1331,8 +1353,6 @@ void AliasClass::InsertMayDefUseIntrncall(StmtNode &stmt, BBId bbid) { for (int32 i = 0; i < stmt.NumOpnds(); i++) { InsertMayUseExpr(*stmt.Opnd(i)); } - } else { - CollectMayUseFromNADS(mayDefUseOsts); } // 2. collect mayDefs and mayUses caused by not_all_defs_seen_ae CollectMayUseFromNADS(mayDefUseOsts);