@@ -26,16 +26,13 @@ using namespace swift;
2626using namespace irgen ;
2727
2828DebugTypeInfo::DebugTypeInfo (swift::Type Ty, llvm::Type *FragmentStorageTy,
29- std::optional<Size::int_type> SizeInBits,
3029 Alignment Align, bool HasDefaultAlignment,
31- bool IsMetadata, bool SizeIsFragmentSize,
32- bool IsFixedBuffer,
30+ bool IsMetadata, bool IsFixedBuffer,
3331 std::optional<uint32_t > NumExtraInhabitants)
3432 : Type(Ty.getPointer()), FragmentStorageType(FragmentStorageTy),
35- SizeInBits(SizeInBits), NumExtraInhabitants(NumExtraInhabitants),
33+ NumExtraInhabitants(NumExtraInhabitants),
3634 Align(Align), DefaultAlignment(HasDefaultAlignment),
37- IsMetadataType(IsMetadata), SizeIsFragmentSize(SizeIsFragmentSize),
38- IsFixedBuffer(IsFixedBuffer) {
35+ IsMetadataType(IsMetadata), IsFixedBuffer(IsFixedBuffer) {
3936 assert (Align.getValue () != 0 );
4037}
4138
@@ -50,32 +47,23 @@ static bool hasDefaultAlignment(swift::Type Ty) {
5047}
5148
5249DebugTypeInfo DebugTypeInfo::getFromTypeInfo (swift::Type Ty, const TypeInfo &TI,
53- IRGenModule &IGM,
54- bool IsFragmentTypeInfo) {
55- std::optional<Size::int_type> SizeInBits;
50+ IRGenModule &IGM) {
5651 llvm::Type *StorageType = TI.getStorageType ();
5752 std::optional<uint32_t > NumExtraInhabitants;
58- if (StorageType->isSized ())
59- SizeInBits = IGM.DataLayout .getTypeSizeInBits (StorageType);
60- else if (TI.isFixedSize ()) {
61- const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&TI);
62- Size::int_type Size = FixTy.getFixedSize ().getValue () * 8 ;
63- SizeInBits = Size;
64- }
6553 if (TI.isFixedSize ()) {
6654 const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&TI);
6755 NumExtraInhabitants = FixTy.getFixedExtraInhabitantCount (IGM);
6856 }
6957 assert (TI.getStorageType () && " StorageType is a nullptr" );
70- return DebugTypeInfo (Ty.getPointer (), StorageType, SizeInBits,
58+ return DebugTypeInfo (Ty.getPointer (), StorageType,
7159 TI.getBestKnownAlignment (), ::hasDefaultAlignment (Ty),
72- false , IsFragmentTypeInfo, false , NumExtraInhabitants);
60+ /* IsMetadataType = */ false ,
61+ /* IsFixedBuffer = */ false , NumExtraInhabitants);
7362}
7463
7564DebugTypeInfo DebugTypeInfo::getLocalVariable (VarDecl *Decl, swift::Type Ty,
7665 const TypeInfo &Info,
77- IRGenModule &IGM,
78- bool IsFragmentTypeInfo) {
66+ IRGenModule &IGM) {
7967
8068 auto DeclType = Decl->getInterfaceType ();
8169 auto RealType = Ty;
@@ -89,14 +77,15 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
8977 // the type hasn't been mucked with by an optimization pass.
9078 auto *Type = Sugared->isEqual (RealType) ? DeclType.getPointer ()
9179 : RealType.getPointer ();
92- return getFromTypeInfo (Type, Info, IGM, IsFragmentTypeInfo );
80+ return getFromTypeInfo (Type, Info, IGM);
9381}
9482
9583DebugTypeInfo DebugTypeInfo::getGlobalMetadata (swift::Type Ty,
9684 llvm::Type *StorageTy, Size size,
9785 Alignment align) {
98- DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size.getValue () * 8 , align,
99- true , false , false );
86+ DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, align,
87+ /* HasDefaultAlignment = */ true ,
88+ /* IsMetadataType = */ false );
10089 assert (StorageTy && " StorageType is a nullptr" );
10190 assert (!DbgTy.isContextArchetype () &&
10291 " type metadata cannot contain an archetype" );
@@ -106,8 +95,9 @@ DebugTypeInfo DebugTypeInfo::getGlobalMetadata(swift::Type Ty,
10695DebugTypeInfo DebugTypeInfo::getTypeMetadata (swift::Type Ty,
10796 llvm::Type *StorageTy, Size size,
10897 Alignment align) {
109- DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size.getValue () * 8 , align,
110- true , true , false );
98+ DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, align,
99+ /* HasDefaultAlignment = */ true ,
100+ /* IsMetadataType = */ true );
111101 assert (StorageTy && " StorageType is a nullptr" );
112102 assert (!DbgTy.isContextArchetype () &&
113103 " type metadata cannot contain an archetype" );
@@ -132,7 +122,7 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
132122 Type = DeclType.getPointer ();
133123 }
134124 auto &TI = IGM.getTypeInfoForUnlowered (Type);
135- DebugTypeInfo DbgTy = getFromTypeInfo (Type, TI, IGM, false );
125+ DebugTypeInfo DbgTy = getFromTypeInfo (Type, TI, IGM);
136126 assert (FragmentStorageType && " FragmentStorageType is a nullptr" );
137127 assert (!DbgTy.isContextArchetype () &&
138128 " type of global variable cannot be an archetype" );
@@ -152,8 +142,9 @@ DebugTypeInfo::getGlobalFixedBuffer(SILGlobalVariable *GV,
152142 if (DeclType->isEqual (LowTy))
153143 Type = DeclType.getPointer ();
154144 }
155- DebugTypeInfo DbgTy (Type, FragmentStorageType, SizeInBytes.getValue () * 8 ,
156- Align, ::hasDefaultAlignment (Type), false , false , true );
145+ DebugTypeInfo DbgTy (Type, FragmentStorageType,
146+ Align, ::hasDefaultAlignment (Type),
147+ /* IsMetadataType = */ false , /* IsFixedBuffer = */ true );
157148 assert (FragmentStorageType && " FragmentStorageType is a nullptr" );
158149 assert (!DbgTy.isContextArchetype () &&
159150 " type of global variable cannot be an archetype" );
@@ -164,8 +155,9 @@ DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass,
164155 llvm::Type *FragmentStorageType,
165156 Size SizeInBytes, Alignment align) {
166157 DebugTypeInfo DbgTy (theClass->getInterfaceType ().getPointer (),
167- FragmentStorageType, SizeInBytes.getValue () * 8 , align,
168- true , false , false );
158+ FragmentStorageType, align,
159+ /* HasDefaultAlignment = */ true ,
160+ /* IsMetadataType = */ false );
169161 assert (FragmentStorageType && " FragmentStorageType is a nullptr" );
170162 assert (!DbgTy.isContextArchetype () &&
171163 " type of objc class cannot be an archetype" );
@@ -175,13 +167,12 @@ DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass,
175167DebugTypeInfo DebugTypeInfo::getErrorResult (swift::Type Ty,
176168 IRGenModule &IGM) {
177169 auto &TI = IGM.getTypeInfoForUnlowered (Ty);
178- DebugTypeInfo DbgTy = getFromTypeInfo (Ty, TI, IGM, false );
170+ DebugTypeInfo DbgTy = getFromTypeInfo (Ty, TI, IGM);
179171 return DbgTy;
180172}
181173
182174bool DebugTypeInfo::operator ==(DebugTypeInfo T) const {
183175 return getType () == T.getType () &&
184- SizeInBits == T.SizeInBits &&
185176 Align == T.Align ;
186177}
187178
@@ -204,8 +195,6 @@ TypeDecl *DebugTypeInfo::getDecl() const {
204195#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
205196LLVM_DUMP_METHOD void DebugTypeInfo::dump () const {
206197 llvm::errs () << " [" ;
207- if (SizeInBits)
208- llvm::errs () << " SizeInBits " << *SizeInBits << " " ;
209198 llvm::errs () << " Alignment " << Align.getValue () << " ] " ;
210199 if (auto *Type = getType ())
211200 Type->dump (llvm::errs ());
@@ -217,3 +206,19 @@ LLVM_DUMP_METHOD void DebugTypeInfo::dump() const {
217206 llvm::errs () << " forward-declared\n " ;
218207}
219208#endif
209+
210+ std::optional<CompletedDebugTypeInfo>
211+ CompletedDebugTypeInfo::getFromTypeInfo (swift::Type Ty, const TypeInfo &Info, IRGenModule &IGM) {
212+ auto *StorageType = IGM.getStorageTypeForUnlowered (Ty);
213+ std::optional<uint64_t > SizeInBits;
214+ if (StorageType->isSized ())
215+ SizeInBits = IGM.DataLayout .getTypeSizeInBits (StorageType);
216+ else if (Info.isFixedSize ()) {
217+ const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&Info);
218+ Size::int_type Size = FixTy.getFixedSize ().getValue () * 8 ;
219+ SizeInBits = Size;
220+ }
221+
222+ return CompletedDebugTypeInfo::get (
223+ DebugTypeInfo::getFromTypeInfo (Ty, Info, IGM), SizeInBits);
224+ }
0 commit comments