16
16
// ===----------------------------------------------------------------------===//
17
17
18
18
#include " DebugTypeInfo.h"
19
- #include " IRGen.h"
20
19
#include " FixedTypeInfo.h"
20
+ #include " IRGen.h"
21
+ #include " swift/SIL/SILGlobalVariable.h"
21
22
#include " llvm/Support/Debug.h"
22
23
#include " llvm/Support/raw_ostream.h"
23
24
24
25
using namespace swift ;
25
26
using namespace irgen ;
26
27
27
- DebugTypeInfo::DebugTypeInfo (swift::Type Ty, llvm::Type *StorageTy,
28
- uint64_t SizeInBytes, uint32_t AlignInBytes,
29
- DeclContext *DC)
30
- : DeclCtx(DC), Type(Ty.getPointer()), StorageType(StorageTy),
31
- size(SizeInBytes), align(AlignInBytes) {
32
- assert (StorageType && " StorageType is a nullptr" );
33
- assert (align.getValue () != 0 );
34
- }
35
-
36
- DebugTypeInfo::DebugTypeInfo (swift::Type Ty, llvm::Type *StorageTy, Size size,
37
- Alignment align, DeclContext *DC)
38
- : DeclCtx(DC), Type(Ty.getPointer()), StorageType(StorageTy),
39
- size(size), align(align) {
28
+ DebugTypeInfo::DebugTypeInfo (DeclContext *DC, swift::Type Ty,
29
+ llvm::Type *StorageTy, Size size, Alignment align)
30
+ : DeclCtx(DC), Type(Ty.getPointer()), StorageType(StorageTy), size(size),
31
+ align(align) {
32
+ assert ((!isArchetype () || (isArchetype () && DC)) &&
33
+ " archetype without a declcontext" );
40
34
assert (StorageType && " StorageType is a nullptr" );
41
35
assert (align.getValue () != 0 );
42
36
}
43
37
44
- static void
45
- initFromTypeInfo (Size &size, Alignment &align, llvm::Type *&StorageType,
46
- const TypeInfo &Info) {
47
- StorageType = Info.getStorageType ();
38
+ DebugTypeInfo DebugTypeInfo::getFromTypeInfo (DeclContext *DC, swift::Type Ty,
39
+ const TypeInfo &Info) {
40
+ Size size;
48
41
if (Info.isFixedSize ()) {
49
42
const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&Info);
50
43
size = FixTy.getFixedSize ();
@@ -53,50 +46,20 @@ initFromTypeInfo(Size &size, Alignment &align, llvm::Type *&StorageType,
53
46
// encounter one.
54
47
size = Size (0 );
55
48
}
56
- align = Info.getBestKnownAlignment ();
57
- assert (align.getValue () != 0 );
58
- assert (StorageType && " StorageType is a nullptr" );
59
- }
60
-
61
- DebugTypeInfo::DebugTypeInfo (swift::Type Ty, const TypeInfo &Info,
62
- DeclContext *DC)
63
- : DeclCtx(DC), Type(Ty.getPointer()) {
64
- initFromTypeInfo (size, align, StorageType, Info);
49
+ return DebugTypeInfo (DC, Ty.getPointer (), Info.getStorageType (), size,
50
+ Info.getBestKnownAlignment ());
65
51
}
66
52
67
- DebugTypeInfo::DebugTypeInfo (TypeDecl *Decl, const TypeInfo &Info)
68
- : DeclCtx(Decl->getDeclContext ()) {
69
- // Use the sugared version of the type, if there is one.
70
- if (auto AliasDecl = dyn_cast<TypeAliasDecl>(Decl))
71
- Type = AliasDecl->getDeclaredInterfaceType ().getPointer ();
72
- else
73
- Type = Decl->getInterfaceType ().getPointer ();
74
-
75
- initFromTypeInfo (size, align, StorageType, Info);
76
- }
77
-
78
- DebugTypeInfo::DebugTypeInfo (ValueDecl *Decl, llvm::Type *StorageTy, Size size,
79
- Alignment align)
80
- : DeclCtx(Decl->getDeclContext ()), StorageType(StorageTy), size(size),
81
- align(align) {
82
- // Use the sugared version of the type, if there is one.
83
- if (auto AliasDecl = dyn_cast<TypeAliasDecl>(Decl))
84
- Type = AliasDecl->getDeclaredInterfaceType ().getPointer ();
85
- else
86
- Type = Decl->getInterfaceType ().getPointer ();
87
-
88
- assert (StorageType && " StorageType is a nullptr" );
89
- assert (align.getValue () != 0 );
90
- }
53
+ DebugTypeInfo DebugTypeInfo::getLocalVariable (DeclContext *DeclCtx,
54
+ VarDecl *Decl, swift::Type Ty,
55
+ const TypeInfo &Info,
56
+ bool Unwrap) {
91
57
92
- DebugTypeInfo::DebugTypeInfo (VarDecl *Decl, swift::Type Ty,
93
- const TypeInfo &Info, bool Unwrap)
94
- : DeclCtx(Decl->getDeclContext ()) {
95
- // Prefer the original, potentially sugared version of the type if
96
- // the type hasn't been mucked with by an optimization pass.
97
- auto DeclType = (Decl->hasType ()
98
- ? Decl->getType ()
99
- : DeclCtx->mapTypeIntoContext (Decl->getInterfaceType ()));
58
+ auto DeclType = Ty;
59
+ if (DeclCtx)
60
+ DeclType = (Decl->hasType ()
61
+ ? Decl->getType ()
62
+ : DeclCtx->mapTypeIntoContext (Decl->getInterfaceType ()));
100
63
auto RealType = Ty;
101
64
if (Unwrap) {
102
65
DeclType = DeclType->getInOutObjectType ();
@@ -108,27 +71,51 @@ DebugTypeInfo::DebugTypeInfo(VarDecl *Decl, swift::Type Ty,
108
71
if (auto DynSelfTy = DeclType->getAs <DynamicSelfType>())
109
72
DeclSelfType = DynSelfTy->getSelfType ();
110
73
111
- if (DeclSelfType->isEqual (RealType) || DeclType->getAs <FunctionType>())
112
- Type = DeclType.getPointer ();
113
- else
114
- Type = RealType.getPointer ();
74
+ // Prefer the original, potentially sugared version of the type if
75
+ // the type hasn't been mucked with by an optimization pass.
76
+ auto *Type = DeclSelfType->isEqual (RealType) ? DeclType.getPointer ()
77
+ : RealType.getPointer ();
78
+ return getFromTypeInfo (DeclCtx, Type, Info);
79
+ }
115
80
116
- initFromTypeInfo (size, align, StorageType, Info);
81
+ DebugTypeInfo DebugTypeInfo::getMetadata (swift::Type Ty, llvm::Type *StorageTy,
82
+ Size size, Alignment align) {
83
+ DebugTypeInfo DbgTy = {nullptr , Ty.getPointer (), StorageTy, size, align};
84
+ assert (!DbgTy.isArchetype () && " type metadata cannot contain an archetype" );
85
+ return DbgTy;
117
86
}
118
87
119
- DebugTypeInfo::DebugTypeInfo (VarDecl *Decl, swift::Type Ty,
120
- llvm::Type *StorageTy, Size size, Alignment align)
121
- : DeclCtx(Decl->getDeclContext ()), StorageType(StorageTy), size(size),
122
- align(align) {
88
+ DebugTypeInfo DebugTypeInfo::getGlobal (SILGlobalVariable *GV,
89
+ llvm::Type *StorageTy, Size size,
90
+ Alignment align) {
123
91
// Prefer the original, potentially sugared version of the type if
124
92
// the type hasn't been mucked with by an optimization pass.
125
- auto DeclType = (Decl->hasType ()
126
- ? Decl->getType ()
127
- : DeclCtx->mapTypeIntoContext (Decl->getInterfaceType ()));
128
- if (Ty && Decl->getInterfaceType ()->isEqual (Ty))
129
- Type = DeclType.getPointer ();
130
- else
131
- Type = Ty.getPointer ();
93
+ auto LowTy = GV->getLoweredType ().getSwiftType ();
94
+ auto *Type = LowTy.getPointer ();
95
+ if (auto *Decl = GV->getDecl ()) {
96
+ auto DeclType =
97
+ (Decl->hasType () ? Decl->getType ()
98
+ : Decl->getDeclContext ()->mapTypeIntoContext (
99
+ Decl->getInterfaceType ()));
100
+ if (DeclType->isEqual (LowTy))
101
+ Type = DeclType.getPointer ();
102
+ }
103
+ DebugTypeInfo DbgTy = {nullptr , Type, StorageTy, size, align};
104
+ assert (StorageTy && " StorageType is a nullptr" );
105
+ assert (!DbgTy.isArchetype () &&
106
+ " type of a global var cannot contain an archetype" );
107
+ assert (align.getValue () != 0 );
108
+ return DbgTy;
109
+ }
110
+
111
+ DebugTypeInfo DebugTypeInfo::getObjCClass (ClassDecl *theClass,
112
+ llvm::Type *StorageType, Size size,
113
+ Alignment align) {
114
+ DebugTypeInfo DbgTy (nullptr , theClass->getInterfaceType ().getPointer (),
115
+ StorageType, size, align);
116
+ assert (!DbgTy.isArchetype () &&
117
+ " type of an objc class cannot contain an archetype" );
118
+ return DbgTy;
132
119
}
133
120
134
121
static bool typesEqual (Type A, Type B) {
@@ -141,7 +128,7 @@ static bool typesEqual(Type A, Type B) {
141
128
142
129
// Tombstone.
143
130
auto Tombstone =
144
- llvm::DenseMapInfo<swift::Type>::getTombstoneKey ().getPointer ();
131
+ llvm::DenseMapInfo<swift::Type>::getTombstoneKey ().getPointer ();
145
132
if ((A.getPointer () == Tombstone) || (B.getPointer () == Tombstone))
146
133
return false ;
147
134
@@ -150,14 +137,11 @@ static bool typesEqual(Type A, Type B) {
150
137
}
151
138
152
139
bool DebugTypeInfo::operator ==(DebugTypeInfo T) const {
153
- return typesEqual (getType (), T.getType ())
154
- && size == T.size
155
- && align == T.align ;
140
+ return typesEqual (getType (), T.getType ()) && size == T.size &&
141
+ align == T.align ;
156
142
}
157
143
158
- bool DebugTypeInfo::operator !=(DebugTypeInfo T) const {
159
- return !operator ==(T);
160
- }
144
+ bool DebugTypeInfo::operator !=(DebugTypeInfo T) const { return !operator ==(T); }
161
145
162
146
TypeDecl *DebugTypeInfo::getDecl () const {
163
147
if (auto *N = dyn_cast<NominalType>(Type))
@@ -172,8 +156,8 @@ TypeDecl *DebugTypeInfo::getDecl() const {
172
156
}
173
157
174
158
void DebugTypeInfo::dump () const {
175
- llvm::errs () << " [Size " << size.getValue ()
176
- << " Alignment " << align.getValue ()<< " ] " ;
159
+ llvm::errs () << " [Size " << size.getValue () << " Alignment "
160
+ << align.getValue () << " ] " ;
177
161
178
162
getType ()->dump ();
179
163
if (StorageType) {
0 commit comments