Skip to content

Conversation

@erichkeane
Copy link
Collaborator

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.

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.
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Dec 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 15, 2025

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)

Changes

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.


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

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp (+3-2)
  • (added) clang/test/CIR/CodeGenOpenMP/barrier.c (+14)
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
+}

Copy link
Member

@ergawy ergawy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see the support being added. LG.

@erichkeane erichkeane merged commit 49f6979 into llvm:main Dec 16, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants