[Mlir-commits] [mlir] [MLIR][OpenMP] Support `llvm` conversion for `omp.private` regions (PR #81414)

Sergio Afonso llvmlistbot at llvm.org
Thu Feb 15 05:55:09 PST 2024


================
@@ -200,16 +200,20 @@ struct ReductionOpConversion : public ConvertOpToLLVMPattern<omp::ReductionOp> {
   }
 };
 
-struct ReductionDeclareOpConversion
-    : public ConvertOpToLLVMPattern<omp::ReductionDeclareOp> {
-  using ConvertOpToLLVMPattern<omp::ReductionDeclareOp>::ConvertOpToLLVMPattern;
+template <typename OpType>
+struct MultiRegionOpConversion : public ConvertOpToLLVMPattern<OpType> {
+  using ConvertOpToLLVMPattern<OpType>::ConvertOpToLLVMPattern;
   LogicalResult
-  matchAndRewrite(omp::ReductionDeclareOp curOp, OpAdaptor adaptor,
+  matchAndRewrite(OpType curOp, typename OpType::Adaptor adaptor,
                   ConversionPatternRewriter &rewriter) const override {
-    auto newOp = rewriter.create<omp::ReductionDeclareOp>(
+    auto newOp = rewriter.create<OpType>(
         curOp.getLoc(), TypeRange(), curOp.getSymNameAttr(),
         TypeAttr::get(this->getTypeConverter()->convertType(
             curOp.getTypeAttr().getValue())));
+
+    if constexpr (std::is_same_v<OpType, mlir::omp::PrivateClauseOp>)
----------------
skatrak wrote:

Nit: Feel free to ignore this comment if you don't agree, but could this be refactored into a separate function? Something like this, to be more easily extensible to other operations:
```c++
template <typename OpType>
struct MultiRegionOpConversion ... {
  ...
  void forwardOpAttrs(OpType curOp, OpType newOp) const {}

  LogicalResult matchAndRewrite(...) {
    auto newOp = ...
    forwardOpAttrs(curOp, newOp);
  }
};

template<>
void MultiRegionOpConversion<omp::PrivateClauseOp>::forwardOpAttrs(omp::PrivateClauseOp curOp, omp::PrivateClauseOp newOp) {
  newOp.setDataSharingType(curOp.getDataSharingType());
}
```

https://github.com/llvm/llvm-project/pull/81414


More information about the Mlir-commits mailing list