[Mlir-commits] [mlir] 067ecad - [Flang][OpenMP] Convert elementTypeAttr for AtomicRead Op

Kiran Chandramohan llvmlistbot at llvm.org
Thu Aug 3 04:51:03 PDT 2023


Author: Kiran Chandramohan
Date: 2023-08-03T11:49:26Z
New Revision: 067ecad620b682ebd1003621edd354f31f31ea2c

URL: https://github.com/llvm/llvm-project/commit/067ecad620b682ebd1003621edd354f31f31ea2c
DIFF: https://github.com/llvm/llvm-project/commit/067ecad620b682ebd1003621edd354f31f31ea2c.diff

LOG: [Flang][OpenMP] Convert elementTypeAttr for AtomicRead Op

Convert the elementTypeAttr of AtomicRead Op for LLVMConversion.
This is required when the elementType is non-integer, non-real.

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D155817

Added: 
    

Modified: 
    flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
    mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp

Removed: 
    


################################################################################
diff  --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
index 61df6d8e16c349..b9b46c24098c8e 100644
--- a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
+++ b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
@@ -644,3 +644,14 @@ func.func @_QPsimple_reduction(%arg0: !fir.ref<!fir.array<100x!fir.logical<4>>>
   }
   return
 }
+
+// -----
+
+// CHECK: llvm.func @_QPs
+// CHECK: omp.atomic.read %{{.*}} = %{{.*}}   : !llvm.ptr<struct<(f32, f32)>>, !llvm.struct<(f32, f32)>
+
+func.func @_QPs(%arg0: !fir.ref<!fir.complex<4>> {fir.bindc_name = "x"}) {
+  %0 = fir.alloca !fir.complex<4> {bindc_name = "v", uniq_name = "_QFsEv"}
+  omp.atomic.read %0 = %arg0   : !fir.ref<!fir.complex<4>>, !fir.complex<4>
+  return
+} 

diff  --git a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
index a5fdc4e7fd9c07..fb8ad5a4c31f54 100644
--- a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
+++ b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
@@ -77,6 +77,7 @@ struct RegionLessOpWithVarOperandsConversion
       }
       convertedOperands.emplace_back(adaptor.getOperands()[idx]);
     }
+
     rewriter.replaceOpWithNewOp<T>(curOp, resTypes, convertedOperands,
                                    curOp->getAttrs());
     return success();
@@ -138,6 +139,23 @@ struct RegionLessOpConversion : public ConvertOpToLLVMPattern<T> {
   }
 };
 
+struct AtomicReadOpConversion
+    : public ConvertOpToLLVMPattern<omp::AtomicReadOp> {
+  using ConvertOpToLLVMPattern<omp::AtomicReadOp>::ConvertOpToLLVMPattern;
+  LogicalResult
+  matchAndRewrite(omp::AtomicReadOp curOp, OpAdaptor adaptor,
+                  ConversionPatternRewriter &rewriter) const override {
+    TypeConverter *converter = ConvertToLLVMPattern::getTypeConverter();
+    Type curElementType = curOp.getElementType();
+    auto newOp = rewriter.create<omp::AtomicReadOp>(
+        curOp.getLoc(), TypeRange(), adaptor.getOperands(), curOp->getAttrs());
+    TypeAttr typeAttr = TypeAttr::get(converter->convertType(curElementType));
+    newOp.setElementTypeAttr(typeAttr);
+    rewriter.eraseOp(curOp);
+    return success();
+  }
+};
+
 struct ReductionOpConversion : public ConvertOpToLLVMPattern<omp::ReductionOp> {
   using ConvertOpToLLVMPattern<omp::ReductionOp>::ConvertOpToLLVMPattern;
   LogicalResult
@@ -213,15 +231,14 @@ void mlir::configureOpenMPToLLVMConversionLegality(
 void mlir::populateOpenMPToLLVMConversionPatterns(LLVMTypeConverter &converter,
                                                   RewritePatternSet &patterns) {
   patterns.add<
-      ReductionOpConversion, ReductionDeclareOpConversion,
-      RegionOpConversion<omp::CriticalOp>, RegionOpConversion<omp::MasterOp>,
-      ReductionOpConversion, RegionOpConversion<omp::ParallelOp>,
-      RegionOpConversion<omp::WsLoopOp>, RegionOpConversion<omp::SectionsOp>,
-      RegionOpConversion<omp::SectionOp>, RegionOpConversion<omp::SimdLoopOp>,
-      RegionOpConversion<omp::SingleOp>, RegionOpConversion<omp::TaskGroupOp>,
-      RegionOpConversion<omp::TaskOp>, RegionOpConversion<omp::DataOp>,
-      RegionOpConversion<omp::TargetOp>,
-      RegionLessOpWithVarOperandsConversion<omp::AtomicReadOp>,
+      AtomicReadOpConversion, ReductionOpConversion,
+      ReductionDeclareOpConversion, RegionOpConversion<omp::CriticalOp>,
+      RegionOpConversion<omp::MasterOp>, ReductionOpConversion,
+      RegionOpConversion<omp::ParallelOp>, RegionOpConversion<omp::WsLoopOp>,
+      RegionOpConversion<omp::SectionsOp>, RegionOpConversion<omp::SectionOp>,
+      RegionOpConversion<omp::SimdLoopOp>, RegionOpConversion<omp::SingleOp>,
+      RegionOpConversion<omp::TaskGroupOp>, RegionOpConversion<omp::TaskOp>,
+      RegionOpConversion<omp::DataOp>, RegionOpConversion<omp::TargetOp>,
       RegionLessOpWithVarOperandsConversion<omp::AtomicWriteOp>,
       RegionOpWithVarOperandsConversion<omp::AtomicUpdateOp>,
       RegionLessOpWithVarOperandsConversion<omp::FlushOp>,


        


More information about the Mlir-commits mailing list