================
@@ -30,14 +32,34 @@ CIRGenFunction::emitOMPErrorDirective(const 
OMPErrorDirective &s) {
   getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP OMPErrorDirective");
   return mlir::failure();
 }
-mlir::LogicalResult
-CIRGenFunction::emitOMPParallelDirective(const OMPParallelDirective &s) {
-  mlir::LogicalResult res = mlir::success();
-  mlir::Location begin = getLoc(s.getBeginLoc());
-  mlir::Location end = getLoc(s.getEndLoc());
+
+/// Returns the subset of \p s's clauses that are allowed on the given leaf
+/// directive.
+static llvm::SmallVector<const OMPClause *>
+getLeafClauses(CIRGenFunction &cgf, const OMPExecutableDirective &s,
+               llvm::omp::Directive leaf) {
+  unsigned version = cgf.getContext().getLangOpts().OpenMP;
+  llvm::SmallVector<const OMPClause *> result;
+  for (const OMPClause *c : s.clauses())
+    if (llvm::omp::isAllowedClauseForDirective(leaf, c->getClauseKind(),
+                                               version))
+      result.push_back(c);
+  return result;
+}
+
+template <typename DirectiveTy>
+static mlir::LogicalResult
+emitParallelOp(CIRGenFunction &cgf, const DirectiveTy &s, mlir::Location begin,
+               mlir::Location end,
+               llvm::function_ref<mlir::LogicalResult()> emitBody) {
+  CIRGenBuilderTy &builder = cgf.getBuilder();
+  CIRGenModule &cgm = cgf.getCIRGenModule();
+
+  llvm::SmallVector<const OMPClause *> clauses =
----------------
skatrak wrote:

Nit: Rather than evaluating clauses as part of the same function, I'd suggest 
splitting it up like we do in Flang lowering (`genParallelOp` + 
`genParallelClauses`) and use operand structures to pass data around. Now it 
doesn't make a lot of difference, but this is part of what enabled us to reuse 
the same lowering functions for composite constructs.

Specifically, how I see it:
- `CIRGenFunction::emitOMP*Directive`: Split the clauses per leaf construct, 
call all the relevant `emit*Clauses` and `emit*Op` helpers.
- `emit*Clauses`: Use an `OpenMPClauseEmitter` to evaluate present clauses and 
populate an operand structure.
- `emit*Op`: Create the operation itself, based on the operand structure.

https://github.com/llvm/llvm-project/pull/207019
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to