Skip to content

Commit 8d66017

Browse files
committed
[IRGenSIL] Factor out shouldUseDispatchThunk() (NFC)
1 parent 2221f45 commit 8d66017

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,9 @@ class IRGenSILFunction :
12051205
// SIL instruction lowering
12061206
//===--------------------------------------------------------------------===//
12071207

1208-
void visitSILBasicBlock(SILBasicBlock *BB);
1208+
bool shouldUseDispatchThunk(SILDeclRef method);
12091209

1210+
void visitSILBasicBlock(SILBasicBlock *BB);
12101211
void emitErrorResultVar(CanSILFunctionType FnTy,
12111212
SILResultInfo ErrorInfo,
12121213
DebugValueInst *DbgValue);
@@ -8414,17 +8415,7 @@ void IRGenSILFunction::visitObjCSuperMethodInst(swift::ObjCSuperMethodInst *i) {
84148415
/*startAtSuper=*/true);
84158416
}
84168417

8417-
void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
8418-
assert(!i->getMember().isForeign);
8419-
8420-
Explosion base = getLoweredExplosion(i->getOperand());
8421-
llvm::Value *baseValue = base.claimNext();
8422-
8423-
SILDeclRef method = i->getMember().getOverriddenVTableEntry();
8424-
PrettyStackTraceSILDeclRef entry("lowering class method call to", method);
8425-
8426-
auto methodType = i->getType().castTo<SILFunctionType>();
8427-
8418+
bool IRGenSILFunction::shouldUseDispatchThunk(SILDeclRef method) {
84288419
AccessLevel methodAccess = method.getDecl()->getEffectiveAccess();
84298420
auto *classDecl = cast<ClassDecl>(method.getDecl()->getDeclContext());
84308421
bool shouldUseDispatchThunk = false;
@@ -8452,9 +8443,22 @@ void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
84528443
shouldUseDispatchThunk =
84538444
classDecl->getModuleContext() != IGM.getSwiftModule();
84548445
}
8446+
return shouldUseDispatchThunk;
8447+
}
84558448

8456-
if (shouldUseDispatchThunk) {
8457-
llvm::Constant *fnPtr = IGM.getAddrOfDispatchThunk(method, NotForDefinition);
8449+
void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
8450+
assert(!i->getMember().isForeign);
8451+
8452+
Explosion base = getLoweredExplosion(i->getOperand());
8453+
llvm::Value *baseValue = base.claimNext();
8454+
8455+
SILDeclRef method = i->getMember().getOverriddenVTableEntry();
8456+
PrettyStackTraceSILDeclRef entry("lowering class method call to", method);
8457+
8458+
auto methodType = i->getType().castTo<SILFunctionType>();
8459+
if (shouldUseDispatchThunk(method)) {
8460+
llvm::Constant *fnPtr =
8461+
IGM.getAddrOfDispatchThunk(method, NotForDefinition);
84588462

84598463
if (methodType->isAsync()) {
84608464
auto *fnPtrType = fnPtr->getType();

0 commit comments

Comments
 (0)