MLIR  20.0.0git
Namespaces | Macros | Functions
SCFToOpenMP.cpp File Reference
#include "mlir/Conversion/SCFToOpenMP/SCFToOpenMP.h"
#include "mlir/Analysis/SliceAnalysis.h"
#include "mlir/Dialect/Affine/Analysis/LoopAnalysis.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/ImplicitLocOpBuilder.h"
#include "mlir/IR/SymbolTable.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Conversion/Passes.h.inc"

Go to the source code of this file.

Namespaces

 mlir
 Include the generated interface declarations.
 

Macros

#define GEN_PASS_DEF_CONVERTSCFTOOPENMPPASS
 

Functions

template<typename... OpTy>
static bool matchSimpleReduction (Block &block)
 Matches a block containing a "simple" reduction. More...
 
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. More...
 
static const llvm::fltSemantics & fltSemanticsForType (FloatType type)
 Returns the float semantics for the given float type. More...
 
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. More...
 
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). More...
 
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). More...
 
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. More...
 
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. More...
 
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. More...
 

Macro Definition Documentation

◆ GEN_PASS_DEF_CONVERTSCFTOOPENMPPASS

#define GEN_PASS_DEF_CONVERTSCFTOOPENMPPASS

Definition at line 29 of file SCFToOpenMP.cpp.

Function Documentation

◆ addAtomicRMW()

static 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::create(), mlir::OpBuilder::createBlock(), mlir::get(), mlir::Block::getArgument(), mlir::Builder::getContext(), mlir::Value::getLoc(), reduce(), and mlir::OpBuilder::setInsertionPointToEnd().

Referenced by declareReduction().

◆ createDecl()

static 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 187 of file SCFToOpenMP.cpp.

References mlir::OpBuilder::create(), mlir::OpBuilder::createBlock(), mlir::Value::getLoc(), mlir::Value::getType(), mlir::RewriterBase::inlineRegionBefore(), mlir::SymbolTable::insert(), reduce(), mlir::RewriterBase::replaceOpWithNewOp(), mlir::OpBuilder::setInsertionPoint(), and mlir::OpBuilder::setInsertionPointToEnd().

Referenced by declareReduction().

◆ declareReduction()

static 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(), mlir::Value::getType(), max(), min(), minMaxValueForFloat(), minMaxValueForSignedInt(), minMaxValueForUnsignedInt(), reduce(), and mlir::OpBuilder::setInsertionPoint().

◆ fltSemanticsForType()

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

Returns the float semantics for the given float type.

Definition at line 138 of file SCFToOpenMP.cpp.

References mlir::Type::isBF16(), mlir::Type::isF128(), mlir::Type::isF16(), mlir::Type::isF32(), mlir::Type::isF64(), and mlir::Type::isF80().

Referenced by minMaxValueForFloat().

◆ matchSelectReduction()

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 
)
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 77 of file SCFToOpenMP.cpp.

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

◆ matchSimpleReduction()

template<typename... OpTy>
static 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 42 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().

◆ minMaxValueForFloat()

static 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 156 of file SCFToOpenMP.cpp.

References fltSemanticsForType(), mlir::get(), and min().

Referenced by declareReduction().

◆ minMaxValueForSignedInt()

static 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 165 of file SCFToOpenMP.cpp.

References mlir::get(), and min().

Referenced by declareReduction().

◆ minMaxValueForUnsignedInt()

static 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 175 of file SCFToOpenMP.cpp.

References mlir::get(), getZero(), and min().

Referenced by declareReduction().