================ @@ -88,6 +91,175 @@ void gatherFuncAndVarSyms( symbolAndClause.emplace_back(clause, *object.id()); } +int getComponentPlacementInParent( + const Fortran::semantics::Symbol *componentSym) { + const auto *derived = + componentSym->owner() + .derivedTypeSpec() + ->typeSymbol() + .detailsIf<Fortran::semantics::DerivedTypeDetails>(); + assert(derived && + "expected derived type details when processing component symbol"); + int placement = 0; + for (auto t : derived->componentNames()) { + if (t == componentSym->name()) + return placement; + placement++; + } + return -1; +} + +std::optional<Object> +getCompObjOrNull(std::optional<Object> object, + Fortran::semantics::SemanticsContext &semaCtx) { + if (!object) + return std::nullopt; + + auto ref = evaluate::ExtractDataRef(*object.value().ref()); + if (!ref) + return std::nullopt; + + if (std::get_if<evaluate::Component>(&ref->u)) + return object; + + auto baseObj = getBaseObject(object.value(), semaCtx); + if (!baseObj) + return std::nullopt; + + return getCompObjOrNull(baseObj.value(), semaCtx); +} + +llvm::SmallVector<int> +generateMemberPlacementIndices(const Object &object, + Fortran::semantics::SemanticsContext &semaCtx) { + std::list<int> indices; + auto compObj = getCompObjOrNull(object, semaCtx); + while (compObj) { + indices.push_front(getComponentPlacementInParent(compObj->id())); + compObj = + getCompObjOrNull(getBaseObject(compObj.value(), semaCtx), semaCtx); + } + + return llvm::SmallVector<int>{std::begin(indices), std::end(indices)}; +} + +static void calculateShapeAndFillIndices( + llvm::SmallVectorImpl<int64_t> &shape, + llvm::SmallVector<OmpMapMemberIndicesData> &memberPlacementData) { ---------------- skatrak wrote:
You're right, elements in `llvm::ArrayRef` are read-only. Sorry about that, I hope I didn't make you waste too much time trying this! https://github.com/llvm/llvm-project/pull/82853 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits