Skip to content

Commit 9bd85c6

Browse files
committed
SIL: add some Function APIs
* `isReferencedInModule` * `shouldOptimize`
1 parent d8e4e50 commit 9bd85c6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
3636
hasher.combine(ObjectIdentifier(self))
3737
}
3838

39+
/// True if this function is referenced from anywhere within the module,
40+
/// e.g. from a `function_ref` instruction.
41+
public var isReferencedInModule: Bool { bridged.isReferencedInModule() }
42+
43+
/// True if this function should be optimized, i.e. the module is compiled with optimizations
44+
/// and the function has no `@_optimize(none)` attribute.
45+
public var shouldOptimize: Bool { bridged.shouldOptimize() }
46+
3947
public var wasDeserializedCanonical: Bool { bridged.wasDeserializedCanonical() }
4048

4149
public var isTrapNoReturn: Bool { bridged.isTrapNoReturn() }

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ struct BridgedFunction {
514514
BRIDGED_INLINE ThunkKind isThunk() const;
515515
BRIDGED_INLINE void setThunk(ThunkKind) const;
516516
BRIDGED_INLINE bool needsStackProtection() const;
517+
BRIDGED_INLINE bool shouldOptimize() const;
518+
BRIDGED_INLINE bool isReferencedInModule() const;
517519
BRIDGED_INLINE bool wasDeserializedCanonical() const;
518520
BRIDGED_INLINE void setNeedStackProtection(bool needSP) const;
519521
BRIDGED_INLINE void setIsPerformanceConstraint(bool isPerfConstraint) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,14 @@ bool BridgedFunction::needsStackProtection() const {
844844
return getFunction()->needsStackProtection();
845845
}
846846

847+
bool BridgedFunction::shouldOptimize() const {
848+
return getFunction()->shouldOptimize();
849+
}
850+
851+
bool BridgedFunction::isReferencedInModule() const {
852+
return getFunction()->getRefCount() != 0;
853+
}
854+
847855
bool BridgedFunction::wasDeserializedCanonical() const {
848856
return getFunction()->wasDeserializedCanonical();
849857
}

0 commit comments

Comments
 (0)