================
@@ -211,8 +211,25 @@ CIRGenFunction::emitOMPMasterDirective(const 
OMPMasterDirective &s) {
 }
 mlir::LogicalResult
 CIRGenFunction::emitOMPCriticalDirective(const OMPCriticalDirective &s) {
-  getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP 
OMPCriticalDirective");
-  return mlir::failure();
+  if (s.getDirectiveName().getName()) {
+    getCIRGenModule().errorNYI(s.getSourceRange(), "OpenMP named critical");
+    return mlir::failure();
+  }
+  assert(s.clauses().empty() && "Sema rejects hint without a name");
+
+  mlir::Location begin = getLoc(s.getBeginLoc());
+  auto criticalOp =
+      mlir::omp::CriticalOp::create(builder, begin, mlir::FlatSymbolRefAttr());
+
+  mlir::Block &block = criticalOp.getRegion().emplaceBlock();
+  mlir::OpBuilder::InsertionGuard guard(builder);
+  builder.setInsertionPointToEnd(&block);
+
+  LexicalScope ls{*this, begin, builder.getInsertionBlock()};
+  mlir::LogicalResult res =
+      emitStmt(s.getAssociatedStmt(), /*useCurrentScope=*/true);
----------------
jsjodin wrote:

Compiling with -O2 gives an error because of the lexical scoping. You would 
have to add a ls.forceCleanup(); for now, I have a helper function in #229256 
that will take care of this as well. Also add -O2 runs in the tests.

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

Reply via email to