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"
22 llvm::BumpPtrAllocator *&NestedMatch::allocator() {
23 thread_local llvm::BumpPtrAllocator *allocator =
nullptr;
29 auto *result = allocator()->Allocate<
NestedMatch>();
30 auto *children = allocator()->Allocate<
NestedMatch>(nestedMatches.size());
31 std::uninitialized_copy(nestedMatches.begin(), nestedMatches.end(), children);
33 result->matchedOperation = operation;
34 result->matchedChildren =
39 llvm::BumpPtrAllocator *&NestedPattern::allocator() {
40 thread_local llvm::BumpPtrAllocator *allocator =
nullptr;
48 auto *newNested = allocator()->Allocate<
NestedPattern>(nested.size());
49 std::uninitialized_copy(nested.begin(), nested.end(), newNested);
53 void NestedPattern::freeNested() {
54 for (
const auto &p : nestedPatterns)
60 : filter(std::move(filter)), skip(nullptr) {
61 copyNestedToThis(nested);
65 : filter(other.filter), skip(other.skip) {
66 copyNestedToThis(other.nestedPatterns);
71 filter = other.filter;
73 copyNestedToThis(other.nestedPatterns);
78 if (nestedPatterns.empty()) {
82 for (
auto &c : nestedPatterns) {
83 depth =
std::max(depth, c.getDepth());
98 void NestedPattern::matchOne(
Operation *op,
108 if (nestedPatterns.empty()) {
114 for (
auto nestedPattern : nestedPatterns) {
118 nestedPattern.skip = op;
119 nestedPattern.match(op, &nestedMatches);
122 if (nestedMatches.empty()) {
177 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.