Skip to content

Commit 8ef2178

Browse files
committed
Make data members of DebugTypeInfo private (NFC)
1 parent 3bc9d43 commit 8ef2178

File tree

3 files changed

+50
-33
lines changed

3 files changed

+50
-33
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty,
5454
}
5555
assert(Info.getStorageType() && "StorageType is a nullptr");
5656
return DebugTypeInfo(Ty.getPointer(), Info.getStorageType(), size,
57-
Info.getBestKnownAlignment(), hasDefaultAlignment(Ty),
57+
Info.getBestKnownAlignment(), ::hasDefaultAlignment(Ty),
5858
false);
5959
}
6060

@@ -112,7 +112,7 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
112112
if (DeclType->isEqual(LowTy))
113113
Type = DeclType.getPointer();
114114
}
115-
DebugTypeInfo DbgTy(Type, StorageTy, size, align, hasDefaultAlignment(Type),
115+
DebugTypeInfo DbgTy(Type, StorageTy, size, align, ::hasDefaultAlignment(Type),
116116
false);
117117
assert(StorageTy && "StorageType is a nullptr");
118118
assert(!DbgTy.isContextArchetype() &&
@@ -167,6 +167,7 @@ LLVM_DUMP_METHOD void DebugTypeInfo::dump() const {
167167
if (StorageType) {
168168
llvm::errs() << "StorageType=";
169169
StorageType->dump();
170-
}
170+
} else
171+
llvm::errs() << "forward-declared\n";
171172
}
172173
#endif

lib/IRGen/DebugTypeInfo.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class TypeInfo;
3636
/// This data structure holds everything needed to emit debug info
3737
/// for a type.
3838
class DebugTypeInfo {
39-
public:
4039
/// The type we need to emit may be different from the type
4140
/// mentioned in the Decl, for example, stripped of qualifiers.
4241
TypeBase *Type = nullptr;
@@ -48,7 +47,8 @@ class DebugTypeInfo {
4847
bool DefaultAlignment = true;
4948
bool IsMetadataType = false;
5049

51-
DebugTypeInfo() {}
50+
public:
51+
DebugTypeInfo() = default;
5252
DebugTypeInfo(swift::Type Ty, llvm::Type *StorageTy, Size SizeInBytes,
5353
Alignment AlignInBytes, bool HasDefaultAlignment,
5454
bool IsMetadataType);
@@ -91,12 +91,24 @@ class DebugTypeInfo {
9191
return false;
9292
}
9393

94+
llvm::Type *getStorageType() const {
95+
assert((StorageType || size.isZero()) &&
96+
"only defined types may have a size");
97+
return StorageType;
98+
}
99+
Size getSize() const { return size; }
100+
void setSize(Size NewSize) { size = NewSize; }
101+
Alignment getAlignment() const { return align; }
94102
bool isNull() const { return Type == nullptr; }
95103
bool isForwardDecl() const { return StorageType == nullptr; }
104+
bool isMetadataType() const { return IsMetadataType; }
105+
bool hasDefaultAlignment() const { return DefaultAlignment; }
106+
96107
bool operator==(DebugTypeInfo T) const;
97108
bool operator!=(DebugTypeInfo T) const;
98-
99-
void dump() const;
109+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
110+
LLVM_DUMP_METHOD void dump() const;
111+
#endif
100112
};
101113
}
102114
}

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
766766
}
767767

768768
StringRef getMangledName(DebugTypeInfo DbgTy) {
769-
if (DbgTy.IsMetadataType)
769+
if (DbgTy.isMetadataType())
770770
return MetadataTypeDeclCache.find(DbgTy.getDecl()->getName().str())
771771
->getKey();
772772

@@ -830,12 +830,12 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
830830
llvm::DINode::DIFlags Flags) {
831831
unsigned SizeOfByte = CI.getTargetInfo().getCharWidth();
832832
auto *Ty = getOrCreateType(DbgTy);
833-
auto *DITy = DBuilder.createMemberType(Scope, Name, File, 0,
834-
SizeOfByte * DbgTy.size.getValue(),
835-
0, OffsetInBits, Flags, Ty);
833+
auto *DITy = DBuilder.createMemberType(
834+
Scope, Name, File, 0, SizeOfByte * DbgTy.getSize().getValue(), 0,
835+
OffsetInBits, Flags, Ty);
836836
OffsetInBits += getSizeInBits(Ty);
837-
OffsetInBits =
838-
llvm::alignTo(OffsetInBits, SizeOfByte * DbgTy.align.getValue());
837+
OffsetInBits = llvm::alignTo(OffsetInBits,
838+
SizeOfByte * DbgTy.getAlignment().getValue());
839839
return DITy;
840840
}
841841

@@ -930,8 +930,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
930930
// one of the raw type as long as it is large enough to hold
931931
// all enum values. Use the raw type for the debug type, but
932932
// the storage size from the enum.
933-
ElemDbgTy = DebugTypeInfo(ED->getRawType(), DbgTy.StorageType,
934-
DbgTy.size, DbgTy.align, true, false);
933+
ElemDbgTy =
934+
DebugTypeInfo(ED->getRawType(), DbgTy.getStorageType(),
935+
DbgTy.getSize(), DbgTy.getAlignment(), true, false);
935936
else if (auto ArgTy = ElemDecl->getArgumentInterfaceType()) {
936937
// A discriminated union. This should really be described as a
937938
// DW_TAG_variant_type. For now only describing the data.
@@ -942,12 +943,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
942943
// Discriminated union case without argument. Fallback to Int
943944
// as the element type; there is no storage here.
944945
Type IntTy = IGM.Context.getIntDecl()->getDeclaredType();
945-
ElemDbgTy = DebugTypeInfo(IntTy, DbgTy.StorageType, Size(0),
946+
ElemDbgTy = DebugTypeInfo(IntTy, DbgTy.getStorageType(), Size(0),
946947
Alignment(1), true, false);
947948
}
948949
unsigned Offset = 0;
949-
auto MTy = createMemberType(ElemDbgTy, ElemDecl->getBaseIdentifier().str(),
950-
Offset, Scope, File, Flags);
950+
auto MTy =
951+
createMemberType(ElemDbgTy, ElemDecl->getBaseIdentifier().str(),
952+
Offset, Scope, File, Flags);
951953
Elements.push_back(MTy);
952954
}
953955
return DBuilder.getOrCreateArray(Elements);
@@ -959,7 +961,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
959961
llvm::DIFile *File, unsigned Line,
960962
llvm::DINode::DIFlags Flags) {
961963
unsigned SizeOfByte = CI.getTargetInfo().getCharWidth();
962-
unsigned SizeInBits = DbgTy.size.getValue() * SizeOfByte;
964+
unsigned SizeInBits = DbgTy.getSize().getValue() * SizeOfByte;
963965
// Default, since Swift doesn't allow specifying a custom alignment.
964966
unsigned AlignInBits = 0;
965967

@@ -983,16 +985,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
983985
}
984986

985987
llvm::DIType *getOrCreateDesugaredType(Type Ty, DebugTypeInfo DbgTy) {
986-
DebugTypeInfo BlandDbgTy(Ty, DbgTy.StorageType, DbgTy.size, DbgTy.align,
987-
DbgTy.DefaultAlignment, DbgTy.IsMetadataType);
988+
DebugTypeInfo BlandDbgTy(Ty, DbgTy.getStorageType(), DbgTy.getSize(),
989+
DbgTy.getAlignment(), DbgTy.hasDefaultAlignment(),
990+
DbgTy.isMetadataType());
988991
return getOrCreateType(BlandDbgTy);
989992
}
990993

991994
uint64_t getSizeOfBasicType(DebugTypeInfo DbgTy) {
992995
uint64_t SizeOfByte = CI.getTargetInfo().getCharWidth();
993-
uint64_t BitWidth = DbgTy.size.getValue() * SizeOfByte;
994-
llvm::Type *StorageType = DbgTy.StorageType
995-
? DbgTy.StorageType
996+
uint64_t BitWidth = DbgTy.getSize().getValue() * SizeOfByte;
997+
llvm::Type *StorageType = DbgTy.getStorageType()
998+
? DbgTy.getStorageType()
996999
: IGM.DataLayout.getSmallestLegalIntType(
9971000
IGM.getLLVMContext(), BitWidth);
9981001

@@ -1210,9 +1213,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
12101213
// emitting the storage size of the struct, but it may be necessary
12111214
// to emit the (target!) size of the underlying basic type.
12121215
uint64_t SizeOfByte = CI.getTargetInfo().getCharWidth();
1213-
uint64_t SizeInBits = DbgTy.size.getValue() * SizeOfByte;
1214-
unsigned AlignInBits =
1215-
DbgTy.DefaultAlignment ? 0 : DbgTy.align.getValue() * SizeOfByte;
1216+
uint64_t SizeInBits = DbgTy.getSize().getValue() * SizeOfByte;
1217+
unsigned AlignInBits = DbgTy.hasDefaultAlignment()
1218+
? 0
1219+
: DbgTy.getAlignment().getValue() * SizeOfByte;
12161220
unsigned Encoding = 0;
12171221
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
12181222

@@ -1502,9 +1506,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15021506
auto File = getOrCreateFile(L.Filename);
15031507
// For TypeAlias types, the DeclContext for the aliased type is
15041508
// in the decl of the alias type.
1505-
DebugTypeInfo AliasedDbgTy(AliasedTy, DbgTy.StorageType, DbgTy.size,
1506-
DbgTy.align, DbgTy.DefaultAlignment,
1507-
false);
1509+
DebugTypeInfo AliasedDbgTy(AliasedTy, DbgTy.getStorageType(),
1510+
DbgTy.getSize(), DbgTy.getAlignment(),
1511+
DbgTy.hasDefaultAlignment(), false);
15081512
return DBuilder.createTypedef(getOrCreateType(AliasedDbgTy), MangledName,
15091513
File, L.Line, Scope);
15101514
}
@@ -2216,11 +2220,11 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
22162220
return;
22172221

22182222
// We cannot yet represent opened existentials.
2219-
if (DbgTy.Type->hasOpenedExistential())
2223+
if (DbgTy.getType()->hasOpenedExistential())
22202224
return;
22212225

2222-
if (!DbgTy.size)
2223-
DbgTy.size = getStorageSize(IGM.DataLayout, Storage);
2226+
if (!DbgTy.getSize())
2227+
DbgTy.setSize(getStorageSize(IGM.DataLayout, Storage));
22242228

22252229
auto *Scope = dyn_cast_or_null<llvm::DILocalScope>(getOrCreateScope(DS));
22262230
assert(Scope && "variable has no local scope");

0 commit comments

Comments
 (0)