@@ -380,11 +380,16 @@ llvm::LogicalResult fir::AllocMemOp::verify() {
380380
381381// CHARACTERs and derived types with LEN PARAMETERs are dependent types that
382382// require runtime values to fully define the type of an object.
383- static bool validTypeParams (mlir::Type dynTy, mlir::ValueRange typeParams) {
383+ static bool validTypeParams (mlir::Type dynTy, mlir::ValueRange typeParams,
384+ bool allowParamsForBox = false ) {
384385 dynTy = fir::unwrapAllRefAndSeqType (dynTy);
385- // A box value will contain type parameter values itself.
386- if (mlir::isa<fir::BoxType>(dynTy))
387- return typeParams.size () == 0 ;
386+ if (mlir::isa<fir::BaseBoxType>(dynTy)) {
387+ // A box value will contain type parameter values itself.
388+ if (!allowParamsForBox)
389+ return typeParams.size () == 0 ;
390+
391+ dynTy = fir::getFortranElementType (dynTy);
392+ }
388393 // Derived type must have all type parameters satisfied.
389394 if (auto recTy = mlir::dyn_cast<fir::RecordType>(dynTy))
390395 return typeParams.size () == recTy.getNumLenParams ();
@@ -4561,6 +4566,111 @@ llvm::LogicalResult fir::DeclareOp::verify() {
45614566 return fortranVar.verifyDeclareLikeOpImpl (getMemref ());
45624567}
45634568
4569+ // ===----------------------------------------------------------------------===//
4570+ // PackArrayOp
4571+ // ===----------------------------------------------------------------------===//
4572+
4573+ llvm::LogicalResult fir::PackArrayOp::verify () {
4574+ mlir::Type arrayType = getArray ().getType ();
4575+ if (!validTypeParams (arrayType, getTypeparams (), /* allowParamsForBox=*/ true ))
4576+ return emitOpError (" invalid type parameters" );
4577+
4578+ if (getInnermost () && fir::getBoxRank (arrayType) == 1 )
4579+ return emitOpError (
4580+ " 'innermost' is invalid for 1D arrays, use 'whole' instead" );
4581+ return mlir::success ();
4582+ }
4583+
4584+ void fir::PackArrayOp::getEffects (
4585+ llvm::SmallVectorImpl<
4586+ mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>
4587+ &effects) {
4588+ if (getStack ())
4589+ effects.emplace_back (
4590+ mlir::MemoryEffects::Allocate::get (),
4591+ mlir::SideEffects::AutomaticAllocationScopeResource::get ());
4592+ else
4593+ effects.emplace_back (mlir::MemoryEffects::Allocate::get (),
4594+ mlir::SideEffects::DefaultResource::get ());
4595+
4596+ if (!getNoCopy ())
4597+ effects.emplace_back (mlir::MemoryEffects::Read::get (),
4598+ mlir::SideEffects::DefaultResource::get ());
4599+ }
4600+
4601+ static mlir::ParseResult
4602+ parsePackArrayConstraints (mlir::OpAsmParser &parser, mlir::IntegerAttr &maxSize,
4603+ mlir::IntegerAttr &maxElementSize,
4604+ mlir::IntegerAttr &minStride) {
4605+ mlir::OperationName opName = mlir::OperationName (
4606+ fir::PackArrayOp::getOperationName (), parser.getContext ());
4607+ struct {
4608+ llvm::StringRef name;
4609+ mlir::IntegerAttr &ref;
4610+ } attributes[] = {
4611+ {fir::PackArrayOp::getMaxSizeAttrName (opName), maxSize},
4612+ {fir::PackArrayOp::getMaxElementSizeAttrName (opName), maxElementSize},
4613+ {fir::PackArrayOp::getMinStrideAttrName (opName), minStride}};
4614+
4615+ mlir::NamedAttrList parsedAttrs;
4616+ if (succeeded (parser.parseOptionalAttrDict (parsedAttrs))) {
4617+ for (auto parsedAttr : parsedAttrs) {
4618+ for (auto opAttr : attributes) {
4619+ if (parsedAttr.getName () == opAttr.name )
4620+ opAttr.ref = mlir::cast<mlir::IntegerAttr>(parsedAttr.getValue ());
4621+ }
4622+ }
4623+ return mlir::success ();
4624+ }
4625+ return mlir::failure ();
4626+ }
4627+
4628+ static void printPackArrayConstraints (mlir::OpAsmPrinter &p,
4629+ fir::PackArrayOp &op,
4630+ const mlir::IntegerAttr &maxSize,
4631+ const mlir::IntegerAttr &maxElementSize,
4632+ const mlir::IntegerAttr &minStride) {
4633+ llvm::SmallVector<mlir::NamedAttribute> attributes;
4634+ if (maxSize)
4635+ attributes.emplace_back (op.getMaxSizeAttrName (), maxSize);
4636+ if (maxElementSize)
4637+ attributes.emplace_back (op.getMaxElementSizeAttrName (), maxElementSize);
4638+ if (minStride)
4639+ attributes.emplace_back (op.getMinStrideAttrName (), minStride);
4640+
4641+ p.printOptionalAttrDict (attributes);
4642+ }
4643+
4644+ // ===----------------------------------------------------------------------===//
4645+ // UnpackArrayOp
4646+ // ===----------------------------------------------------------------------===//
4647+
4648+ llvm::LogicalResult fir::UnpackArrayOp::verify () {
4649+ if (auto packOp = getTemp ().getDefiningOp <fir::PackArrayOp>())
4650+ if (getStack () != packOp.getStack ())
4651+ return emitOpError () << " the pack operation uses different memory for "
4652+ " the temporary (stack vs heap): "
4653+ << *packOp.getOperation () << " \n " ;
4654+ return mlir::success ();
4655+ }
4656+
4657+ void fir::UnpackArrayOp::getEffects (
4658+ llvm::SmallVectorImpl<
4659+ mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>
4660+ &effects) {
4661+ if (getStack ())
4662+ effects.emplace_back (
4663+ mlir::MemoryEffects::Free::get (),
4664+ mlir::SideEffects::AutomaticAllocationScopeResource::get ());
4665+ else
4666+ effects.emplace_back (mlir::MemoryEffects::Free::get (),
4667+ mlir::SideEffects::DefaultResource::get ());
4668+
4669+ if (!getNoCopy ())
4670+ effects.emplace_back (mlir::MemoryEffects::Write::get (),
4671+ mlir::SideEffects::DefaultResource::get ());
4672+ }
4673+
45644674// ===----------------------------------------------------------------------===//
45654675// FIROpsDialect
45664676// ===----------------------------------------------------------------------===//
0 commit comments