MLIR 22.0.0git
SCFToOpenMP.cpp File Reference

Go to the source code of this file.

Classes

class  mlir::impl::ConvertSCFToOpenMPPassBase< DerivedT >

Namespaces

namespace  mlir
 Include the generated interface declarations.
namespace  mlir::impl
 Attribute collections provide a dictionary-like interface.

Macros

#define GEN_PASS_DEF_CONVERTSCFTOOPENMPPASS

Functions

std::unique_ptr<::mlir::Passmlir::impl::createConvertSCFToOpenMPPass ()
std::unique_ptr<::mlir::Passmlir::impl::createConvertSCFToOpenMPPass (ConvertSCFToOpenMPPassOptions options)
std::unique_ptr<::mlir::Passmlir::createConvertSCFToOpenMPPass ()
std::unique_ptr<::mlir::Passmlir::createConvertSCFToOpenMPPass (ConvertSCFToOpenMPPassOptions options)
template<typename... OpTy>
static bool matchSimpleReduction (Block &block)
 Matches a block containing a "simple" reduction.
template<typename CompareOpTy, typename SelectOpTy, typename Predicate = decltype(std::declval<CompareOpTy>().getPredicate())>
static bool matchSelectReduction (Block &block, ArrayRef< Predicate > lessThanPredicates, ArrayRef< Predicate > greaterThanPredicates, bool &isMin)
 Matches a block containing a select-based min/max reduction.
static const llvm::fltSemantics & fltSemanticsForType (FloatType type)
 Returns the float semantics for the given float type.
static Attribute minMaxValueForFloat (Type type, bool min)
 Returns an attribute with the minimum (if min is set) or the maximum value (otherwise) for the given float type.
static Attribute minMaxValueForSignedInt (Type type, bool min)
 Returns an attribute with the signed integer minimum (if min is set) or the maximum value (otherwise) for the given integer type, regardless of its signedness semantics (only the width is considered).
static Attribute minMaxValueForUnsignedInt (Type type, bool min)
 Returns an attribute with the unsigned integer minimum (if min is set) or the maximum value (otherwise) for the given integer type, regardless of its signedness semantics (only the width is considered).
static omp::DeclareReductionOp createDecl (PatternRewriter &builder, SymbolTable &symbolTable, scf::ReduceOp reduce, int64_t reductionIndex, Attribute initValue)
 Creates an OpenMP reduction declaration and inserts it into the provided symbol table.
static omp::DeclareReductionOp addAtomicRMW (OpBuilder &builder, LLVM::AtomicBinOp atomicKind, omp::DeclareReductionOp decl, scf::ReduceOp reduce, int64_t reductionIndex)
 Adds an atomic reduction combiner to the given OpenMP reduction declaration using llvm.atomicrmw of the given kind.
static omp::DeclareReductionOp declareReduction (PatternRewriter &builder, scf::ReduceOp reduce, int64_t reductionIndex)
 Creates an OpenMP reduction declaration that corresponds to the given SCF reduction and returns it.

Macro Definition Documentation

◆ GEN_PASS_DEF_CONVERTSCFTOOPENMPPASS

#define GEN_PASS_DEF_CONVERTSCFTOOPENMPPASS

Definition at line 28 of file SCFToOpenMP.cpp.

Function Documentation

◆ addAtomicRMW()

omp::DeclareReductionOp addAtomicRMW ( OpBuilder & builder,
LLVM::AtomicBinOp atomicKind,
omp::DeclareReductionOp decl,
scf::ReduceOp reduce,
int64_t reductionIndex )
static

Adds an atomic reduction combiner to the given OpenMP reduction declaration using llvm.atomicrmw of the given kind.

Definition at line 218 of file SCFToOpenMP.cpp.

References mlir::Block::back(), mlir::OpBuilder::createBlock(), mlir::Block::getArgument(), mlir::Builder::getContext(), reduce(), and mlir::OpBuilder::setInsertionPointToEnd().

Referenced by declareReduction().

◆ createDecl()

omp::DeclareReductionOp createDecl ( PatternRewriter & builder,
SymbolTable & symbolTable,
scf::ReduceOp reduce,
int64_t reductionIndex,
Attribute initValue )
static

Creates an OpenMP reduction declaration and inserts it into the provided symbol table.

The declaration has a constant initializer with the neutral value initValue, and the reductionIndex-th reduction combiner carried over from reduce.

Definition at line 186 of file SCFToOpenMP.cpp.

References mlir::OpBuilder::createBlock(), mlir::Operation::getOperands(), mlir::RewriterBase::inlineRegionBefore(), mlir::SymbolTable::insert(), reduce(), mlir::RewriterBase::replaceOpWithNewOp(), mlir::OpBuilder::setInsertionPoint(), and mlir::OpBuilder::setInsertionPointToEnd().

Referenced by declareReduction().

◆ declareReduction()

omp::DeclareReductionOp declareReduction ( PatternRewriter & builder,
scf::ReduceOp reduce,
int64_t reductionIndex )
static

Creates an OpenMP reduction declaration that corresponds to the given SCF reduction and returns it.

Recognizes common reductions in order to identify the neutral value, necessary for the OpenMP declaration. If the reduction cannot be recognized, returns null.

Definition at line 244 of file SCFToOpenMP.cpp.

References addAtomicRMW(), createDecl(), mlir::Builder::getFloatAttr(), mlir::Builder::getIntegerAttr(), mlir::Type::getIntOrFloatBitWidth(), mlir::SymbolTable::getNearestSymbolTable(), mlir::Operation::getParentOp(), matchSelectReduction(), matchSimpleReduction(), minMaxValueForFloat(), minMaxValueForSignedInt(), minMaxValueForUnsignedInt(), reduce(), and mlir::OpBuilder::setInsertionPoint().

◆ fltSemanticsForType()

const llvm::fltSemantics & fltSemanticsForType ( FloatType type)
static

Returns the float semantics for the given float type.

Definition at line 137 of file SCFToOpenMP.cpp.

Referenced by minMaxValueForFloat().

◆ matchSelectReduction()

template<typename CompareOpTy, typename SelectOpTy, typename Predicate = decltype(std::declval<CompareOpTy>().getPredicate())>
bool matchSelectReduction ( Block & block,
ArrayRef< Predicate > lessThanPredicates,
ArrayRef< Predicate > greaterThanPredicates,
bool & isMin )
static

Matches a block containing a select-based min/max reduction.

The types of select and compare operations are provided as template arguments. The comparison predicates suitable for min and max are provided as function arguments. If a reduction is matched, ifMin will be set if the reduction compute the minimum and unset if it computes the maximum, otherwise it remains unmodified. The expected shape of the block is as follows.

^bb(arg0, arg1): %0 = CompareOpTy(<one-of-predicates>, arg0, arg1) %1 = SelectOpTy(%0, arg0, arg1) // arg0, arg1 may be swapped here. scf.reduce.return %1

Definition at line 76 of file SCFToOpenMP.cpp.

References mlir::Block::back(), mlir::Block::begin(), mlir::Block::empty(), mlir::Block::end(), mlir::Block::front(), and mlir::Block::getArguments().

Referenced by declareReduction().

◆ matchSimpleReduction()

template<typename... OpTy>
bool matchSimpleReduction ( Block & block)
static

Matches a block containing a "simple" reduction.

The expected shape of the block is as follows.

^bb(arg0, arg1): %0 = OpTy(arg0, arg1) scf.reduce.return %0

Definition at line 41 of file SCFToOpenMP.cpp.

References mlir::Block::back(), mlir::Block::begin(), mlir::Block::empty(), mlir::Block::end(), mlir::Block::front(), mlir::Block::getArguments(), mlir::Block::getNumArguments(), mlir::Operation::getOperands(), and mlir::matchReduction().

Referenced by declareReduction().

◆ minMaxValueForFloat()

Attribute minMaxValueForFloat ( Type type,
bool min )
static

Returns an attribute with the minimum (if min is set) or the maximum value (otherwise) for the given float type.

Definition at line 155 of file SCFToOpenMP.cpp.

References fltSemanticsForType(), and min().

Referenced by declareReduction().

◆ minMaxValueForSignedInt()

Attribute minMaxValueForSignedInt ( Type type,
bool min )
static

Returns an attribute with the signed integer minimum (if min is set) or the maximum value (otherwise) for the given integer type, regardless of its signedness semantics (only the width is considered).

Definition at line 164 of file SCFToOpenMP.cpp.

References min().

Referenced by declareReduction().

◆ minMaxValueForUnsignedInt()

Attribute minMaxValueForUnsignedInt ( Type type,
bool min )
static

Returns an attribute with the unsigned integer minimum (if min is set) or the maximum value (otherwise) for the given integer type, regardless of its signedness semantics (only the width is considered).

Definition at line 174 of file SCFToOpenMP.cpp.

References min().

Referenced by declareReduction().