@@ -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 ();
@@ -4541,6 +4546,111 @@ llvm::LogicalResult fir::DeclareOp::verify() {
45414546 return fortranVar.verifyDeclareLikeOpImpl (getMemref ());
45424547}
45434548
4549+ // ===----------------------------------------------------------------------===//
4550+ // PackArrayOp
4551+ // ===----------------------------------------------------------------------===//
4552+
4553+ llvm::LogicalResult fir::PackArrayOp::verify () {
4554+ mlir::Type arrayType = getArray ().getType ();
4555+ if (!validTypeParams (arrayType, getTypeparams (), /* allowParamsForBox=*/ true ))
4556+ return emitOpError (" invalid type parameters" );
4557+
4558+ if (getInnermost () && fir::getBoxRank (arrayType) == 1 )
4559+ return emitOpError (
4560+ " 'innermost' is invalid for 1D arrays, use 'whole' instead" );
4561+ return mlir::success ();
4562+ }
4563+
4564+ void fir::PackArrayOp::getEffects (
4565+ llvm::SmallVectorImpl<
4566+ mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>
4567+ &effects) {
4568+ if (getStack ())
4569+ effects.emplace_back (
4570+ mlir::MemoryEffects::Allocate::get (),
4571+ mlir::SideEffects::AutomaticAllocationScopeResource::get ());
4572+ else
4573+ effects.emplace_back (mlir::MemoryEffects::Allocate::get (),
4574+ mlir::SideEffects::DefaultResource::get ());
4575+
4576+ if (!getNoCopy ())
4577+ effects.emplace_back (mlir::MemoryEffects::Read::get (),
4578+ mlir::SideEffects::DefaultResource::get ());
4579+ }
4580+
4581+ static mlir::ParseResult
4582+ parsePackArrayConstraints (mlir::OpAsmParser &parser, mlir::IntegerAttr &maxSize,
4583+ mlir::IntegerAttr &maxElementSize,
4584+ mlir::IntegerAttr &minStride) {
4585+ mlir::OperationName opName = mlir::OperationName (
4586+ fir::PackArrayOp::getOperationName (), parser.getContext ());
4587+ struct {
4588+ llvm::StringRef name;
4589+ mlir::IntegerAttr &ref;
4590+ } attributes[] = {
4591+ {fir::PackArrayOp::getMaxSizeAttrName (opName), maxSize},
4592+ {fir::PackArrayOp::getMaxElementSizeAttrName (opName), maxElementSize},
4593+ {fir::PackArrayOp::getMinStrideAttrName (opName), minStride}};
4594+
4595+ mlir::NamedAttrList parsedAttrs;
4596+ if (succeeded (parser.parseOptionalAttrDict (parsedAttrs))) {
4597+ for (auto parsedAttr : parsedAttrs) {
4598+ for (auto opAttr : attributes) {
4599+ if (parsedAttr.getName () == opAttr.name )
4600+ opAttr.ref = mlir::cast<mlir::IntegerAttr>(parsedAttr.getValue ());
4601+ }
4602+ }
4603+ return mlir::success ();
4604+ }
4605+ return mlir::failure ();
4606+ }
4607+
4608+ static void printPackArrayConstraints (mlir::OpAsmPrinter &p,
4609+ fir::PackArrayOp &op,
4610+ const mlir::IntegerAttr &maxSize,
4611+ const mlir::IntegerAttr &maxElementSize,
4612+ const mlir::IntegerAttr &minStride) {
4613+ llvm::SmallVector<mlir::NamedAttribute> attributes;
4614+ if (maxSize)
4615+ attributes.emplace_back (op.getMaxSizeAttrName (), maxSize);
4616+ if (maxElementSize)
4617+ attributes.emplace_back (op.getMaxElementSizeAttrName (), maxElementSize);
4618+ if (minStride)
4619+ attributes.emplace_back (op.getMinStrideAttrName (), minStride);
4620+
4621+ p.printOptionalAttrDict (attributes);
4622+ }
4623+
4624+ // ===----------------------------------------------------------------------===//
4625+ // UnpackArrayOp
4626+ // ===----------------------------------------------------------------------===//
4627+
4628+ llvm::LogicalResult fir::UnpackArrayOp::verify () {
4629+ if (auto packOp = getTemp ().getDefiningOp <fir::PackArrayOp>())
4630+ if (getStack () != packOp.getStack ())
4631+ return emitOpError () << " the pack operation uses different memory for "
4632+ " the temporary (stack vs heap): "
4633+ << *packOp.getOperation () << " \n " ;
4634+ return mlir::success ();
4635+ }
4636+
4637+ void fir::UnpackArrayOp::getEffects (
4638+ llvm::SmallVectorImpl<
4639+ mlir::SideEffects::EffectInstance<mlir::MemoryEffects::Effect>>
4640+ &effects) {
4641+ if (getStack ())
4642+ effects.emplace_back (
4643+ mlir::MemoryEffects::Free::get (),
4644+ mlir::SideEffects::AutomaticAllocationScopeResource::get ());
4645+ else
4646+ effects.emplace_back (mlir::MemoryEffects::Free::get (),
4647+ mlir::SideEffects::DefaultResource::get ());
4648+
4649+ if (!getNoCopy ())
4650+ effects.emplace_back (mlir::MemoryEffects::Write::get (),
4651+ mlir::SideEffects::DefaultResource::get ());
4652+ }
4653+
45444654// ===----------------------------------------------------------------------===//
45454655// FIROpsDialect
45464656// ===----------------------------------------------------------------------===//
0 commit comments