Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h =================================================================== --- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h +++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h @@ -89,6 +89,8 @@ #define OMP_IDENT_FLAG(Enum, ...) constexpr auto Enum = omp::IdentFlag::Enum; #include "llvm/Frontend/OpenMP/OMPKinds.def" +ProcBindKind getProcBindKind(llvm::StringRef Str); + } // end namespace omp } // end namespace llvm Index: llvm/lib/Frontend/OpenMP/CMakeLists.txt =================================================================== --- llvm/lib/Frontend/OpenMP/CMakeLists.txt +++ llvm/lib/Frontend/OpenMP/CMakeLists.txt @@ -4,6 +4,7 @@ add_llvm_component_library(LLVMFrontendOpenMP OMP.cpp # Generated by tablegen above + OMPConstants.cpp OMPContext.cpp OMPIRBuilder.cpp Index: llvm/lib/Frontend/OpenMP/OMPConstants.cpp =================================================================== --- /dev/null +++ llvm/lib/Frontend/OpenMP/OMPConstants.cpp @@ -0,0 +1,29 @@ +//===- OMPConstants.h - OpenMP related constants and helpers ------ C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// \file +/// This file defines constants and helpers used when dealing with OpenMP. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/Frontend/OpenMP/OMPConstants.h" +#include "llvm/ADT/StringSwitch.h" + +namespace llvm { + +namespace omp { + +ProcBindKind getProcBindKind(StringRef Str) { + return llvm::StringSwitch(Str) +#define OMP_PROC_BIND_KIND(Enum, Name, Value) .Case(Name, Enum) +#include "llvm/Frontend/OpenMP/OMPKinds.def" + .Default(llvm::omp::OMP_PROC_BIND_unknown); +} + +} // end namespace omp + +} // end namespace llvm Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp =================================================================== --- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -454,10 +454,13 @@ // Parallel operation is created with some default options for now. llvm::Value *ifCond = nullptr; llvm::Value *numThreads = nullptr; + llvm::omp::ProcBindKind pbKind = llvm::omp::OMP_PROC_BIND_default; + if (auto bind = cast(opInst).proc_bind_val()) + pbKind = llvm::omp::getProcBindKind(bind.getValue()); bool isCancellable = false; - builder.restoreIP(ompBuilder->CreateParallel( - builder, bodyGenCB, privCB, finiCB, ifCond, numThreads, - llvm::omp::OMP_PROC_BIND_default, isCancellable)); + builder.restoreIP(ompBuilder->CreateParallel(builder, bodyGenCB, privCB, + finiCB, ifCond, numThreads, + pbKind, isCancellable)); return success(); } Index: mlir/test/Target/openmp-llvm.mlir =================================================================== --- mlir/test/Target/openmp-llvm.mlir +++ mlir/test/Target/openmp-llvm.mlir @@ -78,3 +78,34 @@ // CHECK-LABEL: omp.par.region2: // CHECK: call void @body(i64 43) // CHECK: br label %omp.par.pre_finalize + +// CHECK-LABEL: define void @test_omp_parallel_3() +llvm.func @test_omp_parallel_3() -> () { + // CHECK: [[OMP_THREAD_3_1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @{{[0-9]+}}) + // CHECK: call void @__kmpc_push_proc_bind(%struct.ident_t* @{{[0-9]+}}, i32 [[OMP_THREAD_3_1]], i32 2) + // CHECK: call void{{.*}}@__kmpc_fork_call{{.*}}@[[OMP_OUTLINED_FN_3_1:.*]] to {{.*}} + omp.parallel proc_bind(master) { + omp.barrier + omp.terminator + } + // CHECK: [[OMP_THREAD_3_2:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @{{[0-9]+}}) + // CHECK: call void @__kmpc_push_proc_bind(%struct.ident_t* @{{[0-9]+}}, i32 [[OMP_THREAD_3_2]], i32 3) + // CHECK: call void{{.*}}@__kmpc_fork_call{{.*}}@[[OMP_OUTLINED_FN_3_2:.*]] to {{.*}} + omp.parallel proc_bind(close) { + omp.barrier + omp.terminator + } + // CHECK: [[OMP_THREAD_3_3:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @{{[0-9]+}}) + // CHECK: call void @__kmpc_push_proc_bind(%struct.ident_t* @{{[0-9]+}}, i32 [[OMP_THREAD_3_3]], i32 4) + // CHECK: call void{{.*}}@__kmpc_fork_call{{.*}}@[[OMP_OUTLINED_FN_3_3:.*]] to {{.*}} + omp.parallel proc_bind(spread) { + omp.barrier + omp.terminator + } + + llvm.return +} + +// CHECK: define internal void @[[OMP_OUTLINED_FN_3_3]] +// CHECK: define internal void @[[OMP_OUTLINED_FN_3_2]] +// CHECK: define internal void @[[OMP_OUTLINED_FN_3_1]]