This patch updates Flang lowering to use the new set of OpenMP clause operand structures and their groupings into directive-specific sets of clause operands. It simplifies the passing of information from the clause processor and the creation of operations. The `DataSharingProcessor` is slightly modified to not hold delayed privatization state. Instead, optional arguments are added to `processStep1` which are only passed when delayed privatization is used. This enables using the clause operand structure for `private` and removes the need for the ad-hoc `DelayedPrivatizationInfo` structure. The processing of the `schedule` clause is updated to process the `chunk` modifier rather than requiring two separate calls to the `ClauseProcessor`. Lowering of a block-associated `ordered` construct is updated to emit a TODO error if the `simd` clause is specified, since it is not currently supported by the `ClauseProcessor` or later compilation stages. Removed processing of `schedule` from `omp.simdloop`, as it doesn't apply to `simd` constructs.
117 lines
4.8 KiB
C++
117 lines
4.8 KiB
C++
//===-- Lower/OpenMP/DataSharingProcessor.h ---------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#ifndef FORTRAN_LOWER_DATASHARINGPROCESSOR_H
|
|
#define FORTRAN_LOWER_DATASHARINGPROCESSOR_H
|
|
|
|
#include "Clauses.h"
|
|
#include "flang/Lower/AbstractConverter.h"
|
|
#include "flang/Lower/OpenMP.h"
|
|
#include "flang/Optimizer/Builder/FIRBuilder.h"
|
|
#include "flang/Parser/parse-tree.h"
|
|
#include "flang/Semantics/symbol.h"
|
|
|
|
namespace mlir {
|
|
namespace omp {
|
|
struct PrivateClauseOps;
|
|
} // namespace omp
|
|
} // namespace mlir
|
|
|
|
namespace Fortran {
|
|
namespace lower {
|
|
namespace omp {
|
|
|
|
class DataSharingProcessor {
|
|
private:
|
|
bool hasLastPrivateOp;
|
|
mlir::OpBuilder::InsertPoint lastPrivIP;
|
|
mlir::OpBuilder::InsertPoint insPt;
|
|
mlir::Value loopIV;
|
|
// Symbols in private, firstprivate, and/or lastprivate clauses.
|
|
llvm::SetVector<const Fortran::semantics::Symbol *> privatizedSymbols;
|
|
llvm::SetVector<const Fortran::semantics::Symbol *> defaultSymbols;
|
|
llvm::SetVector<const Fortran::semantics::Symbol *> symbolsInNestedRegions;
|
|
llvm::SetVector<const Fortran::semantics::Symbol *> symbolsInParentRegions;
|
|
Fortran::lower::AbstractConverter &converter;
|
|
fir::FirOpBuilder &firOpBuilder;
|
|
omp::List<omp::Clause> clauses;
|
|
Fortran::lower::pft::Evaluation &eval;
|
|
bool useDelayedPrivatization;
|
|
Fortran::lower::SymMap *symTable;
|
|
|
|
bool needBarrier();
|
|
void collectSymbols(Fortran::semantics::Symbol::Flag flag);
|
|
void collectOmpObjectListSymbol(
|
|
const omp::ObjectList &objects,
|
|
llvm::SetVector<const Fortran::semantics::Symbol *> &symbolSet);
|
|
void collectSymbolsForPrivatization();
|
|
void insertBarrier();
|
|
void collectDefaultSymbols();
|
|
void privatize(
|
|
mlir::omp::PrivateClauseOps *clauseOps,
|
|
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *> *privateSyms);
|
|
void defaultPrivatize(
|
|
mlir::omp::PrivateClauseOps *clauseOps,
|
|
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *> *privateSyms);
|
|
void doPrivatize(
|
|
const Fortran::semantics::Symbol *sym,
|
|
mlir::omp::PrivateClauseOps *clauseOps,
|
|
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *> *privateSyms);
|
|
void copyLastPrivatize(mlir::Operation *op);
|
|
void insertLastPrivateCompare(mlir::Operation *op);
|
|
void cloneSymbol(const Fortran::semantics::Symbol *sym);
|
|
void
|
|
copyFirstPrivateSymbol(const Fortran::semantics::Symbol *sym,
|
|
mlir::OpBuilder::InsertPoint *copyAssignIP = nullptr);
|
|
void copyLastPrivateSymbol(const Fortran::semantics::Symbol *sym,
|
|
mlir::OpBuilder::InsertPoint *lastPrivIP);
|
|
void insertDeallocs();
|
|
|
|
public:
|
|
DataSharingProcessor(Fortran::lower::AbstractConverter &converter,
|
|
Fortran::semantics::SemanticsContext &semaCtx,
|
|
const Fortran::parser::OmpClauseList &opClauseList,
|
|
Fortran::lower::pft::Evaluation &eval,
|
|
bool useDelayedPrivatization = false,
|
|
Fortran::lower::SymMap *symTable = nullptr)
|
|
: hasLastPrivateOp(false), converter(converter),
|
|
firOpBuilder(converter.getFirOpBuilder()),
|
|
clauses(omp::makeClauses(opClauseList, semaCtx)), eval(eval),
|
|
useDelayedPrivatization(useDelayedPrivatization), symTable(symTable) {}
|
|
|
|
// Privatisation is split into two steps.
|
|
// Step1 performs cloning of all privatisation clauses and copying for
|
|
// firstprivates. Step1 is performed at the place where process/processStep1
|
|
// is called. This is usually inside the Operation corresponding to the OpenMP
|
|
// construct, for looping constructs this is just before the Operation. The
|
|
// split into two steps was performed basically to be able to call
|
|
// privatisation for looping constructs before the operation is created since
|
|
// the bounds of the MLIR OpenMP operation can be privatised.
|
|
// Step2 performs the copying for lastprivates and requires knowledge of the
|
|
// MLIR operation to insert the last private update. Step2 adds
|
|
// dealocation code as well.
|
|
void processStep1(mlir::omp::PrivateClauseOps *clauseOps = nullptr,
|
|
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *>
|
|
*privateSyms = nullptr);
|
|
void processStep2(mlir::Operation *op, bool isLoop);
|
|
|
|
void setLoopIV(mlir::Value iv) {
|
|
assert(!loopIV && "Loop iteration variable already set");
|
|
loopIV = iv;
|
|
}
|
|
};
|
|
|
|
} // namespace omp
|
|
} // namespace lower
|
|
} // namespace Fortran
|
|
|
|
#endif // FORTRAN_LOWER_DATASHARINGPROCESSOR_H
|