[Mlir-commits] [mlir] 4ee9f3d - [MLIR, OpenMP] : Add Conversion pattern for Critical Op
Kiran Chandramohan
llvmlistbot at llvm.org
Fri Jul 22 06:02:57 PDT 2022
Author: Kiran Chandramohan
Date: 2022-07-22T12:57:48Z
New Revision: 4ee9f3d59e62b4152fb50cad90d4c3bd9b5f63bc
URL: https://github.com/llvm/llvm-project/commit/4ee9f3d59e62b4152fb50cad90d4c3bd9b5f63bc
DIFF: https://github.com/llvm/llvm-project/commit/4ee9f3d59e62b4152fb50cad90d4c3bd9b5f63bc.diff
LOG: [MLIR,OpenMP] : Add Conversion pattern for Critical Op
The Conversion pattern enables conversion of Critical Op with block
arguments.
Fixes https://github.com/llvm/llvm-project/issues/56629
Reviewed By: shraiysh
Differential Revision: https://reviews.llvm.org/D130343
Added:
Modified:
mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
index bb8f523a1374f..f4887d25f2177 100644
--- a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
+++ b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
@@ -81,13 +81,14 @@ struct RegionLessOpWithVarOperandsConversion
void mlir::configureOpenMPToLLVMConversionLegality(
ConversionTarget &target, LLVMTypeConverter &typeConverter) {
- target.addDynamicallyLegalOp<mlir::omp::ParallelOp, mlir::omp::WsLoopOp,
- mlir::omp::MasterOp, mlir::omp::SectionsOp,
- mlir::omp::SingleOp>([&](Operation *op) {
- return typeConverter.isLegal(&op->getRegion(0)) &&
- typeConverter.isLegal(op->getOperandTypes()) &&
- typeConverter.isLegal(op->getResultTypes());
- });
+ target.addDynamicallyLegalOp<mlir::omp::CriticalOp, mlir::omp::ParallelOp,
+ mlir::omp::WsLoopOp, mlir::omp::MasterOp,
+ mlir::omp::SectionsOp, mlir::omp::SingleOp>(
+ [&](Operation *op) {
+ return typeConverter.isLegal(&op->getRegion(0)) &&
+ typeConverter.isLegal(op->getOperandTypes()) &&
+ typeConverter.isLegal(op->getResultTypes());
+ });
target
.addDynamicallyLegalOp<mlir::omp::AtomicReadOp, mlir::omp::AtomicWriteOp,
mlir::omp::FlushOp, mlir::omp::ThreadprivateOp>(
@@ -100,9 +101,9 @@ void mlir::configureOpenMPToLLVMConversionLegality(
void mlir::populateOpenMPToLLVMConversionPatterns(LLVMTypeConverter &converter,
RewritePatternSet &patterns) {
patterns.add<
- RegionOpConversion<omp::MasterOp>, RegionOpConversion<omp::ParallelOp>,
- RegionOpConversion<omp::WsLoopOp>, RegionOpConversion<omp::SectionsOp>,
- RegionOpConversion<omp::SingleOp>,
+ RegionOpConversion<omp::CriticalOp>, RegionOpConversion<omp::MasterOp>,
+ RegionOpConversion<omp::ParallelOp>, RegionOpConversion<omp::WsLoopOp>,
+ RegionOpConversion<omp::SectionsOp>, RegionOpConversion<omp::SingleOp>,
RegionLessOpWithVarOperandsConversion<omp::AtomicReadOp>,
RegionLessOpWithVarOperandsConversion<omp::AtomicWriteOp>,
RegionLessOpWithVarOperandsConversion<omp::FlushOp>,
diff --git a/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir b/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
index 341e283ffd333..b9dcbb4fb7c53 100644
--- a/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
+++ b/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
@@ -1,5 +1,23 @@
// RUN: mlir-opt -convert-openmp-to-llvm -split-input-file %s | FileCheck %s
+// CHECK-LABEL: llvm.func @foo(i64, i64)
+func.func private @foo(index, index)
+
+// CHECK-LABEL: llvm.func @critical_block_arg
+func.func @critical_block_arg() {
+ // CHECK: omp.critical
+ omp.critical {
+ // CHECK-NEXT: ^[[BB0:.*]](%[[ARG1:.*]]: i64, %[[ARG2:.*]]: i64):
+ ^bb0(%arg1: index, %arg2: index):
+ // CHECK-NEXT: llvm.call @foo(%[[ARG1]], %[[ARG2]]) : (i64, i64) -> ()
+ func.call @foo(%arg1, %arg2) : (index, index) -> ()
+ omp.terminator
+ }
+ return
+}
+
+// -----
+
// CHECK-LABEL: llvm.func @master_block_arg
func.func @master_block_arg() {
// CHECK: omp.master
More information about the Mlir-commits
mailing list