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"
@@ -165,6 +166,27 @@ class SILFunction
165
166
166
167
Identifier ObjCReplacementFor;
167
168
169
+ // / The function's set of semantics attributes.
170
+ // /
171
+ // / TODO: Why is this using a std::string? Why don't we use uniqued
172
+ // / StringRefs?
173
+ std::vector<std::string> SemanticsAttrSet;
174
+
175
+ // / The function's remaining set of specialize attributes.
176
+ std::vector<SILSpecializeAttr*> SpecializeAttrSet;
177
+
178
+ // / Has value if there's a profile for this function
179
+ // / Contains Function Entry Count
180
+ ProfileCounter EntryCount;
181
+
182
+ // / The availability used to determine if declarations of this function
183
+ // / should use weak linking.
184
+ AvailabilityContext Availability;
185
+
186
+ // / This is the number of uses of this SILFunction inside the SIL.
187
+ // / It does not include references from debug scopes.
188
+ unsigned RefCount = 0 ;
189
+
168
190
// / The function's bare attribute. Bare means that the function is SIL-only
169
191
// / and does not require debug info.
170
192
unsigned Bare : 1 ;
@@ -199,8 +221,9 @@ class SILFunction
199
221
// / would indicate.
200
222
unsigned HasCReferences : 1 ;
201
223
202
- // / Whether cross-module references to this function should use weak linking.
203
- unsigned IsWeakLinked : 1 ;
224
+ // / Whether cross-module references to this function should always use
225
+ // / weak linking.
226
+ unsigned IsWeakImported : 1 ;
204
227
205
228
// / Whether the implementation can be dynamically replaced.
206
229
unsigned IsDynamicReplaceable : 1 ;
@@ -209,33 +232,9 @@ class SILFunction
209
232
// / invoked with a `self` argument of the exact base class type.
210
233
unsigned ExactSelfClass : 1 ;
211
234
212
- // / If != OptimizationMode::NotSet, the optimization mode specified with an
213
- // / function attribute.
214
- OptimizationMode OptMode;
215
-
216
- // / This is the number of uses of this SILFunction inside the SIL.
217
- // / It does not include references from debug scopes.
218
- unsigned RefCount = 0 ;
219
-
220
- // / The function's set of semantics attributes.
221
- // /
222
- // / TODO: Why is this using a std::string? Why don't we use uniqued
223
- // / StringRefs?
224
- llvm::SmallVector<std::string, 1 > SemanticsAttrSet;
225
-
226
- // / The function's remaining set of specialize attributes.
227
- std::vector<SILSpecializeAttr*> SpecializeAttrSet;
228
-
229
- // / The function's effects attribute.
230
- EffectsKind EffectsKindAttr;
231
-
232
- // / Has value if there's a profile for this function
233
- // / Contains Function Entry Count
234
- ProfileCounter EntryCount;
235
-
236
235
// / True if this function is inlined at least once. This means that the
237
236
// / debug info keeps a pointer to this function.
238
- bool Inlined = false ;
237
+ unsigned Inlined : 1 ;
239
238
240
239
// / True if this function is a zombie function. This means that the function
241
240
// / is dead and not referenced from anywhere inside the SIL. But it is kept
@@ -244,28 +243,35 @@ class SILFunction
244
243
// / *) It is a dead method of a class which has higher visibility than the
245
244
// / method itself. In this case we need to create a vtable stub for it.
246
245
// / *) It is a function referenced by the specialization information.
247
- bool Zombie = false ;
246
+ unsigned Zombie : 1 ;
248
247
249
248
// / True if this function is in Ownership SSA form and thus must pass
250
249
// / ownership verification.
251
250
// /
252
251
// / This enables the verifier to easily prove that before the Ownership Model
253
252
// / Eliminator runs on a function, we only see a non-semantic-arc world and
254
253
// / after the pass runs, we only see a semantic-arc world.
255
- bool HasOwnership = true ;
254
+ unsigned HasOwnership : 1 ;
256
255
257
256
// / Set if the function body was deserialized from canonical SIL. This implies
258
257
// / that the function's home module performed SIL diagnostics prior to
259
258
// / serialization.
260
- bool WasDeserializedCanonical = false ;
259
+ unsigned WasDeserializedCanonical : 1 ;
261
260
262
261
// / True if this is a reabstraction thunk of escaping function type whose
263
262
// / single argument is a potentially non-escaping closure. This is an escape
264
263
// / hatch to allow non-escaping functions to be stored or passed as an
265
264
// / argument with escaping function type. The thunk argument's function type
266
265
// / is not necessarily @noescape. The only relevant aspect of the argument is
267
266
// / that it may have unboxed capture (i.e. @inout_aliasable parameters).
268
- bool IsWithoutActuallyEscapingThunk = false ;
267
+ unsigned IsWithoutActuallyEscapingThunk : 1 ;
268
+
269
+ // / If != OptimizationMode::NotSet, the optimization mode specified with an
270
+ // / function attribute.
271
+ unsigned OptMode : NumOptimizationModeBits;
272
+
273
+ // / The function's effects attribute.
274
+ unsigned EffectsKindAttr : NumEffectsKindBits;
269
275
270
276
static void
271
277
validateSubclassScope (SubclassScope scope, IsThunk_t isThunk,
@@ -591,16 +597,26 @@ class SILFunction
591
597
bool hasCReferences () const { return HasCReferences; }
592
598
void setHasCReferences (bool value) { HasCReferences = value; }
593
599
600
+ // / Returns the availability context used to determine if the function's
601
+ // / symbol should be weakly referenced across module boundaries.
602
+ AvailabilityContext getAvailabilityForLinkage () const {
603
+ return Availability;
604
+ }
605
+
606
+ void setAvailabilityForLinkage (AvailabilityContext availability) {
607
+ Availability = availability;
608
+ }
609
+
594
610
// / Returns whether this function's symbol must always be weakly referenced
595
611
// / across module boundaries.
596
- bool isWeakLinked () const { return IsWeakLinked; }
597
- // / Forces IRGen to treat references to this function as weak across module
598
- // / boundaries (i.e. if it has external linkage).
599
- void setWeakLinked (bool value = true ) {
600
- assert (!IsWeakLinked && " already set" );
601
- IsWeakLinked = value;
612
+ bool isAlwaysWeakImported () const { return IsWeakImported; }
613
+
614
+ void setAlwaysWeakImported (bool value) {
615
+ IsWeakImported = value;
602
616
}
603
617
618
+ bool isWeakImported () const ;
619
+
604
620
// / Returns whether this function implementation can be dynamically replaced.
605
621
IsDynamicallyReplaceable_t isDynamicallyReplaceable () const {
606
622
return IsDynamicallyReplaceable_t (IsDynamicReplaceable);
@@ -671,13 +687,17 @@ class SILFunction
671
687
672
688
// / Get this function's optimization mode or OptimizationMode::NotSet if it is
673
689
// / not set for this specific function.
674
- OptimizationMode getOptimizationMode () const { return OptMode; }
690
+ OptimizationMode getOptimizationMode () const {
691
+ return OptimizationMode (OptMode);
692
+ }
675
693
676
694
// / Returns the optimization mode for the function. If no mode is set for the
677
695
// / function, returns the global mode, i.e. the mode of the module's options.
678
696
OptimizationMode getEffectiveOptimizationMode () const ;
679
697
680
- void setOptimizationMode (OptimizationMode mode) { OptMode = mode; }
698
+ void setOptimizationMode (OptimizationMode mode) {
699
+ OptMode = unsigned (mode);
700
+ }
681
701
682
702
// / \returns True if the function is optimizable (i.e. not marked as no-opt),
683
703
// / or is raw SIL (so that the mandatory passes still run).
@@ -755,16 +775,16 @@ class SILFunction
755
775
void setInlineStrategy (Inline_t inStr) { InlineStrategy = inStr; }
756
776
757
777
// / \return the function side effects information.
758
- EffectsKind getEffectsKind () const { return EffectsKindAttr; }
778
+ EffectsKind getEffectsKind () const { return EffectsKind ( EffectsKindAttr) ; }
759
779
760
780
// / \return True if the function is annotated with the @_effects attribute.
761
781
bool hasEffectsKind () const {
762
- return EffectsKindAttr != EffectsKind::Unspecified;
782
+ return EffectsKind ( EffectsKindAttr) != EffectsKind::Unspecified;
763
783
}
764
784
765
785
// / Set the function side effect information.
766
786
void setEffectsKind (EffectsKind E) {
767
- EffectsKindAttr = E ;
787
+ EffectsKindAttr = unsigned (E) ;
768
788
}
769
789
770
790
// / Get this function's global_init attribute.
0 commit comments