MLIR
20.0.0git
|
A utility class for folding operations, and unifying duplicated constants generated along the way. More...
#include "mlir/Transforms/FoldUtils.h"
Public Member Functions | |
OperationFolder (MLIRContext *ctx, OpBuilder::Listener *listener=nullptr) | |
LogicalResult | tryToFold (Operation *op, bool *inPlaceUpdate=nullptr) |
Tries to perform folding on the given op , including unifying deduplicated constants. More... | |
bool | insertKnownConstant (Operation *op, Attribute constValue={}) |
Tries to fold a pre-existing constant operation. More... | |
void | notifyRemoval (Operation *op) |
Notifies that the given constant op should be remove from this OperationFolder's internal bookkeeping. More... | |
void | clear () |
Clear out any constants cached inside of the folder. More... | |
Value | getOrCreateConstant (Block *block, Dialect *dialect, Attribute value, Type type) |
Get or create a constant for use in the specified block. More... | |
A utility class for folding operations, and unifying duplicated constants generated along the way.
Definition at line 33 of file FoldUtils.h.
|
inline |
Definition at line 35 of file FoldUtils.h.
void OperationFolder::clear | ( | ) |
Clear out any constants cached inside of the folder.
Definition at line 195 of file FoldUtils.cpp.
Value OperationFolder::getOrCreateConstant | ( | Block * | block, |
Dialect * | dialect, | ||
Attribute | value, | ||
Type | type | ||
) |
Get or create a constant for use in the specified block.
Get or create a constant using the given builder.
The constant may be created in a parent block. On success this returns the constant operation, nullptr otherwise.
On success this returns the constant operation, nullptr otherwise.
Definition at line 202 of file FoldUtils.cpp.
References getInsertionRegion(), mlir::Operation::getResult(), and mlir::OpBuilder::setInsertionPointToStart().
Referenced by replaceWithConstant().
Tries to fold a pre-existing constant operation.
constValue
represents the value of the constant, and can be optionally passed if the value is already known (e.g. if the constant was discovered by m_Constant). This is purely an optimization opportunity for callers that already know the value of the constant. Returns false if an existing constant for op
already exists in the folder, in which case op
is replaced and erased. Otherwise, returns true and op
is inserted into the folder (and hoisted if necessary).
Definition at line 111 of file FoldUtils.cpp.
References mlir::Block::front(), mlir::Region::front(), mlir::Operation::getBlock(), mlir::Operation::getDialect(), getInsertionRegion(), mlir::Operation::getResults(), mlir::m_Constant(), mlir::matchPattern(), mlir::Operation::moveBefore(), notifyRemoval(), mlir::RewriterBase::replaceOp(), mlir::Operation::result_type_begin(), and mlir::Operation::setLoc().
void OperationFolder::notifyRemoval | ( | Operation * | op | ) |
Notifies that the given constant op
should be remove from this OperationFolder's internal bookkeeping.
Note: this method must be called if a constant op is to be deleted externally to this OperationFolder. op
must be a constant op.
Definition at line 171 of file FoldUtils.cpp.
References mlir::Operation::getBlock(), getInsertionRegion(), mlir::Operation::getResult(), mlir::Value::getType(), mlir::m_Constant(), and mlir::matchPattern().
Referenced by insertKnownConstant(), and tryToFold().
LogicalResult OperationFolder::tryToFold | ( | Operation * | op, |
bool * | inPlaceUpdate = nullptr |
||
) |
Tries to perform folding on the given op
, including unifying deduplicated constants.
If successful, replaces op
's uses with folded results, and returns success. If the op was completely folded it is erased. If it is just updated in place, inPlaceUpdate
is set to true.
Definition at line 70 of file FoldUtils.cpp.
References mlir::Block::front(), mlir::Operation::getBlock(), mlir::OpBuilder::getListener(), mlir::Operation::moveBefore(), notifyRemoval(), mlir::RewriterBase::replaceOp(), and mlir::Operation::setLoc().