-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SILOptimizer: Allow inlining of transparent functions in @backDeployed
thunks
#76135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tshortli
merged 4 commits into
swiftlang:main
from
tshortli:backdeployed-ios-apps-on-macos
Aug 29, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2b46c01
Tests: Use %target-cpu in availability_query_maccatalyst_zippered.swift.
tshortli 51143aa
stdlib: Upstream _stdlib_isOSVersionAtLeast_AEIC().
tshortli 7ad12d7
IRGen: Adjust tests for upstreaming of _stdlib_isOSVersionAtLeast_AEI…
tshortli 789b795
SILOptimizer: Allow inlining of transparent functions in @backDeploye…
tshortli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@backDeployed(before: SwiftStdlib 6.0) | ||
public func backDeployedFunc() { | ||
otherFunc() | ||
} | ||
|
||
@usableFromInline internal func otherFunc() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s | ||
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=OPT | ||
|
||
// On iOS _stdlib_isOSVersionAtLeast() is @_transparent, which affects optimization. | ||
// See IRGen/availability.swift for other Apple platforms. | ||
// REQUIRES: OS=ios | ||
|
||
import Foundation | ||
|
||
// We mustn't hoist the alloc_stack for measurement out of the availability | ||
// guard. | ||
|
||
// CHECK-LABEL: define{{.*}} @{{.*}}dontHoist | ||
// CHECK-NOT: s10Foundation11MeasurementVySo17NSUnitTemperature | ||
// CHECK: call swiftcc i1 @"$ss31_stdlib_isOSVersionAtLeast_AEICyBi1_Bw_BwBwtF"( | ||
// CHECK: s10Foundation11MeasurementVySo17NSUnitTemperature | ||
|
||
// OPT-LABEL: define{{.*}} @{{.*}}dontHoist | ||
// OPT-NOT: S10Foundation11MeasurementVySo17NSUnitTemperature | ||
// OPT: call {{.*}} @__isPlatformVersionAtLeast( | ||
// OPT: s10Foundation11MeasurementVySo17NSUnitTemperature | ||
|
||
public func dontHoist() { | ||
if #available(macOS 51.0, iOS 54.0, watchOS 57.0, tvOS 54.0, visionOS 51.1, *) { | ||
let measurement = Measurement<UnitTemperature>(value: Double(42), unit: .celsius) | ||
print("\(measurement)") | ||
} else { | ||
print("Not measurement") | ||
} | ||
} | ||
|
||
|
||
// Now that _isOSVersionAtLeast is no longer inlinable, we do still | ||
// mark it as _effects(readnone). | ||
// This means that unlike in the past the optimizer can now only coalesce | ||
// availability checks with the same availability. It does not determine, | ||
// for example, that a check for iOS 10 is sufficient to guarantee that a check | ||
// for iOS 9 will also succeed. | ||
|
||
// With optimizations on, multiple #availability checks should generate only | ||
// a single call into _isOSVersionAtLeast, which after inlining will be a | ||
// call to __isPlatformVersionAtLeast. | ||
|
||
// CHECK-LABEL: define{{.*}} @{{.*}}multipleAvailabilityChecks | ||
// CHECK: call swiftcc i1 @"$ss31_stdlib_isOSVersionAtLeast_AEICyBi1_Bw_BwBwtF"( | ||
// CHECK: call swiftcc i1 @"$ss31_stdlib_isOSVersionAtLeast_AEICyBi1_Bw_BwBwtF"( | ||
// CHECK: call swiftcc i1 @"$ss31_stdlib_isOSVersionAtLeast_AEICyBi1_Bw_BwBwtF"( | ||
// CHECK: ret void | ||
|
||
// OPT-LABEL: define{{.*}} @{{.*}}multipleAvailabilityChecks | ||
// OPT: call {{.*}} @__isPlatformVersionAtLeast | ||
// OPT-NOT: call {{.*}} @$__isPlatformVersionAtLeast | ||
// OPT: ret void | ||
public func multipleAvailabilityChecks() { | ||
if #available(macOS 51.0, iOS 54.0, watchOS 57.0, tvOS 54.0, visionOS 51.1, *) { | ||
print("test one") | ||
} | ||
if #available(macOS 51.0, iOS 54.0, watchOS 57.0, tvOS 54.0, visionOS 51.1, *) { | ||
print("test two") | ||
} | ||
if #available(macOS 51.0, iOS 54.0, watchOS 57.0, tvOS 54.0, visionOS 51.1, *) { | ||
print("test three") | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend -emit-module %S/Inputs/back_deployed.swift -o %t/ -swift-version 5 -enable-library-evolution | ||
// RUN: %target-swift-frontend -emit-ir %s -I %t -Onone | %FileCheck %s | ||
|
||
// _stdlib_isOSVersionAtLeast() is not @_transparent on macOS, watchOS, and tvOS | ||
// REQUIRES: OS=macosx || OS=watchos || OS=tvos | ||
|
||
import back_deployed | ||
|
||
public func test() { | ||
backDeployedFunc() | ||
} | ||
|
||
// CHECK: define{{.*}} hidden swiftcc void @"$s13back_deployed0A12DeployedFuncyyFTwb" | ||
// CHECK: call swiftcc i1 @"$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF" | ||
// CHECK: call swiftcc void @"$s13back_deployed0A12DeployedFuncyyFTwB" | ||
// CHECK: call swiftcc void @"$s13back_deployed0A12DeployedFuncyyF" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend -emit-module %S/Inputs/back_deployed.swift -o %t/ -swift-version 5 -enable-library-evolution | ||
// RUN: %target-swift-frontend -emit-ir %s -I %t -Onone | %FileCheck %s | ||
|
||
// _stdlib_isOSVersionAtLeast() is @_transparent on iOS | ||
// REQUIRES: OS=ios | ||
|
||
import back_deployed | ||
|
||
public func test() { | ||
backDeployedFunc() | ||
} | ||
|
||
// CHECK: define{{.*}} hidden swiftcc void @"$s13back_deployed0A12DeployedFuncyyFTwb" | ||
// CHECK: call swiftcc i1 @"$ss31_stdlib_isOSVersionAtLeast_AEICyBi1_Bw_BwBwtF" | ||
// CHECK: call swiftcc void @"$s13back_deployed0A12DeployedFuncyyFTwB" | ||
// CHECK: call swiftcc void @"$s13back_deployed0A12DeployedFuncyyF" | ||
|
||
// CHECK: define{{.*}} hidden swiftcc i1 @"$ss31_stdlib_isOSVersionAtLeast_AEICyBi1_Bw_BwBwtF" | ||
// CHECK: call i32 @__isPlatformVersionAtLeast |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.