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/LLVMIR/LLVMAttrs.h"
15#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
16#include "mlir/IR/Location.h"
17#include "mlir/IR/Value.h"
18#include "llvm/Frontend/OpenMP/OMPContext.h"
19#include "llvm/Support/CommandLine.h"
20#include <cstdint>
21#include <optional>
22
23extern llvm::cl::opt<bool> treatIndexAsSection;
24
25namespace fir {
26class FirOpBuilder;
27class RecordType;
28} // namespace fir
29namespace Fortran {
30
31namespace semantics {
33class Symbol;
34namespace omp {
36} // namespace omp
37} // namespace semantics
38
39namespace parser {
40struct OmpObject;
41struct OmpObjectList;
42} // namespace parser
43
44namespace lower {
46namespace pft {
47struct Evaluation;
48}
49
51
52namespace omp {
53
54struct DeclareTargetCaptureInfo {
55 mlir::omp::DeclareTargetCaptureClause clause;
56 bool automap = false;
57 const semantics::Symbol &symbol;
58
59 DeclareTargetCaptureInfo(mlir::omp::DeclareTargetCaptureClause c,
60 const semantics::Symbol &s, bool a = false)
61 : clause(c), automap(a), symbol(s) {}
62};
63
64// A small helper structure for keeping track of a component members MapInfoOp
65// and index data when lowering OpenMP map clauses. Keeps track of the
66// placement of the component in the derived type hierarchy it rests within,
67// alongside the generated mlir::omp::MapInfoOp for the mapped component.
68//
69// As an example of what the contents of this data structure may be like,
70// when provided the following derived type and map of that type:
71//
72// type :: bottom_layer
73// real(8) :: i2
74// real(4) :: array_i2(10)
75// real(4) :: array_j2(10)
76// end type bottom_layer
77//
78// type :: top_layer
79// real(4) :: i
80// integer(4) :: array_i(10)
81// real(4) :: j
82// type(bottom_layer) :: nested
83// integer, allocatable :: array_j(:)
84// integer(4) :: k
85// end type top_layer
86//
87// type(top_layer) :: top_dtype
88//
89// map(tofrom: top_dtype%nested%i2, top_dtype%k, top_dtype%nested%array_i2)
90//
91// We would end up with an OmpMapParentAndMemberData populated like below:
92//
93// memberPlacementIndices:
94// Vector 1: 3, 0
95// Vector 2: 5
96// Vector 3: 3, 1
97//
98// memberMap:
99// Entry 1: omp.map.info for "top_dtype%nested%i2"
100// Entry 2: omp.map.info for "top_dtype%k"
101// Entry 3: omp.map.info for "top_dtype%nested%array_i2"
102//
103// And this OmpMapParentAndMemberData would be accessed via the parent
104// symbol for top_dtype. Other parent derived type instances that have
105// members mapped would have there own OmpMapParentAndMemberData entry
106// accessed via their own symbol.
108 // The indices representing the component members placement in its derived
109 // type parents hierarchy.
110 llvm::SmallVector<llvm::SmallVector<int64_t>> memberPlacementIndices;
111
112 // Placement of the member in the member vector.
114
115 bool isDuplicateMemberMapInfo(llvm::SmallVectorImpl<int64_t> &memberIndices) {
116 return llvm::find_if(memberPlacementIndices, [&](auto &memberData) {
117 return llvm::equal(memberIndices, memberData);
118 }) != memberPlacementIndices.end();
119 }
120
121 void addChildIndexAndMapToParent(const omp::Object &object,
122 mlir::omp::MapInfoOp &mapOp,
124};
125
126void insertChildMapInfoIntoParent(
130 std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
133
134void generateMemberPlacementIndices(
135 const Object &object, llvm::SmallVectorImpl<int64_t> &indices,
137
138bool isMemberOrParentAllocatableOrPointer(
139 const Object &object, Fortran::semantics::SemanticsContext &semaCtx);
140
141mlir::Value createParentSymAndGenIntermediateMaps(
142 mlir::Location clauseLocation, Fortran::lower::AbstractConverter &converter,
144 omp::ObjectList &objectList, llvm::SmallVectorImpl<int64_t> &indices,
145 OmpMapParentAndMemberData &parentMemberIndices, llvm::StringRef asFortran,
146 mlir::omp::ClauseMapFlags mapTypeBits);
147
148bool requiresImplicitDefaultDeclareMapper(
149 const semantics::DerivedTypeSpec &typeSpec);
150
151omp::ObjectList gatherObjectsOf(omp::Object derivedTypeMember,
153
154mlir::Type getLoopVarType(lower::AbstractConverter &converter,
155 std::size_t loopVarTypeSize);
156
158getIterationVariableSymbol(const lower::pft::Evaluation &eval);
159
160void gatherFuncAndVarSyms(
161 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
163 bool automap = false);
164
165int64_t getCollapseValue(const List<Clause> &clauses);
166
167void genObjectList(const ObjectList &objects,
168 lower::AbstractConverter &converter,
170
171void lastprivateModifierNotSupported(const omp::clause::Lastprivate &lastp,
172 mlir::Location loc);
173
174pft::Evaluation *tryGetNestedDoConstruct(pft::Evaluation &eval);
175
176pft::Evaluation *getNestedDoConstruct(pft::Evaluation &eval);
177
178int64_t collectLoopRelatedInfo(
179 lower::AbstractConverter &converter, mlir::Location currentLocation,
181 const omp::List<omp::Clause> &clauses,
182 mlir::omp::LoopRelatedClauseOps &result,
184
185void collectLoopRelatedInfo(
186 lower::AbstractConverter &converter, mlir::Location currentLocation,
188 std::int64_t collapseValue,
189 // const omp::List<omp::Clause> &clauses,
190 mlir::omp::LoopRelatedClauseOps &result,
192
193void collectTileSizesFromOpenMPConstruct(
194 const parser::OpenMPConstruct *ompCons,
197
198mlir::Value genElementSizeInBytes(fir::FirOpBuilder &builder,
199 mlir::Location loc,
200 const mlir::DataLayout &dl,
201 hlfir::Entity entity);
202
203mlir::Value genAffinityAddr(Fortran::lower::AbstractConverter &converter,
204 const omp::Object &object,
206 mlir::Location loc);
207
208mlir::Value genAffinityLen(fir::FirOpBuilder &builder, mlir::Location loc,
209 const mlir::DataLayout &dl, hlfir::Entity entity,
211
213 mlir::Value lb;
214 mlir::Value ub;
215 mlir::Value step;
216 Fortran::semantics::Symbol *ivSym = nullptr;
217};
218
219bool hasIteratorIVReference(
220 const omp::Object &object,
221 const llvm::SmallPtrSetImpl<const Fortran::semantics::Symbol *> &ivSyms);
222
228void defaultMangler(Fortran::lower::AbstractConverter &converter,
229 std::string &mapperIdName, llvm::StringRef memberName);
230
231mlir::Value genIteratorCoordinate(Fortran::lower::AbstractConverter &converter,
232 hlfir::Entity entity,
234 mlir::Location loc);
235
252mlir::FlatSymbolRefAttr resolveMapperId(
253 Fortran::lower::AbstractConverter &converter, mlir::Location loc,
254 const omp::Object &object, llvm::StringRef mapperIdName,
255 mlir::omp::ClauseMapFlags mapTypeBits, llvm::omp::Directive directive);
256
257std::optional<llvm::SmallVector<mlir::Value>> getIteratorElementIndices(
258 Fortran::lower::AbstractConverter &converter, const omp::Object &object,
259 Fortran::lower::StatementContext &stmtCtx, mlir::Location loc);
260
265void collectEnclosingConstructTraits(
266 mlir::Operation *op,
268
271bool hasOnlyAMDGCNTargets(mlir::ModuleOp module);
272
275bool requiresUnifiedSharedMemory(mlir::ModuleOp module,
277
281semantics::omp::OmpVariantMatchContext makeVariantMatchContext(
282 mlir::ModuleOp module,
284
285} // namespace omp
286} // namespace lower
287} // namespace Fortran
288
289#endif // FORTRAN_LOWER_OPENMPUTILS_H
Definition AbstractConverter.h:87
Definition StatementContext.h:46
Definition semantics.h:67
Definition symbol.h:916
Definition FIRBuilder.h:66
Definition HLFIRTools.h:52
Definition FIRType.h:106
Definition OpenACC.h:22
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:222
Definition parse-tree.h:3646
Definition parse-tree.h:3634
Definition parse-tree.h:5681