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);
65
- }
66
-
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);
49
+ return DebugTypeInfo (DC, Ty.getPointer (), Info.getStorageType (), size,
50
+ Info.getBestKnownAlignment ());
76
51
}
77
52
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 ();
53
+ DebugTypeInfo DebugTypeInfo::getLocalVariable (DeclContext *DeclCtx,
54
+ VarDecl *Decl, swift::Type Ty,
55
+ const TypeInfo &Info,
56
+ bool Unwrap) {
87
57
88
- assert (StorageType && " StorageType is a nullptr" );
89
- assert (align.getValue () != 0 );
90
- }
91
-
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,54 @@ 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>())
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
+ // FIXME: LLDB cannot deal with manglings that contain @owning annotations.
79
+ if (DeclType->getAs <FunctionType>())
112
80
Type = DeclType.getPointer ();
113
- else
114
- Type = RealType. getPointer ();
81
+ return getFromTypeInfo (DeclCtx, Type, Info);
82
+ }
115
83
116
- initFromTypeInfo (size, align, StorageType, Info);
84
+ DebugTypeInfo DebugTypeInfo::getMetadata (swift::Type Ty, llvm::Type *StorageTy,
85
+ Size size, Alignment align) {
86
+ DebugTypeInfo DbgTy = {nullptr , Ty.getPointer (), StorageTy, size, align};
87
+ assert (!DbgTy.isArchetype () && " type metadata cannot contain an archetype" );
88
+ return DbgTy;
117
89
}
118
90
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) {
91
+ DebugTypeInfo DebugTypeInfo::getGlobal (SILGlobalVariable *GV,
92
+ llvm::Type *StorageTy, Size size,
93
+ Alignment align) {
123
94
// Prefer the original, potentially sugared version of the type if
124
95
// 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 ();
96
+ auto LowTy = GV->getLoweredType ().getSwiftType ();
97
+ auto *Type = LowTy.getPointer ();
98
+ if (auto *Decl = GV->getDecl ()) {
99
+ auto DeclType =
100
+ (Decl->hasType () ? Decl->getType ()
101
+ : Decl->getDeclContext ()->mapTypeIntoContext (
102
+ Decl->getInterfaceType ()));
103
+ if (DeclType->isEqual (LowTy))
104
+ Type = DeclType.getPointer ();
105
+ }
106
+ DebugTypeInfo DbgTy = {nullptr , Type, StorageTy, size, align};
107
+ assert (StorageTy && " StorageType is a nullptr" );
108
+ assert (!DbgTy.isArchetype () &&
109
+ " type of a global var cannot contain an archetype" );
110
+ assert (align.getValue () != 0 );
111
+ return DbgTy;
112
+ }
113
+
114
+ DebugTypeInfo DebugTypeInfo::getObjCClass (ClassDecl *theClass,
115
+ llvm::Type *StorageType, Size size,
116
+ Alignment align) {
117
+ DebugTypeInfo DbgTy (nullptr , theClass->getInterfaceType ().getPointer (),
118
+ StorageType, size, align);
119
+ assert (!DbgTy.isArchetype () &&
120
+ " type of an objc class cannot contain an archetype" );
121
+ return DbgTy;
132
122
}
133
123
134
124
static bool typesEqual (Type A, Type B) {
@@ -141,7 +131,7 @@ static bool typesEqual(Type A, Type B) {
141
131
142
132
// Tombstone.
143
133
auto Tombstone =
144
- llvm::DenseMapInfo<swift::Type>::getTombstoneKey ().getPointer ();
134
+ llvm::DenseMapInfo<swift::Type>::getTombstoneKey ().getPointer ();
145
135
if ((A.getPointer () == Tombstone) || (B.getPointer () == Tombstone))
146
136
return false ;
147
137
@@ -150,14 +140,11 @@ static bool typesEqual(Type A, Type B) {
150
140
}
151
141
152
142
bool DebugTypeInfo::operator ==(DebugTypeInfo T) const {
153
- return typesEqual (getType (), T.getType ())
154
- && size == T.size
155
- && align == T.align ;
143
+ return typesEqual (getType (), T.getType ()) && size == T.size &&
144
+ align == T.align ;
156
145
}
157
146
158
- bool DebugTypeInfo::operator !=(DebugTypeInfo T) const {
159
- return !operator ==(T);
160
- }
147
+ bool DebugTypeInfo::operator !=(DebugTypeInfo T) const { return !operator ==(T); }
161
148
162
149
TypeDecl *DebugTypeInfo::getDecl () const {
163
150
if (auto *N = dyn_cast<NominalType>(Type))
@@ -172,8 +159,8 @@ TypeDecl *DebugTypeInfo::getDecl() const {
172
159
}
173
160
174
161
void DebugTypeInfo::dump () const {
175
- llvm::errs () << " [Size " << size.getValue ()
176
- << " Alignment " << align.getValue ()<< " ] " ;
162
+ llvm::errs () << " [Size " << size.getValue () << " Alignment "
163
+ << align.getValue () << " ] " ;
177
164
178
165
getType ()->dump ();
179
166
if (StorageType) {
0 commit comments