MLIR
18.0.0git
|
#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... | |
Attribute | replace (Attribute attr) |
Replace the given attribute/type, and recursively replace any sub elements. More... | |
Type | replace (Type type) |
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... | |
This class provides a utility for replacing attributes/types, and their sub elements. Multiple replacement functions may be registered.
Definition at line 121 of file AttrTypeSubElements.h.
using mlir::AttrTypeReplacer::ReplaceFn = std::function<ReplaceFnResult<T>(T)> |
Definition at line 158 of file AttrTypeSubElements.h.
using mlir::AttrTypeReplacer::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 156 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 193 of file AttrTypeSubElements.h.
References addReplacement(), and mlir::WalkResult::advance().
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 73 of file AttrTypeSubElements.cpp.
Referenced by addReplacement(), mlir::Attribute::replace(), mlir::Type::replace(), and replaceAllSymbolUsesImpl().
Definition at line 76 of file AttrTypeSubElements.cpp.
void AttrTypeReplacer::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 130 of file AttrTypeSubElements.cpp.
Replace the given attribute/type, and recursively replace any sub elements.
Returns either the new attribute/type, or nullptr in the case of failure.
Definition at line 222 of file AttrTypeSubElements.cpp.
Referenced by mlir::Attribute::replace(), mlir::Type::replace(), and updateSubElementImpl().
Definition at line 226 of file AttrTypeSubElements.cpp.
void AttrTypeReplacer::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 80 of file AttrTypeSubElements.cpp.