13#ifndef FORTRAN_LOWER_REDUCTIONPROCESSOR_H
14#define FORTRAN_LOWER_REDUCTIONPROCESSOR_H
16#include "flang/Lower/OpenMP/Clauses.h"
17#include "flang/Optimizer/Builder/FIRBuilder.h"
18#include "flang/Optimizer/Dialect/FIRType.h"
19#include "flang/Parser/parse-tree.h"
20#include "flang/Semantics/symbol.h"
21#include "flang/Semantics/type.h"
22#include "mlir/IR/Location.h"
23#include "mlir/IR/Types.h"
27class DeclareReductionOp;
49 using GenInitValueCBTy = std::function<mlir::Value(
51 mlir::Value ompOrig, mlir::Value ompPriv)>;
52 using GenCombinerCBTy = std::function<void(
54 mlir::Value op1, mlir::Value op2,
bool isByRef)>;
57 enum ReductionIdentifier {
74 static bool doReductionByRef(mlir::Type reductionType);
75 static bool doReductionByRef(mlir::Value reductionVar);
77 static ReductionIdentifier
78 getReductionType(
const omp::clause::ProcedureDesignator &pd);
80 static ReductionIdentifier
81 getReductionType(omp::clause::DefinedOperator::IntrinsicOperator intrinsicOp);
88 static parser::DefinedOperator::IntrinsicOperator
91 static ReductionIdentifier
92 getReductionType(
const fir::ReduceOperationEnum &pd);
95 supportedIntrinsicProcReduction(
const omp::clause::ProcedureDesignator &pd);
102 const omp::clause::ProcedureDesignator &reductionIntrinsic,
105 static const semantics::SourceName
108 static const semantics::SourceName
109 getRealName(
const omp::clause::ProcedureDesignator &pd);
111 static std::string getReductionName(llvm::StringRef name,
113 mlir::Type ty,
bool isByRef);
115 static std::string getReductionName(ReductionIdentifier redId,
117 mlir::Type ty,
bool isByRef);
131 mlir::Type reductionType,
bool isByRef);
140 static mlir::Value getReductionInitValue(mlir::Location loc, mlir::Type type,
141 ReductionIdentifier redId,
144 template <
typename FloatOp,
typename IntegerOp>
146 mlir::Type type, mlir::Location loc,
147 mlir::Value op1, mlir::Value op2);
148 template <
typename FloatOp,
typename IntegerOp,
typename ComplexOp>
150 mlir::Type type, mlir::Location loc,
151 mlir::Value op1, mlir::Value op2);
155 ReductionIdentifier redId,
156 mlir::Type type, mlir::Value op1,
161 template <
typename DeclareRedType>
164 mlir::Type type, mlir::Location loc,
bool isByRef,
165 GenCombinerCBTy genCombinerCB, GenInitValueCBTy genInitValueCB,
172 template <
typename OpType>
174 llvm::StringRef reductionOpName,
175 const ReductionIdentifier redId,
176 mlir::Type type, mlir::Location loc,
187 template <
typename OpType,
typename RedOperatorListTy>
190 const RedOperatorListTy &redOperatorList,
196 llvm::DenseMap<const semantics::Symbol *, mlir::Value>
197 *reductionVarCache =
nullptr);
200template <
typename FloatOp,
typename IntegerOp>
203 mlir::Type type, mlir::Location loc,
204 mlir::Value op1, mlir::Value op2) {
205 type = fir::unwrapRefType(type);
206 assert(type.isIntOrIndexOrFloat() &&
207 "only integer, float and complex types are currently supported");
208 if (type.isIntOrIndex())
209 return IntegerOp::create(builder, loc, op1, op2);
210 return FloatOp::create(builder, loc, op1, op2);
213template <
typename FloatOp,
typename IntegerOp,
typename ComplexOp>
216 mlir::Type type, mlir::Location loc,
217 mlir::Value op1, mlir::Value op2) {
219 "only integer, float and complex types are currently supported");
220 if (type.isIntOrIndex())
221 return IntegerOp::create(builder, loc, op1, op2);
223 return FloatOp::create(builder, loc, op1, op2);
224 return ComplexOp::create(builder, loc, op1, op2);
Definition AbstractConverter.h:87
Definition ReductionProcessor.h:45
static std::string getScopedUserReductionName(AbstractConverter &converter, const semantics::Symbol &reductionSymbol, mlir::Type reductionType, bool isByRef)
Definition ReductionProcessor.cpp:280
static int getOperationIdentity(ReductionIdentifier redId, mlir::Location loc)
Definition ReductionProcessor.cpp:1464
static OpType createDeclareReduction(AbstractConverter &builder, llvm::StringRef reductionOpName, const ReductionIdentifier redId, mlir::Type type, mlir::Location loc, bool isByRef)
Definition ReductionProcessor.cpp:710
static bool processReductionArguments(mlir::Location currentLocation, lower::AbstractConverter &converter, const RedOperatorListTy &redOperatorList, llvm::SmallVectorImpl< mlir::Value > &reductionVars, llvm::SmallVectorImpl< bool > &reduceVarByRef, llvm::SmallVectorImpl< mlir::Attribute > &reductionDeclSymbols, const llvm::SmallVectorImpl< const semantics::Symbol * > &reductionSymbols, semantics::SemanticsContext *semaCtx=nullptr, llvm::DenseMap< const semantics::Symbol *, mlir::Value > *reductionVarCache=nullptr)
Definition ReductionProcessor.cpp:915
static parser::DefinedOperator::IntrinsicOperator toParserIntrinsicOperator(omp::clause::DefinedOperator::IntrinsicOperator op)
Definition ReductionProcessor.cpp:129
static const semantics::Symbol * findUserDefinedReductionForIntrinsic(const semantics::Scope &scope, const omp::clause::ProcedureDesignator &reductionIntrinsic, const semantics::DeclTypeSpec *type)
Definition ReductionProcessor.cpp:199
static DeclareRedType createDeclareReductionHelper(AbstractConverter &converter, llvm::StringRef reductionOpName, mlir::Type type, mlir::Location loc, bool isByRef, GenCombinerCBTy genCombinerCB, GenInitValueCBTy genInitValueCB, const semantics::Symbol *sym=nullptr)
Definition ReductionProcessor.cpp:648
Definition semantics.h:67
Definition FIRBuilder.h:66
Definition KindMapping.h:48
Definition ParserActions.h:24
Definition bit-population-count.h:20
bool isa_complex(mlir::Type t)
Is t a floating point complex type?
Definition FIRType.h:221
bool isa_real(mlir::Type t)
Is t a real type?
Definition FIRType.h:200
Definition AbstractConverter.h:32