diff --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir --- 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 @@ } return } + +// ----- + +// CHECK: llvm.func @_QPs +// CHECK: omp.atomic.read %{{.*}} = %{{.*}} : !llvm.ptr>, !llvm.struct<(f32, f32)> + +func.func @_QPs(%arg0: !fir.ref> {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> + return +} diff --git a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp --- a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp +++ b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp @@ -77,6 +77,7 @@ } convertedOperands.emplace_back(adaptor.getOperands()[idx]); } + rewriter.replaceOpWithNewOp(curOp, resTypes, convertedOperands, curOp->getAttrs()); return success(); @@ -138,6 +139,23 @@ } }; +struct AtomicReadOpConversion + : public ConvertOpToLLVMPattern { + using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern; + LogicalResult + matchAndRewrite(omp::AtomicReadOp curOp, OpAdaptor adaptor, + ConversionPatternRewriter &rewriter) const override { + TypeConverter *converter = ConvertToLLVMPattern::getTypeConverter(); + Type curElementType = curOp.getElementType(); + auto newOp = rewriter.create( + 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 { using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern; LogicalResult @@ -213,15 +231,14 @@ void mlir::populateOpenMPToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns) { patterns.add< - ReductionOpConversion, ReductionDeclareOpConversion, - RegionOpConversion, RegionOpConversion, - ReductionOpConversion, RegionOpConversion, - RegionOpConversion, RegionOpConversion, - RegionOpConversion, RegionOpConversion, - RegionOpConversion, RegionOpConversion, - RegionOpConversion, RegionOpConversion, - RegionOpConversion, - RegionLessOpWithVarOperandsConversion, + AtomicReadOpConversion, ReductionOpConversion, + ReductionDeclareOpConversion, RegionOpConversion, + RegionOpConversion, ReductionOpConversion, + RegionOpConversion, RegionOpConversion, + RegionOpConversion, RegionOpConversion, + RegionOpConversion, RegionOpConversion, + RegionOpConversion, RegionOpConversion, + RegionOpConversion, RegionOpConversion, RegionLessOpWithVarOperandsConversion, RegionOpWithVarOperandsConversion, RegionLessOpWithVarOperandsConversion,