llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Julian Brown (jtb20)

<details>
<summary>Changes</summary>

Add two Clang codegen tests for the OpenMP 6.0 taskgraph
directive exercising its interaction with templates -- in
particular checking that different instantiations of the same
template get distinct taskgraph handles.

Assisted-By: Claude Opus 4.7


---
Full diff: https://github.com/llvm/llvm-project/pull/200409.diff


2 Files Affected:

- (added) clang/test/OpenMP/taskgraph_template_handle_codegen.cpp (+36) 
- (added) clang/test/OpenMP/taskgraph_templates_codegen.cpp (+73) 


``````````diff
diff --git a/clang/test/OpenMP/taskgraph_template_handle_codegen.cpp 
b/clang/test/OpenMP/taskgraph_template_handle_codegen.cpp
new file mode 100644
index 0000000000000..0874fe58edb03
--- /dev/null
+++ b/clang/test/OpenMP/taskgraph_template_handle_codegen.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=60 -x c++ -triple 
x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+template <typename T>
+void templ_handle(T &x) {
+#pragma omp taskgraph
+  {
+#pragma omp task shared(x)
+    {
+      x += 1;
+    }
+  }
+}
+
+int main() {
+  int i = 0;
+  long l = 0;
+  templ_handle(i);
+  templ_handle(l);
+  return 0;
+}
+
+// CHECK-DAG: @[[H1:.omp.taskgraph.handle[^ ]*]] = internal global ptr null
+// CHECK-DAG: @[[H2:.omp.taskgraph.handle[^ ]*]] = internal global ptr null
+
+// CHECK-LABEL: define linkonce_odr {{.*}} @_Z12templ_handleIiEvRT_(
+// CHECK: call void @__kmpc_taskgraph(ptr {{[^,]+}}, i32 {{[^,]+}}, ptr 
@[[H1]], i64 0, i32 0, i32 0, ptr {{[^,]+}}, ptr {{[^)]+}})
+
+// CHECK-LABEL: define linkonce_odr {{.*}} @_Z12templ_handleIlEvRT_(
+// CHECK-NOT: ptr @[[H1]]
+// CHECK: call void @__kmpc_taskgraph(ptr {{[^,]+}}, i32 {{[^,]+}}, ptr 
@[[H2]], i64 0, i32 0, i32 0, ptr {{[^,]+}}, ptr {{[^)]+}})
+
+#endif
diff --git a/clang/test/OpenMP/taskgraph_templates_codegen.cpp 
b/clang/test/OpenMP/taskgraph_templates_codegen.cpp
new file mode 100644
index 0000000000000..16765bb078f4e
--- /dev/null
+++ b/clang/test/OpenMP/taskgraph_templates_codegen.cpp
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=60 -x c++ -triple 
x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | 
FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+// Exercises taskgraph codegen with orthogonal language/runtime features:
+//  - C++ templates + non-trivial firstprivate cloning.
+//  - taskgroup task_reduction / task in_reduction inside taskgraph.
+//  - taskwait depend(...) inside taskgraph (task-generating path).
+
+template <typename T>
+struct Box {
+  T v;
+  Box();
+  Box(const Box &);
+  ~Box();
+};
+
+template <typename T>
+void templated_clone(T seed) {
+  Box<T> B;
+  B.v = seed;
+#pragma omp taskgraph
+  {
+#pragma omp task firstprivate(B)
+    {
+      (void)B.v;
+    }
+
+#pragma omp task replayable(false) firstprivate(B)
+    {
+      (void)B.v;
+    }
+  }
+}
+
+template <typename T>
+T templated_task_reduction(T seed) {
+  T Acc = seed;
+#pragma omp taskgraph
+  {
+#pragma omp taskgroup task_reduction(+: Acc)
+    {
+#pragma omp task in_reduction(+: Acc)
+      {
+        Acc += seed;
+      }
+    }
+#pragma omp taskwait depend(in: Acc)
+  }
+  return Acc;
+}
+
+int main() {
+  templated_clone<int>(7);
+  return templated_task_reduction<int>(1);
+}
+
+// The taskgraph task entry uses the taskgraph runtime path and carries a
+// clone helper for non-trivial firstprivate copies.
+// CHECK: call i32 @__kmpc_taskgraph_task(
+// CHECK-SAME: ptr @.omp_task_clone.)
+// CHECK: define internal void @.omp_task_clone.(
+
+// task_reduction in a taskgraph uses the dedicated taskgraph reduction init.
+// CHECK: call ptr @__kmpc_taskgraph_taskred_init(
+
+// taskwait depend(...) inside taskgraph uses the dedicated taskgraph taskwait
+// entry point instead of the generic taskwait runtime path.
+// CHECK: call void @__kmpc_taskgraph_taskwait(
+
+#endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/200409
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to