[llvm] 47144a0 - [CloneFunction][DebugInfo] Ensure DILocalVariables of inlined functions are not cloned (NFC) (#138590)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 10:42:00 PDT 2025
Author: Vladislav Dzhidzhoev
Date: 2025-05-14T19:41:56+02:00
New Revision: 47144a0dc1f987981da14c18af9dbf962a6eb9c7
URL: https://github.com/llvm/llvm-project/commit/47144a0dc1f987981da14c18af9dbf962a6eb9c7
DIFF: https://github.com/llvm/llvm-project/commit/47144a0dc1f987981da14c18af9dbf962a6eb9c7.diff
LOG: [CloneFunction][DebugInfo] Ensure DILocalVariables of inlined functions are not cloned (NFC) (#138590)
This change was separated from
https://github.com/llvm/llvm-project/pull/119001.
When cloning functions, use IdentityMDPredicate to ensure that if
DISubprogram is not cloned, then its DILocalVariables are not cloned
either.
This is currently expected to be an NFC, as DILocalVariables only
reference their subprograms (via DILocalScopes) and types, and inlined
DISubprograms and DITypes are not cloned. Thus, DILocalVariables are
mapped to self in ValueMapper (in mapTopLevelUniquedNode).
However, it will be needed for the original PR
https://github.com/llvm/llvm-project/pull/119001, where a
DILocalVariable may refer to a local type of a DISubprogram that is
being cloned. In that case, ValueMapper will clone DILocalVariable even
if it belongs to an inlined DISubprogram that is not cloned, which
should be avoided.
I'm making this change into a separate PR to make the original PR a bit
smaller, and because this has more to do with variables than with types.
Added:
Modified:
llvm/lib/Transforms/Utils/CloneFunction.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 0e0c012a9d676..5487dbef8a434 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -81,17 +81,28 @@ MetadataPredicate createIdentityMDPredicate(const Function &F,
return [](const Metadata *MD) { return false; };
DISubprogram *SPClonedWithinModule = F.getSubprogram();
+
+ // Don't clone inlined subprograms.
+ auto ShouldKeep = [SPClonedWithinModule](const DISubprogram *SP) -> bool {
+ return SP != SPClonedWithinModule;
+ };
+
return [=](const Metadata *MD) {
// Avoid cloning types, compile units, and (other) subprograms.
if (isa<DICompileUnit>(MD) || isa<DIType>(MD))
return true;
if (auto *SP = dyn_cast<DISubprogram>(MD))
- return SP != SPClonedWithinModule;
+ return ShouldKeep(SP);
// If a subprogram isn't going to be cloned skip its lexical blocks as well.
if (auto *LScope = dyn_cast<DILocalScope>(MD))
- return LScope->getSubprogram() != SPClonedWithinModule;
+ return ShouldKeep(LScope->getSubprogram());
+
+ // Avoid cloning local variables of subprograms that won't be cloned.
+ if (auto *DV = dyn_cast<DILocalVariable>(MD))
+ if (auto *S = dyn_cast_or_null<DILocalScope>(DV->getScope()))
+ return ShouldKeep(S->getSubprogram());
return false;
};
More information about the llvm-commits
mailing list