1; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
2; RUN: opt < %s -pgo-instr-gen -instrprof -S | FileCheck %s --check-prefix=LOWER
3
4; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
5; RUN: opt < %s -passes=pgo-instr-gen,instrprof -S | FileCheck %s --check-prefix=LOWER
6
7; This test is to verify that PGO runtime library calls get created with the
8; appropriate operand bundle funclet information when an indirect call
9; was marked with as belonging to a particular funclet.
10
11; Test case based on this source:
12;  extern void may_throw(int);
13;
14;  class base {
15;  public:
16;    base() : x(0) {};
17;    int get_x() const { return x; }
18;    virtual void update() { x++; }
19;    int x;
20;  };
21;
22;  class derived : public base {
23;  public:
24;    derived() {}
25;    virtual void update() { x--; }
26;  };
27;
28;  void run(base* b, int count) {
29;    try {
30;      may_throw(count);
31;    }
32;    catch (...) {
33;      // Virtual function call in exception handler for value profiling.
34;      b->update();
35;    }
36;  }
37
38%class.base = type { i32 (...)**, i32 }
39define dso_local void @"?run@@YAXPEAVbase@@H@Z"(%class.base* %b, i32 %count) personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
40entry:
41  invoke void @"?may_throw@@YAXH@Z"(i32 %count)
42          to label %try.cont unwind label %catch.dispatch
43
44catch.dispatch:                                   ; preds = %entry
45  %tmp = catchswitch within none [label %catch] unwind to caller
46
47catch:                                            ; preds = %catch.dispatch
48  %tmp1 = catchpad within %tmp [i8* null, i32 64, i8* null]
49  %tmp2 = bitcast %class.base* %b to void (%class.base*)***
50  %vtable = load void (%class.base*)**, void (%class.base*)*** %tmp2, align 8
51  %tmp3 = load void (%class.base*)*, void (%class.base*)** %vtable, align 8
52  call void %tmp3(%class.base* %b) [ "funclet"(token %tmp1) ]
53  catchret from %tmp1 to label %try.cont
54
55try.cont:                                         ; preds = %catch, %entry
56  ret void
57}
58
59; GEN: catch:
60; GEN: call void @llvm.instrprof.value.profile(
61; GEN-SAME: [ "funclet"(token %tmp1) ]
62
63; LOWER: catch:
64; LOWER: call void @__llvm_profile_instrument_target(
65; LOWER-SAME: [ "funclet"(token %tmp1) ]
66
67declare dso_local void @"?may_throw@@YAXH@Z"(i32)
68declare dso_local i32 @__CxxFrameHandler3(...)
69