[clang] [OpenMP][CIR] Implement 'barrier' lowering (PR #172305)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 15 06:24:26 PST 2025
https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/172305
As my next patch showing how OMP lowering should work, here is a simple construct implementation. Best I can tell, the 'barrier' construct just results in a omp.barrier to be emitted into the IR. This is our first use of the omp dialect, though the dialect was already added in my last patch.
>From 70c9ad4e08e03e79d43eb964c9d0d3fda87069de Mon Sep 17 00:00:00 2001
From: erichkeane <ekeane at nvidia.com>
Date: Fri, 12 Dec 2025 06:40:25 -0800
Subject: [PATCH] [OpenMP][CIR] Implement 'barrier' lowering
As my next patch showing how OMP lowering should work, here is a simple
construct implementation. Best I can tell, the 'barrier' construct just
results in a omp.barrier to be emitted into the IR. This is our first
use of the omp dialect, though the dialect was already added in my last
patch.
---
clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp | 5 +++--
clang/test/CIR/CodeGenOpenMP/barrier.c | 14 ++++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 clang/test/CIR/CodeGenOpenMP/barrier.c
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
index 7fb2dd085acd3..08eeefcbeb151 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp
@@ -47,8 +47,9 @@ CIRGenFunction::emitOMPTaskyieldDirective(const OMPTaskyieldDirective &s) {
}
mlir::LogicalResult
CIRGenFunction::emitOMPBarrierDirective(const OMPBarrierDirective &s) {
- getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPBarrierDirective");
- return mlir::failure();
+ mlir::omp::BarrierOp::create(builder, getLoc(s.getBeginLoc()));
+ assert(s.clauses().empty() && "omp barrier doesn't support clauses");
+ return mlir::success();
}
mlir::LogicalResult
CIRGenFunction::emitOMPMetaDirective(const OMPMetaDirective &s) {
diff --git a/clang/test/CIR/CodeGenOpenMP/barrier.c b/clang/test/CIR/CodeGenOpenMP/barrier.c
new file mode 100644
index 0000000000000..83520b26dfe05
--- /dev/null
+++ b/clang/test/CIR/CodeGenOpenMP/barrier.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fopenmp -emit-cir -fclangir %s -o - | FileCheck %s
+
+void before(void);
+void after(void);
+
+void emit_simple_barrier() {
+ // CHECK: cir.func{{.*}}@emit_simple_barrier
+ before();
+ // CHECK-NEXT: cir.call @before
+#pragma omp barrier
+ // CHECK-NEXT: omp.barrier
+ after();
+ // CHECK-NEXT: cir.call @after
+}
More information about the cfe-commits
mailing list