@@ -4125,46 +4125,28 @@ calculateBoundsOffset(LLVM::ModuleTranslation &moduleTranslation,
41254125 // with a pointer that's being treated like an array and we have the
41264126 // underlying type e.g. an i32, or f64 etc, e.g. a fortran descriptor base
41274127 // address (pointer pointing to the actual data) so we must caclulate the
4128- // offset using a single index which the following two loops attempts to
4129- // compute.
4130-
4131- // Calculates the size offset we need to make per row e.g. first row or
4132- // column only needs to be offset by one, but the next would have to be
4133- // the previous row/column offset multiplied by the extent of current row.
4128+ // offset using a single index which the following loop attempts to
4129+ // compute using the standard column-major algorihtm e.g for a 3D array:
41344130 //
4135- // For example ([1][10][100]):
4131+ // ((((c-idx * b-len) + b-idx) * a-len) + a_idx)
41364132 //
4137- // - First row/column we move by 1 for each index increment
4138- // - Second row/column we move by 1 (first row/column) * 10 (extent/size of
4139- // current) for 10 for each index increment
4140- // - Third row/column we would move by 10 (second row/column) *
4141- // (extent/size of current) 100 for 1000 for each index increment
4142- std::vector<llvm::Value *> dimensionIndexSizeOffset{builder.getInt64 (1 )};
4143- for (size_t i = 1 ; i < bounds.size (); ++i) {
4144- if (auto boundOp = dyn_cast_if_present<omp::MapBoundsOp>(
4145- bounds[i].getDefiningOp ())) {
4146- dimensionIndexSizeOffset.push_back (builder.CreateMul (
4147- moduleTranslation.lookupValue (boundOp.getExtent ()),
4148- dimensionIndexSizeOffset[i - 1 ]));
4149- }
4150- }
4151-
4152- // Now that we have calculated how much we move by per index, we must
4153- // multiply each lower bound offset in indexes by the size offset we
4154- // have calculated in the previous and accumulate the results to get
4155- // our final resulting offset.
4133+ // It is of note that it's doing column-major rather than row-major at the
4134+ // moment, but having a way for the frontend to indicate which major format
4135+ // to use or standardizing/canonicalizing the order of the bounds to compute
4136+ // the offset may be useful in the future when there's other frontends with
4137+ // different formats.
4138+ std::vector<llvm::Value *> dimensionIndexSizeOffset;
41564139 for (int i = bounds.size () - 1 ; i >= 0 ; --i) {
41574140 if (auto boundOp = dyn_cast_if_present<omp::MapBoundsOp>(
41584141 bounds[i].getDefiningOp ())) {
4159- if (idx.empty ())
4160- idx.emplace_back (builder.CreateMul (
4161- moduleTranslation.lookupValue (boundOp.getLowerBound ()),
4162- dimensionIndexSizeOffset[i]));
4142+ if (i == ((int )bounds.size () - 1 ))
4143+ idx.emplace_back (
4144+ moduleTranslation.lookupValue (boundOp.getLowerBound ()));
41634145 else
41644146 idx.back () = builder.CreateAdd (
4165- idx.back (), builder. CreateMul ( moduleTranslation.lookupValue (
4166- boundOp.getLowerBound ( )),
4167- dimensionIndexSizeOffset[i] ));
4147+ builder. CreateMul ( idx.back (), moduleTranslation.lookupValue (
4148+ boundOp.getExtent () )),
4149+ moduleTranslation. lookupValue (boundOp. getLowerBound () ));
41684150 }
41694151 }
41704152 }
0 commit comments