34class DataSharingProcessor {
39 struct OMPConstructSymbolVisitor {
41 : version(ctx.langOptions().OpenMPVersion) {}
47 void Post(
const T &) {}
51 if (isOpenMPPrivatizingConstruct(omp, version))
52 constructs.push_back(&omp);
57 if (isOpenMPPrivatizingConstruct(omp, version))
58 constructs.pop_back();
62 auto current = !constructs.empty() ? constructs.back() : ConstructPtr();
63 symDefMap.try_emplace(name.symbol, current);
67 constructs.push_back(&decl);
72 constructs.pop_back();
89 llvm::DenseMap<semantics::Symbol *, ConstructPtr> symDefMap;
94 mlir::OpBuilder::InsertPoint lastPrivIP;
97 llvm::SetVector<const semantics::Symbol *> explicitlyPrivatizedSymbols;
98 llvm::SetVector<const semantics::Symbol *> defaultSymbols;
99 llvm::SetVector<const semantics::Symbol *> allPrivatizedSymbols;
100 llvm::SetVector<const semantics::Symbol *> conditionalLastPrivatizedSymbols;
107 bool conditionalLpUsesPrivateCopy =
false;
112 omp::List<omp::Clause> clauses;
114 bool shouldCollectPreDeterminedSymbols;
115 bool useDelayedPrivatization;
116 bool forceHeapAllocationForPrivateDynamicArrays =
false;
117 llvm::SmallPtrSet<const semantics::Symbol *, 16> mightHaveReadHostSym;
119 bool isTargetPrivatization;
120 OMPConstructSymbolVisitor visitor;
123 void collectPrivatizedSymbols(
124 std::optional<semantics::Symbol::Flag> flag,
125 const llvm::SetVector<const semantics::Symbol *> &allSymbols,
126 const llvm::SetVector<const semantics::Symbol *> &symbolsInNestedRegions,
127 llvm::SetVector<const semantics::Symbol *> *symbols =
nullptr);
129 collectSymbols(semantics::Symbol::Flag flag,
130 llvm::SetVector<const semantics::Symbol *> *symbols =
nullptr);
131 void collectSymbolsInNestedRegions(
133 llvm::SetVector<const semantics::Symbol *> &symbolsInNestedRegions);
134 void collectOmpObjectListSymbol(
135 const omp::ObjectList &objects,
136 llvm::SetVector<const semantics::Symbol *> &symbolSet);
137 void collectSymbolsForPrivatization();
138 void insertBarrier(mlir::omp::PrivateClauseOps *clauseOps);
139 void collectDefaultSymbols();
140 void collectImplicitSymbols();
141 void collectPreDeterminedSymbols();
142 void collectIndirectReferences();
143 void privatize(mlir::omp::PrivateClauseOps *clauseOps,
144 std::optional<llvm::omp::Directive> dir = std::nullopt);
145 void copyLastPrivatize(mlir::Operation *op);
146 void insertLastPrivateCompare(mlir::Operation *op);
150 mlir::OpBuilder::InsertPoint *copyAssignIP =
nullptr);
152 mlir::OpBuilder::InsertPoint *lastPrivIP);
153 void insertDeallocs();
162 const List<Clause> &clauses,
164 bool shouldCollectPreDeterminedSymbols,
166 bool isTargetPrivatization =
false);
172 bool isTargetPrivatization =
false);
185 void processStep1(mlir::omp::PrivateClauseOps *clauseOps =
nullptr,
186 std::optional<llvm::omp::Directive> dir = std::nullopt);
187 void processStep2(mlir::Operation *op,
bool isLoop);
189 void pushLoopIV(mlir::Value iv) { loopIVs.push_back(iv); }
191 void setForceHeapAllocationForPrivateDynamicArrays(
bool value =
true) {
192 forceHeapAllocationForPrivateDynamicArrays = value;
195 const llvm::SetVector<const semantics::Symbol *> &
196 getAllSymbolsToPrivatize()
const {
197 return allPrivatizedSymbols;
201 return useDelayedPrivatization
202 ? allPrivatizedSymbols.getArrayRef()
207 mlir::omp::PrivateClauseOps *clauseOps,
208 std::optional<llvm::omp::Directive> dir = std::nullopt);
210 const llvm::SetVector<const semantics::Symbol *> &
211 getConditionalLastprivateSymbols()
const {
212 return conditionalLastPrivatizedSymbols;
215 void setConditionalLpUsesPrivateCopy(
bool v) {
216 conditionalLpUsesPrivateCopy = v;