MLIR  19.0.0git
Public Member Functions | Static Public Member Functions | Protected 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

AliasingOpOperandList getAliasingOpOperands (Value value) const
 Determine which OpOperand* will alias with value if the op is bufferized in place. More...
 
AliasingValueList getAliasingValues (OpOperand &opOperand) const
 Determine which Value 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 bufferizesToMemoryWrite (Value value) const
 Return true if the given value 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, TraversalConfig config=TraversalConfig()) const
 Starting from value, follow the use-def chain in reverse, always selecting the aliasing OpOperands. More...
 
SetVector< ValuefindDefinitions (Value value) const
 Find the values that may define the contents of the given value at runtime. 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...
 
const BufferizationOptionsgetOptions () const
 Return a reference to the BufferizationOptions. More...
 
 AnalysisState (const BufferizationOptions &options)
 
 AnalysisState (const AnalysisState &)=delete
 
virtual ~AnalysisState ()=default
 
TypeID getType () const
 
RegiongetEnclosingRepetitiveRegion (Operation *op, const BufferizationOptions &options)
 Return the closest enclosing repetitive region around the given op. More...
 
RegiongetEnclosingRepetitiveRegion (Value value, const BufferizationOptions &options)
 Return the closest enclosing repetitive region around the place where the given value is defined. More...
 
RegiongetEnclosingRepetitiveRegion (Block *block, const BufferizationOptions &options)
 Return the closest enclosing repetitive region around the given block. More...
 
virtual void resetCache ()
 

Static Public Member Functions

static bool classof (const AnalysisState *base)
 

Protected Member Functions

 AnalysisState (const BufferizationOptions &options, TypeID type)
 

Detailed Description

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

Definition at line 416 of file BufferizableOpInterface.h.

Constructor & Destructor Documentation

◆ AnalysisState() [1/3]

AnalysisState::AnalysisState ( const BufferizationOptions options)

Definition at line 571 of file BufferizableOpInterface.cpp.

◆ AnalysisState() [2/3]

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

◆ ~AnalysisState()

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

◆ AnalysisState() [3/3]

AnalysisState::AnalysisState ( const BufferizationOptions options,
TypeID  type 
)
protected

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 618 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 612 of file BufferizableOpInterface.cpp.

◆ 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 436 of file BufferizableOpInterface.cpp.

References getOptions(), and mlir::detail::IROperandBase::getOwner().

Referenced by isValueRead().

◆ 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 412 of file BufferizableOpInterface.cpp.

References getOptions(), and mlir::detail::IROperandBase::getOwner().

Referenced by canOmitTensorCopy(), and isValueRead().

◆ bufferizesToMemoryWrite() [1/2]

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 424 of file BufferizableOpInterface.cpp.

References getOptions(), and mlir::detail::IROperandBase::getOwner().

Referenced by canOmitTensorCopy(), findDefinitions(), isInPlace(), and mlir::bufferization::OneShotAnalysisState::isValueWritten().

◆ bufferizesToMemoryWrite() [2/2]

bool AnalysisState::bufferizesToMemoryWrite ( Value  value) const

Return true if the given value bufferizes to a memory write.

Return true if the value is a block argument. Return true if the defining op is not bufferizable. Otherwise, consult the BufferizableOpInterface.

Definition at line 446 of file BufferizableOpInterface.cpp.

References mlir::bufferization::BufferizationOptions::dynCastBufferizableOp(), and getOptions().

◆ 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 581 of file BufferizableOpInterface.cpp.

References bufferizesToMemoryRead(), bufferizesToMemoryWrite(), getAliasingValues(), hasUndefinedContents(), isValueRead(), and mlir::bufferization::AliasingValue::value.

◆ classof()

static bool mlir::bufferization::AnalysisState::classof ( const AnalysisState base)
inlinestatic

Definition at line 539 of file BufferizableOpInterface.h.

◆ findDefinitions()

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

Find the values that may define the contents of the given value at runtime.

A block argument is always a definition. An OpResult is a definition if it bufferizes to memory write. If it does not bufferize to a memory write but has aliasing operands, we continue the lookup on these values.

Example: r = tensor.insert f into t[c0] : tensor<?xf32> findDefinitions(r) = {r} because r bufferizes to memory write.

Example: r = tensor.empty() : tensor<10xf32> findDefinitions(r) = {} because tensor.empty does not the define the contents of its result (i.e., it does not bufferize to a memory write) and it has no aliasing OpOperands.

Example: a = arith.constant ... : tensor<10xf32> b1 = tensor.insert f into t : tensor<50xf32> b2 = tensor.extract_slice b1[0][10][1] : tensor<50xf32> tensor<10xf32> r = arith.select cond, a, b : tensor<10xf32> findDefinitions(r) = {a, b1}. r and b2 are skipped (lookup continues in the operands) because their defining ops do not define the contents of the tensor.

Example: a = tensor.empty() : tensor<10xf32> b = arith.constant ... : tensor<10xf32> r = arith.select cond, a, b : tensor<10xf32> findDefinitions(r) = {b}. a is excluded because it does not define the contents of the tensor.

Note: OpResults of unknown ops are handled conservatively and assumed to be definitions.

Definition at line 564 of file BufferizableOpInterface.cpp.

References mlir::bufferization::TraversalConfig::alwaysIncludeLeaves, bufferizesToMemoryWrite(), and findValueInReverseUseDefChain().

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

◆ findValueInReverseUseDefChain()

llvm::SetVector< Value > AnalysisState::findValueInReverseUseDefChain ( Value  value,
llvm::function_ref< bool(Value)>  condition,
TraversalConfig  config = TraversalConfig() 
) 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, also return the last Value of that chain if config.alwaysIncludeLeaves is set.

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 }

Additional stopping conditions for the traversal can be specified in config.

Definition at line 488 of file BufferizableOpInterface.cpp.

References mlir::bufferization::TraversalConfig::alwaysIncludeLeaves, mlir::bufferization::BufferizationOptions::dynCastBufferizableOp(), mlir::bufferization::Equivalent, mlir::bufferization::TraversalConfig::followEquivalentOnly, mlir::bufferization::TraversalConfig::followInPlaceOnly, mlir::bufferization::TraversalConfig::followSameTypeOrCastsOnly, mlir::bufferization::TraversalConfig::followUnknownOps, getAliasingOpOperands(), mlir::Value::getDefiningOp(), mlir::bufferization::AliasList< T >::getNumAliases(), mlir::Value::getType(), isInPlace(), and mlir::bufferization::TraversalConfig::revisitAlreadyVisitedValues.

Referenced by findDefinitions().

◆ getAliasingOpOperands()

AliasingOpOperandList AnalysisState::getAliasingOpOperands ( Value  value) const

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

Return all tensor OpOperand* if the op is not bufferizable.

Definition at line 390 of file BufferizableOpInterface.cpp.

Referenced by findValueInReverseUseDefChain().

◆ getAliasingValues()

AliasingValueList AnalysisState::getAliasingValues ( OpOperand opOperand) const

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

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

Return all tensor Values if the op is not bufferizable.

Definition at line 401 of file BufferizableOpInterface.cpp.

References getOptions(), mlir::detail::IROperandBase::getOwner(), and mlir::bufferization::detail::unknownGetAliasingValues().

Referenced by mlir::bufferization::OneShotAnalysisState::bufferizeInPlace(), canOmitTensorCopy(), and isValueRead().

◆ getEnclosingRepetitiveRegion() [1/3]

Region * AnalysisState::getEnclosingRepetitiveRegion ( Block block,
const BufferizationOptions options 
)

Return the closest enclosing repetitive region around the given block.

Definition at line 87 of file BufferizableOpInterface.cpp.

References mlir::Block::getParent().

◆ getEnclosingRepetitiveRegion() [2/3]

Region * AnalysisState::getEnclosingRepetitiveRegion ( Operation op,
const BufferizationOptions options 
)

Return the closest enclosing repetitive region around the given op.

Definition at line 54 of file BufferizableOpInterface.cpp.

◆ getEnclosingRepetitiveRegion() [3/3]

Region * AnalysisState::getEnclosingRepetitiveRegion ( Value  value,
const BufferizationOptions options 
)

Return the closest enclosing repetitive region around the place where the given value is defined.

Definition at line 65 of file BufferizableOpInterface.cpp.

References mlir::Region::getParentRegion(), mlir::Value::getParentRegion(), and isRepetitiveRegion().

◆ getOptions()

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

◆ getType()

TypeID mlir::bufferization::AnalysisState::getType ( ) const
inline

◆ 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 624 of file BufferizableOpInterface.cpp.

Referenced by canOmitTensorCopy().

◆ 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 602 of file BufferizableOpInterface.cpp.

References bufferizesToMemoryWrite(), and mlir::detail::IROperandBase::getOwner().

Referenced by findValueInReverseUseDefChain().

◆ 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 459 of file BufferizableOpInterface.cpp.

References bufferizesToAliasOnly(), bufferizesToMemoryRead(), getAliasingValues(), mlir::Value::getType(), and mlir::Value::getUses().

Referenced by canOmitTensorCopy().

◆ resetCache()

void AnalysisState::resetCache ( )
virtual

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