Skip to content

Commit 54301e4

Browse files
committed
IRGen: Update AllocStackHoisting for macCatalyst.
Teach `inhibitsAllocStackHoisting` about the `targetVariantOSVersionAtLeast` and `targetOSVersionOrVariantOSVersionAtLeast` builtins.
1 parent f7ff3f0 commit 54301e4

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ bool inhibitsAllocStackHoisting(SILInstruction *I) {
442442
return Apply->hasSemantics(semantics::AVAILABILITY_OSVERSION);
443443
}
444444
if (auto *bi = dyn_cast<BuiltinInst>(I)) {
445-
return bi->getBuiltinInfo().ID == BuiltinValueKind::TargetOSVersionAtLeast;
445+
return bi->getBuiltinInfo().ID == BuiltinValueKind::TargetOSVersionAtLeast
446+
|| bi->getBuiltinInfo().ID == BuiltinValueKind::TargetVariantOSVersionAtLeast
447+
|| bi->getBuiltinInfo().ID == BuiltinValueKind::TargetOSVersionOrVariantOSVersionAtLeast;
446448
}
447449
if (isa<HasSymbolInst>(I)) {
448450
return true;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %target-swift-frontend -target x86_64-apple-ios13.1-macabi -primary-file %s -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend -target x86_64-apple-ios13.1-macabi -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=OPT
3+
4+
// REQUIRES: objc_interop
5+
// REQUIRES: OS=macosx || OS=maccatalyst
6+
7+
import Foundation
8+
9+
10+
// We mustn't hoist the alloc_stack for measurement out of the availability
11+
// guard.
12+
13+
// CHECK-LABEL: define{{.*}} @{{.*}}dontHoist
14+
// CHECK-NOT: s10Foundation11MeasurementVySo17NSUnitTemperature
15+
// CHECK: call swiftcc i1 @"$ss33_stdlib_isVariantOSVersionAtLeastyBi1_Bw_BwBwtF"(
16+
// CHECK: s10Foundation11MeasurementVySo17NSUnitTemperature
17+
18+
// OPT-LABEL: define{{.*}} @{{.*}}dontHoist
19+
// OPT-NOT: S10Foundation11MeasurementVySo17NSUnitTemperature
20+
// OPT: call {{.*}} @"$ss33_stdlib_isVariantOSVersionAtLeastyBi1_Bw_BwBwtF"(
21+
// OPT: s10Foundation11MeasurementVySo17NSUnitTemperature
22+
23+
public func dontHoist() {
24+
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
25+
let measurement = Measurement<UnitTemperature>(value: Double(42), unit: .celsius)
26+
print("\(measurement)")
27+
} else {
28+
print("Not measurement")
29+
}
30+
}
31+
32+
// The optimizer is weaker for _isVariantOSVersionAtLeast than for _isOSVersionAtLeast
33+
// because the first is implemented in a runtime call in compiler-rt. We don't want
34+
// to inline the implementation details of the compiler-rt support into apps, so
35+
// _isVariantOSVersionAtLeast not marked as inlinable, but we do mark it as
36+
// _effects(readnone).
37+
// This means that unlike _isOSVersionAtLeast the optimizer can only coalesce
38+
// availability checks with the same availability. It does not determine, for example,
39+
// that a check for iOS 10 is sufficient to guarantee that a check for iOS 9 will also
40+
// succeed.
41+
42+
// With optimizations on, multiple #availability checks should generate only
43+
// a single call into _isVariantOSVersionAtLeast.
44+
45+
// CHECK-LABEL: define{{.*}} @{{.*}}multipleAvailabilityChecks
46+
// CHECK: call swiftcc i1 @"$ss33_stdlib_isVariantOSVersionAtLeastyBi1_Bw_BwBwtF"(
47+
// CHECK: call swiftcc i1 @"$ss33_stdlib_isVariantOSVersionAtLeastyBi1_Bw_BwBwtF"(
48+
// CHECK: call swiftcc i1 @"$ss33_stdlib_isVariantOSVersionAtLeastyBi1_Bw_BwBwtF"(
49+
// CHECK: ret void
50+
51+
// OPT-LABEL: define{{.*}} @{{.*}}multipleAvailabilityChecks
52+
// OPT: call {{.*}} @"$ss33_stdlib_isVariantOSVersionAtLeastyBi1_Bw_BwBwtF"
53+
// OPT-NOT: call {{.*}} @"$ss33_stdlib_isVariantOSVersionAtLeastyBi1_Bw_BwBwtF"
54+
// OPT: ret void
55+
public func multipleAvailabilityChecks() {
56+
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
57+
print("test one")
58+
}
59+
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
60+
print("test two")
61+
}
62+
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
63+
print("test three")
64+
}
65+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swift-frontend -primary-file %s -target x86_64-apple-macosx10.50 -target-variant x86_64-apple-ios48.0-macabi -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend -primary-file %s -target x86_64-apple-macosx10.50 -target-variant x86_64-apple-ios48.0-macabi -O -emit-ir | %FileCheck %s --check-prefix=OPT
3+
4+
// REQUIRES: objc_interop
5+
// REQUIRES: OS=macosx || OS=maccatalyst
6+
7+
// With optimizations on, multiple #availability checks should generate only
8+
// a single call into _isVariantOSVersionAtLeast.
9+
10+
// CHECK-LABEL: define{{.*}} @{{.*}}multipleAvailabilityChecks
11+
// CHECK: call swiftcc i1 @"$ss042_stdlib_isOSVersionAtLeastOrVariantVersiondE0yBi1_Bw_BwBwBwBwBwtF"(
12+
// CHECK: call swiftcc i1 @"$ss042_stdlib_isOSVersionAtLeastOrVariantVersiondE0yBi1_Bw_BwBwBwBwBwtF"(
13+
// CHECK: call swiftcc i1 @"$ss042_stdlib_isOSVersionAtLeastOrVariantVersiondE0yBi1_Bw_BwBwBwBwBwtF"(
14+
// CHECK: ret void
15+
16+
// OPT-LABEL: define{{.*}} @{{.*}}multipleAvailabilityChecks
17+
// OPT: call {{.*}} @"$ss042_stdlib_isOSVersionAtLeastOrVariantVersiondE0yBi1_Bw_BwBwBwBwBwtF"
18+
// OPT-NOT: call {{.*}} @"$ss042_stdlib_isOSVersionAtLeastOrVariantVersiondE0yBi1_Bw_BwBwBwBwBwtF"
19+
// OPT: ret void
20+
public func multipleAvailabilityChecks() {
21+
if #available(OSX 10.52, iOS 50.0, watchOS 43.0, tvOS 50.0, *) {
22+
print("test one")
23+
}
24+
if #available(OSX 10.52, iOS 50.0, watchOS 43.0, tvOS 50.0, *) {
25+
print("test two")
26+
}
27+
if #available(OSX 10.52, iOS 50.0, watchOS 43.0, tvOS 50.0, *) {
28+
print("test three")
29+
}
30+
}

0 commit comments

Comments
 (0)