https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/172501
This patch implements the 'first' clause for OMP, which is the 'proc_bind' clause. This clause takes one of a handful of values and just passes it onto the OMP dialect. The 'default' value for this isn't present in the OMP dialect, however the classic-codegen doesn't generate the library call when this value is passed, so this is effectively a 'no-op'. >From fe6afb5e9ba004f6e7010fd292ad3c22365b3cc3 Mon Sep 17 00:00:00 2001 From: erichkeane <[email protected]> Date: Fri, 12 Dec 2025 10:42:27 -0800 Subject: [PATCH] [OpenMP][CIR] Implement 'parallel's 'proc_bind' clause lowering This patch implements the 'first' clause for OMP, which is the 'proc_bind' clause. This clause takes one of a handful of values and just passes it onto the OMP dialect. The 'default' value for this isn't present in the OMP dialect, however the classic-codegen doesn't generate the library call when this value is passed, so this is effectively a 'no-op'. --- clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp | 32 ++++++++++++++++++++ clang/test/CIR/CodeGenOpenMP/parallel.c | 28 +++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp index f73c0c4000d7e..8c1c3323b37f1 100644 --- a/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenOpenMPClause.cpp @@ -34,6 +34,38 @@ class OpenMPClauseCIREmitter final clause->getClauseKind()); } + void VisitOMPProcBindClause(const OMPProcBindClause *clause) { + if constexpr (std::is_same_v<OpTy, mlir::omp::ParallelOp>) { + mlir::omp::ClauseProcBindKind kind; + switch (clause->getProcBindKind()) { + case llvm::omp::ProcBindKind::OMP_PROC_BIND_master: + kind = mlir::omp::ClauseProcBindKind::Master; + break; + case llvm::omp::ProcBindKind::OMP_PROC_BIND_close: + kind = mlir::omp::ClauseProcBindKind::Close; + break; + case llvm::omp::ProcBindKind::OMP_PROC_BIND_spread: + kind = mlir::omp::ClauseProcBindKind::Spread; + break; + case llvm::omp::ProcBindKind::OMP_PROC_BIND_primary: + kind = mlir::omp::ClauseProcBindKind::Primary; + break; + case llvm::omp::ProcBindKind::OMP_PROC_BIND_default: + // 'default' in the classic-codegen does no runtime call/doesn't + // really do anything. So this is a no-op, and thus shouldn't change + // the IR. + return; + case llvm::omp::ProcBindKind::OMP_PROC_BIND_unknown: + llvm_unreachable("unknown proc-bind kind"); + } + operation.setProcBindKind(kind); + } 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/test/CIR/CodeGenOpenMP/parallel.c b/clang/test/CIR/CodeGenOpenMP/parallel.c index 84095bd994fac..a2bfc8f4ce82e 100644 --- a/clang/test/CIR/CodeGenOpenMP/parallel.c +++ b/clang/test/CIR/CodeGenOpenMP/parallel.c @@ -48,3 +48,31 @@ void parallel_with_operations() { // CHECK-NEXT: omp.terminator // CHECK-NEXT: } } +void proc_bind_parallel() { + // CHECK: cir.func{{.*}}@proc_bind_parallel +#pragma omp parallel proc_bind(master) + {} + // CHECK-NEXT: omp.parallel proc_bind(master) { + // CHECK-NEXT: omp.terminator + // CHECK-NEXT: } +#pragma omp parallel proc_bind(close) + {} + // CHECK-NEXT: omp.parallel proc_bind(close) { + // CHECK-NEXT: omp.terminator + // CHECK-NEXT: } +#pragma omp parallel proc_bind(spread) + {} + // CHECK-NEXT: omp.parallel proc_bind(spread) { + // CHECK-NEXT: omp.terminator + // CHECK-NEXT: } +#pragma omp parallel proc_bind(primary) + {} + // CHECK-NEXT: omp.parallel proc_bind(primary) { + // CHECK-NEXT: omp.terminator + // CHECK-NEXT: } +#pragma omp parallel proc_bind(default) + {} + // CHECK-NEXT: omp.parallel { + // CHECK-NEXT: omp.terminator + // CHECK-NEXT: } +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
