@@ -207,54 +207,6 @@ static bool isAllocatableOrPointer(const Fortran::lower::SomeExpr &expr) {
207207 return sym && Fortran::semantics::IsAllocatableOrPointer (*sym);
208208}
209209
210- // / Given the address of an array element and the ExtendedValue describing the
211- // / array, returns the ExtendedValue describing the array element. The purpose
212- // / is to propagate the length parameters of the array to the element.
213- // / This can be used for elements of `array` or `array(i:j:k)`. If \p element
214- // / belongs to an array section `array%x` whose base is \p array,
215- // / arraySectionElementToExtendedValue must be used instead.
216- static fir::ExtendedValue
217- arrayElementToExtendedValue (fir::FirOpBuilder &builder, mlir::Location loc,
218- const fir::ExtendedValue &array,
219- mlir::Value element) {
220- return array.match (
221- [&](const fir::CharBoxValue &cb) -> fir::ExtendedValue {
222- return cb.clone (element);
223- },
224- [&](const fir::CharArrayBoxValue &bv) -> fir::ExtendedValue {
225- return bv.cloneElement (element);
226- },
227- [&](const fir::BoxValue &box) -> fir::ExtendedValue {
228- if (box.isCharacter ()) {
229- auto len = fir::factory::readCharLen (builder, loc, box);
230- return fir::CharBoxValue{element, len};
231- }
232- if (box.isDerivedWithLengthParameters ())
233- TODO (loc, " get length parameters from derived type BoxValue" );
234- return element;
235- },
236- [&](const auto &) -> fir::ExtendedValue { return element; });
237- }
238-
239- // / Build the ExtendedValue for \p element that is an element of an array or
240- // / array section with \p array base (`array` or `array(i:j:k)%x%y`).
241- // / If it is an array section, \p slice must be provided and be a fir::SliceOp
242- // / that describes the section.
243- static fir::ExtendedValue arraySectionElementToExtendedValue (
244- fir::FirOpBuilder &builder, mlir::Location loc,
245- const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice) {
246- if (!slice)
247- return arrayElementToExtendedValue (builder, loc, array, element);
248- auto sliceOp = mlir::dyn_cast_or_null<fir::SliceOp>(slice.getDefiningOp ());
249- assert (sliceOp && " slice must be a sliceOp" );
250- if (sliceOp.fields ().empty ())
251- return arrayElementToExtendedValue (builder, loc, array, element);
252- // For F95, using componentToExtendedValue will work, but when PDTs are
253- // lowered. It will be required to go down the slice to propagate the length
254- // parameters.
255- return fir::factory::componentToExtendedValue (builder, loc, element);
256- }
257-
258210// / Convert the array_load, `load`, to an extended value. If `path` is not
259211// / empty, then traverse through the components designated. The base value is
260212// / `newBase`. This does not accept an array_load with a slice operand.
@@ -1442,7 +1394,7 @@ class ScalarExprLowering {
14421394 assert (args.size () == seqTy.getDimension ());
14431395 auto ty = builder.getRefType (seqTy.getEleTy ());
14441396 auto addr = builder.create <fir::CoordinateOp>(loc, ty, base, args);
1445- return arrayElementToExtendedValue (builder, loc, array, addr);
1397+ return fir::factory:: arrayElementToExtendedValue (builder, loc, array, addr);
14461398 }
14471399
14481400 // / Lower an ArrayRef to a fir.coordinate_of using an element offset instead
@@ -1552,7 +1504,8 @@ class ScalarExprLowering {
15521504 auto elementAddr = builder.create <fir::ArrayCoorOp>(
15531505 loc, refTy, addr, shape, /* slice=*/ mlir::Value{}, arrayCoorArgs,
15541506 fir::getTypeParams (exv));
1555- return arrayElementToExtendedValue (builder, loc, exv, elementAddr);
1507+ return fir::factory::arrayElementToExtendedValue (builder, loc, exv,
1508+ elementAddr);
15561509 }
15571510
15581511 // / Return the coordinate of the array reference.
@@ -4842,8 +4795,8 @@ class ArrayExprLowering {
48424795 mlir::Value coor = builder.create <fir::ArrayCoorOp>(
48434796 loc, refEleTy, memref, shape, slice, indices,
48444797 fir::getTypeParams (extMemref));
4845- return arraySectionElementToExtendedValue (builder, loc, extMemref, coor,
4846- slice);
4798+ return fir::factory:: arraySectionElementToExtendedValue (
4799+ builder, loc, extMemref, coor, slice);
48474800 };
48484801 }
48494802 auto arrLoad = builder.create <fir::ArrayLoadOp>(
@@ -4893,8 +4846,8 @@ class ArrayExprLowering {
48934846 llvm::ArrayRef<mlir::NamedAttribute>{
48944847 Fortran::lower::getAdaptToByRefAttr (builder)});
48954848 builder.create <fir::StoreOp>(loc, base, temp);
4896- return arraySectionElementToExtendedValue (builder, loc, extMemref, temp,
4897- slice);
4849+ return fir::factory:: arraySectionElementToExtendedValue (
4850+ builder, loc, extMemref, temp, slice);
48984851 };
48994852 }
49004853 // In the default case, the array reference forwards an `array_fetch` Op
@@ -4903,8 +4856,8 @@ class ArrayExprLowering {
49034856 auto arrFetch = builder.create <fir::ArrayFetchOp>(
49044857 loc, adjustedArraySubtype (arrTy, iters.iterVec ()), arrLd,
49054858 iters.iterVec (), arrLdTypeParams);
4906- return arraySectionElementToExtendedValue (builder, loc, extMemref,
4907- arrFetch, slice);
4859+ return fir::factory:: arraySectionElementToExtendedValue (
4860+ builder, loc, extMemref, arrFetch, slice);
49084861 };
49094862 }
49104863
0 commit comments