MLIR 22.0.0git
TransformOps.cpp File Reference
#include "mlir/Dialect/Transform/IR/TransformOps.h"
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Dialect/Transform/IR/TransformAttrs.h"
#include "mlir/Dialect/Transform/IR/TransformDialect.h"
#include "mlir/Dialect/Transform/IR/TransformTypes.h"
#include "mlir/Dialect/Transform/Interfaces/MatchInterfaces.h"
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/Dominance.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/IR/OperationSupport.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/Verifier.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/FunctionImplementation.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Pass/PassRegistry.h"
#include "mlir/Transforms/CSE.h"
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/Transforms/LoopInvariantCodeMotionUtils.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugLog.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/InterleavedRange.h"
#include <optional>
#include "mlir/Dialect/Transform/IR/TransformOps.cpp.inc"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "transform-dialect"
#define DEBUG_TYPE_MATCHER   "transform-matcher"
#define GET_OP_CLASSES

Functions

static ParseResult parseApplyRegisteredPassOptions (OpAsmParser &parser, DictionaryAttr &options, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &dynamicOptions)
static void printApplyRegisteredPassOptions (OpAsmPrinter &printer, Operation *op, DictionaryAttr options, ValueRange dynamicOptions)
static ParseResult parseSequenceOpOperands (OpAsmParser &parser, std::optional< OpAsmParser::UnresolvedOperand > &root, Type &rootType, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &extraBindings, SmallVectorImpl< Type > &extraBindingTypes)
static void printSequenceOpOperands (OpAsmPrinter &printer, Operation *op, Value root, Type rootType, ValueRange extraBindings, TypeRange extraBindingTypes)
static void printForeachMatchSymbols (OpAsmPrinter &printer, Operation *op, ArrayAttr matchers, ArrayAttr actions)
 Prints the comma-separated list of symbol reference pairs of the format @matcher -> @action.
static ParseResult parseForeachMatchSymbols (OpAsmParser &parser, ArrayAttr &matchers, ArrayAttr &actions)
 Parses the comma-separated list of symbol reference pairs of the format @matcher -> @action.
static DiagnosedSilenceableFailure ensurePayloadIsSeparateFromTransform (transform::TransformOpInterface transform, Operation *payload)
 Helper function to check if the given transform op is contained in (or equal to) the given payload target op.
static void forwardEmptyOperands (Block *block, transform::TransformState &state, transform::TransformResults &results)
static DiagnosedSilenceableFailure matchBlock (Block &block, ArrayRef< SmallVector< transform::MappedValue > > blockArgumentMapping, transform::TransformState &state, SmallVectorImpl< SmallVector< transform::MappedValue > > &mappings)
 Applies matcher operations from the given block using blockArgumentMapping to initialize block arguments.
template<typename... Tys>
static bool implementSameInterface (Type t1, Type t2)
 Returns true if both types implement one of the interfaces provided as template parameters.
static bool implementSameTransformInterface (Type t1, Type t2)
 Returns true if both types implement one of the transform dialect interfaces.
static DiagnosedSilenceableFailure verifyFunctionLikeConsumeAnnotations (FunctionOpInterface op, bool emitWarnings, bool alsoVerifyInternal=false)
 Checks that the attributes of the function-like operation have correct consumption effect annotations.
static DiagnosedSilenceableFailure applySequenceBlock (Block &block, transform::FailurePropagationMode mode, transform::TransformState &state, transform::TransformResults &results)
 Applies the transform ops contained in block.
static DiagnosedSilenceableFailure verifyNamedSequenceOp (transform::NamedSequenceOp op, bool emitWarnings)
 Verification of a NamedSequenceOp.
static DiagnosedSilenceableFailure verifyYieldingSingleBlockOp (FunctionOpInterface op, bool allowExternal)
 Verifies that a symbol function-like transform dialect operation has the signature and the terminator that have conforming types, i.e., types implementing the same transform dialect type interface.
template<typename FnTy>
static void buildSequenceBody (OpBuilder &builder, OperationState &state, Type bbArgType, TypeRange extraBindingTypes, FnTy bodyBuilder)
static bool isValueUsePotentialConsumer (OpOperand &use)
 Returns true if the given op operand may be consuming the handle value in the Transform IR.
LogicalResult checkDoubleConsume (Value value, function_ref< InFlightDiagnostic()> reportError)

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "transform-dialect"

Definition at line 45 of file TransformOps.cpp.

◆ DEBUG_TYPE_MATCHER

#define DEBUG_TYPE_MATCHER   "transform-matcher"

Definition at line 46 of file TransformOps.cpp.

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 92 of file TransformOps.cpp.

Function Documentation

◆ applySequenceBlock()

DiagnosedSilenceableFailure applySequenceBlock ( Block & block,
transform::FailurePropagationMode mode,
transform::TransformState & state,
transform::TransformResults & results )
static

Applies the transform ops contained in block.

Maps results to the same values as the operands of the block terminator.

Definition at line 2016 of file TransformOps.cpp.

References mlir::transform::TransformState::applyTransform(), forwardEmptyOperands(), mlir::transform::detail::forwardTerminatorOperands(), result, mlir::DiagnosedSilenceableFailure::success(), and mlir::Block::without_terminator().

◆ buildSequenceBody()

template<typename FnTy>
void buildSequenceBody ( OpBuilder & builder,
OperationState & state,
Type bbArgType,
TypeRange extraBindingTypes,
FnTy bodyBuilder )
static

◆ checkDoubleConsume()

◆ ensurePayloadIsSeparateFromTransform()

DiagnosedSilenceableFailure ensurePayloadIsSeparateFromTransform ( transform::TransformOpInterface transform,
Operation * payload )
static

Helper function to check if the given transform op is contained in (or equal to) the given payload target op.

In that case, an error is returned. Transforming transform IR that is currently executing is generally unsafe.

Definition at line 76 of file TransformOps.cpp.

References diag(), mlir::Operation::getLoc(), mlir::Operation::getParentOp(), and mlir::DiagnosedSilenceableFailure::success().

◆ forwardEmptyOperands()

void forwardEmptyOperands ( Block * block,
transform::TransformState & state,
transform::TransformResults & results )
static

◆ implementSameInterface()

template<typename... Tys>
bool implementSameInterface ( Type t1,
Type t2 )
static

Returns true if both types implement one of the interfaces provided as template parameters.

Definition at line 1123 of file TransformOps.cpp.

Referenced by implementSameTransformInterface().

◆ implementSameTransformInterface()

bool implementSameTransformInterface ( Type t1,
Type t2 )
static

Returns true if both types implement one of the transform dialect interfaces.

Definition at line 1129 of file TransformOps.cpp.

References implementSameInterface().

◆ isValueUsePotentialConsumer()

bool isValueUsePotentialConsumer ( OpOperand & use)
static

Returns true if the given op operand may be consuming the handle value in the Transform IR.

That is, if it may have a Free effect on it.

Definition at line 2863 of file TransformOps.cpp.

References mlir::IROperand< DerivedT, IRValueT >::get(), and mlir::detail::IROperandBase::getOwner().

Referenced by checkDoubleConsume().

◆ matchBlock()

DiagnosedSilenceableFailure matchBlock ( Block & block,
ArrayRef< SmallVector< transform::MappedValue > > blockArgumentMapping,
transform::TransformState & state,
SmallVectorImpl< SmallVector< transform::MappedValue > > & mappings )
static

Applies matcher operations from the given block using blockArgumentMapping to initialize block arguments.

Updates state accordingly. If any of the matcher produces a silenceable failure, discards it (printing the content to the debug output stream) and returns failure. If any of the matchers produces a definite failure, reports it and returns failure. If all matchers in the block succeed, populates mappings with the payload entities associated with the block terminator operands. Note that mappings will be cleared before that.

Definition at line 1086 of file TransformOps.cpp.

References mlir::transform::TransformState::applyTransform(), mlir::DiagnosedSilenceableFailure::definiteFailure(), diag(), mlir::emitDefiniteFailure(), mlir::Block::getArguments(), mlir::Operation::getOperands(), mlir::Block::getParent(), mlir::Block::getTerminator(), mlir::transform::TransformState::make_region_scope(), mlir::transform::TransformState::mapBlockArguments(), mlir::transform::detail::prepareValueMappings(), mlir::DiagnosedSilenceableFailure::success(), and mlir::Block::without_terminator().

◆ parseApplyRegisteredPassOptions()

◆ parseForeachMatchSymbols()

ParseResult parseForeachMatchSymbols ( OpAsmParser & parser,
ArrayAttr & matchers,
ArrayAttr & actions )
static

Parses the comma-separated list of symbol reference pairs of the format @matcher -> @action.

Definition at line 1404 of file TransformOps.cpp.

References ArrayAttr(), mlir::Builder::getArrayAttr(), mlir::AsmParser::getBuilder(), mlir::AsmParser::parseArrow(), mlir::AsmParser::parseOptionalComma(), mlir::AsmParser::parseSymbolName(), and success().

◆ parseSequenceOpOperands()

◆ printApplyRegisteredPassOptions()

void printApplyRegisteredPassOptions ( OpAsmPrinter & printer,
Operation * op,
DictionaryAttr options,
ValueRange dynamicOptions )
static

◆ printForeachMatchSymbols()

void printForeachMatchSymbols ( OpAsmPrinter & printer,
Operation * op,
ArrayAttr matchers,
ArrayAttr actions )
static

Prints the comma-separated list of symbol reference pairs of the format @matcher -> @action.

Definition at line 1427 of file TransformOps.cpp.

References ArrayAttr(), mlir::OpAsmPrinter::decreaseIndent(), mlir::OpAsmPrinter::increaseIndent(), and mlir::OpAsmPrinter::printNewline().

◆ printSequenceOpOperands()

void printSequenceOpOperands ( OpAsmPrinter & printer,
Operation * op,
Value root,
Type rootType,
ValueRange extraBindings,
TypeRange extraBindingTypes )
static

Definition at line 2838 of file TransformOps.cpp.

References mlir::OpAsmPrinter::printOperands().

◆ verifyFunctionLikeConsumeAnnotations()

DiagnosedSilenceableFailure verifyFunctionLikeConsumeAnnotations ( FunctionOpInterface op,
bool emitWarnings,
bool alsoVerifyInternal = false )
static

Checks that the attributes of the function-like operation have correct consumption effect annotations.

If alsoVerifyInternal, checks for annotations being present even if they can be inferred from the body.

Definition at line 1464 of file TransformOps.cpp.

References mlir::emitWarning(), mlir::transform::getConsumedBlockArguments(), and mlir::DiagnosedSilenceableFailure::success().

Referenced by verifyNamedSequenceOp().

◆ verifyNamedSequenceOp()

DiagnosedSilenceableFailure verifyNamedSequenceOp ( transform::NamedSequenceOp op,
bool emitWarnings )
static

Verification of a NamedSequenceOp.

This does not report the error immediately, so it can be used to check for op's well-formedness before the verifier runs, e.g., during trait verification.

Definition at line 2466 of file TransformOps.cpp.

References diag(), mlir::emitSilenceableFailure(), mlir::Operation::getAttr(), mlir::Operation::getLoc(), mlir::Operation::getNumOperands(), mlir::Operation::getOperands(), mlir::Operation::getParentOfType(), mlir::Operation::getParentWithTrait(), mlir::OperandRange::getType(), verifyFunctionLikeConsumeAnnotations(), and verifyYieldingSingleBlockOp().

◆ verifyYieldingSingleBlockOp()

DiagnosedSilenceableFailure verifyYieldingSingleBlockOp ( FunctionOpInterface op,
bool allowExternal )
static

Verifies that a symbol function-like transform dialect operation has the signature and the terminator that have conforming types, i.e., types implementing the same transform dialect type interface.

If allowExternal is set, allow external symbols (declarations) and don't check the terminator as it may not exist.

Definition at line 2414 of file TransformOps.cpp.

References diag(), mlir::emitSilenceableFailure(), mlir::Operation::getLoc(), mlir::Operation::getNumOperands(), mlir::Operation::getOperands(), mlir::Operation::getParentOfType(), mlir::OperandRange::getType(), and mlir::DiagnosedSilenceableFailure::success().

Referenced by verifyNamedSequenceOp().