MLIR
20.0.0git
|
AnalysisState provides a variety of helper functions for dealing with tensor values. More...
#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
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< Value > | 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. More... | |
SetVector< Value > | findDefinitions (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 BufferizationOptions & | getOptions () const |
Return a reference to the BufferizationOptions. More... | |
AnalysisState (const BufferizationOptions &options) | |
AnalysisState (const AnalysisState &)=delete | |
virtual | ~AnalysisState ()=default |
TypeID | getType () const |
Region * | getEnclosingRepetitiveRegion (Operation *op, const BufferizationOptions &options) |
Return the closest enclosing repetitive region around the given op. More... | |
Region * | getEnclosingRepetitiveRegion (Value value, const BufferizationOptions &options) |
Return the closest enclosing repetitive region around the place where the given value is defined. More... | |
Region * | getEnclosingRepetitiveRegion (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) | |
AnalysisState provides a variety of helper functions for dealing with tensor values.
Definition at line 422 of file BufferizableOpInterface.h.
AnalysisState::AnalysisState | ( | const BufferizationOptions & | options | ) |
Definition at line 570 of file BufferizableOpInterface.cpp.
|
delete |
|
virtualdefault |
|
protected |
Definition at line 573 of file BufferizableOpInterface.cpp.
References mlir::bufferization::BufferizationOptions::stateInitializers.
Return true if v1
and v2
may bufferize to aliasing buffers.
Reimplemented in mlir::bufferization::OneShotAnalysisState.
Definition at line 617 of file BufferizableOpInterface.cpp.
Return true if v1
and v2
bufferize to equivalent buffers.
Reimplemented in mlir::bufferization::OneShotAnalysisState.
Definition at line 611 of file BufferizableOpInterface.cpp.
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().
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().
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().
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().
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 580 of file BufferizableOpInterface.cpp.
References bufferizesToMemoryRead(), bufferizesToMemoryWrite(), getAliasingValues(), hasUndefinedContents(), isValueRead(), and mlir::bufferization::AliasingValue::value.
|
inlinestatic |
Definition at line 545 of file BufferizableOpInterface.h.
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 563 of file BufferizableOpInterface.cpp.
References mlir::bufferization::TraversalConfig::alwaysIncludeLeaves, bufferizesToMemoryWrite(), and findValueInReverseUseDefChain().
Referenced by mlir::bufferization::OneShotAnalysisState::findDefinitionsCached().
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 487 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().
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.
References getOptions(), mlir::bufferization::getOwnerOfValue(), and mlir::bufferization::detail::unknownGetAliasingOpOperands().
Referenced by findValueInReverseUseDefChain().
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().
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(), mlir::Region::getParentOp(), mlir::Operation::getParentRegion(), and isRepetitiveRegion().
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.
References mlir::Operation::getBlock().
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().
|
inline |
Return a reference to the BufferizationOptions.
Definition at line 536 of file BufferizableOpInterface.h.
Referenced by bufferizesToAliasOnly(), bufferizesToMemoryRead(), bufferizesToMemoryWrite(), getAliasingOpOperands(), getAliasingValues(), and mlir::bufferization::OneShotAnalysisState::getOptions().
|
inline |
Definition at line 547 of file BufferizableOpInterface.h.
Referenced by mlir::bufferization::OneShotAnalysisState::classof().
|
virtual |
Return true
if the given tensor has undefined contents.
Reimplemented in mlir::bufferization::OneShotAnalysisState.
Definition at line 623 of file BufferizableOpInterface.cpp.
Referenced by canOmitTensorCopy().
|
virtual |
Return true
if the given OpResult has been decided to bufferize inplace.
Reimplemented in mlir::bufferization::OneShotAnalysisState.
Definition at line 601 of file BufferizableOpInterface.cpp.
References bufferizesToMemoryWrite(), and mlir::detail::IROperandBase::getOwner().
Referenced by findValueInReverseUseDefChain().
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().
|
virtual |
Reimplemented in mlir::bufferization::OneShotAnalysisState.
Definition at line 110 of file BufferizableOpInterface.cpp.
Referenced by mlir::bufferization::OneShotAnalysisState::resetCache().