From 37f72fc54de308214c1eae288dfdb48d74ef3066 Mon Sep 17 00:00:00 2001 From: fye Date: Wed, 13 Apr 2022 08:23:38 -0700 Subject: [PATCH] PGO: profileGen fixes: NoCriticalEdgeSplit-0CtrTbl-InitProfDesc etc --- .../maple_ipa/src/ipa_phase_manager.cpp | 4 --- .../maple_me/include/me_pgo_instrument.h | 9 +++++-- src/mapleall/maple_me/src/me_option.cpp | 1 + src/mapleall/maple_me/src/me_profile_gen.cpp | 6 ++--- src/mapleall/mpl2mpl/include/gen_profile.h | 4 +-- src/mapleall/mpl2mpl/src/gen_profile.cpp | 27 ++++++++++++++----- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/mapleall/maple_ipa/src/ipa_phase_manager.cpp b/src/mapleall/maple_ipa/src/ipa_phase_manager.cpp index 8712b101a2..292b6fa613 100644 --- a/src/mapleall/maple_ipa/src/ipa_phase_manager.cpp +++ b/src/mapleall/maple_ipa/src/ipa_phase_manager.cpp @@ -191,10 +191,6 @@ bool SCCProfile::PhaseRun(SCCNode &scc) { SetQuiet(true); AddPhase("mecfgbuild", true); if (Options::profileGen) { - AddPhase("ssatab", true); - AddPhase("aliasclass", true); - AddPhase("ssa", true); - AddPhase("irmapbuild", 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 16ca3d7c43..1aca4ef177 100644 --- a/src/mapleall/maple_me/include/me_pgo_instrument.h +++ b/src/mapleall/maple_me/include/me_pgo_instrument.h @@ -106,8 +106,13 @@ class PGOInstrument { } else if (!edge->IsCritical()) { bbs.push_back(dest); } else { - func->GetCfg()->DumpToFile("profGenError", false); - CHECK_FATAL(false, "impossible critial edge %d -> %d", src->UintID(), dest->UintID()); + if (func->GetMIRModule().IsCModule()) { + // If it is a c module, do not split the edge until the next PGO phase + bbs.push_back(dest); + } 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_option.cpp b/src/mapleall/maple_me/src/me_option.cpp index 4ac0ddd3da..1a3df75f88 100644 --- a/src/mapleall/maple_me/src/me_option.cpp +++ b/src/mapleall/maple_me/src/me_option.cpp @@ -1457,6 +1457,7 @@ bool MeOption::SolveOptions(const std::deque &opts, bool is break; case kVerbose: quiet = (opt.Type() == kEnable) ? false : true; + break; case kProfileGen: if (optLevel != kLevelZero) { WARN(kLncWarn, "profileGen requires no optimization"); diff --git a/src/mapleall/maple_me/src/me_profile_gen.cpp b/src/mapleall/maple_me/src/me_profile_gen.cpp index 970e146dcc..9bd067fbe8 100644 --- a/src/mapleall/maple_me/src/me_profile_gen.cpp +++ b/src/mapleall/maple_me/src/me_profile_gen.cpp @@ -112,8 +112,7 @@ void MeProfGen::InstrumentFunc() { if (nCtrs != 0) { MIRType *arrOfInt64Ty = GlobalTables::GetTypeTable().GetOrCreateArrayType( *GlobalTables::GetTypeTable().GetInt64(), nCtrs); - - // Likely pathname is needed + // flatten the counter table name std::string ctrTblName = namemangler::kprefixProfCtrTbl + func->GetMIRModule().GetFileName() + "_" + func->GetMirFunc()->GetName(); @@ -122,6 +121,7 @@ void MeProfGen::InstrumentFunc() { std::replace(ctrTblName.begin(), ctrTblName.end(), '/', '_'); MIRSymbol *ctrTblSym = mod->GetMIRBuilder()->CreateGlobalDecl(ctrTblName, *arrOfInt64Ty, kScFstatic); + ctrTblSym->SetSKind(kStVar); func->GetMirFunc()->SetProfCtrTbl(ctrTblSym); } @@ -129,7 +129,7 @@ void MeProfGen::InstrumentFunc() { InstrumentBB(*bb); } - // Checksums are relatively sensible to source changes + // Checksums are relatively sensitive to source changes // Generate the function's lineno checksum std::string fileName = func->GetMIRModule().GetFileName(); uint64 fileNameHash = DJBHash(fileName.c_str()); diff --git a/src/mapleall/mpl2mpl/include/gen_profile.h b/src/mapleall/mpl2mpl/include/gen_profile.h index 6f3bf39302..060056b029 100644 --- a/src/mapleall/mpl2mpl/include/gen_profile.h +++ b/src/mapleall/mpl2mpl/include/gen_profile.h @@ -68,9 +68,9 @@ class ProfileGen { private: MIRModule &mod; - MIRSymbol *modProfDesc; + MIRSymbol *modProfDesc = nullptr; // Keep order of funcs visited - MIRSymbol *funcProfDescTbl; + MIRSymbol *funcProfDescTbl = nullptr; std::vector funcProfDescs; std::vector validFuncs; }; diff --git a/src/mapleall/mpl2mpl/src/gen_profile.cpp b/src/mapleall/mpl2mpl/src/gen_profile.cpp index 9eeb5e7231..88ed5134e1 100644 --- a/src/mapleall/mpl2mpl/src/gen_profile.cpp +++ b/src/mapleall/mpl2mpl/src/gen_profile.cpp @@ -203,10 +203,13 @@ void ProfileGen::CreateFuncProfDesc() { MIRIntConst *zeroMirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *u64Ty); MIRType *arrOfUInt64Ty = GlobalTables::GetTypeTable().GetOrCreateArrayType(*u64Ty, nCtrs); MIRAggConst *initCtrTblMirConst = modMP->New(mod, *arrOfUInt64Ty); - for (uint32 i=0; iAddItem(zeroMirConst, 0); + + if (ctrTblSym && nCtrs > 0) { + for (uint32 i=0; iAddItem(zeroMirConst, i); + } + ctrTblSym->SetKonst(initCtrTblMirConst); } - ctrTblSym->SetKonst(initCtrTblMirConst); PUIdx puID = f->GetPuidx(); @@ -238,9 +241,17 @@ void ProfileGen::CreateFuncProfDesc() { MIRIntConst *nCtrMirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(nCtrs, *u32Ty); ctrDescMirConst->AddItem(nCtrMirConst, 1); - MIRAddrofConst *ctrTblMirConst = - modMP->New(ctrTblSym->GetStIdx(), 0, *GlobalTables::GetTypeTable().GetPtr()); - ctrDescMirConst->AddItem(ctrTblMirConst, 2); + + MIRAddrofConst *ctrTblMirConst; + if (ctrTblSym) { + ctrTblMirConst = modMP->New(ctrTblSym->GetStIdx(), 0, *GlobalTables::GetTypeTable().GetPtr()); + ctrDescMirConst->AddItem(ctrTblMirConst, 2); + } else { + MIRType *voidPtrTy = GlobalTables::GetTypeTable().GetVoidPtr(); + MIRIntConst *nullPtrMirConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *voidPtrTy); + ctrDescMirConst->AddItem(nullPtrMirConst, 2); + } + MIRType *arrOfCtrDescTy = GlobalTables::GetTypeTable().GetOrCreateArrayType(*ctrDescTy, kMplFuncProfCtrInfoNum); MIRAggConst *arrOfCtrDescMirConst = modMP->New(mod, *arrOfCtrDescTy); @@ -284,6 +295,10 @@ void ProfileGen::CreateFuncProfDescTbl() { } void ProfileGen::FixupDesc() { + if (funcProfDescTbl == nullptr) { + return; + } + MIRAggConst *modProfDescMirConst = static_cast(modProfDesc->GetKonst()); MIRAddrofConst *funcProfDescTblAddr = mod.GetMemPool()->New( funcProfDescTbl->GetStIdx(), 0, *GlobalTables::GetTypeTable().GetPtr()); -- Gitee