MLIR  19.0.0git
Public Member Functions | List of all members
mlir::bufferization::DeallocationState Class Reference

This class collects all the state that we need to perform the buffer deallocation pass with associated helper functions such that we have easy access to it in the BufferDeallocationOpInterface implementations and the BufferDeallocation pass. More...

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

Public Member Functions

 DeallocationState (Operation *op)
 
 DeallocationState (const DeallocationState &)=delete
 
void updateOwnership (Value memref, Ownership ownership, Block *block=nullptr)
 Small helper function to update the ownership map by taking the current ownership ('Uninitialized' state if not yet present), computing the join with the passed ownership and storing this new value in the map. More...
 
void resetOwnerships (ValueRange memrefs, Block *block)
 Removes ownerships associated with all values in the passed range for 'block'. More...
 
Ownership getOwnership (Value memref, Block *block) const
 Returns the ownership of 'memref' for the given basic block. More...
 
void addMemrefToDeallocate (Value memref, Block *block)
 Remember the given 'memref' to deallocate it at the end of the 'block'. More...
 
void dropMemrefToDeallocate (Value memref, Block *block)
 Forget about a MemRef that we originally wanted to deallocate at the end of 'block', possibly because it already gets deallocated before the end of the block. More...
 
void getLiveMemrefsIn (Block *block, SmallVectorImpl< Value > &memrefs)
 Return a sorted list of MemRef values which are live at the start of the given block. More...
 
std::pair< Value, ValuegetMemrefWithUniqueOwnership (OpBuilder &builder, Value memref, Block *block)
 Given an SSA value of MemRef type, this function queries the ownership and if it is not already in the 'Unique' state, potentially inserts IR to get a new SSA value, returned as the first element of the pair, which has 'Unique' ownership and can be used instead of the passed Value with the the ownership indicator returned as the second element of the pair. More...
 
void getMemrefsToRetain (Block *fromBlock, Block *toBlock, ValueRange destOperands, SmallVectorImpl< Value > &toRetain) const
 Given two basic blocks and the values passed via block arguments to the destination block, compute the list of MemRefs that have to be retained in the 'fromBlock' to not run into a use-after-free situation. More...
 
LogicalResult getMemrefsAndConditionsToDeallocate (OpBuilder &builder, Location loc, Block *block, SmallVectorImpl< Value > &memrefs, SmallVectorImpl< Value > &conditions) const
 For a given block, computes the list of MemRefs that potentially need to be deallocated at the end of that block. More...
 
SymbolTableCollectiongetSymbolTable ()
 Returns the symbol cache to lookup functions from call operations to check attributes on the function operation. More...
 

Detailed Description

This class collects all the state that we need to perform the buffer deallocation pass with associated helper functions such that we have easy access to it in the BufferDeallocationOpInterface implementations and the BufferDeallocation pass.

Definition at line 105 of file BufferDeallocationOpInterface.h.

Constructor & Destructor Documentation

◆ DeallocationState() [1/2]

DeallocationState::DeallocationState ( Operation op)

Definition at line 97 of file BufferDeallocationOpInterface.cpp.

◆ DeallocationState() [2/2]

mlir::bufferization::DeallocationState::DeallocationState ( const DeallocationState )
delete

Member Function Documentation

◆ addMemrefToDeallocate()

void DeallocationState::addMemrefToDeallocate ( Value  memref,
Block block 
)

Remember the given 'memref' to deallocate it at the end of the 'block'.

Definition at line 118 of file BufferDeallocationOpInterface.cpp.

◆ dropMemrefToDeallocate()

void DeallocationState::dropMemrefToDeallocate ( Value  memref,
Block block 
)

Forget about a MemRef that we originally wanted to deallocate at the end of 'block', possibly because it already gets deallocated before the end of the block.

Definition at line 122 of file BufferDeallocationOpInterface.cpp.

◆ getLiveMemrefsIn()

void DeallocationState::getLiveMemrefsIn ( Block block,
SmallVectorImpl< Value > &  memrefs 
)

Return a sorted list of MemRef values which are live at the start of the given block.

Definition at line 126 of file BufferDeallocationOpInterface.cpp.

References mlir::Liveness::getLiveIn(), and isMemref().

◆ getMemrefsAndConditionsToDeallocate()

LogicalResult DeallocationState::getMemrefsAndConditionsToDeallocate ( OpBuilder builder,
Location  loc,
Block block,
SmallVectorImpl< Value > &  memrefs,
SmallVectorImpl< Value > &  conditions 
) const

For a given block, computes the list of MemRefs that potentially need to be deallocated at the end of that block.

This list also contains values that have to be retained (and are thus part of the list returned by getMemrefsToRetain) and is computed by taking the MemRefs in the 'in' set of the liveness analysis of 'block' appended by the set of MemRefs allocated in 'block' itself and subtracted by the set of MemRefs deallocated in 'block'. Note that we don't have to take the intersection of the liveness 'in' set with the 'out' set of the predecessor block because a value that is in the 'in' set must be defined in an ancestor block that dominates all direct predecessors and thus the 'in' set of this block is a subset of the 'out' sets of each predecessor.

memrefs = filter((liveIn(block) U allocated(block) U arguments(block)) \ deallocated(block), isMemRef)

The list of conditions is then populated by querying the internal datastructures for the ownership value of that MemRef.

Definition at line 185 of file BufferDeallocationOpInterface.cpp.

References mlir::OpBuilder::create(), mlir::emitError(), mlir::detail::enumerate(), mlir::get(), mlir::bufferization::Ownership::getIndicator(), mlir::Operation::getResult(), and mlir::bufferization::Ownership::isUnique().

◆ getMemrefsToRetain()

void DeallocationState::getMemrefsToRetain ( Block fromBlock,
Block toBlock,
ValueRange  destOperands,
SmallVectorImpl< Value > &  toRetain 
) const

Given two basic blocks and the values passed via block arguments to the destination block, compute the list of MemRefs that have to be retained in the 'fromBlock' to not run into a use-after-free situation.

This list consists of the MemRefs in the successor operand list of the terminator and the MemRefs in the 'out' set of the liveness analysis intersected with the 'in' set of the destination block.

toRetain = filter(successorOperands + (liveOut(fromBlock) insersect liveIn(toBlock)), isMemRef)

Definition at line 160 of file BufferDeallocationOpInterface.cpp.

References mlir::Liveness::getLiveIn(), mlir::Liveness::getLiveOut(), and isMemref().

◆ getMemrefWithUniqueOwnership()

std::pair< Value, Value > DeallocationState::getMemrefWithUniqueOwnership ( OpBuilder builder,
Value  memref,
Block block 
)

Given an SSA value of MemRef type, this function queries the ownership and if it is not already in the 'Unique' state, potentially inserts IR to get a new SSA value, returned as the first element of the pair, which has 'Unique' ownership and can be used instead of the passed Value with the the ownership indicator returned as the second element of the pair.

Definition at line 135 of file BufferDeallocationOpInterface.cpp.

References buildBoolValue(), mlir::OpBuilder::create(), mlir::bufferization::Ownership::getIndicator(), mlir::Value::getLoc(), mlir::Value::getParentBlock(), mlir::bufferization::Ownership::isUnique(), and updateOwnership().

◆ getOwnership()

Ownership DeallocationState::getOwnership ( Value  memref,
Block block 
) const

Returns the ownership of 'memref' for the given basic block.

Definition at line 114 of file BufferDeallocationOpInterface.cpp.

◆ getSymbolTable()

SymbolTableCollection* mlir::bufferization::DeallocationState::getSymbolTable ( )
inline

Returns the symbol cache to lookup functions from call operations to check attributes on the function operation.

Definition at line 187 of file BufferDeallocationOpInterface.h.

◆ resetOwnerships()

void DeallocationState::resetOwnerships ( ValueRange  memrefs,
Block block 
)

Removes ownerships associated with all values in the passed range for 'block'.

Definition at line 109 of file BufferDeallocationOpInterface.cpp.

References mlir::bufferization::Ownership::getUninitialized().

◆ updateOwnership()

void DeallocationState::updateOwnership ( Value  memref,
Ownership  ownership,
Block block = nullptr 
)

Small helper function to update the ownership map by taking the current ownership ('Uninitialized' state if not yet present), computing the join with the passed ownership and storing this new value in the map.

By default, it will be performed for the block where 'owned' is defined. If the ownership of the given value should be updated for another block, the 'block' argument can be explicitly passed.

Definition at line 99 of file BufferDeallocationOpInterface.cpp.

References mlir::Value::getParentBlock().

Referenced by getMemrefWithUniqueOwnership().


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