[clang] [llvm] [InstrPGO] Instrument sampling profile based cold function (PR #109837)

Ellis Hoag via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 8 12:55:15 PDT 2024


================
@@ -1119,6 +1125,18 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
       // removed.
       MPM.addPass(
           PGOIndirectCallPromotion(true /* IsInLTO */, true /* SamplePGO */));
+
+    if (InstrumentSampleColdFuncPath.getNumOccurrences() &&
+        Phase != ThinOrFullLTOPhase::ThinLTOPostLink) {
+      assert(!InstrumentSampleColdFuncPath.empty() &&
+             "File path is requeired for instrumentation generation");
+      InstrumentColdFunctionCoverage = true;
+      addPreInlinerPasses(MPM, Level, Phase);
+      addPGOInstrPasses(MPM, Level, /* RunProfileGen */ true,
+                        /* IsCS */ false, /* AtomicCounterUpdate */ false,
+                        InstrumentSampleColdFuncPath, "",
+                        IntrusiveRefCntPtr<vfs::FileSystem>());
+    }
----------------
ellishg wrote:

> if a function symbol shows in the binary but not in the profile, we can treat it as cold function(set 0 entry count)

I wasn't aware that SamplePGO did this. This is indeed different than IRPGO. Perhaps it makes more sense to use a separate flag to control this case. Maybe something like `-instrument-cold-function-coverage-mode={optimistic,conservative}` where `optimistic` means we optimistically treat unprofiled functions as cold and `conservative` means we conservatively assume unprofiled functions is hot. 

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


More information about the cfe-commits mailing list