MLIR 22.0.0git
Utils.cpp File Reference
#include "mlir/Dialect/SCF/Utils/Utils.h"
#include "mlir/Analysis/SliceAnalysis.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/DebugLog.h"
#include <cstdint>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "scf-utils"

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 bool areInnerBoundsInvariant (scf::ForOp forOp)
 Check if bounds of all inner loops are defined outside of forOp and return false if not.
static Range emitNormalizedLoopBoundsForIndexType (RewriterBase &rewriter, Location loc, OpFoldResult lb, OpFoldResult ub, OpFoldResult step)
static void denormalizeInductionVariableForIndexType (RewriterBase &rewriter, Location loc, Value normalizedIv, OpFoldResult origLb, OpFoldResult origStep)
static OpFoldResult getProductOfIndexes (RewriterBase &rewriter, Location loc, ArrayRef< OpFoldResult > values)
static Value getProductOfIntsOrIndexes (RewriterBase &rewriter, Location loc, ArrayRef< Value > values)
 Helper function to multiply a sequence of values.
static std::pair< SmallVector< Value >, SmallPtrSet< Operation *, 2 > > delinearizeInductionVariable (RewriterBase &rewriter, Location loc, Value linearizedIv, ArrayRef< Value > ubs)
 For each original loop, the value of the induction variable can be obtained by dividing the induction variable of the linearized loop by the total number of iterations of the loops nested in it modulo the number of iterations in this loop (remove the values related to the outer loops): iv_i = floordiv(iv_linear, product-of-loop-ranges-until-i) mod range_i.
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.
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)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "scf-utils"

Definition at line 33 of file Utils.cpp.

Function Documentation

◆ areInnerBoundsInvariant()

bool areInnerBoundsInvariant ( scf::ForOp forOp)
static

Check if bounds of all inner loops are defined outside of forOp and return false if not.

Definition at line 510 of file Utils.cpp.

References mlir::WalkResult::advance(), and mlir::WalkResult::interrupt().

Referenced by mlir::loopUnrollJamByFactor().

◆ ceilDivPositive() [1/2]

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

◆ ceilDivPositive() [2/2]

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

◆ delinearizeInductionVariable()

std::pair< SmallVector< Value >, SmallPtrSet< Operation *, 2 > > delinearizeInductionVariable ( RewriterBase & rewriter,
Location loc,
Value linearizedIv,
ArrayRef< Value > ubs )
static

For each original loop, the value of the induction variable can be obtained by dividing the induction variable of the linearized loop by the total number of iterations of the loops nested in it modulo the number of iterations in this loop (remove the values related to the outer loops): iv_i = floordiv(iv_linear, product-of-loop-ranges-until-i) mod range_i.

Compute these iteratively from the innermost loop by creating a "running quotient" of division by the range.

Definition at line 854 of file Utils.cpp.

References mlir::getConstantIntValue(), mlir::Value::getDefiningOp(), mlir::Operation::getResults(), mlir::Value::getType(), mlir::Builder::getZeroAttr(), and mlir::Type::isIndex().

Referenced by mlir::coalesceLoops().

◆ denormalizeInductionVariableForIndexType()

◆ emitNormalizedLoopBoundsForIndexType()

◆ getPerfectlyNestedLoopsImpl()

template<typename T>
void getPerfectlyNestedLoopsImpl ( SmallVectorImpl< T > & forOps,
T 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 1227 of file Utils.cpp.

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

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

◆ getProductOfIndexes()

◆ getProductOfIntsOrIndexes()

Value getProductOfIntsOrIndexes ( RewriterBase & rewriter,
Location loc,
ArrayRef< Value > values )
static

◆ hoistOpsBetween()

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

Definition at line 1161 of file Utils.cpp.

References mlir::getForwardSlice(), mlir::isMemoryEffectFree(), options, and success().

Referenced by tryIsolateBands().

◆ stripmineSink() [1/2]

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

Definition at line 1282 of file Utils.cpp.

References stripmineSink(), and target.

◆ stripmineSink() [2/2]

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

Definition at line 1242 of file Utils.cpp.

References mlir::OpBuilder::atBlockTerminator(), b, and mlir::replaceAllUsesInRegionWith().

Referenced by stripmineSink(), and mlir::tile().

◆ tryIsolateBands()

LogicalResult tryIsolateBands ( const TileLoops & tileLoops)
static

Definition at line 1205 of file Utils.cpp.

References hoistOpsBetween(), and success().

Referenced by mlir::extractFixedOuterLoops().