MLIR
18.0.0git
|
#include "PredicateTree.h"
#include "RootOrdering.h"
#include "mlir/Dialect/PDL/IR/PDL.h"
#include "mlir/Dialect/PDL/IR/PDLTypes.h"
#include "mlir/Dialect/PDLInterp/IR/PDLInterp.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include <queue>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "pdl-predicate-tree" |
Functions | |
static void | getTreePredicates (std::vector< PositionalPredicate > &predList, Value val, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs, Position *pos) |
Collect the tree predicates anchored at the given value. More... | |
static bool | comparePosDepth (Position *lhs, Position *rhs) |
Compares the depths of two positions. More... | |
static unsigned | getNumNonRangeValues (ValueRange values) |
Returns the number of non-range elements within values . More... | |
static void | getTreePredicates (std::vector< PositionalPredicate > &predList, Value val, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs, AttributePosition *pos) |
static void | getOperandTreePredicates (std::vector< PositionalPredicate > &predList, Value val, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs, Position *pos) |
Collect all of the predicates for the given operand position. More... | |
static void | getTreePredicates (std::vector< PositionalPredicate > &predList, Value val, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs, OperationPosition *pos, std::optional< unsigned > ignoreOperand=std::nullopt) |
static void | getTreePredicates (std::vector< PositionalPredicate > &predList, Value val, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs, TypePosition *pos) |
static void | getAttributePredicates (pdl::AttributeOp op, std::vector< PositionalPredicate > &predList, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs) |
static void | getConstraintPredicates (pdl::ApplyNativeConstraintOp op, std::vector< PositionalPredicate > &predList, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs) |
static void | getResultPredicates (pdl::ResultOp op, std::vector< PositionalPredicate > &predList, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs) |
static void | getResultPredicates (pdl::ResultsOp op, std::vector< PositionalPredicate > &predList, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs) |
static void | getTypePredicates (Value typeValue, function_ref< Attribute()> typeAttrFn, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs) |
static void | getNonTreePredicates (pdl::PatternOp pattern, std::vector< PositionalPredicate > &predList, PredicateBuilder &builder, DenseMap< Value, Position * > &inputs) |
Collect all of the predicates that cannot be determined via walking the tree. More... | |
static SmallVector< Value > | detectRoots (pdl::PatternOp pattern) |
Given a pattern, determines the set of roots present in this pattern. More... | |
static void | buildCostGraph (ArrayRef< Value > roots, RootOrderingGraph &graph, ParentMaps &parentMaps) |
Given a list of candidate roots, builds the cost graph for connecting them. More... | |
static bool | useOperandGroup (pdl::OperationOp op, unsigned index) |
Returns true if the operand at the given index needs to be queried using an operand group, i.e., if it is variadic itself or follows a variadic operand. More... | |
static void | visitUpward (std::vector< PositionalPredicate > &predList, OpIndex opIndex, PredicateBuilder &builder, DenseMap< Value, Position * > &valueToPosition, Position *&pos, unsigned rootID) |
Visit a node during upward traversal. More... | |
static Value | buildPredicateList (pdl::PatternOp pattern, PredicateBuilder &builder, std::vector< PositionalPredicate > &predList, DenseMap< Value, Position * > &valueToPosition) |
Given a pattern operation, build the set of matcher predicates necessary to match this pattern. More... | |
static bool | isSamePredicate (MatcherNode *node, OrderedPredicate *predicate) |
Returns true if the given matcher refers to the same predicate as the given ordered predicate. More... | |
std::unique_ptr< MatcherNode > & | getOrCreateChild (SwitchNode *node, OrderedPredicate *predicate, pdl::PatternOp pattern) |
Get or insert a child matcher for the given parent switch node, given a predicate and parent pattern. More... | |
static void | propagatePattern (std::unique_ptr< MatcherNode > &node, OrderedPredicateList &list, std::vector< OrderedPredicate * >::iterator current, std::vector< OrderedPredicate * >::iterator end) |
Build the matcher CFG by "pushing" patterns through by sorted predicate order. More... | |
static void | foldSwitchToBool (std::unique_ptr< MatcherNode > &node) |
Fold any switch nodes nested under node to boolean nodes when possible. More... | |
static void | insertExitNode (std::unique_ptr< MatcherNode > *root) |
Insert an exit node at the end of the failure path of the root . More... | |
#define DEBUG_TYPE "pdl-predicate-tree" |
Definition at line 22 of file PredicateTree.cpp.
|
static |
Given a list of candidate roots, builds the cost graph for connecting them.
The graph is formed by traversing the DAG of operations starting from each root and marking the depth of each connector value (operand). Then we join the candidate roots based on the common connector values, taking the one with the minimum depth. Along the way, we compute, for each candidate root, a mapping from each operation (in the DAG underneath this root) to its parent operation and the corresponding operand index.
Definition at line 402 of file PredicateTree.cpp.
References mlir::detail::enumerate().
Referenced by buildPredicateList().
|
static |
Given a pattern operation, build the set of matcher predicates necessary to match this pattern.
Definition at line 594 of file PredicateTree.cpp.
References buildCostGraph(), mlir::pdl_to_pdl_interp::RootOrderingEntry::connector, mlir::pdl_to_pdl_interp::RootOrderingEntry::cost, detectRoots(), mlir::detail::enumerate(), mlir::Value::getLoc(), getNonTreePredicates(), mlir::pdl_to_pdl_interp::PredicateBuilder::getRoot(), getTreePredicates(), mlir::pdl_to_pdl_interp::OptimalBranching::preOrderTraversal(), mlir::pdl_to_pdl_interp::OptimalBranching::solve(), and visitUpward().
Referenced by mlir::pdl_to_pdl_interp::MatcherNode::generateMatcherTree().
Compares the depths of two positions.
Definition at line 37 of file PredicateTree.cpp.
References mlir::pdl_to_pdl_interp::Position::getOperationDepth().
Referenced by getTreePredicates().
|
static |
Given a pattern, determines the set of roots present in this pattern.
These are the operations whose results are not consumed by other operations.
Definition at line 370 of file PredicateTree.cpp.
Referenced by buildPredicateList().
|
static |
Fold any switch nodes nested under node
to boolean nodes when possible.
node
is updated in-place if it is a switch.
Definition at line 847 of file PredicateTree.cpp.
Referenced by mlir::pdl_to_pdl_interp::MatcherNode::generateMatcherTree().
|
static |
Definition at line 249 of file PredicateTree.cpp.
|
static |
Definition at line 261 of file PredicateTree.cpp.
|
static |
Collect all of the predicates that cannot be determined via walking the tree.
Definition at line 326 of file PredicateTree.cpp.
Referenced by buildPredicateList().
|
static |
Returns the number of non-range elements within values
.
Definition at line 42 of file PredicateTree.cpp.
References mlir::ValueRange::getTypes().
|
static |
Collect all of the predicates for the given operand position.
Definition at line 63 of file PredicateTree.cpp.
References mlir::Value::getDefiningOp(), and mlir::Value::getType().
Referenced by getTreePredicates().
std::unique_ptr<MatcherNode>& getOrCreateChild | ( | SwitchNode * | node, |
OrderedPredicate * | predicate, | ||
pdl::PatternOp | pattern | ||
) |
Get or insert a child matcher for the given parent switch node, given a predicate and parent pattern.
Definition at line 792 of file PredicateTree.cpp.
References mlir::pdl_to_pdl_interp::SwitchNode::getChildren(), and isSamePredicate().
Referenced by propagatePattern().
|
static |
Definition at line 280 of file PredicateTree.cpp.
|
static |
Definition at line 294 of file PredicateTree.cpp.
|
static |
Definition at line 47 of file PredicateTree.cpp.
References mlir::pdl_to_pdl_interp::PredicateBuilder::getAttributeConstraint(), mlir::Value::getDefiningOp(), mlir::pdl_to_pdl_interp::PredicateBuilder::getIsNotNull(), getTreePredicates(), mlir::Value::getType(), and mlir::pdl_to_pdl_interp::PredicateBuilder::getType().
|
static |
Operands.
Results.
Definition at line 110 of file PredicateTree.cpp.
References mlir::Value::getType().
|
static |
Collect the tree predicates anchored at the given value.
Definition at line 220 of file PredicateTree.cpp.
References comparePosDepth(), mlir::Value::getDefiningOp(), mlir::pdl_to_pdl_interp::PredicateBuilder::getEqualTo(), and getOperandTreePredicates().
Referenced by buildPredicateList(), getTreePredicates(), and visitUpward().
|
static |
Definition at line 205 of file PredicateTree.cpp.
References mlir::Value::getDefiningOp(), and mlir::pdl_to_pdl_interp::PredicateBuilder::getTypeConstraint().
|
static |
Definition at line 311 of file PredicateTree.cpp.
References mlir::pdl_to_pdl_interp::PredicateBuilder::getTypeLiteral().
|
static |
Insert an exit node at the end of the failure path of the root
.
Definition at line 872 of file PredicateTree.cpp.
Referenced by mlir::pdl_to_pdl_interp::MatcherNode::generateMatcherTree().
|
static |
Returns true if the given matcher refers to the same predicate as the given ordered predicate.
This means that the position and questions of the two match.
Definition at line 785 of file PredicateTree.cpp.
References mlir::pdl_to_pdl_interp::MatcherNode::getPosition(), and mlir::pdl_to_pdl_interp::MatcherNode::getQuestion().
Referenced by getOrCreateChild(), and propagatePattern().
|
static |
Build the matcher CFG by "pushing" patterns through by sorted predicate order.
A pattern will traverse as far as possible using common predicates and then either diverge from the CFG or reach the end of a branch and start creating new nodes.
Definition at line 808 of file PredicateTree.cpp.
References getOrCreateChild(), and isSamePredicate().
Referenced by mlir::pdl_to_pdl_interp::MatcherNode::generateMatcherTree().
|
static |
Returns true if the operand at the given index needs to be queried using an operand group, i.e., if it is variadic itself or follows a variadic operand.
Definition at line 513 of file PredicateTree.cpp.
Referenced by visitUpward().
|
static |
Visit a node during upward traversal.
Definition at line 523 of file PredicateTree.cpp.
References mlir::pdl_to_pdl_interp::PredicateBuilder::getAllOperands(), mlir::pdl_to_pdl_interp::PredicateBuilder::getAllResults(), mlir::Value::getDefiningOp(), mlir::pdl_to_pdl_interp::PredicateBuilder::getEqualTo(), mlir::pdl_to_pdl_interp::PredicateBuilder::getForEach(), mlir::pdl_to_pdl_interp::PredicateBuilder::getOperand(), mlir::pdl_to_pdl_interp::PredicateBuilder::getOperandGroup(), mlir::pdl_to_pdl_interp::PredicateBuilder::getPassthroughOp(), mlir::pdl_to_pdl_interp::PredicateBuilder::getResult(), mlir::pdl_to_pdl_interp::PredicateBuilder::getResultGroup(), getTreePredicates(), mlir::Value::getType(), mlir::pdl_to_pdl_interp::PredicateBuilder::getUsers(), and useOperandGroup().
Referenced by buildPredicateList().