The main purpose of this patch is to centralize the logic for creating MLIR operation entry blocks and for binding them to the corresponding symbols. This minimizes the chances of mixing arguments up for operations having multiple entry block argument-generating clauses and prevents divergence while binding arguments. Some changes implemented to this end are: - Split into two functions the creation of the entry block, and the binding of its arguments and the corresponding Fortran symbol. This enabled a significant simplification of the lowering of composite constructs, where it's no longer necessary to manually ensure the lists of arguments and symbols refer to the same variables in the same order and also match the expected order by the `BlockArgOpenMPOpInterface`. - Removed redundant and error-prone passing of types and locations from `ClauseProcessor` methods. Instead, these are obtained from the values in the appropriate clause operands structure. This also simplifies argument lists of several lowering functions. - Access block arguments of already created MLIR operations through the `BlockArgOpenMPOpInterface` instead of directly indexing the argument list of the operation, which is not scalable as more entry block argument-generating clauses are added to an operation. - Simplified the implementation of `genParallelOp` to no longer need to define different callbacks depending on whether delayed privatization is enabled.
109 lines
3.7 KiB
C++
109 lines
3.7 KiB
C++
//===-- Lower/OpenMP/Utils.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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef FORTRAN_LOWER_OPENMPUTILS_H
|
|
#define FORTRAN_LOWER_OPENMPUTILS_H
|
|
|
|
#include "Clauses.h"
|
|
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
|
|
#include "mlir/IR/Location.h"
|
|
#include "mlir/IR/Value.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
extern llvm::cl::opt<bool> treatIndexAsSection;
|
|
extern llvm::cl::opt<bool> enableDelayedPrivatization;
|
|
extern llvm::cl::opt<bool> enableDelayedPrivatizationStaging;
|
|
|
|
namespace fir {
|
|
class FirOpBuilder;
|
|
} // namespace fir
|
|
namespace Fortran {
|
|
|
|
namespace semantics {
|
|
class Symbol;
|
|
} // namespace semantics
|
|
|
|
namespace parser {
|
|
struct OmpObject;
|
|
struct OmpObjectList;
|
|
} // namespace parser
|
|
|
|
namespace lower {
|
|
namespace pft {
|
|
struct Evaluation;
|
|
}
|
|
|
|
class AbstractConverter;
|
|
|
|
namespace omp {
|
|
|
|
using DeclareTargetCapturePair =
|
|
std::pair<mlir::omp::DeclareTargetCaptureClause, const semantics::Symbol &>;
|
|
|
|
// A small helper structure for keeping track of a component members MapInfoOp
|
|
// and index data when lowering OpenMP map clauses. Keeps track of the
|
|
// placement of the component in the derived type hierarchy it rests within,
|
|
// alongside the generated mlir::omp::MapInfoOp for the mapped component.
|
|
struct OmpMapMemberIndicesData {
|
|
// The indices representing the component members placement in its derived
|
|
// type parents hierarchy.
|
|
llvm::SmallVector<int> memberPlacementIndices;
|
|
|
|
// Placement of the member in the member vector.
|
|
mlir::omp::MapInfoOp memberMap;
|
|
};
|
|
|
|
mlir::omp::MapInfoOp
|
|
createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
|
|
mlir::Value baseAddr, mlir::Value varPtrPtr, std::string name,
|
|
mlir::ArrayRef<mlir::Value> bounds,
|
|
mlir::ArrayRef<mlir::Value> members,
|
|
mlir::DenseIntElementsAttr membersIndex, uint64_t mapType,
|
|
mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy,
|
|
bool partialMap = false);
|
|
|
|
void addChildIndexAndMapToParent(
|
|
const omp::Object &object,
|
|
std::map<const semantics::Symbol *,
|
|
llvm::SmallVector<OmpMapMemberIndicesData>> &parentMemberIndices,
|
|
mlir::omp::MapInfoOp &mapOp, semantics::SemanticsContext &semaCtx);
|
|
|
|
void insertChildMapInfoIntoParent(
|
|
lower::AbstractConverter &converter,
|
|
std::map<const semantics::Symbol *,
|
|
llvm::SmallVector<OmpMapMemberIndicesData>> &parentMemberIndices,
|
|
llvm::SmallVectorImpl<mlir::Value> &mapOperands,
|
|
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms);
|
|
|
|
mlir::Type getLoopVarType(lower::AbstractConverter &converter,
|
|
std::size_t loopVarTypeSize);
|
|
|
|
semantics::Symbol *
|
|
getIterationVariableSymbol(const lower::pft::Evaluation &eval);
|
|
|
|
void gatherFuncAndVarSyms(
|
|
const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
|
|
llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause);
|
|
|
|
int64_t getCollapseValue(const List<Clause> &clauses);
|
|
|
|
semantics::Symbol *getOmpObjectSymbol(const parser::OmpObject &ompObject);
|
|
|
|
void genObjectList(const ObjectList &objects,
|
|
lower::AbstractConverter &converter,
|
|
llvm::SmallVectorImpl<mlir::Value> &operands);
|
|
|
|
void lastprivateModifierNotSupported(const omp::clause::Lastprivate &lastp,
|
|
mlir::Location loc);
|
|
|
|
} // namespace omp
|
|
} // namespace lower
|
|
} // namespace Fortran
|
|
|
|
#endif // FORTRAN_LOWER_OPENMPUTILS_H
|