[clang] [CIR][OpenMP] Implement unnamed critical directive (PR #236140)
Jan Leyonberg via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 11 05:01:47 PST 2026
================
@@ -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
More information about the cfe-commits
mailing list