|
| 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