[compiler-rt] [compiler-rt][pgo] Add profile instrumentation test for coroutines (PR #213801)
Jin Huang via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 5 21:59:12 PDT 2026
https://github.com/jinhuang1102 updated https://github.com/llvm/llvm-project/pull/213801
>From 119de54f9b38e98a0e29bcb544f1a2f4def18588 Mon Sep 17 00:00:00 2001
From: Jin Huang <jingold at google.com>
Date: Mon, 3 Aug 2026 23:30:56 +0000
Subject: [PATCH] [compiler-rt][pgo] Add profile instrumentation test for
coroutines
---
.../profile/instrprof-coroutine-profile.cpp | 46 +++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 compiler-rt/test/profile/instrprof-coroutine-profile.cpp
diff --git a/compiler-rt/test/profile/instrprof-coroutine-profile.cpp b/compiler-rt/test/profile/instrprof-coroutine-profile.cpp
new file mode 100644
index 0000000000000..e4c8bd47ceca5
--- /dev/null
+++ b/compiler-rt/test/profile/instrprof-coroutine-profile.cpp
@@ -0,0 +1,46 @@
+// RUN: %clangxx_pgogen -std=c++20 -O2 -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata show -function=foo -counts %t.profraw | FileCheck %s
+
+#include <coroutine>
+
+struct State {
+ struct promise_type {
+ std::suspend_never initial_suspend() noexcept { return {}; }
+ std::suspend_never final_suspend() noexcept { return {}; }
+ State get_return_object() noexcept {
+ return State{std::coroutine_handle<promise_type>::from_promise(*this)};
+ }
+ void return_void() noexcept {}
+ void unhandled_exception() noexcept {}
+ };
+ std::coroutine_handle<promise_type> handle;
+};
+
+struct Awaitable {
+ bool await_ready() noexcept { return false; }
+ void await_suspend(std::coroutine_handle<> h) noexcept { h.resume(); }
+ void await_resume() noexcept {}
+};
+
+__attribute__((noinline)) State foo(int x) {
+ for (int i = 0; i < x; ++i) {
+ co_await Awaitable{};
+ }
+ co_return;
+}
+
+int main() {
+ foo(5);
+ return 0;
+}
+
+// Note: Index 6 in Block counts (the 7th value '1') represents the function entry count of foo(5).
+// CHECK: Counters:
+// CHECK-NEXT: {{.*foo.*}}:
+// CHECK-NEXT: Hash: {{.*}}
+// CHECK-NEXT: Counters: 8
+// CHECK-NEXT: Block counts: [0, 5, 5, 5, 1, 1, 1, 1]
+// CHECK-NOT: .resume
+// CHECK-NOT: .destroy
+// CHECK-NOT: .cleanup
More information about the llvm-commits
mailing list