Skip to content

Commit bc3dd8c

Browse files
authored
Merge pull request swiftlang#32279 from gottesmm/pr-153bb098e8dbcdf855bdfe38c150f4de7e1e3220
[ownership] Add new OwnershipEliminatorPass that does not run when the current module is the stdlib.
2 parents 713c76b + c749f37 commit bc3dd8c

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)