Skip to content

[memprof] Skip MemProfUsePass on the empty module #117210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

kazutakahirata
Copy link
Contributor

@kazutakahirata kazutakahirata commented Nov 21, 2024

This patch teaches the MemProfUsePass to return immediately 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(*M.begin());

when we undrift the MemProf profile in near future.

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.
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

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 --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);

Copy link
Contributor

@teresajohnson teresajohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code change lgtm but the description might need a slight tweak, I feel like there is a missing/wrong word or so in "This patch teaches the MemProfUsePass on the empty module."

@kazutakahirata
Copy link
Contributor Author

The code change lgtm but the description might need a slight tweak, I feel like there is a missing/wrong word or so in "This patch teaches the MemProfUsePass on the empty module."

Oops! Thank you for pointing this out! Fixed.

@kazutakahirata kazutakahirata merged commit 51cdf1f into llvm:main Nov 21, 2024
7 of 9 checks passed
@kazutakahirata kazutakahirata deleted the memprof_undrift_return branch November 21, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants