https://github.com/pedropiin updated https://github.com/llvm/llvm-project/pull/204999
>From 19547508da4845163cbc76ddc23aad6c7edadd07 Mon Sep 17 00:00:00 2001 From: pedropiin <[email protected]> Date: Sun, 21 Jun 2026 15:12:26 -0300 Subject: [PATCH] [CIR][OpenMP] Implement lowering for the 'if' clause for 'parallel' directive --- clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp | 23 ++++++++++++++++++++ clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h | 2 ++ clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp | 5 +++-- clang/test/CIR/CodeGenOpenMP/parallel.c | 22 +++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp index 16ac4440660b5..8155e4697e32d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp @@ -93,6 +93,29 @@ bool OpenMPClauseEmitter::emitProcBind( return false; } +bool OpenMPClauseEmitter::emitIf(mlir::omp::IfClauseOps &result) const { + for (const OMPClause *clause : clauses) { + const auto *ic = dyn_cast<OMPIfClause>(clause); + if (!ic) + continue; + + Expr *ifCondition = ic->getCondition(); + mlir::Value ifBoolValue = cgf.evaluateExprAsBool(ifCondition); // !cir.bool + + mlir::Type uIntType = builder.getUIntNTy(1); + mlir::Value ifUIntValue = + builder.createBoolToInt(ifBoolValue, uIntType); // u1 + + mlir::Type intType = builder.getI1Type(); + mlir::Value ifExpr = + builder.createBuiltinIntCast(ifUIntValue, intType); // i1 + + result.ifExpr = ifExpr; + return true; + } + return false; +} + bool OpenMPClauseEmitter::emitMap( mlir::omp::MapClauseOps &result, llvm::SmallVectorImpl<const VarDecl *> *mapSyms) const { diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h index 54c7366b1d769..ee048296f1946 100644 --- a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h +++ b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.h @@ -42,6 +42,8 @@ class OpenMPClauseEmitter { bool emitProcBind(mlir::omp::ProcBindClauseOps &result) const; + bool emitIf(mlir::omp::IfClauseOps &result) const; + /// Emit map clauses. The optional \p mapSyms parameter collects the /// VarDecls corresponding to each map operand. bool emitMap(mlir::omp::MapClauseOps &result, diff --git a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp index 17a1fb8090f5c..4766891dc5b70 100644 --- a/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenStmtOpenMP.cpp @@ -39,10 +39,11 @@ CIRGenFunction::emitOMPParallelDirective(const OMPParallelDirective &s) { mlir::omp::ParallelOperands clauseOps; OpenMPClauseEmitter ce(*this, getCIRGenModule(), builder, begin, s.clauses()); ce.emitProcBind(clauseOps); - ce.emitNYI</*supported=*/OMPProcBindClause>( + ce.emitIf(clauseOps); + ce.emitNYI</*supported=*/OMPProcBindClause, OMPIfClause>( /*nyi=*/OpenMPNYIClauseList< OMPAllocateClause, OMPCopyinClause, OMPDefaultClause, - OMPFirstprivateClause, OMPIfClause, OMPNumThreadsClause, + OMPFirstprivateClause, OMPNumThreadsClause, OMPPrivateClause, OMPReductionClause, OMPSharedClause>{}, llvm::omp::Directive::OMPD_parallel); diff --git a/clang/test/CIR/CodeGenOpenMP/parallel.c b/clang/test/CIR/CodeGenOpenMP/parallel.c index 36a48b38ee789..b3b82fbd3ea23 100644 --- a/clang/test/CIR/CodeGenOpenMP/parallel.c +++ b/clang/test/CIR/CodeGenOpenMP/parallel.c @@ -84,3 +84,25 @@ void proc_bind_parallel() { // CHECK-NEXT: omp.terminator // CHECK-NEXT: } } + +void if_parallel() { + // CHECK: omp.parallel if(%{{.*}}) { +#pragma omp parallel if (1) + {} + // CHECK-NEXT: omp.terminator + // CHECK-NEXT: } + +int validCondition = 10; + // CHECK: omp.parallel if(%{{.*}}) { +#pragma omp parallel if (validCondition) + {} + // CHECK-NEXT: omp.terminator + // CHECK-NEXT: } + +void *nullPtr = ((void *)0); + // CHECK: omp.parallel if(%{{.*}}) { +#pragma omp parallel if (nullPtr) + {} + // CHECK-NEXT: omp.terminator + // CHECK-NEXT: } +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
