diff --git a/src/mapleall/maple_ipa/src/ipa_phase_manager.cpp b/src/mapleall/maple_ipa/src/ipa_phase_manager.cpp index 8cf4d85bcda4c87682132841a1ca026c79da7d2a..05bc4b00fa7bc17db7cffaed578ec66bacf05766 100644 --- a/src/mapleall/maple_ipa/src/ipa_phase_manager.cpp +++ b/src/mapleall/maple_ipa/src/ipa_phase_manager.cpp @@ -194,6 +194,7 @@ bool SCCProfile::PhaseRun(SCCNode &scc) { SetQuiet(true); AddPhase("mecfgbuild", true); if (Options::profileGen) { + AddPhase("splitcriticaledge", true); AddPhase("profileGen", true); } else { AddPhase("profileUse", true); diff --git a/src/mapleall/maple_me/include/me_pgo_instrument.h b/src/mapleall/maple_me/include/me_pgo_instrument.h index 9cefde6cc9e08e587c08cad2b249a09fc72c937b..ba6727676b8aea0884858f593fbc073cbfb444b3 100644 --- a/src/mapleall/maple_me/include/me_pgo_instrument.h +++ b/src/mapleall/maple_me/include/me_pgo_instrument.h @@ -93,6 +93,8 @@ class PGOInstrument { void GetInstrumentBBs(std::vector &bbs) const { std::vector instrumentEdges; mst.GetInstrumentEdges(instrumentEdges); + std::unordered_set visitedBBs; + for (auto &edge : instrumentEdges) { BB *src = edge->GetSrcBB(); BB *dest = edge->GetDestBB(); @@ -107,8 +109,16 @@ class PGOInstrument { bbs.push_back(dest); } else { if (func->GetMIRModule().IsCModule()) { - // If it is a c module, do not split the edge until the next PGO phase - bbs.push_back(dest); + if (src->GetKind() == kBBIgoto) { + if (visitedBBs.find(dest) == visitedBBs.end()) { + // In this case, we have to instrument it anyway + bbs.push_back(dest); + visitedBBs.insert(dest); + } + } else { + func->GetCfg()->DumpToFile("profGenErrorForCModule", false); + CHECK_FATAL(false, "Unexpected case %d -> %d", src->UintID(), dest->UintID()); + } } else { func->GetCfg()->DumpToFile("profGenError", false); CHECK_FATAL(false, "impossible critial edge %d -> %d", src->UintID(), dest->UintID()); diff --git a/src/mapleall/maple_me/src/me_critical_edge.cpp b/src/mapleall/maple_me/src/me_critical_edge.cpp index c37fe842a800c1471cdb793a05edc9b5dc9c8c83..b04a72496f41d283b349d6439dd09227aae6ca85 100644 --- a/src/mapleall/maple_me/src/me_critical_edge.cpp +++ b/src/mapleall/maple_me/src/me_critical_edge.cpp @@ -19,6 +19,7 @@ #include "me_dominance.h" #include "me_function.h" #include "me_loop_analysis.h" +#include "me_irmap.h" // This phase finds critical edges and split them into two, because their // presence would restrict the optimizations performed by SSAPRE-based phases. @@ -175,6 +176,23 @@ void MeSplitCEdge::BreakCriticalEdge(MeFunction &func, BB &pred, BB &succ) const UpdateCaseLabel(*newBB, func, pred, succ); } } + // profileGen invokes MESplitCEdge to remove critical edges without going through ME completely + // newBB needs to be materialized + if (Options::profileGen) { + LabelIdx succLabel = succ.GetBBLabel(); + ASSERT(succLabel != 0, "succ's label missed"); + if (func.GetIRMap() != nullptr) { + GotoNode stmt(OP_goto); + GotoMeStmt *gotoSucc = func.GetIRMap()->New(&stmt); + gotoSucc->SetOffset(succLabel); + newBB->AddMeStmtLast(gotoSucc); + } else { + GotoNode *gotoSucc = func.GetMirFunc()->GetCodeMempool()->New(OP_goto); + gotoSucc->SetOffset(succLabel); + newBB->AddStmtNode(gotoSucc); + } + newBB->SetKind(kBBGoto); + } } // Is a critical edge is cut by bb