MLIR  19.0.0git
Namespaces | Macros | Functions | Variables
LoopSpecialization.cpp File Reference
#include "mlir/Dialect/SCF/Transforms/Passes.h"
#include "mlir/Dialect/Affine/Analysis/AffineStructures.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/SCF/IR/SCF.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/IRMapping.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/ADT/DenseMap.h"
#include "mlir/Dialect/SCF/Transforms/Passes.h.inc"

Go to the source code of this file.

Namespaces

 mlir
 Include the generated interface declarations.
 

Macros

#define GEN_PASS_DEF_SCFFORLOOPPEELING
 
#define GEN_PASS_DEF_SCFFORLOOPSPECIALIZATION
 
#define GEN_PASS_DEF_SCFPARALLELLOOPSPECIALIZATION
 

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...
 
static void rewriteAffineOpAfterPeeling (RewriterBase &rewriter, ForOp forOp, ForOp partialIteration, Value previousUb)
 

Variables

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

Macro Definition Documentation

◆ GEN_PASS_DEF_SCFFORLOOPPEELING

#define GEN_PASS_DEF_SCFFORLOOPPEELING

Definition at line 30 of file LoopSpecialization.cpp.

◆ GEN_PASS_DEF_SCFFORLOOPSPECIALIZATION

#define GEN_PASS_DEF_SCFFORLOOPSPECIALIZATION

Definition at line 31 of file LoopSpecialization.cpp.

◆ GEN_PASS_DEF_SCFPARALLELLOOPSPECIALIZATION

#define GEN_PASS_DEF_SCFPARALLELLOOPSPECIALIZATION

Definition at line 32 of file LoopSpecialization.cpp.

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 119 of file LoopSpecialization.cpp.

References mlir::bindSymbols(), mlir::OpBuilder::clone(), mlir::OpBuilder::createOrFold(), mlir::failure(), mlir::affine::fullyComposeAffineMapAndOperands(), mlir::AffineMap::get(), mlir::getConstantIntValue(), mlir::Builder::getContext(), mlir::AffineMap::getResult(), mlir::RewriterBase::modifyOpInPlace(), mlir::RewriterBase::replaceAllUsesWith(), mlir::OpBuilder::setInsertionPoint(), mlir::OpBuilder::setInsertionPointAfter(), and mlir::success().

◆ rewriteAffineOpAfterPeeling()

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 83 of file LoopSpecialization.cpp.

◆ 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 45 of file LoopSpecialization.cpp.

Variable Documentation

◆ kPartialIterationLabel

constexpr char kPartialIterationLabel[] = "__partial_iteration__"
staticconstexpr

Definition at line 251 of file LoopSpecialization.cpp.

◆ kPeeledLoopLabel

constexpr char kPeeledLoopLabel[] = "__peeled_loop__"
staticconstexpr

Definition at line 250 of file LoopSpecialization.cpp.