Files
swift-mirror/test/Profiler/pgo_switchenum.swift
Michael Gottesman f854547c55 [ownership] Enable ownership verification by default.
I also removed the -verify-sil-ownership flag in favor of a disable flag
-disable-sil-ownership-verifier. I used this on only two tests that still need
work to get them to pass with ownership, but whose problems are well understood,
small corner cases. I am going to fix them in follow on commits. I detail them
below:

1. SILOptimizer/definite_init_inout_super_init.swift. This is a test case where
DI is supposed to error. The only problem is that we crash before we error since
the code emitting by SILGen to trigger this error does not pass ownership
invariants. I have spoken with JoeG about this and he suggested that I fix this
earlier in the compiler. Since we do not run the ownership verifier without
asserts enabled, this should not affect compiler users. Given that it has
triggered DI errors previously I think it is safe to disable ownership here.

2. PrintAsObjC/extensions.swift. In this case, the signature generated by type
lowering for one of the thunks here uses an unsafe +0 return value instead of
doing an autorelease return. The ownership checker rightly flags this leak. This
is going to require either an AST level change or a change to TypeLowering. I
think it is safe to turn this off since it is such a corner case that it was
found by a test that has nothing to do with it.

rdar://43398898
2019-03-25 00:11:52 -07:00

106 lines
4.7 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -profile-generate -Xfrontend -disable-incremental-llvm-codegen -module-name pgo_switchenum -o %t/main
// This unusual use of 'sh' allows the path of the profraw file to be
// substituted by %target-run.
// RUN: %target-run sh -c 'env LLVM_PROFILE_FILE=$1 $2' -- %t/default.profraw %t/main
// RUN: %llvm-profdata merge %t/default.profraw -o %t/default.profdata
// need to move counts attached to expr for this
// RUN: %target-swift-frontend %s -Xllvm -sil-full-demangle -profile-use=%t/default.profdata -emit-sorted-sil -emit-sil -module-name pgo_switchenum -o - | %FileCheck %s --check-prefix=SIL
// need to lower switch_enum(addr) into IR for this
// %target-swift-frontend %s -Xllvm -sil-full-demangle -profile-use=%t/default.profdata -emit-ir -module-name pgo_switchenum -o - | %FileCheck %s --check-prefix=IR
// need to check Opt support
// %target-swift-frontend %s -Xllvm -sil-full-demangle -profile-use=%t/default.profdata -O -emit-sorted-sil -emit-sil -module-name pgo_switchenum -o - | %FileCheck %s --check-prefix=SIL-OPT
// need to lower switch_enum(addr) into IR for this
// %target-swift-frontend %s -Xllvm -sil-full-demangle -profile-use=%t/default.profdata -O -emit-ir -module-name pgo_switchenum -o - | %FileCheck %s --check-prefix=IR-OPT
// REQUIRES: profile_runtime
// REQUIRES: executable_test
// REQUIRES: OS=macosx
public enum MaybePair {
case Neither
case Left(Int32)
case Right(String)
case Both(Int32, String)
}
// SIL-LABEL: // pgo_switchenum.guess1
// SIL-LABEL: sil @$s14pgo_switchenum6guess11xs5Int32VAA9MaybePairO_tF : $@convention(thin) (@guaranteed MaybePair) -> Int32 !function_entry_count(5011) {
// IR-LABEL: define swiftcc i32 @$s9pgo_switchenum6guess1s5Int32VAD1x_tF
// IR-OPT-LABEL: define swiftcc i32 @$s9pgo_switchenum6guess1s5Int32VAD1x_tF
public func guess1(x: MaybePair) -> Int32 {
// SIL: switch_enum {{.*}} : $MaybePair, case #MaybePair.Neither!enumelt: {{.*}} !case_count(2), case #MaybePair.Left!enumelt.1: {{.*}} !case_count(5001), case #MaybePair.Right!enumelt.1: {{.*}} !case_count(3), case #MaybePair.Both!enumelt.1: {{.*}} !case_count(5)
// SIL-OPT: switch_enum {{.*}} : $MaybePair, case #MaybePair.Neither!enumelt: {{.*}} !case_count(2), case #MaybePair.Left!enumelt.1: {{.*}} !case_count(5001), case #MaybePair.Right!enumelt.1: {{.*}} !case_count(3), case #MaybePair.Both!enumelt.1: {{.*}} !case_count(5)
switch x {
case .Neither:
return 1
case let .Left(val):
return val*2
case let .Right(val):
return Int32(val.count)
case let .Both(valNum, valStr):
return valNum + Int32(valStr.count)
}
}
// SIL-LABEL: // pgo_switchenum.guess2
// SIL-LABEL: sil @$s14pgo_switchenum6guess21xs5Int32VAA9MaybePairO_tF : $@convention(thin) (@guaranteed MaybePair) -> Int32 !function_entry_count(5011) {
public func guess2(x: MaybePair) -> Int32 {
// SIL: switch_enum {{.*}} : $MaybePair, case #MaybePair.Neither!enumelt: {{.*}} !case_count(2), case #MaybePair.Left!enumelt.1: {{.*}} !case_count(5001), default {{.*}} !default_count(8)
// SIL-OPT: switch_enum {{.*}} : $MaybePair, case #MaybePair.Neither!enumelt: {{.*}} !case_count(2), case #MaybePair.Left!enumelt.1: {{.*}} !case_count(5001), default {{.*}} !default_count(8)
switch x {
case .Neither:
return 1
case let .Left(val):
return val*2
default:
return 42;
}
}
func main() {
var guesses : Int32 = 0;
guesses += guess1(x: MaybePair.Neither)
guesses += guess1(x: MaybePair.Neither)
guesses += guess1(x: MaybePair.Left(42))
guesses += guess1(x: MaybePair.Right("The Answer"))
guesses += guess1(x: MaybePair.Right("The Answer"))
guesses += guess1(x: MaybePair.Right("The Answer"))
guesses += guess1(x: MaybePair.Both(42, "The Answer"))
guesses += guess1(x: MaybePair.Both(42, "The Answer"))
guesses += guess1(x: MaybePair.Both(42, "The Answer"))
guesses += guess1(x: MaybePair.Both(42, "The Answer"))
guesses += guess1(x: MaybePair.Both(42, "The Answer"))
for _ in 1...5000 {
guesses += guess1(x: MaybePair.Left(10))
}
guesses += guess2(x: MaybePair.Neither)
guesses += guess2(x: MaybePair.Neither)
guesses += guess2(x: MaybePair.Left(42))
guesses += guess2(x: MaybePair.Right("The Answer"))
guesses += guess2(x: MaybePair.Right("The Answer"))
guesses += guess2(x: MaybePair.Right("The Answer"))
guesses += guess2(x: MaybePair.Both(42, "The Answer"))
guesses += guess2(x: MaybePair.Both(42, "The Answer"))
guesses += guess2(x: MaybePair.Both(42, "The Answer"))
guesses += guess2(x: MaybePair.Both(42, "The Answer"))
guesses += guess2(x: MaybePair.Both(42, "The Answer"))
for _ in 1...5000 {
guesses += guess2(x: MaybePair.Left(10))
}
}
main()
// IR: !{!"branch_weights", i32 5001, i32 3}
// IR-OPT: !{!"branch_weights", i32 5001, i32 3}