[clang] [llvm] [MemProf] Expand optimization scope to internal linakge function (PR #73236)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 23 04:30:18 PST 2023
https://github.com/lifengxiang1025 created https://github.com/llvm/llvm-project/pull/73236
Now MemProf can't do IR annotation right in the local linkage function and global initial function __cxx_global_var_init. In llvm-profdata which convert raw memory profile to memory profile, it uses function name in dwarf to create GUID. But when llvm consumes memory profile, it use `getIRPGOFuncName` or `getPGOFuncName` which returns local linkage function as `FileName;FunctionName` or `FileName:FunctionName` to get function name and create GUID. So profile creator's GUID is not same as profile consumer.
So I think MemProf should be used with `unique-internal-linkage-names` and don't use PGOFuncName.
__cxx_global_var_init is created later than where UniqueInternalLinkageNames works. So I add uniq suffix to __cxx_global_var_init additionally.
>From 9dd4626612f706b8df08ee5a1f43a6b59ae47acf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E5=87=A4=E7=A5=A5?=
<lifengxiang.1025 at bytedance.com>
Date: Thu, 23 Nov 2023 20:13:24 +0800
Subject: [PATCH] [MemProf] Expand optimization scope to internal linakge
function
---
clang/lib/CodeGen/CGDeclCXX.cpp | 3 +++
.../Transforms/Instrumentation/MemProfiler.cpp | 16 +---------------
2 files changed, 4 insertions(+), 15 deletions(-)
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index e08a1e5f42df20c..ae45c23c9e6811c 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -538,6 +538,9 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
{
llvm::raw_svector_ostream Out(FnName);
getCXXABI().getMangleContext().mangleDynamicInitializer(D, Out);
+ if (getCodeGenOpts().UniqueInternalLinkageNames) {
+ Out << getModuleNameHash();
+ }
}
// Create a variable initialization function.
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
index c6134ce77136364..97db0122be7c8e7 100644
--- a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
@@ -677,24 +677,10 @@ static void readMemprof(Module &M, Function &F,
const TargetLibraryInfo &TLI) {
auto &Ctx = M.getContext();
- auto FuncName = getIRPGOFuncName(F);
+ auto FuncName = F.getName();
auto FuncGUID = Function::getGUID(FuncName);
std::optional<memprof::MemProfRecord> MemProfRec;
auto Err = MemProfReader->getMemProfRecord(FuncGUID).moveInto(MemProfRec);
- if (Err) {
- // If we don't find getIRPGOFuncName(), try getPGOFuncName() to handle
- // profiles built by older compilers
- Err = handleErrors(std::move(Err), [&](const InstrProfError &IE) -> Error {
- if (IE.get() != instrprof_error::unknown_function)
- return make_error<InstrProfError>(IE);
- auto FuncName = getPGOFuncName(F);
- auto FuncGUID = Function::getGUID(FuncName);
- if (auto Err =
- MemProfReader->getMemProfRecord(FuncGUID).moveInto(MemProfRec))
- return Err;
- return Error::success();
- });
- }
if (Err) {
handleAllErrors(std::move(Err), [&](const InstrProfError &IPE) {
auto Err = IPE.get();
More information about the cfe-commits
mailing list