13#ifndef MLIR_DIALECT_AFFINE_UTILS_H
14#define MLIR_DIALECT_AFFINE_UTILS_H
35class ReinterpretCastOp;
41class AffineParallelOp;
54 AffineParallelOp *resOp =
nullptr);
93struct VectorizationStrategy {
103 ReductionLoopMap reductionLoops;
109void affineScalarReplace(func::FuncOp f, DominanceInfo &domInfo,
110 PostDominanceInfo &postDomInfo,
111 AliasAnalysis &analysis);
120void vectorizeAffineLoops(
123 ArrayRef<int64_t> vectorSizes, ArrayRef<int64_t> fastestVaryingPattern,
163 const VectorizationStrategy &strategy);
168void normalizeAffineParallel(AffineParallelOp op);
177LogicalResult normalizeAffineFor(AffineForOp op,
178 bool promoteSingleIter =
false);
186AffineExpr substWithMin(AffineExpr e, AffineExpr dim, AffineExpr
min,
187 AffineExpr
max,
bool positivePath =
true);
228LogicalResult replaceAllMemRefUsesWith(
229 Value oldMemRef, Value newMemRef, ArrayRef<Value> extraIndices = {},
230 AffineMap indexRemap = AffineMap(), ArrayRef<Value> extraOperands = {},
231 ArrayRef<Value> symbolOperands = {},
232 llvm::function_ref<bool(Operation *)> userFilterFn =
nullptr,
233 bool allowNonDereferencingOps =
false,
bool replaceInDeallocOp =
false);
239LogicalResult replaceAllMemRefUsesWith(Value oldMemRef, Value newMemRef,
241 ArrayRef<Value> extraIndices = {},
242 AffineMap indexRemap = AffineMap(),
243 ArrayRef<Value> extraOperands = {},
244 ArrayRef<Value> symbolOperands = {},
245 bool allowNonDereferencingOps =
false);
250template <
typename AllocLikeOp>
251LogicalResult normalizeMemRef(AllocLikeOp op);
252extern template LogicalResult
254extern template LogicalResult
256LogicalResult normalizeMemRef(memref::ReinterpretCastOp op);
262MemRefType normalizeMemRefType(MemRefType memrefType);
293void createAffineComputationSlice(Operation *opInst,
294 SmallVectorImpl<AffineApplyOp> *sliceOps);
298Value expandAffineExpr(OpBuilder &builder, Location loc, AffineExpr expr,
303std::optional<SmallVector<Value, 8>> expandAffineMap(OpBuilder &builder,
315DivModValue getDivMod(OpBuilder &
b, Location loc, Value
lhs, Value
rhs);
322FailureOr<SmallVector<Value>> delinearizeIndex(OpBuilder &
b, Location loc,
324 ArrayRef<Value> basis,
325 bool hasOuterBound =
true);
327FailureOr<SmallVector<Value>> delinearizeIndex(OpBuilder &
b, Location loc,
329 ArrayRef<OpFoldResult> basis,
330 bool hasOuterBound =
true);
336 ArrayRef<OpFoldResult> basis,
337 ImplicitLocOpBuilder &builder);
340 ArrayRef<OpFoldResult> multiIndex,
341 ArrayRef<OpFoldResult> basis);
350template <
typename EffectType,
typename T>
352 llvm::function_ref<
bool(Value, Value)>
mayAlias);
static AffineIfOp hoistAffineIfOp(AffineIfOp ifOp, Operation *hoistOverOp)
A helper for the mechanics of mlir::hoistAffineIfOp.
template LogicalResult mlir::affine::normalizeMemRef< memref::AllocaOp >(memref::AllocaOp op)
template LogicalResult mlir::affine::normalizeMemRef< memref::AllocOp >(memref::AllocOp op)
static bool mayAlias(Value first, Value second)
Returns true if two values may be referencing aliasing memory.
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
Base type for affine expression.
static AffineMap getMultiDimIdentityMap(unsigned numDims, MLIRContext *context)
Returns an AffineMap with 'numDims' identity result dim exprs.
A class for computing basic dominance information.
ImplicitLocOpBuilder maintains a 'current location', allowing use of the create<> method without spec...
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
This class represents a single result from folding an operation.
Operation is the basic unit of execution within MLIR.
A class for computing basic postdominance information.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
DenseMap< Operation *, SmallVector< LoopReduction, 2 > > ReductionLoopMap
LogicalResult affineParallelize(AffineForOp forOp, ArrayRef< LoopReduction > parallelReductions={}, AffineParallelOp *resOp=nullptr)
Replaces a parallel affine.for op with a 1-d affine.parallel op.
OpFoldResult makeComposedFoldedAffineMax(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Constructs an AffineMinOp that computes a maximum across the results of applying map to operands,...
OpFoldResult makeComposedFoldedAffineApply(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands, bool composeAffineMin=false)
Constructs an AffineApplyOp that applies map to operands after composing the map with the maps of any...
OpFoldResult makeComposedFoldedAffineMin(OpBuilder &b, Location loc, AffineMap map, ArrayRef< OpFoldResult > operands)
Constructs an AffineMinOp that computes a minimum across the results of applying map to operands,...
bool hasNoInterveningEffect(Operation *start, T memOp, llvm::function_ref< bool(Value, Value)> mayAlias)
Hoists out affine.if/else to as high as possible, i.e., past all invariant affine....
Value linearizeIndex(ValueRange indices, ArrayRef< int64_t > strides, int64_t offset, Type integerType, Location loc, OpBuilder &builder)
Generates IR to perform index linearization with the given indices and their corresponding strides,...
Include the generated interface declarations.
llvm::DenseMapInfo< T, Enable > DenseMapInfo
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
OpFoldResult add(AffineValueExpr lhs, AffineValueExpr rhs)
OpFoldResult min(ArrayRef< OpFoldResult > vals)
OpFoldResult ceil(AffineValueExpr lhs, AffineValueExpr rhs)
OpFoldResult max(ArrayRef< OpFoldResult > vals)
AffineBuilder(OpBuilder &b, Location loc)
OpFoldResult floor(AffineValueExpr lhs, AffineValueExpr rhs)
OpFoldResult sub(AffineValueExpr lhs, AffineValueExpr rhs)
OpFoldResult mul(AffineValueExpr lhs, AffineValueExpr rhs)
AffineValueExpr(AffineExpr e)
AffineValueExpr bind(Value v)
AffineValueExpr bind(OpFoldResult v)