[llvm] [ctx_prof] Add Inlining support (PR #106154)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 21:17:37 PDT 2024


================
@@ -0,0 +1,101 @@
+; RUN: rm -rf %t
+; RUN: split-file %s %t
+; RUN: llvm-ctxprof-util fromJSON --input=%t/profile.json --output=%t/profile.ctxprofdata
+
+; RUN: opt -passes='module-inline,print<ctx-prof-analysis>' %t/module.ll -S \
+; RUN:   -use-ctx-profile=%t/profile.ctxprofdata -ctx-profile-printer-level=json \
+; RUN:   -o - 2> %t/profile-final.txt | FileCheck %s
+; RUN: %python %S/json_equals.py %t/profile-final.txt %t/expected.json
+
+; CHECK-LABEL: @entrypoint
+; CHECK-LABEL: yes:
+; CHECK:         call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 1)
+; CHECK-NEXT:    br label %loop.i
+; CHECK-LABEL:  loop.i:
+; CHECK-NEXT:    %indvar.i = phi i32 [ %indvar.next.i, %loop.i ], [ 0, %yes ]
+; CHECK-NEXT:    call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 2, i32 3)
+; CHECK-NEXT:    %b.i = add i32 %x, %indvar.i
+; CHECK-NEXT:    call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 1, i32 2, ptr @b)
+; CHECK-NEXT:    %call3.i = call i32 @b() #1
+; CHECK-LABEL: no:
+; CHECK-NEXT:    call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 2)
+; CHECK-NEXT:    call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 2, i32 1, ptr @a)
+; CHECK-NEXT:    %call2 = call i32 @a(i32 %x) #1
+; CHECK-NEXT:    br label %exit
+
+
+;--- module.ll
+define i32 @entrypoint(i32 %x) !guid !0 {
+  call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 0)
+  %t = icmp eq i32 %x, 0
----------------
minglotus-6 wrote:

Naive question, is it intended that `llvm.instrprof.increment` intrinsic (https://llvm.org/docs/LangRef.html#llvm-instrprof-increment-intrinsic) show up in a profile-use IR?

https://github.com/llvm/llvm-project/pull/106154


More information about the llvm-commits mailing list