[llvm] [memprof] Skip MemProfUsePass on the empty module (PR #117210)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 10:45:53 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

This patch teaches the MemProfUsePass on the empty module.

Aside from saving time to deserialize the MemProf profile, this patch
ensures that we can obtain TLI like so:

  TargetLibraryInfo &TLI = FAM.getResult<TargetLibraryAnalysis>(*M.begin());

when we undrift the MemProf profile in near future.


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


1 Files Affected:

- (modified) llvm/lib/Transforms/Instrumentation/MemProfiler.cpp (+4) 


``````````diff
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
index 867158e7822214..33a7a37fa28e65 100644
--- a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
@@ -1121,6 +1121,10 @@ MemProfUsePass::MemProfUsePass(std::string MemoryProfileFile,
 }
 
 PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
+  // Return immediately if the module doesn't contain any function.
+  if (M.empty())
+    return PreservedAnalyses::all();
+
   LLVM_DEBUG(dbgs() << "Read in memory profile:");
   auto &Ctx = M.getContext();
   auto ReaderOrErr = IndexedInstrProfReader::create(MemoryProfileFileName, *FS);

``````````

</details>


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


More information about the llvm-commits mailing list