MLIR
20.0.0git
|
This class provides a base utility for replacing attributes/types, and their sub elements. More...
#include "mlir/IR/AttrTypeSubElements.h"
Public Types | |
template<typename T > | |
using | ReplaceFnResult = std::optional< std::pair< T, WalkResult > > |
A replacement mapping function, which returns either std::nullopt (to signal the element wasn't handled), or a pair of the replacement element and a WalkResult. More... | |
template<typename T > | |
using | ReplaceFn = std::function< ReplaceFnResult< T >(T)> |
Public Member Functions | |
void | replaceElementsIn (Operation *op, bool replaceAttrs=true, bool replaceLocs=false, bool replaceTypes=false) |
Replace the elements within the given operation. More... | |
void | recursivelyReplaceElementsIn (Operation *op, bool replaceAttrs=true, bool replaceLocs=false, bool replaceTypes=false) |
Replace the elements within the given operation, and all nested operations. More... | |
void | addReplacement (ReplaceFn< Attribute > fn) |
Register a replacement function for mapping a given attribute or type. More... | |
void | addReplacement (ReplaceFn< Type > fn) |
template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<0>, typename BaseT = std::conditional_t<std::is_base_of_v<Attribute, T>, Attribute, Type>, typename ResultT = std::invoke_result_t<FnT, T>> | |
std::enable_if_t<!std::is_same_v< T, BaseT >||!std::is_convertible_v< ResultT, ReplaceFnResult< BaseT > > > | addReplacement (FnT &&callback) |
Register a replacement function that doesn't match the default signature, either because it uses a derived parameter type, or it uses a simplified result type. More... | |
Protected Member Functions | |
Attribute | replaceBase (Attribute attr) |
Invokes the registered replacement functions from most recently registered to least recently registered until a successful replacement is returned. More... | |
Type | replaceBase (Type type) |
This class provides a base utility for replacing attributes/types, and their sub elements.
Multiple replacement functions may be registered.
This base utility is uncached. Users can choose between two cached versions of this replacer:
AttrTypeReplacer
.CyclicAttrTypeReplacer
.Concrete implementations implement the following replace
entry functions:
Definition at line 134 of file AttrTypeSubElements.h.
using mlir::detail::AttrTypeReplacerBase< Concrete >::ReplaceFn = std::function<ReplaceFnResult<T>(T)> |
Definition at line 165 of file AttrTypeSubElements.h.
using mlir::detail::AttrTypeReplacerBase< Concrete >::ReplaceFnResult = std::optional<std::pair<T, WalkResult> > |
A replacement mapping function, which returns either std::nullopt (to signal the element wasn't handled), or a pair of the replacement element and a WalkResult.
Definition at line 163 of file AttrTypeSubElements.h.
|
inline |
Register a replacement function that doesn't match the default signature, either because it uses a derived parameter type, or it uses a simplified result type.
Definition at line 200 of file AttrTypeSubElements.h.
References mlir::detail::AttrTypeReplacerBase< Concrete >::addReplacement(), and mlir::WalkResult::advance().
void detail::AttrTypeReplacerBase::addReplacement | ( | ReplaceFn< Attribute > | fn | ) |
Register a replacement function for mapping a given attribute or type.
A replacement function must be convertible to any of the following forms(where T
is a class derived from Type
or Attribute
, and BaseT
is either Type
or Attribute
respectively):
std::nullopt
to signify that additional replacement functions may be applied (i.e. this function doesn't handle that instance).skip
result, for example, will not recursively process the resultant attribute or type value.Note: When replacing, the mostly recently added replacement functions will be invoked first.
Definition at line 74 of file AttrTypeSubElements.cpp.
Referenced by mlir::detail::AttrTypeReplacerBase< Concrete >::addReplacement(), mlir::spirv::convertMemRefTypesAndAttrs(), handleLoopAnnotations(), mlir::LLVM::legalizeDIExpressionsRecursively(), remapInlinedLocations(), mlir::Attribute::replace(), mlir::Type::replace(), and replaceAllSymbolUsesImpl().
void detail::AttrTypeReplacerBase::addReplacement | ( | ReplaceFn< Type > | fn | ) |
Definition at line 80 of file AttrTypeSubElements.cpp.
void detail::AttrTypeReplacerBase::recursivelyReplaceElementsIn | ( | Operation * | op, |
bool | replaceAttrs = true , |
||
bool | replaceLocs = false , |
||
bool | replaceTypes = false |
||
) |
Replace the elements within the given operation, and all nested operations.
Definition at line 137 of file AttrTypeSubElements.cpp.
References mlir::Operation::walk().
Referenced by mlir::spirv::convertMemRefTypesAndAttrs(), handleLoopAnnotations(), mlir::LLVM::legalizeDIExpressionsRecursively(), and remapInlinedLocations().
|
protected |
Invokes the registered replacement functions from most recently registered to least recently registered until a successful replacement is returned.
Unless skipping is requested, invokes replace
on sub-elements of the current attr/type.
Definition at line 221 of file AttrTypeSubElements.cpp.
Definition at line 227 of file AttrTypeSubElements.cpp.
References replaceElementImpl().
void detail::AttrTypeReplacerBase::replaceElementsIn | ( | Operation * | op, |
bool | replaceAttrs = true , |
||
bool | replaceLocs = false , |
||
bool | replaceTypes = false |
||
) |
Replace the elements within the given operation.
If replaceAttrs
is true, this updates the attribute dictionary of the operation. If replaceLocs
is true, this also updates its location, and the locations of any nested block arguments. If replaceTypes
is true, this also updates the result types of the operation, and the types of any nested block arguments.
Definition at line 86 of file AttrTypeSubElements.cpp.
References mlir::Operation::getAttrDictionary(), mlir::Operation::getLoc(), mlir::Operation::getRegions(), mlir::Operation::getResults(), mlir::Operation::setAttrs(), and mlir::Operation::setLoc().
Referenced by replaceAllSymbolUsesImpl().