Skip to content

Commit f5c8119

Browse files
committed
Address suggestions
Added tests
1 parent 08bc2e1 commit f5c8119

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
334334
inputArgs.AddLastArg(arguments, options::OPT_profile_use);
335335
inputArgs.AddLastArg(arguments, options::OPT_ir_profile_generate);
336336
inputArgs.AddLastArg(arguments, options::OPT_cs_profile_generate);
337+
inputArgs.AddLastArg(arguments, options::OPT_cs_profile_generate_EQ);
337338
inputArgs.AddLastArg(arguments, options::OPT_profile_coverage_mapping);
338339
inputArgs.AddAllArgs(arguments, options::OPT_warning_treating_Group);
339340
inputArgs.AddLastArg(arguments, options::OPT_sanitize_EQ);

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static void populatePGOOptions(std::optional<PGOOptions> &Out,
234234
if (Opts.EnableCSIRProfileGen) {
235235
const bool hasUse = !Opts.UseProfile.empty();
236236
Out = PGOOptions(
237-
/*ProfileFile=*/ hasUse ? Opts.UseProfile : "",
237+
/*ProfileFile=*/ Opts.UseProfile,
238238
/*CSProfileGenFile=*/ Opts.CSProfileGenFile,
239239
/*ProfileRemappingFile=*/ "",
240240
/*MemoryProfile=*/ "",

test/IRGen/cs_profile_generate.sil

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %target-swift-frontend -cs-profile-generate -O -emit-ir %s | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
import SwiftShims
8+
9+
sil @b : $@convention(thin) () -> ()
10+
11+
sil @c : $@convention(thin) () -> ()
12+
13+
14+
// CHECK: @__llvm_profile_runtime = external hidden global
15+
16+
// counter array (2 counters for the then/else)
17+
// CHECK: @__profc_a = {{.*}} global [2 x i64]
18+
// data record pointing at the counter array and the function
19+
// CHECK: @__profd_a = {{.*}} global {{.*}} ptr @a.local
20+
21+
22+
// CHECK: br i1 {{.*}}, label %[[THEN:[0-9]+]], label %[[ELSE:[0-9]+]]
23+
// THEN: increment counter[0] and call b()
24+
// CHECK: [[THEN]]:
25+
// CHECK: %[[L0:.*]] = load i64, ptr @__profc_a, align 8
26+
// CHECK: %[[A0:.*]] = add i64 %[[L0]], 1
27+
// CHECK: store i64 %[[A0]], ptr @__profc_a, align 8
28+
// CHECK: call swiftcc void @b()
29+
// CHECK: br label %[[MERGE:[0-9]+]]
30+
31+
// ELSE: increment counter[1] and call c()
32+
// CHECK: [[ELSE]]:
33+
// CHECK: %[[L1:.*]] = load i64, ptr getelementptr inbounds (i8, ptr @__profc_a, i64 8), align 8
34+
// CHECK: %[[A1:.*]] = add i64 %[[L1]], 1
35+
// CHECK: store i64 %[[A1]], ptr getelementptr inbounds (i8, ptr @__profc_a, i64 8), align 8
36+
// CHECK: call swiftcc void @c()
37+
// CHECK: br label %[[MERGE]]
38+
39+
// CHECK: [[MERGE]]:
40+
// CHECK: ret void
41+
42+
// CHECK: declare swiftcc void @c()
43+
// CHECK: declare swiftcc void @b()
44+
45+
sil @a : $@convention(thin) (Bool) -> () {
46+
bb0(%0 : $Bool):
47+
%2 = struct_extract %0, #Bool._value
48+
cond_br %2, bb1, bb2
49+
50+
bb1:
51+
// function_ref b()
52+
%4 = function_ref @b : $@convention(thin) () -> ()
53+
%5 = apply %4() : $@convention(thin) () -> ()
54+
br bb3
55+
56+
bb2:
57+
// function_ref c()
58+
%7 = function_ref @c: $@convention(thin) () -> ()
59+
%8 = apply %7() : $@convention(thin) () -> ()
60+
br bb3
61+
62+
bb3:
63+
%10 = tuple ()
64+
return %10
65+
}

test/IRGen/ir_profile_generate.sil

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %target-swift-frontend -ir-profile-generate -emit-ir %s | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
import SwiftShims
8+
9+
sil @b : $@convention(thin) () -> ()
10+
11+
sil @c : $@convention(thin) () -> ()
12+
13+
// CHECK: @__llvm_profile_runtime = external hidden global
14+
15+
// counter array (2 counters for the then/else)
16+
// CHECK: @__profc_a = {{.*}} global [2 x i64]
17+
// data record pointing at the counter array and the function
18+
// CHECK: @__profd_a = {{.*}} global {{.*}} ptr @a.local
19+
20+
// CHECK: br i1 {{.*}}, label %[[THEN:[0-9]+]], label %[[ELSE:[0-9]+]]
21+
22+
// THEN: increment counter[0] and call b()
23+
// CHECK: [[THEN]]:
24+
// CHECK: %[[L0:.*]] = load i64, ptr @__profc_a, align 8
25+
// CHECK: %[[A0:.*]] = add i64 %[[L0]], 1
26+
// CHECK: store i64 %[[A0]], ptr @__profc_a, align 8
27+
// CHECK: call swiftcc void @b()
28+
// CHECK: br label %[[MERGE:[0-9]+]]
29+
30+
// ELSE: increment counter[1] and call c()
31+
// CHECK: [[ELSE]]:
32+
// CHECK: %[[L1:.*]] = load i64, ptr getelementptr inbounds ([2 x i64], ptr @__profc_a, i32 0, i32 1), align 8
33+
// CHECK: %[[A1:.*]] = add i64 %[[L1]], 1
34+
// CHECK: store i64 %[[A1]], ptr getelementptr inbounds ([2 x i64], ptr @__profc_a, i32 0, i32 1), align 8
35+
// CHECK: call swiftcc void @c()
36+
// CHECK: br label %[[MERGE]]
37+
38+
// CHECK: [[MERGE]]:
39+
// CHECK: ret void
40+
41+
// CHECK: declare swiftcc void @c()
42+
// CHECK: declare swiftcc void @b()
43+
// CHECK: declare void @llvm.instrprof.increment
44+
45+
sil @a : $@convention(thin) (Bool) -> () {
46+
bb0(%0 : $Bool):
47+
%2 = struct_extract %0, #Bool._value
48+
cond_br %2, bb1, bb2
49+
50+
bb1:
51+
// function_ref b()
52+
%4 = function_ref @b : $@convention(thin) () -> ()
53+
%5 = apply %4() : $@convention(thin) () -> ()
54+
br bb3
55+
56+
bb2:
57+
// function_ref c()
58+
%7 = function_ref @c: $@convention(thin) () -> ()
59+
%8 = apply %7() : $@convention(thin) () -> ()
60+
br bb3
61+
62+
bb3:
63+
%10 = tuple ()
64+
return %10
65+
}

0 commit comments

Comments
 (0)