17
17
18
18
#include " DebugTypeInfo.h"
19
19
#include " FixedTypeInfo.h"
20
+ #include " IRGenModule.h"
20
21
#include " swift/SIL/SILGlobalVariable.h"
21
22
#include " llvm/Support/Debug.h"
22
23
#include " llvm/Support/raw_ostream.h"
@@ -25,13 +26,15 @@ using namespace swift;
25
26
using namespace irgen ;
26
27
27
28
DebugTypeInfo::DebugTypeInfo (swift::Type Ty, llvm::Type *FragmentStorageTy,
28
- Optional<Size> size, Alignment align,
29
- bool HasDefaultAlignment, bool IsMetadata,
30
- bool SizeIsFragmentSize)
31
- : Type(Ty.getPointer()), FragmentStorageType(FragmentStorageTy), size(size),
32
- align(align), DefaultAlignment(HasDefaultAlignment),
33
- IsMetadataType(IsMetadata), SizeIsFragmentSize(SizeIsFragmentSize) {
34
- assert (align.getValue () != 0 );
29
+ Optional<Size::int_type> SizeInBits,
30
+ Alignment Align, bool HasDefaultAlignment,
31
+ bool IsMetadata, bool SizeIsFragmentSize,
32
+ bool IsFixedBuffer)
33
+ : Type(Ty.getPointer()), FragmentStorageType(FragmentStorageTy),
34
+ SizeInBits(SizeInBits), Align(Align),
35
+ DefaultAlignment(HasDefaultAlignment), IsMetadataType(IsMetadata),
36
+ SizeIsFragmentSize(SizeIsFragmentSize), IsFixedBuffer(IsFixedBuffer) {
37
+ assert (Align.getValue () != 0 );
35
38
}
36
39
37
40
// / Determine whether this type has a custom @_alignment attribute.
@@ -43,17 +46,20 @@ static bool hasDefaultAlignment(swift::Type Ty) {
43
46
return true ;
44
47
}
45
48
46
- DebugTypeInfo DebugTypeInfo::getFromTypeInfo (swift::Type Ty,
47
- const TypeInfo &Info,
49
+ DebugTypeInfo DebugTypeInfo::getFromTypeInfo (swift::Type Ty, const TypeInfo &TI,
48
50
bool IsFragmentTypeInfo) {
49
- Optional<Size> size;
50
- if (Info.isFixedSize ()) {
51
- const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&Info);
52
- size = FixTy.getFixedSize ();
51
+ Optional<Size::int_type> SizeInBits;
52
+ llvm::Type *StorageType = TI.getStorageType ();
53
+ if (TI.isFixedSize ()) {
54
+ const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&TI);
55
+ Size::int_type Size = FixTy.getFixedSize ().getValue () * 8 ;
56
+ // if (!StorageType->isPointerTy())
57
+ // Size -= FixTy.getSpareBits().asAPInt().countTrailingOnes();
58
+ SizeInBits = Size;
53
59
}
54
- assert (Info .getStorageType () && " StorageType is a nullptr" );
55
- return DebugTypeInfo (Ty.getPointer (), Info. getStorageType (), size ,
56
- Info .getBestKnownAlignment (), ::hasDefaultAlignment (Ty),
60
+ assert (TI .getStorageType () && " StorageType is a nullptr" );
61
+ return DebugTypeInfo (Ty.getPointer (), StorageType, SizeInBits ,
62
+ TI .getBestKnownAlignment (), ::hasDefaultAlignment (Ty),
57
63
false , IsFragmentTypeInfo);
58
64
}
59
65
@@ -79,8 +85,8 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
79
85
DebugTypeInfo DebugTypeInfo::getGlobalMetadata (swift::Type Ty,
80
86
llvm::Type *StorageTy, Size size,
81
87
Alignment align) {
82
- DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size,
83
- align, true , false , false );
88
+ DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size. getValue () * 8 , align ,
89
+ true , false , false );
84
90
assert (StorageTy && " StorageType is a nullptr" );
85
91
assert (!DbgTy.isContextArchetype () &&
86
92
" type metadata cannot contain an archetype" );
@@ -90,23 +96,22 @@ DebugTypeInfo DebugTypeInfo::getGlobalMetadata(swift::Type Ty,
90
96
DebugTypeInfo DebugTypeInfo::getTypeMetadata (swift::Type Ty,
91
97
llvm::Type *StorageTy, Size size,
92
98
Alignment align) {
93
- DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size,
94
- align, true , true , false );
99
+ DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size. getValue () * 8 , align ,
100
+ true , true , false );
95
101
assert (StorageTy && " StorageType is a nullptr" );
96
102
assert (!DbgTy.isContextArchetype () &&
97
103
" type metadata cannot contain an archetype" );
98
104
return DbgTy;
99
105
}
100
106
101
107
DebugTypeInfo DebugTypeInfo::getForwardDecl (swift::Type Ty) {
102
- DebugTypeInfo DbgTy (Ty.getPointer (), nullptr , {}, Alignment (1 ), true ,
103
- false , false );
108
+ DebugTypeInfo DbgTy (Ty.getPointer ());
104
109
return DbgTy;
105
110
}
106
111
107
112
DebugTypeInfo DebugTypeInfo::getGlobal (SILGlobalVariable *GV,
108
- llvm::Type *StorageTy, Size size ,
109
- Alignment align ) {
113
+ llvm::Type *FragmentStorageType ,
114
+ IRGenModule &IGM ) {
110
115
// Prefer the original, potentially sugared version of the type if
111
116
// the type hasn't been mucked with by an optimization pass.
112
117
auto LowTy = GV->getLoweredType ().getASTType ();
@@ -116,37 +121,61 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
116
121
if (DeclType->isEqual (LowTy))
117
122
Type = DeclType.getPointer ();
118
123
}
119
- DebugTypeInfo DbgTy (Type, StorageTy, size, align, ::hasDefaultAlignment (Type),
120
- false , false );
121
- assert (StorageTy && " FragmentStorageType is a nullptr" );
124
+ auto &TI = IGM.getTypeInfoForUnlowered (Type);
125
+ DebugTypeInfo DbgTy = getFromTypeInfo (Type, TI, false );
126
+ assert (FragmentStorageType && " FragmentStorageType is a nullptr" );
127
+ assert (!DbgTy.isContextArchetype () &&
128
+ " type of global variable cannot be an archetype" );
129
+ return DbgTy;
130
+ }
131
+
132
+ DebugTypeInfo
133
+ DebugTypeInfo::getGlobalFixedBuffer (SILGlobalVariable *GV,
134
+ llvm::Type *FragmentStorageType,
135
+ Size SizeInBytes, Alignment Align) {
136
+ // Prefer the original, potentially sugared version of the type if
137
+ // the type hasn't been mucked with by an optimization pass.
138
+ auto LowTy = GV->getLoweredType ().getASTType ();
139
+ auto *Type = LowTy.getPointer ();
140
+ if (auto *Decl = GV->getDecl ()) {
141
+ auto DeclType = Decl->getType ();
142
+ if (DeclType->isEqual (LowTy))
143
+ Type = DeclType.getPointer ();
144
+ }
145
+ DebugTypeInfo DbgTy (Type, FragmentStorageType, SizeInBytes.getValue () * 8 ,
146
+ Align, ::hasDefaultAlignment (Type), false , false , true );
147
+ assert (FragmentStorageType && " FragmentStorageType is a nullptr" );
122
148
assert (!DbgTy.isContextArchetype () &&
123
149
" type of global variable cannot be an archetype" );
124
- assert (align.getValue () != 0 );
125
150
return DbgTy;
126
151
}
127
152
128
153
DebugTypeInfo DebugTypeInfo::getObjCClass (ClassDecl *theClass,
129
154
llvm::Type *FragmentStorageType,
130
- Size size , Alignment align) {
155
+ Size SizeInBytes , Alignment align) {
131
156
DebugTypeInfo DbgTy (theClass->getInterfaceType ().getPointer (),
132
- FragmentStorageType, size, align, true , false , false );
157
+ FragmentStorageType, SizeInBytes.getValue () * 8 , align,
158
+ true , false , false );
133
159
assert (FragmentStorageType && " FragmentStorageType is a nullptr" );
134
160
assert (!DbgTy.isContextArchetype () &&
135
161
" type of objc class cannot be an archetype" );
136
162
return DbgTy;
137
163
}
138
164
139
165
DebugTypeInfo DebugTypeInfo::getErrorResult (swift::Type Ty,
140
- llvm::Type *StorageType, Size size,
141
- Alignment align) {
166
+ llvm::Type *StorageType,
167
+ IRGenModule &IGM) {
168
+ auto &TI = IGM.getTypeInfoForUnlowered (Ty);
169
+ assert (TI.getStorageType () == StorageType);
170
+ DebugTypeInfo DbgTy = getFromTypeInfo (Ty, TI, false );
142
171
assert (StorageType && " FragmentStorageType is a nullptr" );
143
- return {Ty, StorageType, size, align, true , false , false } ;
172
+ return DbgTy ;
144
173
}
145
174
146
175
bool DebugTypeInfo::operator ==(DebugTypeInfo T) const {
147
- return ( getType () == T.getType () &&
148
- size == T.size &&
149
- align == T.align ) ;
176
+ return getType () == T.getType () &&
177
+ SizeInBits == T.SizeInBits &&
178
+ Align == T.Align ;
150
179
}
151
180
152
181
bool DebugTypeInfo::operator !=(DebugTypeInfo T) const { return !operator ==(T); }
@@ -168,9 +197,9 @@ TypeDecl *DebugTypeInfo::getDecl() const {
168
197
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
169
198
LLVM_DUMP_METHOD void DebugTypeInfo::dump () const {
170
199
llvm::errs () << " [" ;
171
- if (size )
172
- llvm::errs () << " Size " << size-> getValue () << " " ;
173
- llvm::errs () << " Alignment " << align .getValue () << " ] " ;
200
+ if (SizeInBits )
201
+ llvm::errs () << " SizeInBits " << *SizeInBits << " " ;
202
+ llvm::errs () << " Alignment " << Align .getValue () << " ] " ;
174
203
getType ()->dump (llvm::errs ());
175
204
176
205
if (FragmentStorageType) {
0 commit comments