aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2025-05-28 16:44:44 -0700
committerGitHub <noreply@github.com>2025-05-28 16:44:44 -0700
commit49d48c32e04742ebd05cbbd7dd544b1217b6d9d0 (patch)
tree41d46a964fdb65f9270db8edfe1c971f3f3f825b /llvm/lib/Transforms/Utils/InlineFunction.cpp
parented5eb1c6c6c3e1bb53448d8916ecf7c91fdb692e (diff)
downloadllvm-49d48c32e04742ebd05cbbd7dd544b1217b6d9d0.zip
llvm-49d48c32e04742ebd05cbbd7dd544b1217b6d9d0.tar.gz
llvm-49d48c32e04742ebd05cbbd7dd544b1217b6d9d0.tar.bz2
[MemProf] Emit remarks when hinting allocations not needing cloning (#141859)
The context disambiguation code already emits remarks when hinting allocations (by adding hotness attributes) during cloning. However, we did not yet emit hints when applying the hotness attributes during building of the metadata (during matching and again after inlining). Add remarks when we apply the hint attributes for these non-context-sensitive allocations.
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 21467a90..7a9605b 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -828,12 +828,13 @@ static void removeCallsiteMetadata(CallBase *Call) {
}
static void updateMemprofMetadata(CallBase *CI,
- const std::vector<Metadata *> &MIBList) {
+ const std::vector<Metadata *> &MIBList,
+ OptimizationRemarkEmitter *ORE) {
assert(!MIBList.empty());
// Remove existing memprof, which will either be replaced or may not be needed
// if we are able to use a single allocation type function attribute.
removeMemProfMetadata(CI);
- CallStackTrie CallStack;
+ CallStackTrie CallStack(ORE);
for (Metadata *MIB : MIBList)
CallStack.addCallStack(cast<MDNode>(MIB));
bool MemprofMDAttached = CallStack.buildAndAttachMIBMetadata(CI);
@@ -848,7 +849,8 @@ static void updateMemprofMetadata(CallBase *CI,
// the call that was inlined.
static void propagateMemProfHelper(const CallBase *OrigCall,
CallBase *ClonedCall,
- MDNode *InlinedCallsiteMD) {
+ MDNode *InlinedCallsiteMD,
+ OptimizationRemarkEmitter *ORE) {
MDNode *OrigCallsiteMD = ClonedCall->getMetadata(LLVMContext::MD_callsite);
MDNode *ClonedCallsiteMD = nullptr;
// Check if the call originally had callsite metadata, and update it for the
@@ -891,7 +893,7 @@ static void propagateMemProfHelper(const CallBase *OrigCall,
return;
}
if (NewMIBList.size() < OrigMemProfMD->getNumOperands())
- updateMemprofMetadata(ClonedCall, NewMIBList);
+ updateMemprofMetadata(ClonedCall, NewMIBList, ORE);
}
// Update memprof related metadata (!memprof and !callsite) based on the
@@ -902,7 +904,8 @@ static void propagateMemProfHelper(const CallBase *OrigCall,
static void
propagateMemProfMetadata(Function *Callee, CallBase &CB,
bool ContainsMemProfMetadata,
- const ValueMap<const Value *, WeakTrackingVH> &VMap) {
+ const ValueMap<const Value *, WeakTrackingVH> &VMap,
+ OptimizationRemarkEmitter *ORE) {
MDNode *CallsiteMD = CB.getMetadata(LLVMContext::MD_callsite);
// Only need to update if the inlined callsite had callsite metadata, or if
// there was any memprof metadata inlined.
@@ -925,7 +928,7 @@ propagateMemProfMetadata(Function *Callee, CallBase &CB,
removeCallsiteMetadata(ClonedCall);
continue;
}
- propagateMemProfHelper(OrigCall, ClonedCall, CallsiteMD);
+ propagateMemProfHelper(OrigCall, ClonedCall, CallsiteMD, ORE);
}
}
@@ -2473,7 +2476,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
bool MergeAttributes,
AAResults *CalleeAAR,
bool InsertLifetime,
- Function *ForwardVarArgsTo) {
+ Function *ForwardVarArgsTo,
+ OptimizationRemarkEmitter *ORE) {
assert(CB.getParent() && CB.getFunction() && "Instruction not in function!");
// FIXME: we don't inline callbr yet.
@@ -2807,8 +2811,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// inlined function which use the same param.
AddParamAndFnBasicAttributes(CB, VMap, InlinedFunctionInfo);
- propagateMemProfMetadata(CalledFunc, CB,
- InlinedFunctionInfo.ContainsMemProfMetadata, VMap);
+ propagateMemProfMetadata(
+ CalledFunc, CB, InlinedFunctionInfo.ContainsMemProfMetadata, VMap, ORE);
// Propagate metadata on the callsite if necessary.
PropagateCallSiteMetadata(CB, FirstNewBlock, Caller->end());