14 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/Support/Allocator.h"
20 llvm::BumpPtrAllocator *&NestedMatch::allocator() {
21 thread_local llvm::BumpPtrAllocator *allocator =
nullptr;
27 auto *result = allocator()->Allocate<
NestedMatch>();
28 auto *children = allocator()->Allocate<
NestedMatch>(nestedMatches.size());
29 llvm::uninitialized_copy(nestedMatches, children);
31 result->matchedOperation = operation;
32 result->matchedChildren =
37 llvm::BumpPtrAllocator *&NestedPattern::allocator() {
38 thread_local llvm::BumpPtrAllocator *allocator =
nullptr;
46 auto *newNested = allocator()->Allocate<
NestedPattern>(nested.size());
47 llvm::uninitialized_copy(nested, newNested);
51 void NestedPattern::freeNested() {
52 for (
const auto &p : nestedPatterns)
58 : filter(std::move(filter)), skip(nullptr) {
59 copyNestedToThis(nested);
63 : filter(other.filter), skip(other.skip) {
64 copyNestedToThis(other.nestedPatterns);
69 filter = other.filter;
71 copyNestedToThis(other.nestedPatterns);
76 if (nestedPatterns.empty()) {
80 for (
auto &c : nestedPatterns) {
81 depth =
std::max(depth, c.getDepth());
96 void NestedPattern::matchOne(
Operation *op,
106 if (nestedPatterns.empty()) {
112 for (
auto nestedPattern : nestedPatterns) {
116 nestedPattern.skip = op;
117 nestedPattern.match(op, &nestedMatches);
120 if (nestedMatches.empty()) {
175 return isa<AffineLoadOp, AffineStoreOp>(op);
static bool isAffineForOp(Operation &op)
static bool isAffineIfOp(Operation &op)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
Operation is the basic unit of execution within MLIR.
An NestedPattern captures nested patterns in the IR.
static NestedMatch build(Operation *operation, ArrayRef< NestedMatch > nestedMatches)
unsigned getDepth() const
Returns the depth of the pattern.
NestedPattern & operator=(const NestedPattern &other)
NestedPattern(ArrayRef< NestedPattern > nested, FilterFunctionType filter=defaultFilterFunction)
NestedPattern If(const NestedPattern &child)
NestedPattern For(const NestedPattern &child)
bool isLoadOrStore(Operation &op)
NestedPattern Op(FilterFunctionType filter=defaultFilterFunction)
std::function< bool(Operation &)> FilterFunctionType
A NestedPattern is a nested operation walker that:
Include the generated interface declarations.