[flang-commits] [flang] [flang] Expand SUM(DIM=CONSTANT) into an hlfir.elemental. (PR #118556)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Wed Dec 4 03:12:31 PST 2024


================
@@ -90,13 +91,198 @@ class TransposeAsElementalConversion
   }
 };
 
+// Expand the SUM(DIM=CONSTANT) operation into .
+class SumAsElementalConversion : public mlir::OpRewritePattern<hlfir::SumOp> {
+public:
+  using mlir::OpRewritePattern<hlfir::SumOp>::OpRewritePattern;
+
+  llvm::LogicalResult
+  matchAndRewrite(hlfir::SumOp sum,
+                  mlir::PatternRewriter &rewriter) const override {
+    mlir::Location loc = sum.getLoc();
+    fir::FirOpBuilder builder{rewriter, sum.getOperation()};
+    hlfir::ExprType expr = mlir::dyn_cast<hlfir::ExprType>(sum.getType());
+    assert(expr && "expected an expression type for the result of hlfir.sum");
----------------
tblah wrote:

```suggestion
    hlfir::ExprType expr = mlir::cast<hlfir::ExprType>(sum.getType());
```
nit: `cast<>()` already has the assertion built in https://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates

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


More information about the flang-commits mailing list