MLIR  16.0.0git
Functions
Utils.cpp File Reference
#include "mlir/Dialect/SCF/Utils/Utils.h"
#include "mlir/Analysis/SliceAnalysis.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Support/MathExtras.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
+ Include dependency graph for Utils.cpp:

Go to the source code of this file.

Functions

static Value ceilDivPositive (OpBuilder &builder, Location loc, Value dividend, int64_t divisor)
 
static Value ceilDivPositive (OpBuilder &builder, Location loc, Value dividend, Value divisor)
 
static void replaceIterArgsAndYieldResults (scf::ForOp forOp)
 Helper to replace uses of loop carried values (iter_args) and loop yield values while promoting single iteration scf.for ops. More...
 
static void generateUnrolledLoop (Block *loopBodyBlock, Value forOpIV, uint64_t unrollFactor, function_ref< Value(unsigned, Value, OpBuilder)> ivRemapFn, function_ref< void(unsigned, Operation *, OpBuilder)> annotateFn, ValueRange iterArgs, ValueRange yieldedValues)
 Generates unrolled copies of scf::ForOp 'loopBodyBlock', with associated 'forOpIV' by 'unrollFactor', calling 'ivRemapFn' to remap 'forOpIV' for each unrolled body. More...
 
static LoopParams normalizeLoop (OpBuilder &boundsBuilder, OpBuilder &insideLoopBuilder, Location loc, Value lowerBound, Value upperBound, Value step, Value inductionVar)
 Return the new lower bound, upper bound, and step in that order. More...
 
static void normalizeLoop (scf::ForOp loop, scf::ForOp outer, scf::ForOp inner)
 Transform a loop with a strictly positive step for i = lb to ub step s into a 0-based loop with step 1 for ii = 0 to ceildiv(ub - lb, s) step 1 { i = ii * s + lb Insert the induction variable remapping in the body of inner, which is expected to be either loop or another loop perfectly nested under loop. More...
 
static LogicalResult hoistOpsBetween (scf::ForOp outer, scf::ForOp inner)
 
static LogicalResult tryIsolateBands (const TileLoops &tileLoops)
 
template<typename T >
static void getPerfectlyNestedLoopsImpl (SmallVectorImpl< T > &forOps, T rootForOp, unsigned maxLoops=std::numeric_limits< unsigned >::max())
 Collect perfectly nested loops starting from rootForOps. More...
 
static Loops stripmineSink (scf::ForOp forOp, Value factor, ArrayRef< scf::ForOp > targets)
 
template<typename SizeType >
static scf::ForOp stripmineSink (scf::ForOp forOp, SizeType factor, scf::ForOp target)
 

Function Documentation

◆ ceilDivPositive() [1/2]

static Value ceilDivPositive ( OpBuilder builder,
Location  loc,
Value  dividend,
int64_t  divisor 
)
static

◆ ceilDivPositive() [2/2]

static Value ceilDivPositive ( OpBuilder builder,
Location  loc,
Value  dividend,
Value  divisor 
)
static

◆ generateUnrolledLoop()

static void generateUnrolledLoop ( Block loopBodyBlock,
Value  forOpIV,
uint64_t  unrollFactor,
function_ref< Value(unsigned, Value, OpBuilder)>  ivRemapFn,
function_ref< void(unsigned, Operation *, OpBuilder)>  annotateFn,
ValueRange  iterArgs,
ValueRange  yieldedValues 
)
static

Generates unrolled copies of scf::ForOp 'loopBodyBlock', with associated 'forOpIV' by 'unrollFactor', calling 'ivRemapFn' to remap 'forOpIV' for each unrolled body.

If specified, annotates the Ops in each unrolled iteration using annotateFn.

Definition at line 413 of file Utils.cpp.

References mlir::OpBuilder::atBlockTerminator(), mlir::Block::begin(), mlir::Operation::clone(), mlir::Block::end(), mlir::Block::getTerminator(), mlir::BlockAndValueMapping::lookup(), mlir::BlockAndValueMapping::map(), mlir::Operation::setOperands(), and mlir::Value::use_empty().

Referenced by mlir::loopUnrollByFactor().

◆ getPerfectlyNestedLoopsImpl()

template<typename T >
static void getPerfectlyNestedLoopsImpl ( SmallVectorImpl< T > &  forOps,
rootForOp,
unsigned  maxLoops = std::numeric_limits<unsigned>::max() 
)
static

Collect perfectly nested loops starting from rootForOps.

Loops are perfectly nested if each loop is the first and only non-terminator operation in the parent loop. Collect at most maxLoops loops and append them to forOps.

Definition at line 867 of file Utils.cpp.

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

Referenced by mlir::extractFixedOuterLoops(), mlir::getPerfectlyNestedLoops(), and mlir::tilePerfectlyNested().

◆ hoistOpsBetween()

static LogicalResult hoistOpsBetween ( scf::ForOp  outer,
scf::ForOp  inner 
)
static

◆ normalizeLoop() [1/2]

static LoopParams normalizeLoop ( OpBuilder boundsBuilder,
OpBuilder insideLoopBuilder,
Location  loc,
Value  lowerBound,
Value  upperBound,
Value  step,
Value  inductionVar 
)
static

Return the new lower bound, upper bound, and step in that order.

Insert any additional bounds calculations before the given builder and any additional conversion back to the original loop induction value inside the given Block.

Definition at line 589 of file Utils.cpp.

References mlir::OpBuilder::create(), mlir::Value::getDefiningOp(), and mlir::Value::replaceAllUsesExcept().

Referenced by mlir::coalesceLoops(), mlir::collapseParallelLoops(), and normalizeLoop().

◆ normalizeLoop() [2/2]

static void normalizeLoop ( scf::ForOp  loop,
scf::ForOp  outer,
scf::ForOp  inner 
)
static

Transform a loop with a strictly positive step for i = lb to ub step s into a 0-based loop with step 1 for ii = 0 to ceildiv(ub - lb, s) step 1 { i = ii * s + lb Insert the induction variable remapping in the body of inner, which is expected to be either loop or another loop perfectly nested under loop.

Insert the definition of new bounds immediate before outer, which is expected to be either loop or its parent in the loop nest.

Definition at line 647 of file Utils.cpp.

References mlir::OpBuilder::atBlockBegin(), and normalizeLoop().

◆ replaceIterArgsAndYieldResults()

static void replaceIterArgsAndYieldResults ( scf::ForOp  forOp)
static

Helper to replace uses of loop carried values (iter_args) and loop yield values while promoting single iteration scf.for ops.

Definition at line 367 of file Utils.cpp.

Referenced by mlir::promoteIfSingleIteration().

◆ stripmineSink() [1/2]

template<typename SizeType >
static scf::ForOp stripmineSink ( scf::ForOp  forOp,
SizeType  factor,
scf::ForOp  target 
)
static

Definition at line 921 of file Utils.cpp.

◆ stripmineSink() [2/2]

static Loops stripmineSink ( scf::ForOp  forOp,
Value  factor,
ArrayRef< scf::ForOp >  targets 
)
static

◆ tryIsolateBands()

static LogicalResult tryIsolateBands ( const TileLoops tileLoops)
static