[llvm] 57a0990 - [nfc][DebugInfo] Move subprogram rewriting utility to header
Felipe de Azevedo Piovezan via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 12 06:24:37 PST 2022
Author: Felipe de Azevedo Piovezan
Date: 2022-12-12T09:24:04-05:00
New Revision: 57a0990e61066fb18294d7a461adb9188e82b01d
URL: https://github.com/llvm/llvm-project/commit/57a0990e61066fb18294d7a461adb9188e82b01d
DIFF: https://github.com/llvm/llvm-project/commit/57a0990e61066fb18294d7a461adb9188e82b01d.diff
LOG: [nfc][DebugInfo] Move subprogram rewriting utility to header
This utility will be useful in subsequent patches, as such we expose it
in the DebugInfoMetadata header.
Depends on D139669
Differential Revision: https://reviews.llvm.org/D139670
Added:
Modified:
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/DebugLoc.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index ed2058c95fe78..291916e9782d5 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1579,6 +1579,13 @@ class DILocalScope : public DIScope {
/// chain.
DISubprogram *getSubprogram() const;
+ /// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
+ /// recreating the chain with "NewSP" instead.
+ static DILocalScope *
+ cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP,
+ LLVMContext &Ctx,
+ DenseMap<const MDNode *, MDNode *> &Cache);
+
/// Get the first non DILexicalBlockFile scope of this scope.
///
/// Return this if it's not a \a DILexicalBlockFIle; otherwise, look up the
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 2d220cc133093..1a2bfa83fecdd 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -974,6 +974,35 @@ DILocalScope *DILocalScope::getNonLexicalBlockFileScope() const {
return const_cast<DILocalScope *>(this);
}
+DILocalScope *DILocalScope::cloneScopeForSubprogram(
+ DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx,
+ DenseMap<const MDNode *, MDNode *> &Cache) {
+ SmallVector<DIScope *> ScopeChain;
+ DIScope *CachedResult = nullptr;
+
+ for (DIScope *Scope = &RootScope; !isa<DISubprogram>(Scope);
+ Scope = Scope->getScope()) {
+ if (auto It = Cache.find(Scope); It != Cache.end()) {
+ CachedResult = cast<DIScope>(It->second);
+ break;
+ }
+ ScopeChain.push_back(Scope);
+ }
+
+ // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
+ // cached result).
+ DIScope *UpdatedScope = CachedResult ? CachedResult : &NewSP;
+ for (DIScope *ScopeToUpdate : reverse(ScopeChain)) {
+ TempMDNode ClonedScope = ScopeToUpdate->clone();
+ cast<DILexicalBlockBase>(*ClonedScope).replaceScope(UpdatedScope);
+ UpdatedScope =
+ cast<DIScope>(MDNode::replaceWithUniqued(std::move(ClonedScope)));
+ Cache[ScopeToUpdate] = UpdatedScope;
+ }
+
+ return cast<DILocalScope>(UpdatedScope);
+}
+
DISubprogram::DISPFlags DISubprogram::getFlag(StringRef Flag) {
return StringSwitch<DISPFlags>(Flag)
#define HANDLE_DISP_FLAG(ID, NAME) .Case("DISPFlag" #NAME, SPFlag##NAME)
diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp
index 62230b51e9146..bdea52180f74a 100644
--- a/llvm/lib/IR/DebugLoc.cpp
+++ b/llvm/lib/IR/DebugLoc.cpp
@@ -67,37 +67,6 @@ void DebugLoc::setImplicitCode(bool ImplicitCode) {
}
}
-/// Traverses the scope chain rooted at RootScope until it hits a Subprogram,
-/// recreating the chain with "NewSP" instead.
-static DIScope *
-cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP,
- LLVMContext &Ctx,
- DenseMap<const MDNode *, MDNode *> &Cache) {
- SmallVector<DIScope *> ScopeChain;
- DIScope *CachedResult = nullptr;
-
- for (DIScope *Scope = &RootScope; !isa<DISubprogram>(Scope);
- Scope = Scope->getScope()) {
- if (auto It = Cache.find(Scope); It != Cache.end()) {
- CachedResult = cast<DIScope>(It->second);
- break;
- }
- ScopeChain.push_back(Scope);
- }
-
- // Recreate the scope chain, bottom-up, starting at the new subprogram (or a
- // cached result).
- DIScope *UpdatedScope = CachedResult ? CachedResult : &NewSP;
- for (DIScope *ScopeToUpdate : reverse(ScopeChain)) {
- TempMDNode ClonedScope = ScopeToUpdate->clone();
- cast<DILexicalBlockBase>(*ClonedScope).replaceScope(UpdatedScope);
- UpdatedScope =
- cast<DIScope>(MDNode::replaceWithUniqued(std::move(ClonedScope)));
- Cache[ScopeToUpdate] = UpdatedScope;
- }
- return UpdatedScope;
-}
-
DebugLoc DebugLoc::replaceInlinedAtSubprogram(
const DebugLoc &RootLoc, DISubprogram &NewSP, LLVMContext &Ctx,
DenseMap<const MDNode *, MDNode *> &Cache) {
@@ -119,8 +88,8 @@ DebugLoc DebugLoc::replaceInlinedAtSubprogram(
// If no cache hits, then back() is the end of the inline chain, that is,
// the DILocation whose scope ends in the Subprogram to be replaced.
DILocation *LocToUpdate = LocChain.pop_back_val();
- DIScope *NewScope =
- cloneScopeForSubprogram(*LocToUpdate->getScope(), NewSP, Ctx, Cache);
+ DIScope *NewScope = DILocalScope::cloneScopeForSubprogram(
+ *LocToUpdate->getScope(), NewSP, Ctx, Cache);
UpdatedLoc = DILocation::get(Ctx, LocToUpdate->getLine(),
LocToUpdate->getColumn(), NewScope);
Cache[LocToUpdate] = UpdatedLoc;
More information about the llvm-commits
mailing list