[Mlir-commits] [mlir] 874b880 - [MLIR][OpenMP] Lowering support for Order clause in SIMD directive (#96866)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jun 27 19:34:00 PDT 2024
Author: harishch4
Date: 2024-06-28T08:03:57+05:30
New Revision: 874b880fce8522b06c6cf73a76612a844e2eaf1b
URL: https://github.com/llvm/llvm-project/commit/874b880fce8522b06c6cf73a76612a844e2eaf1b
DIFF: https://github.com/llvm/llvm-project/commit/874b880fce8522b06c6cf73a76612a844e2eaf1b.diff
LOG: [MLIR][OpenMP] Lowering support for Order clause in SIMD directive (#96866)
Added:
Modified:
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
mlir/test/Target/LLVMIR/openmp-llvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index eabc4b30f57a9..6754a5c002efc 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1460,6 +1460,18 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
return bodyGenStatus;
}
+/// Convert Order attribute to llvm::omp::OrderKind.
+static llvm::omp::OrderKind
+convertOrderKind(std::optional<omp::ClauseOrderKind> o) {
+ if (!o)
+ return llvm::omp::OrderKind::OMP_ORDER_unknown;
+ switch (*o) {
+ case omp::ClauseOrderKind::Concurrent:
+ return llvm::omp::OrderKind::OMP_ORDER_concurrent;
+ }
+ llvm_unreachable("Unknown ClauseOrderKind kind");
+}
+
/// Converts an OpenMP simd loop into LLVM IR using OpenMPIRBuilder.
static LogicalResult
convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
@@ -1539,11 +1551,12 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
safelen = builder.getInt64(safelenVar.value());
llvm::MapVector<llvm::Value *, llvm::Value *> alignedVars;
- ompBuilder->applySimd(
- loopInfo, alignedVars,
- simdOp.getIfExpr() ? moduleTranslation.lookupValue(simdOp.getIfExpr())
- : nullptr,
- llvm::omp::OrderKind::OMP_ORDER_unknown, simdlen, safelen);
+ llvm::omp::OrderKind order = convertOrderKind(simdOp.getOrderVal());
+ ompBuilder->applySimd(loopInfo, alignedVars,
+ simdOp.getIfExpr()
+ ? moduleTranslation.lookupValue(simdOp.getIfExpr())
+ : nullptr,
+ order, simdlen, safelen);
builder.restoreIP(afterIP);
return success();
diff --git a/mlir/test/Target/LLVMIR/openmp-llvm.mlir b/mlir/test/Target/LLVMIR/openmp-llvm.mlir
index a1cc76f9ab770..7c6ab21e21c60 100644
--- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -826,6 +826,26 @@ llvm.func @simd_if(%arg0: !llvm.ptr {fir.bindc_name = "n"}, %arg1: !llvm.ptr {fi
// -----
+// CHECK-LABEL: @simd_order
+llvm.func @simd_order() {
+ %0 = llvm.mlir.constant(10 : i64) : i64
+ %1 = llvm.mlir.constant(1 : i64) : i64
+ %2 = llvm.alloca %1 x i64 : (i64) -> !llvm.ptr
+ omp.simd order(concurrent) safelen(2) {
+ omp.loop_nest (%arg0) : i64 = (%1) to (%0) inclusive step (%1) {
+ llvm.store %arg0, %2 : i64, !llvm.ptr
+ omp.yield
+ }
+ }
+ llvm.return
+}
+// If clause order(concurrent) is specified then the memory instructions
+// are marked parallel even if 'safelen' is finite.
+// CHECK: llvm.loop.parallel_accesses
+// CHECK-NEXT: llvm.loop.vectorize.enable
+// CHECK-NEXT: llvm.loop.vectorize.width{{.*}}i64 2
+// -----
+
llvm.func @body(i64)
llvm.func @test_omp_wsloop_ordered(%lb : i64, %ub : i64, %step : i64) -> () {
More information about the Mlir-commits
mailing list