Skip to content

Commit 1375dd0

Browse files
committed
[ownership] Add a specialized version of ome that skips transparent functions.
This will let me strip ownership from non-transparent functions at the beginning of the perf pipeline. Then after we serialize, I will run OME on the transparent functions. Otherwise, we can not perform mandatory inlining successfully since we can not inline ossa into non-ossa functions.
1 parent 87b66e7 commit 1375dd0

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ PASS(Outliner, "outliner",
226226
"Function Outlining Optimization")
227227
PASS(OwnershipModelEliminator, "ownership-model-eliminator",
228228
"Eliminate Ownership Annotation of SIL")
229+
PASS(NonTransparentFunctionOwnershipModelEliminator,
230+
"non-transparent-func-ownership-model-eliminator",
231+
"Eliminate Ownership Annotations from non-transparent SIL Functions")
229232
PASS(RCIdentityDumper, "rc-id-dumper",
230233
"Print Reference Count Identities")
231234
PASS(PerfInliner, "inline",

lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ bool OwnershipModelEliminatorVisitor::visitDestructureTupleInst(
287287
namespace {
288288

289289
struct OwnershipModelEliminator : SILModuleTransform {
290+
bool SkipTransparent;
291+
292+
OwnershipModelEliminator(bool SkipTransparent)
293+
: SkipTransparent(SkipTransparent) {}
294+
290295
void run() override {
291296
if (DumpBefore.size()) {
292297
getModule()->dump(DumpBefore.c_str());
@@ -297,6 +302,11 @@ struct OwnershipModelEliminator : SILModuleTransform {
297302
if (!F.hasOwnership())
298303
continue;
299304

305+
// If we were asked to not strip ownership from transparent functions,
306+
// continue.
307+
if (SkipTransparent && F.isTransparent())
308+
continue;
309+
300310
// Set F to have unqualified ownership.
301311
F.setOwnershipEliminated();
302312

@@ -334,5 +344,9 @@ struct OwnershipModelEliminator : SILModuleTransform {
334344
} // end anonymous namespace
335345

336346
SILTransform *swift::createOwnershipModelEliminator() {
337-
return new OwnershipModelEliminator();
347+
return new OwnershipModelEliminator(false /*skip transparent*/);
348+
}
349+
350+
SILTransform *swift::createNonTransparentFunctionOwnershipModelEliminator() {
351+
return new OwnershipModelEliminator(true /*skip transparent*/);
338352
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-sil-opt -enable-sil-ownership -non-transparent-func-ownership-model-eliminator %s | %FileCheck %s
2+
3+
sil_stage raw
4+
5+
import Builtin
6+
7+
// CHECK-LABEL: sil [transparent] [ossa] @foo : $@convention(thin) () -> () {
8+
sil [transparent] [ossa] @foo : $@convention(thin) () -> () {
9+
bb0:
10+
%9999 = tuple()
11+
return %9999 : $()
12+
}
13+
14+
// CHECK-LABEL: sil @bar : $@convention(thin) () -> () {
15+
sil [ossa] @bar : $@convention(thin) () -> () {
16+
bb0:
17+
%9999 = tuple()
18+
return %9999 : $()
19+
}

0 commit comments

Comments
 (0)