MLIR  20.0.0git
Macros | Functions
TransformOps.cpp File Reference
#include "mlir/Dialect/Transform/IR/TransformOps.h"
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
#include "mlir/Conversion/LLVMCommon/ConversionTarget.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/CallInterfaces.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/FunctionImplementation.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Pass/Pass.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/ErrorHandling.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 DBGS()   (llvm::dbgs() << "[" DEBUG_TYPE "] ")
 
#define DEBUG_TYPE_MATCHER   "transform-matcher"
 
#define DBGS_MATCHER()   (llvm::dbgs() << "[" DEBUG_TYPE_MATCHER "] ")
 
#define DEBUG_MATCHER(x)   DEBUG_WITH_TYPE(DEBUG_TYPE_MATCHER, x)
 
#define GET_OP_CLASSES
 

Functions

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. More...
 
static ParseResult parseForeachMatchSymbols (OpAsmParser &parser, ArrayAttr &matchers, ArrayAttr &actions)
 Parses the comma-separated list of symbol reference pairs of the format @matcher -> @action. More...
 
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. More...
 
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. More...
 
template<typename... Tys>
static bool implementSameInterface (Type t1, Type t2)
 Returns true if both types implement one of the interfaces provided as template parameters. More...
 
static bool implementSameTransformInterface (Type t1, Type t2)
 Returns true if both types implement one of the transform dialect interfaces. More...
 
static DiagnosedSilenceableFailure verifyFunctionLikeConsumeAnnotations (FunctionOpInterface op, bool emitWarnings, bool alsoVerifyInternal=false)
 Checks that the attributes of the function-like operation have correct consumption effect annotations. More...
 
static DiagnosedSilenceableFailure applySequenceBlock (Block &block, transform::FailurePropagationMode mode, transform::TransformState &state, transform::TransformResults &results)
 Applies the transform ops contained in block. More...
 
static DiagnosedSilenceableFailure verifyNamedSequenceOp (transform::NamedSequenceOp op, bool emitWarnings)
 Verification of a NamedSequenceOp. More...
 
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. More...
 
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. More...
 
LogicalResult checkDoubleConsume (Value value, function_ref< InFlightDiagnostic()> reportError)
 

Macro Definition Documentation

◆ DBGS

#define DBGS ( )    (llvm::dbgs() << "[" DEBUG_TYPE "] ")

Definition at line 47 of file TransformOps.cpp.

◆ DBGS_MATCHER

#define DBGS_MATCHER ( )    (llvm::dbgs() << "[" DEBUG_TYPE_MATCHER "] ")

Definition at line 50 of file TransformOps.cpp.

◆ DEBUG_MATCHER

#define DEBUG_MATCHER (   x)    DEBUG_WITH_TYPE(DEBUG_TYPE_MATCHER, x)

Definition at line 51 of file TransformOps.cpp.

◆ DEBUG_TYPE

#define DEBUG_TYPE   "transform-dialect"

Definition at line 46 of file TransformOps.cpp.

◆ DEBUG_TYPE_MATCHER

#define DEBUG_TYPE_MATCHER   "transform-matcher"

Definition at line 49 of file TransformOps.cpp.

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 90 of file TransformOps.cpp.

Function Documentation

◆ applySequenceBlock()

static 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 1780 of file TransformOps.cpp.

◆ buildSequenceBody()

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

Definition at line 2308 of file TransformOps.cpp.

◆ checkDoubleConsume()

LogicalResult checkDoubleConsume ( Value  value,
function_ref< InFlightDiagnostic()>  reportError 
)

◆ ensurePayloadIsSeparateFromTransform()

static 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 74 of file TransformOps.cpp.

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

◆ forwardEmptyOperands()

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

Definition at line 129 of file TransformOps.cpp.

◆ implementSameInterface()

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

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

Definition at line 885 of file TransformOps.cpp.

Referenced by implementSameTransformInterface().

◆ implementSameTransformInterface()

static bool implementSameTransformInterface ( Type  t1,
Type  t2 
)
static

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

Definition at line 891 of file TransformOps.cpp.

References implementSameInterface().

◆ isValueUsePotentialConsumer()

static 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 2642 of file TransformOps.cpp.

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

Referenced by checkDoubleConsume().

◆ matchBlock()

static 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 848 of file TransformOps.cpp.

◆ parseForeachMatchSymbols()

static 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 1170 of file TransformOps.cpp.

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

◆ parseSequenceOpOperands()

static ParseResult parseSequenceOpOperands ( OpAsmParser parser,
std::optional< OpAsmParser::UnresolvedOperand > &  root,
Type rootType,
SmallVectorImpl< OpAsmParser::UnresolvedOperand > &  extraBindings,
SmallVectorImpl< Type > &  extraBindingTypes 
)
static

◆ printForeachMatchSymbols()

static 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 1193 of file TransformOps.cpp.

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

◆ printSequenceOpOperands()

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

◆ verifyFunctionLikeConsumeAnnotations()

static 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 1230 of file TransformOps.cpp.

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

Referenced by verifyNamedSequenceOp().

◆ verifyNamedSequenceOp()

static 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 2236 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()

static 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 2184 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().