MLIR  16.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"
+ Include dependency graph for SCFToOpenMP.cpp:

Go to the source code of this file.

Namespaces

 mlir
 Include the generated interface declarations.
 

Macros

#define GEN_PASS_DEF_CONVERTSCFTOOPENMP
 

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::ReductionDeclareOp createDecl (PatternRewriter &builder, SymbolTable &symbolTable, scf::ReduceOp reduce, Attribute initValue)
 Creates an OpenMP reduction declaration and inserts it into the provided symbol table. More...
 
static omp::ReductionDeclareOp addAtomicRMW (OpBuilder &builder, LLVM::AtomicBinOp atomicKind, omp::ReductionDeclareOp decl, scf::ReduceOp reduce)
 Adds an atomic reduction combiner to the given OpenMP reduction declaration using llvm.atomicrmw of the given kind. More...
 
static omp::ReductionDeclareOp declareReduction (PatternRewriter &builder, scf::ReduceOp reduce)
 Creates an OpenMP reduction declaration that corresponds to the given SCF reduction and returns it. More...
 

Macro Definition Documentation

◆ GEN_PASS_DEF_CONVERTSCFTOOPENMP

#define GEN_PASS_DEF_CONVERTSCFTOOPENMP

Definition at line 29 of file SCFToOpenMP.cpp.

Function Documentation

◆ addAtomicRMW()

static omp::ReductionDeclareOp addAtomicRMW ( OpBuilder builder,
LLVM::AtomicBinOp  atomicKind,
omp::ReductionDeclareOp  decl,
scf::ReduceOp  reduce 
)
static

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

Definition at line 217 of file SCFToOpenMP.cpp.

References mlir::Block::back(), mlir::OpBuilder::create(), mlir::OpBuilder::createBlock(), mlir::Block::getArgument(), and mlir::OpBuilder::setInsertionPointToEnd().

Referenced by declareReduction().

◆ createDecl()

static omp::ReductionDeclareOp createDecl ( PatternRewriter builder,
SymbolTable symbolTable,
scf::ReduceOp  reduce,
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 reduction combiner carried over from reduce.

Definition at line 186 of file SCFToOpenMP.cpp.

References mlir::Block::back(), mlir::OpBuilder::create(), mlir::OpBuilder::createBlock(), mlir::Region::front(), mlir::Operation::getRegion(), mlir::RewriterBase::inlineRegionBefore(), mlir::SymbolTable::insert(), mlir::RewriterBase::replaceOpWithNewOp(), mlir::OpBuilder::setInsertionPoint(), and mlir::OpBuilder::setInsertionPointToEnd().

Referenced by declareReduction().

◆ declareReduction()

static omp::ReductionDeclareOp declareReduction ( PatternRewriter builder,
scf::ReduceOp  reduce 
)
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 243 of file SCFToOpenMP.cpp.

References addAtomicRMW(), createDecl(), mlir::Block::front(), mlir::Builder::getFloatAttr(), mlir::Builder::getIntegerAttr(), mlir::Type::getIntOrFloatBitWidth(), mlir::SymbolTable::getNearestSymbolTable(), mlir::Operation::getParentOp(), max(), min(), minMaxValueForFloat(), minMaxValueForSignedInt(), minMaxValueForUnsignedInt(), 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 139 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 78 of file SCFToOpenMP.cpp.

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

◆ 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(), mlir::Value::isa(), 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 157 of file SCFToOpenMP.cpp.

References mlir::Type::cast(), fltSemanticsForType(), 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 166 of file SCFToOpenMP.cpp.

References mlir::Type::cast(), 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 176 of file SCFToOpenMP.cpp.

References mlir::Type::cast(), and min().

Referenced by declareReduction().