14 #ifndef MLIR_LIB_CONVERSION_PDLTOPDLINTERP_PREDICATETREE_H_
15 #define MLIR_LIB_CONVERSION_PDLTOPDLINTERP_PREDICATETREE_H_
19 #include "llvm/ADT/MapVector.h"
24 namespace pdl_to_pdl_interp {
58 static std::unique_ptr<MatcherNode>
74 failureNode = std::move(node);
84 std::unique_ptr<MatcherNode> failureNode =
nullptr);
94 std::unique_ptr<MatcherNode> failureNode;
97 std::unique_ptr<MatcherNode> failureNodeStorage;
111 std::unique_ptr<MatcherNode> successNode,
112 std::unique_ptr<MatcherNode> failureNode =
nullptr);
131 std::unique_ptr<MatcherNode> successNode;
156 std::unique_ptr<MatcherNode> failureNode);
173 pdl::PatternOp pattern;
196 using ChildMapT = llvm::MapVector<Qualifier *, std::unique_ptr<MatcherNode>>;
200 std::pair<Qualifier *, std::unique_ptr<MatcherNode>> &
getChild(
unsigned i) {
201 assert(i < children.size() &&
"invalid child index");
202 return *std::next(children.begin(), i);
This class provides an efficient unique identifier for a specific C++ type.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
This class represents the base of a predicate matcher node.
Position * getPosition() const
Returns the position on which the question predicate should be checked.
TypeID getMatcherTypeID() const
Returns the unique type ID of this matcher instance.
std::unique_ptr< MatcherNode > & getFailureNode()
Returns the node that should be visited if this, or a subsequent node fails.
Qualifier * getQuestion() const
Returns the predicate checked on this node.
MatcherNode(TypeID matcherTypeID, Position *position=nullptr, Qualifier *question=nullptr, std::unique_ptr< MatcherNode > failureNode=nullptr)
static std::unique_ptr< MatcherNode > generateMatcherTree(ModuleOp module, PredicateBuilder &builder, DenseMap< Value, Position * > &valueToPosition)
Given a module containing PDL pattern operations, generate a matcher tree using the patterns within t...
void setFailureNode(std::unique_ptr< MatcherNode > node)
Sets the node that should be visited if this, or a subsequent node fails.
virtual ~MatcherNode()=default
A position describes a value on the input IR on which a predicate may be applied, such as an operatio...
This class provides utilities for constructing predicates.
std::pair< Qualifier *, Qualifier * > Predicate
An ordinal predicate consists of a "Question" and a set of acceptable "Answers" (later converted to o...
An ordinal predicate consists of a "Question" and a set of acceptable "Answers" (later converted to o...
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
A BoolNode denotes a question with a boolean-like result.
static bool classof(const MatcherNode *node)
Returns if the given matcher node is an instance of this class, used to support type casting.
BoolNode(Position *position, Qualifier *question, Qualifier *answer, std::unique_ptr< MatcherNode > successNode, std::unique_ptr< MatcherNode > failureNode=nullptr)
std::unique_ptr< MatcherNode > & getSuccessNode()
Returns the node that should be visited on success.
Qualifier * getAnswer() const
Returns the expected answer of this boolean node.
An ExitNode is a special sentinel node that denotes the end of matcher.
static bool classof(const MatcherNode *node)
Returns if the given matcher node is an instance of this class, used to support type casting.
A PositionalPredicate is a predicate that is associated with a specific positional value.
Position * position
The position the predicate is applied to.
PositionalPredicate(Position *pos, const PredicateBuilder::Predicate &predicate)
Qualifier * answer
The expected answer of the predicate.
Qualifier * question
The question that the predicate applies.
A SuccessNode denotes that a given high level pattern has successfully been matched.
static bool classof(const MatcherNode *node)
Returns if the given matcher node is an instance of this class, used to support type casting.
pdl::PatternOp getPattern() const
Return the high level pattern operation that is matched with this node.
Value getRoot() const
Return the chosen root of the pattern.
SuccessNode(pdl::PatternOp pattern, Value root, std::unique_ptr< MatcherNode > failureNode)
A SwitchNode denotes a question with multiple potential results.
std::pair< Qualifier *, std::unique_ptr< MatcherNode > > & getChild(unsigned i)
Returns the child at the given index.
static bool classof(const MatcherNode *node)
Returns if the given matcher node is an instance of this class, used to support type casting.
llvm::MapVector< Qualifier *, std::unique_ptr< MatcherNode > > ChildMapT
Returns the children of this switch node.
ChildMapT & getChildren()
SwitchNode(Position *position, Qualifier *question)