[clang] [CIR][OpenMP] Implement codegen for OpenMP `critical` directive in ClangIR (PR #240414)
Shrisha Kumar via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 24 03:44:10 PST 2026
https://github.com/Shrisha4real updated https://github.com/llvm/llvm-project/pull/240414
>From cf036256ece133c3e63bc9b3301ecf5cc0e1304e Mon Sep 17 00:00:00 2001
From: shrikuma <Shrisha.Kumar at amd.com>
Date: Mon, 9 Nov 2026 18:47:57 +0530
Subject: [PATCH 1/5] [CIR][OpenMP] Emit unnamed critical directive
Lower '#pragma omp critical' without a name to omp.critical. The
associated statement is emitted into the region in its own lexical
scope. Named critical sections and the hint clause are still reported
as not yet implemented.
---
clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp | 36 +++++++++++-
clang/test/CIR/CodeGenOpenMP/critical.c | 56 +++++++++++++++++++
.../CIR/CodeGenOpenMP/not-yet-implemented.c | 4 +-
3 files changed, 92 insertions(+), 4 deletions(-)
create mode 100644 clang/test/CIR/CodeGenOpenMP/critical.c
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
index 9d937f5ed67f90..11c989a112b660 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
@@ -209,10 +209,42 @@ CIRGenFunction::emitOMPMasterDirective(const OMPMasterDirective &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPMasterDirective");
return mlir::failure();
}
+
mlir::LogicalResult
CIRGenFunction::emitOMPCriticalDirective(const OMPCriticalDirective &s) {
- getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPCriticalDirective");
- 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();
+
+ OpenMPClauseEmitter ce(*this, getCIRGenModule(), builder, begin,
+ item->clauses);
+ if (mlir::failed(ce.emitNYI(/*nyi=*/OpenMPNYIClauseList<OMPHintClause>{},
+ llvm::omp::Directive::OMPD_critical)))
+ return mlir::failure();
+
+ if (!s.getDirectiveName().getAsString().empty()) {
+ getCIRGenModule().errorNYI(s.getBeginLoc(), "OpenMP named critical");
+ return mlir::failure();
+ }
+
+ auto criticalOp =
+ mlir::omp::CriticalOp::create(builder, begin, mlir::FlatSymbolRefAttr());
+ mlir::Block &block = criticalOp.getRegion().emplaceBlock();
+ mlir::OpBuilder::InsertionGuard guard(builder);
+ builder.setInsertionPointToEnd(&block);
+
+ CIRGenFunction::LexicalScope ls{*this, begin, builder.getInsertionBlock()};
+
+ mlir::LogicalResult res =
+ emitStmt(s.getAssociatedStmt(), /*useCurrentScope=*/true);
+ mlir::omp::TerminatorOp::create(builder, end);
+ return res;
}
mlir::LogicalResult
CIRGenFunction::emitOMPParallelForDirective(const OMPParallelForDirective &s) {
diff --git a/clang/test/CIR/CodeGenOpenMP/critical.c b/clang/test/CIR/CodeGenOpenMP/critical.c
new file mode 100644
index 00000000000000..d32b09c0f13e46
--- /dev/null
+++ b/clang/test/CIR/CodeGenOpenMP/critical.c
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %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=OGCG
+
+void work(void);
+
+void unnamed(void) {
+#pragma omp critical
+ work();
+}
+
+void local_var(int *p) {
+#pragma omp critical
+ {
+ int tmp = *p;
+ *p = tmp + 1;
+ }
+}
+
+// CIR-LABEL: cir.func {{.*}}@unnamed()
+// CIR: omp.critical {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+// CIR: cir.return
+
+// CIR-LABEL: cir.func {{.*}}@local_var(
+// CIR: omp.critical {
+// CIR: cir.alloca "tmp"
+// CIR: omp.terminator
+// CIR: }
+
+// LLVM-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
+
+// LLVM-LABEL: define {{.*}}void @unnamed()
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// LLVM-LABEL: define {{.*}}void @local_var(
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// OGCG-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
+
+// OGCG-LABEL: define {{.*}}void @unnamed()
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// OGCG-LABEL: define {{.*}}void @local_var(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
diff --git a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
index c4a97e2b76d05b..3d7f849ecd27df 100644
--- a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
+++ b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
@@ -1,8 +1,8 @@
// RUN: %clang_cc1 -fopenmp -triple x86_64-linux-gnu -fclangir %s -verify -emit-cir -o -
void do_things() {
- // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP OMPCriticalDirective}}
-#pragma omp critical
+ // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP named critical}}
+#pragma omp critical(name)
{}
// expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP OMPSingleDirective}}
>From a733deaa2f78e123688d13cd297a3ad52a894004 Mon Sep 17 00:00:00 2001
From: shrikuma <Shrisha.Kumar at amd.com>
Date: Mon, 9 Nov 2026 18:51:46 +0530
Subject: [PATCH 2/5] [CIR][OpenMP] Emit named critical directive
A named critical section refers to an omp.critical.declare op with the
same name. Create it at module scope the first time the name is used,
and reuse it for later critical sections with the same name.
Critical names share the module symbol table with functions and
globals, so a name that clashes with another symbol is reported as not
yet implemented. Renaming the declaration is not an option because the
lock variable name must match other translation units.
---
clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp | 35 ++++-
clang/test/CIR/CodeGenOpenMP/critical.c | 142 ++++++++++++++++++
.../CIR/CodeGenOpenMP/not-yet-implemented.c | 20 ++-
3 files changed, 188 insertions(+), 9 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
index 11c989a112b660..fa686afeb64f35 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
@@ -210,6 +210,29 @@ CIRGenFunction::emitOMPMasterDirective(const OMPMasterDirective &s) {
return mlir::failure();
}
+/// Find or create the module-level declaration of the critical section \p name.
+/// Returns null, after emitting an error, if the name is already used by
+/// another symbol.
+static mlir::omp::CriticalDeclareOp
+getOrCreateCriticalDeclare(CIRGenFunction &cgf, const OMPCriticalDirective &s,
+ llvm::StringRef name, mlir::Location loc) {
+ CIRGenModule &cgm = cgf.getCIRGenModule();
+ mlir::ModuleOp module = cgm.getModule();
+
+ if (mlir::Operation *sym = mlir::SymbolTable::lookupSymbolIn(module, name)) {
+ if (auto declareOp = mlir::dyn_cast<mlir::omp::CriticalDeclareOp>(sym))
+ return declareOp;
+ cgm.errorNYI(s.getBeginLoc(),
+ "OpenMP critical name that clashes with another symbol");
+ return nullptr;
+ }
+
+ mlir::omp::CriticalDeclareOperands clauseOps;
+ clauseOps.symName = mlir::StringAttr::get(&cgf.getMLIRContext(), name);
+ mlir::OpBuilder modBuilder(module.getBodyRegion());
+ return mlir::omp::CriticalDeclareOp::create(modBuilder, loc, clauseOps);
+}
+
mlir::LogicalResult
CIRGenFunction::emitOMPCriticalDirective(const OMPCriticalDirective &s) {
mlir::Location begin = getLoc(s.getBeginLoc());
@@ -228,13 +251,15 @@ CIRGenFunction::emitOMPCriticalDirective(const OMPCriticalDirective &s) {
llvm::omp::Directive::OMPD_critical)))
return mlir::failure();
- if (!s.getDirectiveName().getAsString().empty()) {
- getCIRGenModule().errorNYI(s.getBeginLoc(), "OpenMP named critical");
- return mlir::failure();
+ mlir::FlatSymbolRefAttr nameAttr;
+ std::string name = s.getDirectiveName().getAsString();
+ if (!name.empty()) {
+ if (!getOrCreateCriticalDeclare(*this, s, name, begin))
+ return mlir::failure();
+ nameAttr = mlir::FlatSymbolRefAttr::get(&getMLIRContext(), name);
}
- auto criticalOp =
- mlir::omp::CriticalOp::create(builder, begin, mlir::FlatSymbolRefAttr());
+ auto criticalOp = mlir::omp::CriticalOp::create(builder, begin, nameAttr);
mlir::Block &block = criticalOp.getRegion().emplaceBlock();
mlir::OpBuilder::InsertionGuard guard(builder);
builder.setInsertionPointToEnd(&block);
diff --git a/clang/test/CIR/CodeGenOpenMP/critical.c b/clang/test/CIR/CodeGenOpenMP/critical.c
index d32b09c0f13e46..e12bbe0c8494a2 100644
--- a/clang/test/CIR/CodeGenOpenMP/critical.c
+++ b/clang/test/CIR/CodeGenOpenMP/critical.c
@@ -6,12 +6,29 @@
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
void work(void);
+void work2(void);
void unnamed(void) {
#pragma omp critical
work();
}
+void named(void) {
+#pragma omp critical(mylock)
+ work();
+}
+
+// The same name in another function reuses the one declaration.
+void named_again(void) {
+#pragma omp critical(mylock)
+ work2();
+}
+
+void no_braces(int *p) {
+#pragma omp critical(mylock)
+ *p += 1;
+}
+
void local_var(int *p) {
#pragma omp critical
{
@@ -20,6 +37,28 @@ void local_var(int *p) {
}
}
+void in_parallel(int *p) {
+#pragma omp parallel
+ {
+#pragma omp critical(mylock)
+ { *p += 1; }
+ }
+}
+
+void nested(void) {
+#pragma omp critical(outer)
+ {
+ work();
+#pragma omp critical(inner)
+ work2();
+ }
+}
+
+// Each name is declared once, at the start of the module.
+// CIR-DAG: omp.critical.declare @mylock
+// CIR-DAG: omp.critical.declare @outer
+// CIR-DAG: omp.critical.declare @inner
+
// CIR-LABEL: cir.func {{.*}}@unnamed()
// CIR: omp.critical {
// CIR: cir.call @work() : () -> ()
@@ -27,30 +66,133 @@ void local_var(int *p) {
// CIR: }
// CIR: cir.return
+// CIR-LABEL: cir.func {{.*}}@named()
+// CIR: omp.critical(@mylock) {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@named_again()
+// CIR: omp.critical(@mylock) {
+// CIR: cir.call @work2() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@no_braces(
+// CIR: omp.critical(@mylock) {
+// CIR: cir.load
+// CIR: cir.add
+// CIR: cir.store
+// CIR: omp.terminator
+// CIR: }
+
// CIR-LABEL: cir.func {{.*}}@local_var(
// CIR: omp.critical {
// CIR: cir.alloca "tmp"
// CIR: omp.terminator
// CIR: }
+// CIR-LABEL: cir.func {{.*}}@in_parallel(
+// CIR: omp.parallel {
+// CIR: omp.critical(@mylock) {
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@nested()
+// CIR: omp.critical(@outer) {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.critical(@inner) {
+// CIR: cir.call @work2() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+
+// The lock variables are shared by every critical section of the same name.
+// Unlike classic codegen, a named critical section always goes through
+// __kmpc_critical_with_hint, with a hint of 0 when none was given.
// LLVM-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
+// LLVM-DAG: @[[MYLOCK:.gomp_critical_user_mylock.var]] = {{.*}}global [8 x i32] zeroinitializer
+// LLVM-DAG: @[[OUTER:.gomp_critical_user_outer.var]] = {{.*}}global [8 x i32] zeroinitializer
+// LLVM-DAG: @[[INNER:.gomp_critical_user_inner.var]] = {{.*}}global [8 x i32] zeroinitializer
// LLVM-LABEL: define {{.*}}void @unnamed()
// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
// LLVM: call void @work()
// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM-LABEL: define {{.*}}void @named()
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]], i32 0)
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// LLVM-LABEL: define {{.*}}void @named_again()
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]], i32 0)
+// LLVM: call void @work2()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// LLVM-LABEL: define {{.*}}void @no_braces(
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]], i32 0)
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
// LLVM-LABEL: define {{.*}}void @local_var(
// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM-LABEL: define {{.*}}void @in_parallel(
+// LLVM: call {{.*}}@__kmpc_fork_call(
+// LLVM-LABEL: define {{.*}}void @in_parallel..omp_par(
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]], i32 0)
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// LLVM-LABEL: define {{.*}}void @nested()
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[OUTER]], i32 0)
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[INNER]], i32 0)
+// LLVM: call void @work2()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[INNER]])
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[OUTER]])
+
// OGCG-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
+// OGCG-DAG: @[[MYLOCK:.gomp_critical_user_mylock.var]] = {{.*}}global [8 x i32] zeroinitializer
+// OGCG-DAG: @[[OUTER:.gomp_critical_user_outer.var]] = {{.*}}global [8 x i32] zeroinitializer
+// OGCG-DAG: @[[INNER:.gomp_critical_user_inner.var]] = {{.*}}global [8 x i32] zeroinitializer
// OGCG-LABEL: define {{.*}}void @unnamed()
// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
// OGCG: call void @work()
// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG-LABEL: define {{.*}}void @named()
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// OGCG-LABEL: define {{.*}}void @named_again()
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+// OGCG: call void @work2()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// OGCG-LABEL: define {{.*}}void @no_braces(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
// OGCG-LABEL: define {{.*}}void @local_var(
// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// OGCG-LABEL: define {{.*}}void @in_parallel(
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @in_parallel.omp_outlined(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// OGCG-LABEL: define {{.*}}void @nested()
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[OUTER]])
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[INNER]])
+// OGCG: call void @work2()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[INNER]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[OUTER]])
diff --git a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
index 3d7f849ecd27df..4d16df20db4e82 100644
--- a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
+++ b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
@@ -1,10 +1,8 @@
// RUN: %clang_cc1 -fopenmp -triple x86_64-linux-gnu -fclangir %s -verify -emit-cir -o -
-void do_things() {
- // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP named critical}}
-#pragma omp critical(name)
- {}
+void clash(void);
+void do_things() {
// expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP OMPSingleDirective}}
#pragma omp single
{}
@@ -30,3 +28,17 @@ void do_things() {
#pragma omp target
{ i = 1; }
}
+
+void use_clash() {
+ clash();
+ // A critical name shares the symbol table with functions.
+ // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP critical name that clashes with another symbol}}
+#pragma omp critical(clash)
+ {}
+}
+
+void hint_nyi() {
+ // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP CRITICAL 'hint' clause}}
+#pragma omp critical(hinted) hint(2)
+ {}
+}
>From dbb313cea4b5c9f215965aed662a67c9a3411d1a Mon Sep 17 00:00:00 2001
From: shrikuma <Shrisha.Kumar at amd.com>
Date: Mon, 9 Nov 2026 18:52:57 +0530
Subject: [PATCH 3/5] [CIR][OpenMP] Support hint clause on critical directive
The hint is stored on the omp.critical.declare op. Sema accepts hints
that combine uncontended with contended, or nonspeculative with
speculative, but the omp dialect verifier rejects them, so report
those as not yet implemented instead of failing module verification.
---
clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp | 24 ++++++++++++++++---
clang/test/CIR/CodeGenOpenMP/critical.c | 24 +++++++++++++++++++
.../CIR/CodeGenOpenMP/not-yet-implemented.c | 8 ++++---
3 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
index fa686afeb64f35..3f3b1de672a7ae 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
@@ -212,7 +212,7 @@ CIRGenFunction::emitOMPMasterDirective(const OMPMasterDirective &s) {
/// Find or create the module-level declaration of the critical section \p name.
/// Returns null, after emitting an error, if the name is already used by
-/// another symbol.
+/// another symbol or the hint cannot be represented.
static mlir::omp::CriticalDeclareOp
getOrCreateCriticalDeclare(CIRGenFunction &cgf, const OMPCriticalDirective &s,
llvm::StringRef name, mlir::Location loc) {
@@ -229,6 +229,22 @@ getOrCreateCriticalDeclare(CIRGenFunction &cgf, const OMPCriticalDirective &s,
mlir::omp::CriticalDeclareOperands clauseOps;
clauseOps.symName = mlir::StringAttr::get(&cgf.getMLIRContext(), name);
+ if (const auto *hint = s.getSingleClause<OMPHintClause>()) {
+ uint64_t value =
+ hint->getHint()->EvaluateKnownConstInt(cgf.getContext()).getZExtValue();
+ // Sema accepts hints that combine uncontended (1) with contended (2), or
+ // nonspeculative (4) with speculative (8), but the omp dialect rejects
+ // them. OpenMP 5.0 [2.17.12] forbids these combinations, so Sema should
+ // diagnose them; once it does, this check can become an assertion.
+ if ((value & 0x3) == 0x3 || (value & 0xC) == 0xC) {
+ cgm.errorNYI(hint->getBeginLoc(),
+ "OpenMP critical 'hint' combining conflicting sync hints");
+ return nullptr;
+ }
+ clauseOps.hint = mlir::IntegerAttr::get(
+ mlir::IntegerType::get(&cgf.getMLIRContext(), 64), value);
+ }
+
mlir::OpBuilder modBuilder(module.getBodyRegion());
return mlir::omp::CriticalDeclareOp::create(modBuilder, loc, clauseOps);
}
@@ -247,8 +263,10 @@ CIRGenFunction::emitOMPCriticalDirective(const OMPCriticalDirective &s) {
OpenMPClauseEmitter ce(*this, getCIRGenModule(), builder, begin,
item->clauses);
- if (mlir::failed(ce.emitNYI(/*nyi=*/OpenMPNYIClauseList<OMPHintClause>{},
- llvm::omp::Directive::OMPD_critical)))
+ // The hint is consumed when the named critical section is declared.
+ if (mlir::failed(ce.emitNYI</*supported=*/OMPHintClause>(
+ /*nyi=*/OpenMPNYIClauseList<>{},
+ llvm::omp::Directive::OMPD_critical)))
return mlir::failure();
mlir::FlatSymbolRefAttr nameAttr;
diff --git a/clang/test/CIR/CodeGenOpenMP/critical.c b/clang/test/CIR/CodeGenOpenMP/critical.c
index e12bbe0c8494a2..1f48f09577e02f 100644
--- a/clang/test/CIR/CodeGenOpenMP/critical.c
+++ b/clang/test/CIR/CodeGenOpenMP/critical.c
@@ -18,6 +18,11 @@ void named(void) {
work();
}
+void named_hint(void) {
+#pragma omp critical(fast) hint(2)
+ work();
+}
+
// The same name in another function reuses the one declaration.
void named_again(void) {
#pragma omp critical(mylock)
@@ -56,6 +61,7 @@ void nested(void) {
// Each name is declared once, at the start of the module.
// CIR-DAG: omp.critical.declare @mylock
+// CIR-DAG: omp.critical.declare @fast hint(contended)
// CIR-DAG: omp.critical.declare @outer
// CIR-DAG: omp.critical.declare @inner
@@ -72,6 +78,12 @@ void nested(void) {
// CIR: omp.terminator
// CIR: }
+// CIR-LABEL: cir.func {{.*}}@named_hint()
+// CIR: omp.critical(@fast) {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+
// CIR-LABEL: cir.func {{.*}}@named_again()
// CIR: omp.critical(@mylock) {
// CIR: cir.call @work2() : () -> ()
@@ -115,6 +127,7 @@ void nested(void) {
// __kmpc_critical_with_hint, with a hint of 0 when none was given.
// LLVM-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
// LLVM-DAG: @[[MYLOCK:.gomp_critical_user_mylock.var]] = {{.*}}global [8 x i32] zeroinitializer
+// LLVM-DAG: @[[FAST:.gomp_critical_user_fast.var]] = {{.*}}global [8 x i32] zeroinitializer
// LLVM-DAG: @[[OUTER:.gomp_critical_user_outer.var]] = {{.*}}global [8 x i32] zeroinitializer
// LLVM-DAG: @[[INNER:.gomp_critical_user_inner.var]] = {{.*}}global [8 x i32] zeroinitializer
@@ -128,6 +141,11 @@ void nested(void) {
// LLVM: call void @work()
// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+// LLVM-LABEL: define {{.*}}void @named_hint()
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[FAST]], i32 2)
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[FAST]])
+
// LLVM-LABEL: define {{.*}}void @named_again()
// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]], i32 0)
// LLVM: call void @work2()
@@ -157,6 +175,7 @@ void nested(void) {
// OGCG-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
// OGCG-DAG: @[[MYLOCK:.gomp_critical_user_mylock.var]] = {{.*}}global [8 x i32] zeroinitializer
+// OGCG-DAG: @[[FAST:.gomp_critical_user_fast.var]] = {{.*}}global [8 x i32] zeroinitializer
// OGCG-DAG: @[[OUTER:.gomp_critical_user_outer.var]] = {{.*}}global [8 x i32] zeroinitializer
// OGCG-DAG: @[[INNER:.gomp_critical_user_inner.var]] = {{.*}}global [8 x i32] zeroinitializer
@@ -170,6 +189,11 @@ void nested(void) {
// OGCG: call void @work()
// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+// OGCG-LABEL: define {{.*}}void @named_hint()
+// OGCG: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[FAST]], i32 2)
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[FAST]])
+
// OGCG-LABEL: define {{.*}}void @named_again()
// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
// OGCG: call void @work2()
diff --git a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
index 4d16df20db4e82..1afc8a683decfb 100644
--- a/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
+++ b/clang/test/CIR/CodeGenOpenMP/not-yet-implemented.c
@@ -37,8 +37,10 @@ void use_clash() {
{}
}
-void hint_nyi() {
- // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP CRITICAL 'hint' clause}}
-#pragma omp critical(hinted) hint(2)
+void conflicting_hint() {
+ // Sema accepts uncontended (1) together with contended (2), but the omp
+ // dialect rejects it.
+ // expected-error at +1{{ClangIR code gen Not Yet Implemented: OpenMP critical 'hint' combining conflicting sync hints}}
+#pragma omp critical(conflict) hint(3)
{}
}
>From 6dd81ba6fb9d6bba709bd4495105f01788c07095 Mon Sep 17 00:00:00 2001
From: shrikuma <Shrisha.Kumar at amd.com>
Date: Mon, 9 Nov 2026 18:54:11 +0530
Subject: [PATCH 4/5] [CIR][OpenMP] Test critical combined with other
directives
Add tests for critical inside parallel (with and without braces, and
with num_threads and if clauses), next to a barrier, around a parallel
region, and inside target parallel.
---
clang/test/CIR/CodeGenOpenMP/critical.c | 177 ++++++++++++++++++++++++
1 file changed, 177 insertions(+)
diff --git a/clang/test/CIR/CodeGenOpenMP/critical.c b/clang/test/CIR/CodeGenOpenMP/critical.c
index 1f48f09577e02f..dd3d94d82d8dca 100644
--- a/clang/test/CIR/CodeGenOpenMP/critical.c
+++ b/clang/test/CIR/CodeGenOpenMP/critical.c
@@ -59,6 +59,49 @@ void nested(void) {
}
}
+// Combinations with other directives.
+
+void parallel_no_braces(void) {
+#pragma omp parallel
+#pragma omp critical
+ work();
+}
+
+void parallel_clauses(int n, int cond) {
+#pragma omp parallel num_threads(n) if(cond)
+ {
+#pragma omp critical(mylock)
+ work();
+ }
+}
+
+void barrier_between(void) {
+#pragma omp parallel
+ {
+#pragma omp critical
+ work();
+#pragma omp barrier
+#pragma omp critical(mylock)
+ work2();
+ }
+}
+
+void parallel_in_critical(void) {
+#pragma omp critical(outer)
+ {
+#pragma omp parallel
+ work();
+ }
+}
+
+void target_parallel_critical(void) {
+#pragma omp target parallel
+ {
+#pragma omp critical
+ work();
+ }
+}
+
// Each name is declared once, at the start of the module.
// CIR-DAG: omp.critical.declare @mylock
// CIR-DAG: omp.critical.declare @fast hint(contended)
@@ -122,6 +165,59 @@ void nested(void) {
// CIR: omp.terminator
// CIR: }
+// CIR-LABEL: cir.func {{.*}}@parallel_no_braces()
+// CIR: omp.parallel {
+// CIR: omp.critical {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@parallel_clauses(
+// CIR: omp.parallel if(%{{.*}}) num_threads(%{{.*}} : i32) {
+// CIR: omp.critical(@mylock) {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@barrier_between()
+// CIR: omp.parallel {
+// CIR: omp.critical {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.barrier
+// CIR: omp.critical(@mylock) {
+// CIR: cir.call @work2() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@parallel_in_critical()
+// CIR: omp.critical(@outer) {
+// CIR: omp.parallel {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@target_parallel_critical()
+// CIR: omp.target
+// CIR: omp.parallel {
+// CIR: omp.critical {
+// CIR: cir.call @work() : () -> ()
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+
// The lock variables are shared by every critical section of the same name.
// Unlike classic codegen, a named critical section always goes through
// __kmpc_critical_with_hint, with a hint of 0 when none was given.
@@ -173,6 +269,47 @@ void nested(void) {
// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[INNER]])
// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[OUTER]])
+// LLVM-LABEL: define {{.*}}void @parallel_no_braces()
+// LLVM: call {{.*}}@__kmpc_fork_call(
+// LLVM-LABEL: define {{.*}}void @parallel_no_braces..omp_par(
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// LLVM-LABEL: define {{.*}}void @parallel_clauses(
+// LLVM: call {{.*}}@__kmpc_fork_call_if(
+// LLVM-LABEL: define {{.*}}void @parallel_clauses..omp_par(
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]], i32 0)
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// LLVM-LABEL: define {{.*}}void @barrier_between()
+// LLVM: call {{.*}}@__kmpc_fork_call(
+// LLVM-LABEL: define {{.*}}void @barrier_between..omp_par(
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @__kmpc_barrier(
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]], i32 0)
+// LLVM: call void @work2()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// The parallel region runs while the calling thread holds the lock.
+// LLVM-LABEL: define {{.*}}void @parallel_in_critical()
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[OUTER]], i32 0)
+// LLVM: call {{.*}}@__kmpc_fork_call(
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[OUTER]])
+// LLVM-LABEL: define {{.*}}void @parallel_in_critical..omp_par(
+// LLVM: call void @work()
+
+// LLVM-LABEL: define {{.*}}void @target_parallel_critical()
+// LLVM-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_target_parallel_critical_l{{[0-9]+}}(
+// LLVM: call {{.*}}@__kmpc_fork_call(
+// LLVM-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_target_parallel_critical_l{{[0-9]+}}..omp_par(
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @work()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
// OGCG-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
// OGCG-DAG: @[[MYLOCK:.gomp_critical_user_mylock.var]] = {{.*}}global [8 x i32] zeroinitializer
// OGCG-DAG: @[[FAST:.gomp_critical_user_fast.var]] = {{.*}}global [8 x i32] zeroinitializer
@@ -220,3 +357,43 @@ void nested(void) {
// OGCG: call void @work2()
// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[INNER]])
// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[OUTER]])
+
+// OGCG-LABEL: define {{.*}}void @parallel_no_braces()
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @parallel_no_braces.omp_outlined(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// OGCG-LABEL: define {{.*}}void @parallel_clauses(
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @parallel_clauses.omp_outlined(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// OGCG-LABEL: define {{.*}}void @barrier_between()
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @barrier_between.omp_outlined(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @__kmpc_barrier(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+// OGCG: call void @work2()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[MYLOCK]])
+
+// OGCG-LABEL: define {{.*}}void @parallel_in_critical()
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[OUTER]])
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[OUTER]])
+// OGCG-LABEL: define {{.*}}void @parallel_in_critical.omp_outlined(
+// OGCG: call void @work()
+
+// OGCG-LABEL: define {{.*}}void @target_parallel_critical()
+// OGCG-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_target_parallel_critical_l{{[0-9]+}}(
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @__omp_offloading_{{.*}}_target_parallel_critical_l{{[0-9]+}}.omp_outlined(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @work()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
>From 8a1a30ecad5e45c1024a65db38a1d2835de00db3 Mon Sep 17 00:00:00 2001
From: shrikuma <Shrisha.Kumar at amd.com>
Date: Mon, 9 Nov 2026 18:54:12 +0530
Subject: [PATCH 5/5] [CIR][OpenMP] Port critical codegen tests from classic
codegen
Port the cases from clang/test/OpenMP/critical_codegen.cpp: named
critical sections with and without a hint, a critical around an
infinite loop, critical inside lambdas, through a reference, and in
template instantiations that share one lock. Exceptions are left out
because OpenMP regions in CIR do not yet get a terminate scope.
---
clang/test/CIR/CodeGenOpenMP/critical.c | 2 +
clang/test/CIR/CodeGenOpenMP/critical.cpp | 203 ++++++++++++++++++++++
2 files changed, 205 insertions(+)
create mode 100644 clang/test/CIR/CodeGenOpenMP/critical.cpp
diff --git a/clang/test/CIR/CodeGenOpenMP/critical.c b/clang/test/CIR/CodeGenOpenMP/critical.c
index dd3d94d82d8dca..43b08b5578d48e 100644
--- a/clang/test/CIR/CodeGenOpenMP/critical.c
+++ b/clang/test/CIR/CodeGenOpenMP/critical.c
@@ -5,6 +5,8 @@
// 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=OGCG
+// C++-specific cases (lambdas, references, templates) are in critical.cpp.
+
void work(void);
void work2(void);
diff --git a/clang/test/CIR/CodeGenOpenMP/critical.cpp b/clang/test/CIR/CodeGenOpenMP/critical.cpp
new file mode 100644
index 00000000000000..7cea239cb668d9
--- /dev/null
+++ b/clang/test/CIR/CodeGenOpenMP/critical.cpp
@@ -0,0 +1,203 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %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=OGCG
+
+// Cases adapted from clang/test/OpenMP/critical_codegen.cpp, without
+// exceptions. Language-independent cases (names, hints, nesting, combinations
+// with other directives) are in critical.c.
+
+void foo();
+
+int critical_in_main() {
+ char a;
+#pragma omp critical
+ a = 2;
+#pragma omp critical(the_name)
+ foo();
+#pragma omp critical(the_name1) hint(4)
+ foo();
+ if (a)
+#pragma omp critical(the_name)
+ while (1)
+ ;
+ foo();
+ return a;
+}
+
+void lambda_critical(int a, int b) {
+ auto l = [=]() {
+#pragma omp critical
+ {
+ int c = a + b;
+ }
+ };
+ l();
+ auto l1 = [=]() {
+#pragma omp parallel
+#pragma omp critical
+ {
+ int c = a + b;
+ }
+ };
+ l1();
+}
+
+struct S {
+ int a;
+};
+
+void critical_ref(S &s) {
+ ++s.a;
+#pragma omp critical
+ ++s.a;
+}
+
+// Every instantiation uses the same lock.
+template <typename T> T critical_template(T x) {
+#pragma omp critical(tmpl)
+ x += 1;
+ return x;
+}
+
+int use_template() { return critical_template(1) + (int)critical_template(2.0); }
+
+// CIR-DAG: omp.critical.declare @the_name{{ }}
+// CIR-DAG: omp.critical.declare @the_name1 hint(nonspeculative)
+// CIR-DAG: omp.critical.declare @tmpl
+
+// CIR-LABEL: cir.func {{.*}}@_Z16critical_in_mainv()
+// CIR: %[[A:.*]] = cir.alloca "a"
+// CIR: omp.critical {
+// CIR: cir.store {{.*}}, %[[A]]
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.critical(@the_name) {
+// CIR: cir.call @_Z3foov()
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.critical(@the_name1) {
+// CIR: cir.call @_Z3foov()
+// CIR: omp.terminator
+// CIR: }
+// CIR: cir.if
+// CIR: omp.critical(@the_name) {
+// CIR: cir.while {
+// CIR: omp.terminator
+// CIR: }
+// CIR: cir.call @_Z3foov()
+
+// CIR-LABEL: cir.func {{.*}}@_ZZ15lambda_criticaliiENK3$_0clEv(
+// CIR: omp.critical {
+// CIR: cir.alloca "c"
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@_ZZ15lambda_criticaliiENK3$_1clEv(
+// CIR: omp.parallel {
+// CIR: omp.critical {
+// CIR: cir.alloca "c"
+// CIR: omp.terminator
+// CIR: }
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@_Z12critical_refR1S(
+// CIR: cir.inc
+// CIR: omp.critical {
+// CIR: cir.get_member {{.*}}{name = "a"}
+// CIR: cir.inc
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@_Z17critical_templateIiET_S0_(
+// CIR: omp.critical(@tmpl) {
+// CIR: omp.terminator
+// CIR: }
+
+// CIR-LABEL: cir.func {{.*}}@_Z17critical_templateIdET_S0_(
+// CIR: omp.critical(@tmpl) {
+// CIR: omp.terminator
+// CIR: }
+
+// LLVM-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
+// LLVM-DAG: @[[THE_NAME:.gomp_critical_user_the_name.var]] = {{.*}}global [8 x i32] zeroinitializer
+// LLVM-DAG: @[[THE_NAME1:.gomp_critical_user_the_name1.var]] = {{.*}}global [8 x i32] zeroinitializer
+// LLVM-DAG: @[[TMPL:.gomp_critical_user_tmpl.var]] = {{.*}}global [8 x i32] zeroinitializer
+
+// LLVM-LABEL: define {{.*}}i32 @_Z16critical_in_mainv()
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: store i8 2,
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[THE_NAME]], i32 0)
+// LLVM: call void @_Z3foov()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[THE_NAME]])
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[THE_NAME1]], i32 4)
+// LLVM: call void @_Z3foov()
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[THE_NAME1]])
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[THE_NAME]], i32 0)
+// LLVM: call void @_Z3foov()
+
+// LLVM-LABEL: define {{.*}}void @"_ZZ15lambda_criticaliiENK3$_0clEv"(
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// LLVM-LABEL: define {{.*}}void @"_ZZ15lambda_criticaliiENK3$_1clEv"(
+// LLVM: call {{.*}}@__kmpc_fork_call(
+// LLVM-LABEL: define {{.*}}void @"_ZZ15lambda_criticaliiENK3$_1clEv..omp_par"(
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// LLVM-LABEL: define {{.*}}void @_Z12critical_refR1S(
+// LLVM: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// LLVM-LABEL: define {{.*}}i32 @_Z17critical_templateIiET_S0_(
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[TMPL]], i32 0)
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[TMPL]])
+
+// LLVM-LABEL: define {{.*}}double @_Z17critical_templateIdET_S0_(
+// LLVM: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[TMPL]], i32 0)
+// LLVM: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[TMPL]])
+
+// OGCG-DAG: @[[UNNAMED:.gomp_critical_user_.var]] = {{.*}}global [8 x i32] zeroinitializer
+// OGCG-DAG: @[[THE_NAME:.gomp_critical_user_the_name.var]] = {{.*}}global [8 x i32] zeroinitializer
+// OGCG-DAG: @[[THE_NAME1:.gomp_critical_user_the_name1.var]] = {{.*}}global [8 x i32] zeroinitializer
+// OGCG-DAG: @[[TMPL:.gomp_critical_user_tmpl.var]] = {{.*}}global [8 x i32] zeroinitializer
+
+// OGCG-LABEL: define {{.*}}i32 @_Z16critical_in_mainv()
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: store i8 2,
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[THE_NAME]])
+// OGCG: call void @_Z3foov()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[THE_NAME]])
+// OGCG: call void @__kmpc_critical_with_hint({{.*}}, i32 {{.*}}, ptr @[[THE_NAME1]], i32 4)
+// OGCG: call void @_Z3foov()
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[THE_NAME1]])
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[THE_NAME]])
+// OGCG: call void @_Z3foov()
+
+// OGCG-LABEL: define {{.*}}void @"_ZZ15lambda_criticaliiENK3$_0clEv"(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// OGCG-LABEL: define {{.*}}void @"_ZZ15lambda_criticaliiENK3$_1clEv"(
+// OGCG: call {{.*}}@__kmpc_fork_call(
+// OGCG-LABEL: define {{.*}}void @"_ZZ15lambda_criticaliiENK3$_1clEv.omp_outlined"(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// OGCG-LABEL: define {{.*}}void @_Z12critical_refR1S(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[UNNAMED]])
+
+// OGCG-LABEL: define {{.*}}i32 @_Z17critical_templateIiET_S0_(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[TMPL]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[TMPL]])
+
+// OGCG-LABEL: define {{.*}}double @_Z17critical_templateIdET_S0_(
+// OGCG: call void @__kmpc_critical({{.*}}, i32 {{.*}}, ptr @[[TMPL]])
+// OGCG: call void @__kmpc_end_critical({{.*}}, i32 {{.*}}, ptr @[[TMPL]])
More information about the cfe-commits
mailing list