Skip to content

Commit 0629afc

Browse files
committed
[func-sig-opts][+0->+1] Add a benchmark that requires the optimizer to propagate a +1 value from an opaque entry point through a simple linear call tree.
rdar://38196046
1 parent a5f44c5 commit 0629afc

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ set(SWIFT_BENCH_MODULES
109109
single-source/ObserverForwarderStruct
110110
single-source/ObserverPartiallyAppliedMethod
111111
single-source/ObserverUnappliedMethod
112+
single-source/OpaqueConsumingUsers
112113
single-source/OpenClose
113114
single-source/PartialApplyDynamicType
114115
single-source/Phonebook
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//===--- OpaqueConsumingUsers.swift ---------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
public let OpaqueConsumingUsers = BenchmarkInfo(
16+
name: "OpaqueConsumingUsers",
17+
runFunction: run_OpaqueConsumingUsers,
18+
tags: [.regression, .abstraction, .refcount],
19+
setUpFunction: setup_OpaqueConsumingUsers)
20+
21+
// This test exercises the ability of the optimizer to propagate the +1 from a
22+
// consuming argument of a non-inlineable through multiple non-inlinable call
23+
// frames.
24+
//
25+
// We are trying to simulate a user application that calls into a resilient
26+
// setter or initialization. We want to be able to propagate the +1 from the
27+
// setter through the app as far as we can.
28+
29+
class Klass {}
30+
31+
class ConsumingUser {
32+
var _innerValue: Klass = Klass()
33+
34+
var value: Klass {
35+
@inline(never) get {
36+
return _innerValue
37+
}
38+
@inline(never) set {
39+
_innerValue = newValue
40+
}
41+
}
42+
}
43+
44+
var data: Klass? = nil
45+
var user: ConsumingUser? = nil
46+
47+
func setup_OpaqueConsumingUsers() {
48+
switch (data, user) {
49+
case (let x?, let y?):
50+
let _ = x
51+
let _ = y
52+
return
53+
case (nil, nil):
54+
data = Klass()
55+
user = ConsumingUser()
56+
default:
57+
fatalError("Data and user should both be .none or .some")
58+
}
59+
}
60+
61+
@inline(never)
62+
func callFrame1(_ data: Klass, _ user: ConsumingUser) {
63+
callFrame2(data, user)
64+
}
65+
66+
@inline(never)
67+
func callFrame2(_ data: Klass, _ user: ConsumingUser) {
68+
callFrame3(data, user)
69+
}
70+
71+
@inline(never)
72+
func callFrame3(_ data: Klass, _ user: ConsumingUser) {
73+
callFrame4(data, user)
74+
}
75+
76+
@inline(never)
77+
func callFrame4(_ data: Klass, _ user: ConsumingUser) {
78+
user.value = data
79+
}
80+
81+
@inline(never)
82+
public func run_OpaqueConsumingUsers(_ N: Int) {
83+
let d = data._unsafelyUnwrappedUnchecked
84+
let u = user._unsafelyUnwrappedUnchecked
85+
for _ in 0..<N*200000 {
86+
callFrame4(d, u)
87+
}
88+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import ObserverClosure
9696
import ObserverForwarderStruct
9797
import ObserverPartiallyAppliedMethod
9898
import ObserverUnappliedMethod
99+
import OpaqueConsumingUsers
99100
import OpenClose
100101
import PartialApplyDynamicType
101102
import Phonebook
@@ -253,6 +254,7 @@ registerBenchmark(ObserverClosure)
253254
registerBenchmark(ObserverForwarderStruct)
254255
registerBenchmark(ObserverPartiallyAppliedMethod)
255256
registerBenchmark(ObserverUnappliedMethod)
257+
registerBenchmark(OpaqueConsumingUsers)
256258
registerBenchmark(OpenClose)
257259
registerBenchmark(PartialApplyDynamicType)
258260
registerBenchmark(Phonebook)

0 commit comments

Comments
 (0)