Skip to content

Commit d2e1a0d

Browse files
Merge pull request swiftlang#18711 from aschwaighofer/renable_inlining_isOSVersionAtLeast
Re-enable inlining of the _stdlib_isOSVersionAtLeast macro
2 parents bc3189a + 8993b0d commit d2e1a0d

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,20 @@ class HoistAllocStack {
332332
};
333333
} // end anonymous namespace
334334

335+
bool indicatesDynamicAvailabilityCheckUse(SILInstruction *I) {
336+
auto *Apply = dyn_cast<ApplyInst>(I);
337+
if (!Apply)
338+
return false;
339+
if (Apply->hasSemantics("availability.osversion"))
340+
return true;
341+
auto *FunRef = Apply->getReferencedFunction();
342+
if (!FunRef)
343+
return false;
344+
if (FunRef->getName().equals("_swift_stdlib_operatingSystemVersion"))
345+
return true;
346+
return false;
347+
}
348+
335349
/// Collect generic alloc_stack instructions in the current function can be
336350
/// hoisted.
337351
/// We can hoist generic alloc_stack instructions if they are not dependent on a
@@ -349,11 +363,9 @@ void HoistAllocStack::collectHoistableInstructions() {
349363
continue;
350364
}
351365
// Don't perform alloc_stack hoisting in functions with availability.
352-
if (auto *Apply = dyn_cast<ApplyInst>(&Inst)) {
353-
if (Apply->hasSemantics("availability.osversion")) {
354-
AllocStackToHoist.clear();
355-
return;
356-
}
366+
if (indicatesDynamicAvailabilityCheckUse(&Inst)) {
367+
AllocStackToHoist.clear();
368+
return;
357369
}
358370
auto *ASI = dyn_cast<AllocStackInst>(&Inst);
359371
if (!ASI) {

stdlib/public/core/Availability.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ import SwiftShims
1717
///
1818
/// This is a magic entry point known to the compiler. It is called in
1919
/// generated code for API availability checking.
20-
/// Note: It is important not to make this function inlinable. There is a pass
21-
/// that relies on being able to tell whether this function is called. It does
22-
/// this using the semantics attribute.
2320
@_semantics("availability.osversion")
24-
@inline(never)
21+
@inlinable
2522
public func _stdlib_isOSVersionAtLeast(
2623
_ major: Builtin.Word,
2724
_ minor: Builtin.Word,
2825
_ patch: Builtin.Word
2926
) -> Builtin.Int1 {
3027
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
28+
// The call to _swift_stdlib_operatingSystemVersion is used as an indicator
29+
// that this function was called by a compiler optimization pass. If it is
30+
// replaced that pass needs to be updated.
3131
let runningVersion = _swift_stdlib_operatingSystemVersion()
3232
let queryVersion = _SwiftNSOperatingSystemVersion(
3333
majorVersion: Int(major),

test/IRGen/availability.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -emit-ir | %FileCheck %s
2-
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -O -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -O -emit-ir | %FileCheck %s --check-prefix=OPT
33

44
// REQUIRES: objc_interop
55

@@ -13,6 +13,11 @@ import Foundation
1313
// CHECK: call swiftcc i1 @"$Ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF"(
1414
// CHECK: S10Foundation11MeasurementVySo17NSUnitTemperature
1515

16+
// OPT-LABEL: define{{.*}} @{{.*}}dontHoist
17+
// OPT-NOT: S10Foundation11MeasurementVySo17NSUnitTemperature
18+
// OPT: call {{.*}} @_swift_stdlib_operatingSystemVersion(
19+
// OPT: S10Foundation11MeasurementVySo17NSUnitTemperature
20+
1621
public func dontHoist() {
1722
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
1823
let measurement = Measurement<UnitTemperature>(value: Double(42), unit: .celsius)

0 commit comments

Comments
 (0)