#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/SmallPtrSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include <queue>
#define DEBUG_TYPE …
usingnamespacemlir;
usingnamespacemlir::pdl_to_pdl_interp;
static void getTreePredicates(std::vector<PositionalPredicate> &predList,
Value val, PredicateBuilder &builder,
DenseMap<Value, Position *> &inputs,
Position *pos);
static bool comparePosDepth(Position *lhs, Position *rhs) { … }
static unsigned getNumNonRangeValues(ValueRange values) { … }
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) { … }
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 getTreePredicates(std::vector<PositionalPredicate> &predList,
Value val, PredicateBuilder &builder,
DenseMap<Value, Position *> &inputs,
Position *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) { … }
namespace {
struct OpIndex { … };
ParentMaps;
}
static SmallVector<Value> detectRoots(pdl::PatternOp pattern) { … }
static void buildCostGraph(ArrayRef<Value> roots, RootOrderingGraph &graph,
ParentMaps &parentMaps) { … }
static bool useOperandGroup(pdl::OperationOp op, unsigned index) { … }
static void visitUpward(std::vector<PositionalPredicate> &predList,
OpIndex opIndex, PredicateBuilder &builder,
DenseMap<Value, Position *> &valueToPosition,
Position *&pos, unsigned rootID) { … }
static Value buildPredicateList(pdl::PatternOp pattern,
PredicateBuilder &builder,
std::vector<PositionalPredicate> &predList,
DenseMap<Value, Position *> &valueToPosition) { … }
namespace {
struct OrderedPredicate { … };
struct OrderedPredicateDenseInfo { … };
struct OrderedPredicateList { … };
}
static bool isSamePredicate(MatcherNode *node, OrderedPredicate *predicate) { … }
std::unique_ptr<MatcherNode> &getOrCreateChild(SwitchNode *node,
OrderedPredicate *predicate,
pdl::PatternOp pattern) { … }
static void propagatePattern(std::unique_ptr<MatcherNode> &node,
OrderedPredicateList &list,
std::vector<OrderedPredicate *>::iterator current,
std::vector<OrderedPredicate *>::iterator end) { … }
static void foldSwitchToBool(std::unique_ptr<MatcherNode> &node) { … }
static void insertExitNode(std::unique_ptr<MatcherNode> *root) { … }
template <typename Iterator, typename Compare>
static void stableTopologicalSort(Iterator begin, Iterator end, Compare cmp) { … }
static bool dependsOn(OrderedPredicate *a, OrderedPredicate *b) { … }
std::unique_ptr<MatcherNode>
MatcherNode::generateMatcherTree(ModuleOp module, PredicateBuilder &builder,
DenseMap<Value, Position *> &valueToPosition) { … }
MatcherNode::MatcherNode(TypeID matcherTypeID, Position *p, Qualifier *q,
std::unique_ptr<MatcherNode> failureNode)
: … { … }
BoolNode::BoolNode(Position *position, Qualifier *question, Qualifier *answer,
std::unique_ptr<MatcherNode> successNode,
std::unique_ptr<MatcherNode> failureNode)
: … { … }
SuccessNode::SuccessNode(pdl::PatternOp pattern, Value root,
std::unique_ptr<MatcherNode> failureNode)
: … { … }
SwitchNode::SwitchNode(Position *position, Qualifier *question)
: … { … }