diff --git a/build/toolchain/BUILD.gn b/build/toolchain/BUILD.gn index 6c03bcc57e09aa45b3e7d4f484a66f972d31d8e1..51ca552715917c391906ba48aad3bb6130dd252b 100644 --- a/build/toolchain/BUILD.gn +++ b/build/toolchain/BUILD.gn @@ -72,7 +72,11 @@ toolchain("clang") { outfile = "${GN_BINARY_OUTPUT_DIRECTORY}/{{target_output_name}}{{output_extension}}" rspfile = "$outfile.rsp" rspfile_content = "{{inputs}}" - command = "${GN_CXX_COMPILER} -fuse-ld=lld {{ldflags}} -o $outfile -Wl,--start-group ${rspfile_content} {{libs}} -Wl,--end-group {{solibs}}" + if (GN_BUILD_TYPE == "RELEASE") { + command = "${GN_CXX_COMPILER} -s -fuse-ld=lld {{ldflags}} -o $outfile -Wl,--start-group ${rspfile_content} {{libs}} -Wl,--end-group {{solibs}}" + } else { + command = "${GN_CXX_COMPILER} -fuse-ld=lld {{ldflags}} -o $outfile -Wl,--start-group ${rspfile_content} {{libs}} -Wl,--end-group {{solibs}}" + } description = "LINK $outfile" rspfile_content = "{{inputs}}" outputs = [ diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 1c6a732a9172dc5d5af693cc7c3fe1f258aa4a4b..70fdfdc8872767e33ff933163b87fe2b4191dbee 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index 0be32734f30a97ef9cf564193d8d915b11f6effc..2dc97b7628817e874a17746d4fae65bec18db582 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 91972c3b37a61b641ce16d822432ad1cf1069545..3fc9d67f5773208fe21a545d469fc67aaa2d11eb 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/maple_ir/include/bin_mplt.h b/src/maple_ir/include/bin_mplt.h index 9fc9ccc0e55990035c1d11a40e44bbee2ad71986..a5ef263c203345882629de037ff1de8cabe50a6a 100644 --- a/src/maple_ir/include/bin_mplt.h +++ b/src/maple_ir/include/bin_mplt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/include/mir_symbol.h b/src/maple_ir/include/mir_symbol.h index 7bf7c4ee89b7886090a19224c207cc2c6c1b3e03..396497f050e81e2f6da212534b6026542aa67437 100644 --- a/src/maple_ir/include/mir_symbol.h +++ b/src/maple_ir/include/mir_symbol.h @@ -17,6 +17,7 @@ #include #include "mir_const.h" #include "mir_preg.h" +#include "global_tables.h" constexpr int kScopeLocal = 2; // the default scope level for function variables constexpr int kScopeGlobal = 1; // the scope level for global variables @@ -224,7 +225,9 @@ class MIRSymbol { MIRType *GetType() const; - const std::string &GetName() const; + const std::string &GetName() const { + return GlobalTables::GetStrTable().GetStringFromStrIdx(nameStrIdx); + } MIRConst *GetKonst() const { ASSERT((sKind == kStConst || sKind == kStVar), "must be const symbol"); diff --git a/src/maple_ir/src/lexer.cpp b/src/maple_ir/src/lexer.cpp index 7f6745a0f4bf23a572f3d556af0266c08e7c74ff..0a6daf77b316e9517f495c3ea42c38e73358fd9d 100644 --- a/src/maple_ir/src/lexer.cpp +++ b/src/maple_ir/src/lexer.cpp @@ -98,16 +98,14 @@ void MIRLexer::PrepareForString(const std::string &src) { void MIRLexer::GenName() { uint32 startIdx = curIdx; - char c = GetCharAtWithUpperCheck(curIdx); - if (isalnum(c) || c < 0 || c == '_' || c == '$' || c == '@') { - c = GetNextCurrentCharWithUpperCheck(); - } - char cp = GetCharAtWithLowerCheck(curIdx - 1); + char c = GetNextCurrentCharWithUpperCheck(); + char cp = GetCharAt(curIdx - 1); if (c == '@' && (cp == 'h' || cp == 'f')) { // special pattern for exception handling labels: catch or finally c = GetNextCurrentCharWithUpperCheck(); } - while (isalnum(c) || c < 0 || c == '_' || c == '$' || c == ';' || c == '/' || c == '|' || c == '.' || c == '?' || + while (utils::IsAlnum(c) || c < 0 || c == '_' || c == '$' || c == ';' || + c == '/' || c == '|' || c == '.' || c == '?' || c == '@') { c = GetNextCurrentCharWithUpperCheck(); } @@ -150,22 +148,26 @@ TokenKind MIRLexer::GetConstVal(){ TokenKind MIRLexer::GetSpecialFloatConst() { constexpr uint32 lenSpecFloat = 4; constexpr uint32 lenSpecDouble = 3; - if (line.compare(curIdx, lenSpecFloat, "inff") == 0 && !isalnum(GetCharAtWithUpperCheck(curIdx + lenSpecFloat))) { + if (line.compare(curIdx, lenSpecFloat, "inff") == 0 && + !utils::IsAlnum(GetCharAtWithUpperCheck(curIdx + lenSpecFloat))) { curIdx += lenSpecFloat; theFloatVal = -INFINITY; return TK_floatconst; } - if (line.compare(curIdx, lenSpecDouble, "inf") == 0 && !isalnum(GetCharAtWithUpperCheck(curIdx + lenSpecDouble))) { + if (line.compare(curIdx, lenSpecDouble, "inf") == 0 && + !utils::IsAlnum(GetCharAtWithUpperCheck(curIdx + lenSpecDouble))) { curIdx += lenSpecDouble; theDoubleVal = -INFINITY; return TK_doubleconst; } - if (line.compare(curIdx, lenSpecFloat, "nanf") == 0 && !isalnum(GetCharAtWithUpperCheck(curIdx + lenSpecFloat))) { + if (line.compare(curIdx, lenSpecFloat, "nanf") == 0 && + !utils::IsAlnum(GetCharAtWithUpperCheck(curIdx + lenSpecFloat))) { curIdx += lenSpecFloat; theFloatVal = -NAN; return TK_floatconst; } - if (line.compare(curIdx, lenSpecDouble, "nan") == 0 && !isalnum(GetCharAtWithUpperCheck(curIdx + lenSpecDouble))) { + if (line.compare(curIdx, lenSpecDouble, "nan") == 0 && + !utils::IsAlnum(GetCharAtWithUpperCheck(curIdx + lenSpecDouble))) { curIdx += lenSpecDouble; theDoubleVal = -NAN; return TK_doubleconst; @@ -306,7 +308,7 @@ TokenKind MIRLexer::GetFloatConst(uint32 valStart, uint32 startIdx, bool negativ TokenKind MIRLexer::GetTokenWithPrefixDollar() { // token with prefix '$' char c = GetCharAtWithUpperCheck(curIdx); - if (isalpha(c) || c == '_' || c == '$') { + if (utils::IsAlpha(c) || c == '_' || c == '$') { GenName(); return TK_gname; } else { @@ -331,11 +333,11 @@ TokenKind MIRLexer::GetTokenWithPrefixPercent() { name = line.substr(valStart, curIdx - valStart); return TK_preg; } - if (isalpha(c) || c == '_' || c == '$') { + if (utils::IsAlpha(c) || c == '_' || c == '$') { GenName(); return TK_lname; } - if (c == '%' && isalpha(GetCharAtWithUpperCheck(curIdx + 1))) { + if (c == '%' && utils::IsAlpha(GetCharAtWithUpperCheck(curIdx + 1))) { ++curIdx; GenName(); return TK_specialreg; @@ -346,7 +348,7 @@ TokenKind MIRLexer::GetTokenWithPrefixPercent() { TokenKind MIRLexer::GetTokenWithPrefixAmpersand() { // token with prefix '&' char c = GetCurrentCharWithUpperCheck(); - if (isalpha(c) || c == '_') { + if (utils::IsAlpha(c) || c == '_') { GenName(); return TK_fname; } @@ -359,7 +361,7 @@ TokenKind MIRLexer::GetTokenWithPrefixAmpersand() { TokenKind MIRLexer::GetTokenWithPrefixAtOrCircumflex(char prefix) { // token with prefix '@' or `^` char c = GetCurrentCharWithUpperCheck(); - if (isalnum(c) || c < 0 || c == '_' || c == '@' || c == '$' || c == '|') { + if (utils::IsAlnum(c) || c < 0 || c == '_' || c == '@' || c == '$' || c == '|') { GenName(); if (prefix == '@') { return TK_label; @@ -372,7 +374,7 @@ TokenKind MIRLexer::GetTokenWithPrefixAtOrCircumflex(char prefix) { TokenKind MIRLexer::GetTokenWithPrefixExclamation() { // token with prefix '!' char c = GetCurrentCharWithUpperCheck(); - if (isalpha(c)) { + if (utils::IsAlpha(c)) { GenName(); return TK_typeparam; } @@ -491,7 +493,7 @@ TokenKind MIRLexer::GetTokenWithPrefixDoubleQuotation() { TokenKind MIRLexer::GetTokenSpecial() { --curIdx; char c = GetCharAtWithLowerCheck(curIdx); - if (isalpha(c) || c < 0 || c == '_') { + if (utils::IsAlpha(c) || c < 0 || c == '_') { GenName(); TokenKind tk = keywordMap[name]; switch (tk) { diff --git a/src/maple_ir/src/mir_symbol.cpp b/src/maple_ir/src/mir_symbol.cpp index 25eb7c1167d5a72d4e5db80b43eaf878edf8d755..8bd6eb9b68bc914649e206d038aa8c49c6b60105 100644 --- a/src/maple_ir/src/mir_symbol.cpp +++ b/src/maple_ir/src/mir_symbol.cpp @@ -58,10 +58,6 @@ MIRType *MIRSymbol::GetType() const { return GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); } -const std::string &MIRSymbol::GetName() const { - return GlobalTables::GetStrTable().GetStringFromStrIdx(nameStrIdx); -} - bool MIRSymbol::PointsToConstString() const { MIRType *origType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); if (origType->GetKind() == kTypePointer) { diff --git a/src/maple_me/include/dse.h b/src/maple_me/include/dse.h index 42d9300b3e2a89d903c3a7842d61b9b618846eaa..6ea25d2928bbb872a53bb55d48a728166583ff43 100644 --- a/src/maple_me/include/dse.h +++ b/src/maple_me/include/dse.h @@ -26,7 +26,7 @@ namespace maple { class DSE { public: - DSE(MIRModule&, std::vector &&bbVec, BB &commonEntryBB, BB &commonExitBB, SSATab &ssaTab, + DSE(std::vector &&bbVec, BB &commonEntryBB, BB &commonExitBB, SSATab &ssaTab, Dominance &postDom, bool enableDebug = false) : enableDebug(enableDebug), bbVec(bbVec), commonEntryBB(commonEntryBB), diff --git a/src/maple_me/include/me_dse.h b/src/maple_me/include/me_dse.h index 658561821937e6c172086c2cadedab231f2d3d83..6efd7ed45d30cb3ac09e29aa8ddebd94a5a02102 100644 --- a/src/maple_me/include/me_dse.h +++ b/src/maple_me/include/me_dse.h @@ -27,7 +27,7 @@ namespace maple { class MeDSE : public DSE { public: MeDSE(MeFunction *f, Dominance *dom, bool enabledDebug) - : DSE(f->GetMIRModule(), std::vector(f->GetAllBBs().begin(), f->GetAllBBs().end()), + : DSE(std::vector(f->GetAllBBs().begin(), f->GetAllBBs().end()), *f->GetCommonEntryBB(), *f->GetCommonExitBB(), *f->GetMeSSATab(), *dom, enabledDebug), func(*f) {} diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h index 6c7dd746cca82f8cd417d02930a0f045f97fdf5e..ca36e92de09711938f7042bcf0e7d7773d00cd3c 100644 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -1228,6 +1228,10 @@ class MeStmt { return nullptr; } + virtual VarMeExpr *GetVarLHS() { + return nullptr; + } + virtual RegMeExpr *GetRegLHS() { return nullptr; } @@ -1614,6 +1618,10 @@ class DassignMeStmt : public MeStmt { return lhs; } + VarMeExpr *GetVarLHS() { + return lhs; + } + MeExpr *GetLHSRef(SSATab &ssaTab, bool excludeLocalRefVar); void UpdateLHS(VarMeExpr &var) { lhs = &var; @@ -1784,6 +1792,10 @@ class MaydassignMeStmt : public MeStmt { return chiList.begin()->second->GetLHS(); } + VarMeExpr *GetVarLHS() { + return chiList.begin()->second->GetLHS(); + } + MeExpr *GetLHSRef(SSATab &ssaTab, bool excludeLocalRefVar); StmtNode &EmitStmt(SSATab &ssaTab); @@ -2061,6 +2073,13 @@ class CallMeStmt : public NaryMeStmt, public MuChiMePart, public AssignedPart { return GetAssignedPartLHSRef(ssaTab, excludeLocalRefVar); } + VarMeExpr *GetVarLHS() { + if (mustDefList.empty() || mustDefList.front().GetLHS()->GetMeOp() != kMeOpVar) { + return nullptr; + } + return static_cast(mustDefList.front().GetLHS()); + } + bool NeedDecref() const { return needDecref; } diff --git a/src/maple_me/include/me_ssa_epre.h b/src/maple_me/include/me_ssa_epre.h index 1c4e8490cbccc1dfaae1d4f7f2cba9d4e869c3db..ed40ad3974514c91d61ff89640b514f498577e81 100644 --- a/src/maple_me/include/me_ssa_epre.h +++ b/src/maple_me/include/me_ssa_epre.h @@ -19,18 +19,20 @@ #include "me_irmap.h" #include "me_cfg.h" #include "ssa_epre.h" +#include "class_hierarchy.h" namespace maple { class MeSSAEPre : public SSAEPre { public: // a symbol is a candidate for ssaupdate if its ostidx key exists in the map; // the mapped set gives bbs where dassign's are inserted by ssa_epre for the symbol - explicit MeSSAEPre(MeFunction *func, IRMap &map, Dominance &dom, MemPool &memPool, MemPool &mp2, uint32 limit, - bool includeRef, bool epreLocalRefVar, bool lhsIvar) + explicit MeSSAEPre(MeFunction *func, IRMap &map, Dominance &dom, KlassHierarchy &kh, MemPool &memPool, MemPool &mp2, + uint32 limit, bool includeRef, bool epreLocalRefVar, bool lhsIvar) : SSAEPre(map, dom, memPool, mp2, kExprPre, limit, includeRef, lhsIvar), candsForSSAUpdate(std::less(), ssaPreAllocator.Adapter()), func(func), - epreLocalRefVar(epreLocalRefVar) {} + epreLocalRefVar(epreLocalRefVar), + klassHierarchy(kh) {} virtual ~MeSSAEPre() = default; void GetIterDomFrontier(BB &bb, MapleSet &dfSet, std::vector &visitedMap) override; @@ -46,9 +48,11 @@ class MeSSAEPre : public SSAEPre { MapleMap*> candsForSSAUpdate; MeFunction *func; bool epreLocalRefVar; + KlassHierarchy &klassHierarchy; private: void BuildWorkList() override; + bool IsThreadObjField(const IvarMeExpr &expr) override; BB *GetBB(BBId id) override { return func->GetBBFromID(id); } diff --git a/src/maple_me/include/me_ssu_pre.h b/src/maple_me/include/me_ssu_pre.h index 80d1480a12c2ed0ff6b2a318143b146f566cf5ab..0de4d9c229963fc91e01ecada19830955a051c9d 100644 --- a/src/maple_me/include/me_ssu_pre.h +++ b/src/maple_me/include/me_ssu_pre.h @@ -31,6 +31,8 @@ class SOcc { public: SOcc(SOccType ty, BB *bb) : occTy(ty), classId(0), mirBB(bb), use(nullptr) {} + virtual ~SOcc() = default; + virtual void Dump() = 0; bool IsPostDominate(Dominance *dom, SOcc *occ) { CHECK_NULL_FATAL(occ); @@ -42,16 +44,16 @@ class SOcc { return occTy; } - void SetOccTy(SOccType occTy) { - this->occTy = occTy; + void SetOccTy(SOccType type) { + this->occTy = type; } uint32 GetClassId() { return classId; } - void SetClassId(uint32 classId) { - this->classId = classId; + void SetClassId(uint32 id) { + this->classId = id; } BB *GetBB() { @@ -62,16 +64,16 @@ class SOcc { return mirBB; } - void SetBB(BB *mirBB) { - this->mirBB = mirBB; + void SetBB(BB *currMirBB) { + this->mirBB = currMirBB; } SOcc *GetUse() { return use; } - void SetUse(SOcc *use) { - this->use = use; + void SetUse(SOcc *currUse) { + this->use = currUse; } private: SOccType occTy; @@ -110,16 +112,16 @@ class SRealOcc : public SOcc { return realFromDef; } - void SetRealFromDef(bool realFromDef) { - this->realFromDef = realFromDef; + void SetRealFromDef(bool real) { + this->realFromDef = real; } bool GetRedundant() { return redundant; } - void SetRedundant(bool redundant) { - this->redundant = redundant; + void SetRedundant(bool isRedundant) { + this->redundant = isRedundant; } private: MeStmt *meStmt; // the stmt of this real occurrence; null for formal at entry @@ -141,24 +143,24 @@ class SLambdaResOcc : public SOcc { return useLambdaOcc; } - void SetUseLambdaOcc(SLambdaOcc *useLambdaOcc) { - this->useLambdaOcc = useLambdaOcc; + void SetUseLambdaOcc(SLambdaOcc *currUseLambdaOcc) { + this->useLambdaOcc = currUseLambdaOcc; } bool GetHasRealUse() { return hasRealUse; } - void SetHasRealUse(bool hasRealUse) { - this->hasRealUse = hasRealUse; + void SetHasRealUse(bool has) { + this->hasRealUse = has; } bool GetInsertHere() { return insertHere; } - void SetInsertHere(bool insertHere) { - this->insertHere = insertHere; + void SetInsertHere(bool currInsertHere) { + this->insertHere = currInsertHere; } private: SLambdaOcc *useLambdaOcc; // its rhs use @@ -190,24 +192,24 @@ class SLambdaOcc : public SOcc { return isUpsafe; } - void SetIsUpsafe(bool isUpsafe) { - this->isUpsafe = isUpsafe; + void SetIsUpsafe(bool upsafe) { + this->isUpsafe = upsafe; } bool GetIsCanBeAnt() { return isCanBeAnt; } - void SetIsCanBeAnt(bool isCanBeAnt) { - this->isCanBeAnt = isCanBeAnt; + void SetIsCanBeAnt(bool canBeAnt) { + this->isCanBeAnt = canBeAnt; } bool GetIsEarlier() { return isEarlier; } - void SetIsEarlier(bool isEarlier) { - this->isEarlier = isEarlier; + void SetIsEarlier(bool earlier) { + this->isEarlier = earlier; } MapleVector &GetLambdaRes() { @@ -290,8 +292,8 @@ class SpreWorkCand { return theVar; } - void SetTheVar(VarMeExpr *theVar) { - this->theVar = theVar; + void SetTheVar(VarMeExpr *var) { + this->theVar = var; } MapleVector &GetRealOccs() { @@ -302,16 +304,16 @@ class SpreWorkCand { return hasStoreOcc; } - void SetHasStoreOcc(bool hasStoreOcc) { - this->hasStoreOcc = hasStoreOcc; + void SetHasStoreOcc(bool has) { + this->hasStoreOcc = has; } bool GetHasCriticalEdge() { return hasCriticalEdge; } - void SetHasCriticalEdge(bool hasCriticalEdge) { - this->hasCriticalEdge = hasCriticalEdge; + void SetHasCriticalEdge(bool criticalEdge) { + this->hasCriticalEdge = criticalEdge; } private: @@ -349,6 +351,8 @@ class MeSSUPre { catchBlocks2Insert(spreAllocator.Adapter()), enabledDebug(enabledDebug) {} + virtual ~MeSSUPre() = default; + void ApplySSUPre(); protected: diff --git a/src/maple_me/include/ssa_epre.h b/src/maple_me/include/ssa_epre.h index 4cdbff5c638b954b3f27ef7cf157da6745169aba..d128b460e2c740d0ebee84102656284b039c10b6 100644 --- a/src/maple_me/include/ssa_epre.h +++ b/src/maple_me/include/ssa_epre.h @@ -40,6 +40,9 @@ class SSAEPre : public SSAPre { VarMeExpr *v = safe_cast(x); return v != nullptr && v->IsVolatile(irMap->GetSSATab()); } + virtual bool IsThreadObjField(const IvarMeExpr &expr) { + return false; + } virtual bool CfgHasDoWhile() { return false; diff --git a/src/maple_me/include/ssa_pre.h b/src/maple_me/include/ssa_pre.h index 49615b49746f8dc348fc1ed6ead6ae434b746ed5..878053f51d539c68fd18b4ccfd4176e0793487a8 100644 --- a/src/maple_me/include/ssa_pre.h +++ b/src/maple_me/include/ssa_pre.h @@ -49,6 +49,8 @@ class SSAPre { PreWorkCand::GetWorkcandHashTable().fill(nullptr); } + virtual ~SSAPre() = default; + void ApplySSAPRE(); bool DefVarDominateOcc(MeExpr *meExpr, MeOccur *meOcc); virtual void CollectVarForMeExpr(MeExpr *meExpr, std::vector &varVec) = 0; diff --git a/src/maple_me/src/dse.cpp b/src/maple_me/src/dse.cpp index 5a0fbfd54dde917941925d7521f9baac4c84e882..342694e35819a19388b201b28aab2b835c72a1db 100644 --- a/src/maple_me/src/dse.cpp +++ b/src/maple_me/src/dse.cpp @@ -147,7 +147,8 @@ void DSE::CheckRemoveCallAssignedReturn(StmtNode &stmt) { } void DSE::OnRemoveBranchStmt(BB &bb, const StmtNode &stmt) { - if (IsBranch(stmt.GetOpCode())) { + // switch is special, which can not be set to kBBFallthru + if (IsBranch(stmt.GetOpCode()) && stmt.GetOpCode() != OP_switch) { // update BB pred/succ bb.SetKind(kBBFallthru); cfgUpdated = true; // tag cfg is changed diff --git a/src/maple_me/src/hdse.cpp b/src/maple_me/src/hdse.cpp index 7a541be3185550dfaa1a5224d8de35d3d1ac797a..fa1a9e197b88ba326ba74ecea4d0abb7a6e3164e 100644 --- a/src/maple_me/src/hdse.cpp +++ b/src/maple_me/src/hdse.cpp @@ -199,6 +199,7 @@ bool HDSE::ExprNonDeletable(MeExpr &meExpr) { if (meExpr.GetOp() == OP_gcmallocjarray) { return true; } + break; } case kMeOpNary: { auto &opNary = static_cast(meExpr); @@ -206,6 +207,7 @@ bool HDSE::ExprNonDeletable(MeExpr &meExpr) { IntrinDesc *intrinDesc = &IntrinDesc::intrinTable[opNary.GetIntrinsic()]; return (!intrinDesc->HasNoSideEffect()); } + break; } default: break; diff --git a/src/maple_me/src/me_loop_canon.cpp b/src/maple_me/src/me_loop_canon.cpp index c80db1fda4a313a9095b9afe961b2697c2348872..edfece37439c3c613ceafd10152a1bfd4c7262f4 100644 --- a/src/maple_me/src/me_loop_canon.cpp +++ b/src/maple_me/src/me_loop_canon.cpp @@ -214,7 +214,6 @@ AnalysisResult *MeDoLoopCanon::Run(MeFunction *func, MeFuncResultMgr *m, ModuleR } MapleAllocator localAlloc(NewMemPool()); MapleVector> backEdges(localAlloc.Adapter()); - using Key = std::pair; MapleMap swapSuccs(std::less(), localAlloc.Adapter()); // collect backedge first: if bb dominator its pred, then the edge pred->bb is a backedge eIt = func->valid_end(); diff --git a/src/maple_me/src/me_ssa_epre.cpp b/src/maple_me/src/me_ssa_epre.cpp index 951b63b8b5cdff4ba8a10ea4d82beafe41751bfa..4ac77fce0b5a4aa35f99f46170112075e63f4687 100644 --- a/src/maple_me/src/me_ssa_epre.cpp +++ b/src/maple_me/src/me_ssa_epre.cpp @@ -41,7 +41,25 @@ void MeSSAEPre::BuildWorkList() { } } -AnalysisResult *MeDoSSAEPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr*) { +bool MeSSAEPre::IsThreadObjField(const IvarMeExpr &expr) { + if (expr.GetFieldID() == 0) { + return false; + } + auto *type = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(expr.GetTyIdx())); + TyIdx runnableInterface = klassHierarchy.GetKlassFromLiteral("Ljava_2Flang_2FRunnable_3B")->GetTypeIdx(); + Klass *klass = klassHierarchy.GetKlassFromTyIdx(type->GetPointedTyIdx()); + if (klass == nullptr) { + return false; + } + for (Klass *inter : klass->GetImplInterfaces()) { + if (inter->GetTypeIdx() == runnableInterface) { + return true; + } + } + return false; +} + +AnalysisResult *MeDoSSAEPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleResultMgr *mrm) { static uint32 puCount = 0; // count PU to support the eprePULimit option if (puCount > MeOption::eprePULimit) { ++puCount; @@ -51,12 +69,14 @@ AnalysisResult *MeDoSSAEPre::Run(MeFunction *func, MeFuncResultMgr *m, ModuleRes ASSERT(dom != nullptr, "dominance phase has problem"); auto *irMap = static_cast(m->GetAnalysisResult(MeFuncPhase_IRMAP, func)); ASSERT(irMap != nullptr, "irMap phase has problem"); + KlassHierarchy *kh = static_cast(mrm->GetAnalysisResult(MoPhase_CHA, &func->GetMIRModule())); + CHECK_FATAL(kh != nullptr, "KlassHierarchy phase has problem"); bool eprePULimitSpecified = MeOption::eprePULimit != UINT32_MAX; uint32 epreLimitUsed = (eprePULimitSpecified && puCount != MeOption::eprePULimit) ? UINT32_MAX : MeOption::epreLimit; MemPool *ssaPreMemPool = NewMemPool(); bool epreIncludeRef = MeOption::epreIncludeRef; - MeSSAEPre ssaPre(func, *irMap, *dom, *ssaPreMemPool, *NewMemPool(), epreLimitUsed, epreIncludeRef, + MeSSAEPre ssaPre(func, *irMap, *dom, *kh, *ssaPreMemPool, *NewMemPool(), epreLimitUsed, epreIncludeRef, MeOption::epreLocalRefVar, MeOption::epreLHSIvar); ssaPre.SetSpillAtCatch(MeOption::spillAtCatch); if (eprePULimitSpecified && puCount == MeOption::eprePULimit && epreLimitUsed != UINT32_MAX) { diff --git a/src/maple_me/src/me_stmt_fre.cpp b/src/maple_me/src/me_stmt_fre.cpp index 57e22c76c10d2f0a33118087e3d44bec16ef24bf..84bfdaf8495b4e8ac04813041703d11169b84051 100644 --- a/src/maple_me/src/me_stmt_fre.cpp +++ b/src/maple_me/src/me_stmt_fre.cpp @@ -50,13 +50,17 @@ void MeStmtPre::ComputeFullyAvail() { } bool MeStmtPre::AllVarsSameVersionStmtFre(MeRealOcc *topOcc, MeRealOcc *curOcc) const { - ASSERT(topOcc->GetOpcodeOfMeStmt() == OP_dassign, "AllVarsSameVersionStmtFre: only dassign is handled"); - auto *dass1 = static_cast(topOcc->GetMeStmt()); - auto *dass2 = static_cast(curOcc->GetMeStmt()); - if (dass1->GetRHS() != dass2->GetRHS()) { + ASSERT(topOcc->GetOpcodeOfMeStmt() == OP_dassign || topOcc->GetOpcodeOfMeStmt() == OP_callassigned, + "AllVarsSameVersionStmtFre: only dassign or callassigned is handled"); + if (topOcc->GetMeStmt()->NumMeStmtOpnds() != curOcc->GetMeStmt()->NumMeStmtOpnds()) { return false; } - return dass1->GetLHS() == curOcc->GetMeExpr(); + for (size_t i = 0; i < topOcc->GetMeStmt()->NumMeStmtOpnds(); ++i) { + if (topOcc->GetMeStmt()->GetOpnd(i) != curOcc->GetMeStmt()->GetOpnd(i)) { + return false; + } + } + return topOcc->GetMeStmt()->GetVarLHS() == curOcc->GetMeExpr(); } void MeStmtPre::Rename1StmtFre() { diff --git a/src/maple_me/src/me_stmt_pre.cpp b/src/maple_me/src/me_stmt_pre.cpp index 0b86840670ebc9197686387f2b89b0f86c3d62dc..fd9207fd2829c62a6f341dc3da37701f9e8928e1 100644 --- a/src/maple_me/src/me_stmt_pre.cpp +++ b/src/maple_me/src/me_stmt_pre.cpp @@ -17,12 +17,14 @@ #include "me_dominance.h" #include "me_option.h" #include "me_ssa_update.h" + // Note: after the movement of assignments, some phi nodes that used to be dead // can become live. Before we run another round of dead store elimination, we // should NOT trust the isLive flag in phi nodes. // accumulate the BBs that are in the iterated dominance frontiers of bb in // the set dfset, visiting each BB only once namespace maple { + void MeStmtPre::GetIterDomFrontier(BB &bb, MapleSet &dfSet, std::vector &visitedMap) { CHECK_FATAL(bb.GetBBId() < visitedMap.size(), "index out of range in MeStmtPre::GetIterDomFrontier"); if (visitedMap[bb.GetBBId()]) { @@ -240,7 +242,7 @@ bool MeStmtPre::AllVarsSameVersion(MeRealOcc *realOcc1, MeRealOcc *realOcc2) { if (op == OP_intrinsiccallwithtype) { return true; } - if (op == OP_dassign && realOcc1->GetMeExpr() != realOcc2->GetMeExpr()) { + if ((op == OP_dassign || op == OP_callassigned) && realOcc1->GetMeExpr() != realOcc2->GetMeExpr()) { return false; } MeStmt *stmt2 = realOcc2->GetMeStmt(); @@ -268,7 +270,7 @@ void MeStmtPre::CollectVarForMeStmt(MeStmt *meStmt, MeExpr *meExpr, std::vector< if (dassMeStmt->GetRHS()->GetMeOp() == kMeOpVar || dassMeStmt->GetRHS()->GetMeOp() == kMeOpReg) { varVec.push_back(dassMeStmt->GetRHS()); } - if (meExpr) { + if (meExpr != nullptr) { CHECK_FATAL(meExpr->GetMeOp() == kMeOpVar, "CollectVarForMeStmt:bad meExpr field in realocc node"); varVec.push_back(meExpr); } @@ -282,6 +284,10 @@ void MeStmtPre::CollectVarForMeStmt(MeStmt *meStmt, MeExpr *meExpr, std::vector< if (nStmt->GetOpnds()[i]->GetMeOp() == kMeOpVar || nStmt->GetOpnds()[i]->GetMeOp() == kMeOpReg) { varVec.push_back(nStmt->GetOpnds()[i]); } + if (meExpr != nullptr) { + CHECK_FATAL(meExpr->GetMeOp() == kMeOpVar, "CollectVarForMeStmt:bad meExpr field in realocc node"); + varVec.push_back(meExpr); + } break; } default: @@ -346,10 +352,6 @@ MeStmt *MeStmtPre::PhiOpndFromRes4Stmt(MeRealOcc *realZ, size_t j, MeExpr *&lhsV if (retOpnd != nullptr) { dassQ->SetRHS(retOpnd); } - retOpnd = GetReplaceMeExpr(realZ->GetMeExpr(), ephiBB, j); - if (retOpnd != nullptr) { - lhsVar = retOpnd; - } break; } case OP_intrinsiccall: @@ -367,6 +369,12 @@ MeStmt *MeStmtPre::PhiOpndFromRes4Stmt(MeRealOcc *realZ, size_t j, MeExpr *&lhsV default: ASSERT(false, "MeStmtPre::PhiOpndFromRes4Stmt: NYI"); } + if (stmtQ->GetOp() == OP_dassign || stmtQ->GetOp() == OP_callassigned) { + MeExpr *retOpnd = GetReplaceMeExpr(realZ->GetMeExpr(), ephiBB, j); + if (retOpnd != nullptr) { + lhsVar = retOpnd; + } + } return stmtQ; } @@ -403,7 +411,7 @@ void MeStmtPre::Rename2() { bool hasSameVersion = true; size_t checkLimit = varVecY.size(); if (varY != nullptr) { - if (varVecY[checkLimit - 1] == static_cast(stmtY)->GetLHS()) { + if (varVecY[checkLimit - 1] == realDefX->GetMeStmt()->GetVarLHS()) { --checkLimit; } } @@ -422,7 +430,7 @@ void MeStmtPre::Rename2() { CollectVarForMeStmt(stmtY, varY, varVecY); size_t checkLimit = varVecY.size(); if (varY != nullptr) { - if (varVecY[checkLimit - 1] == static_cast(stmtY)->GetLHS()) { + if (varVecY[checkLimit - 1] == stmtY->GetVarLHS()) { --checkLimit; } } @@ -499,6 +507,9 @@ void MeStmtPre::ComputeVarAndDfPhis() { for (size_t i = 0; i < nStmt->NumMeStmtOpnds(); ++i) { SetVarPhis(nStmt->GetOpnds()[i]); } + if (realOcc->GetMeExpr() != nullptr) { + SetVarPhis(realOcc->GetMeExpr()); + } break; } default: @@ -515,12 +526,13 @@ void MeStmtPre::ComputeVarAndDfPhis() { // When a real_occ has uses before it in its bb, ignore (do not insert) // the real_occ. void MeStmtPre::CreateSortedOccs() { - // get set of bb dfns that contain uses if candidate is dassign + // get set of bb dfns that contain uses if candidate is dassign or callassigned MapleSet *useDfns; PreWorkCand *workCand = GetWorkCand(); auto *stmtWkCand = static_cast(workCand); - if (stmtWkCand->GetTheMeStmt()->GetOp() == OP_dassign && !stmtWkCand->LHSIsFinal()) { - VarMeExpr *lhsVar = static_cast(stmtWkCand->GetTheMeStmt())->GetVarLHS(); + if ((stmtWkCand->GetTheMeStmt()->GetOp() == OP_dassign || stmtWkCand->GetTheMeStmt()->GetOp() == OP_callassigned) && + !stmtWkCand->LHSIsFinal()) { + VarMeExpr *lhsVar = stmtWkCand->GetTheMeStmt()->GetVarLHS(); OStIdx ostIdx = lhsVar->GetOStIdx(); MapleMap*>::iterator uMapIt = useOccurMap.find(ostIdx); CHECK_FATAL(uMapIt != useOccurMap.end(), "MeStmtPre::CreateSortedOccs: missing entry in useOccurMap"); @@ -711,13 +723,13 @@ void MeStmtPre::ConstructUseOccurMapExpr(uint32 bbDfn, MeExpr *x) { void MeStmtPre::ConstructUseOccurMap() { for (PreWorkCand *wkCand : workList) { auto *stmtWkCand = static_cast(wkCand); - if (stmtWkCand->GetTheMeStmt()->GetOp() != OP_dassign) { + if (stmtWkCand->GetTheMeStmt()->GetOp() != OP_dassign && stmtWkCand->GetTheMeStmt()->GetOp() != OP_callassigned) { continue; } if (stmtWkCand->LHSIsFinal()) { continue; } - VarMeExpr *lhsVar = static_cast(stmtWkCand->GetTheMeStmt())->GetVarLHS(); + VarMeExpr *lhsVar = stmtWkCand->GetTheMeStmt()->GetVarLHS(); OStIdx ostIdx = lhsVar->GetOStIdx(); if (useOccurMap.find(ostIdx) == useOccurMap.end()) { // add an entry for ostIdx @@ -749,9 +761,8 @@ PreStmtWorkCand *MeStmtPre::CreateStmtRealOcc(MeStmt &meStmt, int seqStmt) { wkCand = static_cast(wkCand->GetNext()); } MeExpr *meExpr = nullptr; - if (meStmt.GetOp() == OP_dassign) { - auto &dass = static_cast(meStmt); - MapleStack *pStack = versionStackVec.at(dass.GetVarLHS()->GetOStIdx()); + if (meStmt.GetOp() == OP_dassign || meStmt.GetOp() == OP_callassigned) { + MapleStack *pStack = versionStackVec.at(meStmt.GetVarLHS()->GetOStIdx()); meExpr = pStack->top(); } MeRealOcc *newOcc = ssaPreMemPool->New(&meStmt, seqStmt, meExpr); diff --git a/src/maple_me/src/ssa_epre.cpp b/src/maple_me/src/ssa_epre.cpp index 81c68b9715dd46bc5fb3a88895640490b4b5dd18..21f75ecffff41df8ca85a0546523e1c393aad711 100644 --- a/src/maple_me/src/ssa_epre.cpp +++ b/src/maple_me/src/ssa_epre.cpp @@ -357,6 +357,8 @@ void SSAEPre::BuildWorkListExpr(MeStmt *meStmt, int32 seqStmt, MeExpr *meExpr, b BuildWorkListExpr(meStmt, seqStmt, ivarMeExpr->GetBase(), isRebuild, tempVar, false); } else if (ivarMeExpr->IsVolatile()) { break; + } else if (IsThreadObjField(*ivarMeExpr)) { + break; } else if (!epreIncludeRef && ivarMeExpr->GetPrimType() == PTY_ref) { break; } else if (!isRebuild || base->IsUseSameSymbol(*tempVar)) { diff --git a/src/maple_me/src/ssa_pre.cpp b/src/maple_me/src/ssa_pre.cpp index 753faddde62ec48a17f88a8bf7627eb1f1e5b238..b77ae598f5f23340f2c4b56cb16629764f7978df 100644 --- a/src/maple_me/src/ssa_pre.cpp +++ b/src/maple_me/src/ssa_pre.cpp @@ -968,8 +968,8 @@ void SSAPre::SetVarPhis(MeExpr *meExpr) { BBId defbbid = phiMeNode->GetDefBB()->GetBBId(); if (varPhiDfns.find(dom->GetDtDfnItem(defbbid)) == varPhiDfns.end() && ScreenPhiBB(defbbid)) { varPhiDfns.insert(dom->GetDtDfnItem(defbbid)); - for (auto opndit = phiMeNode->GetOpnds().begin(); opndit != phiMeNode->GetOpnds().end(); ++opndit) { - VarMeExpr *opnd = *opndit; + for (auto opndIt = phiMeNode->GetOpnds().begin(); opndIt != phiMeNode->GetOpnds().end(); ++opndIt) { + VarMeExpr *opnd = *opndIt; SetVarPhis(opnd); } } @@ -1689,7 +1689,8 @@ void SSAPre::ApplySSAPRE() { Finalize2(); // #6 CodeMotion and recompute worklist based on newly occurrence CodeMotion(); - if (preKind == kStmtPre && workCand->GetRealOccs().front()->GetOpcodeOfMeStmt() == OP_dassign) { + if (preKind == kStmtPre && (workCand->GetRealOccs().front()->GetOpcodeOfMeStmt() == OP_dassign || + workCand->GetRealOccs().front()->GetOpcodeOfMeStmt() == OP_callassigned)) { // apply full redundancy elimination DoSSAFRE(); }