From 0247b97b82ff5b95a5d9d35bd0b8978a638f2050 Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Fri, 4 Feb 2022 16:13:14 -0800 Subject: [PATCH] in ssupre for restores, if there is redundancy among the saves (assumed true for now), disable the optimization to insert restores as late as possible --- src/mapleall/maple_be/include/cg/cg_ssu_pre.h | 4 +- src/mapleall/maple_be/src/cg/cg_ssu_pre.cpp | 39 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/mapleall/maple_be/include/cg/cg_ssu_pre.h b/src/mapleall/maple_be/include/cg/cg_ssu_pre.h index 2e9f67c2be..899b8e837a 100644 --- a/src/mapleall/maple_be/include/cg/cg_ssu_pre.h +++ b/src/mapleall/maple_be/include/cg/cg_ssu_pre.h @@ -155,7 +155,7 @@ class SKillOcc : public SOcc { class SSUPre { public: - SSUPre(CGFunc *cgfunc, PostDomAnalysis *pd, MemPool *memPool, SPreWorkCand *wkcand, bool enDebug) + SSUPre(CGFunc *cgfunc, PostDomAnalysis *pd, MemPool *memPool, SPreWorkCand *wkcand, bool redSaves, bool enDebug) : cgFunc(cgfunc), pdom(pd), spreMp(memPool), @@ -169,6 +169,7 @@ class SSUPre { allOccs(spreAllocator.Adapter()), lambdaOccs(spreAllocator.Adapter()), entryOccs(spreAllocator.Adapter()), + redundanciesAmongSaves(redSaves), enabledDebug(enDebug) { CreateEntryOcc(cgfunc->GetFirstBB()); } @@ -227,6 +228,7 @@ class SSUPre { MapleVector allOccs; MapleVector lambdaOccs; MapleVector entryOccs; + bool redundanciesAmongSaves; // if there is redundancy among the input saves bool enabledDebug; }; diff --git a/src/mapleall/maple_be/src/cg/cg_ssu_pre.cpp b/src/mapleall/maple_be/src/cg/cg_ssu_pre.cpp index 46508d2885..41b3d7df64 100644 --- a/src/mapleall/maple_be/src/cg/cg_ssu_pre.cpp +++ b/src/mapleall/maple_be/src/cg/cg_ssu_pre.cpp @@ -521,22 +521,38 @@ void SSUPre::PropagateNotAvail(BB *bb, std::set *visitedBBs) { } void SSUPre::FormReals() { - std::set visitedBBs; - fullyAvailBBs[cgFunc->GetCommonExitBB()->GetId()] = false; - PropagateNotAvail(cgFunc->GetFirstBB(), &visitedBBs); - - for (uint32 i = 0; i < pdom->GetPdtPreOrderSize(); i++) { - BBId bbid = pdom->GetPdtPreOrderItem(i); - BB *cgbb = cgFunc->GetAllBBs()[bbid]; - if (fullyAvailBBs[cgbb->GetId()]) { - SRealOcc *realOcc = spreMp->New(cgbb); - realOccs.push_back(realOcc); + if (redundanciesAmongSaves) { + for (uint32 i = 0; i < pdom->GetPdtPreOrderSize(); i++) { + BBId bbid = pdom->GetPdtPreOrderItem(i); + BB *cgbb = cgFunc->GetAllBBs()[bbid]; if (workCand->saveBBs.count(cgbb->GetId()) != 0) { + SRealOcc *realOcc = spreMp->New(cgbb); + realOccs.push_back(realOcc); SKillOcc *killOcc = spreMp->New(cgbb); realOccs.push_back(killOcc); + } else if (workCand->occBBs.count(cgbb->GetId()) != 0) { + SRealOcc *realOcc = spreMp->New(cgbb); + realOccs.push_back(realOcc); + } + } + } else { + std::set visitedBBs; + fullyAvailBBs[cgFunc->GetCommonExitBB()->GetId()] = false; + PropagateNotAvail(cgFunc->GetFirstBB(), &visitedBBs); + for (uint32 i = 0; i < pdom->GetPdtPreOrderSize(); i++) { + BBId bbid = pdom->GetPdtPreOrderItem(i); + BB *cgbb = cgFunc->GetAllBBs()[bbid]; + if (fullyAvailBBs[cgbb->GetId()]) { + SRealOcc *realOcc = spreMp->New(cgbb); + realOccs.push_back(realOcc); + if (workCand->saveBBs.count(cgbb->GetId()) != 0) { + SKillOcc *killOcc = spreMp->New(cgbb); + realOccs.push_back(killOcc); + } } } } + if (enabledDebug) { LogInfo::MapleLogger() << "Placement Optimization for callee-save restores" << '\n'; LogInfo::MapleLogger() << "-----------------------------------------------" << '\n'; @@ -577,7 +593,8 @@ void SSUPre::ApplySSUPre() { void DoRestorePlacementOpt(CGFunc *f, PostDomAnalysis *pdom, SPreWorkCand *workCand) { MemPool *tempMP = memPoolCtrler.NewMemPool("cg_ssu_pre", true); - SSUPre cgssupre(f, pdom, tempMP, workCand, false/*enabledDebug*/); + SSUPre cgssupre(f, pdom, tempMP, workCand, true/*redundanciesAmongSaves*/, + false/*enabledDebug*/); cgssupre.ApplySSUPre(); -- Gitee