summaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CloneFunction.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2022-06-30 15:28:10 -0700
committerTeresa Johnson <tejohnson@google.com>2022-09-30 16:46:17 -0700
commit0d7f3464ce0ba3a97df73e08ee0acd4e33adbe9b (patch)
tree245013e305db183adc4610ab8aea7c1ba7b03c5a /llvm/lib/Transforms/Utils/CloneFunction.cpp
parentf9403ca41e5f3dab60cd6e5de26eea65dcab01a4 (diff)
[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), via utilities in MemoryProfileInfo. Depends on D128142. 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 d20d2a2d77d0..2fde87ef7b09 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();