MLIR  16.0.0git
Public Member Functions | List of all members
mlir::bufferization::AnalysisState Class Reference

AnalysisState provides a variety of helper functions for dealing with tensor values. More...

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

+ Inheritance diagram for mlir::bufferization::AnalysisState:

Public Member Functions

SmallVector< OpOperand * > getAliasingOpOperand (OpResult result) const
 Determine which OpOperand* will alias with result if the op is bufferized in place. More...
 
SmallVector< OpResultgetAliasingOpResult (OpOperand &opOperand) const
 Determine which OpResult will alias with opOperand if the op is bufferized in place. More...
 
bool bufferizesToMemoryRead (OpOperand &opOperand) const
 Return true if opOperand bufferizes to a memory read. More...
 
bool bufferizesToMemoryWrite (OpOperand &opOperand) const
 Return true if opOperand bufferizes to a memory write. More...
 
bool bufferizesToAliasOnly (OpOperand &opOperand) const
 Return true if opOperand does neither read nor write but bufferizes to an alias. More...
 
bool canOmitTensorCopy (OpOperand &opOperand) const
 Return true if a copy can always be avoided when allocating a new tensor for the given OpOperand. More...
 
bool isValueRead (Value value) const
 Return true if the given value is read by an op that bufferizes to a memory read. More...
 
SetVector< ValuefindValueInReverseUseDefChain (Value value, llvm::function_ref< bool(Value)> condition) const
 Starting from value, follow the use-def chain in reverse, always selecting the aliasing OpOperands. More...
 
SetVector< ValuefindLastPrecedingWrite (Value value) const
 Find the Values of the last preceding write of a given Value. More...
 
virtual bool isInPlace (OpOperand &opOperand) const
 Return true if the given OpResult has been decided to bufferize inplace. More...
 
virtual bool areEquivalentBufferizedValues (Value v1, Value v2) const
 Return true if v1 and v2 bufferize to equivalent buffers. More...
 
virtual bool areAliasingBufferizedValues (Value v1, Value v2) const
 Return true if v1 and v2 may bufferize to aliasing buffers. More...
 
virtual bool hasUndefinedContents (OpOperand *opOperand) const
 Return true if the given tensor has undefined contents. More...
 
virtual bool isTensorYielded (Value tensor) const
 Return true if the given tensor (or an aliasing tensor) is yielded from the containing block. More...
 
bool hasDialectState (StringRef name) const
 Return true if the given dialect state exists. More...
 
template<typename StateT >
Optional< const StateT * > getDialectState (StringRef name) const
 Return dialect-specific bufferization state. More...
 
template<typename StateT >
StateT & getOrCreateDialectState (StringRef name)
 Return dialect-specific analysis state or create one if none exists. More...
 
void insertDialectState (StringRef name, std::unique_ptr< DialectAnalysisState > state)
 
const BufferizationOptionsgetOptions () const
 Return a reference to the BufferizationOptions. More...
 
 AnalysisState (const BufferizationOptions &options)
 
 AnalysisState (const AnalysisState &)=delete
 
virtual ~AnalysisState ()=default
 

Detailed Description

AnalysisState provides a variety of helper functions for dealing with tensor values.

Definition at line 335 of file BufferizableOpInterface.h.

Constructor & Destructor Documentation

◆ AnalysisState() [1/2]

mlir::bufferization::AnalysisState::AnalysisState ( const BufferizationOptions options)
explicit

Referenced by findLastPrecedingWrite().

◆ AnalysisState() [2/2]

mlir::bufferization::AnalysisState::AnalysisState ( const AnalysisState )
delete

◆ ~AnalysisState()

virtual mlir::bufferization::AnalysisState::~AnalysisState ( )
virtualdefault

Member Function Documentation

◆ areAliasingBufferizedValues()

bool AnalysisState::areAliasingBufferizedValues ( Value  v1,
Value  v2 
) const
virtual

Return true if v1 and v2 may bufferize to aliasing buffers.

Reimplemented in mlir::bufferization::OneShotAnalysisState.

Definition at line 484 of file BufferizableOpInterface.cpp.

◆ areEquivalentBufferizedValues()

bool AnalysisState::areEquivalentBufferizedValues ( Value  v1,
Value  v2 
) const
virtual

Return true if v1 and v2 bufferize to equivalent buffers.

Reimplemented in mlir::bufferization::OneShotAnalysisState.

Definition at line 478 of file BufferizableOpInterface.cpp.

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

◆ bufferizesToAliasOnly()

bool AnalysisState::bufferizesToAliasOnly ( OpOperand opOperand) const

Return true if opOperand does neither read nor write but bufferizes to an alias.

Return false if the op is not bufferizable.

Definition at line 363 of file BufferizableOpInterface.cpp.

References mlir::bufferization::BufferizationOptions::dynCastBufferizableOp(), and mlir::detail::IROperandBase::getOwner().

◆ bufferizesToMemoryRead()

bool AnalysisState::bufferizesToMemoryRead ( OpOperand opOperand) const

Return true if opOperand bufferizes to a memory read.

Return true if the op is not bufferizable.

Definition at line 339 of file BufferizableOpInterface.cpp.

References mlir::bufferization::BufferizationOptions::dynCastBufferizableOp(), and mlir::detail::IROperandBase::getOwner().

◆ bufferizesToMemoryWrite()

bool AnalysisState::bufferizesToMemoryWrite ( OpOperand opOperand) const

Return true if opOperand bufferizes to a memory write.

Return true` if the op is not bufferizable.

Return true if the op is not bufferizable.

Definition at line 351 of file BufferizableOpInterface.cpp.

References mlir::bufferization::BufferizationOptions::dynCastBufferizableOp(), and mlir::detail::IROperandBase::getOwner().

Referenced by mlir::bufferization::allocateTensorForShapedValue(), mlir::bufferization::OneShotAnalysisState::isValueWritten(), and wouldCreateWriteToNonWritableBuffer().

◆ canOmitTensorCopy()

bool AnalysisState::canOmitTensorCopy ( OpOperand opOperand) const

Return true if a copy can always be avoided when allocating a new tensor for the given OpOperand.

Definition at line 447 of file BufferizableOpInterface.cpp.

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

◆ findLastPrecedingWrite()

llvm::SetVector< Value > AnalysisState::findLastPrecedingWrite ( Value  value) const

Find the Values of the last preceding write of a given Value.

Note: Unknown ops are handled conservatively and assumed to be writes. Furthermore, BlockArguments are also assumed to be writes. There is no analysis across block boundaries.

Note: When reaching an end of the reverse SSA use-def chain, that value is returned regardless of whether it is a memory write or not.

Definition at line 428 of file BufferizableOpInterface.cpp.

References AnalysisState(), mlir::Value::cast(), mlir::Value::getDefiningOp(), options, and mlir::bufferization::BufferizationOptions::stateInitializers.

Referenced by mlir::bufferization::OneShotAnalysisState::gatherUndefinedTensorUses().

◆ findValueInReverseUseDefChain()

llvm::SetVector< Value > AnalysisState::findValueInReverseUseDefChain ( Value  value,
llvm::function_ref< bool(Value)>  condition 
) const

Starting from value, follow the use-def chain in reverse, always selecting the aliasing OpOperands.

Find and return Values for which condition evaluates to true. OpOperands of such matching Values are not traversed any further.

When reaching the end of a chain (BlockArgument or Value without aliasing OpOperands), also return the last Value of that chain.

Example:

                          8
                          |

6* 7* +--—+-—+ | | | | 2* 3 4* 5 | | | | +-------—+-------—+-------—+ | 1

In the above example, Values with a star satisfy the condition. When starting the traversal from Value 1, the resulting SetVector is: { 2, 7, 8, 5 }

Definition at line 400 of file BufferizableOpInterface.cpp.

References mlir::Value::cast(), mlir::Value::getDefiningOp(), mlir::Value::isa(), and options.

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

◆ getAliasingOpOperand()

SmallVector< OpOperand * > AnalysisState::getAliasingOpOperand ( OpResult  result) const

Determine which OpOperand* will alias with result if the op is bufferized in place.

Return an empty vector if the op is not bufferizable.

Definition at line 320 of file BufferizableOpInterface.cpp.

References mlir::Value::getDefiningOp().

Referenced by mlir::bufferization::allocateTensorForShapedValue(), mlir::bufferization::eliminateAllocTensors(), and hasPrecedingAliasingNonWritableTensor().

◆ getAliasingOpResult()

SmallVector< OpResult > AnalysisState::getAliasingOpResult ( OpOperand opOperand) const

Determine which OpResult will alias with opOperand if the op is bufferized in place.

Return an empty vector if the op is not bufferizable.

Definition at line 330 of file BufferizableOpInterface.cpp.

References mlir::bufferization::BufferizationOptions::dynCastBufferizableOp(), and mlir::detail::IROperandBase::getOwner().

Referenced by mlir::bufferization::allocateTensorForShapedValue(), mlir::bufferization::BufferizationAliasInfo::bufferizeInPlace(), and wouldCreateWriteToNonWritableBuffer().

◆ getDialectState()

template<typename StateT >
Optional<const StateT *> mlir::bufferization::AnalysisState::getDialectState ( StringRef  name) const
inline

Return dialect-specific bufferization state.

Definition at line 429 of file BufferizableOpInterface.h.

References mlir::bufferization::None.

Referenced by mlir::bufferization::func_ext::getFuncAnalysisState(), and mlir::bufferization::func_ext::getFuncOpAnalysisState().

◆ getOptions()

const BufferizationOptions& mlir::bufferization::AnalysisState::getOptions ( ) const
inline

◆ getOrCreateDialectState()

template<typename StateT >
StateT& mlir::bufferization::AnalysisState::getOrCreateDialectState ( StringRef  name)
inline

Return dialect-specific analysis state or create one if none exists.

Definition at line 438 of file BufferizableOpInterface.h.

◆ hasDialectState()

bool mlir::bufferization::AnalysisState::hasDialectState ( StringRef  name) const
inline

Return true if the given dialect state exists.

Definition at line 422 of file BufferizableOpInterface.h.

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

◆ hasUndefinedContents()

bool AnalysisState::hasUndefinedContents ( OpOperand opOperand) const
virtual

Return true if the given tensor has undefined contents.

Reimplemented in mlir::bufferization::OneShotAnalysisState.

Definition at line 490 of file BufferizableOpInterface.cpp.

◆ insertDialectState()

void mlir::bufferization::AnalysisState::insertDialectState ( StringRef  name,
std::unique_ptr< DialectAnalysisState state 
)
inline

◆ isInPlace()

bool AnalysisState::isInPlace ( OpOperand opOperand) const
virtual

Return true if the given OpResult has been decided to bufferize inplace.

Reimplemented in mlir::bufferization::OneShotAnalysisState.

Definition at line 468 of file BufferizableOpInterface.cpp.

References mlir::detail::IROperandBase::getOwner().

Referenced by mlir::bufferization::allocateTensorForShapedValue(), and mlir::bufferization::eliminateAllocTensors().

◆ isTensorYielded()

bool AnalysisState::isTensorYielded ( Value  tensor) const
virtual

Return true if the given tensor (or an aliasing tensor) is yielded from the containing block.

Also include all aliasing tensors in the same block.

Note: In the absence of an analysis, an implementation may return true for any given tensor.

Reimplemented in mlir::bufferization::OneShotAnalysisState.

Definition at line 495 of file BufferizableOpInterface.cpp.

References mlir::bufferization::BufferizationOptions::dynCastBufferizableOp(), mlir::Value::getDefiningOp(), mlir::detail::IROperandBase::getOwner(), mlir::Value::getUses(), and mlir::isRegionReturnLike().

Referenced by mlir::bufferization::allocateTensorForShapedValue(), and mlir::bufferization::insertTensorCopies().

◆ isValueRead()

bool AnalysisState::isValueRead ( Value  value) const

Return true if the given value is read by an op that bufferizes to a memory read.

Also takes into account ops that create an alias but do not read by themselves (e.g., ExtractSliceOp).

Definition at line 376 of file BufferizableOpInterface.cpp.

References mlir::Value::getType(), mlir::Value::getUses(), and mlir::Type::isa().

Referenced by getAssumedUniqueReturnOp().


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