[flang-commits] [flang] [flang] Added hlfir.reshape definition/lowering/codegen. (PR #124226)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Fri Jan 24 08:30:39 PST 2025
================
@@ -1444,6 +1444,63 @@ void hlfir::CShiftOp::getEffects(
getIntrinsicEffects(getOperation(), effects);
}
+//===----------------------------------------------------------------------===//
+// ReshapeOp
+//===----------------------------------------------------------------------===//
+
+llvm::LogicalResult hlfir::ReshapeOp::verify() {
+ auto results = this->getOperation()->getResultTypes();
+ assert(results.size() == 1);
+ hlfir::ExprType resultType = mlir::cast<hlfir::ExprType>(results[0]);
+ mlir::Value array = this->getArray();
+ auto arrayType = mlir::cast<fir::SequenceType>(
+ hlfir::getFortranElementOrSequenceType(array.getType()));
+ if (hlfir::getFortranElementType(resultType) != arrayType.getElementType())
+ return this->emitOpError(
+ "ARRAY and the result must have the same element type");
+ if (hlfir::isPolymorphicType(resultType) !=
+ hlfir::isPolymorphicType(array.getType()))
+ return this->emitOpError(
+ "ARRAY must be polymorphic iff result is polymorphic");
+
+ mlir::Value shape = this->getShape();
+ auto shapeArrayType = mlir::cast<fir::SequenceType>(
+ hlfir::getFortranElementOrSequenceType(shape.getType()));
+ if (shapeArrayType.getDimension() != 1)
+ return this->emitOpError("SHAPE must be an array of rank 1");
+ if (!mlir::isa<mlir::IntegerType>(shapeArrayType.getElementType()))
+ return this->emitOpError("SHAPE must be an integer array");
+ if (shapeArrayType.hasDynamicExtents())
+ return this->emitOpError("SHAPE must have known size");
+ if (shapeArrayType.getConstantArraySize() != resultType.getRank())
+ return this->emitOpError("SHAPE's extent must match the result rank");
+
+ if (mlir::Value pad = this->getPad()) {
+ auto padArrayType = mlir::cast<fir::SequenceType>(
+ hlfir::getFortranElementOrSequenceType(pad.getType()));
+ if (arrayType.getElementType() != padArrayType.getElementType())
----------------
vzakhari wrote:
Yes, I forgot about about typeparams :) Thanks!
https://github.com/llvm/llvm-project/pull/124226
More information about the flang-commits
mailing list