Skip to content

Commit f985b0e

Browse files
committed
[thunk-lowering] Add a pass that performs lowering of ThunkInsts.
Right now it just handles the "identity" case so we can validate the functionality.
1 parent 561662d commit f985b0e

File tree

7 files changed

+1362
-0
lines changed

7 files changed

+1362
-0
lines changed

include/swift/SIL/SILModule.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,13 @@ class SILModule {
644644
return {functions.begin(), functions.end()};
645645
}
646646

647+
/// Move \p fn to be in the function list before \p moveBefore.
648+
void moveBefore(SILModule::iterator moveBefore, SILFunction *fn);
649+
650+
/// Move \p fn to be in the function list after \p moveAfter. It is assumed
651+
/// that \p moveAfter is not end.
652+
void moveAfter(SILModule::iterator moveAfter, SILFunction *fn);
653+
647654
const_iterator zombies_begin() const { return zombieFunctions.begin(); }
648655
const_iterator zombies_end() const { return zombieFunctions.end(); }
649656

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ SWIFT_FUNCTION_PASS(UpdateBorrowedFrom, "update-borrowed-from",
510510
"Test pass for update borrowed-from instructions")
511511
PASS(DiagnoseUnnecessaryPreconcurrencyImports, "sil-diagnose-unnecessary-preconcurrency-imports",
512512
"Diagnose any preconcurrency imports that Sema and TransferNonSendable did not use")
513+
PASS(ThunkLowering, "sil-thunk-lowering",
514+
"Lower thunk instructions to actual thunks")
513515
PASS(PruneVTables, "prune-vtables",
514516
"Mark class methods that do not require vtable dispatch")
515517
PASS_RANGE(AllPasses, AliasInfoDumper, PruneVTables)

lib/SIL/IR/SILModule.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,26 @@ void SILModule::performOnceForPrespecializedImportedExtensions(
940940
prespecializedFunctionDeclsImported = true;
941941
}
942942

943+
void SILModule::moveBefore(SILModule::iterator moveAfter, SILFunction *fn) {
944+
assert(&fn->getModule() == this);
945+
assert(&moveAfter->getModule() == this);
946+
assert(moveAfter != end() &&
947+
"We assume that moveAfter must not be end since nothing is after end");
948+
949+
getFunctionList().remove(fn->getIterator());
950+
getFunctionList().insert(moveAfter, fn);
951+
}
952+
953+
void SILModule::moveAfter(SILModule::iterator moveAfter, SILFunction *fn) {
954+
assert(&fn->getModule() == this);
955+
assert(&moveAfter->getModule() == this);
956+
assert(moveAfter != end() &&
957+
"We assume that moveAfter must not be end since nothing is after end");
958+
959+
getFunctionList().remove(fn->getIterator());
960+
getFunctionList().insertAfter(moveAfter, fn);
961+
}
962+
943963
SILProperty *
944964
SILProperty::create(SILModule &M, unsigned Serialized, AbstractStorageDecl *Decl,
945965
std::optional<KeyPathPatternComponent> Component) {

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ target_sources(swiftSILOptimizer PRIVATE
4444
PMOMemoryUseCollector.cpp
4545
RawSILInstLowering.cpp
4646
ReferenceBindingTransform.cpp
47+
ThunkLowering.cpp
4748
TransferNonSendable.cpp
4849
LowerTupleAddrConstructor.cpp
4950
SILGenCleanup.cpp

0 commit comments

Comments
 (0)