@@ -1124,12 +1124,16 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1124
1124
unsigned SizeInBits, unsigned AlignInBits, llvm::DINode::DIFlags Flags,
1125
1125
StringRef MangledName, StringRef Name) {
1126
1126
#ifndef NDEBUG
1127
- if (MangledName.empty ())
1128
- assert (!Name.empty () &&
1129
- " no mangled name and no human readable name given" );
1130
- else
1131
- assert (swift::Demangle::isMangledName (MangledName) &&
1132
- " UID is not a mangled name" );
1127
+ {
1128
+ if (MangledName.empty ())
1129
+ assert (!Name.empty () &&
1130
+ " no mangled name and no human readable name given" );
1131
+ else
1132
+ assert (swift::Demangle::isMangledName (MangledName) &&
1133
+ " UID is not a mangled name" );
1134
+ auto UID = llvm::MDString::get (IGM.getLLVMContext (), MangledName);
1135
+ assert (DIRefMap.count (UID) == 0 && " type is already cached" );
1136
+ }
1133
1137
#endif
1134
1138
auto ReplaceableType = DBuilder.createReplaceableCompositeType (
1135
1139
llvm::dwarf::DW_TAG_structure_type, " " , Scope, File, Line,
@@ -1236,14 +1240,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1236
1240
SmallVector<llvm::Metadata *, 16 > Members;
1237
1241
for (auto &Member : MemberTypes) {
1238
1242
unsigned OffsetInBits = 0 ;
1239
- Members. push_back ( createMemberType (Member.DIType , Member.Name ,
1243
+ auto *member = createMemberType (Member.DIType , Member.Name ,
1240
1244
OffsetInBits, Member.AlignInBits ,
1241
- Scope, File, Flags));
1245
+ Scope, File, Flags);
1246
+ member->dump ();
1247
+ Members.push_back (member);
1242
1248
}
1243
1249
1244
1250
llvm::DICompositeType *DITy = DBuilder.createStructType (
1245
1251
Scope, Name, File, Line, SizeInBits, AlignInBits, Flags, DerivedFrom,
1246
1252
DBuilder.getOrCreateArray (Members), RuntimeLang, nullptr , UniqueID);
1253
+ DITy->dump ();
1247
1254
return DBuilder.replaceTemporary (std::move (FwdDecl), DITy);
1248
1255
}
1249
1256
@@ -1313,20 +1320,15 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1313
1320
if (!Decl)
1314
1321
return nullptr ;
1315
1322
1316
- // This temporary forward decl seems to be redundant. Can it be removed?
1317
- StringRef Name = Decl->getName ().str ();
1318
- auto FwdDecl = createTemporaryReplaceableForwardDecl (
1319
- Type, Scope, File, Line, SizeInBits, AlignInBits, Flags, MangledName,
1320
- Name);
1321
-
1322
1323
auto [IsUnsubstitued, UnsubstitutedType] =
1323
1324
getUnsubstitutedType (Type, MangledName);
1324
1325
auto UnsubstitutedDbgTy = DebugTypeInfo::getFromTypeInfo (
1325
1326
UnsubstitutedType, IGM.getTypeInfoForUnlowered (UnsubstitutedType), IGM);
1326
- if (IsUnsubstitued)
1327
+ if (IsUnsubstitued) {
1327
1328
return createUnsubstitutedGenericStructOrClassType (
1328
1329
UnsubstitutedDbgTy, Decl, UnsubstitutedType, Scope, File, Line, Flags,
1329
1330
nullptr , llvm::dwarf::DW_LANG_Swift, MangledName);
1331
+ }
1330
1332
1331
1333
// Force the creation of the unsubstituted type, don't create it
1332
1334
// directly so it goes through all the caching/verification logic.
@@ -1361,7 +1363,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1361
1363
Scope, Decl ? Decl->getNameStr () : " " , File, Line, SizeInBits,
1362
1364
AlignInBits, Flags, MangledName, collectGenericParams (Type),
1363
1365
UnsubstitutedDITy);
1364
- return DBuilder. replaceTemporary ( std::move (FwdDecl), SpecializedDITy) ;
1366
+ return SpecializedDITy;
1365
1367
}
1366
1368
1367
1369
// / Create debug information for an enum with a raw type (enum E : Int {}).
@@ -2644,12 +2646,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2644
2646
auto *DITy = cast<llvm::DIType>(CachedTy);
2645
2647
assert (sanityCheckCachedType (DbgTy, DITy));
2646
2648
return DITy;
2649
+ } else {
2650
+ UID = llvm::MDString::get (IGM.getLLVMContext (), Mangled.Canonical );
2651
+ if (llvm::Metadata *CachedTy = DIRefMap.lookup (UID))
2652
+ return cast<llvm::DIType>(CachedTy);
2647
2653
}
2648
2654
}
2649
2655
2650
2656
Scope = updateScope (Scope, DbgTy);
2651
2657
StringRef MangledName =
2652
2658
!Mangled.Sugared .empty () ? Mangled.Sugared : Mangled.Canonical ;
2659
+
2653
2660
StringRef Name = MangledName;
2654
2661
if (auto *Decl = DbgTy.getDecl ())
2655
2662
Name = Decl->getName ().str ();
@@ -2675,7 +2682,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
2675
2682
}
2676
2683
llvm::DIType *DITy = createType (DbgTy, MangledName, Scope, getFile (Scope));
2677
2684
2678
-
2679
2685
if (!shouldCacheDIType (DITy, DbgTy))
2680
2686
return DITy;
2681
2687
0 commit comments