[clang] [OpenMP][CIR] Implement basic 'parallel' lowering + some clause infra (PR #172308)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 15 08:28:34 PST 2025


================
@@ -30,8 +30,35 @@ CIRGenFunction::emitOMPErrorDirective(const OMPErrorDirective &s) {
 }
 mlir::LogicalResult
 CIRGenFunction::emitOMPParallelDirective(const OMPParallelDirective &s) {
-  getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPParallelDirective");
-  return mlir::failure();
+  mlir::LogicalResult res = mlir::success();
+  llvm::SmallVector<mlir::Type> retTy;
+  llvm::SmallVector<mlir::Value> operands;
+  mlir::Location begin = getLoc(s.getBeginLoc());
+  mlir::Location end = getLoc(s.getEndLoc());
+
+  auto parallelOp =
+      mlir::omp::ParallelOp::create(builder, begin, retTy, operands);
+  emitOpenMPClauses(parallelOp, s.clauses());
+
+  {
+    mlir::Block &block = parallelOp.getRegion().emplaceBlock();
+    mlir::OpBuilder::InsertionGuard guardCase(builder);
+    builder.setInsertionPointToEnd(&block);
+
+    LexicalScope ls{*this, begin, builder.getInsertionBlock()};
+
+    if (s.hasCancel())
+      getCIRGenModule().errorNYI(s.getBeginLoc(),
+                                 "OpenMP Parallel with Cancel");
+    if (s.getTaskReductionRefExpr())
+      getCIRGenModule().errorNYI(s.getBeginLoc(),
+                                 "OpenMP Parallel with Task Reduction");
+
+    res = emitStmt(s.getAssociatedStmt(), /*useCurrentScope=*/true);
----------------
erichkeane wrote:

At the moment this has a 'not yet implemented' diagnostic, due to lack of `CapturedStmt` being implemented.  I don't believe we're at the point where 'does anything valuable at runtime' is an expectation of this.

That said, I'm not sure what tests you're asking for, can you clarify?  Frankly, my familiarity with OpenMP is very limited and I'm really just trying to show how the 'next' person along can start adding things piecemeal, so you might have to hand-hold a little :) 

https://github.com/llvm/llvm-project/pull/172308


More information about the cfe-commits mailing list