llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (lifengxiang1025)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/73236.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (+3) 
- (modified) llvm/lib/Transforms/Instrumentation/MemProfiler.cpp (+1-15) 


``````````diff
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();

``````````

</details>


https://github.com/llvm/llvm-project/pull/73236
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to