From bf38d82e9ecbe8d0db6e9b8a5220c1bb4e85a1da Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 21 Nov 2024 10:08:26 -0800 Subject: [PATCH] [memprof] Skip MemProfUsePass on the empty module 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(*M.begin()); when we undrift the MemProf profile in near future. --- llvm/lib/Transforms/Instrumentation/MemProfiler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp index 867158e782221..33a7a37fa28e6 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);