MLIR  15.0.0git
Functions | Variables
LoopSpecialization.cpp File Reference
#include "PassDetail.h"
#include "mlir/Dialect/Affine/Analysis/AffineStructures.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/SCF/Transforms/Passes.h"
#include "mlir/Dialect/SCF/Transforms/Transforms.h"
#include "mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/ADT/DenseMap.h"
+ Include dependency graph for LoopSpecialization.cpp:

Go to the source code of this file.

Functions

static void specializeParallelLoopForUnrolling (ParallelOp op)
 Rewrite a parallel loop with bounds defined by an affine.min with a constant into 2 loops after checking if the bounds are equal to that constant. More...
 
static void specializeForLoopForUnrolling (ForOp op)
 Rewrite a for loop with bounds defined by an affine.min with a constant into 2 loops after checking if the bounds are equal to that constant. More...
 
static LogicalResult peelForLoop (RewriterBase &b, ForOp forOp, ForOp &partialIteration, Value &splitBound)
 Rewrite a for loop with bounds/step that potentially do not divide evenly into a for loop where the step divides the iteration space evenly, followed by an scf.if for the last (partial) iteration (if any). More...
 
template<typename OpTy , bool IsMin>
static void rewriteAffineOpAfterPeeling (RewriterBase &rewriter, ForOp forOp, ForOp partialIteration, Value previousUb)
 

Variables

static constexpr char kPeeledLoopLabel [] = "__peeled_loop__"
 
static constexpr char kPartialIterationLabel [] = "__partial_iteration__"
 

Function Documentation

◆ peelForLoop()

static LogicalResult peelForLoop ( RewriterBase b,
ForOp  forOp,
ForOp &  partialIteration,
Value splitBound 
)
static

Rewrite a for loop with bounds/step that potentially do not divide evenly into a for loop where the step divides the iteration space evenly, followed by an scf.if for the last (partial) iteration (if any).

This function rewrites the given scf.for loop in-place and creates a new scf.if operation for the last iteration. It replaces all uses of the unpeeled loop with the results of the newly generated scf.if.

The newly generated scf.if operation is returned via ifOp. The boundary at which the loop is split (new upper bound) is returned via splitBound. The return value indicates whether the loop was rewritten or not.

Definition at line 111 of file LoopSpecialization.cpp.

References mlir::bindSymbols(), mlir::OpBuilder::clone(), mlir::OpBuilder::createOrFold(), mlir::failure(), mlir::AffineMap::get(), mlir::getConstantIntValue(), mlir::Builder::getContext(), mlir::OpBuilder::setInsertionPoint(), mlir::OpBuilder::setInsertionPointAfter(), mlir::success(), and mlir::RewriterBase::updateRootInPlace().

Referenced by rewriteAffineOpAfterPeeling().

◆ rewriteAffineOpAfterPeeling()

template<typename OpTy , bool IsMin>
static void rewriteAffineOpAfterPeeling ( RewriterBase rewriter,
ForOp  forOp,
ForOp  partialIteration,
Value  previousUb 
)
static

◆ specializeForLoopForUnrolling()

static void specializeForLoopForUnrolling ( ForOp  op)
static

Rewrite a for loop with bounds defined by an affine.min with a constant into 2 loops after checking if the bounds are equal to that constant.

This is beneficial if the loop will almost always have the constant bound and that version can be fully unrolled and vectorized.

Definition at line 75 of file LoopSpecialization.cpp.

References mlir::Operation::clone(), mlir::sparse_tensor::constantIndex(), mlir::OpBuilder::create(), mlir::Value::dyn_cast(), mlir::Operation::erase(), mlir::BlockAndValueMapping::map(), max(), and min().

◆ specializeParallelLoopForUnrolling()

static void specializeParallelLoopForUnrolling ( ParallelOp  op)
static

Rewrite a parallel loop with bounds defined by an affine.min with a constant into 2 loops after checking if the bounds are equal to that constant.

This is beneficial if the loop will almost always have the constant bound and that version can be fully unrolled and vectorized.

Definition at line 37 of file LoopSpecialization.cpp.

References mlir::Operation::clone(), mlir::sparse_tensor::constantIndex(), mlir::OpBuilder::create(), mlir::Value::dyn_cast(), mlir::Operation::erase(), mlir::BlockAndValueMapping::map(), max(), and min().

Variable Documentation

◆ kPartialIterationLabel

constexpr char kPartialIterationLabel[] = "__partial_iteration__"
static

Definition at line 193 of file LoopSpecialization.cpp.

◆ kPeeledLoopLabel

constexpr char kPeeledLoopLabel[] = "__peeled_loop__"
static

Definition at line 192 of file LoopSpecialization.cpp.