[clang] [CIR][OpenMP] Add support for combined target parallel directives (PR #207019)

Sergio Afonso via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 2 07:14:14 PDT 2026


================
@@ -361,9 +436,35 @@ mlir::LogicalResult CIRGenFunction::emitOMPTargetExitDataDirective(
 }
 mlir::LogicalResult CIRGenFunction::emitOMPTargetParallelDirective(
     const OMPTargetParallelDirective &s) {
-  getCIRGenModule().errorNYI(s.getSourceRange(),
-                             "OpenMP OMPTargetParallelDirective");
-  return mlir::failure();
+  mlir::Location begin = getLoc(s.getBeginLoc());
+  mlir::Location end = getLoc(s.getEndLoc());
+
+  // Split the clauses per leaf construct and evaluate them into their operand
+  // structures before creating the nested target/parallel ops.
+  llvm::SmallVector<const OMPClause *> targetClauses =
+      getLeafClauses(*this, s, llvm::omp::OMPD_target);
+  mlir::omp::TargetExtOperands targetOps;
+  llvm::SmallVector<const VarDecl *> mapSyms;
+  if (mlir::failed(emitTargetClauses(*this, getCIRGenModule(), builder, begin,
+                                     targetClauses, targetOps, mapSyms)))
+    return mlir::failure();
+
+  llvm::SmallVector<const OMPClause *> parallelClauses =
+      getLeafClauses(*this, s, llvm::omp::OMPD_parallel);
+  mlir::omp::ParallelOperands parallelOps;
+  if (mlir::failed(emitParallelClauses(*this, getCIRGenModule(), builder, begin,
+                                       parallelClauses, parallelOps)))
+    return mlir::failure();
----------------
skatrak wrote:

This should be evaluated inside of the target region, in the `emitTargetOp` callback. Otherwise, we could end up passing outside values into the IsolatedFromAbove region. In general, I think that's the pattern we should follow for combined constructs. We evaluate all leafs in advance only for composite ones in Flang.

The set of specific clauses/expressions that must actually be host-evaluated in this way is quite restricted.

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


More information about the cfe-commits mailing list