Lines Matching defs:box
24 /// Create a fir.box describing the new address, bounds, and length parameters
25 /// for a MutableBox \p box.
28 const fir::MutableBoxValue &box, mlir::Value addr,
33 return builder.createConvert(loc, box.getBoxTy(), addr);
52 // Ignore lengths if already constant in the box type (this would trigger an
56 if (auto charTy = mlir::dyn_cast<fir::CharacterType>(box.getEleTy())) {
57 // Cast address to box type so that both input and output type have
59 auto bt = box.getBaseTy();
68 } else if (fir::isUnlimitedPolymorphicType(box.getBoxTy())) {
74 } else if (box.isDerivedWithLenParameters()) {
79 return builder.create<fir::EmboxOp>(loc, box.getBoxTy(), cleanedAddr, shape,
92 /// That is, the properties may be only stored in a fir.box in memory if we
96 /// when they are not aware of what a fir.box is and fir.box have not been
103 const fir::MutableBoxValue &box,
105 : builder{builder}, loc{loc}, box{box} {
106 if (forceIRBoxRead || !box.isDescribedByVariables())
107 irBox = builder.create<fir::LoadOp>(loc, box.getAddr());
112 auto memrefTy = box.getBoxTy().getEleTy();
117 auto addrVar = box.getMutableProperties().addr;
130 const auto &mutableProperties = box.getMutableProperties();
139 if (box.hasNonDeferredLenParams())
140 return box.nonDeferredLenParams()[0];
144 const auto &deferred = box.getMutableProperties().deferredParams;
155 auto rank = box.rank();
170 if (box.isCharacter())
172 else if (box.isDerivedWithLenParameters())
177 /// Return the loaded fir.box.
185 auto rank = box.rank();
193 fir::MutableBoxValue box;
201 const fir::MutableBoxValue &box,
203 : builder{builder}, loc{loc}, box{box}, typeSourceBox{typeSourceBox},
213 if (box.isDescribedByVariables())
219 /// Update MutableBoxValue with a new fir.box. This requires that the mutable
220 /// box is not described by a set of variables, since they could not describe
221 /// all that can be described in the new fir.box (e.g. non contiguous entity).
223 assert(!box.isDescribedByVariables());
224 builder.create<fir::StoreOp>(loc, newBox, box.getAddr());
229 if (box.isDescribedByVariables()) {
230 auto addrVar = box.getMutableProperties().addr;
236 // declaration type of the mutable box. See Fortran 2018 7.8.2 NOTE 1.
238 // currently unallocating fir.box guarantees that we are resetting the
245 builder, loc, box.getBoxTy(), box.nonDeferredLenParams(),
247 builder.create<fir::StoreOp>(loc, deallocatedBox, box.getAddr());
251 /// Copy Values from the fir.box into the property variables if any.
253 if (!box.isDescribedByVariables())
259 MutablePropertyReader{builder, loc, box, /*forceIRBoxRead=*/true}.read(
264 /// Copy Values from property variables, if any, into the fir.box.
266 if (!box.isDescribedByVariables())
271 auto addr = MutablePropertyReader{builder, loc, box}.read(lbounds, extents,
277 /// Update the IR box (fir.ref<fir.box<T>>) of the MutableBoxValue.
282 mlir::Value irBox = createNewFirBox(builder, loc, box, addr, lbounds,
284 builder.create<fir::StoreOp>(loc, irBox, box.getAddr());
296 const auto &mutableProperties = box.getMutableProperties();
313 if (box.isCharacter())
320 else if (box.isDerivedWithLenParameters())
325 fir::MutableBoxValue box;
354 TODO(loc, "creating unallocated fir.box of derived type with length "
397 auto box =
400 MutablePropertyWriter{builder, loc, box, typeSourceBox}
402 return box;
406 /// can be read to a reified box value.
407 static bool readToBoxValue(const fir::MutableBoxValue &box,
410 // should not be tracked as a fir.box.
411 if (box.isDescribedByVariables())
414 // Track value as fir.box
415 if ((box.isDerived() && mayBePolymorphic) || box.isUnlimitedPolymorphic())
417 if (box.hasAssumedRank())
420 // fir.box.
421 if (box.isAllocatable() || box.rank() == 0)
425 return !fir::valueHasFirAttribute(box.getAddr(),
431 const fir::MutableBoxValue &box,
437 if (readToBoxValue(box, mayBePolymorphic)) {
438 auto reader = MutablePropertyReader(builder, loc, box);
439 if (preserveLowerBounds && !box.hasAssumedRank())
442 box.nonDeferredLenParams()};
445 // fir.box.
447 MutablePropertyReader(builder, loc, box).read(lbounds, extents, lengths);
450 auto rank = box.rank();
451 if (box.isCharacter()) {
458 if (box.isPolymorphic())
459 sourceBox = builder.create<fir::LoadOp>(loc, box.getAddr());
462 if (box.isPolymorphic())
470 const fir::MutableBoxValue &box) {
471 auto addr = MutablePropertyReader(builder, loc, box).readBaseAddress();
477 const fir::MutableBoxValue &box) {
478 auto addr = MutablePropertyReader(builder, loc, box).readBaseAddress();
495 const fir::MutableBoxValue &box) {
496 auto addr = MutablePropertyReader(builder, loc, box).readBaseAddress();
512 const fir::MutableBoxValue &box,
515 MutablePropertyWriter writer(builder, loc, box);
545 // Rebox array fir.box to the pointer type and apply potential new lower
550 if (box.hasAssumedRank()) {
552 "expect both arr and box to be assumed-rank");
554 loc, box.getBoxTy(), arr.getAddr(),
557 } else if (box.isDescribedByVariables()) {
559 // fir.box to update the LHS.
579 builder.create<fir::ReboxOp>(loc, box.getBoxTy(), arr.getAddr(),
598 const fir::MutableBoxValue &box, const fir::ExtendedValue &source,
630 MutablePropertyWriter writer(builder, loc, box);
653 // Rebox right-hand side fir.box with a new shape and type.
654 if (box.isDescribedByVariables()) {
656 // fir.box to update the LHS.
680 builder.create<fir::ReboxOp>(loc, box.getBoxTy(), arr.getAddr(),
699 const fir::MutableBoxValue &box,
702 if (box.isPolymorphic() && polymorphicSetType) {
705 auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(box.getBoxTy());
709 fir::runtime::genNullifyDerivedType(builder, loc, box.getAddr(), recTy,
710 box.rank());
714 MutablePropertyWriter{builder, loc, box, {}, allocator}
720 const fir::MutableBoxValue &box, mlir::ValueRange lenParams) {
723 if (auto charTy = mlir::dyn_cast<fir::CharacterType>(box.getEleTy())) {
725 if (box.hasNonDeferredLenParams()) {
727 builder.createConvert(loc, idxTy, box.nonDeferredLenParams()[0]));
743 const fir::MutableBoxValue &box,
747 auto lengths = getNewLengths(builder, loc, box, lenParams);
749 loc, box.getBaseTy(), allocName, lengths, extents);
750 if (mlir::isa<fir::RecordType>(box.getEleTy())) {
755 mlir::Value irBox = createNewFirBox(builder, loc, box, newStorage,
764 const fir::MutableBoxValue &box, mlir::ValueRange lbounds,
767 auto lengths = getNewLengths(builder, loc, box, lenParams);
771 auto heap = builder.create<fir::AllocMemOp>(loc, box.getBaseTy(), allocName,
773 MutablePropertyWriter{builder, loc, box}.updateMutableBox(
775 if (mlir::isa<fir::RecordType>(box.getEleTy())) {
780 mlir::Value irBox = fir::factory::getMutableIRBox(builder, loc, box);
790 const fir::MutableBoxValue &box) {
791 auto addr = MutablePropertyReader(builder, loc, box).readBaseAddress();
793 MutablePropertyWriter{builder, loc, box}.setUnallocatedStatus();
799 const fir::MutableBoxValue &box, mlir::ValueRange shape,
803 auto reader = MutablePropertyReader(builder, loc, box);
810 if (box.hasRank()) {
816 if (box.isCharacter()) {
817 auto len = box.hasNonDeferredLenParams() ? reader.readCharacterLength()
819 if (box.hasRank())
823 if (box.isDerivedWithLenParameters())
825 if (box.hasRank())
834 // The box is allocated. Check if it must be reallocated and
852 if (box.isCharacter() && !box.hasNonDeferredLenParams()) {
859 } else if (box.isDerivedWithLenParameters()) {
875 builder, loc, box, extents, lengthParams,
893 // The box is not yet allocated, simply allocate it.
894 if (shape.empty() && box.rank() != 0) {
904 builder, loc, box, shape, lengthParams, ".auto.alloc");
921 const fir::MutableBoxValue &box,
927 auto reader = MutablePropertyReader(builder, loc, box);
929 if (!takeLboundsIfRealloc && box.hasRank())
934 if (box.isCharacter())
936 if (box.isDerivedWithLenParameters())
939 auto lengths = getNewLengths(builder, loc, box, lenParams);
945 MutablePropertyWriter{builder, loc, box}.updateMutableBox(
960 const fir::MutableBoxValue &box) {
961 MutablePropertyWriter{builder, loc, box}.syncIRBoxFromMutableProperties();
962 return box.getAddr();
966 const fir::MutableBoxValue &box) {
967 MutablePropertyWriter{builder, loc, box}.syncMutablePropertiesFromIRBox();