MLIR  15.0.0git
Namespaces | Classes | Typedefs | Enumerations | Functions
mlir::bufferization Namespace Reference

Namespaces

 func_ext
 

Classes

class  AlwaysCopyAnalysisState
 This a "no analysis, always copy" AnalysisState. More...
 
class  AnalysisState
 AnalysisState provides a variety of helper functions for dealing with tensor values. More...
 
class  BufferizationAliasInfo
 The BufferizationAliasInfo class maintains a list of buffer aliases and equivalence classes to support bufferization. More...
 
struct  BufferizationOptions
 Options for BufferizableOpInterface-based bufferization. More...
 
struct  BufferizationState
 BufferizationState provides helper functions for performing bufferization rewrites and handling memref buffers. More...
 
class  BufferizeTypeConverter
 A helper type converter class that automatically populates the relevant materializations and type conversions for bufferization. More...
 
class  BufferPlacementAllocs
 A simple analysis that detects allocation operations. More...
 
class  BufferPlacementTransformationBase
 The base class for all BufferPlacement transformations. More...
 
struct  DialectAnalysisState
 Dialect-specific analysis state. More...
 
class  OneShotAnalysisState
 State for analysis-enabled bufferization. More...
 
struct  OneShotBufferizationOptions
 Options for analysis-enabled bufferization. More...
 

Typedefs

using AnchorMatchFn = std::function< bool(OpOperand &, SmallVector< Value > &)>
 A function that matches anchor OpOperands for AllocTensorOp elimination. More...
 
using RewriteFn = std::function< Value(OpBuilder &, Location, OpOperand &)>
 A function that rewrites matched anchors. More...
 
using PostAnalysisStepFn = std::function< LogicalResult(Operation *, AnalysisState &, BufferizationAliasInfo &, SmallVector< Operation * > &)>
 PostAnalysisStepFns can be registered with BufferizationOptions and are executed after the analysis, but before bufferization. More...
 
using PostAnalysisStepList = SmallVector< PostAnalysisStepFn >
 

Enumerations

enum  BufferRelation { BufferRelation::None, BufferRelation::Equivalent }
 Specify fine-grain relationship between buffers to enable more analysis. More...
 

Functions

bool isFunctionArgument (Value value)
 Return true if the given value is a BlockArgument of a func::FuncOp. More...
 
void replaceOpWithBufferizedValues (RewriterBase &rewriter, Operation *op, ValueRange values)
 Replace an op with replacement values. More...
 
Value lookupBuffer (RewriterBase &rewriter, Value tensor, const BufferizationOptions &options)
 Lookup the buffer for the given value. More...
 
template<typename OpTy , typename... Args>
OpTy replaceOpWithNewBufferizedOp (RewriterBase &rewriter, Operation *op, Args &&...args)
 Replace an op with a new op. More...
 
BaseMemRefType getMemRefType (TensorType tensorType, const BufferizationOptions &options, MemRefLayoutAttrInterface layout={}, Attribute memorySpace={})
 Return a MemRefType to which the tensorType can be bufferized. More...
 
BaseMemRefType getMemRefTypeWithFullyDynamicLayout (TensorType tensorType, Attribute memorySpace={})
 Return a MemRef type with fully dynamic layout. More...
 
BaseMemRefType getMemRefTypeWithStaticIdentityLayout (TensorType tensorType, Attribute memorySpace={})
 Return a MemRef type with a static identity layout (i.e., no layout map). More...
 
LogicalResult hoistBufferAllocations (Operation *op, const BufferizationOptions &options)
 Try to hoist all new buffer allocations until the next hoisting barrier. More...
 
LogicalResult createAllocDeallocOps (Operation *op, const BufferizationOptions &options, bool onlyLeakingAllocs=false, bool *changed=nullptr)
 Create alloc/dealloc ops as specified in the bufferization options. More...
 
FailureOr< ValuecastOrReallocMemRefValue (OpBuilder &b, Value value, MemRefType type)
 Try to cast the given ranked MemRef-typed value to the given ranked MemRef type. More...
 
LogicalResult foldToMemrefToTensorPair (RewriterBase &rewriter, ToMemrefOp toMemref, bool allowSameType=true)
 Try to fold to_memref(to_tensor(x)). More...
 
LogicalResult eliminateAllocTensors (RewriterBase &rewriter, Operation *op, bufferization::AnalysisState &state, AnchorMatchFn anchorMatchFunc, RewriteFn rewriteFunc)
 Try to eliminate AllocTensorOps inside op. More...
 
LogicalResult insertSliceAnchoredAllocTensorEliminationStep (RewriterBase &rewriter, Operation *op, bufferization::AnalysisState &state)
 Try to eliminate AllocTensorOps inside op that are anchored on an InsertSliceOp, i.e., if it is eventually inserted into another tensor (and some other conditions are met). More...
 
void populateBufferizeMaterializationLegality (ConversionTarget &target)
 Marks ops used by bufferization for type conversion materializations as "legal" in the given ConversionTarget. More...
 
void populateEliminateBufferizeMaterializationsPatterns (BufferizeTypeConverter &typeConverter, RewritePatternSet &patterns)
 Populate patterns to eliminate bufferize materializations. More...
 
LogicalResult bufferizeOp (Operation *op, const AnalysisState &analysisState)
 Bufferize op and its nested ops that implement BufferizableOpInterface. More...
 
LogicalResult bufferizeOp (Operation *op, const BufferizationOptions &options)
 Bufferize op and its nested ops that implement BufferizableOpInterface. More...
 
BufferizationOptions getPartialBufferizationOptions ()
 
LogicalResult bufferizeOp (Operation *op, BufferizationState &bufferizationState)
 Bufferize op and its nested ops that implement BufferizableOpInterface. More...
 
LogicalResult finalizeBuffers (Operation *op, const BufferizationOptions &options)
 Finalize all buffer allocations. More...
 
FailureOr< memref::GlobalOp > getGlobalFor (arith::ConstantOp constantOp, uint64_t alignment)
 
LogicalResult analyzeOp (Operation *op, OneShotAnalysisState &state)
 Analyze op and its nested ops. More...
 
LogicalResult runOneShotBufferize (Operation *op, const OneShotBufferizationOptions &options)
 Run One-Shot Bufferize on the given op: Analysis + Bufferization. More...
 
LogicalResult runOneShotModuleBufferize (ModuleOp moduleOp, bufferization::OneShotBufferizationOptions options)
 Run One-Shot Module Bufferization on the given module. More...
 
std::unique_ptr< PasscreateBufferDeallocationPass ()
 Creates an instance of the BufferDeallocation pass to free all allocated buffers. More...
 
LogicalResult deallocateBuffers (Operation *op)
 Run buffer deallocation. More...
 
std::unique_ptr< PasscreateBufferHoistingPass ()
 Creates a pass that moves allocations upwards to reduce the number of required copies that are inserted during the BufferDeallocation pass. More...
 
std::unique_ptr< PasscreateBufferLoopHoistingPass ()
 Creates a pass that moves allocations upwards out of loops. More...
 
std::unique_ptr< PasscreateBufferResultsToOutParamsPass ()
 Creates a pass that converts memref function results to out-params. More...
 
LogicalResult promoteBufferResultsToOutParams (ModuleOp module)
 Replace buffers that are returned from a function with an out parameter. More...
 
std::unique_ptr< OperationPass< func::FuncOp > > createFinalizingBufferizePass ()
 Creates a pass that finalizes a partial bufferization by removing remaining bufferization.to_tensor and bufferization.to_memref operations. More...
 
std::unique_ptr< PasscreateOneShotBufferizePass ()
 Create a pass that bufferizes all ops that implement BufferizableOpInterface with One-Shot Bufferize. More...
 
std::unique_ptr< PasscreateOneShotBufferizePass (const OneShotBufferizationOptions &options)
 Create a pass that bufferizes all ops that implement BufferizableOpInterface with One-Shot Bufferize and the specified bufferization options. More...
 
std::unique_ptr< PasscreatePromoteBuffersToStackPass (unsigned maxAllocSizeInBytes=1024, unsigned maxRankOfAllocatedMemRef=1)
 Creates a pass that promotes heap-based allocations to stack-based ones. More...
 
std::unique_ptr< PasscreatePromoteBuffersToStackPass (std::function< bool(Value)> isSmallAlloc)
 Creates a pass that promotes heap-based allocations to stack-based ones. More...
 
std::unique_ptr< PasscreateAllocTensorEliminationPass ()
 Create a pass that tries to eliminate alloc_tensor ops that are anchored on insert_slice ops. More...
 
std::unique_ptr< PasscreateBufferizationBufferizePass ()
 Create a pass that bufferizes ops from the bufferization dialect. More...
 
void registerAllocationOpInterfaceExternalModels (DialectRegistry &registry)
 Register external models for AllocationOpInterface. More...
 

Typedef Documentation

◆ AnchorMatchFn

using mlir::bufferization::AnchorMatchFn = typedef std::function<bool(OpOperand &, SmallVector<Value> &)>

A function that matches anchor OpOperands for AllocTensorOp elimination.

If an OpOperand is matched, the function should populate the SmallVector with all values that are needed during RewriteFn to produce the replacement value.

Definition at line 21 of file AllocTensorElimination.h.

◆ PostAnalysisStepFn

PostAnalysisStepFns can be registered with BufferizationOptions and are executed after the analysis, but before bufferization.

They can be used to implement custom dialect-specific optimizations. They may modify the IR, but must keep aliasInfo consistent. Newly created operations and operations that should be re-analyzed must be added to newOps.

Definition at line 30 of file OneShotAnalysis.h.

◆ PostAnalysisStepList

Definition at line 32 of file OneShotAnalysis.h.

◆ RewriteFn

using mlir::bufferization::RewriteFn = typedef std::function<Value(OpBuilder &, Location, OpOperand &)>

A function that rewrites matched anchors.

Definition at line 24 of file AllocTensorElimination.h.

Enumeration Type Documentation

◆ BufferRelation

Specify fine-grain relationship between buffers to enable more analysis.

Enumerator
None 
Equivalent 

Definition at line 333 of file BufferizableOpInterface.h.

Function Documentation

◆ analyzeOp()

LogicalResult mlir::bufferization::analyzeOp ( Operation op,
OneShotAnalysisState state 
)

◆ bufferizeOp() [1/3]

LogicalResult mlir::bufferization::bufferizeOp ( Operation op,
const AnalysisState analysisState 
)

Bufferize op and its nested ops that implement BufferizableOpInterface.

Whether buffer copies are needed or not is queried from state.

Note: If allowUnknownOps is set to false, bufferization fails when an unknown op (that does not implement BufferizableOpInterface) is found. No to_tensor/to_memref ops are inserted in that case.

Note: The layout map chosen to bufferize is the most dynamic canonical strided layout of the proper rank. This ensures compatibility with expected layouts after transformations. Combinations of memref.cast + canonicalization are responsible for clean ups.

Definition at line 330 of file Bufferize.cpp.

References mlir::bufferization::BufferizationOptions::bufferizeFunctionBoundaries, mlir::failed(), mlir::failure(), finalizeBuffers(), mlir::bufferization::AnalysisState::getOptions(), mlir::bufferization::AnalysisState::hasDialectState(), hasTensorSemantics(), mlir::bufferization::BufferizationOptions::isOpAllowed(), mlir::OpBuilder::Listener::notifyOperationInserted(), mlir::RewriterBase::notifyOperationRemoved(), options, and mlir::success().

Referenced by bufferizeOp(), populateEliminateBufferizeMaterializationsPatterns(), runOneShotBufferize(), and runOneShotModuleBufferize().

◆ bufferizeOp() [2/3]

LogicalResult mlir::bufferization::bufferizeOp ( Operation op,
const BufferizationOptions options 
)

Bufferize op and its nested ops that implement BufferizableOpInterface.

Buffers are duplicated and copied before any tensor use that bufferizes to a memory write.

Note: This function bufferizes ops without utilizing analysis results. It can be used to implement partial bufferization passes.

Definition at line 507 of file Bufferize.cpp.

References bufferizeOp().

◆ bufferizeOp() [3/3]

LogicalResult mlir::bufferization::bufferizeOp ( Operation op,
BufferizationState bufferizationState 
)

Bufferize op and its nested ops that implement BufferizableOpInterface.

Reuse an existing BufferizationState.

Note: This function overload is useful for extending the bufferization.

Check the result of bufferization. Return an error if an op was not bufferized, unless partial bufferization is allowed.

Definition at line 398 of file Bufferize.cpp.

References mlir::bufferization::BufferizationOptions::allowUnknownOps, mlir::Operation::emitError(), mlir::failed(), foldToMemrefToTensorPair(), mlir::Operation::getContext(), mlir::bufferization::BufferizationState::getOptions(), mlir::Operation::getUses(), hasTensorSemantics(), mlir::bufferization::BufferizationOptions::InferLayoutMap, isInPlace(), options, mlir::PreOrder, mlir::success(), and mlir::Operation::walk().

◆ castOrReallocMemRefValue()

FailureOr< Value > mlir::bufferization::castOrReallocMemRefValue ( OpBuilder b,
Value  value,
MemRefType  type 
)

Try to cast the given ranked MemRef-typed value to the given ranked MemRef type.

Insert a reallocation + copy if it cannot be statically guaranteed that a direct cast would be valid.

E.g., when casting from a ranked MemRef type with dynamic layout to a ranked MemRef type with static layout, it is not statically known whether the cast will succeed or not. Such memref.cast ops may fail at runtime. This function never generates such casts and conservatively inserts a copy.

This function returns failure() in case of unsupported casts. E.g., casts with differing element types or memory spaces.

Definition at line 25 of file BufferizationOps.cpp.

References mlir::Type::cast(), copy(), mlir::OpBuilder::create(), mlir::OpBuilder::createOrFold(), mlir::failed(), mlir::failure(), mlir::Value::getLoc(), mlir::getStridesAndOffset(), mlir::Value::getType(), and value.

Referenced by mlir::bufferization::BufferizeTypeConverter::BufferizeTypeConverter(), and foldToMemrefToTensorPair().

◆ createAllocDeallocOps()

LogicalResult mlir::bufferization::createAllocDeallocOps ( Operation op,
const BufferizationOptions options,
bool  onlyLeakingAllocs = false,
bool *  changed = nullptr 
)

Create alloc/dealloc ops as specified in the bufferization options.

If onlyLeakingAlloc, only those buffer allocations are processed for which no buffer deallocation can be created. changed is set to true if the IR was modified.

Definition at line 539 of file BufferizableOpInterface.cpp.

References mlir::WalkResult::advance(), mlir::bufferization::BufferizationOptions::createAlloc(), mlir::bufferization::BufferizationOptions::createDealloc(), mlir::failed(), mlir::Operation::getContext(), mlir::Block::getTerminator(), mlir::WalkResult::interrupt(), kBufferAllocationAttr, kSkipDeallocAttr, mlir::WalkResult::skip(), mlir::success(), mlir::Operation::walk(), and mlir::WalkResult::wasInterrupted().

Referenced by finalizeBuffers(), and replaceOpWithNewBufferizedOp().

◆ createAllocTensorEliminationPass()

std::unique_ptr< Pass > mlir::bufferization::createAllocTensorEliminationPass ( )

Create a pass that tries to eliminate alloc_tensor ops that are anchored on insert_slice ops.

Definition at line 270 of file AllocTensorElimination.cpp.

◆ createBufferDeallocationPass()

std::unique_ptr< Pass > mlir::bufferization::createBufferDeallocationPass ( )

Creates an instance of the BufferDeallocation pass to free all allocated buffers.

Definition at line 702 of file BufferDeallocation.cpp.

◆ createBufferHoistingPass()

std::unique_ptr< Pass > mlir::bufferization::createBufferHoistingPass ( )

Creates a pass that moves allocations upwards to reduce the number of required copies that are inserted during the BufferDeallocation pass.

Definition at line 420 of file BufferOptimizations.cpp.

◆ createBufferizationBufferizePass()

std::unique_ptr< Pass > mlir::bufferization::createBufferizationBufferizePass ( )

Create a pass that bufferizes ops from the bufferization dialect.

Definition at line 258 of file Bufferize.cpp.

◆ createBufferLoopHoistingPass()

std::unique_ptr< Pass > mlir::bufferization::createBufferLoopHoistingPass ( )

Creates a pass that moves allocations upwards out of loops.

This avoids reallocations inside of loops.

Definition at line 424 of file BufferOptimizations.cpp.

◆ createBufferResultsToOutParamsPass()

std::unique_ptr< Pass > mlir::bufferization::createBufferResultsToOutParamsPass ( )

Creates a pass that converts memref function results to out-params.

Definition at line 193 of file BufferResultsToOutParams.cpp.

◆ createFinalizingBufferizePass()

std::unique_ptr< OperationPass< func::FuncOp > > mlir::bufferization::createFinalizingBufferizePass ( )

Creates a pass that finalizes a partial bufferization by removing remaining bufferization.to_tensor and bufferization.to_memref operations.

Definition at line 272 of file Bufferize.cpp.

Referenced by mlir::sparse_tensor::buildSparseCompiler().

◆ createOneShotBufferizePass() [1/2]

std::unique_ptr< Pass > mlir::bufferization::createOneShotBufferizePass ( )

Create a pass that bufferizes all ops that implement BufferizableOpInterface with One-Shot Bufferize.

Definition at line 262 of file Bufferize.cpp.

◆ createOneShotBufferizePass() [2/2]

std::unique_ptr< Pass > mlir::bufferization::createOneShotBufferizePass ( const OneShotBufferizationOptions options)

Create a pass that bufferizes all ops that implement BufferizableOpInterface with One-Shot Bufferize and the specified bufferization options.

Definition at line 266 of file Bufferize.cpp.

References options.

◆ createPromoteBuffersToStackPass() [1/2]

std::unique_ptr< Pass > mlir::bufferization::createPromoteBuffersToStackPass ( unsigned  maxAllocSizeInBytes = 1024,
unsigned  maxRankOfAllocatedMemRef = 1 
)

Creates a pass that promotes heap-based allocations to stack-based ones.

Only buffers smaller than the provided size are promoted. Dynamic shaped buffers are promoted up to the given rank.

Definition at line 428 of file BufferOptimizations.cpp.

◆ createPromoteBuffersToStackPass() [2/2]

std::unique_ptr< Pass > mlir::bufferization::createPromoteBuffersToStackPass ( std::function< bool(Value)>  isSmallAlloc)

Creates a pass that promotes heap-based allocations to stack-based ones.

Only buffers smaller with isSmallAlloc(alloc) == true are promoted.

Definition at line 434 of file BufferOptimizations.cpp.

◆ deallocateBuffers()

LogicalResult mlir::bufferization::deallocateBuffers ( Operation op)

◆ eliminateAllocTensors()

LogicalResult mlir::bufferization::eliminateAllocTensors ( RewriterBase rewriter,
Operation op,
bufferization::AnalysisState state,
AnchorMatchFn  anchorMatchFunc,
RewriteFn  rewriteFunc 
)

Try to eliminate AllocTensorOps inside op.

  • rewriteFunc generates the replacement for the AllocTensorOp.
  • Only AllocTensorOps that are anchored on a matching OpOperand as per anchorMatchFunc are considered. "Anchored" means that there is a path on the reverse SSA use-def chain, starting from the OpOperand and always following the aliasing OpOperand, that eventually ends at a single AllocTensorOp.

    An AllocTensorOp is replaced with the result of rewriteFunc if it is anchored on a matching OpOperand. "Anchored" means that there is a path on the reverse SSA use-def chain, starting from the OpOperand and always following the aliasing OpOperand, that eventually ends at a single AllocTensorOp.

Definition at line 101 of file AllocTensorElimination.cpp.

References mlir::WalkResult::advance(), mlir::bufferization::AnalysisState::areEquivalentBufferizedValues(), mlir::Value::dyn_cast(), mlir::failure(), findValidInsertionPoint(), mlir::bufferization::AnalysisState::findValueInReverseUseDefChain(), mlir::IROperand< DerivedT, IRValueT >::get(), mlir::bufferization::AnalysisState::getAliasingOpOperand(), mlir::Value::getDefiningOp(), mlir::Value::getLoc(), mlir::Operation::getOpOperands(), mlir::bufferization::AnalysisState::isInPlace(), mlir::RewriterBase::replaceOp(), mlir::OpBuilder::setInsertionPoint(), mlir::WalkResult::skip(), mlir::Operation::walk(), and mlir::WalkResult::wasInterrupted().

Referenced by insertSliceAnchoredAllocTensorEliminationStep().

◆ finalizeBuffers()

LogicalResult mlir::bufferization::finalizeBuffers ( Operation op,
const BufferizationOptions options 
)

Finalize all buffer allocations.

  • Hoist buffer allocations as much as possible.
  • Create alloc/dealloc ops as specified by the bufferization options.

Definition at line 296 of file Bufferize.cpp.

References createAllocDeallocOps(), mlir::bufferization::BufferizationOptions::createDeallocs, deallocateBuffers(), mlir::failed(), mlir::failure(), hoistBufferAllocations(), promoteBufferResultsToOutParams(), mlir::bufferization::BufferizationOptions::promoteBufferResultsToOutParams, and mlir::success().

Referenced by bufferizeOp(), and runOneShotModuleBufferize().

◆ foldToMemrefToTensorPair()

LogicalResult mlir::bufferization::foldToMemrefToTensorPair ( RewriterBase rewriter,
ToMemrefOp  toMemref,
bool  allowSameType = true 
)

◆ getGlobalFor()

FailureOr< memref::GlobalOp > mlir::bufferization::getGlobalFor ( arith::ConstantOp  constantOp,
uint64_t  alignment 
)

◆ getMemRefType()

BaseMemRefType mlir::bufferization::getMemRefType ( TensorType  tensorType,
const BufferizationOptions options,
MemRefLayoutAttrInterface  layout = {},
Attribute  memorySpace = {} 
)

Return a MemRefType to which the tensorType can be bufferized.

If possible, op bufferization implementations should not use this function and instead infer precise memref types for tensor results by themselves.

Unless a layout map was specified, options.unknownTypeConverter determines what kind of layout map will be used. For best composability (without copies), the fully dynamic layout map is used by default.

Note: Canonicalization patterns could clean up layout maps and infer more precise layout maps after bufferization. However, many possible canonicalizations are currently not implemented.

Definition at line 653 of file BufferizableOpInterface.cpp.

References mlir::Type::cast(), mlir::Type::dyn_cast(), mlir::bufferization::BufferizationOptions::FullyDynamicLayoutMap, getMemRefTypeWithFullyDynamicLayout(), getMemRefTypeWithStaticIdentityLayout(), mlir::bufferization::BufferizationOptions::IdentityLayoutMap, and mlir::bufferization::BufferizationOptions::unknownTypeConversion.

Referenced by mlir::bufferization::func_ext::FuncOpInterface::bufferize(), foldTransferInBoundsAttribute(), mlir::bufferization::BufferizationState::getBufferType(), lookupBuffer(), CollapseShapeOpMemRefCastFolder::matchAndRewrite(), CanonicalizeSingleResultAffineMinMaxOp< T >::matchAndRewrite(), parseGlobalMemrefOpTypeAndInitialValue(), mlir::replaceForOpWithNewYields(), replaceOpWithNewBufferizedOp(), verifyMemoryOpIndexing(), verifyMultShape(), and verifyVectorMemoryOp().

◆ getMemRefTypeWithFullyDynamicLayout()

BaseMemRefType mlir::bufferization::getMemRefTypeWithFullyDynamicLayout ( TensorType  tensorType,
Attribute  memorySpace = {} 
)

Return a MemRef type with fully dynamic layout.

If the given tensor type is unranked, return an unranked MemRef type.

Definition at line 686 of file BufferizableOpInterface.cpp.

References mlir::Type::cast(), mlir::Type::dyn_cast(), and mlir::makeStridedLinearLayoutMap().

Referenced by mlir::bufferization::func_ext::FuncOpInterface::bufferize(), mlir::bufferization::func_ext::getBufferizedFunctionArgType(), getMemRefType(), and replaceOpWithNewBufferizedOp().

◆ getMemRefTypeWithStaticIdentityLayout()

BaseMemRefType mlir::bufferization::getMemRefTypeWithStaticIdentityLayout ( TensorType  tensorType,
Attribute  memorySpace = {} 
)

Return a MemRef type with a static identity layout (i.e., no layout map).

If the given tensor type is unranked, return an unranked MemRef type.

Definition at line 709 of file BufferizableOpInterface.cpp.

References mlir::Type::cast(), and mlir::Type::dyn_cast().

Referenced by mlir::bufferization::func_ext::FuncOpInterface::bufferize(), mlir::bufferization::func_ext::getBufferizedFunctionArgType(), getMemRefType(), and replaceOpWithNewBufferizedOp().

◆ getPartialBufferizationOptions()

BufferizationOptions mlir::bufferization::getPartialBufferizationOptions ( )

◆ hoistBufferAllocations()

LogicalResult mlir::bufferization::hoistBufferAllocations ( Operation op,
const BufferizationOptions options 
)

◆ insertSliceAnchoredAllocTensorEliminationStep()

LogicalResult mlir::bufferization::insertSliceAnchoredAllocTensorEliminationStep ( RewriterBase rewriter,
Operation op,
bufferization::AnalysisState state 
)

Try to eliminate AllocTensorOps inside op that are anchored on an InsertSliceOp, i.e., if it is eventually inserted into another tensor (and some other conditions are met).

Try to eliminate AllocTensorOps inside op.

An AllocTensorOp can be eliminated if it is eventually inserted into another tensor (and some other conditions are met).

E.g.: %0 = linalg.alloc_tensor %1 = linalg.fill(cst, %0) {inplace = [true]} %2 = tensor.insert_slice %1 into t[10][20][1]

AllocTensorOp elimination will try to fill t inplace instead of filling a new allocation %0 and inserting it into t. This is done by replacing the AllocTensorOp with:

%0 = tensor.extract_slice t[10][20][1]

The analysis looks for matching ExtractSliceOp/InsertSliceOp pairs and lets those bufferize inplace in the absence of other conflicts.

Starting from an InsertSliceOp, an AllocTensorOp at the end of the insert source's reverse use-def chain is eliminated if:

  • On the reverse use-def chain path from the InsertSliceOp to the AllocTensorOp, all ops were decided to bufferize inplace and the buffer relation is "equivalent" (TODO: can be relaxed if needed).
  • The reverse use-def chain has exactly one end, which is the AllocTensorOp.

Definition at line 191 of file AllocTensorElimination.cpp.

References analyzeOp(), mlir::OpBuilder::create(), eliminateAllocTensors(), mlir::failed(), mlir::Operation::getContext(), mlir::Builder::getIndexAttr(), mlir::detail::IROperandBase::getOwner(), mlir::DialectRegistry::insert(), and options.

◆ isFunctionArgument()

bool mlir::bufferization::isFunctionArgument ( Value  value)

Return true if the given value is a BlockArgument of a func::FuncOp.

Definition at line 646 of file BufferizableOpInterface.cpp.

References mlir::Value::dyn_cast().

◆ lookupBuffer()

Value mlir::bufferization::lookupBuffer ( RewriterBase rewriter,
Value  tensor,
const BufferizationOptions options 
)

Lookup the buffer for the given value.

If the value was not bufferized yet, wrap it in a ToMemrefOp. Otherwise, it is the result of a ToTensorOp, from which the memref operand is returned.

Note: Use BufferizationState::getBuffer during bufferization. lookupBuffer is just for compatibility and gradual migration of bufferization patterns to BufferizableOpInterface-based bufferization. It does not insert any buffer copies.

Definition at line 255 of file BufferizableOpInterface.cpp.

References mlir::OpBuilder::create(), mlir::Type::dyn_cast(), ensureToMemrefOpIsValid(), mlir::Value::getDefiningOp(), mlir::Value::getLoc(), getMemRefType(), mlir::Value::getType(), and setInsertionPointAfter().

Referenced by mlir::bufferization::BufferizationState::getAnalysisState(), and mlir::bufferization::BufferizationState::getBuffer().

◆ populateBufferizeMaterializationLegality()

void mlir::bufferization::populateBufferizeMaterializationLegality ( ConversionTarget target)

Marks ops used by bufferization for type conversion materializations as "legal" in the given ConversionTarget.

This function should be called by all bufferization passes using BufferizeTypeConverter so that materializations work properly. One exception is bufferization passes doing "full" conversions, where it can be desirable for even the materializations to remain illegal so that they are eliminated, such as via the patterns in populateEliminateBufferizeMaterializationsPatterns.

Definition at line 79 of file Bufferize.cpp.

References mlir::ConversionTarget::addLegalOp(), mlir::OpConversionPattern< SourceOp >::OpConversionPattern(), mlir::ConversionPatternRewriter::replaceOp(), and mlir::success().

◆ populateEliminateBufferizeMaterializationsPatterns()

void mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns ( BufferizeTypeConverter typeConverter,
RewritePatternSet patterns 
)

Populate patterns to eliminate bufferize materializations.

In particular, these are the tensor_load/buffer_cast ops.

Definition at line 116 of file Bufferize.cpp.

References mlir::RewritePatternSet::add(), mlir::OpPassManager::addPass(), mlir::bufferization::BufferizationOptions::allowDialectInFilter(), mlir::bufferization::BufferizationOptions::allowOperationInFilter(), mlir::bufferization::OneShotBufferizationOptions::allowReturnAllocs, mlir::bufferization::BufferizationOptions::allowUnknownOps, mlir::bufferization::BufferizationOptions::alwaysAliasingWithDest, mlir::bufferization::BufferizationOptions::analysisFuzzerSeed, mlir::applyFullConversion(), mlir::bufferization::BufferizationOptions::bufferizeFunctionBoundaries, bufferizeOp(), mlir::createCanonicalizerPass(), mlir::createCSEPass(), mlir::bufferization::BufferizationOptions::createDeallocs, mlir::createLoopInvariantCodeMotionPass(), mlir::bufferization::OneShotBufferizationOptions::dropEquivalentFuncResults, mlir::failed(), mlir::bufferization::BufferizationOptions::FullyDynamicLayoutMap, mlir::bufferization::BufferizationOptions::functionBoundaryTypeConversion, mlir::RewritePatternSet::getContext(), getPartialBufferizationOptions(), mlir::bufferization::BufferizationOptions::IdentityLayoutMap, mlir::bufferization::BufferizationOptions::InferLayoutMap, mlir::DialectRegistry::insert(), mlir::TypeConverter::isLegal(), mlir::ConversionTarget::markUnknownOpDynamicallyLegal(), options, mlir::bufferization::BufferizationOptions::printConflicts, promoteBufferResultsToOutParams(), mlir::bufferization::BufferizationOptions::promoteBufferResultsToOutParams, registerAllocationOpInterfaceExternalModels(), runOneShotBufferize(), runOneShotModuleBufferize(), mlir::bufferization::BufferizationOptions::testAnalysisOnly, and mlir::bufferization::BufferizationOptions::unknownTypeConversion.

◆ promoteBufferResultsToOutParams()

LogicalResult mlir::bufferization::promoteBufferResultsToOutParams ( ModuleOp  module)

Replace buffers that are returned from a function with an out parameter.

Also update all call sites.

Definition at line 168 of file BufferResultsToOutParams.cpp.

References mlir::failed(), mlir::failure(), mlir::success(), updateCalls(), updateFuncOp(), and updateReturnOps().

Referenced by finalizeBuffers(), and populateEliminateBufferizeMaterializationsPatterns().

◆ registerAllocationOpInterfaceExternalModels()

void mlir::bufferization::registerAllocationOpInterfaceExternalModels ( DialectRegistry registry)

Register external models for AllocationOpInterface.

Definition at line 691 of file BufferDeallocation.cpp.

References mlir::DialectRegistry::addExtension().

Referenced by populateEliminateBufferizeMaterializationsPatterns(), and validateSupportedControlFlow().

◆ replaceOpWithBufferizedValues()

void mlir::bufferization::replaceOpWithBufferizedValues ( RewriterBase rewriter,
Operation op,
ValueRange  values 
)

◆ replaceOpWithNewBufferizedOp()

template<typename OpTy , typename... Args>
OpTy mlir::bufferization::replaceOpWithNewBufferizedOp ( RewriterBase rewriter,
Operation op,
Args &&...  args 
)

Replace an op with a new op.

The new op must have the same number of results as the replaced op. The new op may not return any tensor values.

Definition at line 586 of file BufferizableOpInterface.h.

References mlir::OpBuilder::create(), createAllocDeallocOps(), mlir::Operation::getLoc(), getMemRefType(), getMemRefTypeWithFullyDynamicLayout(), getMemRefTypeWithStaticIdentityLayout(), mlir::Operation::getResults(), hoistBufferAllocations(), and replaceOpWithBufferizedValues().

◆ runOneShotBufferize()

LogicalResult mlir::bufferization::runOneShotBufferize ( Operation op,
const OneShotBufferizationOptions options 
)

◆ runOneShotModuleBufferize()

LogicalResult mlir::bufferization::runOneShotModuleBufferize ( ModuleOp  moduleOp,
bufferization::OneShotBufferizationOptions  options 
)