Skip to content

Commit d5f6bef

Browse files
Merge pull request #78965 from adrian-prantl/remove-fragmenttype
[Debug Info] Remove the mostly unused FragmentStorageType from DebugTypeInfo
2 parents 76de7ec + e70a344 commit d5f6bef

14 files changed

+108
-143
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 24 additions & 36 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;
@@ -193,23 +179,25 @@ TypeDecl *DebugTypeInfo::getDecl() const {
193179
return nullptr;
194180
}
195181

182+
bool DebugTypeInfo::isForwardDecl() const {
183+
return isNull() || (!isa<TypeAliasType>(getType()));
184+
}
185+
196186
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
197187
LLVM_DUMP_METHOD void DebugTypeInfo::dump() const {
198188
llvm::errs() << "[";
199189
llvm::errs() << "Alignment " << Align.getValue() << "] ";
200190
if (auto *Type = getType())
201191
Type->dump(llvm::errs());
202192

203-
if (FragmentStorageType) {
204-
llvm::errs() << "FragmentStorageType=";
205-
FragmentStorageType->dump();
206-
} else
193+
if (isForwardDecl())
207194
llvm::errs() << "forward-declared\n";
208195
}
209196
#endif
210197

211198
std::optional<CompletedDebugTypeInfo>
212-
CompletedDebugTypeInfo::getFromTypeInfo(swift::Type Ty, const TypeInfo &Info, IRGenModule &IGM) {
199+
CompletedDebugTypeInfo::getFromTypeInfo(swift::Type Ty, const TypeInfo &Info,
200+
IRGenModule &IGM) {
213201
auto *StorageType = IGM.getStorageTypeForUnlowered(Ty);
214202
std::optional<uint64_t> SizeInBits;
215203
if (StorageType->isSized())

lib/IRGen/DebugTypeInfo.h

Lines changed: 10 additions & 16 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,10 +95,9 @@ class DebugTypeInfo {
10095
return false;
10196
}
10297

103-
llvm::Type *getFragmentStorageType() const { return FragmentStorageType; }
10498
Alignment getAlignment() const { return Align; }
105-
bool isNull() const { return Type == nullptr; }
106-
bool isForwardDecl() const { return FragmentStorageType == nullptr; }
99+
bool isNull() const { return !Type; }
100+
bool isForwardDecl() const;
107101
bool isMetadataType() const { return IsMetadataType; }
108102
bool hasDefaultAlignment() const { return DefaultAlignment; }
109103
bool isFixedBuffer() const { return IsFixedBuffer; }
@@ -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
}
@@ -4766,8 +4765,8 @@ Address IRGenModule::getAddrOfObjCClassRef(ClassDecl *theClass) {
47664765
assert(ObjCInterop && "getting address of ObjC class ref in no-interop mode");
47674766

47684767
LinkEntity entity = LinkEntity::forObjCClassRef(theClass);
4769-
auto DbgTy = DebugTypeInfo::getObjCClass(
4770-
theClass, ObjCClassPtrTy, getPointerSize(), getPointerAlignment());
4768+
auto DbgTy = DebugTypeInfo::getObjCClass(theClass, getPointerSize(),
4769+
getPointerAlignment());
47714770
auto addr = getAddrOfLLVMVariable(entity, ConstantInit(), DbgTy);
47724771

47734772
// Define it lazily.
@@ -4792,8 +4791,8 @@ llvm::Constant *IRGenModule::getAddrOfObjCClass(ClassDecl *theClass,
47924791
assert(ObjCInterop && "getting address of ObjC class in no-interop mode");
47934792
assert(!theClass->isForeign());
47944793
LinkEntity entity = LinkEntity::forObjCClass(theClass);
4795-
auto DbgTy = DebugTypeInfo::getObjCClass(
4796-
theClass, ObjCClassPtrTy, getPointerSize(), getPointerAlignment());
4794+
auto DbgTy = DebugTypeInfo::getObjCClass(theClass, getPointerSize(),
4795+
getPointerAlignment());
47974796
auto addr = getAddrOfLLVMVariable(entity, forDefinition, DbgTy);
47984797
return addr;
47994798
}
@@ -4812,8 +4811,8 @@ IRGenModule::getAddrOfMetaclassObject(ClassDecl *decl,
48124811
? LinkEntity::forObjCMetaclass(decl)
48134812
: LinkEntity::forSwiftMetaclassStub(decl);
48144813

4815-
auto DbgTy = DebugTypeInfo::getObjCClass(
4816-
decl, ObjCClassPtrTy, getPointerSize(), getPointerAlignment());
4814+
auto DbgTy = DebugTypeInfo::getObjCClass(decl, getPointerSize(),
4815+
getPointerAlignment());
48174816
auto addr = getAddrOfLLVMVariable(entity, forDefinition, DbgTy);
48184817
return addr;
48194818
}
@@ -4828,8 +4827,8 @@ IRGenModule::getAddrOfCanonicalSpecializedGenericMetaclassObject(
48284827
auto entity =
48294828
LinkEntity::forSpecializedGenericSwiftMetaclassStub(concreteType);
48304829

4831-
auto DbgTy = DebugTypeInfo::getObjCClass(
4832-
theClass, ObjCClassPtrTy, getPointerSize(), getPointerAlignment());
4830+
auto DbgTy = DebugTypeInfo::getObjCClass(theClass, getPointerSize(),
4831+
getPointerAlignment());
48334832
auto addr = getAddrOfLLVMVariable(entity, forDefinition, DbgTy);
48344833
return addr;
48354834
}
@@ -5177,10 +5176,8 @@ llvm::GlobalValue *IRGenModule::defineTypeMetadata(
51775176
TypeMetadataAddress::AddressPoint);
51785177
}
51795178

5180-
auto DbgTy = DebugTypeInfo::getGlobalMetadata(
5181-
MetatypeType::get(concreteType),
5182-
entity.getDefaultDeclarationType(*this)->getPointerTo(), Size(0),
5183-
Alignment(1));
5179+
auto DbgTy = DebugTypeInfo::getGlobalMetadata(MetatypeType::get(concreteType),
5180+
Size(0), Alignment(1));
51845181

51855182
// Define the variable.
51865183
llvm::GlobalVariable *var = cast<llvm::GlobalVariable>(
@@ -5344,7 +5341,6 @@ IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
53445341
break;
53455342
}
53465343
DbgTy = DebugTypeInfo::getGlobalMetadata(MetatypeType::get(concreteType),
5347-
defaultVarTy->getPointerTo(),
53485344
Size(0), Alignment(1));
53495345

53505346
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)