From 3b6ce53422d8c210d824ff6a3343c8d87a7a3169 Mon Sep 17 00:00:00 2001 From: fye Date: Mon, 29 Aug 2022 15:14:04 -0700 Subject: [PATCH 1/5] PGO: add simplify to profileGen to sync with profileUse --- src/mapleall/maple_phase/include/phases.def | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mapleall/maple_phase/include/phases.def b/src/mapleall/maple_phase/include/phases.def index 0d6aaa1e44..f4987ad068 100644 --- a/src/mapleall/maple_phase/include/phases.def +++ b/src/mapleall/maple_phase/include/phases.def @@ -12,6 +12,7 @@ ADDMODULEPHASE("inline", Options::O2 && Options::useInline && !Options::profileU // run callgraph again to delete fully inlined static function ADDMODULEPHASE("callgraph", Options::O2 && Options::useInline && !Options::profileUse) ADDMODULEPHASE("simplify", Options::O2 && !Options::genLMBC) +ADDMODULEPHASE("simplify", CLANG && Options::profileGen) ADDMODULEPHASE("ConstantFold", Options::O2) // ipa phase manager ADDMODULEPHASE("IpaSccPM", CLANG && (Options::O2 || Options::profileGen || Options::profileUse)) -- Gitee From d8d1c1976c9c2c25e747c2a8a130b17167118c41 Mon Sep 17 00:00:00 2001 From: fye Date: Mon, 29 Aug 2022 15:43:44 -0700 Subject: [PATCH 2/5] PGO: add simplify to profileGen to sync with profileUse --- src/mapleall/maple_me/src/me_profile_use.cpp | 11 ++++------- src/mapleall/maple_phase/include/phases.def | 3 +-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/mapleall/maple_me/src/me_profile_use.cpp b/src/mapleall/maple_me/src/me_profile_use.cpp index 44538d4780..2ca4b92d40 100644 --- a/src/mapleall/maple_me/src/me_profile_use.cpp +++ b/src/mapleall/maple_me/src/me_profile_use.cpp @@ -308,11 +308,9 @@ FuncProfInfo *MeProfUse::GetFuncData() { bool MeProfUse::CheckSumFail(const uint64 hash, const uint32 expectedCheckSum, const std::string &tag) { uint32 curCheckSum = static_cast((hash >> 32) ^ (hash & 0xffffffff)); if (curCheckSum != expectedCheckSum) { - if (dump) { - LogInfo::MapleLogger() << func->GetName() << " " << tag << " checksum doesn't match the expected " - << expectedCheckSum << " with " << tag << " real hash " << curCheckSum << '\n'; - } - return true; + LogInfo::MapleLogger() << func->GetName() << "() " << tag << " checksum " << curCheckSum + << " doesn't match the expected " << expectedCheckSum << "; aborting\n"; + abort(); } return false; } @@ -325,12 +323,11 @@ bool MeProfUse::MapleProfRun() { func->GetMirFunc()->SetFuncProfData(funcData); // early return if lineno fail if (CheckSumFail(ComputeLinenoHash(), funcData->linenoChecksum, "lineno")) { - func->GetMirFunc()->SetFuncProfData(nullptr); // clear func profile data return false; } FindInstrumentEdges(); // early return if cfgchecksum fail - if (CheckSumFail(ComputeFuncHash(), funcData->cfgChecksum, "func")) { + if (CheckSumFail(ComputeFuncHash(), funcData->cfgChecksum, "function")) { return false; } std::vector instrumentBBs; diff --git a/src/mapleall/maple_phase/include/phases.def b/src/mapleall/maple_phase/include/phases.def index f4987ad068..e15cda7610 100644 --- a/src/mapleall/maple_phase/include/phases.def +++ b/src/mapleall/maple_phase/include/phases.def @@ -11,8 +11,7 @@ ADDMODULEPHASE("callgraph", !Options::profileUse) ADDMODULEPHASE("inline", Options::O2 && Options::useInline && !Options::profileUse && !Options::enableInlineSummary) // run callgraph again to delete fully inlined static function ADDMODULEPHASE("callgraph", Options::O2 && Options::useInline && !Options::profileUse) -ADDMODULEPHASE("simplify", Options::O2 && !Options::genLMBC) -ADDMODULEPHASE("simplify", CLANG && Options::profileGen) +ADDMODULEPHASE("simplify", (Options::O2 && !Options::genLMBC) || CLANG && Options::profileGen) ADDMODULEPHASE("ConstantFold", Options::O2) // ipa phase manager ADDMODULEPHASE("IpaSccPM", CLANG && (Options::O2 || Options::profileGen || Options::profileUse)) -- Gitee From 5c659e74fef03b6de59d059f465ea8200e43a329 Mon Sep 17 00:00:00 2001 From: fye Date: Mon, 29 Aug 2022 17:09:53 -0700 Subject: [PATCH 3/5] PGO: add simplify to profileGen to sync with profileUse --- src/mapleall/maple_phase/include/phases.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mapleall/maple_phase/include/phases.def b/src/mapleall/maple_phase/include/phases.def index e15cda7610..5aa63aa504 100644 --- a/src/mapleall/maple_phase/include/phases.def +++ b/src/mapleall/maple_phase/include/phases.def @@ -11,7 +11,7 @@ ADDMODULEPHASE("callgraph", !Options::profileUse) ADDMODULEPHASE("inline", Options::O2 && Options::useInline && !Options::profileUse && !Options::enableInlineSummary) // run callgraph again to delete fully inlined static function ADDMODULEPHASE("callgraph", Options::O2 && Options::useInline && !Options::profileUse) -ADDMODULEPHASE("simplify", (Options::O2 && !Options::genLMBC) || CLANG && Options::profileGen) +ADDMODULEPHASE("simplify", (Options::O2 && !Options::genLMBC) || (CLANG && Options::profileGen)) ADDMODULEPHASE("ConstantFold", Options::O2) // ipa phase manager ADDMODULEPHASE("IpaSccPM", CLANG && (Options::O2 || Options::profileGen || Options::profileUse)) -- Gitee From 9689853c53b4fb1615693b39489bea8edbec2f6f Mon Sep 17 00:00:00 2001 From: fye Date: Tue, 30 Aug 2022 13:59:02 -0700 Subject: [PATCH 4/5] PGO: support non-exit code for c module --- src/mapleall/maple_me/include/me_pgo_instrument.h | 2 +- src/mapleall/maple_me/src/me_profile_gen.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mapleall/maple_me/include/me_pgo_instrument.h b/src/mapleall/maple_me/include/me_pgo_instrument.h index 77c8ac0680..b1bc3d9786 100644 --- a/src/mapleall/maple_me/include/me_pgo_instrument.h +++ b/src/mapleall/maple_me/include/me_pgo_instrument.h @@ -109,7 +109,7 @@ class PGOInstrument { bbs.push_back(dest); } else { if (func->GetMIRModule().IsCModule()) { - if (src->GetKind() == kBBIgoto) { + if (src->GetKind() == kBBIgoto || src->GetKind() == kBBGoto) { if (visitedBBs.find(dest) == visitedBBs.end()) { // In this case, we have to instrument it anyway bbs.push_back(dest); diff --git a/src/mapleall/maple_me/src/me_profile_gen.cpp b/src/mapleall/maple_me/src/me_profile_gen.cpp index b29b27cd25..a36b769c42 100644 --- a/src/mapleall/maple_me/src/me_profile_gen.cpp +++ b/src/mapleall/maple_me/src/me_profile_gen.cpp @@ -187,7 +187,12 @@ bool MeProfGen::CanInstrument() const { } auto *bb = *bIt; if (bb->GetAttributes(kBBAttrIsTry) || bb->GetAttributes(kBBAttrWontExit)) { - return false; + if (func->GetMIRModule().IsCModule()) { + // Consider the case of non-exit as a special program + continue; + } else { + return false; + } } } return true; -- Gitee From f4452bccb811ebf002412466a5f373714a479f7f Mon Sep 17 00:00:00 2001 From: fye Date: Fri, 2 Sep 2022 13:21:13 -0700 Subject: [PATCH 5/5] PGO: add simplify to profileGen to sync with profileUse --- src/mapleall/maple_me/include/me_profile_use.h | 2 +- src/mapleall/maple_me/src/me_profile_use.cpp | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/mapleall/maple_me/include/me_profile_use.h b/src/mapleall/maple_me/include/me_profile_use.h index 2014e80026..e5d1de857c 100644 --- a/src/mapleall/maple_me/include/me_profile_use.h +++ b/src/mapleall/maple_me/include/me_profile_use.h @@ -138,7 +138,7 @@ class MeProfUse : public PGOInstrument { return succCalcuAllEdgeFreq; } bool MapleProfRun(); - bool CheckSumFail(const uint64 hash, const uint32 expectedCheckSum, const std::string &tag); + void CheckSumFail(const uint64 hash, const uint32 expectedCheckSum, const std::string &tag); private: bool IsAllZero(Profile::BBInfo &result) const; void SetEdgeCount(BBUseEdge &edge, size_t value); diff --git a/src/mapleall/maple_me/src/me_profile_use.cpp b/src/mapleall/maple_me/src/me_profile_use.cpp index 2ca4b92d40..3e8f5e558a 100644 --- a/src/mapleall/maple_me/src/me_profile_use.cpp +++ b/src/mapleall/maple_me/src/me_profile_use.cpp @@ -305,14 +305,13 @@ FuncProfInfo *MeProfUse::GetFuncData() { return funcData; } -bool MeProfUse::CheckSumFail(const uint64 hash, const uint32 expectedCheckSum, const std::string &tag) { +void MeProfUse::CheckSumFail(const uint64 hash, const uint32 expectedCheckSum, const std::string &tag) { uint32 curCheckSum = static_cast((hash >> 32) ^ (hash & 0xffffffff)); if (curCheckSum != expectedCheckSum) { LogInfo::MapleLogger() << func->GetName() << "() " << tag << " checksum " << curCheckSum << " doesn't match the expected " << expectedCheckSum << "; aborting\n"; abort(); } - return false; } bool MeProfUse::MapleProfRun() { @@ -321,15 +320,13 @@ bool MeProfUse::MapleProfRun() { return false; } func->GetMirFunc()->SetFuncProfData(funcData); - // early return if lineno fail - if (CheckSumFail(ComputeLinenoHash(), funcData->linenoChecksum, "lineno")) { - return false; - } + // Abort if lineno fail + CheckSumFail(ComputeLinenoHash(), funcData->linenoChecksum, "lineno"); + FindInstrumentEdges(); - // early return if cfgchecksum fail - if (CheckSumFail(ComputeFuncHash(), funcData->cfgChecksum, "function")) { - return false; - } + // Abort if cfgchecksum fail + CheckSumFail(ComputeFuncHash(), funcData->cfgChecksum, "function"); + std::vector instrumentBBs; GetInstrumentBBs(instrumentBBs); if (dump) { -- Gitee