https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/174881

>From 67e33c8f7d5740e08fd30c54596d3bfa20327d47 Mon Sep 17 00:00:00 2001
From: Wei Wang <[email protected]>
Date: Wed, 7 Jan 2026 12:20:04 -0800
Subject: [PATCH 1/2] [SampleProf] Handle coro wrapper function name
 canonicalization

---
 clang/lib/CodeGen/CGCoroutine.cpp             |  1 +
 .../CodeGenCoroutines/coro-attributes.cpp     |  4 +++
 .../SampleProfile/Inputs/coro-annotate.prof   |  2 ++
 .../Transforms/SampleProfile/coro-annotate.ll | 31 +++++++++++++++++++
 4 files changed, 38 insertions(+)
 create mode 100644 llvm/test/Transforms/SampleProfile/Inputs/coro-annotate.prof
 create mode 100644 llvm/test/Transforms/SampleProfile/coro-annotate.ll

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index c80bb0e004367..7282c42420657 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -447,6 +447,7 @@ CodeGenFunction::generateAwaitSuspendWrapper(Twine const 
&CoroName,
 
   Fn->setMustProgress();
   Fn->addFnAttr(llvm::Attribute::AttrKind::AlwaysInline);
+  Fn->addFnAttr("sample-profile-suffix-elision-policy", "selected");
 
   StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
 
diff --git a/clang/test/CodeGenCoroutines/coro-attributes.cpp 
b/clang/test/CodeGenCoroutines/coro-attributes.cpp
index 8f171771a8cbc..2dfb6cc052ce9 100644
--- a/clang/test/CodeGenCoroutines/coro-attributes.cpp
+++ b/clang/test/CodeGenCoroutines/coro-attributes.cpp
@@ -15,8 +15,12 @@ struct coro {
 
 // CHECK: void @_Z3foov() #[[FOO_ATTR_NUM:[0-9]+]]
 // CHECK: declare token @llvm.coro.save(ptr) #[[SAVE_ATTR_NUM:[0-9]+]]
+// CHECK: void @_Z3foov.__await_suspend_wrapper__init({{.*}}) 
#[[WRAPPER_ATTR_NUM:[0-9]+]]
+// CHECK: void @_Z3foov.__await_suspend_wrapper__await({{.*}}) 
#[[WRAPPER_ATTR_NUM:[0-9]+]]
+// CHECK: void @_Z3foov.__await_suspend_wrapper__final({{.*}}) 
#[[WRAPPER_ATTR_NUM:[0-9]+]]
 // CHECK: attributes #[[FOO_ATTR_NUM]] = { {{.*}} presplitcoroutine
 // CHECK: attributes #[[SAVE_ATTR_NUM]] = { {{.*}}nomerge
+// CHECK: attributes #[[WRAPPER_ATTR_NUM]] = { 
{{.*}}"sample-profile-suffix-elision-policy"="selected"
 coro foo() {
   co_await suspend_always{};
 }
diff --git a/llvm/test/Transforms/SampleProfile/Inputs/coro-annotate.prof 
b/llvm/test/Transforms/SampleProfile/Inputs/coro-annotate.prof
new file mode 100644
index 0000000000000..6b9ccb2653918
--- /dev/null
+++ b/llvm/test/Transforms/SampleProfile/Inputs/coro-annotate.prof
@@ -0,0 +1,2 @@
+bar:100:13293
+ 0: 100
diff --git a/llvm/test/Transforms/SampleProfile/coro-annotate.ll 
b/llvm/test/Transforms/SampleProfile/coro-annotate.ll
new file mode 100644
index 0000000000000..ba191bb76e4e8
--- /dev/null
+++ b/llvm/test/Transforms/SampleProfile/coro-annotate.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -sample-profile-file=%S/Inputs/coro-annotate.prof 
-passes=sample-profile -S | FileCheck %s
+
+; This test checks if a coro function can correctly get sample annotation with 
the present of its await suspend wrappers.
+; Please ignore the incomplete coro function body and missing coro intrinsics 
since only the function names matter here.
+; Note: Do not change the function names. They are intentionally made to 
create a specific order in the module's ValSymTab iterator.
+
+; CHECK: define void @bar() {{.*}} !prof ![[PROF:[0-9]+]]
+; CHECK: ![[PROF]] = !{!"function_entry_count", i64 13294}
+define void @bar() #0 !dbg !4 {
+entry:
+  ret void, !dbg !9
+}
+
+define internal void @bar.__await_suspend_wrapper__init(ptr noundef nonnull 
%0, ptr noundef %1) #1 {
+entry:
+  ret void
+}
+
+attributes #0 = { presplitcoroutine "use-sample-profile" }
+attributes #1 = { "sample-profile-suffix-elision-policy"="selected" }
+
+!llvm.module.flags = !{!7, !8}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: 
!5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: 
!0, retainedNodes: !2)
+!5 = !DISubroutineType(types: !2)
+!7 = !{i32 2, !"Dwarf Version", i32 4}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!9 = !DILocation(line: 1, column: 15, scope: !4)

>From 539b337b346fa3360fd9fc6de4f03c79014a8bcd Mon Sep 17 00:00:00 2001
From: Wei Wang <[email protected]>
Date: Thu, 8 Jan 2026 11:27:52 -0800
Subject: [PATCH 2/2] fix typo

---
 llvm/test/Transforms/SampleProfile/coro-annotate.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/Transforms/SampleProfile/coro-annotate.ll 
b/llvm/test/Transforms/SampleProfile/coro-annotate.ll
index ba191bb76e4e8..9aa85353cca28 100644
--- a/llvm/test/Transforms/SampleProfile/coro-annotate.ll
+++ b/llvm/test/Transforms/SampleProfile/coro-annotate.ll
@@ -24,7 +24,7 @@ attributes #1 = { 
"sample-profile-suffix-elision-policy"="selected" }
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
 !1 = !DIFile(filename: "test.c", directory: "")
 !2 = !{}
-!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: 
!5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: 
!0, retainedNodes: !2)
+!4 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: 
!5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: 
!0, retainedNodes: !2)
 !5 = !DISubroutineType(types: !2)
 !7 = !{i32 2, !"Dwarf Version", i32 4}
 !8 = !{i32 2, !"Debug Info Version", i32 3}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to