MLIR  21.0.0git
FrozenRewritePatternSet.h
Go to the documentation of this file.
1 //===- FrozenRewritePatternSet.h --------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef MLIR_REWRITE_FROZENREWRITEPATTERNSET_H
10 #define MLIR_REWRITE_FROZENREWRITEPATTERNSET_H
11 
12 #include "mlir/IR/PatternMatch.h"
13 
14 namespace mlir {
15 namespace detail {
16 class PDLByteCode;
17 } // namespace detail
18 
19 /// This class represents a frozen set of patterns that can be processed by a
20 /// pattern applicator. This class is designed to enable caching pattern lists
21 /// such that they need not be continuously recomputed. Note that all copies of
22 /// this class share the same compiled pattern list, allowing for a reduction in
23 /// the number of duplicated patterns that need to be created.
25  using NativePatternListT = std::vector<std::unique_ptr<RewritePattern>>;
26 
27 public:
28  /// A map of operation specific native patterns.
31 
40 
41  /// Freeze the patterns held in `patterns`, and take ownership.
42  /// `disabledPatternLabels` is a set of labels used to filter out input
43  /// patterns with a debug label or debug name in this set.
44  /// `enabledPatternLabels` is a set of labels used to filter out input
45  /// patterns that do not have one of the labels in this set. Debug labels must
46  /// be set explicitly on patterns or when adding them with
47  /// `RewritePatternSet::addWithLabel`. Debug names may be empty, but patterns
48  /// created with `RewritePattern::create` have their default debug name set to
49  /// their type name.
51  ArrayRef<std::string> disabledPatternLabels = {},
52  ArrayRef<std::string> enabledPatternLabels = {});
53 
54  /// Return the op specific native patterns held by this list.
56  return impl->nativeOpSpecificPatternMap;
57  }
58 
59  /// Return the "match any" native patterns held by this list.
62  const NativePatternListT &nativeList = impl->nativeAnyOpPatterns;
63  return llvm::make_pointee_range(nativeList);
64  }
65 
66  /// Return the compiled PDL bytecode held by this list. Returns null if
67  /// there are no PDL patterns within the list.
69  return impl->pdlByteCode.get();
70  }
71 
72 private:
73  /// The internal implementation of the frozen pattern list.
74  struct Impl {
75  /// The set of native C++ rewrite patterns that are matched to specific
76  /// operation kinds.
77  OpSpecificNativePatternListT nativeOpSpecificPatternMap;
78 
79  /// The full op-specific native rewrite list. This allows for the map above
80  /// to contain duplicate patterns, e.g. for interfaces and traits.
81  NativePatternListT nativeOpSpecificPatternList;
82 
83  /// The set of native C++ rewrite patterns that are matched to "any"
84  /// operation.
85  NativePatternListT nativeAnyOpPatterns;
86 
87  /// The bytecode containing the compiled PDL patterns.
88  std::unique_ptr<detail::PDLByteCode> pdlByteCode;
89  };
90 
91  /// A pointer to the internal pattern list. This uses a shared_ptr to avoid
92  /// the need to compile the same pattern list multiple times. For example,
93  /// during multi-threaded pass execution, all copies of a pass can share the
94  /// same pattern list.
95  std::shared_ptr<Impl> impl;
96 };
97 
98 } // namespace mlir
99 
100 #endif // MLIR_REWRITE_FROZENREWRITEPATTERNSET_H
This class represents a frozen set of patterns that can be processed by a pattern applicator.
FrozenRewritePatternSet(FrozenRewritePatternSet &&patterns)=default
FrozenRewritePatternSet & operator=(const FrozenRewritePatternSet &patterns)=default
FrozenRewritePatternSet & operator=(FrozenRewritePatternSet &&patterns)=default
const detail::PDLByteCode * getPDLByteCode() const
Return the compiled PDL bytecode held by this list.
iterator_range< llvm::pointee_iterator< NativePatternListT::const_iterator > > getMatchAnyOpNativePatterns() const
Return the "match any" native patterns held by this list.
const OpSpecificNativePatternListT & getOpSpecificNativePatterns() const
Return the op specific native patterns held by this list.
DenseMap< OperationName, std::vector< RewritePattern * > > OpSpecificNativePatternListT
A map of operation specific native patterns.
FrozenRewritePatternSet(const FrozenRewritePatternSet &patterns)=default
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns