[clang] [CIR][OpenMP] Add support for omp single construct (PR #243797)
Thirumalai Shaktivel via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 27 03:22:48 PST 2026
https://github.com/Thirumalai-Shaktivel updated https://github.com/llvm/llvm-project/pull/243797
>From 89c192b7122a3d0965e80346e09b35f232305ff3 Mon Sep 17 00:00:00 2001
From: Thirumalai-Shaktivel <thirumalaishaktivel at gmail.com>
Date: Wed, 18 Nov 2026 16:04:54 +0530
Subject: [PATCH 1/5] [CIR][OpenMP] Add support for omp single construct
Issue: emitOMPSingleDirective was Not-Yet-Implemented, so
#pragma omp single hit errorNYI in ClangIR codegen.
Fix: Lower OMPSingleDirective to omp.single, adding an
emitNowait clause emitter. allocate, copyprivate,
firstprivate, and private clauses remain NYI. Add CIR and LLVM
lowering tests.
---
clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp | 11 ++
clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h | 2 +
clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp | 43 ++++-
.../CIR/CodeGenOpenMP/not-yet-implemented.c | 8 +-
clang/test/CIR/CodeGenOpenMP/single.c | 57 ++++++
clang/test/CIR/CodeGenOpenMP/single_llvm.c | 171 ++++++++++++++++++
6 files changed, 286 insertions(+), 6 deletions(-)
create mode 100644 clang/test/CIR/CodeGenOpenMP/single.c
create mode 100644 clang/test/CIR/CodeGenOpenMP/single_llvm.c
diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
index 2e64632f037c53..7eea93da7e7908 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
@@ -112,6 +112,17 @@ bool OpenMPClauseEmitter::emitNumThreads(
return false;
}
+bool OpenMPClauseEmitter::emitNowait(mlir::omp::NowaitClauseOps &result) const {
+ for (const OMPClause *clause : clauses) {
+ if (!isa<OMPNowaitClause>(clause))
+ continue;
+
+ result.nowait = builder.getUnitAttr();
+ return true;
+ }
+ return false;
+}
+
bool OpenMPClauseEmitter::emitIf(mlir::omp::IfClauseOps &result,
llvm::omp::Directive directiveName) const {
for (const OMPClause *clause : clauses) {
diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h
index a5dcbcb918c737..dc5d2e9fd5c112 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h
@@ -52,6 +52,8 @@ class OpenMPClauseEmitter {
bool emitProcBind(mlir::omp::ProcBindClauseOps &result) const;
+ bool emitNowait(mlir::omp::NowaitClauseOps &result) const;
+
/// Verify the clauses of a directive to make sure all legal cases are either
/// implemented or give a NYI error. The \p SupportedClauses and \p
/// NYIClauses type lists must be disjoint and cover all clauses eligible for
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
index eb5f3a430b290c..5ffc8f37b9f11d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
@@ -484,10 +484,49 @@ CIRGenFunction::emitOMPSectionDirective(const OMPSectionDirective &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSectionDirective");
return mlir::failure();
}
+static mlir::LogicalResult
+emitSingleClauses(CIRGenFunction &cgf, CIRGenModule &cgm,
+ CIRGenBuilderTy &builder, mlir::Location loc,
+ llvm::ArrayRef<const OMPClause *> clauses,
+ mlir::omp::SingleOperands &clauseOps) {
+ OpenMPClauseEmitter ce(cgf, cgm, builder, loc, clauses);
+ ce.emitNowait(clauseOps);
+ return ce.emitNYI</*supported=*/OMPNowaitClause>(
+ /*nyi=*/OpenMPNYIClauseList<OMPAllocateClause, OMPCopyprivateClause,
+ OMPFirstprivateClause, OMPPrivateClause>{},
+ llvm::omp::Directive::OMPD_single);
+}
+
mlir::LogicalResult
CIRGenFunction::emitOMPSingleDirective(const OMPSingleDirective &s) {
- getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPSingleDirective");
- return mlir::failure();
+ mlir::Location begin = getLoc(s.getBeginLoc());
+ mlir::Location end = getLoc(s.getEndLoc());
+
+ omp::ConstructQueue queue =
+ omp::buildConstructQueue(getContext().getLangOpts().OpenMP, s);
+ omp::ConstructQueue::const_iterator item = queue.begin();
+
+ if (mlir::failed(checkSynthesizedClauses(*this, s, item)))
+ return mlir::failure();
+
+ mlir::omp::SingleOperands clauseOps;
+ if (mlir::failed(emitSingleClauses(*this, getCIRGenModule(), builder, begin,
+ item->clauses, clauseOps)))
+ return mlir::failure();
+
+ auto singleOp = mlir::omp::SingleOp::create(builder, begin, clauseOps);
+
+ mlir::Block &block = singleOp.getRegion().emplaceBlock();
+ mlir::OpBuilder::InsertionGuard guard(builder);
+ builder.setInsertionPointToEnd(&block);
+
+ CIRGenFunction::LexicalScope ls{*this, begin, builder.getInsertionBlock()};
+
+ const CapturedStmt *cs = s.getInnermostCapturedStmt();
+ mlir::LogicalResult res =
+ emitStmt(cs->getCapturedStmt(), /*useCurrentScope=*/true);
+ mlir::omp::TerminatorOp::create(builder, end);
+ return res;
}
mlir::LogicalResult
CIRGenFunction::emitOMPMasterDirective(const OMPMasterDirective &s) {
diff --git a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
index 1cf0ecd315e0d1..3e905d225126c1 100644
--- a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
+++ b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
@@ -5,10 +5,6 @@ void do_things() {
#pragma omp critical
{}
- // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP OMPSingleDirective}}
-#pragma omp single
- {}
-
int i;
// A leaf that reports a not-yet-implemented clause emits no op at all, rather
// than one that silently ignores the clause.
@@ -18,6 +14,10 @@ void do_things() {
#pragma omp parallel shared(a) firstprivate(b)
{}
+ // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP SINGLE 'copyprivate' clause}}
+#pragma omp single copyprivate(a)
+ {}
+
// A clause routed through construct decomposition but not yet emittable must
// still be diagnosed by the leaf emitter's NYI handling.
// expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP TARGET 'private' clause}}
diff --git a/clang/test/CIR/CodeGenOpenMP/single.c b/clang/test/CIR/CodeGenOpenMP/single.c
new file mode 100644
index 00000000000000..bb18561791ffe3
--- /dev/null
+++ b/clang/test/CIR/CodeGenOpenMP/single.c
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -fopenmp -triple x86_64-linux-gnu -emit-cir -fclangir %s -o - | FileCheck %s
+
+void before(void);
+void during(void);
+void after(void);
+
+void emit_simple_single() {
+ // CHECK: cir.func{{.*}}@emit_simple_single
+ before();
+ // CHECK-NEXT: cir.call @before
+#pragma omp single
+ { during(); }
+ // CHECK-NEXT: omp.single {
+ // CHECK-NEXT: cir.call @during
+ // CHECK-NEXT: omp.terminator
+ // CHECK-NEXT: }
+ after();
+ // CHECK-NEXT: cir.call @after
+}
+
+void nowait_single() {
+ // CHECK: cir.func{{.*}}@nowait_single
+#pragma omp single nowait
+ {}
+ // CHECK-NEXT: omp.single nowait {
+ // CHECK-NEXT: omp.terminator
+ // CHECK-NEXT: }
+}
+
+void single_with_local_variable(int *ptr) {
+ // CHECK: cir.func{{.*}}@single_with_local_variable
+#pragma omp single
+ {
+ int local = *ptr;
+ *ptr = local + 1;
+ }
+ // CHECK: omp.single {
+ // CHECK-NEXT: cir.alloca {{.*}}"local"
+ // CHECK: omp.terminator
+ // CHECK-NEXT: }
+}
+
+void single_inside_parallel(void) {
+ // CHECK: cir.func{{.*}}@single_inside_parallel
+#pragma omp parallel
+ {
+#pragma omp single
+ { during(); }
+ }
+ // CHECK-NEXT: omp.parallel {
+ // CHECK-NEXT: omp.single {
+ // CHECK-NEXT: cir.call @during
+ // CHECK-NEXT: omp.terminator
+ // CHECK-NEXT: }
+ // CHECK-NEXT: omp.terminator
+ // CHECK-NEXT: }
+}
diff --git a/clang/test/CIR/CodeGenOpenMP/single_llvm.c b/clang/test/CIR/CodeGenOpenMP/single_llvm.c
new file mode 100644
index 00000000000000..6a50a42086e829
--- /dev/null
+++ b/clang/test/CIR/CodeGenOpenMP/single_llvm.c
@@ -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(
+// CIR: call i32 @__kmpc_single(
+// CIR-DAG: call void @work()
+// CIR-DAG: call void @__kmpc_end_single(
+// CIR-DAG: call void @__kmpc_barrier(
+
+// OGCG-LABEL: define {{.*}}void @single_inside_parallel()
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @single_inside_parallel.omp_outlined(
+// OGCG: call i32 @__kmpc_single(
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_single(
+// OGCG: call void @__kmpc_barrier(
+
+void nowait_single_then_other_work_in_parallel(void) {
+#pragma omp parallel
+ {
+#pragma omp single nowait
+ work();
+ other_work();
+ }
+}
+
+// CIR-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel()
+// CIR: call {{.*}}@__kmpc_fork_call(
+// CIR-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel..omp_par(
+// CIR: call i32 @__kmpc_single(
+// CIR-DAG: call void @work()
+// CIR-DAG: call void @__kmpc_end_single(
+// CIR-DAG: call void @other_work()
+// CIR-NOT: @__kmpc_barrier
+
+// OGCG-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel()
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel.omp_outlined(
+// OGCG: call i32 @__kmpc_single(
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_single(
+// OGCG: call void @other_work()
+// OGCG-NOT: @__kmpc_barrier
+
+void single_in_parallel_with_clauses(int num_threads_value, int condition) {
+#pragma omp parallel num_threads(num_threads_value) if (condition)
+ {
+#pragma omp single
+ work();
+ }
+}
+
+// CIR-LABEL: define {{.*}}void @single_in_parallel_with_clauses(
+// CIR: call void @__kmpc_push_num_threads(
+// CIR: call {{.*}}@__kmpc_fork_call_if(
+// CIR-LABEL: define {{.*}}void @single_in_parallel_with_clauses..omp_par(
+// CIR: call i32 @__kmpc_single(
+// CIR-DAG: call void @work()
+// CIR-DAG: call void @__kmpc_end_single(
+// CIR-DAG: call void @__kmpc_barrier(
+
+// OGCG-LABEL: define {{.*}}void @single_in_parallel_with_clauses(
+// OGCG: call void @__kmpc_push_num_threads(
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @single_in_parallel_with_clauses.omp_outlined(
+// OGCG: call i32 @__kmpc_single(
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_single(
+// OGCG: call void @__kmpc_barrier(
+
+void two_singles_around_barrier(void) {
+#pragma omp parallel
+ {
+#pragma omp single
+ work();
+#pragma omp barrier
+#pragma omp single nowait
+ other_work();
+ }
+}
+
+// CIR-LABEL: define {{.*}}void @two_singles_around_barrier()
+// CIR: call {{.*}}@__kmpc_fork_call(
+// CIR-LABEL: define {{.*}}void @two_singles_around_barrier..omp_par(
+// CIR: call i32 @__kmpc_single(
+// CIR-DAG: call void @work()
+// CIR-DAG: call void @__kmpc_end_single(
+// CIR-DAG: call void @__kmpc_barrier(
+// CIR-DAG: call void @__kmpc_barrier(
+// CIR-DAG: call i32 @__kmpc_single(
+// CIR-DAG: call void @other_work()
+// CIR-DAG: call void @__kmpc_end_single(
+
+// OGCG-LABEL: define {{.*}}void @two_singles_around_barrier()
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @two_singles_around_barrier.omp_outlined(
+// OGCG: call i32 @__kmpc_single(
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_single(
+// OGCG: call void @__kmpc_barrier(
+// OGCG: call void @__kmpc_barrier(
+// OGCG: call i32 @__kmpc_single(
+// OGCG: call void @other_work()
+// OGCG: call void @__kmpc_end_single(
+
+void single_inside_target_parallel(void) {
+#pragma omp target parallel
+ {
+#pragma omp single
+ work();
+ }
+}
+
+// CIR-LABEL: define {{.*}}void @single_inside_target_parallel()
+// CIR-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}(
+// CIR: call {{.*}}@__kmpc_fork_call(
+// CIR-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}..omp_par(
+// CIR: call i32 @__kmpc_single(
+// CIR-DAG: call void @work()
+// CIR-DAG: call void @__kmpc_end_single(
+// CIR-DAG: call void @__kmpc_barrier(
+
+// OGCG-LABEL: define {{.*}}void @single_inside_target_parallel()
+// OGCG-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}(
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}.omp_outlined(
+// OGCG: call i32 @__kmpc_single(
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_single(
+// OGCG: call void @__kmpc_barrier(
>From 4a0d9289bb935902f8340a5d59a006dbfbf0a4b2 Mon Sep 17 00:00:00 2001
From: Thirumalai-Shaktivel <thirumalaishaktivel at gmail.com>
Date: Wed, 25 Nov 2026 11:55:36 +0530
Subject: [PATCH 2/5] Address the review comment by Steffen
Merge both into single.c. Check the CIR, and the LLVM IR from
ClangIR and classic codegen under one shared LLVM prefix. Match the
differing outlined function names and fork call with regexes, and use
LLVM-DAG where the two paths order calls differently.
---
clang/test/CIR/CodeGenOpenMP/single.c | 177 ++++++++++++++++++---
clang/test/CIR/CodeGenOpenMP/single_llvm.c | 171 --------------------
2 files changed, 152 insertions(+), 196 deletions(-)
delete mode 100644 clang/test/CIR/CodeGenOpenMP/single_llvm.c
diff --git a/clang/test/CIR/CodeGenOpenMP/single.c b/clang/test/CIR/CodeGenOpenMP/single.c
index bb18561791ffe3..7c2296fc3619cb 100644
--- a/clang/test/CIR/CodeGenOpenMP/single.c
+++ b/clang/test/CIR/CodeGenOpenMP/single.c
@@ -1,57 +1,184 @@
-// RUN: %clang_cc1 -fopenmp -triple x86_64-linux-gnu -emit-cir -fclangir %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -triple x86_64-linux-gnu -emit-cir -fclangir %s -o - | FileCheck %s --check-prefix=CIR
+// 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-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=LLVM
+
+// Check the CIR of omp single, and the LLVM IR from both ClangIR and classic
+// codegen. The prefixes are CIR (ClangIR output) and LLVM (LLVM IR checks
+// shared by both paths).
void before(void);
void during(void);
void after(void);
void emit_simple_single() {
- // CHECK: cir.func{{.*}}@emit_simple_single
+ // CIR: cir.func{{.*}}@emit_simple_single
before();
- // CHECK-NEXT: cir.call @before
+ // CIR-NEXT: cir.call @before
#pragma omp single
{ during(); }
- // CHECK-NEXT: omp.single {
- // CHECK-NEXT: cir.call @during
- // CHECK-NEXT: omp.terminator
- // CHECK-NEXT: }
+ // CIR-NEXT: omp.single {
+ // CIR-NEXT: cir.call @during
+ // CIR-NEXT: omp.terminator
+ // CIR-NEXT: }
after();
- // CHECK-NEXT: cir.call @after
+ // CIR-NEXT: cir.call @after
}
void nowait_single() {
- // CHECK: cir.func{{.*}}@nowait_single
+ // CIR: cir.func{{.*}}@nowait_single
#pragma omp single nowait
{}
- // CHECK-NEXT: omp.single nowait {
- // CHECK-NEXT: omp.terminator
- // CHECK-NEXT: }
+ // CIR-NEXT: omp.single nowait {
+ // CIR-NEXT: omp.terminator
+ // CIR-NEXT: }
}
void single_with_local_variable(int *ptr) {
- // CHECK: cir.func{{.*}}@single_with_local_variable
+ // CIR: cir.func{{.*}}@single_with_local_variable
#pragma omp single
{
int local = *ptr;
*ptr = local + 1;
}
- // CHECK: omp.single {
- // CHECK-NEXT: cir.alloca {{.*}}"local"
- // CHECK: omp.terminator
- // CHECK-NEXT: }
+ // CIR: omp.single {
+ // CIR-NEXT: cir.alloca {{.*}}"local"
+ // CIR: omp.terminator
+ // CIR-NEXT: }
}
void single_inside_parallel(void) {
- // CHECK: cir.func{{.*}}@single_inside_parallel
+ // CIR: cir.func{{.*}}@single_inside_parallel
#pragma omp parallel
{
#pragma omp single
{ during(); }
}
- // CHECK-NEXT: omp.parallel {
- // CHECK-NEXT: omp.single {
- // CHECK-NEXT: cir.call @during
- // CHECK-NEXT: omp.terminator
- // CHECK-NEXT: }
- // CHECK-NEXT: omp.terminator
- // CHECK-NEXT: }
+ // CIR-NEXT: omp.parallel {
+ // CIR-NEXT: omp.single {
+ // CIR-NEXT: cir.call @during
+ // CIR-NEXT: omp.terminator
+ // CIR-NEXT: }
+ // CIR-NEXT: omp.terminator
+ // CIR-NEXT: }
+}
+
+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_in_parallel_region(void) {
+#pragma omp parallel
+ {
+#pragma omp single
+ work();
+ }
+}
+
+// LLVM-LABEL: define {{.*}}void @single_in_parallel_region()
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+// The outlined function name differs between the two paths (ClangIR:
+// "<fn>..omp_par", classic codegen: "<fn>.omp_outlined"), so the dot count
+// and suffix are matched with a regex.
+// LLVM-LABEL: define {{.*}}void @single_in_parallel_region{{\.+}}omp_{{(par|outlined)}}(
+// LLVM: call i32 @__kmpc_single(
+// LLVM-DAG: call void @work()
+// LLVM-DAG: call void @__kmpc_end_single(
+// LLVM-DAG: call void @__kmpc_barrier(
+
+void nowait_single_then_other_work_in_parallel(void) {
+#pragma omp parallel
+ {
+#pragma omp single nowait
+ work();
+ other_work();
+ }
+}
+
+// LLVM-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel()
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+// LLVM-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel{{\.+}}omp_{{(par|outlined)}}(
+// LLVM: call i32 @__kmpc_single(
+// LLVM-DAG: call void @work()
+// LLVM-DAG: call void @__kmpc_end_single(
+// LLVM-DAG: call void @other_work()
+// LLVM-NOT: @__kmpc_barrier
+
+void single_in_parallel_with_clauses(int num_threads_value, int condition) {
+#pragma omp parallel num_threads(num_threads_value) if (condition)
+ {
+#pragma omp single
+ work();
+ }
+}
+
+// LLVM-LABEL: define {{.*}}void @single_in_parallel_with_clauses(
+// LLVM: call void @__kmpc_push_num_threads(
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+// LLVM-LABEL: define {{.*}}void @single_in_parallel_with_clauses{{\.+}}omp_{{(par|outlined)}}(
+// LLVM: call i32 @__kmpc_single(
+// LLVM-DAG: call void @work()
+// LLVM-DAG: call void @__kmpc_end_single(
+// LLVM-DAG: call void @__kmpc_barrier(
+
+void two_singles_around_barrier(void) {
+#pragma omp parallel
+ {
+#pragma omp single
+ work();
+#pragma omp barrier
+#pragma omp single nowait
+ other_work();
+ }
}
+
+// LLVM-LABEL: define {{.*}}void @two_singles_around_barrier()
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+// LLVM-LABEL: define {{.*}}void @two_singles_around_barrier{{\.+}}omp_{{(par|outlined)}}(
+// LLVM: call i32 @__kmpc_single(
+// LLVM-DAG: call void @work()
+// LLVM-DAG: call void @__kmpc_end_single(
+// LLVM-DAG: call void @__kmpc_barrier(
+// LLVM-DAG: call void @__kmpc_barrier(
+// LLVM-DAG: call i32 @__kmpc_single(
+// LLVM-DAG: call void @other_work()
+// LLVM: call void @__kmpc_end_single(
+
+void single_inside_target_parallel(void) {
+#pragma omp target parallel
+ {
+#pragma omp single
+ work();
+ }
+}
+
+// LLVM-LABEL: define {{.*}}void @single_inside_target_parallel()
+// LLVM-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}(
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+// LLVM-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}{{\.+}}omp_{{(par|outlined)}}(
+// LLVM: call i32 @__kmpc_single(
+// LLVM-DAG: call void @work()
+// LLVM-DAG: call void @__kmpc_end_single(
+// LLVM-DAG: call void @__kmpc_barrier(
diff --git a/clang/test/CIR/CodeGenOpenMP/single_llvm.c b/clang/test/CIR/CodeGenOpenMP/single_llvm.c
deleted file mode 100644
index 6a50a42086e829..00000000000000
--- a/clang/test/CIR/CodeGenOpenMP/single_llvm.c
+++ /dev/null
@@ -1,171 +0,0 @@
-// 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(
-// CIR: call i32 @__kmpc_single(
-// CIR-DAG: call void @work()
-// CIR-DAG: call void @__kmpc_end_single(
-// CIR-DAG: call void @__kmpc_barrier(
-
-// OGCG-LABEL: define {{.*}}void @single_inside_parallel()
-// OGCG: call {{.*}}@__kmpc_fork_call(
-// OGCG-LABEL: define {{.*}}void @single_inside_parallel.omp_outlined(
-// OGCG: call i32 @__kmpc_single(
-// OGCG: call void @work()
-// OGCG: call void @__kmpc_end_single(
-// OGCG: call void @__kmpc_barrier(
-
-void nowait_single_then_other_work_in_parallel(void) {
-#pragma omp parallel
- {
-#pragma omp single nowait
- work();
- other_work();
- }
-}
-
-// CIR-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel()
-// CIR: call {{.*}}@__kmpc_fork_call(
-// CIR-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel..omp_par(
-// CIR: call i32 @__kmpc_single(
-// CIR-DAG: call void @work()
-// CIR-DAG: call void @__kmpc_end_single(
-// CIR-DAG: call void @other_work()
-// CIR-NOT: @__kmpc_barrier
-
-// OGCG-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel()
-// OGCG: call {{.*}}@__kmpc_fork_call(
-// OGCG-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel.omp_outlined(
-// OGCG: call i32 @__kmpc_single(
-// OGCG: call void @work()
-// OGCG: call void @__kmpc_end_single(
-// OGCG: call void @other_work()
-// OGCG-NOT: @__kmpc_barrier
-
-void single_in_parallel_with_clauses(int num_threads_value, int condition) {
-#pragma omp parallel num_threads(num_threads_value) if (condition)
- {
-#pragma omp single
- work();
- }
-}
-
-// CIR-LABEL: define {{.*}}void @single_in_parallel_with_clauses(
-// CIR: call void @__kmpc_push_num_threads(
-// CIR: call {{.*}}@__kmpc_fork_call_if(
-// CIR-LABEL: define {{.*}}void @single_in_parallel_with_clauses..omp_par(
-// CIR: call i32 @__kmpc_single(
-// CIR-DAG: call void @work()
-// CIR-DAG: call void @__kmpc_end_single(
-// CIR-DAG: call void @__kmpc_barrier(
-
-// OGCG-LABEL: define {{.*}}void @single_in_parallel_with_clauses(
-// OGCG: call void @__kmpc_push_num_threads(
-// OGCG: call {{.*}}@__kmpc_fork_call(
-// OGCG-LABEL: define {{.*}}void @single_in_parallel_with_clauses.omp_outlined(
-// OGCG: call i32 @__kmpc_single(
-// OGCG: call void @work()
-// OGCG: call void @__kmpc_end_single(
-// OGCG: call void @__kmpc_barrier(
-
-void two_singles_around_barrier(void) {
-#pragma omp parallel
- {
-#pragma omp single
- work();
-#pragma omp barrier
-#pragma omp single nowait
- other_work();
- }
-}
-
-// CIR-LABEL: define {{.*}}void @two_singles_around_barrier()
-// CIR: call {{.*}}@__kmpc_fork_call(
-// CIR-LABEL: define {{.*}}void @two_singles_around_barrier..omp_par(
-// CIR: call i32 @__kmpc_single(
-// CIR-DAG: call void @work()
-// CIR-DAG: call void @__kmpc_end_single(
-// CIR-DAG: call void @__kmpc_barrier(
-// CIR-DAG: call void @__kmpc_barrier(
-// CIR-DAG: call i32 @__kmpc_single(
-// CIR-DAG: call void @other_work()
-// CIR-DAG: call void @__kmpc_end_single(
-
-// OGCG-LABEL: define {{.*}}void @two_singles_around_barrier()
-// OGCG: call {{.*}}@__kmpc_fork_call(
-// OGCG-LABEL: define {{.*}}void @two_singles_around_barrier.omp_outlined(
-// OGCG: call i32 @__kmpc_single(
-// OGCG: call void @work()
-// OGCG: call void @__kmpc_end_single(
-// OGCG: call void @__kmpc_barrier(
-// OGCG: call void @__kmpc_barrier(
-// OGCG: call i32 @__kmpc_single(
-// OGCG: call void @other_work()
-// OGCG: call void @__kmpc_end_single(
-
-void single_inside_target_parallel(void) {
-#pragma omp target parallel
- {
-#pragma omp single
- work();
- }
-}
-
-// CIR-LABEL: define {{.*}}void @single_inside_target_parallel()
-// CIR-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}(
-// CIR: call {{.*}}@__kmpc_fork_call(
-// CIR-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}..omp_par(
-// CIR: call i32 @__kmpc_single(
-// CIR-DAG: call void @work()
-// CIR-DAG: call void @__kmpc_end_single(
-// CIR-DAG: call void @__kmpc_barrier(
-
-// OGCG-LABEL: define {{.*}}void @single_inside_target_parallel()
-// OGCG-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}(
-// OGCG: call {{.*}}@__kmpc_fork_call(
-// OGCG-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}.omp_outlined(
-// OGCG: call i32 @__kmpc_single(
-// OGCG: call void @work()
-// OGCG: call void @__kmpc_end_single(
-// OGCG: call void @__kmpc_barrier(
>From 4a3416fae5b273d72282a60d9ebb6d39b70bd678 Mon Sep 17 00:00:00 2001
From: Thirumalai-Shaktivel <thirumalaishaktivel at gmail.com>
Date: Wed, 25 Nov 2026 12:00:54 +0530
Subject: [PATCH 3/5] Address review comment by Steffen
Simplify emitNowait with llvm::any_of
---
clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
index 7eea93da7e7908..c48d729b63e948 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
@@ -113,14 +113,10 @@ bool OpenMPClauseEmitter::emitNumThreads(
}
bool OpenMPClauseEmitter::emitNowait(mlir::omp::NowaitClauseOps &result) const {
- for (const OMPClause *clause : clauses) {
- if (!isa<OMPNowaitClause>(clause))
- continue;
-
- result.nowait = builder.getUnitAttr();
- return true;
- }
- return false;
+ bool hasNoWaitClause = llvm::any_of(clauses, llvm::IsaPred<OMPNowaitClause>);
+ if (hasNoWaitClause)
+ result.nowait = build.getUnitAttr();
+ return hasNoWaitClause;
}
bool OpenMPClauseEmitter::emitIf(mlir::omp::IfClauseOps &result,
>From d833aaa455cbed0322007c1f8bf1237f214d7d65 Mon Sep 17 00:00:00 2001
From: Thirumalai-Shaktivel <thirumalaishaktivel at gmail.com>
Date: Wed, 25 Nov 2026 15:00:11 +0530
Subject: [PATCH 4/5] Fix builder name in emitNowait
---
clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
index c48d729b63e948..de04282c532a0b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp
@@ -115,7 +115,7 @@ bool OpenMPClauseEmitter::emitNumThreads(
bool OpenMPClauseEmitter::emitNowait(mlir::omp::NowaitClauseOps &result) const {
bool hasNoWaitClause = llvm::any_of(clauses, llvm::IsaPred<OMPNowaitClause>);
if (hasNoWaitClause)
- result.nowait = build.getUnitAttr();
+ result.nowait = builder.getUnitAttr();
return hasNoWaitClause;
}
>From 0ee4c79968eb7174c2988327618d138d33f2fe55 Mon Sep 17 00:00:00 2001
From: Thirumalai-Shaktivel <thirumalaishaktivel at gmail.com>
Date: Wed, 25 Nov 2026 17:51:34 +0530
Subject: [PATCH 5/5] Address the review comment by Steffen
---
clang/test/CIR/CodeGenOpenMP/single.c | 218 +++++++++++++++++++-------
1 file changed, 158 insertions(+), 60 deletions(-)
diff --git a/clang/test/CIR/CodeGenOpenMP/single.c b/clang/test/CIR/CodeGenOpenMP/single.c
index 7c2296fc3619cb..098c324e79877e 100644
--- a/clang/test/CIR/CodeGenOpenMP/single.c
+++ b/clang/test/CIR/CodeGenOpenMP/single.c
@@ -1,12 +1,21 @@
// RUN: %clang_cc1 -fopenmp -triple x86_64-linux-gnu -emit-cir -fclangir %s -o - | FileCheck %s --check-prefix=CIR
// 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-prefix=LLVM
+// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefixes=LLVM,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-prefix=LLVM
+// RUN: FileCheck --input-file=%t.ll %s --check-prefixes=LLVM,LLVM-OGCG
-// Check the CIR of omp single, and the LLVM IR from both ClangIR and classic
-// codegen. The prefixes are CIR (ClangIR output) and LLVM (LLVM IR checks
-// shared by both paths).
+// Prefixes:
+// CIR - CIR dialect output.
+// LLVM - LLVM IR checks shared by ClangIR and classic codegen.
+// LLVM-CIR - LLVM IR checks for ClangIR only.
+// LLVM-OGCG - LLVM IR checks for classic codegen only.
+//
+// NOTE: LLVM-CIR and LLVM-OGCG are separate because the block order and the
+// block labels differ. The control flow is the same: a body block and an end
+// block, with the barrier in the end block.
+// - Order: ClangIR prints the end block first, Classic the body first.
+// - Labels: ClangIR uses omp_region.body/end, Classic uses omp_if.then/end.
+// The checks capture them as [[BODY]] and [[END]].
void before(void);
void during(void);
@@ -72,22 +81,22 @@ void single_only(void) {
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(
+// 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
+// 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_in_parallel_region(void) {
#pragma omp parallel
@@ -97,16 +106,36 @@ void single_in_parallel_region(void) {
}
}
-// LLVM-LABEL: define {{.*}}void @single_in_parallel_region()
-// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
-// The outlined function name differs between the two paths (ClangIR:
-// "<fn>..omp_par", classic codegen: "<fn>.omp_outlined"), so the dot count
-// and suffix are matched with a regex.
-// LLVM-LABEL: define {{.*}}void @single_in_parallel_region{{\.+}}omp_{{(par|outlined)}}(
-// LLVM: call i32 @__kmpc_single(
-// LLVM-DAG: call void @work()
-// LLVM-DAG: call void @__kmpc_end_single(
-// LLVM-DAG: call void @__kmpc_barrier(
+// Flow of execution in the outlined function:
+// - The thread that wins __kmpc_single runs the body block (work, then
+// __kmpc_end_single) and then goes to the end block.
+// - The other threads go straight to the end block.
+// - The end block holds the barrier, so every thread waits there until the
+// body has finished.
+// The remaining tests below follow the same flow, with their own extra calls.
+
+// LLVM-LABEL: define {{.*}}void @single_in_parallel_region()
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+
+// LLVM-OGCG-LABEL: define {{.*}}void @single_in_parallel_region.omp_outlined(
+// LLVM-OGCG: call i32 @__kmpc_single(
+// LLVM-OGCG: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-OGCG: {{^}}[[BODY]]:
+// LLVM-OGCG-NEXT: call void @work()
+// LLVM-OGCG-NEXT: call void @__kmpc_end_single(
+// LLVM-OGCG-NEXT: br label %[[END]]
+// LLVM-OGCG: {{^}}[[END]]:
+// LLVM-OGCG-NEXT: call void @__kmpc_barrier(
+
+// LLVM-CIR-LABEL: define {{.*}}void @single_in_parallel_region..omp_par(
+// LLVM-CIR: call i32 @__kmpc_single(
+// LLVM-CIR: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-CIR: {{^}}[[END]]:
+// LLVM-CIR: call void @__kmpc_barrier(
+// LLVM-CIR: {{^}}[[BODY]]:
+// LLVM-CIR: call void @work()
+// LLVM-CIR: call void @__kmpc_end_single(
+// LLVM-CIR: br label %[[END]]
void nowait_single_then_other_work_in_parallel(void) {
#pragma omp parallel
@@ -117,14 +146,30 @@ void nowait_single_then_other_work_in_parallel(void) {
}
}
-// LLVM-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel()
-// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
-// LLVM-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel{{\.+}}omp_{{(par|outlined)}}(
-// LLVM: call i32 @__kmpc_single(
-// LLVM-DAG: call void @work()
-// LLVM-DAG: call void @__kmpc_end_single(
-// LLVM-DAG: call void @other_work()
-// LLVM-NOT: @__kmpc_barrier
+// LLVM-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel()
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+
+// LLVM-OGCG-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel.omp_outlined(
+// LLVM-OGCG: call i32 @__kmpc_single(
+// LLVM-OGCG: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-OGCG: {{^}}[[BODY]]:
+// LLVM-OGCG-NEXT: call void @work()
+// LLVM-OGCG-NEXT: call void @__kmpc_end_single(
+// LLVM-OGCG-NEXT: br label %[[END]]
+// LLVM-OGCG: {{^}}[[END]]:
+// LLVM-OGCG-NEXT: call void @other_work()
+// LLVM-OGCG-NOT: @__kmpc_barrier
+
+// LLVM-CIR-LABEL: define {{.*}}void @nowait_single_then_other_work_in_parallel..omp_par(
+// LLVM-CIR: call i32 @__kmpc_single(
+// LLVM-CIR: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-CIR: {{^}}[[END]]:
+// LLVM-CIR: call void @other_work()
+// LLVM-CIR: {{^}}[[BODY]]:
+// LLVM-CIR: call void @work()
+// LLVM-CIR: call void @__kmpc_end_single(
+// LLVM-CIR: br label %[[END]]
+// LLVM-CIR-NOT: @__kmpc_barrier
void single_in_parallel_with_clauses(int num_threads_value, int condition) {
#pragma omp parallel num_threads(num_threads_value) if (condition)
@@ -134,14 +179,29 @@ void single_in_parallel_with_clauses(int num_threads_value, int condition) {
}
}
-// LLVM-LABEL: define {{.*}}void @single_in_parallel_with_clauses(
-// LLVM: call void @__kmpc_push_num_threads(
-// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
-// LLVM-LABEL: define {{.*}}void @single_in_parallel_with_clauses{{\.+}}omp_{{(par|outlined)}}(
-// LLVM: call i32 @__kmpc_single(
-// LLVM-DAG: call void @work()
-// LLVM-DAG: call void @__kmpc_end_single(
-// LLVM-DAG: call void @__kmpc_barrier(
+// LLVM-LABEL: define {{.*}}void @single_in_parallel_with_clauses(
+// LLVM: call void @__kmpc_push_num_threads(
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+
+// LLVM-OGCG-LABEL: define {{.*}}void @single_in_parallel_with_clauses.omp_outlined(
+// LLVM-OGCG: call i32 @__kmpc_single(
+// LLVM-OGCG: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-OGCG: {{^}}[[BODY]]:
+// LLVM-OGCG-NEXT: call void @work()
+// LLVM-OGCG-NEXT: call void @__kmpc_end_single(
+// LLVM-OGCG-NEXT: br label %[[END]]
+// LLVM-OGCG: {{^}}[[END]]:
+// LLVM-OGCG-NEXT: call void @__kmpc_barrier(
+
+// LLVM-CIR-LABEL: define {{.*}}void @single_in_parallel_with_clauses..omp_par(
+// LLVM-CIR: call i32 @__kmpc_single(
+// LLVM-CIR: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-CIR: {{^}}[[END]]:
+// LLVM-CIR: call void @__kmpc_barrier(
+// LLVM-CIR: {{^}}[[BODY]]:
+// LLVM-CIR: call void @work()
+// LLVM-CIR: call void @__kmpc_end_single(
+// LLVM-CIR: br label %[[END]]
void two_singles_around_barrier(void) {
#pragma omp parallel
@@ -154,17 +214,42 @@ void two_singles_around_barrier(void) {
}
}
-// LLVM-LABEL: define {{.*}}void @two_singles_around_barrier()
-// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
-// LLVM-LABEL: define {{.*}}void @two_singles_around_barrier{{\.+}}omp_{{(par|outlined)}}(
-// LLVM: call i32 @__kmpc_single(
-// LLVM-DAG: call void @work()
-// LLVM-DAG: call void @__kmpc_end_single(
-// LLVM-DAG: call void @__kmpc_barrier(
-// LLVM-DAG: call void @__kmpc_barrier(
-// LLVM-DAG: call i32 @__kmpc_single(
-// LLVM-DAG: call void @other_work()
-// LLVM: call void @__kmpc_end_single(
+// LLVM-LABEL: define {{.*}}void @two_singles_around_barrier()
+// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
+
+// LLVM-OGCG-LABEL: define {{.*}}void @two_singles_around_barrier.omp_outlined(
+// LLVM-OGCG: call i32 @__kmpc_single(
+// LLVM-OGCG: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-OGCG: {{^}}[[BODY]]:
+// LLVM-OGCG-NEXT: call void @work()
+// LLVM-OGCG-NEXT: call void @__kmpc_end_single(
+// LLVM-OGCG-NEXT: br label %[[END]]
+// LLVM-OGCG: {{^}}[[END]]:
+// LLVM-OGCG-NEXT: call void @__kmpc_barrier(
+// LLVM-OGCG-NEXT: call void @__kmpc_barrier(
+// LLVM-OGCG-NEXT: call i32 @__kmpc_single(
+// LLVM-OGCG-NEXT: icmp
+// LLVM-OGCG-NEXT: br i1 %{{.*}}, label %[[BODY2:[^,]+]], label %[[END2:.+]]
+// LLVM-OGCG: {{^}}[[BODY2]]:
+// LLVM-OGCG-NEXT: call void @other_work()
+// LLVM-OGCG-NEXT: call void @__kmpc_end_single(
+
+// LLVM-CIR-LABEL: define {{.*}}void @two_singles_around_barrier..omp_par(
+// LLVM-CIR: call i32 @__kmpc_single(
+// LLVM-CIR: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-CIR: {{^}}[[END]]:
+// LLVM-CIR: call void @__kmpc_barrier(
+// LLVM-CIR: call void @__kmpc_barrier(
+// LLVM-CIR: call i32 @__kmpc_single(
+// LLVM-CIR: icmp
+// LLVM-CIR: br i1 %{{.*}}, label %[[BODY2:[^,]+]], label %[[END2:.+]]
+// LLVM-CIR: {{^}}[[BODY2]]:
+// LLVM-CIR: call void @other_work()
+// LLVM-CIR: call void @__kmpc_end_single(
+// LLVM-CIR: {{^}}[[BODY]]:
+// LLVM-CIR: call void @work()
+// LLVM-CIR: call void @__kmpc_end_single(
+// LLVM-CIR: br label %[[END]]
void single_inside_target_parallel(void) {
#pragma omp target parallel
@@ -174,11 +259,24 @@ void single_inside_target_parallel(void) {
}
}
-// LLVM-LABEL: define {{.*}}void @single_inside_target_parallel()
-// LLVM-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}(
-// LLVM: call {{.*}}@__kmpc_fork_call{{.*}}(
-// LLVM-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}{{\.+}}omp_{{(par|outlined)}}(
-// LLVM: call i32 @__kmpc_single(
-// LLVM-DAG: call void @work()
-// LLVM-DAG: call void @__kmpc_end_single(
-// LLVM-DAG: call void @__kmpc_barrier(
+// LLVM-LABEL: define {{.*}}void @single_inside_target_parallel()
+
+// LLVM-OGCG-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}.omp_outlined(
+// LLVM-OGCG: call i32 @__kmpc_single(
+// LLVM-OGCG: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-OGCG: {{^}}[[BODY]]:
+// LLVM-OGCG-NEXT: call void @work()
+// LLVM-OGCG-NEXT: call void @__kmpc_end_single(
+// LLVM-OGCG-NEXT: br label %[[END]]
+// LLVM-OGCG: {{^}}[[END]]:
+// LLVM-OGCG-NEXT: call void @__kmpc_barrier(
+
+// LLVM-CIR-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_single_inside_target_parallel_l{{[0-9]+}}..omp_par(
+// LLVM-CIR: call i32 @__kmpc_single(
+// LLVM-CIR: br i1 %{{.*}}, label %[[BODY:[^,]+]], label %[[END:.+]]
+// LLVM-CIR: {{^}}[[END]]:
+// LLVM-CIR: call void @__kmpc_barrier(
+// LLVM-CIR: {{^}}[[BODY]]:
+// LLVM-CIR: call void @work()
+// LLVM-CIR: call void @__kmpc_end_single(
+// LLVM-CIR: br label %[[END]]
More information about the cfe-commits
mailing list