MLIR  17.0.0git
Classes | Public Member Functions | Protected Member Functions | List of all members
mlir::Pattern Class Reference

This class contains all of the data related to a pattern, but does not contain any methods or logic for the actual matching. More...

#include "mlir/IR/PatternMatch.h"

+ Inheritance diagram for mlir::Pattern:

Classes

struct  MatchAnyOpTypeTag
 This class acts as a special tag that makes the desire to match "any" operation type explicit. More...
 
struct  MatchInterfaceOpTypeTag
 This class acts as a special tag that makes the desire to match any operation that implements a given interface explicit. More...
 
struct  MatchTraitOpTypeTag
 This class acts as a special tag that makes the desire to match any operation that implements a given trait explicit. More...
 

Public Member Functions

ArrayRef< OperationNamegetGeneratedOps () const
 Return a list of operations that may be generated when rewriting an operation instance with this pattern. More...
 
std::optional< OperationNamegetRootKind () const
 Return the root node that this pattern matches. More...
 
std::optional< TypeIDgetRootInterfaceID () const
 Return the interface ID used to match the root operation of this pattern. More...
 
std::optional< TypeIDgetRootTraitID () const
 Return the trait ID used to match the root operation of this pattern. More...
 
PatternBenefit getBenefit () const
 Return the benefit (the inverse of "cost") of matching this pattern. More...
 
bool hasBoundedRewriteRecursion () const
 Returns true if this pattern is known to result in recursive application, i.e. More...
 
MLIRContextgetContext () const
 Return the MLIRContext used to create this pattern. More...
 
StringRef getDebugName () const
 Return a readable name for this pattern. More...
 
void setDebugName (StringRef name)
 Set the human readable debug name used for this pattern. More...
 
ArrayRef< StringRef > getDebugLabels () const
 Return the set of debug labels attached to this pattern. More...
 
void addDebugLabels (ArrayRef< StringRef > labels)
 Add the provided debug labels to this pattern. More...
 
void addDebugLabels (StringRef label)
 

Protected Member Functions

 Pattern (StringRef rootName, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={})
 Construct a pattern with a certain benefit that matches the operation with the given root name. More...
 
 Pattern (MatchAnyOpTypeTag tag, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={})
 Construct a pattern that may match any operation type. More...
 
 Pattern (MatchInterfaceOpTypeTag tag, TypeID interfaceID, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={})
 Construct a pattern that may match any operation that implements the interface defined by the provided interfaceID. More...
 
 Pattern (MatchTraitOpTypeTag tag, TypeID traitID, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={})
 Construct a pattern that may match any operation that implements the trait defined by the provided traitID. More...
 
void setHasBoundedRewriteRecursion (bool hasBoundedRecursionArg=true)
 Set the flag detailing if this pattern has bounded rewrite recursion or not. More...
 

Detailed Description

This class contains all of the data related to a pattern, but does not contain any methods or logic for the actual matching.

This class is solely used to interface with the metadata of a pattern, such as the benefit or root operation.

Definition at line 72 of file PatternMatch.h.

Constructor & Destructor Documentation

◆ Pattern() [1/4]

Pattern::Pattern ( StringRef  rootName,
PatternBenefit  benefit,
MLIRContext context,
ArrayRef< StringRef >  generatedNames = {} 
)
protected

Construct a pattern with a certain benefit that matches the operation with the given root name.

Definition at line 35 of file PatternMatch.cpp.

◆ Pattern() [2/4]

Pattern::Pattern ( MatchAnyOpTypeTag  tag,
PatternBenefit  benefit,
MLIRContext context,
ArrayRef< StringRef >  generatedNames = {} 
)
protected

Construct a pattern that may match any operation type.

generatedNames contains the names of operations that may be generated during a successful rewrite. MatchAnyOpTypeTag is just a tag to ensure that the "match any" behavior is what the user actually desired, MatchAnyOpTypeTag() should always be supplied here.

Definition at line 43 of file PatternMatch.cpp.

◆ Pattern() [3/4]

Pattern::Pattern ( MatchInterfaceOpTypeTag  tag,
TypeID  interfaceID,
PatternBenefit  benefit,
MLIRContext context,
ArrayRef< StringRef >  generatedNames = {} 
)
protected

Construct a pattern that may match any operation that implements the interface defined by the provided interfaceID.

generatedNames contains the names of operations that may be generated during a successful rewrite. MatchInterfaceOpTypeTag is just a tag to ensure that the "match interface" behavior is what the user actually desired, MatchInterfaceOpTypeTag() should always be supplied here.

Definition at line 50 of file PatternMatch.cpp.

◆ Pattern() [4/4]

Pattern::Pattern ( MatchTraitOpTypeTag  tag,
TypeID  traitID,
PatternBenefit  benefit,
MLIRContext context,
ArrayRef< StringRef >  generatedNames = {} 
)
protected

Construct a pattern that may match any operation that implements the trait defined by the provided traitID.

generatedNames contains the names of operations that may be generated during a successful rewrite. MatchTraitOpTypeTag is just a tag to ensure that the "match trait" behavior is what the user actually desired, MatchTraitOpTypeTag() should always be supplied here.

Definition at line 59 of file PatternMatch.cpp.

Member Function Documentation

◆ addDebugLabels() [1/2]

void mlir::Pattern::addDebugLabels ( ArrayRef< StringRef >  labels)
inline

Add the provided debug labels to this pattern.

Definition at line 149 of file PatternMatch.h.

◆ addDebugLabels() [2/2]

void mlir::Pattern::addDebugLabels ( StringRef  label)
inline

Definition at line 152 of file PatternMatch.h.

◆ getBenefit()

int Pattern::getBenefit ( ) const
inline

Return the benefit (the inverse of "cost") of matching this pattern.

The benefit of a Pattern is always static - rewrites that may have dynamic benefit can be instantiated multiple times (different Pattern instances) for each benefit that they may return, and be guarded by different match condition predicates.

Definition at line 122 of file PatternMatch.h.

Referenced by mlir::PatternApplicator::applyCostModel(), mlir::PatternApplicator::applyDefaultCostModel(), and mlir::PatternApplicator::matchAndRewrite().

◆ getContext()

MLIRContext* mlir::Pattern::getContext ( ) const
inline

Return the MLIRContext used to create this pattern.

Definition at line 133 of file PatternMatch.h.

Referenced by mlir::ConvertToLLVMPattern::getIntPtrType(), and mlir::ConvertToLLVMPattern::getVoidType().

◆ getDebugLabels()

ArrayRef<StringRef> mlir::Pattern::getDebugLabels ( ) const
inline

Return the set of debug labels attached to this pattern.

Definition at line 146 of file PatternMatch.h.

◆ getDebugName()

StringRef mlir::Pattern::getDebugName ( ) const
inline

Return a readable name for this pattern.

This name should only be used for debugging purposes, and may be empty.

Definition at line 139 of file PatternMatch.h.

Referenced by mlir::PatternApplicator::matchAndRewrite().

◆ getGeneratedOps()

ArrayRef<OperationName> mlir::Pattern::getGeneratedOps ( ) const
inline

Return a list of operations that may be generated when rewriting an operation instance with this pattern.

Definition at line 89 of file PatternMatch.h.

◆ getRootInterfaceID()

std::optional<TypeID> mlir::Pattern::getRootInterfaceID ( ) const
inline

Return the interface ID used to match the root operation of this pattern.

If the pattern does not use an interface ID for deciding the root match, this returns std::nullopt.

Definition at line 102 of file PatternMatch.h.

References mlir::TypeID::getFromOpaquePointer().

◆ getRootKind()

std::optional<OperationName> mlir::Pattern::getRootKind ( ) const
inline

Return the root node that this pattern matches.

Patterns that can match multiple root types return std::nullopt.

Definition at line 93 of file PatternMatch.h.

References mlir::OperationName::getFromOpaquePointer().

Referenced by logImpossibleToMatch().

◆ getRootTraitID()

std::optional<TypeID> mlir::Pattern::getRootTraitID ( ) const
inline

Return the trait ID used to match the root operation of this pattern.

If the pattern does not use a trait ID for deciding the root match, this returns std::nullopt.

Definition at line 111 of file PatternMatch.h.

References mlir::TypeID::getFromOpaquePointer().

◆ hasBoundedRewriteRecursion()

bool mlir::Pattern::hasBoundedRewriteRecursion ( ) const
inline

Returns true if this pattern is known to result in recursive application, i.e.

this pattern may generate IR that also matches this pattern, but is known to bound the recursion. This signals to a rewrite driver that it is safe to apply this pattern recursively to generated IR.

Definition at line 128 of file PatternMatch.h.

◆ setDebugName()

void mlir::Pattern::setDebugName ( StringRef  name)
inline

Set the human readable debug name used for this pattern.

This name will only be used for debugging purposes.

Definition at line 143 of file PatternMatch.h.

◆ setHasBoundedRewriteRecursion()

void mlir::Pattern::setHasBoundedRewriteRecursion ( bool  hasBoundedRecursionArg = true)
inlineprotected

Set the flag detailing if this pattern has bounded rewrite recursion or not.

Definition at line 201 of file PatternMatch.h.


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