@@ -25,6 +25,18 @@ using namespace irgen;
25
25
26
26
TypeLayoutEntry::~TypeLayoutEntry () {}
27
27
28
+ void TypeLayoutEntry::computeProperties () {
29
+ // does not add anything.
30
+ }
31
+
32
+ void TypeLayoutEntry::gatherProperties (TypeLayoutEntry *fromEntry) {
33
+ hasArchetypeField |= fromEntry->hasArchetypeField ;
34
+ hasResilientField |= fromEntry->hasResilientField ;
35
+ hasDependentResilientField |= fromEntry->hasDependentResilientField ;
36
+
37
+ assert (!(!hasResilientField && hasDependentResilientField));
38
+ }
39
+
28
40
const EnumTypeLayoutEntry *TypeLayoutEntry::getAsEnum () const {
29
41
if (getKind () == TypeLayoutEntryKind::Enum) {
30
42
return static_cast <const EnumTypeLayoutEntry *>(this );
@@ -99,8 +111,16 @@ void TypeLayoutEntry::initWithTake(IRGenFunction &IGF, Address dest,
99
111
// Nothing to copy.
100
112
}
101
113
102
- bool TypeLayoutEntry::containsEnum () const {
103
- return false ;
114
+ bool TypeLayoutEntry::containsResilientField () const {
115
+ return hasResilientField;
116
+ }
117
+
118
+ bool TypeLayoutEntry::containsArchetypeField () const {
119
+ return hasArchetypeField;
120
+ }
121
+
122
+ bool TypeLayoutEntry::containsDependentResilientField () const {
123
+ return hasDependentResilientField;
104
124
}
105
125
106
126
llvm::Value *TypeLayoutEntry::getEnumTagSinglePayload (
@@ -571,6 +591,10 @@ llvm::Value *TypeLayoutEntry::initBufferWithCopyOfBuffer(IRGenFunction &IGF,
571
591
return pointerToObject;
572
592
}
573
593
594
+ void ScalarTypeLayoutEntry::computeProperties () {
595
+ // does not add anything.
596
+ }
597
+
574
598
void ScalarTypeLayoutEntry::Profile (llvm::FoldingSetNodeID &id) const {
575
599
ScalarTypeLayoutEntry::Profile (id, typeInfo);
576
600
}
@@ -608,10 +632,6 @@ llvm::Value *ScalarTypeLayoutEntry::isBitwiseTakable(IRGenFunction &IGF) const {
608
632
ResilienceExpansion::Maximal));
609
633
}
610
634
611
- bool ScalarTypeLayoutEntry::containsEnum () const {
612
- return false ;
613
- }
614
-
615
635
void ScalarTypeLayoutEntry::destroy (IRGenFunction &IGF, Address addr) const {
616
636
auto alignment = cast<FixedTypeInfo>(typeInfo).getFixedAlignment ();
617
637
auto addressType = typeInfo.getStorageType ()->getPointerTo ();
@@ -709,6 +729,12 @@ LLVM_DUMP_METHOD void ScalarTypeLayoutEntry::dump() const {
709
729
}
710
730
#endif
711
731
732
+ void AlignedGroupEntry::computeProperties () {
733
+ for (auto *entry : entries) {
734
+ gatherProperties (entry);
735
+ }
736
+ }
737
+
712
738
void AlignedGroupEntry::Profile (llvm::FoldingSetNodeID &id) const {
713
739
AlignedGroupEntry::Profile (id, entries, minimumAlignment, isFixedSize);
714
740
}
@@ -763,14 +789,6 @@ llvm::Value *AlignedGroupEntry::size(IRGenFunction &IGF) const {
763
789
return currentSize;
764
790
}
765
791
766
- bool AlignedGroupEntry::containsEnum () const {
767
- for (auto *entry : entries) {
768
- if (entry->containsEnum ())
769
- return true ;
770
- }
771
- return false ;
772
- }
773
-
774
792
llvm::Value *AlignedGroupEntry::extraInhabitantCount (IRGenFunction &IGF) const {
775
793
llvm::Value *currentMaxXICount = IGF.IGM .getInt32 (0 );
776
794
auto &Builder = IGF.Builder ;
@@ -1001,6 +1019,8 @@ LLVM_DUMP_METHOD void AlignedGroupEntry::dump() const {
1001
1019
}
1002
1020
#endif
1003
1021
1022
+ void ArchetypeLayoutEntry::computeProperties () { hasArchetypeField = true ; }
1023
+
1004
1024
void ArchetypeLayoutEntry::Profile (llvm::FoldingSetNodeID &id) const {
1005
1025
ArchetypeLayoutEntry::Profile (id, archetype);
1006
1026
}
@@ -1030,10 +1050,6 @@ ArchetypeLayoutEntry::isBitwiseTakable(IRGenFunction &IGF) const {
1030
1050
return emitLoadOfIsBitwiseTakable (IGF, archetype);
1031
1051
}
1032
1052
1033
- bool ArchetypeLayoutEntry::containsEnum () const {
1034
- return false ;
1035
- }
1036
-
1037
1053
void ArchetypeLayoutEntry::destroy (IRGenFunction &IGF, Address addr) const {
1038
1054
emitDestroyCall (IGF, archetype, addr);
1039
1055
}
@@ -1139,10 +1155,10 @@ llvm::Value *EnumTypeLayoutEntry::isBitwiseTakable(IRGenFunction &IGF) const {
1139
1155
return isBitwiseTakable;
1140
1156
}
1141
1157
1142
- bool EnumTypeLayoutEntry::containsEnum () const {
1143
- if (cases. size () == 1 )
1144
- return false ;
1145
- return false ;
1158
+ void EnumTypeLayoutEntry::computeProperties () {
1159
+ for ( auto c: cases) {
1160
+ gatherProperties (c) ;
1161
+ }
1146
1162
}
1147
1163
1148
1164
llvm::Value *EnumTypeLayoutEntry::size (IRGenFunction &IGF) const {
@@ -2006,8 +2022,10 @@ ResilientTypeLayoutEntry::isBitwiseTakable(IRGenFunction &IGF) const {
2006
2022
return emitLoadOfIsBitwiseTakable (IGF, ty);
2007
2023
}
2008
2024
2009
- bool ResilientTypeLayoutEntry::containsEnum () const {
2010
- return false ;
2025
+ void ResilientTypeLayoutEntry::computeProperties () {
2026
+ hasResilientField = true ;
2027
+ if (ty.getASTType ()->hasArchetype ())
2028
+ hasDependentResilientField = true ;
2011
2029
}
2012
2030
2013
2031
void ResilientTypeLayoutEntry::destroy (IRGenFunction &IGF, Address addr) const {
@@ -2076,6 +2094,7 @@ TypeLayoutCache::getOrCreateScalarEntry(const TypeInfo &ti,
2076
2094
auto mem = bumpAllocator.Allocate (bytes, alignof (ScalarTypeLayoutEntry));
2077
2095
auto newEntry = new (mem) ScalarTypeLayoutEntry (ti, representative);
2078
2096
scalarEntries.InsertNode (newEntry, insertPos);
2097
+ newEntry->computeProperties ();
2079
2098
return newEntry;
2080
2099
}
2081
2100
@@ -2091,6 +2110,7 @@ TypeLayoutCache::getOrCreateArchetypeEntry(SILType archetype) {
2091
2110
auto mem = bumpAllocator.Allocate (bytes, alignof (ArchetypeLayoutEntry));
2092
2111
auto newEntry = new (mem) ArchetypeLayoutEntry (archetype);
2093
2112
archetypeEntries.InsertNode (newEntry, insertPos);
2113
+ newEntry->computeProperties ();
2094
2114
return newEntry;
2095
2115
}
2096
2116
@@ -2108,6 +2128,7 @@ AlignedGroupEntry *TypeLayoutCache::getOrCreateAlignedGroupEntry(
2108
2128
auto newEntry =
2109
2129
new (mem) AlignedGroupEntry (entries, minimumAlignment, isFixedSize);
2110
2130
alignedGroupEntries.InsertNode (newEntry, insertPos);
2131
+ newEntry->computeProperties ();
2111
2132
return newEntry;
2112
2133
}
2113
2134
@@ -2127,6 +2148,7 @@ EnumTypeLayoutEntry *TypeLayoutCache::getOrCreateEnumEntry(
2127
2148
auto mem = bumpAllocator.Allocate (bytes, alignof (EnumTypeLayoutEntry));
2128
2149
auto newEntry = new (mem) EnumTypeLayoutEntry (numEmptyCases, nonEmptyCases);
2129
2150
enumEntries.InsertNode (newEntry, insertPos);
2151
+ newEntry->computeProperties ();
2130
2152
return newEntry;
2131
2153
}
2132
2154
@@ -2142,6 +2164,7 @@ TypeLayoutCache::getOrCreateResilientEntry(SILType ty) {
2142
2164
auto mem = bumpAllocator.Allocate (bytes, alignof (ResilientTypeLayoutEntry));
2143
2165
auto newEntry = new (mem) ResilientTypeLayoutEntry (ty);
2144
2166
resilientEntries.InsertNode (newEntry, insertPos);
2167
+ newEntry->computeProperties ();
2145
2168
return newEntry;
2146
2169
}
2147
2170
0 commit comments