mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Based on prior evaluation, this optimization always increases code size. It splits out blocks and introduces calls, which always adds extra instructions to shuffle values for calling conventions and to make the actual call/return. Apple clang avoids the optimization in `-Oz`, which I think is pretty close to what Swift's `-Osize` really means.
43 lines
1.3 KiB
Swift
43 lines
1.3 KiB
Swift
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
|
|
// RUN: -enable-throws-prediction -O -enable-split-cold-code \
|
|
// RUN: | %FileCheck --check-prefix CHECK-ENABLED %s
|
|
|
|
//// Test disabling just the pass doesn't yield a split.
|
|
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
|
|
// RUN: -enable-throws-prediction -O -disable-split-cold-code \
|
|
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
|
|
|
|
//// Test using -Osize doesn't yield a split.
|
|
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
|
|
// RUN: -enable-throws-prediction -Osize -enable-split-cold-code \
|
|
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
|
|
|
|
//// Test disabling optimization entirely doesn't yield a split.
|
|
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
|
|
// RUN: -enable-throws-prediction -enable-split-cold-code \
|
|
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
|
|
|
|
|
|
// CHECK-ENABLED: cold
|
|
|
|
// CHECK-DISABLED-NOT: cold
|
|
|
|
enum MyError: Error { case err }
|
|
|
|
func getRandom(_ b: Bool) throws -> Int {
|
|
if b {
|
|
return Int.random(in: 0..<1024)
|
|
} else {
|
|
throw MyError.err
|
|
}
|
|
}
|
|
|
|
public func numberWithLogging(_ b: Bool) -> Int {
|
|
do {
|
|
return try getRandom(b)
|
|
} catch {
|
|
print("Log: random number generator failed with b=\(b)")
|
|
return 1337
|
|
}
|
|
}
|