[llvm] [MemProf] Improve metadata cleanup in LTO backend (PR #113039)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 20 11:00:40 PDT 2024


================
@@ -4419,16 +4416,28 @@ bool MemProfContextDisambiguation::applyImport(Module &M) {
             CloneCallsite(Callsite->second, CB, CalledFunction);
           }
         }
-        // Memprof and callsite metadata on memory allocations no longer needed.
-        I.setMetadata(LLVMContext::MD_memprof, nullptr);
-        I.setMetadata(LLVMContext::MD_callsite, nullptr);
       }
     }
 
     // Now do any promotion required for cloning.
     performICP(M, FS->callsites(), VMaps, ICallAnalysisInfo, ORE);
   }
 
+  // We skip some of the functions and instructions above, so remove all the
+  // metadata in a single sweep here.
+  for (auto &F : M) {
+    // We can skip memprof clones because createFunctionClones already strips
+    // the metadata from the newly created clones.
+    if (F.isDeclaration() || isMemProfClone(F))
+      continue;
+    for (auto &BB : F) {
+      for (auto &I : BB) {
----------------
snehasish wrote:

Should we also filter by CallInst to so that we don't call setMetadata unnecessarily? 

https://github.com/llvm/llvm-project/pull/113039


More information about the llvm-commits mailing list