From f627994b2812405cfd2c44268483bf7d9dd104e3 Mon Sep 17 00:00:00 2001 From: fye Date: Mon, 18 Apr 2022 09:29:02 -0700 Subject: [PATCH] PGO: profile data file naming utility --- src/mapleall/maple_ir/include/mir_module.h | 10 ++++++++++ src/mapleall/maple_util/include/namemangler.h | 1 + src/mapleall/mpl2mpl/include/gen_profile.h | 3 +-- src/mapleall/mpl2mpl/src/gen_profile.cpp | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/mapleall/maple_ir/include/mir_module.h b/src/mapleall/maple_ir/include/mir_module.h index c62444e5fd..fefc53d089 100644 --- a/src/mapleall/maple_ir/include/mir_module.h +++ b/src/mapleall/maple_ir/include/mir_module.h @@ -21,6 +21,7 @@ #include "mpl_logging.h" #include "muid.h" #include "profile.h" +#include "namemangler.h" #if MIR_FEATURE_FULL #include #include @@ -317,6 +318,15 @@ class MIRModule { fileName = name; } + std::string GetProfileDataFileName() const { + std::string profileDataFileName = fileName.substr(0, fileName.find_last_of(".")); + std::replace(profileDataFileName.begin(), profileDataFileName.end(), '.', '_'); + std::replace(profileDataFileName.begin(), profileDataFileName.end(), '-', '_'); + std::replace(profileDataFileName.begin(), profileDataFileName.end(), '/', '_'); + profileDataFileName = profileDataFileName + namemangler::kProfFileNameExt; + return profileDataFileName; + } + bool IsJavaModule() const { return srcLang == kSrcLangJava; } diff --git a/src/mapleall/maple_util/include/namemangler.h b/src/mapleall/maple_util/include/namemangler.h index 9a838540e0..997335883d 100644 --- a/src/mapleall/maple_util/include/namemangler.h +++ b/src/mapleall/maple_util/include/namemangler.h @@ -183,6 +183,7 @@ static constexpr const char kprefixProfExit[] = "__mpl_prof_exit_"; static constexpr const char kGCCProfInit[] = "__gcov_init"; static constexpr const char kGCCProfExit[] = "__gcov_exit"; static constexpr const char kMplMergeFuncAdd[] = "__gcov_merge_add"; +static constexpr const char kProfFileNameExt[] = ".gcda"; static constexpr const char kBindingProtectedRegionStr[] = "__BindingProtectRegion__"; diff --git a/src/mapleall/mpl2mpl/include/gen_profile.h b/src/mapleall/mpl2mpl/include/gen_profile.h index 060056b029..55908c70f0 100644 --- a/src/mapleall/mpl2mpl/include/gen_profile.h +++ b/src/mapleall/mpl2mpl/include/gen_profile.h @@ -24,8 +24,7 @@ namespace maple { static constexpr const uint32_t kMplModProfMergeFuncs = 9; // gcov reserves 9 slots static constexpr const uint32_t kGCCVersion = 0x4137352A; // gcc v7.5 under tools -//static constexpr const uint32_t kGCCVersion = 0x4139342A; // GCC V9.3/9.4 -static constexpr const char kProfFileNameExt[] = ".gcda"; +// static constexpr const uint32_t kGCCVersion = 0x4139342A; // GCC V9.3/9.4 // anything other than merge_add will be supported supported in future static constexpr const uint32_t kMplFuncProfCtrInfoNum = 1; diff --git a/src/mapleall/mpl2mpl/src/gen_profile.cpp b/src/mapleall/mpl2mpl/src/gen_profile.cpp index 88ed5134e1..b88e2d8c21 100644 --- a/src/mapleall/mpl2mpl/src/gen_profile.cpp +++ b/src/mapleall/mpl2mpl/src/gen_profile.cpp @@ -15,6 +15,7 @@ #include #include "gen_profile.h" #include "ipa_phase_manager.h" +#include "namemangler.h" // namespace maple namespace maple { @@ -102,7 +103,7 @@ void ProfileGen::CreateModProfDesc() { modProfDescSymMirConst->AddItem(checksumMirConst, 5); // Make the profile file name as fileName.gcda - std::string profFileName = flatenName(srcFN.substr(0,srcFN.find_last_of("."))) + kProfFileNameExt; + std::string profFileName = mod.GetProfileDataFileName(); MIRStrConst *profileFNMirConst = modMP->New( "./" + profFileName, *GlobalTables::GetTypeTable().GetTypeFromTyIdx((TyIdx)PTY_a64)); modProfDescSymMirConst->AddItem(profileFNMirConst, 6); -- Gitee