Skip to content

Commit c749f37

Browse files
committed
[ownership] Add new OwnershipEliminatorPass that does not run when the current module is the stdlib.
As part of bringing up ossa on the rest of the optimizer, I am going to be first moving ossa back for the stdlib module since the stdlib module does not have any sil based dependencies. To do so, I am adding this pass that I can place at the beginning of the pipeline (where NonTransparentFunctionOwnershipModelEliminator runs today) and then move NonTransparentFunctionOwnershipModelEliminator down as I update passes. If we are processing the stdlib, the ome doesn't run early and instead runs late. If we are not processing the stdlib, we perform first an OME run early and then perform an additional OME run that does nothing since lowering ownership is an idempotent operation.
1 parent f7fd83d commit c749f37

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ PASS(OwnershipModelEliminator, "ownership-model-eliminator",
248248
PASS(NonTransparentFunctionOwnershipModelEliminator,
249249
"non-transparent-func-ownership-model-eliminator",
250250
"Eliminate Ownership Annotations from non-transparent SIL Functions")
251+
PASS(NonStdlibNonTransparentFunctionOwnershipModelEliminator,
252+
"non-stdlib-non-transparent-func-ownership-model-eliminator",
253+
"Eliminate Ownership Annotations from non-transparent SIL Functions only when not processing the stdlib.")
251254
PASS(RCIdentityDumper, "rc-id-dumper",
252255
"Print Reference Count Identities")
253256
PASS(AlwaysInlineInliner, "always-inline",

lib/SILOptimizer/Mandatory/OwnershipModelEliminator.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,24 @@ namespace {
362362

363363
struct OwnershipModelEliminator : SILModuleTransform {
364364
bool SkipTransparent;
365+
bool SkipStdlibModule;
365366

366-
OwnershipModelEliminator(bool SkipTransparent)
367-
: SkipTransparent(SkipTransparent) {}
367+
OwnershipModelEliminator(bool SkipTransparent, bool SkipStdlibModule)
368+
: SkipTransparent(SkipTransparent), SkipStdlibModule(SkipStdlibModule) {}
368369

369370
void run() override {
370371
if (DumpBefore.size()) {
371372
getModule()->dump(DumpBefore.c_str());
372373
}
373374

374375
auto &Mod = *getModule();
376+
377+
// If we are supposed to skip the stdlib module and we are in the stdlib
378+
// module bail.
379+
if (SkipStdlibModule && Mod.isStdlibModule()) {
380+
return;
381+
}
382+
375383
for (auto &F : Mod) {
376384
// If F does not have ownership, skip it. We have no further work to do.
377385
if (!F.hasOwnership())
@@ -429,9 +437,17 @@ struct OwnershipModelEliminator : SILModuleTransform {
429437
} // end anonymous namespace
430438

431439
SILTransform *swift::createOwnershipModelEliminator() {
432-
return new OwnershipModelEliminator(false /*skip transparent*/);
440+
return new OwnershipModelEliminator(false /*skip transparent*/,
441+
false /*ignore stdlib*/);
433442
}
434443

435444
SILTransform *swift::createNonTransparentFunctionOwnershipModelEliminator() {
436-
return new OwnershipModelEliminator(true /*skip transparent*/);
445+
return new OwnershipModelEliminator(true /*skip transparent*/,
446+
false /*ignore stdlib*/);
447+
}
448+
449+
SILTransform *
450+
swift::createNonStdlibNonTransparentFunctionOwnershipModelEliminator() {
451+
return new OwnershipModelEliminator(true /*skip transparent*/,
452+
true /*ignore stdlib*/);
437453
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-sil-opt -non-stdlib-non-transparent-func-ownership-model-eliminator %s | %FileCheck %s
2+
// RUN: %target-sil-opt -non-stdlib-non-transparent-func-ownership-model-eliminator %s -module-name Swift | %FileCheck -check-prefix=STDLIB-CHECK %s
3+
4+
// CHECK-NOT: [ossa]
5+
// STDLIB-CHECK: [ossa]
6+
7+
sil_stage canonical
8+
9+
sil [ossa] @my_ossa : $@convention(thin) () -> () {
10+
bb0:
11+
%9999 = tuple()
12+
return %9999 : $()
13+
}

0 commit comments

Comments
 (0)