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 "mlir/Dialect/OpenMP/OpenMPDialect.h"
14#include "mlir/IR/Location.h"
15#include "mlir/IR/Value.h"
16#include "llvm/Support/CommandLine.h"
17#include <cstdint>
18
19extern llvm::cl::opt<bool> treatIndexAsSection;
20
21namespace fir {
22class FirOpBuilder;
23} // namespace fir
24namespace Fortran {
25
26namespace semantics {
27class Symbol;
28} // namespace semantics
29
30namespace parser {
31struct OmpObject;
32struct OmpObjectList;
33} // namespace parser
34
35namespace lower {
36class StatementContext;
37namespace pft {
38struct Evaluation;
39}
40
41class AbstractConverter;
42
43namespace omp {
44
46 mlir::omp::DeclareTargetCaptureClause clause;
47 bool automap = false;
48 const semantics::Symbol &symbol;
49
50 DeclareTargetCaptureInfo(mlir::omp::DeclareTargetCaptureClause c,
51 const semantics::Symbol &s, bool a = false)
52 : clause(c), automap(a), symbol(s) {}
53};
54
55// A small helper structure for keeping track of a component members MapInfoOp
56// and index data when lowering OpenMP map clauses. Keeps track of the
57// placement of the component in the derived type hierarchy it rests within,
58// alongside the generated mlir::omp::MapInfoOp for the mapped component.
59//
60// As an example of what the contents of this data structure may be like,
61// when provided the following derived type and map of that type:
62//
63// type :: bottom_layer
64// real(8) :: i2
65// real(4) :: array_i2(10)
66// real(4) :: array_j2(10)
67// end type bottom_layer
68//
69// type :: top_layer
70// real(4) :: i
71// integer(4) :: array_i(10)
72// real(4) :: j
73// type(bottom_layer) :: nested
74// integer, allocatable :: array_j(:)
75// integer(4) :: k
76// end type top_layer
77//
78// type(top_layer) :: top_dtype
79//
80// map(tofrom: top_dtype%nested%i2, top_dtype%k, top_dtype%nested%array_i2)
81//
82// We would end up with an OmpMapParentAndMemberData populated like below:
83//
84// memberPlacementIndices:
85// Vector 1: 3, 0
86// Vector 2: 5
87// Vector 3: 3, 1
88//
89// memberMap:
90// Entry 1: omp.map.info for "top_dtype%nested%i2"
91// Entry 2: omp.map.info for "top_dtype%k"
92// Entry 3: omp.map.info for "top_dtype%nested%array_i2"
93//
94// And this OmpMapParentAndMemberData would be accessed via the parent
95// symbol for top_dtype. Other parent derived type instances that have
96// members mapped would have there own OmpMapParentAndMemberData entry
97// accessed via their own symbol.
99 // The indices representing the component members placement in its derived
100 // type parents hierarchy.
101 llvm::SmallVector<llvm::SmallVector<int64_t>> memberPlacementIndices;
102
103 // Placement of the member in the member vector.
105
106 bool isDuplicateMemberMapInfo(llvm::SmallVectorImpl<int64_t> &memberIndices) {
107 return llvm::find_if(memberPlacementIndices, [&](auto &memberData) {
108 return llvm::equal(memberIndices, memberData);
109 }) != memberPlacementIndices.end();
110 }
111
112 void addChildIndexAndMapToParent(const omp::Object &object,
113 mlir::omp::MapInfoOp &mapOp,
115};
116
117void insertChildMapInfoIntoParent(
121 std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
122 llvm::SmallVectorImpl<mlir::Value> &mapOperands,
123 llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms);
124
125void generateMemberPlacementIndices(
126 const Object &object, llvm::SmallVectorImpl<int64_t> &indices,
128
129bool isMemberOrParentAllocatableOrPointer(
130 const Object &object, Fortran::semantics::SemanticsContext &semaCtx);
131
132mlir::Value createParentSymAndGenIntermediateMaps(
133 mlir::Location clauseLocation, Fortran::lower::AbstractConverter &converter,
135 omp::ObjectList &objectList, llvm::SmallVectorImpl<int64_t> &indices,
136 OmpMapParentAndMemberData &parentMemberIndices, llvm::StringRef asFortran,
137 llvm::omp::OpenMPOffloadMappingFlags mapTypeBits);
138
139omp::ObjectList gatherObjectsOf(omp::Object derivedTypeMember,
141
142mlir::Type getLoopVarType(lower::AbstractConverter &converter,
143 std::size_t loopVarTypeSize);
144
146getIterationVariableSymbol(const lower::pft::Evaluation &eval);
147
148void gatherFuncAndVarSyms(
149 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
150 llvm::SmallVectorImpl<DeclareTargetCaptureInfo> &symbolAndClause,
151 bool automap = false);
152
153int64_t getCollapseValue(const List<Clause> &clauses);
154
155void genObjectList(const ObjectList &objects,
156 lower::AbstractConverter &converter,
157 llvm::SmallVectorImpl<mlir::Value> &operands);
158
159void lastprivateModifierNotSupported(const omp::clause::Lastprivate &lastp,
160 mlir::Location loc);
161
162bool collectLoopRelatedInfo(
163 lower::AbstractConverter &converter, mlir::Location currentLocation,
164 lower::pft::Evaluation &eval, const omp::List<omp::Clause> &clauses,
165 mlir::omp::LoopRelatedClauseOps &result,
166 llvm::SmallVectorImpl<const semantics::Symbol *> &iv);
167
168} // namespace omp
169} // namespace lower
170} // namespace Fortran
171
172#endif // FORTRAN_LOWER_OPENMPUTILS_H
Definition: AbstractConverter.h:85
Definition: StatementContext.h:46
Definition: semantics.h:67
Definition: symbol.h:778
Definition: OpenACC.h:20
Definition: bit-population-count.h:20
Definition: AbstractConverter.h:34
Definition: PFTBuilder.h:221