@@ -122,40 +122,25 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
122122 typeError ();
123123}
124124
125- fir::ShapeShiftOp
126- Fortran::lower::omp::getShapeShift (fir::FirOpBuilder &builder,
127- mlir::Location loc, mlir::Value box,
128- bool cannotHaveNonDefaultLowerBounds) {
125+ fir::ShapeShiftOp Fortran::lower::omp::getShapeShift (fir::FirOpBuilder &builder,
126+ mlir::Location loc,
127+ mlir::Value box) {
129128 fir::SequenceType sequenceType = mlir::cast<fir::SequenceType>(
130129 hlfir::getFortranElementOrSequenceType (box.getType ()));
131130 const unsigned rank = sequenceType.getDimension ();
132-
133131 llvm::SmallVector<mlir::Value> lbAndExtents;
134132 lbAndExtents.reserve (rank * 2 );
135- mlir::Type idxTy = builder.getIndexType ();
136133
137- if (cannotHaveNonDefaultLowerBounds && !sequenceType.hasDynamicExtents ()) {
138- // We don't need fir::BoxDimsOp if all of the extents are statically known
139- // and we can assume default lower bounds. This helps avoids reads from the
140- // mold arg.
141- mlir::Value one = builder.createIntegerConstant (loc, idxTy, 1 );
142- for (int64_t extent : sequenceType.getShape ()) {
143- assert (extent != sequenceType.getUnknownExtent ());
144- mlir::Value extentVal = builder.createIntegerConstant (loc, idxTy, extent);
145- lbAndExtents.push_back (one);
146- lbAndExtents.push_back (extentVal);
147- }
148- } else {
149- for (unsigned i = 0 ; i < rank; ++i) {
150- // TODO: ideally we want to hoist box reads out of the critical section.
151- // We could do this by having box dimensions in block arguments like
152- // OpenACC does
153- mlir::Value dim = builder.createIntegerConstant (loc, idxTy, i);
154- auto dimInfo =
155- builder.create <fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim);
156- lbAndExtents.push_back (dimInfo.getLowerBound ());
157- lbAndExtents.push_back (dimInfo.getExtent ());
158- }
134+ mlir::Type idxTy = builder.getIndexType ();
135+ for (unsigned i = 0 ; i < rank; ++i) {
136+ // TODO: ideally we want to hoist box reads out of the critical section.
137+ // We could do this by having box dimensions in block arguments like
138+ // OpenACC does
139+ mlir::Value dim = builder.createIntegerConstant (loc, idxTy, i);
140+ auto dimInfo =
141+ builder.create <fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dim);
142+ lbAndExtents.push_back (dimInfo.getLowerBound ());
143+ lbAndExtents.push_back (dimInfo.getExtent ());
159144 }
160145
161146 auto shapeShiftTy = fir::ShapeShiftType::get (builder.getContext (), rank);
@@ -263,13 +248,12 @@ class PopulateInitAndCleanupRegionsHelper {
263248 mlir::Type argType, mlir::Value scalarInitValue,
264249 mlir::Value allocatedPrivVarArg, mlir::Value moldArg,
265250 mlir::Block *initBlock, mlir::Region &cleanupRegion,
266- DeclOperationKind kind, const Fortran::semantics::Symbol *sym,
267- bool cannotHaveLowerBounds)
251+ DeclOperationKind kind, const Fortran::semantics::Symbol *sym)
268252 : converter{converter}, builder{converter.getFirOpBuilder ()}, loc{loc},
269253 argType{argType}, scalarInitValue{scalarInitValue},
270254 allocatedPrivVarArg{allocatedPrivVarArg}, moldArg{moldArg},
271255 initBlock{initBlock}, cleanupRegion{cleanupRegion}, kind{kind},
272- sym{sym}, cannotHaveNonDefaultLowerBounds{cannotHaveLowerBounds} {
256+ sym{sym} {
273257 valType = fir::unwrapRefType (argType);
274258 }
275259
@@ -311,10 +295,6 @@ class PopulateInitAndCleanupRegionsHelper {
311295 // / Any length parameters which have been fetched for the type
312296 mlir::SmallVector<mlir::Value> lenParams;
313297
314- // / If the source variable being privatized definitely can't have non-default
315- // / lower bounds then we don't need to generate code to read them.
316- bool cannotHaveNonDefaultLowerBounds;
317-
318298 void createYield (mlir::Value ret) {
319299 builder.create <mlir::omp::YieldOp>(loc, ret);
320300 }
@@ -452,8 +432,7 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
452432 // Special case for (possibly allocatable) arrays of polymorphic types
453433 // e.g. !fir.class<!fir.heap<!fir.array<?x!fir.type<>>>>
454434 if (source.isPolymorphic ()) {
455- fir::ShapeShiftOp shape =
456- getShapeShift (builder, loc, source, cannotHaveNonDefaultLowerBounds);
435+ fir::ShapeShiftOp shape = getShapeShift (builder, loc, source);
457436 mlir::Type arrayType = source.getElementOrSequenceType ();
458437 mlir::Value allocatedArray = builder.create <fir::AllocMemOp>(
459438 loc, arrayType, /* typeparams=*/ mlir::ValueRange{}, shape.getExtents ());
@@ -501,8 +480,8 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
501480 // Put the temporary inside of a box:
502481 // hlfir::genVariableBox doesn't handle non-default lower bounds
503482 mlir::Value box;
504- fir::ShapeShiftOp shapeShift = getShapeShift (builder, loc, getLoadedMoldArg (),
505- cannotHaveNonDefaultLowerBounds );
483+ fir::ShapeShiftOp shapeShift =
484+ getShapeShift (builder, loc, getLoadedMoldArg () );
506485 mlir::Type boxType = getLoadedMoldArg ().getType ();
507486 if (mlir::isa<fir::BaseBoxType>(temp.getType ()))
508487 // the box created by the declare form createTempFromMold is missing
@@ -637,10 +616,10 @@ void Fortran::lower::omp::populateByRefInitAndCleanupRegions(
637616 mlir::Type argType, mlir::Value scalarInitValue, mlir::Block *initBlock,
638617 mlir::Value allocatedPrivVarArg, mlir::Value moldArg,
639618 mlir::Region &cleanupRegion, DeclOperationKind kind,
640- const Fortran::semantics::Symbol *sym, bool cannotHaveLowerBounds ) {
619+ const Fortran::semantics::Symbol *sym) {
641620 PopulateInitAndCleanupRegionsHelper helper (
642621 converter, loc, argType, scalarInitValue, allocatedPrivVarArg, moldArg,
643- initBlock, cleanupRegion, kind, sym, cannotHaveLowerBounds );
622+ initBlock, cleanupRegion, kind, sym);
644623 helper.populateByRefInitAndCleanupRegions ();
645624
646625 // Often we load moldArg to check something (e.g. length parameters, shape)
0 commit comments