MLIR  17.0.0git
mlir::OperationFolder Class Reference

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, Location loc)
Get or create a constant for use in the specified block. More...

## Detailed Description

A utility class for folding operations, and unifying duplicated constants generated along the way.

Definition at line 33 of file FoldUtils.h.

## ◆ OperationFolder()

 mlir::OperationFolder::OperationFolder ( MLIRContext * ctx, OpBuilder::Listener * listener = nullptr )
inline

Definition at line 35 of file FoldUtils.h.

## ◆ clear()

 void OperationFolder::clear ( )

Clear out any constants cached inside of the folder.

Definition at line 188 of file FoldUtils.cpp.

## ◆ getOrCreateConstant()

 Value OperationFolder::getOrCreateConstant ( Block * block, Dialect * dialect, Attribute value, Type type, Location loc )

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 195 of file FoldUtils.cpp.

Referenced by replaceWithConstant().

## ◆ insertKnownConstant()

 bool OperationFolder::insertKnownConstant ( Operation * op, Attribute constValue = {} )

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 109 of file FoldUtils.cpp.

## ◆ notifyRemoval()

 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 164 of file FoldUtils.cpp.

Referenced by insertKnownConstant(), and tryToFold().

## ◆ 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.

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