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