My Project
Public Member Functions | Static Public Member Functions | List of all members
mlir::FoldingHook< ConcreteType, isSingleResult, typename > Class Template Reference

#include <OpDefinition.h>

Public Member Functions

LogicalResult fold (ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results)
 

Static Public Member Functions

static LogicalResult foldHook (Operation *op, ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results)
 

Detailed Description

template<typename ConcreteType, bool isSingleResult, typename = void>
class mlir::FoldingHook< ConcreteType, isSingleResult, typename >

This template defines the foldHook as used by AbstractOperation.

The default implementation uses a general fold method that can be defined on custom ops which can return multiple results.

Member Function Documentation

◆ fold()

template<typename ConcreteType, bool isSingleResult, typename = void>
LogicalResult mlir::FoldingHook< ConcreteType, isSingleResult, typename >::fold ( ArrayRef< Attribute operands,
SmallVectorImpl< OpFoldResult > &  results 
)
inline

This hook implements a generalized folder for this operation. Operations can implement this to provide simplifications rules that are applied by the Builder::createOrFold API and the canonicalization pass.

This is an intentionally limited interface - implementations of this hook can only perform the following changes to the operation:

  1. They can leave the operation alone and without changing the IR, and return failure.
  2. They can mutate the operation in place, without changing anything else in the IR. In this case, return success.
  3. They can return a list of existing values that can be used instead of the operation. In this case, fill in the results list and return success. The caller will remove the operation and use those results instead.

This allows expression of some simple in-place canonicalizations (e.g. "x+0 -> x", "min(x,y,x,z) -> min(x,y,z)", "x+y-x -> y", etc), as well as generalized constant folding.

If not overridden, this fallback implementation always fails to fold.

◆ foldHook()

template<typename ConcreteType, bool isSingleResult, typename = void>
static LogicalResult mlir::FoldingHook< ConcreteType, isSingleResult, typename >::foldHook ( Operation op,
ArrayRef< Attribute operands,
SmallVectorImpl< OpFoldResult > &  results 
)
inlinestatic

This is an implementation detail of the constant folder hook for AbstractOperation.


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