FLANG
Utils.h
1//===-- Lower/OpenMP/Utils.h ------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef FORTRAN_LOWER_OPENMPUTILS_H
10#define FORTRAN_LOWER_OPENMPUTILS_H
11
12#include "flang/Lower/OpenMP/Clauses.h"
13#include "flang/Optimizer/Builder/HLFIRTools.h"
14#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
15#include "mlir/IR/Location.h"
16#include "mlir/IR/Value.h"
17#include "llvm/Support/CommandLine.h"
18#include <cstdint>
19#include <optional>
20
21extern llvm::cl::opt<bool> treatIndexAsSection;
22
23namespace fir {
24class FirOpBuilder;
25class RecordType;
26} // namespace fir
27namespace Fortran {
28
29namespace semantics {
30class Symbol;
31} // namespace semantics
32
33namespace parser {
34struct OmpObject;
35struct OmpObjectList;
36} // namespace parser
37
38namespace lower {
40namespace pft {
41struct Evaluation;
42}
43
45
46namespace omp {
47
48struct DeclareTargetCaptureInfo {
49 mlir::omp::DeclareTargetCaptureClause clause;
50 bool automap = false;
51 const semantics::Symbol &symbol;
52
53 DeclareTargetCaptureInfo(mlir::omp::DeclareTargetCaptureClause c,
54 const semantics::Symbol &s, bool a = false)
55 : clause(c), automap(a), symbol(s) {}
56};
57
58// A small helper structure for keeping track of a component members MapInfoOp
59// and index data when lowering OpenMP map clauses. Keeps track of the
60// placement of the component in the derived type hierarchy it rests within,
61// alongside the generated mlir::omp::MapInfoOp for the mapped component.
62//
63// As an example of what the contents of this data structure may be like,
64// when provided the following derived type and map of that type:
65//
66// type :: bottom_layer
67// real(8) :: i2
68// real(4) :: array_i2(10)
69// real(4) :: array_j2(10)
70// end type bottom_layer
71//
72// type :: top_layer
73// real(4) :: i
74// integer(4) :: array_i(10)
75// real(4) :: j
76// type(bottom_layer) :: nested
77// integer, allocatable :: array_j(:)
78// integer(4) :: k
79// end type top_layer
80//
81// type(top_layer) :: top_dtype
82//
83// map(tofrom: top_dtype%nested%i2, top_dtype%k, top_dtype%nested%array_i2)
84//
85// We would end up with an OmpMapParentAndMemberData populated like below:
86//
87// memberPlacementIndices:
88// Vector 1: 3, 0
89// Vector 2: 5
90// Vector 3: 3, 1
91//
92// memberMap:
93// Entry 1: omp.map.info for "top_dtype%nested%i2"
94// Entry 2: omp.map.info for "top_dtype%k"
95// Entry 3: omp.map.info for "top_dtype%nested%array_i2"
96//
97// And this OmpMapParentAndMemberData would be accessed via the parent
98// symbol for top_dtype. Other parent derived type instances that have
99// members mapped would have there own OmpMapParentAndMemberData entry
100// accessed via their own symbol.
102 // The indices representing the component members placement in its derived
103 // type parents hierarchy.
104 llvm::SmallVector<llvm::SmallVector<int64_t>> memberPlacementIndices;
105
106 // Placement of the member in the member vector.
108
109 bool isDuplicateMemberMapInfo(llvm::SmallVectorImpl<int64_t> &memberIndices) {
110 return llvm::find_if(memberPlacementIndices, [&](auto &memberData) {
111 return llvm::equal(memberIndices, memberData);
112 }) != memberPlacementIndices.end();
113 }
114
115 void addChildIndexAndMapToParent(const omp::Object &object,
116 mlir::omp::MapInfoOp &mapOp,
118};
119
120void insertChildMapInfoIntoParent(
124 std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
125 llvm::SmallVectorImpl<mlir::Value> &mapOperands,
126 llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms);
127
128void generateMemberPlacementIndices(
129 const Object &object, llvm::SmallVectorImpl<int64_t> &indices,
131
132bool isMemberOrParentAllocatableOrPointer(
133 const Object &object, Fortran::semantics::SemanticsContext &semaCtx);
134
135mlir::Value createParentSymAndGenIntermediateMaps(
136 mlir::Location clauseLocation, Fortran::lower::AbstractConverter &converter,
138 omp::ObjectList &objectList, llvm::SmallVectorImpl<int64_t> &indices,
139 OmpMapParentAndMemberData &parentMemberIndices, llvm::StringRef asFortran,
140 mlir::omp::ClauseMapFlags mapTypeBits);
141
142bool requiresImplicitDefaultDeclareMapper(
143 const semantics::DerivedTypeSpec &typeSpec);
144
145omp::ObjectList gatherObjectsOf(omp::Object derivedTypeMember,
147
148mlir::Type getLoopVarType(lower::AbstractConverter &converter,
149 std::size_t loopVarTypeSize);
150
152getIterationVariableSymbol(const lower::pft::Evaluation &eval);
153
154void gatherFuncAndVarSyms(
155 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
156 llvm::SmallVectorImpl<DeclareTargetCaptureInfo> &symbolAndClause,
157 bool automap = false);
158
159int64_t getCollapseValue(const List<Clause> &clauses);
160
161void genObjectList(const ObjectList &objects,
162 lower::AbstractConverter &converter,
163 llvm::SmallVectorImpl<mlir::Value> &operands);
164
165void lastprivateModifierNotSupported(const omp::clause::Lastprivate &lastp,
166 mlir::Location loc);
167
168pft::Evaluation *getNestedDoConstruct(pft::Evaluation &eval);
169
170int64_t collectLoopRelatedInfo(
171 lower::AbstractConverter &converter, mlir::Location currentLocation,
173 const omp::List<omp::Clause> &clauses,
174 mlir::omp::LoopRelatedClauseOps &result,
175 llvm::SmallVectorImpl<const semantics::Symbol *> &iv);
176
177void collectLoopRelatedInfo(
178 lower::AbstractConverter &converter, mlir::Location currentLocation,
180 std::int64_t collapseValue,
181 // const omp::List<omp::Clause> &clauses,
182 mlir::omp::LoopRelatedClauseOps &result,
183 llvm::SmallVectorImpl<const semantics::Symbol *> &iv);
184
185void collectTileSizesFromOpenMPConstruct(
186 const parser::OpenMPConstruct *ompCons,
187 llvm::SmallVectorImpl<int64_t> &tileSizes,
189
190mlir::Value genElementSizeInBytes(fir::FirOpBuilder &builder,
191 mlir::Location loc,
192 const mlir::DataLayout &dl,
193 hlfir::Entity entity);
194
195mlir::Value genAffinityAddr(Fortran::lower::AbstractConverter &converter,
196 const omp::Object &object,
198 mlir::Location loc);
199
200mlir::Value genAffinityLen(fir::FirOpBuilder &builder, mlir::Location loc,
201 const mlir::DataLayout &dl, hlfir::Entity entity,
203
205 mlir::Value lb;
206 mlir::Value ub;
207 mlir::Value step;
208 Fortran::semantics::Symbol *ivSym = nullptr;
209};
210
211bool hasIteratorIVReference(
212 const omp::Object &object,
213 const llvm::SmallPtrSetImpl<const Fortran::semantics::Symbol *> &ivSyms);
214
220void defaultMangler(Fortran::lower::AbstractConverter &converter,
221 std::string &mapperIdName, llvm::StringRef memberName);
222
223mlir::Value genIteratorCoordinate(Fortran::lower::AbstractConverter &converter,
224 hlfir::Entity entity,
226 mlir::Location loc);
227
228std::optional<llvm::SmallVector<mlir::Value>> getIteratorElementIndices(
229 Fortran::lower::AbstractConverter &converter, const omp::Object &object,
230 Fortran::lower::StatementContext &stmtCtx, mlir::Location loc);
231
232} // namespace omp
233} // namespace lower
234} // namespace Fortran
235
236#endif // FORTRAN_LOWER_OPENMPUTILS_H
Definition AbstractConverter.h:87
Definition StatementContext.h:46
Definition semantics.h:67
Definition symbol.h:825
Definition FIRBuilder.h:56
Definition HLFIRTools.h:52
Definition FIRType.h:103
Definition OpenACC.h:20
Definition ParserActions.h:24
Definition check-expression.h:19
Definition bit-population-count.h:20
Definition AbstractConverter.h:37
Definition PFTBuilder.h:221
Definition parse-tree.h:3537
Definition parse-tree.h:3525
Definition parse-tree.h:5450