[flang-commits] [flang] [Flang][HLFIR] Lower PACK(array, .TRUE.) to hlfir.reshape (PR #220860)
via flang-commits
flang-commits at lists.llvm.org
Mon Sep 7 06:54:28 PDT 2026
================
@@ -1682,6 +1682,55 @@ void hlfir::EOShiftOp::getEffects(
getIntrinsicEffects(getOperation(), effects);
}
+//===----------------------------------------------------------------------===//
+// PackOp
+//===----------------------------------------------------------------------===//
+
+llvm::LogicalResult hlfir::PackOp::verify() {
+ hlfir::ExprType resultType = mlir::cast<hlfir::ExprType>(getType());
+ mlir::Value array = getArray();
+ auto arrayType = mlir::cast<fir::SequenceType>(
+ hlfir::getFortranElementOrSequenceType(array.getType()));
+ if (auto match = areMatchingTypes(
+ *this, hlfir::getFortranElementType(resultType),
+ arrayType.getElementType(),
+ /*allowCharacterLenMismatch=*/!useStrictIntrinsicVerifier);
+ match.failed())
+ return emitOpError("ARRAY and the result must have the same element type");
+ if (hlfir::isPolymorphicType(resultType) !=
+ hlfir::isPolymorphicType(array.getType()))
+ return emitOpError("ARRAY must be polymorphic iff result is polymorphic");
+ if (resultType.getRank() != 1)
+ return emitOpError("result must be of rank 1");
+ if (!hlfir::isMaskArgument(getMask().getType()))
+ return emitOpError("MASK must be of logical type");
+
+ mlir::Type maskSeqTy =
+ hlfir::getFortranElementOrSequenceType(getMask().getType());
+ if (auto maskArrayType = mlir::dyn_cast<fir::SequenceType>(maskSeqTy)) {
+ llvm::ArrayRef<int64_t> arrayShape = arrayType.getShape();
+ llvm::ArrayRef<int64_t> maskShape = maskArrayType.getShape();
+ if (maskShape.size() != arrayShape.size())
+ return emitOpError("MASK must be conformable to ARRAY");
+ if (useStrictIntrinsicVerifier) {
+ constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent();
+ for (std::size_t i = 0; i < arrayShape.size(); ++i) {
+ if (arrayShape[i] != maskShape[i] && arrayShape[i] != unknownExtent &&
+ maskShape[i] != unknownExtent)
+ return emitOpError("MASK must be conformable to ARRAY");
+ }
+ }
+ }
----------------
jeanPerier wrote:
Nit: could add a verifier for VECTOR when present to ensure it is rank one and same element type as ARRAY.
https://github.com/llvm/llvm-project/pull/220860
More information about the flang-commits
mailing list