From 83d99ef4286374e8c41b598f9c6067ee8f942dad Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Wed, 19 Jan 2022 16:40:03 -0800 Subject: [PATCH] added fully-available analysis and insert restores as late as possible as long as the occ is fully available When restore is inside infinite loop, set restoreAtEpilog to true. --- src/mapleall/maple_be/include/cg/cg_ssu_pre.h | 3 ++ src/mapleall/maple_be/src/cg/cg_ssu_pre.cpp | 40 +++++++++++++++---- 2 files changed, 36 insertions(+), 7 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 d7e6eef56e..d2bc7c65d0 100644 --- a/src/mapleall/maple_be/include/cg/cg_ssu_pre.h +++ b/src/mapleall/maple_be/include/cg/cg_ssu_pre.h @@ -161,6 +161,7 @@ class SSUPre { spreMp(memPool), spreAllocator(memPool), workCand(wkcand), + fullyAvailBBs(cgfunc->GetAllBBs().size(), true, spreAllocator.Adapter()), realOccDfns(std::less(), spreAllocator.Adapter()), lambdaDfns(std::less(), spreAllocator.Adapter()), classCount(0), @@ -204,6 +205,7 @@ class SSUPre { SEntryOcc *entryOcc = spreMp->New(bb); entryOccs.push_back(entryOcc); } + void PropagateNotAvail(BB *bb, std::set *visitedBBs); void FormReals(); CGFunc *cgFunc; @@ -214,6 +216,7 @@ class SSUPre { // following are set of BBs in terms of their dfn's; index into // dominance->pdt_preorder to get their bbid's // step 0 + MapleVector fullyAvailBBs; // index is BBid; true if occ is fully available at BB exit MapleSet realOccDfns; // set by FormReals() // step 1 lambda insertion data structures: MapleSet lambdaDfns; // set by FormLambdas() 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 32b910ab5c..46508d2885 100644 --- a/src/mapleall/maple_be/src/cg/cg_ssu_pre.cpp +++ b/src/mapleall/maple_be/src/cg/cg_ssu_pre.cpp @@ -36,10 +36,18 @@ void SSUPre::CodeMotion() { } SRealOcc *realOcc = static_cast(occ); if (!realOcc->redundant) { + if (realOcc->cgbb->IsWontExit()) { + workCand->restoreAtEpilog = true; + break; + } workCand->restoreAtExitBBs.insert(realOcc->cgbb->GetId()); } } if (enabledDebug) { + if (workCand->restoreAtEpilog) { + LogInfo::MapleLogger() << "Giving up because of restore inside infinite loop" << '\n'; + return; + } LogInfo::MapleLogger() << " _______ output _______" << '\n'; LogInfo::MapleLogger() << " restoreAtEntryBBs: ["; for (uint32 id : workCand->restoreAtEntryBBs) { @@ -497,18 +505,36 @@ void SSUPre::CreateSortedOccs() { // ================ Step 0: Preparations ================ +void SSUPre::PropagateNotAvail(BB *bb, std::set *visitedBBs) { + if (visitedBBs->count(bb) != 0) { + return; + } + visitedBBs->insert(bb); + if (workCand->occBBs.count(bb->GetId()) != 0 || + workCand->saveBBs.count(bb->GetId()) != 0) { + return; + } + fullyAvailBBs[bb->GetId()] = false; + for (BB *succbb : bb->GetSuccs()) { + PropagateNotAvail(succbb, visitedBBs); + } +} + void SSUPre::FormReals() { + std::set visitedBBs; + fullyAvailBBs[cgFunc->GetCommonExitBB()->GetId()] = false; + PropagateNotAvail(cgFunc->GetFirstBB(), &visitedBBs); + for (uint32 i = 0; i < pdom->GetPdtPreOrderSize(); i++) { - uint32 bbid = pdom->GetPdtPreOrderItem(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) { + 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) { -- Gitee