[flang-commits] [flang] [flang] Inline hlfir.reshape as hlfir.elemental. (PR #124683)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Tue Jan 28 04:16:59 PST 2025
================
@@ -951,6 +951,213 @@ class DotProductConversion
}
};
+class ReshapeAsElementalConversion
+ : public mlir::OpRewritePattern<hlfir::ReshapeOp> {
+public:
+ using mlir::OpRewritePattern<hlfir::ReshapeOp>::OpRewritePattern;
+
+ llvm::LogicalResult
+ matchAndRewrite(hlfir::ReshapeOp reshape,
+ mlir::PatternRewriter &rewriter) const override {
+ // Do not inline RESHAPE with ORDER yet. The runtime implementation
+ // may be good enough, unless the temporary creation overhead
+ // is high.
+ // TODO: If ORDER is constant, then we can still easily inline.
+ // TODO: If the result's rank is 1, then we can assume ORDER == (/1/).
+ if (reshape.getOrder())
+ return rewriter.notifyMatchFailure(reshape,
+ "RESHAPE with ORDER argument");
+
+ // Verify that the element types of ARRAY, PAD and the result
+ // match before doing any transformations.
+ hlfir::Entity result = hlfir::Entity{reshape};
+ hlfir::Entity array = hlfir::Entity{reshape.getArray()};
+ mlir::Type elementType = array.getFortranElementType();
+ if (result.getFortranElementType() != elementType)
+ return rewriter.notifyMatchFailure(
+ reshape, "ARRAY and result have different types");
----------------
tblah wrote:
Isn't this enforced by the operation verifier?
https://github.com/llvm/llvm-project/pull/124683
More information about the flang-commits
mailing list