MLIR 22.0.0git
mlir::transform::TransformState Class Reference

The state maintained across applications of various ops implementing the TransformOpInterface. More...

#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"

Classes

class  Extension
 Base class for TransformState extensions that allow TransformState to contain user-specified information in the state object. More...
class  RegionScope
 A RAII object maintaining a "stack frame" for a transform IR region. More...

Public Types

using Param = transform::Param

Public Member Functions

const TransformOptionsgetOptions () const
OperationgetTopLevel () const
 Returns the op at which the transformation state is rooted.
size_t getNumTopLevelMappings () const
 Returns the number of extra mappings for the top-level operation.
ArrayRef< MappedValuegetTopLevelMapping (size_t position) const
 Returns the position-th extra mapping for the top-level operation.
auto getPayloadOps (Value value) const
 Returns an iterator that enumerates all ops that the given transform IR value corresponds to.
ArrayRef< AttributegetParams (Value value) const
 Returns the list of parameters that the given transform IR value corresponds to.
auto getPayloadValues (Value handleValue) const
 Returns an iterator that enumerates all payload IR values that the given transform IR value corresponds to.
LogicalResult getHandlesForPayloadOp (Operation *op, SmallVectorImpl< Value > &handles, bool includeOutOfScope=false) const
 Populates handles with all handles pointing to the given Payload IR op.
LogicalResult getHandlesForPayloadValue (Value payloadValue, SmallVectorImpl< Value > &handles, bool includeOutOfScope=false) const
 Populates handles with all handles pointing to the given payload IR value.
DiagnosedSilenceableFailure applyTransform (TransformOpInterface transform)
 Applies the transformation specified by the given transform op and updates the state accordingly.
LogicalResult mapBlockArguments (BlockArgument argument, ArrayRef< Operation * > operations)
 Records the mapping between a block argument in the transform IR and a list of operations in the payload IR.
LogicalResult mapBlockArgument (BlockArgument argument, ArrayRef< MappedValue > values)
LogicalResult mapBlockArguments (Block::BlockArgListType arguments, ArrayRef< SmallVector< MappedValue > > mapping)
RegionScope make_region_scope (Region &region)
 Creates a new region scope for the given region.
template<typename Ty, typename... Args>
Ty & addExtension (Args &&...args)
 Adds a new Extension of the type specified as template parameter, constructing it with the arguments provided.
template<typename Ty>
Ty * getExtension ()
 Returns the extension of the specified type.
template<typename Ty>
void removeExtension ()
 Removes the extension of the specified type.

Friends

class RegionScope
LogicalResult applyTransforms (Operation *payloadRoot, TransformOpInterface transform, const RaggedArray< MappedValue > &extraMapping={}, const TransformOptions &options=TransformOptions(), bool enforceToplevelTransformOp=true, function_ref< void(TransformState &)> stateInitializer=nullptr, function_ref< LogicalResult(TransformState &)> stateExporter=nullptr)
 Entry point to the Transform dialect infrastructure.
TransformState detail::makeTransformStateForTesting (Region *region, Operation *payloadRoot)

Detailed Description

The state maintained across applications of various ops implementing the TransformOpInterface.

The operations implementing this interface and the surrounding structure are referred to as transform IR. The operations to which transformations apply are referred to as payload IR. Transform IR operates on values that can be associated either with a list of payload IR operations (such values are referred to as handles) or with a list of parameters represented as attributes. The state thus contains the mapping between values defined in the transform IR ops and either payload IR ops or parameters. For payload ops, the mapping is many-to-many and the reverse mapping is also stored. The "expensive-checks" option can be passed to the constructor at transformation execution time that transform IR values used as operands by a transform IR operation are not associated with dangling pointers to payload IR operations that are known to have been erased by previous transformation through the same or a different transform IR value.

A reference to this class is passed as an argument to "apply" methods of the transform op interface. Thus the "apply" method can call either state.getPayloadOps( getSomeOperand() ) to obtain the list of operations or state.getParams( getSomeOperand() ) to obtain the list of parameters associated with its operand. The method is expected to populate the TransformResults class instance in order to update the mapping. The applyTransform method takes care of propagating the state of TransformResults into the instance of this class.

When applying transform IR operations with regions, the client is expected to create a RegionScope RAII object to create a new "stack frame" for values defined inside the region. The mappings from and to these values will be automatically dropped when the object goes out of scope, typically at the end of the apply function of the parent operation. If a region contains blocks with arguments, the client can map those arguments to payload IR ops using mapBlockArguments.

Definition at line 173 of file TransformInterfaces.h.

Member Typedef Documentation

◆ Param

Member Function Documentation

◆ addExtension()

template<typename Ty, typename... Args>
Ty & mlir::transform::TransformState::addExtension ( Args &&... args)
inline

Adds a new Extension of the type specified as template parameter, constructing it with the arguments provided.

The extension is owned by the TransformState. It is expected that the state does not already have an extension of the same type. Extension constructors are expected to take a reference to TransformState as first argument, automatically supplied by this call.

Definition at line 452 of file TransformInterfaces.h.

References mlir::TypeID::get(), and result.

◆ applyTransform()

◆ getExtension()

template<typename Ty>
Ty * mlir::transform::TransformState::getExtension ( )
inline

Returns the extension of the specified type.

Definition at line 464 of file TransformInterfaces.h.

References mlir::TypeID::get().

◆ getHandlesForPayloadOp()

LogicalResult transform::TransformState::getHandlesForPayloadOp ( Operation * op,
SmallVectorImpl< Value > & handles,
bool includeOutOfScope = false ) const

Populates handles with all handles pointing to the given Payload IR op.

Returns success if such handles exist, failure otherwise. If includeOutOfScope is set to "true", handles that are defined in regions beyond the most recent isolated from above region are included.

Definition at line 93 of file TransformInterfaces.cpp.

References mlir::Region::getParentOp(), mlir::Operation::hasTrait(), and success().

◆ getHandlesForPayloadValue()

LogicalResult transform::TransformState::getHandlesForPayloadValue ( Value payloadValue,
SmallVectorImpl< Value > & handles,
bool includeOutOfScope = false ) const

Populates handles with all handles pointing to the given payload IR value.

Returns success if such handles exist, failure otherwise. If includeOutOfScope is set to "true", handles that are defined in regions beyond the most recent isolated from above region are included.

Definition at line 112 of file TransformInterfaces.cpp.

References mlir::Region::getParentOp(), mlir::Operation::hasTrait(), and success().

◆ getNumTopLevelMappings()

size_t mlir::transform::TransformState::getNumTopLevelMappings ( ) const
inline

Returns the number of extra mappings for the top-level operation.

Definition at line 237 of file TransformInterfaces.h.

Referenced by mlir::transform::detail::mapPossibleTopLevelTransformOpBlockArguments().

◆ getOptions()

const TransformOptions & mlir::transform::TransformState::getOptions ( ) const
inline

◆ getParams()

ArrayRef< Attribute > transform::TransformState::getParams ( Value value) const

◆ getPayloadOps()

auto mlir::transform::TransformState::getPayloadOps ( Value value) const
inline

◆ getPayloadValues()

auto mlir::transform::TransformState::getPayloadValues ( Value handleValue) const
inline

Returns an iterator that enumerates all payload IR values that the given transform IR value corresponds to.

Definition at line 277 of file TransformInterfaces.h.

Referenced by mlir::transform::detail::appendValueMappings(), mlir::transform::SingleValueMatcherOpTrait< OpTy >::apply(), and mlir::transform::detail::forwardTerminatorOperands().

◆ getTopLevel()

Operation * transform::TransformState::getTopLevel ( ) const

Returns the op at which the transformation state is rooted.

This is typically helpful for transformations that apply globally.

Definition at line 64 of file TransformInterfaces.cpp.

Referenced by applyTransform(), and mlir::transform::detail::mapPossibleTopLevelTransformOpBlockArguments().

◆ getTopLevelMapping()

ArrayRef< MappedValue > mlir::transform::TransformState::getTopLevelMapping ( size_t position) const
inline

Returns the position-th extra mapping for the top-level operation.

Definition at line 240 of file TransformInterfaces.h.

Referenced by mlir::transform::detail::mapPossibleTopLevelTransformOpBlockArguments().

◆ make_region_scope()

TransformState::RegionScope mlir::transform::TransformState::make_region_scope ( Region & region)
inline

Creates a new region scope for the given region.

Creates a RAII object the lifetime of which corresponds to the new mapping for transform IR values defined in the given region.

The region is expected to be nested in the currently processed region.

Values defined in surrounding regions remain accessible.

Definition at line 937 of file TransformInterfaces.h.

References RegionScope.

Referenced by matchBlock().

◆ mapBlockArgument()

LogicalResult transform::TransformState::mapBlockArgument ( BlockArgument argument,
ArrayRef< MappedValue > values )

◆ mapBlockArguments() [1/2]

LogicalResult transform::TransformState::mapBlockArguments ( Block::BlockArgListType arguments,
ArrayRef< SmallVector< MappedValue > > mapping )

Definition at line 205 of file TransformInterfaces.cpp.

References mapBlockArgument(), and success().

◆ mapBlockArguments() [2/2]

LogicalResult mlir::transform::TransformState::mapBlockArguments ( BlockArgument argument,
ArrayRef< Operation * > operations )
inline

Records the mapping between a block argument in the transform IR and a list of operations in the payload IR.

The arguments must be defined in blocks of the currently processed transform IR region, typically after a region scope is defined.

Returns failure if the payload does not satisfy the conditions associated with the type of the handle value.

Definition at line 326 of file TransformInterfaces.h.

References mlir::Region::back(), and mlir::Value::getParentRegion().

Referenced by mlir::transform::detail::mapPossibleTopLevelTransformOpBlockArguments(), and matchBlock().

◆ removeExtension()

template<typename Ty>
void mlir::transform::TransformState::removeExtension ( )
inline

Removes the extension of the specified type.

Definition at line 476 of file TransformInterfaces.h.

References mlir::TypeID::get().

◆ applyTransforms

LogicalResult applyTransforms ( Operation * payloadRoot,
TransformOpInterface transform,
const RaggedArray< MappedValue > & extraMapping = {},
const TransformOptions & options = TransformOptions(),
bool enforceToplevelTransformOp = true,
function_ref< void(TransformState &)> stateInitializer = nullptr,
function_ref< LogicalResult(TransformState &)> stateExporter = nullptr )
friend

Entry point to the Transform dialect infrastructure.

Applies the transformation specified by transform to payload IR contained in payloadRoot. The transform operation may contain other operations that will be executed following the internal logic of the operation. It must have the PossibleTopLevelTransformOp trait and not have any operands. This function internally keeps track of the transformation state.

◆ detail::makeTransformStateForTesting

◆ RegionScope

friend class RegionScope
friend

Definition at line 382 of file TransformInterfaces.h.

Referenced by make_region_scope().


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