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
157std::size_t getLoopVarSize(const semantics::Symbol &sym);
158
160getIterationVariableSymbol(const lower::pft::Evaluation &eval);
161
162void gatherFuncAndVarSyms(
163 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
165 bool automap = false);
166
167int64_t getCollapseValue(const List<Clause> &clauses);
168
169void genObjectList(const ObjectList &objects,
170 lower::AbstractConverter &converter,
172
173void lastprivateModifierNotSupported(const omp::clause::Lastprivate &lastp,
174 mlir::Location loc);
175
176pft::Evaluation *tryGetNestedDoConstruct(pft::Evaluation &eval);
177
178pft::Evaluation *getNestedDoConstruct(pft::Evaluation &eval);
179
180int64_t collectLoopRelatedInfo(
181 lower::AbstractConverter &converter, mlir::Location currentLocation,
183 const omp::List<omp::Clause> &clauses,
184 mlir::omp::LoopRelatedClauseOps &result,
186
187void collectLoopRelatedInfo(
188 lower::AbstractConverter &converter, mlir::Location currentLocation,
190 std::int64_t collapseValue,
191 // const omp::List<omp::Clause> &clauses,
192 mlir::omp::LoopRelatedClauseOps &result,
194
195void collectTileSizesFromOpenMPConstruct(
196 const parser::OpenMPConstruct *ompCons,
199
200mlir::Value genElementSizeInBytes(fir::FirOpBuilder &builder,
201 mlir::Location loc,
202 const mlir::DataLayout &dl,
203 hlfir::Entity entity);
204
205mlir::Value genAffinityAddr(Fortran::lower::AbstractConverter &converter,
206 const omp::Object &object,
208 mlir::Location loc);
209
210mlir::Value genAffinityLen(fir::FirOpBuilder &builder, mlir::Location loc,
211 const mlir::DataLayout &dl, hlfir::Entity entity,
213
215 mlir::Value lb;
216 mlir::Value ub;
217 mlir::Value step;
218 Fortran::semantics::Symbol *ivSym = nullptr;
219};
220
225getIteratorRangesForObject(const omp::Object &object,
227
233void defaultMangler(Fortran::lower::AbstractConverter &converter,
234 std::string &mapperIdName, llvm::StringRef memberName);
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
261void collectEnclosingConstructTraits(
262 mlir::Operation *op,
264
267bool hasOnlyAMDGCNTargets(mlir::ModuleOp module);
268
271bool requiresUnifiedSharedMemory(mlir::ModuleOp module,
273
277semantics::omp::OmpVariantMatchContext makeVariantMatchContext(
278 mlir::ModuleOp module,
280
281} // namespace omp
282} // namespace lower
283} // namespace Fortran
284
285#endif // FORTRAN_LOWER_OPENMPUTILS_H
Definition AbstractConverter.h:87
Definition StatementContext.h:46
Definition semantics.h:71
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