Skip to content

Commit e70a344

Browse files
committed
[Debug Info] Remove the mostly unused FragmentType from DebugTypeInfo
This cleanup allows for more consistent debug info emission since we depend less on IRGen magic to emit debug info for types.
1 parent 266fa2a commit e70a344

14 files changed

+102
-142
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
using namespace swift;
2727
using namespace irgen;
2828

29-
DebugTypeInfo::DebugTypeInfo(swift::Type Ty, llvm::Type *FragmentStorageTy,
30-
Alignment Align, bool HasDefaultAlignment,
31-
bool IsMetadata, bool IsFixedBuffer,
29+
DebugTypeInfo::DebugTypeInfo(swift::Type Ty, Alignment Align,
30+
bool HasDefaultAlignment, bool IsMetadata,
31+
bool IsFixedBuffer,
3232
std::optional<uint32_t> NumExtraInhabitants)
33-
: Type(Ty.getPointer()), FragmentStorageType(FragmentStorageTy),
34-
NumExtraInhabitants(NumExtraInhabitants),
33+
: Type(Ty.getPointer()), NumExtraInhabitants(NumExtraInhabitants),
3534
Align(Align), DefaultAlignment(HasDefaultAlignment),
3635
IsMetadataType(IsMetadata), IsFixedBuffer(IsFixedBuffer) {
3736
assert(Align.getValue() != 0);
@@ -49,15 +48,14 @@ static bool hasDefaultAlignment(swift::Type Ty) {
4948

5049
DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty, const TypeInfo &TI,
5150
IRGenModule &IGM) {
52-
llvm::Type *StorageType = TI.getStorageType();
5351
std::optional<uint32_t> NumExtraInhabitants;
5452
if (TI.isFixedSize()) {
5553
const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&TI);
5654
NumExtraInhabitants = FixTy.getFixedExtraInhabitantCount(IGM);
5755
}
5856
assert(TI.getStorageType() && "StorageType is a nullptr");
59-
return DebugTypeInfo(Ty.getPointer(), StorageType,
60-
TI.getBestKnownAlignment(), ::hasDefaultAlignment(Ty),
57+
return DebugTypeInfo(Ty.getPointer(), TI.getBestKnownAlignment(),
58+
::hasDefaultAlignment(Ty),
6159
/* IsMetadataType = */ false,
6260
/* IsFixedBuffer = */ false, NumExtraInhabitants);
6361
}
@@ -81,25 +79,21 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
8179
return getFromTypeInfo(Type, Info, IGM);
8280
}
8381

84-
DebugTypeInfo DebugTypeInfo::getGlobalMetadata(swift::Type Ty,
85-
llvm::Type *StorageTy, Size size,
82+
DebugTypeInfo DebugTypeInfo::getGlobalMetadata(swift::Type Ty, Size size,
8683
Alignment align) {
87-
DebugTypeInfo DbgTy(Ty.getPointer(), StorageTy, align,
84+
DebugTypeInfo DbgTy(Ty.getPointer(), align,
8885
/* HasDefaultAlignment = */ true,
8986
/* IsMetadataType = */ false);
90-
assert(StorageTy && "StorageType is a nullptr");
9187
assert(!DbgTy.isContextArchetype() &&
9288
"type metadata cannot contain an archetype");
9389
return DbgTy;
9490
}
9591

96-
DebugTypeInfo DebugTypeInfo::getTypeMetadata(swift::Type Ty,
97-
llvm::Type *StorageTy, Size size,
92+
DebugTypeInfo DebugTypeInfo::getTypeMetadata(swift::Type Ty, Size size,
9893
Alignment align) {
99-
DebugTypeInfo DbgTy(Ty.getPointer(), StorageTy, align,
94+
DebugTypeInfo DbgTy(Ty.getPointer(), align,
10095
/* HasDefaultAlignment = */ true,
10196
/* IsMetadataType = */ true);
102-
assert(StorageTy && "StorageType is a nullptr");
10397
assert(!DbgTy.isContextArchetype() &&
10498
"type metadata cannot contain an archetype");
10599
return DbgTy;
@@ -111,7 +105,6 @@ DebugTypeInfo DebugTypeInfo::getForwardDecl(swift::Type Ty) {
111105
}
112106

113107
DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
114-
llvm::Type *FragmentStorageType,
115108
IRGenModule &IGM) {
116109
// Prefer the original, potentially sugared version of the type if
117110
// the type hasn't been mucked with by an optimization pass.
@@ -124,16 +117,14 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
124117
}
125118
auto &TI = IGM.getTypeInfoForUnlowered(Type);
126119
DebugTypeInfo DbgTy = getFromTypeInfo(Type, TI, IGM);
127-
assert(FragmentStorageType && "FragmentStorageType is a nullptr");
128120
assert(!DbgTy.isContextArchetype() &&
129121
"type of global variable cannot be an archetype");
130122
return DbgTy;
131123
}
132124

133-
DebugTypeInfo
134-
DebugTypeInfo::getGlobalFixedBuffer(SILGlobalVariable *GV,
135-
llvm::Type *FragmentStorageType,
136-
Size SizeInBytes, Alignment Align) {
125+
DebugTypeInfo DebugTypeInfo::getGlobalFixedBuffer(SILGlobalVariable *GV,
126+
Size SizeInBytes,
127+
Alignment Align) {
137128
// Prefer the original, potentially sugared version of the type if
138129
// the type hasn't been mucked with by an optimization pass.
139130
auto LowTy = GV->getLoweredType().getASTType();
@@ -143,23 +134,18 @@ DebugTypeInfo::getGlobalFixedBuffer(SILGlobalVariable *GV,
143134
if (DeclType->isEqual(LowTy))
144135
Type = DeclType.getPointer();
145136
}
146-
DebugTypeInfo DbgTy(Type, FragmentStorageType,
147-
Align, ::hasDefaultAlignment(Type),
137+
DebugTypeInfo DbgTy(Type, Align, ::hasDefaultAlignment(Type),
148138
/* IsMetadataType = */ false, /* IsFixedBuffer = */ true);
149-
assert(FragmentStorageType && "FragmentStorageType is a nullptr");
150139
assert(!DbgTy.isContextArchetype() &&
151140
"type of global variable cannot be an archetype");
152141
return DbgTy;
153142
}
154143

155-
DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass,
156-
llvm::Type *FragmentStorageType,
157-
Size SizeInBytes, Alignment align) {
158-
DebugTypeInfo DbgTy(theClass->getInterfaceType().getPointer(),
159-
FragmentStorageType, align,
144+
DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass, Size SizeInBytes,
145+
Alignment align) {
146+
DebugTypeInfo DbgTy(theClass->getInterfaceType().getPointer(), align,
160147
/* HasDefaultAlignment = */ true,
161148
/* IsMetadataType = */ false);
162-
assert(FragmentStorageType && "FragmentStorageType is a nullptr");
163149
assert(!DbgTy.isContextArchetype() &&
164150
"type of objc class cannot be an archetype");
165151
return DbgTy;
@@ -194,7 +180,7 @@ TypeDecl *DebugTypeInfo::getDecl() const {
194180
}
195181

196182
bool DebugTypeInfo::isForwardDecl() const {
197-
return isNull() || (!FragmentStorageType && !isa<TypeAliasType>(getType()));
183+
return isNull() || (!isa<TypeAliasType>(getType()));
198184
}
199185

200186
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -204,17 +190,14 @@ LLVM_DUMP_METHOD void DebugTypeInfo::dump() const {
204190
if (auto *Type = getType())
205191
Type->dump(llvm::errs());
206192

207-
if (FragmentStorageType) {
208-
llvm::errs() << "FragmentStorageType=";
209-
FragmentStorageType->dump();
210-
}
211193
if (isForwardDecl())
212194
llvm::errs() << "forward-declared\n";
213195
}
214196
#endif
215197

216198
std::optional<CompletedDebugTypeInfo>
217-
CompletedDebugTypeInfo::getFromTypeInfo(swift::Type Ty, const TypeInfo &Info, IRGenModule &IGM) {
199+
CompletedDebugTypeInfo::getFromTypeInfo(swift::Type Ty, const TypeInfo &Info,
200+
IRGenModule &IGM) {
218201
auto *StorageType = IGM.getStorageTypeForUnlowered(Ty);
219202
std::optional<uint64_t> SizeInBits;
220203
if (StorageType->isSized())

lib/IRGen/DebugTypeInfo.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class DebugTypeInfo {
4343
TypeBase *Type = nullptr;
4444
/// Needed to determine the size of basic types and to determine
4545
/// the storage type for undefined variables.
46-
llvm::Type *FragmentStorageType = nullptr;
4746
std::optional<uint32_t> NumExtraInhabitants;
4847
Alignment Align;
4948
bool DefaultAlignment = true;
@@ -52,8 +51,7 @@ class DebugTypeInfo {
5251

5352
public:
5453
DebugTypeInfo() = default;
55-
DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy = nullptr,
56-
Alignment AlignInBytes = Alignment(1),
54+
DebugTypeInfo(swift::Type Ty, Alignment AlignInBytes = Alignment(1),
5755
bool HasDefaultAlignment = true, bool IsMetadataType = false,
5856
bool IsFixedBuffer = false,
5957
std::optional<uint32_t> NumExtraInhabitants = {});
@@ -62,11 +60,11 @@ class DebugTypeInfo {
6260
static DebugTypeInfo getLocalVariable(VarDecl *Decl, swift::Type Ty,
6361
const TypeInfo &Info, IRGenModule &IGM);
6462
/// Create type for global type metadata.
65-
static DebugTypeInfo getGlobalMetadata(swift::Type Ty, llvm::Type *StorageTy,
66-
Size size, Alignment align);
63+
static DebugTypeInfo getGlobalMetadata(swift::Type Ty, Size size,
64+
Alignment align);
6765
/// Create type for an artificial metadata variable.
68-
static DebugTypeInfo getTypeMetadata(swift::Type Ty, llvm::Type *StorageTy,
69-
Size size, Alignment align);
66+
static DebugTypeInfo getTypeMetadata(swift::Type Ty, Size size,
67+
Alignment align);
7068

7169
/// Create a forward declaration for a type whose size is unknown.
7270
static DebugTypeInfo getForwardDecl(swift::Type Ty);
@@ -75,14 +73,11 @@ class DebugTypeInfo {
7573
static DebugTypeInfo getFromTypeInfo(swift::Type Ty, const TypeInfo &Info,
7674
IRGenModule &IGM);
7775
/// Global variables.
78-
static DebugTypeInfo getGlobal(SILGlobalVariable *GV,
79-
llvm::Type *StorageType, IRGenModule &IGM);
76+
static DebugTypeInfo getGlobal(SILGlobalVariable *GV, IRGenModule &IGM);
8077
static DebugTypeInfo getGlobalFixedBuffer(SILGlobalVariable *GV,
81-
llvm::Type *StorageType,
8278
Size SizeInBytes, Alignment align);
8379
/// ObjC classes.
84-
static DebugTypeInfo getObjCClass(ClassDecl *theClass,
85-
llvm::Type *StorageType, Size size,
80+
static DebugTypeInfo getObjCClass(ClassDecl *theClass, Size size,
8681
Alignment align);
8782
/// Error type.
8883
static DebugTypeInfo getErrorResult(swift::Type Ty, IRGenModule &IGM);
@@ -100,7 +95,6 @@ class DebugTypeInfo {
10095
return false;
10196
}
10297

103-
llvm::Type *getFragmentStorageType() const { return FragmentStorageType; }
10498
Alignment getAlignment() const { return Align; }
10599
bool isNull() const { return !Type; }
106100
bool isForwardDecl() const;
@@ -151,7 +145,7 @@ template <> struct DenseMapInfo<swift::irgen::DebugTypeInfo> {
151145
}
152146
static swift::irgen::DebugTypeInfo getTombstoneKey() {
153147
return swift::irgen::DebugTypeInfo(
154-
llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey(), nullptr,
148+
llvm::DenseMapInfo<swift::TypeBase *>::getTombstoneKey(),
155149
swift::irgen::Alignment(), /* HasDefaultAlignment = */ false);
156150
}
157151
static unsigned getHashValue(swift::irgen::DebugTypeInfo Val) {

lib/IRGen/GenDecl.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,10 +2741,9 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
27412741
}
27422742

27432743
DebugTypeInfo DbgTy =
2744-
inFixedBuffer
2745-
? DebugTypeInfo::getGlobalFixedBuffer(
2746-
var, globalTy, fixedSize, fixedAlignment)
2747-
: DebugTypeInfo::getGlobal(var, globalTy, *this);
2744+
inFixedBuffer ? DebugTypeInfo::getGlobalFixedBuffer(var, fixedSize,
2745+
fixedAlignment)
2746+
: DebugTypeInfo::getGlobal(var, *this);
27482747

27492748
gvar = createVariable(*this, link, globalTy, fixedAlignment, DbgTy, loc, name);
27502749
}
@@ -4738,8 +4737,8 @@ Address IRGenModule::getAddrOfObjCClassRef(ClassDecl *theClass) {
47384737
assert(ObjCInterop && "getting address of ObjC class ref in no-interop mode");
47394738

47404739
LinkEntity entity = LinkEntity::forObjCClassRef(theClass);
4741-
auto DbgTy = DebugTypeInfo::getObjCClass(
4742-
theClass, ObjCClassPtrTy, getPointerSize(), getPointerAlignment());
4740+
auto DbgTy = DebugTypeInfo::getObjCClass(theClass, getPointerSize(),
4741+
getPointerAlignment());
47434742
auto addr = getAddrOfLLVMVariable(entity, ConstantInit(), DbgTy);
47444743

47454744
// Define it lazily.
@@ -4764,8 +4763,8 @@ llvm::Constant *IRGenModule::getAddrOfObjCClass(ClassDecl *theClass,
47644763
assert(ObjCInterop && "getting address of ObjC class in no-interop mode");
47654764
assert(!theClass->isForeign());
47664765
LinkEntity entity = LinkEntity::forObjCClass(theClass);
4767-
auto DbgTy = DebugTypeInfo::getObjCClass(
4768-
theClass, ObjCClassPtrTy, getPointerSize(), getPointerAlignment());
4766+
auto DbgTy = DebugTypeInfo::getObjCClass(theClass, getPointerSize(),
4767+
getPointerAlignment());
47694768
auto addr = getAddrOfLLVMVariable(entity, forDefinition, DbgTy);
47704769
return addr;
47714770
}
@@ -4784,8 +4783,8 @@ IRGenModule::getAddrOfMetaclassObject(ClassDecl *decl,
47844783
? LinkEntity::forObjCMetaclass(decl)
47854784
: LinkEntity::forSwiftMetaclassStub(decl);
47864785

4787-
auto DbgTy = DebugTypeInfo::getObjCClass(
4788-
decl, ObjCClassPtrTy, getPointerSize(), getPointerAlignment());
4786+
auto DbgTy = DebugTypeInfo::getObjCClass(decl, getPointerSize(),
4787+
getPointerAlignment());
47894788
auto addr = getAddrOfLLVMVariable(entity, forDefinition, DbgTy);
47904789
return addr;
47914790
}
@@ -4800,8 +4799,8 @@ IRGenModule::getAddrOfCanonicalSpecializedGenericMetaclassObject(
48004799
auto entity =
48014800
LinkEntity::forSpecializedGenericSwiftMetaclassStub(concreteType);
48024801

4803-
auto DbgTy = DebugTypeInfo::getObjCClass(
4804-
theClass, ObjCClassPtrTy, getPointerSize(), getPointerAlignment());
4802+
auto DbgTy = DebugTypeInfo::getObjCClass(theClass, getPointerSize(),
4803+
getPointerAlignment());
48054804
auto addr = getAddrOfLLVMVariable(entity, forDefinition, DbgTy);
48064805
return addr;
48074806
}
@@ -5149,10 +5148,8 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(
51495148
TypeMetadataAddress::AddressPoint);
51505149
}
51515150

5152-
auto DbgTy = DebugTypeInfo::getGlobalMetadata(
5153-
MetatypeType::get(concreteType),
5154-
entity.getDefaultDeclarationType(*this)->getPointerTo(), Size(0),
5155-
Alignment(1));
5151+
auto DbgTy = DebugTypeInfo::getGlobalMetadata(MetatypeType::get(concreteType),
5152+
Size(0), Alignment(1));
51565153

51575154
// Define the variable.
51585155
llvm::GlobalVariable *var = cast<llvm::GlobalVariable>(
@@ -5316,7 +5313,6 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
53165313
break;
53175314
}
53185315
DbgTy = DebugTypeInfo::getGlobalMetadata(MetatypeType::get(concreteType),
5319-
defaultVarTy->getPointerTo(),
53205316
Size(0), Alignment(1));
53215317

53225318
ConstantReference addr;

lib/IRGen/GenInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void IRGenModule::emitSILGlobalVariable(SILGlobalVariable *var) {
4444
// variable directly, don't actually emit it; just return undef.
4545
if (ti.isKnownEmpty(expansion)) {
4646
if (DebugInfo && var->getDecl()) {
47-
auto DbgTy = DebugTypeInfo::getGlobal(var, Int8Ty, *this);
47+
auto DbgTy = DebugTypeInfo::getGlobal(var, *this);
4848
DebugInfo->emitGlobalVariableDeclaration(nullptr, var->getDecl()->getName().str(),
4949
"", DbgTy,
5050
var->getLinkage() != SILLinkage::Public &&

0 commit comments

Comments
 (0)