Skip to content

Commit 3b239b2

Browse files
committed
swift SIL: add Function thunk APIs
* `var thunkKind` * `set(thunkKind:)`
1 parent 250e268 commit 3b239b2

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,16 @@ extension Function {
610610
bridged.setNeedStackProtection(needStackProtection)
611611
}
612612

613+
func set(thunkKind: ThunkKind, _ context: FunctionPassContext) {
614+
context.notifyEffectsChanged()
615+
switch thunkKind {
616+
case .noThunk: bridged.setThunk(.IsNotThunk)
617+
case .thunk: bridged.setThunk(.IsThunk)
618+
case .reabstractionThunk: bridged.setThunk(.IsReabstractionThunk)
619+
case .signatureOptimizedThunk: bridged.setThunk(.IsSignatureOptimizedThunk)
620+
}
621+
}
622+
613623
func fixStackNesting(_ context: FunctionPassContext) {
614624
context._bridged.fixStackNesting(bridged)
615625
}

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
261261
public var isSerialized: Bool { bridged.isSerialized() }
262262
public var hasValidLinkageForFragileRef: Bool { bridged.hasValidLinkageForFragileRef() }
263263

264+
public enum ThunkKind {
265+
case noThunk, thunk, reabstractionThunk, signatureOptimizedThunk
266+
}
267+
268+
var thunkKind: ThunkKind {
269+
switch bridged.isThunk() {
270+
case .IsNotThunk: return .noThunk
271+
case .IsThunk: return .thunk
272+
case .IsReabstractionThunk: return .reabstractionThunk
273+
case .IsSignatureOptimizedThunk: return .signatureOptimizedThunk
274+
default:
275+
fatalError()
276+
}
277+
}
278+
264279
/// True, if the function runs with a swift 5.1 runtime.
265280
/// Note that this is function specific, because inlinable functions are de-serialized
266281
/// in a client module, which might be compiled with a different deployment target.

include/swift/SIL/SILBridging.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,13 @@ struct BridgedFunction {
499499
AlwaysInline
500500
};
501501

502+
enum class ThunkKind {
503+
IsNotThunk,
504+
IsThunk,
505+
IsReabstractionThunk,
506+
IsSignatureOptimizedThunk
507+
};
508+
502509
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE swift::SILFunction * _Nonnull getFunction() const;
503510
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
504511
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
@@ -531,6 +538,8 @@ struct BridgedFunction {
531538
BRIDGED_INLINE InlineStrategy getInlineStrategy() const;
532539
BRIDGED_INLINE bool isSerialized() const;
533540
BRIDGED_INLINE bool hasValidLinkageForFragileRef() const;
541+
BRIDGED_INLINE ThunkKind isThunk() const;
542+
BRIDGED_INLINE void setThunk(ThunkKind) const;
534543
BRIDGED_INLINE bool needsStackProtection() const;
535544
BRIDGED_INLINE void setNeedStackProtection(bool needSP) const;
536545
BRIDGED_INLINE bool isResilientNominalDecl(BridgedNominalTypeDecl decl) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,14 @@ BridgedFunction::InlineStrategy BridgedFunction::getInlineStrategy() const {
648648
return (InlineStrategy)getFunction()->getInlineStrategy();
649649
}
650650

651+
BridgedFunction::ThunkKind BridgedFunction::isThunk() const {
652+
return (ThunkKind)getFunction()->isThunk();
653+
}
654+
655+
void BridgedFunction::setThunk(ThunkKind kind) const {
656+
getFunction()->setThunk((swift::IsThunk_t)kind);
657+
}
658+
651659
bool BridgedFunction::isSerialized() const {
652660
return getFunction()->isSerialized();
653661
}

lib/SIL/Utils/SILBridging.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ static_assert((int)BridgedFunction::InlineStrategy::InlineDefault == (int)swift:
221221
static_assert((int)BridgedFunction::InlineStrategy::NoInline == (int)swift::NoInline);
222222
static_assert((int)BridgedFunction::InlineStrategy::AlwaysInline == (int)swift::AlwaysInline);
223223

224+
static_assert((int)BridgedFunction::ThunkKind::IsNotThunk == (int)swift::IsNotThunk);
225+
static_assert((int)BridgedFunction::ThunkKind::IsThunk == (int)swift::IsThunk);
226+
static_assert((int)BridgedFunction::ThunkKind::IsReabstractionThunk == (int)swift::IsReabstractionThunk);
227+
static_assert((int)BridgedFunction::ThunkKind::IsSignatureOptimizedThunk == (int)swift::IsSignatureOptimizedThunk);
228+
224229
BridgedOwnedString BridgedFunction::getDebugDescription() const {
225230
std::string str;
226231
llvm::raw_string_ostream os(str);

0 commit comments

Comments
 (0)