MLIR  19.0.0git
Classes | Public Types | Public Member Functions | Friends | List of all members
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. More...
 
size_t getNumTopLevelMappings () const
 Returns the number of extra mappings for the top-level operation. More...
 
ArrayRef< MappedValuegetTopLevelMapping (size_t position) const
 Returns the position-th extra mapping for the top-level operation. More...
 
auto getPayloadOps (Value value) const
 Returns an iterator that enumerates all ops that the given transform IR value corresponds to. More...
 
ArrayRef< AttributegetParams (Value value) const
 Returns the list of parameters that the given transform IR value corresponds to. More...
 
auto getPayloadValues (Value handleValue) const
 Returns an iterator that enumerates all payload IR values that the given transform IR value corresponds to. More...
 
LogicalResult getHandlesForPayloadOp (Operation *op, SmallVectorImpl< Value > &handles, bool includeOutOfScope=false) const
 Populates handles with all handles pointing to the given Payload IR op. More...
 
LogicalResult getHandlesForPayloadValue (Value payloadValue, SmallVectorImpl< Value > &handles, bool includeOutOfScope=false) const
 Populates handles with all handles pointing to the given payload IR value. More...
 
DiagnosedSilenceableFailure applyTransform (TransformOpInterface transform)
 Applies the transformation specified by the given transform op and updates the state accordingly. More...
 
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. More...
 
LogicalResult mapBlockArgument (BlockArgument argument, ArrayRef< MappedValue > values)
 
RegionScope make_region_scope (Region &region)
 Creates a new region scope for the given region. More...
 
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. More...
 
template<typename Ty >
Ty * getExtension ()
 Returns the extension of the specified type. More...
 
template<typename Ty >
void removeExtension ()
 Removes the extension of the specified type. More...
 

Friends

class RegionScope
 
LogicalResult applyTransforms (Operation *, TransformOpInterface, const RaggedArray< MappedValue > &, const TransformOptions &, bool)
 Entry point to the Transform dialect infrastructure. More...
 
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 161 of file TransformInterfaces.h.

Member Typedef Documentation

◆ Param

Definition at line 163 of file TransformInterfaces.h.

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 436 of file TransformInterfaces.h.

◆ applyTransform()

DiagnosedSilenceableFailure transform::TransformState::applyTransform ( TransformOpInterface  transform)

◆ getExtension()

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

Returns the extension of the specified type.

Definition at line 448 of file TransformInterfaces.h.

◆ 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 97 of file TransformInterfaces.cpp.

◆ 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 116 of file TransformInterfaces.cpp.

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

◆ getNumTopLevelMappings()

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

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

Definition at line 223 of file TransformInterfaces.h.

◆ getOptions()

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

Definition at line 216 of file TransformInterfaces.h.

◆ getParams()

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

Returns the list of parameters that the given transform IR value corresponds to.

Definition at line 80 of file TransformInterfaces.cpp.

◆ getPayloadOps()

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

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

Ops may be erased while iterating; erased ops are not enumerated. This function is helpful for transformations that apply to a particular handle.

Definition at line 234 of file TransformInterfaces.h.

◆ 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 263 of file TransformInterfaces.h.

◆ 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 68 of file TransformInterfaces.cpp.

◆ 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 226 of file TransformInterfaces.h.

◆ 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 921 of file TransformInterfaces.h.

References RegionScope.

◆ mapBlockArgument()

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

Definition at line 193 of file TransformInterfaces.cpp.

References dispatchMappedValues().

◆ mapBlockArguments()

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 312 of file TransformInterfaces.h.

References mlir::Value::getParentRegion().

◆ removeExtension()

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

Removes the extension of the specified type.

Definition at line 460 of file TransformInterfaces.h.

Friends And Related Function Documentation

◆ applyTransforms

LogicalResult applyTransforms ( Operation ,
TransformOpInterface  ,
const RaggedArray< MappedValue > &  ,
const TransformOptions ,
bool   
)
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

TransformState detail::makeTransformStateForTesting ( Region region,
Operation payloadRoot 
)
friend

◆ RegionScope

friend class RegionScope
friend

Definition at line 366 of file TransformInterfaces.h.

Referenced by make_region_scope().


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