@@ -100,18 +100,27 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
100
100
llvm::DenseSet<ModuleDecl *> ImportedModules;
101
101
102
102
llvm::BumpPtrAllocator DebugInfoNames;
103
- StringRef CWDName; // / The current working directory.
104
- SmallString<0 > ConfigMacros; // / User-provided -D macro definitions.
105
- llvm::DICompileUnit *TheCU = nullptr ; // / The current compilation unit.
106
- llvm::DIFile *MainFile = nullptr ; // / The main file.
107
- llvm::DIModule *MainModule = nullptr ; // / The current module.
108
- llvm::DIScope *EntryPointFn =
109
- nullptr ; // / Scope of SWIFT_ENTRY_POINT_FUNCTION.
110
- TypeAliasDecl *MetadataTypeDecl; // / The type decl for swift.type.
111
- llvm::DIType *InternalType; // / Catch-all type for opaque internal types.
112
-
113
- SILLocation::DebugLoc LastDebugLoc; // / The last location that was emitted.
114
- const SILDebugScope *LastScope; // / The scope of that last location.
103
+ // / The current working directory.
104
+ StringRef CWDName;
105
+ // / User-provided -D macro definitions.
106
+ SmallString<0 > ConfigMacros;
107
+ // / The current compilation unit.
108
+ llvm::DICompileUnit *TheCU = nullptr ;
109
+ // / The main file.
110
+ llvm::DIFile *MainFile = nullptr ;
111
+ // / The current module.
112
+ llvm::DIModule *MainModule = nullptr ;
113
+ // / Scope of SWIFT_ENTRY_POINT_FUNCTION.
114
+ llvm::DIScope *EntryPointFn = nullptr ;
115
+ // / The artificial type decls for named archetypes.
116
+ llvm::StringMap<TypeAliasDecl *> MetadataTypeDeclCache;
117
+ // / Catch-all type for opaque internal types.
118
+ llvm::DIType *InternalType = nullptr ;
119
+
120
+ // / The last location that was emitted.
121
+ SILLocation::DebugLoc LastDebugLoc;
122
+ // / The scope of that last location.
123
+ const SILDebugScope *LastScope = nullptr ;
115
124
116
125
// / Used by pushLoc.
117
126
SmallVector<std::pair<SILLocation::DebugLoc, const SILDebugScope *>, 8 >
@@ -170,7 +179,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
170
179
bool IsLocalToUnit, bool InFixedBuffer,
171
180
Optional<SILLocation> Loc);
172
181
void emitTypeMetadata (IRGenFunction &IGF, llvm::Value *Metadata,
173
- unsigned Depth, unsigned Index, StringRef AssocType);
182
+ unsigned Depth, unsigned Index, StringRef ArchetypeName,
183
+ StringRef AssocType);
174
184
175
185
// / Return the DIBuilder.
176
186
llvm::DIBuilder &getBuilder () { return DBuilder; }
@@ -704,15 +714,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
704
714
return getOrCreateModule (M, TheCU, Name, Path);
705
715
}
706
716
707
- TypeAliasDecl *getMetadataType () {
708
- if (!MetadataTypeDecl) {
709
- MetadataTypeDecl = new (IGM.Context ) TypeAliasDecl (
710
- SourceLoc (), SourceLoc (), IGM.Context .getIdentifier (" $swift.type" ),
711
- SourceLoc (),
712
- /* genericparams*/ nullptr , IGM.Context .TheBuiltinModule );
713
- MetadataTypeDecl->setUnderlyingType (IGM.Context .TheRawPointerType );
714
- }
715
- return MetadataTypeDecl;
717
+ TypeAliasDecl *getMetadataType (StringRef ArchetypeName) {
718
+ TypeAliasDecl *&Entry = MetadataTypeDeclCache[ArchetypeName];
719
+ if (Entry)
720
+ return Entry;
721
+
722
+ SourceLoc NoLoc;
723
+ Entry = new (IGM.Context ) TypeAliasDecl (
724
+ NoLoc, NoLoc, IGM.Context .getIdentifier (ArchetypeName), NoLoc,
725
+ /* genericparams*/ nullptr , IGM.Context .TheBuiltinModule );
726
+ Entry->setUnderlyingType (IGM.Context .TheRawPointerType );
727
+ return Entry;
716
728
}
717
729
718
730
// / Return the DIFile that is the ancestor of Scope.
@@ -765,8 +777,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
765
777
#endif
766
778
767
779
StringRef getMangledName (DebugTypeInfo DbgTy) {
768
- if (MetadataTypeDecl && DbgTy.getDecl () == MetadataTypeDecl)
769
- return BumpAllocatedString (DbgTy.getDecl ()->getName ().str ());
780
+ if (DbgTy.IsMetadataType )
781
+ return MetadataTypeDeclCache.find (DbgTy.getDecl ()->getName ().str ())
782
+ ->getKey ();
770
783
771
784
Type Ty = DbgTy.getType ();
772
785
if (!Ty->hasTypeParameter ())
@@ -925,9 +938,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
925
938
// one of the raw type as long as it is large enough to hold
926
939
// all enum values. Use the raw type for the debug type, but
927
940
// the storage size from the enum.
928
- ElemDbgTy =
929
- DebugTypeInfo (ED->getRawType (),
930
- DbgTy.StorageType , DbgTy.size , DbgTy.align , true );
941
+ ElemDbgTy = DebugTypeInfo (ED->getRawType (), DbgTy.StorageType ,
942
+ DbgTy.size , DbgTy.align , true , false );
931
943
else if (auto ArgTy = ElemDecl->getArgumentInterfaceType ()) {
932
944
// A discriminated union. This should really be described as a
933
945
// DW_TAG_variant_type. For now only describing the data.
@@ -938,8 +950,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
938
950
// Discriminated union case without argument. Fallback to Int
939
951
// as the element type; there is no storage here.
940
952
Type IntTy = IGM.Context .getIntDecl ()->getDeclaredType ();
941
- ElemDbgTy = DebugTypeInfo (
942
- IntTy, DbgTy. StorageType , Size ( 0 ), Alignment (1 ), true );
953
+ ElemDbgTy = DebugTypeInfo (IntTy, DbgTy. StorageType , Size ( 0 ),
954
+ Alignment (1 ), true , false );
943
955
}
944
956
unsigned Offset = 0 ;
945
957
auto MTy = createMemberType (ElemDbgTy, ElemDecl->getName ().str (), Offset,
@@ -979,8 +991,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
979
991
}
980
992
981
993
llvm::DIType *getOrCreateDesugaredType (Type Ty, DebugTypeInfo DbgTy) {
982
- DebugTypeInfo BlandDbgTy (
983
- Ty, DbgTy. StorageType , DbgTy. size , DbgTy.align , DbgTy.DefaultAlignment );
994
+ DebugTypeInfo BlandDbgTy (Ty, DbgTy. StorageType , DbgTy. size , DbgTy. align ,
995
+ DbgTy.DefaultAlignment , DbgTy.IsMetadataType );
984
996
return getOrCreateType (BlandDbgTy);
985
997
}
986
998
@@ -1454,9 +1466,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
1454
1466
auto File = getOrCreateFile (L.Filename );
1455
1467
// For TypeAlias types, the DeclContext for the aliased type is
1456
1468
// in the decl of the alias type.
1457
- DebugTypeInfo AliasedDbgTy (
1458
- AliasedTy ,
1459
- DbgTy. StorageType , DbgTy. size , DbgTy. align , DbgTy. DefaultAlignment );
1469
+ DebugTypeInfo AliasedDbgTy (AliasedTy, DbgTy. StorageType , DbgTy. size ,
1470
+ DbgTy. align , DbgTy. DefaultAlignment ,
1471
+ false );
1460
1472
return DBuilder.createTypedef (getOrCreateType (AliasedDbgTy), MangledName,
1461
1473
File, L.Line , Scope);
1462
1474
}
@@ -1637,8 +1649,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
1637
1649
llvm::Module &M,
1638
1650
StringRef MainOutputFilenameForDebugInfo)
1639
1651
: Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), M(M), DBuilder(M),
1640
- IGM (IGM), DebugPrefixMap(Opts.DebugPrefixMap), MetadataTypeDecl(nullptr ),
1641
- InternalType(nullptr ), LastDebugLoc({}), LastScope(nullptr ) {
1652
+ IGM (IGM), DebugPrefixMap(Opts.DebugPrefixMap) {
1642
1653
assert (Opts.DebugInfoLevel > IRGenDebugInfoLevel::None &&
1643
1654
" no debug info should be generated" );
1644
1655
llvm::SmallString<256 > SourcePath;
@@ -2244,7 +2255,9 @@ void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
2244
2255
2245
2256
void IRGenDebugInfoImpl::emitTypeMetadata (IRGenFunction &IGF,
2246
2257
llvm::Value *Metadata, unsigned Depth,
2247
- unsigned Index, StringRef AssocType) {
2258
+ unsigned Index,
2259
+ StringRef ArchetypeName,
2260
+ StringRef AssocType) {
2248
2261
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::LineTables)
2249
2262
return ;
2250
2263
@@ -2254,11 +2267,11 @@ void IRGenDebugInfoImpl::emitTypeMetadata(IRGenFunction &IGF,
2254
2267
return ;
2255
2268
2256
2269
llvm::SmallString<8 > Buf;
2257
- static const char *Tau = u8" \u03C4 _ " ;
2270
+ static const char *Tau = u8" \u03C4 " ;
2258
2271
llvm::raw_svector_ostream OS (Buf);
2259
- OS << ' $' << Tau << Depth << ' _' << Index << AssocType;
2260
- auto DbgTy = DebugTypeInfo::getMetadata (
2261
- getMetadataType ()->getDeclaredInterfaceType ().getPointer (),
2272
+ OS << ' $' << Tau << ' _ ' << Depth << ' _' << Index << AssocType;
2273
+ auto DbgTy = DebugTypeInfo::getArchetype (
2274
+ getMetadataType (ArchetypeName )->getDeclaredInterfaceType ().getPointer (),
2262
2275
Metadata->getType (), Size (CI.getTargetInfo ().getPointerWidth (0 )),
2263
2276
Alignment (CI.getTargetInfo ().getPointerAlign (0 )));
2264
2277
emitVariableDeclaration (IGF.Builder , Metadata, DbgTy, IGF.getDebugScope (),
@@ -2381,9 +2394,10 @@ void IRGenDebugInfo::emitGlobalVariableDeclaration(
2381
2394
2382
2395
void IRGenDebugInfo::emitTypeMetadata (IRGenFunction &IGF, llvm::Value *Metadata,
2383
2396
unsigned Depth, unsigned Index,
2397
+ StringRef ArchetypeName,
2384
2398
StringRef AssocType) {
2385
2399
static_cast <IRGenDebugInfoImpl *>(this )->emitTypeMetadata (
2386
- IGF, Metadata, Depth, Index, AssocType);
2400
+ IGF, Metadata, Depth, Index, ArchetypeName , AssocType);
2387
2401
}
2388
2402
2389
2403
llvm::DIBuilder &IRGenDebugInfo::getBuilder () {
0 commit comments