[compiler-rt] [compiler-rt][pgo] Add profile instrumentation test for coroutines (PR #213801)
Jin Huang via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 17:02:37 PDT 2026
https://github.com/jinhuang1102 updated https://github.com/llvm/llvm-project/pull/213801
>From bbb83ed8b4bccadc9f20ab5909ae5ff79ca01d29 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 | 43 +++++++++++++++++++
1 file changed, 43 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..02ee9eabb5e04
--- /dev/null
+++ b/compiler-rt/test/profile/instrprof-coroutine-profile.cpp
@@ -0,0 +1,43 @@
+// RUN: %clangxx_pgogen -std=c++20 -O2 -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata show -function=_Z3fooi -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: _Z3fooi:
+// CHECK-NEXT: Hash: {{.*}}
+// CHECK-NEXT: Counters: 8
+// CHECK-NEXT: Block counts: [{{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, 1, {{[0-9]+}}]
More information about the llvm-commits
mailing list