https://github.com/pedropiin updated https://github.com/llvm/llvm-project/pull/204999
>From d0154d89c57cee9db7e607c9396ac0619c489858 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 | 20 +++++++++++++++++ .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 3 +++ clang/test/CIR/CodeGenOpenMP/parallel.c | 22 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp index a0f0ea9299c8d..068aa8a2efb82 100644 --- a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp @@ -66,6 +66,26 @@ class OpenMPClauseCIREmitter final } } + void VisitOMPIfClause(const OMPIfClause *clause) { + if constexpr (std::is_same_v<OpTy, mlir::omp::ParallelOp>) { + Expr *ifExpr = clause->getCondition(); + mlir::Value ifValue = cgf.emitScalarExpr(ifExpr); + mlir::Location ifLoc = cgf.cgm.getLoc(ifExpr->getBeginLoc()); + + mlir::Type stdBoolType = builder.getI1Type(); + + mlir::Value unrealizedCastIf = mlir::UnrealizedConversionCastOp::create( + builder, ifLoc, stdBoolType, ifValue) + .getResult(0); + + operation.getIfExprMutable().append(unrealizedCastIf); + } else { + cgf.cgm.errorNYI( + clause->getBeginLoc(), + "OMPProcBindClause unimplemented on this directive kind"); + } + } + void emitClauses(ArrayRef<const OMPClause *> clauses) { for (const auto *c : clauses) this->Visit(c); diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index c844375a000e0..2dc8dc45258dc 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -17,6 +17,7 @@ #include "mlir/Conversion/LLVMCommon/TypeConverter.h" #include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h" +#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h" #include "mlir/Dialect/DLTI/DLTI.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" @@ -3695,6 +3696,7 @@ void ConvertCIRToLLVMPass::runOnOperation() { mlir::populateOpenMPToLLVMConversionPatterns(converter, patterns); target.addIllegalDialect<mlir::BuiltinDialect, cir::CIRDialect, mlir::func::FuncDialect>(); + target.addLegalOp<mlir::UnrealizedConversionCastOp>(); llvm::SmallVector<mlir::Operation *> ops; ops.push_back(module); @@ -4935,6 +4937,7 @@ void populateCIRToLLVMPasses(mlir::OpPassManager &pm) { mlir::populateCIRPreLoweringPasses(pm); pm.addPass(mlir::omp::createMarkDeclareTargetPass()); pm.addPass(createConvertCIRToLLVMPass()); + pm.addPass(mlir::createReconcileUnrealizedCastsPass()); } std::unique_ptr<llvm::Module> 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
