Skip to content

Commit 1d02b3d

Browse files
committed
Cleanup: Factor out common functionality in IRGenDebugInfo.
1 parent 4ec6c62 commit 1d02b3d

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -525,16 +525,11 @@ llvm::DIScope *IRGenDebugInfo::getOrCreateContext(DeclContext *DC) {
525525
// A module may contain multiple files.
526526
return getOrCreateContext(DC->getParent());
527527
case DeclContextKind::GenericTypeDecl: {
528-
auto CachedType = DITypeCache.find(
529-
cast<GenericTypeDecl>(DC)->getDeclaredType().getPointer());
530-
if (CachedType != DITypeCache.end()) {
531-
// Verify that the information still exists.
532-
if (llvm::Metadata *Val = CachedType->second)
533-
return cast<llvm::DIType>(Val);
534-
}
528+
auto *TyDecl = cast<GenericTypeDecl>(DC);
529+
if (auto *DITy = getTypeOrNull(TyDecl->getDeclaredType().getPointer()))
530+
return DITy;
535531

536532
// Create a Forward-declared type.
537-
auto *TyDecl = cast<NominalTypeDecl>(DC);
538533
auto Loc = getDebugLoc(SM, TyDecl);
539534
auto File = getOrCreateFile(Loc.Filename);
540535
auto Line = Loc.Line;
@@ -1707,21 +1702,27 @@ static bool canMangle(TypeBase *Ty) {
17071702
}
17081703
}
17091704

1710-
llvm::DIType *IRGenDebugInfo::getOrCreateType(DebugTypeInfo DbgTy) {
1711-
// Is this an empty type?
1712-
if (DbgTy.isNull())
1713-
// We can't use the empty type as an index into DenseMap.
1714-
return createType(DbgTy, "", TheCU, MainFile);
1715-
1716-
// Look in the cache first.
1717-
auto CachedType = DITypeCache.find(DbgTy.getType());
1705+
llvm::DIType *IRGenDebugInfo::getTypeOrNull(TypeBase *Ty) {
1706+
auto CachedType = DITypeCache.find(Ty);
17181707
if (CachedType != DITypeCache.end()) {
17191708
// Verify that the information still exists.
17201709
if (llvm::Metadata *Val = CachedType->second) {
17211710
auto DITy = cast<llvm::DIType>(Val);
17221711
return DITy;
17231712
}
17241713
}
1714+
return nullptr;
1715+
}
1716+
1717+
llvm::DIType *IRGenDebugInfo::getOrCreateType(DebugTypeInfo DbgTy) {
1718+
// Is this an empty type?
1719+
if (DbgTy.isNull())
1720+
// We can't use the empty type as an index into DenseMap.
1721+
return createType(DbgTy, "", TheCU, MainFile);
1722+
1723+
// Look in the cache first.
1724+
if (auto *DITy = getTypeOrNull(DbgTy.getType()))
1725+
return DITy;
17251726

17261727
// Second line of defense: Look up the mangled name. TypeBase*'s are
17271728
// not necessarily unique, but name mangling is too expensive to do

lib/IRGen/IRGenDebugInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ class IRGenDebugInfo {
213213
/// local reference to the type.
214214
llvm::DIType *createType(DebugTypeInfo DbgTy, StringRef MangledName,
215215
llvm::DIScope *Scope, llvm::DIFile *File);
216+
/// Get a previously created type from the cache.
217+
llvm::DIType *getTypeOrNull(TypeBase *Ty);
216218
/// Get the DIType corresponding to this DebugTypeInfo from the cache,
217219
/// or build a fresh DIType otherwise. There is the underlying
218220
/// assumption that no two types that share the same canonical type

0 commit comments

Comments
 (0)