From fe80bbbbdaaf30f49819bb71cee921417a154644 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Tue, 9 Nov 2021 11:10:47 -0800 Subject: [PATCH] Add mplme option --proplimit= to help in triaging bug in hprop phase --- src/mapleall/maple_me/include/me_option.h | 1 + src/mapleall/maple_me/include/me_prop.h | 4 ++-- src/mapleall/maple_me/include/prop.h | 5 ++++- src/mapleall/maple_me/src/me_option.cpp | 15 +++++++++++++++ src/mapleall/maple_me/src/me_prop.cpp | 5 +++-- src/mapleall/maple_me/src/prop.cpp | 18 +++++++++++++++--- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/mapleall/maple_me/include/me_option.h b/src/mapleall/maple_me/include/me_option.h index ef7f4832d4..76dad4637b 100644 --- a/src/mapleall/maple_me/include/me_option.h +++ b/src/mapleall/maple_me/include/me_option.h @@ -118,6 +118,7 @@ class MeOption : public MapleDriverOptionBase { static bool ignoreInferredRetType; static uint32 pregRenameLimit; static uint32 rename2pregLimit; + static uint32 propLimit; static uint32 copyPropLimit; static uint32 delRcPULimit; static uint32 profileBBHotRate; diff --git a/src/mapleall/maple_me/include/me_prop.h b/src/mapleall/maple_me/include/me_prop.h index cc7995e32a..130a93df3d 100644 --- a/src/mapleall/maple_me/include/me_prop.h +++ b/src/mapleall/maple_me/include/me_prop.h @@ -21,8 +21,8 @@ namespace maple { class MeProp : public Prop { public: - MeProp(MeIRMap &irMap, Dominance &dom, MemPool &memPool, const PropConfig &config) - : Prop(irMap, dom, memPool, irMap.GetFunc().GetCfg()->GetAllBBs().size(), config), + MeProp(MeIRMap &irMap, Dominance &dom, MemPool &memPool, const PropConfig &config, uint32 limit = UINT32_MAX) + : Prop(irMap, dom, memPool, irMap.GetFunc().GetCfg()->GetAllBBs().size(), config, limit), func(&irMap.GetFunc()) {} virtual ~MeProp() = default; diff --git a/src/mapleall/maple_me/include/prop.h b/src/mapleall/maple_me/include/prop.h index 6e74fc1baf..2cbf49b5e4 100644 --- a/src/mapleall/maple_me/include/prop.h +++ b/src/mapleall/maple_me/include/prop.h @@ -43,7 +43,7 @@ class Prop { bool propagateWithInverse; }; - Prop(IRMap&, Dominance&, MemPool&, uint32 bbvecsize, const PropConfig &config); + Prop(IRMap&, Dominance&, MemPool&, uint32 bbvecsize, const PropConfig &config, uint32 limit = UINT32_MAX); virtual ~Prop() = default; MeExpr *CheckTruncation(MeExpr *lhs, MeExpr *rhs) const; @@ -118,6 +118,9 @@ class Prop { BB *curBB = nullptr; // gives the bb of the traversal PropConfig config; MapleMap*> candsForSSAUpdate; + public: + uint32 propLimit; + uint32 propsPerformed = 0; // count number of copy propagations performed }; } // namespace maple #endif // MAPLE_ME_INCLUDE_PROP_H diff --git a/src/mapleall/maple_me/src/me_option.cpp b/src/mapleall/maple_me/src/me_option.cpp index f694896b8c..f926073997 100644 --- a/src/mapleall/maple_me/src/me_option.cpp +++ b/src/mapleall/maple_me/src/me_option.cpp @@ -56,6 +56,7 @@ uint32 MeOption::lpreLimit = UINT32_MAX; uint32 MeOption::lprePULimit = UINT32_MAX; uint32 MeOption::pregRenameLimit = UINT32_MAX; uint32 MeOption::rename2pregLimit = UINT32_MAX; +uint32 MeOption::propLimit = UINT32_MAX; uint32 MeOption::copyPropLimit = UINT32_MAX; uint32 MeOption::profileBBHotRate = 10; uint32 MeOption::profileBBColdRate = 99; @@ -175,6 +176,7 @@ enum OptionIndex { kLprepulLimit, kPregreNameLimit, kRename2pregLimit, + kPropLimit, kCopyPropLimit, kDelrcpuLimit, kProfileBBHotRate, @@ -611,6 +613,16 @@ const Descriptor kUsage[] = { " \t--rename2preglimit=NUM\n", "me", {} }, + { kPropLimit, + 0, + "", + "proplimit", + kBuildTypeExperimental, + kArgCheckPolicyRequired, + " --proplimit \tApply propagation only up to NUM times in each hprop invocation\n" + " \t--proplimit=NUM\n", + "me", + {} }, { kCopyPropLimit, 0, "", @@ -1477,6 +1489,9 @@ bool MeOption::SolveOptions(const std::vector &opts, bool i case kRename2pregLimit: rename2pregLimit = std::stoul(opt.Args(), nullptr); break; + case kPropLimit: + propLimit = std::stoul(opt.Args(), nullptr); + break; case kCopyPropLimit: copyPropLimit = std::stoul(opt.Args(), nullptr); break; diff --git a/src/mapleall/maple_me/src/me_prop.cpp b/src/mapleall/maple_me/src/me_prop.cpp index f34db5ff43..de2a6fef30 100644 --- a/src/mapleall/maple_me/src/me_prop.cpp +++ b/src/mapleall/maple_me/src/me_prop.cpp @@ -64,10 +64,11 @@ bool MEMeProp::PhaseRun(maple::MeFunction &f) { } MeProp meProp(*hMap, *dom, *GetPhaseMemPool(), Prop::PropConfig { MeOption::propBase, propIloadRef, MeOption::propGlobalRef, MeOption::propFinaliLoadRef, MeOption::propIloadRefNonParm, MeOption::propAtPhi, - MeOption::propWithInverse || f.IsLfo() }); + MeOption::propWithInverse || f.IsLfo() }, MeOption::propLimit); meProp.TraversalBB(*f.GetCfg()->GetCommonEntryBB()); if (DEBUGFUNC_NEWPM(f)) { - LogInfo::MapleLogger() << "\n============== After Copy Propagation =============" << '\n'; + LogInfo::MapleLogger() << "\nNumber of propagations performed by hprop: " << meProp.propsPerformed << std::endl; + LogInfo::MapleLogger() << "============== After Copy Propagation =============" << '\n'; f.Dump(false); } diff --git a/src/mapleall/maple_me/src/prop.cpp b/src/mapleall/maple_me/src/prop.cpp index f3739f1888..4b472afa86 100644 --- a/src/mapleall/maple_me/src/prop.cpp +++ b/src/mapleall/maple_me/src/prop.cpp @@ -30,7 +30,7 @@ static constexpr uint32 kMaxRegParamNum = 4; static constexpr uint32 kMaxRegParamNum = 8; #endif -Prop::Prop(IRMap &irMap, Dominance &dom, MemPool &memPool, uint32 bbvecsize, const PropConfig &config) +Prop::Prop(IRMap &irMap, Dominance &dom, MemPool &memPool, uint32 bbvecsize, const PropConfig &config, uint32 limit) : dom(dom), irMap(irMap), ssaTab(irMap.GetSSATab()), @@ -39,7 +39,8 @@ Prop::Prop(IRMap &irMap, Dominance &dom, MemPool &memPool, uint32 bbvecsize, con vstLiveStackVec(propMapAlloc.Adapter()), bbVisited(bbvecsize, false, propMapAlloc.Adapter()), config(config), - candsForSSAUpdate(propMapAlloc.Adapter()) { + candsForSSAUpdate(propMapAlloc.Adapter()), + propLimit(limit) { const MapleVector &originalStVec = ssaTab.GetOriginalStTable().GetOriginalStVector(); vstLiveStackVec.resize(originalStVec.size()); for (size_t i = 1; i < originalStVec.size(); ++i) { @@ -634,7 +635,7 @@ MeExpr *Prop::CheckTruncation(MeExpr *lhs, MeExpr *rhs) const { // return varMeExpr itself if no propagation opportunity MeExpr &Prop::PropVar(VarMeExpr &varMeExpr, bool atParm, bool checkPhi) { const MIRSymbol *st = varMeExpr.GetOst()->GetMIRSymbol(); - if (st->IsInstrumented() || varMeExpr.IsVolatile() || varMeExpr.GetOst()->HasOneElemSimdAttr()) { + if (st->IsInstrumented() || varMeExpr.IsVolatile() || varMeExpr.GetOst()->HasOneElemSimdAttr() || propsPerformed >= propLimit) { return varMeExpr; } @@ -658,6 +659,7 @@ MeExpr &Prop::PropVar(VarMeExpr &varMeExpr, bool atParm, bool checkPhi) { if (propagatable == kPropOnlyWithInverse) { rhs = RehashUsingInverse(rhs); } + propsPerformed++; return *CheckTruncation(&varMeExpr, rhs); } else { return varMeExpr; @@ -681,12 +683,16 @@ MeExpr &Prop::PropVar(VarMeExpr &varMeExpr, bool atParm, bool checkPhi) { return varMeExpr; } } + propsPerformed++; return *opndLastProp; } return varMeExpr; } MeExpr &Prop::PropReg(RegMeExpr ®MeExpr, bool atParm, bool checkPhi) { + if (propsPerformed >= propLimit) { + return regMeExpr; + } if (regMeExpr.GetDefBy() == kDefByStmt) { AssignMeStmt *defStmt = static_cast(regMeExpr.GetDefStmt()); MeExpr &rhs = utils::ToRef(defStmt->GetRHS()); @@ -698,6 +704,7 @@ MeExpr &Prop::PropReg(RegMeExpr ®MeExpr, bool atParm, bool checkPhi) { if (propagatable == kPropOnlyWithInverse) { rhs = *RehashUsingInverse(&rhs); } + propsPerformed++; return rhs; } } else if (checkPhi && regMeExpr.GetDefBy() == kDefByPhi && config.propagateAtPhi) { @@ -715,18 +722,23 @@ MeExpr &Prop::PropReg(RegMeExpr ®MeExpr, bool atParm, bool checkPhi) { return regMeExpr; } } + propsPerformed++; return *opndLastProp; } return regMeExpr; } MeExpr &Prop::PropIvar(IvarMeExpr &ivarMeExpr) { + if (propsPerformed >= propLimit) { + return ivarMeExpr; + } IassignMeStmt *defStmt = ivarMeExpr.GetDefStmt(); if (defStmt == nullptr || ivarMeExpr.IsVolatile()) { return ivarMeExpr; } MeExpr &rhs = utils::ToRef(defStmt->GetRHS()); if (rhs.GetDepth() <= kPropTreeLevel && Propagatable(&rhs, defStmt->GetBB(), false) != kPropNo) { + propsPerformed++; return *CheckTruncation(&ivarMeExpr, &rhs); } if (mirModule.IsCModule() && ivarMeExpr.GetPrimType() != PTY_agg) { -- Gitee