summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/SampleProfile.cpp
diff options
context:
space:
mode:
authorMingming Liu <mingmingl@google.com>2022-06-01 15:21:59 -0700
committerMingming Liu <mingmingl@google.com>2022-06-22 17:00:53 -0700
commitbc856eb3fc8a4b317f6bbf623c50e993a8dfd35a (patch)
tree0bebcce1d80f68b0134d2450185285fe5f67ab76 /llvm/lib/Transforms/IPO/SampleProfile.cpp
parente8716179eb0b57ad6d767bb17f349f32f387c7bd (diff)
[SampleProfile][Inline] Annotate sample profile inline remarks with link phase (prelink/postlink) information.
Differential Revision: https://reviews.llvm.org/D126833
Diffstat (limited to 'llvm/lib/Transforms/IPO/SampleProfile.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/SampleProfile.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 8cf3a64e928e..38bc2fdb4853 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -291,6 +291,11 @@ static cl::opt<bool> OverwriteExistingWeights(
"overwrite-existing-weights", cl::Hidden, cl::init(false),
cl::desc("Ignore existing branch weights on IR and always overwrite."));
+static cl::opt<bool> AnnotateSampleProfileInlinePhase(
+ "annotate-sample-profile-inline-phase", cl::Hidden, cl::init(false),
+ cl::desc("Annotate LTO phase (prelink / postlink), or main (no LTO) for "
+ "sample-profile inline pass name."));
+
extern cl::opt<bool> EnableExtTspBlockPlacement;
namespace {
@@ -423,7 +428,11 @@ public:
: SampleProfileLoaderBaseImpl(std::string(Name), std::string(RemapName)),
GetAC(std::move(GetAssumptionCache)),
GetTTI(std::move(GetTargetTransformInfo)), GetTLI(std::move(GetTLI)),
- LTOPhase(LTOPhase) {}
+ LTOPhase(LTOPhase),
+ AnnotatedPassName(AnnotateSampleProfileInlinePhase
+ ? llvm::AnnotateInlinePassName(InlineContext{
+ LTOPhase, InlinePass::SampleProfileInliner})
+ : CSINLINE_DEBUG) {}
bool doInitialization(Module &M, FunctionAnalysisManager *FAM = nullptr);
bool runOnModule(Module &M, ModuleAnalysisManager *AM,
@@ -490,7 +499,8 @@ protected:
/// We need to know the LTO phase because for example in ThinLTOPrelink
/// phase, in annotation, we should not promote indirect calls. Instead,
/// we will mark GUIDs that needs to be annotated to the function.
- ThinOrFullLTOPhase LTOPhase;
+ const ThinOrFullLTOPhase LTOPhase;
+ const std::string AnnotatedPassName;
/// Profle Symbol list tells whether a function name appears in the binary
/// used to generate the current profile.
@@ -530,6 +540,11 @@ protected:
// A pseudo probe helper to correlate the imported sample counts.
std::unique_ptr<PseudoProbeManager> ProbeManager;
+
+private:
+ const char *getAnnotatedRemarkPassName() const {
+ return AnnotatedPassName.c_str();
+ }
};
class SampleProfileLoaderLegacyPass : public ModulePass {
@@ -1019,8 +1034,9 @@ void SampleProfileLoader::emitOptimizationRemarksForInlineCandidates(
for (auto I : Candidates) {
Function *CalledFunction = I->getCalledFunction();
if (CalledFunction) {
- ORE->emit(OptimizationRemarkAnalysis(CSINLINE_DEBUG, "InlineAttempt",
- I->getDebugLoc(), I->getParent())
+ ORE->emit(OptimizationRemarkAnalysis(getAnnotatedRemarkPassName(),
+ "InlineAttempt", I->getDebugLoc(),
+ I->getParent())
<< "previous inlining reattempted for "
<< (Hot ? "hotness: '" : "size: '")
<< ore::NV("Callee", CalledFunction) << "' into '"
@@ -1239,7 +1255,8 @@ bool SampleProfileLoader::tryInlineCandidate(
InlineCost Cost = shouldInlineCandidate(Candidate);
if (Cost.isNever()) {
- ORE->emit(OptimizationRemarkAnalysis(CSINLINE_DEBUG, "InlineFail", DLoc, BB)
+ ORE->emit(OptimizationRemarkAnalysis(getAnnotatedRemarkPassName(),
+ "InlineFail", DLoc, BB)
<< "incompatible inlining");
return false;
}
@@ -1257,8 +1274,8 @@ bool SampleProfileLoader::tryInlineCandidate(
*CalledFunction);
// The call to InlineFunction erases I, so we can't pass it here.
- emitInlinedIntoBasedOnCost(*ORE, DLoc, BB, *CalledFunction,
- *BB->getParent(), Cost, true, CSINLINE_DEBUG);
+ emitInlinedIntoBasedOnCost(*ORE, DLoc, BB, *CalledFunction, *BB->getParent(),
+ Cost, true, getAnnotatedRemarkPassName());
// Now populate the list of newly exposed call sites.
if (InlinedCallSites) {
@@ -1544,11 +1561,11 @@ void SampleProfileLoader::promoteMergeNotInlinedContextSamples(
if (!Callee || Callee->isDeclaration())
continue;
- ORE->emit(OptimizationRemarkAnalysis(CSINLINE_DEBUG, "NotInline",
- I->getDebugLoc(), I->getParent())
- << "previous inlining not repeated: '"
- << ore::NV("Callee", Callee) << "' into '"
- << ore::NV("Caller", &F) << "'");
+ ORE->emit(
+ OptimizationRemarkAnalysis(getAnnotatedRemarkPassName(), "NotInline",
+ I->getDebugLoc(), I->getParent())
+ << "previous inlining not repeated: '" << ore::NV("Callee", Callee)
+ << "' into '" << ore::NV("Caller", &F) << "'");
++NumCSNotInlined;
const FunctionSamples *FS = Pair.getSecond();