MLIR  16.0.0git
Public Types | Public Member Functions | Public Attributes | List of all members
mlir::bufferization::BufferizationOptions Struct Reference

Options for BufferizableOpInterface-based bufferization. More...

#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"

+ Inheritance diagram for mlir::bufferization::BufferizationOptions:
+ Collaboration diagram for mlir::bufferization::BufferizationOptions:

Public Types

enum  LayoutMapOption : int8_t { LayoutMapOption::InferLayoutMap = 0, LayoutMapOption::IdentityLayoutMap = 1, LayoutMapOption::FullyDynamicLayoutMap = 2 }
 
using AllocationFn = std::function< FailureOr< Value >(OpBuilder &, Location, MemRefType, ValueRange, unsigned int)>
 Allocator function: Generate a memref allocation with the given type, dynamic extents and alignment. More...
 
using DeallocationFn = std::function< LogicalResult(OpBuilder &, Location, Value)>
 Deallocator function: Deallocate a buffer that was allocated with AllocatorFn. More...
 
using MemCpyFn = std::function< LogicalResult(OpBuilder &, Location, Value, Value)>
 Memcpy function: Generate a memcpy between two buffers. More...
 
using AnalysisStateInitFn = std::function< void(AnalysisState &)>
 Initializer function for analysis state. More...
 
using DialectStateInitFn = std::function< std::unique_ptr< DialectAnalysisState >()>
 Initializer function for dialect-specific analysis state. More...
 
using UnknownTypeConverterFn = std::function< BaseMemRefType(Value, unsigned, const BufferizationOptions &)>
 Tensor -> MemRef type converter. More...
 

Public Member Functions

 BufferizationOptions ()
 
BufferizableOpInterface dynCastBufferizableOp (Operation *op) const
 Try to cast the given op to BufferizableOpInterface if the op is allow listed. More...
 
BufferizableOpInterface dynCastBufferizableOp (Value value) const
 Try to cast the given value to BufferizableOpInterface if the op is allow listed. More...
 
bool isOpAllowed (Operation *op) const
 Return true if the given op should be bufferized. More...
 
FailureOr< ValuecreateAlloc (OpBuilder &b, Location loc, MemRefType type, ValueRange dynShape) const
 Create a memref allocation with the given type and dynamic extents. More...
 
LogicalResult createDealloc (OpBuilder &b, Location loc, Value allocatedBuffer) const
 Creates a memref deallocation. More...
 
LogicalResult createMemCpy (OpBuilder &b, Location loc, Value from, Value to) const
 Creates a memcpy between two given buffers. More...
 
void addDialectStateInitializer (StringRef name, const DialectStateInitFn &fn)
 Add a analysis state initializer that initializes the specified dialect-specific analysis state. More...
 

Public Attributes

OpFilter opFilter
 A filter that specifies which ops should be bufferized and which ops should be ignored. More...
 
Optional< AllocationFnallocationFn
 Helper functions for allocation, deallocation, memory copying. More...
 
Optional< DeallocationFndeallocationFn
 
Optional< MemCpyFnmemCpyFn
 
bool allowUnknownOps = false
 Specifies whether not bufferizable ops are allowed in the input. More...
 
bool bufferizeFunctionBoundaries = false
 Specifies whether function boundaries (ops in the func dialect) should be bufferized or not. More...
 
Optional< unsigneddefaultMemorySpace = 0
 The default memory space that should be used when it cannot be inferred from the context. More...
 
bool enforceAliasingInvariants = true
 Certain ops have aliasing OpOperand/OpResult invariants (e.g., scf.for). More...
 
LayoutMapOption functionBoundaryTypeConversion
 This flag controls buffer types on function signatures. More...
 
UnknownTypeConverterFn unknownTypeConverterFn = nullptr
 Type converter from tensors to memrefs. More...
 
bool createDeallocs = true
 Specifies whether dealloc ops should be generated along with alloc ops. More...
 
unsigned analysisFuzzerSeed = 0
 Seed for the analysis fuzzer. More...
 
bool copyBeforeWrite = false
 If set to true, the analysis is skipped. More...
 
bool testAnalysisOnly = false
 If set to true, does not modify the IR apart from adding attributes (for checking the results of the analysis) and post analysis steps. More...
 
bool printConflicts = false
 If set to true, the IR is annotated with details about RaW conflicts. More...
 
unsigned int bufferAlignment = 128
 Buffer alignment for new memory allocations. More...
 
SmallVector< AnalysisStateInitFnstateInitializers
 Initializer functions for analysis state. More...
 

Detailed Description

Options for BufferizableOpInterface-based bufferization.

Definition at line 168 of file BufferizableOpInterface.h.

Member Typedef Documentation

◆ AllocationFn

Allocator function: Generate a memref allocation with the given type, dynamic extents and alignment.

Definition at line 172 of file BufferizableOpInterface.h.

◆ AnalysisStateInitFn

Initializer function for analysis state.

Definition at line 181 of file BufferizableOpInterface.h.

◆ DeallocationFn

Deallocator function: Deallocate a buffer that was allocated with AllocatorFn.

Definition at line 176 of file BufferizableOpInterface.h.

◆ DialectStateInitFn

Initializer function for dialect-specific analysis state.

Definition at line 184 of file BufferizableOpInterface.h.

◆ MemCpyFn

Memcpy function: Generate a memcpy between two buffers.

Definition at line 179 of file BufferizableOpInterface.h.

◆ UnknownTypeConverterFn

Tensor -> MemRef type converter.

Parameters: Value, memory space, bufferization options

Definition at line 188 of file BufferizableOpInterface.h.

Member Enumeration Documentation

◆ LayoutMapOption

Enumerator
InferLayoutMap 
IdentityLayoutMap 
FullyDynamicLayoutMap 

Definition at line 190 of file BufferizableOpInterface.h.

Constructor & Destructor Documentation

◆ BufferizationOptions()

BufferizationOptions::BufferizationOptions ( )

Definition at line 268 of file BufferizableOpInterface.cpp.

Member Function Documentation

◆ addDialectStateInitializer()

void BufferizationOptions::addDialectStateInitializer ( StringRef  name,
const DialectStateInitFn fn 
)

Add a analysis state initializer that initializes the specified dialect-specific analysis state.

Definition at line 299 of file BufferizableOpInterface.cpp.

References mlir::bufferization::AnalysisState::insertDialectState(), and stateInitializers.

◆ createAlloc()

FailureOr< Value > BufferizationOptions::createAlloc ( OpBuilder b,
Location  loc,
MemRefType  type,
ValueRange  dynShape 
) const

Create a memref allocation with the given type and dynamic extents.

Definition at line 671 of file BufferizableOpInterface.cpp.

References allocationFn, bufferAlignment, mlir::OpBuilder::create(), and mlir::Builder::getI64IntegerAttr().

Referenced by mlir::bufferization::populateDynamicDimSizes().

◆ createDealloc()

LogicalResult BufferizationOptions::createDealloc ( OpBuilder b,
Location  loc,
Value  allocatedBuffer 
) const

Creates a memref deallocation.

The given memref buffer must have been allocated using createAlloc.

Definition at line 688 of file BufferizableOpInterface.cpp.

References mlir::OpBuilder::create(), deallocationFn, and mlir::success().

Referenced by mlir::bufferization::populateDynamicDimSizes().

◆ createMemCpy()

LogicalResult BufferizationOptions::createMemCpy ( OpBuilder b,
Location  loc,
Value  from,
Value  to 
) const

Creates a memcpy between two given buffers.

Create a memory copy between two memref buffers.

Definition at line 699 of file BufferizableOpInterface.cpp.

References mlir::OpBuilder::create(), memCpyFn, and mlir::success().

Referenced by mlir::bufferization::populateDynamicDimSizes().

◆ dynCastBufferizableOp() [1/2]

BufferizableOpInterface BufferizationOptions::dynCastBufferizableOp ( Operation op) const

◆ dynCastBufferizableOp() [2/2]

BufferizableOpInterface BufferizationOptions::dynCastBufferizableOp ( Value  value) const

Try to cast the given value to BufferizableOpInterface if the op is allow listed.

Definition at line 292 of file BufferizableOpInterface.cpp.

References mlir::Value::getDefiningOp(), and isOpAllowed().

◆ isOpAllowed()

bool BufferizationOptions::isOpAllowed ( Operation op) const

Member Data Documentation

◆ allocationFn

Optional<AllocationFn> mlir::bufferization::BufferizationOptions::allocationFn

Helper functions for allocation, deallocation, memory copying.

Definition at line 214 of file BufferizableOpInterface.h.

Referenced by createAlloc().

◆ allowUnknownOps

bool mlir::bufferization::BufferizationOptions::allowUnknownOps = false

Specifies whether not bufferizable ops are allowed in the input.

If so, bufferization.to_memref and bufferization.to_tensor ops are inserted at the boundaries.

Definition at line 234 of file BufferizableOpInterface.h.

Referenced by mlir::bufferization::getPartialBufferizationOptions(), and mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns().

◆ analysisFuzzerSeed

unsigned mlir::bufferization::BufferizationOptions::analysisFuzzerSeed = 0

Seed for the analysis fuzzer.

If set to 0, the fuzzer is deactivated. Should be used only with testAnalysisOnly = true.

Definition at line 288 of file BufferizableOpInterface.h.

Referenced by mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns().

◆ bufferAlignment

unsigned int mlir::bufferization::BufferizationOptions::bufferAlignment = 128

Buffer alignment for new memory allocations.

Definition at line 303 of file BufferizableOpInterface.h.

Referenced by createAlloc().

◆ bufferizeFunctionBoundaries

bool mlir::bufferization::BufferizationOptions::bufferizeFunctionBoundaries = false

◆ copyBeforeWrite

bool mlir::bufferization::BufferizationOptions::copyBeforeWrite = false

If set to true, the analysis is skipped.

A buffer is copied before every write. This flag cannot be used together with testAnalysisOnly = true.

Definition at line 292 of file BufferizableOpInterface.h.

Referenced by mlir::bufferization::bufferizeModuleOp(), mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns(), mlir::bufferization::runOneShotBufferize(), and mlir::bufferization::runOneShotModuleBufferize().

◆ createDeallocs

bool mlir::bufferization::BufferizationOptions::createDeallocs = true

◆ deallocationFn

Optional<DeallocationFn> mlir::bufferization::BufferizationOptions::deallocationFn

Definition at line 215 of file BufferizableOpInterface.h.

Referenced by createDealloc().

◆ defaultMemorySpace

Optional<unsigned> mlir::bufferization::BufferizationOptions::defaultMemorySpace = 0

The default memory space that should be used when it cannot be inferred from the context.

If no default memory space is specified, bufferization fails when the memory space cannot be inferred at any point.

Definition at line 243 of file BufferizableOpInterface.h.

Referenced by mlir::bufferization::detail::defaultGetBufferType(), mlir::bufferization::getBufferType(), mlir::bufferization::insertTensorCopies(), mlir::bufferization::populateDynamicDimSizes(), and mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns().

◆ enforceAliasingInvariants

bool mlir::bufferization::BufferizationOptions::enforceAliasingInvariants = true

Certain ops have aliasing OpOperand/OpResult invariants (e.g., scf.for).

If this flag is set to false, those invariants are no longer enforced with buffer copies.

Note: Deactivating this flag can lead to incorrect bufferization results when used incorrectly. This flag is useful with AlwaysCopyAnalysisState which bufferizes all writing tensor OpOperands out-of-place.

Definition at line 253 of file BufferizableOpInterface.h.

Referenced by mlir::bufferization::getPartialBufferizationOptions().

◆ functionBoundaryTypeConversion

LayoutMapOption mlir::bufferization::BufferizationOptions::functionBoundaryTypeConversion
Initial value:

This flag controls buffer types on function signatures.

  • InferLayoutMap: All function parameter types have a fully dynamic layout map, but function result types are inferred from the body of the function.
  • FullyDynamicLayoutMap: All function parameter types and result types have a fully dynamic layout map. This option is most efficient because any layout map can be casted to a fully dynamic one.
  • IdentityLayoutMap: All function parameter types and result types have a static identity layout (i.e., no layout map). This option may introduce additional buffer allocs and copies because layout maps cannot be casted away.

If bufferizeFunctionBoundaries is not set, this flag has no effect.

Note: Inferred layout maps may not be desireable when interacting with external functions, because the generated function signatures will be less predictable.

Definition at line 273 of file BufferizableOpInterface.h.

Referenced by mlir::bufferization::func_ext::FuncOpInterface::bufferize(), mlir::bufferization::bufferizeModuleOp(), mlir::bufferization::func_ext::getBufferizedFunctionArgType(), and mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns().

◆ memCpyFn

Optional<MemCpyFn> mlir::bufferization::BufferizationOptions::memCpyFn

Definition at line 216 of file BufferizableOpInterface.h.

Referenced by createMemCpy().

◆ opFilter

OpFilter mlir::bufferization::BufferizationOptions::opFilter

A filter that specifies which ops should be bufferized and which ops should be ignored.

Definition at line 208 of file BufferizableOpInterface.h.

Referenced by mlir::bufferization::getPartialBufferizationOptions(), isOpAllowed(), and mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns().

◆ printConflicts

bool mlir::bufferization::BufferizationOptions::printConflicts = false

If set to true, the IR is annotated with details about RaW conflicts.

For debugging only. Should be used together with testAnalysisOnly.

Definition at line 300 of file BufferizableOpInterface.h.

Referenced by hasReadAfterWriteInterference(), and mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns().

◆ stateInitializers

SmallVector<AnalysisStateInitFn> mlir::bufferization::BufferizationOptions::stateInitializers

Initializer functions for analysis state.

These can be used to initialize dialect-specific analysis state.

Definition at line 307 of file BufferizableOpInterface.h.

Referenced by addDialectStateInitializer(), and mlir::bufferization::AnalysisState::findLastPrecedingWrite().

◆ testAnalysisOnly

bool mlir::bufferization::BufferizationOptions::testAnalysisOnly = false

If set to true, does not modify the IR apart from adding attributes (for checking the results of the analysis) and post analysis steps.

Definition at line 296 of file BufferizableOpInterface.h.

Referenced by getAssumedUniqueReturnOp(), mlir::bufferization::insertTensorCopies(), mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns(), mlir::bufferization::runOneShotBufferize(), and mlir::bufferization::runOneShotModuleBufferize().

◆ unknownTypeConverterFn

UnknownTypeConverterFn mlir::bufferization::BufferizationOptions::unknownTypeConverterFn = nullptr

Type converter from tensors to memrefs.

This type converter is used if no memref type could be inferred during bufferization. By default, a type converter that returns a memref type with a fully dynamic layout map is used.

Definition at line 280 of file BufferizableOpInterface.h.

Referenced by mlir::bufferization::getMemRefType(), mlir::bufferization::getPartialBufferizationOptions(), and mlir::bufferization::populateEliminateBufferizeMaterializationsPatterns().


The documentation for this struct was generated from the following files: