18
18
#define SWIFT_SIL_SILFUNCTION_H
19
19
20
20
#include " swift/AST/ASTNode.h"
21
+ #include " swift/AST/Availability.h"
21
22
#include " swift/AST/ResilienceExpansion.h"
22
23
#include " swift/Basic/ProfileCounter.h"
23
24
#include " swift/SIL/SILBasicBlock.h"
@@ -160,6 +161,27 @@ class SILFunction
160
161
161
162
Identifier ObjCReplacementFor;
162
163
164
+ // / The function's set of semantics attributes.
165
+ // /
166
+ // / TODO: Why is this using a std::string? Why don't we use uniqued
167
+ // / StringRefs?
168
+ std::vector<std::string> SemanticsAttrSet;
169
+
170
+ // / The function's remaining set of specialize attributes.
171
+ std::vector<SILSpecializeAttr*> SpecializeAttrSet;
172
+
173
+ // / Has value if there's a profile for this function
174
+ // / Contains Function Entry Count
175
+ ProfileCounter EntryCount;
176
+
177
+ // / The availability used to determine if declarations of this function
178
+ // / should use weak linking.
179
+ AvailabilityContext Availability;
180
+
181
+ // / This is the number of uses of this SILFunction inside the SIL.
182
+ // / It does not include references from debug scopes.
183
+ unsigned RefCount = 0 ;
184
+
163
185
// / The function's bare attribute. Bare means that the function is SIL-only
164
186
// / and does not require debug info.
165
187
unsigned Bare : 1 ;
@@ -194,39 +216,16 @@ class SILFunction
194
216
// / would indicate.
195
217
unsigned HasCReferences : 1 ;
196
218
197
- // / Whether cross-module references to this function should use weak linking.
198
- unsigned IsWeakLinked : 1 ;
219
+ // / Whether cross-module references to this function should always use
220
+ // / weak linking.
221
+ unsigned IsWeakImported : 1 ;
199
222
200
223
// Whether the implementation can be dynamically replaced.
201
224
unsigned IsDynamicReplaceable : 1 ;
202
225
203
- // / If != OptimizationMode::NotSet, the optimization mode specified with an
204
- // / function attribute.
205
- OptimizationMode OptMode;
206
-
207
- // / This is the number of uses of this SILFunction inside the SIL.
208
- // / It does not include references from debug scopes.
209
- unsigned RefCount = 0 ;
210
-
211
- // / The function's set of semantics attributes.
212
- // /
213
- // / TODO: Why is this using a std::string? Why don't we use uniqued
214
- // / StringRefs?
215
- llvm::SmallVector<std::string, 1 > SemanticsAttrSet;
216
-
217
- // / The function's remaining set of specialize attributes.
218
- std::vector<SILSpecializeAttr*> SpecializeAttrSet;
219
-
220
- // / The function's effects attribute.
221
- EffectsKind EffectsKindAttr;
222
-
223
- // / Has value if there's a profile for this function
224
- // / Contains Function Entry Count
225
- ProfileCounter EntryCount;
226
-
227
226
// / True if this function is inlined at least once. This means that the
228
227
// / debug info keeps a pointer to this function.
229
- bool Inlined = false ;
228
+ unsigned Inlined : 1 ;
230
229
231
230
// / True if this function is a zombie function. This means that the function
232
231
// / is dead and not referenced from anywhere inside the SIL. But it is kept
@@ -235,28 +234,35 @@ class SILFunction
235
234
// / *) It is a dead method of a class which has higher visibility than the
236
235
// / method itself. In this case we need to create a vtable stub for it.
237
236
// / *) It is a function referenced by the specialization information.
238
- bool Zombie = false ;
237
+ unsigned Zombie : 1 ;
239
238
240
239
// / True if this function is in Ownership SSA form and thus must pass
241
240
// / ownership verification.
242
241
// /
243
242
// / This enables the verifier to easily prove that before the Ownership Model
244
243
// / Eliminator runs on a function, we only see a non-semantic-arc world and
245
244
// / after the pass runs, we only see a semantic-arc world.
246
- bool HasOwnership = true ;
245
+ unsigned HasOwnership : 1 ;
247
246
248
247
// / Set if the function body was deserialized from canonical SIL. This implies
249
248
// / that the function's home module performed SIL diagnostics prior to
250
249
// / serialization.
251
- bool WasDeserializedCanonical = false ;
250
+ unsigned WasDeserializedCanonical : 1 ;
252
251
253
252
// / True if this is a reabstraction thunk of escaping function type whose
254
253
// / single argument is a potentially non-escaping closure. This is an escape
255
254
// / hatch to allow non-escaping functions to be stored or passed as an
256
255
// / argument with escaping function type. The thunk argument's function type
257
256
// / is not necessarily @noescape. The only relevant aspect of the argument is
258
257
// / that it may have unboxed capture (i.e. @inout_aliasable parameters).
259
- bool IsWithoutActuallyEscapingThunk = false ;
258
+ unsigned IsWithoutActuallyEscapingThunk : 1 ;
259
+
260
+ // / If != OptimizationMode::NotSet, the optimization mode specified with an
261
+ // / function attribute.
262
+ unsigned OptMode : NumOptimizationModeBits;
263
+
264
+ // / The function's effects attribute.
265
+ unsigned EffectsKindAttr : NumEffectsKindBits;
260
266
261
267
static void
262
268
validateSubclassScope (SubclassScope scope, IsThunk_t isThunk,
@@ -575,17 +581,27 @@ class SILFunction
575
581
bool hasCReferences () const { return HasCReferences; }
576
582
void setHasCReferences (bool value) { HasCReferences = value; }
577
583
584
+ // / Returns the availability context used to determine if the function's
585
+ // / symbol should be weakly referenced across module boundaries.
586
+ AvailabilityContext getAvailabilityForLinkage () const {
587
+ return Availability;
588
+ }
589
+
590
+ void setAvailabilityForLinkage (AvailabilityContext availability) {
591
+ Availability = availability;
592
+ }
593
+
578
594
// / Returns whether this function's symbol must always be weakly referenced
579
595
// / across module boundaries.
580
- bool isWeakLinked () const { return IsWeakLinked; }
581
- // / Forces IRGen to treat references to this function as weak across module
582
- // / boundaries (i.e. if it has external linkage).
583
- void setWeakLinked (bool value = true ) {
584
- assert (!IsWeakLinked && " already set" );
585
- IsWeakLinked = value;
596
+ bool isAlwaysWeakImported () const { return IsWeakImported; }
597
+
598
+ void setAlwaysWeakImported (bool value) {
599
+ IsWeakImported = value;
586
600
}
587
601
588
- // / Returs whether this function implementation can be dynamically replaced.
602
+ bool isWeakImported () const ;
603
+
604
+ // / Returns whether this function implementation can be dynamically replaced.
589
605
IsDynamicallyReplaceable_t isDynamicallyReplaceable () const {
590
606
return IsDynamicallyReplaceable_t (IsDynamicReplaceable);
591
607
}
@@ -650,13 +666,17 @@ class SILFunction
650
666
651
667
// / Get this function's optimization mode or OptimizationMode::NotSet if it is
652
668
// / not set for this specific function.
653
- OptimizationMode getOptimizationMode () const { return OptMode; }
669
+ OptimizationMode getOptimizationMode () const {
670
+ return OptimizationMode (OptMode);
671
+ }
654
672
655
673
// / Returns the optimization mode for the function. If no mode is set for the
656
674
// / function, returns the global mode, i.e. the mode of the module's options.
657
675
OptimizationMode getEffectiveOptimizationMode () const ;
658
676
659
- void setOptimizationMode (OptimizationMode mode) { OptMode = mode; }
677
+ void setOptimizationMode (OptimizationMode mode) {
678
+ OptMode = unsigned (mode);
679
+ }
660
680
661
681
// / \returns True if the function is optimizable (i.e. not marked as no-opt),
662
682
// / or is raw SIL (so that the mandatory passes still run).
@@ -726,16 +746,16 @@ class SILFunction
726
746
void setInlineStrategy (Inline_t inStr) { InlineStrategy = inStr; }
727
747
728
748
// / \return the function side effects information.
729
- EffectsKind getEffectsKind () const { return EffectsKindAttr; }
749
+ EffectsKind getEffectsKind () const { return EffectsKind ( EffectsKindAttr) ; }
730
750
731
751
// / \return True if the function is annotated with the @_effects attribute.
732
752
bool hasEffectsKind () const {
733
- return EffectsKindAttr != EffectsKind::Unspecified;
753
+ return EffectsKind ( EffectsKindAttr) != EffectsKind::Unspecified;
734
754
}
735
755
736
756
// / Set the function side effect information.
737
757
void setEffectsKind (EffectsKind E) {
738
- EffectsKindAttr = E ;
758
+ EffectsKindAttr = unsigned (E) ;
739
759
}
740
760
741
761
// / Get this function's global_init attribute.
0 commit comments