[clang] [CIR][OpenMP] Add support for omp single construct (PR #243797)
Thirumalai Shaktivel via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 24 21:37:25 PST 2026
================
@@ -0,0 +1,171 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefixes=LLVM,CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefixes=LLVM,OGCG
+
+// Check the LLVM IR of omp single from ClangIR and classic codegen. The
+// prefixes are LLVM (checks shared by both paths), CIR (IR lowered from
+// ClangIR) and OGCG (IR from the original, classic Clang codegen).
+
+void work(void);
+void other_work(void);
+
+void single_only(void) {
+#pragma omp single
+ work();
+}
+
+// LLVM-LABEL: define {{.*}}void @single_only()
+// LLVM: call i32 @__kmpc_single(
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_single(
+// LLVM: call void @__kmpc_barrier(
+
+void nowait_single_only(void) {
+#pragma omp single nowait
+ work();
+}
+
+// LLVM-LABEL: define {{.*}}void @nowait_single_only()
+// LLVM: call i32 @__kmpc_single(
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_single(
+// LLVM-NOT: @__kmpc_barrier
+
+void single_inside_parallel(void) {
+#pragma omp parallel
+ {
+#pragma omp single
+ work();
+ }
+}
+
+// CIR-LABEL: define {{.*}}void @single_inside_parallel()
+// CIR: call {{.*}}@__kmpc_fork_call(
+// CIR-LABEL: define {{.*}}void @single_inside_parallel..omp_par(
----------------
Thirumalai-Shaktivel wrote:
`..omp_par` is intended, and the OpenMP community (Dialect) has been using it for a long time. Mostly, fixing it would require changes in many of the test cases. I think we could replace the `..omp_par` part with `{{.*}}`, so that both CIR and Classic Clang test the same CHECK line
https://github.com/llvm/llvm-project/pull/243797
More information about the cfe-commits
mailing list