================
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Emit OpenMP clause nodes as CIR code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CIRGenFunction.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+
+using namespace clang;
+using namespace clang::CIRGen;
+
+namespace {
+template <typename OpTy>
+class OpenMPClauseCIREmitter final
+    : public ConstOMPClauseVisitor<OpenMPClauseCIREmitter<OpTy>> {
+  OpTy &operation;
+  CIRGen::CIRGenFunction &cgf;
+  CIRGen::CIRGenBuilderTy &builder;
+
+public:
+  OpenMPClauseCIREmitter(OpTy &operation, CIRGen::CIRGenFunction &cgf,
+                         CIRGen::CIRGenBuilderTy &builder)
+      : operation(operation), cgf(cgf), builder(builder) {}
+
+  void VisitOMPClause(const OMPClause *clause) {
+    cgf.cgm.errorNYI(clause->getBeginLoc(), "OpenMPClause ",
+                     clause->getClauseKind());
+  }
+
+  void emitClauses(ArrayRef<const OMPClause *> clauses) {
+    for (const auto *c : clauses)
+      this->Visit(c);
+  }
+};
+template <typename OpTy>
+auto makeClauseEmitter(OpTy &op, CIRGen::CIRGenFunction &cgf,
+                       CIRGen::CIRGenBuilderTy &builder) {
+  return OpenMPClauseCIREmitter<OpTy>(op, cgf, builder);
+}
+} // namespace
+
+template <typename Op>
+void CIRGenFunction::emitOpenMPClauses(Op &op,
+                                       ArrayRef<const OMPClause *> clauses) {
+  mlir::OpBuilder::InsertionGuard guardCase(builder);
+  builder.setInsertionPoint(op);
+  makeClauseEmitter(op, *this, builder).emitClauses(clauses);
+}
+
+// We're defining the template for this in a .cpp file, so we have to 
explicitly
+// specialize the templates.
+#define EXPL_SPEC(N)                                                           
\
+  template void CIRGenFunction::emitOpenMPClauses<N>(                          
\
+      N &, ArrayRef<const OMPClause *>);
+EXPL_SPEC(mlir::omp::ParallelOp)
----------------
erichkeane wrote:

I did the same thing here for OpenACC, we'll end up having to manually 
instantiate each of these (though it is pretty trivial to do so), but it means 
a significant build-time improvement by only instantiating the visitors 1x.

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

Reply via email to