forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Profiler] Support lazy variable initializers
Start visiting LazyInitializerExpr for profiling, such that we emit a profile counter when initializing the initial value for the first time. rdar://43393937
- Loading branch information
1 parent
d915202
commit 64fcbd9
Showing
5 changed files
with
118 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,29 @@ | ||
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -profile-generate -profile-coverage-mapping -emit-sil -module-name coverage_lazy %s | %FileCheck %s | ||
// RUN: %target-swift-frontend -profile-generate -profile-coverage-mapping -emit-ir %s | ||
|
||
// Test that the crash from SR-8429 is avoided, and that we generate the | ||
// correct coverage. | ||
class C { | ||
// CHECK-LABEL: sil hidden [lazy_getter] [noinline] @$s13coverage_lazy1CC6offsetSivg : $@convention(method) (@guaranteed C) -> Int | ||
// CHECK: switch_enum {{%[0-9]+}} : $Optional<Int>, case #Optional.some!enumelt: {{bb[0-9]}}, case #Optional.none!enumelt: [[INITBB:bb[0-9]]] | ||
// CHECK: [[INITBB]] | ||
// CHECK-NEXT: string_literal | ||
// CHECK-NEXT: integer_literal $Builtin.Int64, 0 | ||
// CHECK-NEXT: integer_literal $Builtin.Int32, 4 | ||
// CHECK-NEXT: integer_literal $Builtin.Int32, 2 | ||
// CHECK-NEXT: int_instrprof_increment | ||
// CHECK: function_ref @$sSb6randomSbyFZ : $@convention(method) (@thin Bool.Type) -> Bool | ||
// CHECK: cond_br {{%[0-9]+}}, [[TRUEBB:bb[0-9]]], {{bb[0-9]}} | ||
// CHECK: [[TRUEBB]] | ||
// CHECK-NEXT: string_literal | ||
// CHECK-NEXT: integer_literal $Builtin.Int64, 0 | ||
// CHECK-NEXT: integer_literal $Builtin.Int32, 4 | ||
// CHECK-NEXT: integer_literal $Builtin.Int32, 3 | ||
|
||
// CHECK-LABEL: sil_coverage_map {{.*}} // coverage_lazy.C.offset.getter : Swift.Int | ||
// CHECK-NEXT: [[@LINE+4]]:38 -> [[@LINE+4]]:40 : 3 | ||
// CHECK-NEXT: [[@LINE+3]]:43 -> [[@LINE+3]]:45 : (2 - 3) | ||
// CHECK-NEXT: [[@LINE+2]]:26 -> [[@LINE+2]]:45 : 2 | ||
// CHECK-NEXT: } | ||
lazy var offset: Int = .random() ? 30 : 55 | ||
} |
This file contains 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,41 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-build-swift %s -profile-generate -Xfrontend -disable-incremental-llvm-codegen -module-name pgo_lazy -o %t/main | ||
|
||
// This unusual use of 'sh' allows the path of the profraw file to be | ||
// substituted by %target-run. | ||
// RUN: %target-codesign %t/main | ||
// 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 | ||
|
||
// RUN: %target-swift-frontend %s -Xllvm -sil-full-demangle -profile-use=%t/default.profdata -emit-sorted-sil -emit-sil -module-name pgo_lazy -o - | %FileCheck %s --check-prefix=SIL | ||
// RUN: %target-swift-frontend %s -Xllvm -sil-full-demangle -profile-use=%t/default.profdata -O -emit-sorted-sil -emit-sil -module-name pgo_lazy -o - | %FileCheck %s --check-prefix=SIL | ||
// RUN: %target-swift-frontend %s -Xllvm -sil-full-demangle -profile-use=%t/default.profdata -emit-ir -module-name pgo_lazy -o - | %FileCheck %s --check-prefix=IR | ||
// RUN: %target-swift-frontend %s -Xllvm -sil-full-demangle -profile-use=%t/default.profdata -O -emit-ir -module-name pgo_lazy -o - | %FileCheck %s --check-prefix=IR | ||
|
||
// REQUIRES: profile_runtime | ||
// REQUIRES: executable_test | ||
// REQUIRES: OS=macosx | ||
|
||
var cond = true | ||
|
||
public struct S { | ||
// SIL-LABEL: sil [lazy_getter] [noinline] @$s8pgo_lazy1SV1xSivg : $@convention(method) (@inout S) -> Int !function_entry_count(35) | ||
// SIL: cond_br {{.*}} !true_count(5) !false_count(30) | ||
public lazy var x = cond ? 2 : 3 | ||
} | ||
|
||
func triggerLazy() -> Int { | ||
var s = S() | ||
return s.x | ||
} | ||
public var total = 0 | ||
for _ in 0 ..< 5 { | ||
total += triggerLazy() | ||
} | ||
cond = false | ||
for _ in 0 ..< 30 { | ||
total += triggerLazy() | ||
} | ||
|
||
// IR: !{!"branch_weights", i32 6, i32 31} |