MLIR  16.0.0git
Functions
SCFToOpenMP.cpp File Reference
#include "mlir/Conversion/SCFToOpenMP/SCFToOpenMP.h"
#include "../PassDetail.h"
#include "mlir/Analysis/SliceAnalysis.h"
#include "mlir/Dialect/Affine/Analysis/LoopAnalysis.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.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/Transforms/DialectConversion.h"
+ Include dependency graph for SCFToOpenMP.cpp:

Go to the source code of this file.

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...
 

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

References mlir::Block::back(), mlir::OpBuilder::create(), mlir::OpBuilder::createBlock(), mlir::LLVM::LLVMPointerType::get(), 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 180 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

◆ fltSemanticsForType()

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

Returns the float semantics for the given float type.

Definition at line 133 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 72 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 36 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 151 of file SCFToOpenMP.cpp.

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

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

References mlir::Type::cast().

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

References mlir::Type::cast().

Referenced by declareReduction().