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"
@@ -27,23 +28,12 @@ using namespace irgen;
27
28
DebugTypeInfo::DebugTypeInfo (swift::Type Ty, llvm::Type *FragmentStorageTy,
28
29
Optional<Size::int_type> SizeInBits,
29
30
Alignment Align, bool HasDefaultAlignment,
30
- bool IsMetadata, bool SizeIsFragmentSize)
31
+ bool IsMetadata, bool SizeIsFragmentSize,
32
+ bool IsFixedBuffer)
31
33
: Type(Ty.getPointer()), FragmentStorageType(FragmentStorageTy),
32
34
SizeInBits(SizeInBits), Align(Align),
33
35
DefaultAlignment(HasDefaultAlignment), IsMetadataType(IsMetadata),
34
- SizeIsFragmentSize(SizeIsFragmentSize) {
35
- assert (Align.getValue () != 0 );
36
- }
37
-
38
- DebugTypeInfo::DebugTypeInfo (swift::Type Ty, llvm::Type *FragmentStorageTy,
39
- Optional<Size> SizeInBytes, Alignment Align,
40
- bool HasDefaultAlignment, bool IsMetadata,
41
- bool SizeIsFragmentSize)
42
- : Type(Ty.getPointer()), FragmentStorageType(FragmentStorageTy),
43
- Align(Align), DefaultAlignment(HasDefaultAlignment),
44
- IsMetadataType(IsMetadata), SizeIsFragmentSize(SizeIsFragmentSize) {
45
- if (SizeInBytes)
46
- SizeInBits = SizeInBytes->getValue () * 8 ;
36
+ SizeIsFragmentSize(SizeIsFragmentSize), IsFixedBuffer(IsFixedBuffer) {
47
37
assert (Align.getValue () != 0 );
48
38
}
49
39
@@ -56,17 +46,20 @@ static bool hasDefaultAlignment(swift::Type Ty) {
56
46
return true ;
57
47
}
58
48
59
- DebugTypeInfo DebugTypeInfo::getFromTypeInfo (swift::Type Ty,
60
- const TypeInfo &Info,
49
+ DebugTypeInfo DebugTypeInfo::getFromTypeInfo (swift::Type Ty, const TypeInfo &TI,
61
50
bool IsFragmentTypeInfo) {
62
- Optional<Size> size;
63
- if (Info.isFixedSize ()) {
64
- const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&Info);
65
- 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;
66
59
}
67
- assert (Info .getStorageType () && " StorageType is a nullptr" );
68
- return DebugTypeInfo (Ty.getPointer (), Info. getStorageType (), size ,
69
- Info .getBestKnownAlignment (), ::hasDefaultAlignment (Ty),
60
+ assert (TI .getStorageType () && " StorageType is a nullptr" );
61
+ return DebugTypeInfo (Ty.getPointer (), StorageType, SizeInBits ,
62
+ TI .getBestKnownAlignment (), ::hasDefaultAlignment (Ty),
70
63
false , IsFragmentTypeInfo);
71
64
}
72
65
@@ -92,8 +85,8 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
92
85
DebugTypeInfo DebugTypeInfo::getGlobalMetadata (swift::Type Ty,
93
86
llvm::Type *StorageTy, Size size,
94
87
Alignment align) {
95
- DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size,
96
- align, true , false , false );
88
+ DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size. getValue () * 8 , align ,
89
+ true , false , false );
97
90
assert (StorageTy && " StorageType is a nullptr" );
98
91
assert (!DbgTy.isContextArchetype () &&
99
92
" type metadata cannot contain an archetype" );
@@ -103,8 +96,8 @@ DebugTypeInfo DebugTypeInfo::getGlobalMetadata(swift::Type Ty,
103
96
DebugTypeInfo DebugTypeInfo::getTypeMetadata (swift::Type Ty,
104
97
llvm::Type *StorageTy, Size size,
105
98
Alignment align) {
106
- DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size,
107
- align, true , true , false );
99
+ DebugTypeInfo DbgTy (Ty.getPointer (), StorageTy, size. getValue () * 8 , align ,
100
+ true , true , false );
108
101
assert (StorageTy && " StorageType is a nullptr" );
109
102
assert (!DbgTy.isContextArchetype () &&
110
103
" type metadata cannot contain an archetype" );
@@ -117,8 +110,29 @@ DebugTypeInfo DebugTypeInfo::getForwardDecl(swift::Type Ty) {
117
110
}
118
111
119
112
DebugTypeInfo DebugTypeInfo::getGlobal (SILGlobalVariable *GV,
120
- llvm::Type *StorageTy, Size size,
121
- Alignment align) {
113
+ llvm::Type *FragmentStorageType,
114
+ IRGenModule &IGM) {
115
+ // Prefer the original, potentially sugared version of the type if
116
+ // the type hasn't been mucked with by an optimization pass.
117
+ auto LowTy = GV->getLoweredType ().getASTType ();
118
+ auto *Type = LowTy.getPointer ();
119
+ if (auto *Decl = GV->getDecl ()) {
120
+ auto DeclType = Decl->getType ();
121
+ if (DeclType->isEqual (LowTy))
122
+ Type = DeclType.getPointer ();
123
+ }
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) {
122
136
// Prefer the original, potentially sugared version of the type if
123
137
// the type hasn't been mucked with by an optimization pass.
124
138
auto LowTy = GV->getLoweredType ().getASTType ();
@@ -128,31 +142,34 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
128
142
if (DeclType->isEqual (LowTy))
129
143
Type = DeclType.getPointer ();
130
144
}
131
- DebugTypeInfo DbgTy (Type, StorageTy, size, align, :: hasDefaultAlignment (Type) ,
132
- false , false );
133
- assert (StorageTy && " FragmentStorageType is a nullptr" );
145
+ DebugTypeInfo DbgTy (Type, FragmentStorageType, SizeInBytes. getValue () * 8 ,
146
+ Align, :: hasDefaultAlignment (Type), false , false , true );
147
+ assert (FragmentStorageType && " FragmentStorageType is a nullptr" );
134
148
assert (!DbgTy.isContextArchetype () &&
135
149
" type of global variable cannot be an archetype" );
136
- assert (align.getValue () != 0 );
137
150
return DbgTy;
138
151
}
139
152
140
153
DebugTypeInfo DebugTypeInfo::getObjCClass (ClassDecl *theClass,
141
154
llvm::Type *FragmentStorageType,
142
- Size size , Alignment align) {
155
+ Size SizeInBytes , Alignment align) {
143
156
DebugTypeInfo DbgTy (theClass->getInterfaceType ().getPointer (),
144
- FragmentStorageType, size, align, true , false , false );
157
+ FragmentStorageType, SizeInBytes.getValue () * 8 , align,
158
+ true , false , false );
145
159
assert (FragmentStorageType && " FragmentStorageType is a nullptr" );
146
160
assert (!DbgTy.isContextArchetype () &&
147
161
" type of objc class cannot be an archetype" );
148
162
return DbgTy;
149
163
}
150
164
151
165
DebugTypeInfo DebugTypeInfo::getErrorResult (swift::Type Ty,
152
- llvm::Type *StorageType, Size size,
153
- 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 );
154
171
assert (StorageType && " FragmentStorageType is a nullptr" );
155
- return {Ty, StorageType, size, align, true , false , false } ;
172
+ return DbgTy ;
156
173
}
157
174
158
175
bool DebugTypeInfo::operator ==(DebugTypeInfo T) const {
0 commit comments