aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CloneFunction.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2022-06-30 14:49:44 -0700
committerTeresa Johnson <tejohnson@google.com>2022-09-30 19:21:15 -0700
commit43417d815937e7d241dd536267a57f0cdcd25c09 (patch)
tree45e67328b6e2d5f65f4e193b396af89afb761899 /llvm/lib/Transforms/Utils/CloneFunction.cpp
parentcefb7aab61e71b7ea7a298e5edff0abdf117bd9a (diff)
downloadllvm-43417d815937e7d241dd536267a57f0cdcd25c09.zip
llvm-43417d815937e7d241dd536267a57f0cdcd25c09.tar.gz
llvm-43417d815937e7d241dd536267a57f0cdcd25c09.tar.bz2
[MemProf] Update metadata during inlining
Update both memprof and callsite metadata to reflect inlined functions. For callsite metadata this is simply a concatenation of each cloned call's call stack with that of the inlined callsite's. For memprof metadata, each profiled memory info block (MIB) is either moved to the cloned allocation call or left on the original allocation call depending on whether its context matches the newly refined call stack context on the cloned call. We also reapply context trimming optimizations based on the refined set of contexts on each of the calls (cloned and original). Depends on D128142. Reviewed By: snehasish Differential Revision: https://reviews.llvm.org/D128143
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CloneFunction.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index d20d2a2..2fde87e 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -46,7 +46,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
if (BB->hasName())
NewBB->setName(BB->getName() + NameSuffix);
- bool hasCalls = false, hasDynamicAllocas = false;
+ bool hasCalls = false, hasDynamicAllocas = false, hasMemProfMetadata = false;
Module *TheModule = F ? F->getParent() : nullptr;
// Loop over all instructions, and copy them over.
@@ -60,7 +60,10 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
NewBB->getInstList().push_back(NewInst);
VMap[&I] = NewInst; // Add instruction map to value.
- hasCalls |= (isa<CallInst>(I) && !I.isDebugOrPseudoInst());
+ if (isa<CallInst>(I) && !I.isDebugOrPseudoInst()) {
+ hasCalls = true;
+ hasMemProfMetadata |= I.hasMetadata(LLVMContext::MD_memprof);
+ }
if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
if (!AI->isStaticAlloca()) {
hasDynamicAllocas = true;
@@ -70,6 +73,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
if (CodeInfo) {
CodeInfo->ContainsCalls |= hasCalls;
+ CodeInfo->ContainsMemProfMetadata |= hasMemProfMetadata;
CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
}
return NewBB;
@@ -471,6 +475,7 @@ void PruningFunctionCloner::CloneBlock(
}
bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
+ bool hasMemProfMetadata = false;
// Loop over all instructions, and copy them over, DCE'ing as we go. This
// loop doesn't include the terminator.
@@ -515,7 +520,10 @@ void PruningFunctionCloner::CloneBlock(
NewInst->setName(II->getName() + NameSuffix);
VMap[&*II] = NewInst; // Add instruction map to value.
NewBB->getInstList().push_back(NewInst);
- hasCalls |= (isa<CallInst>(II) && !II->isDebugOrPseudoInst());
+ if (isa<CallInst>(II) && !II->isDebugOrPseudoInst()) {
+ hasCalls = true;
+ hasMemProfMetadata |= II->hasMetadata(LLVMContext::MD_memprof);
+ }
if (CodeInfo) {
CodeInfo->OrigVMap[&*II] = NewInst;
@@ -589,6 +597,7 @@ void PruningFunctionCloner::CloneBlock(
if (CodeInfo) {
CodeInfo->ContainsCalls |= hasCalls;
+ CodeInfo->ContainsMemProfMetadata |= hasMemProfMetadata;
CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
CodeInfo->ContainsDynamicAllocas |=
hasStaticAllocas && BB != &BB->getParent()->front();