14 #include "llvm/ADT/ArrayRef.h" 15 #include "llvm/ADT/STLExtras.h" 16 #include "llvm/Support/Allocator.h" 17 #include "llvm/Support/raw_ostream.h" 21 llvm::BumpPtrAllocator *&NestedMatch::allocator() {
22 thread_local llvm::BumpPtrAllocator *allocator =
nullptr;
28 auto *result = allocator()->Allocate<
NestedMatch>();
29 auto *children = allocator()->Allocate<
NestedMatch>(nestedMatches.size());
30 std::uninitialized_copy(nestedMatches.begin(), nestedMatches.end(), children);
32 result->matchedOperation = operation;
33 result->matchedChildren =
38 llvm::BumpPtrAllocator *&NestedPattern::allocator() {
39 thread_local llvm::BumpPtrAllocator *allocator =
nullptr;
47 auto *newNested = allocator()->Allocate<
NestedPattern>(nested.size());
48 std::uninitialized_copy(nested.begin(), nested.end(), newNested);
52 void NestedPattern::freeNested() {
53 for (
const auto &p : nestedPatterns)
59 : nestedPatterns(), filter(std::move(filter)), skip(nullptr) {
60 copyNestedToThis(nested);
64 : nestedPatterns(), filter(other.filter), skip(other.skip) {
65 copyNestedToThis(other.nestedPatterns);
70 filter = other.filter;
72 copyNestedToThis(other.nestedPatterns);
77 if (nestedPatterns.empty()) {
81 for (
auto &c : nestedPatterns) {
82 depth =
std::max(depth, c.getDepth());
97 void NestedPattern::matchOne(
Operation *op,
107 if (nestedPatterns.empty()) {
113 for (
auto nestedPattern : nestedPatterns) {
117 nestedPattern.skip = op;
118 nestedPattern.match(op, &nestedMatches);
121 if (nestedMatches.empty()) {
175 return isa<AffineLoadOp, AffineStoreOp>(op);
Include the generated interface declarations.
NestedPattern(ArrayRef< NestedPattern > nested, FilterFunctionType filter=defaultFilterFunction)
Operation is a basic unit of execution within MLIR.
bool isLoadOrStore(Operation &op)
unsigned getDepth() const
Returns the depth of the pattern.
static bool isAffineForOp(Operation &op)
static NestedMatch build(Operation *operation, ArrayRef< NestedMatch > nestedMatches)
std::function< bool(Operation &)> FilterFunctionType
A NestedPattern is a nested operation walker that:
NestedPattern If(const NestedPattern &child)
NestedPattern For(const NestedPattern &child)
static bool isAffineIfOp(Operation &op)
An NestedPattern captures nested patterns in the IR.
NestedPattern & operator=(const NestedPattern &other)
NestedPattern Op(FilterFunctionType filter=defaultFilterFunction)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)