/home/arjun/llvm-project/mlir/include/mlir/IR/PatternMatch.h
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | //===- PatternMatch.h - PatternMatcher classes -------==---------*- 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_PATTERNMATCHER_H | 
| 10 |  | #define MLIR_PATTERNMATCHER_H | 
| 11 |  |  | 
| 12 |  | #include "mlir/IR/Builders.h" | 
| 13 |  |  | 
| 14 |  | namespace mlir { | 
| 15 |  |  | 
| 16 |  | class PatternRewriter; | 
| 17 |  |  | 
| 18 |  | //===----------------------------------------------------------------------===// | 
| 19 |  | // PatternBenefit class | 
| 20 |  | //===----------------------------------------------------------------------===// | 
| 21 |  |  | 
| 22 |  | /// This class represents the benefit of a pattern match in a unitless scheme | 
| 23 |  | /// that ranges from 0 (very little benefit) to 65K.  The most common unit to | 
| 24 |  | /// use here is the "number of operations matched" by the pattern. | 
| 25 |  | /// | 
| 26 |  | /// This also has a sentinel representation that can be used for patterns that | 
| 27 |  | /// fail to match. | 
| 28 |  | /// | 
| 29 |  | class PatternBenefit { | 
| 30 |  |   enum { ImpossibleToMatchSentinel = 65535 }; | 
| 31 |  |  | 
| 32 |  | public: | 
| 33 |  |   /*implicit*/ PatternBenefit(unsigned benefit); | 
| 34 |  |   PatternBenefit(const PatternBenefit &) = default; | 
| 35 |  |   PatternBenefit &operator=(const PatternBenefit &) = default; | 
| 36 |  |  | 
| 37 | 0 |   static PatternBenefit impossibleToMatch() { return PatternBenefit(); } | 
| 38 | 0 |   bool isImpossibleToMatch() const { return *this == impossibleToMatch(); } | 
| 39 |  |  | 
| 40 |  |   /// If the corresponding pattern can match, return its benefit.  If the | 
| 41 |  |   // corresponding pattern isImpossibleToMatch() then this aborts. | 
| 42 |  |   unsigned short getBenefit() const; | 
| 43 |  |  | 
| 44 | 0 |   bool operator==(const PatternBenefit &rhs) const { | 
| 45 | 0 |     return representation == rhs.representation; | 
| 46 | 0 |   } | 
| 47 | 0 |   bool operator!=(const PatternBenefit &rhs) const { return !(*this == rhs); } | 
| 48 | 0 |   bool operator<(const PatternBenefit &rhs) const { | 
| 49 | 0 |     return representation < rhs.representation; | 
| 50 | 0 |   } | 
| 51 |  |  | 
| 52 |  | private: | 
| 53 | 0 |   PatternBenefit() : representation(ImpossibleToMatchSentinel) {} | 
| 54 |  |   unsigned short representation; | 
| 55 |  | }; | 
| 56 |  |  | 
| 57 |  | //===----------------------------------------------------------------------===// | 
| 58 |  | // Pattern class | 
| 59 |  | //===----------------------------------------------------------------------===// | 
| 60 |  |  | 
| 61 |  | /// Instances of Pattern can be matched against SSA IR.  These matches get used | 
| 62 |  | /// in ways dependent on their subclasses and the driver doing the matching. | 
| 63 |  | /// For example, RewritePatterns implement a rewrite from one matched pattern | 
| 64 |  | /// to a replacement DAG tile. | 
| 65 |  | class Pattern { | 
| 66 |  | public: | 
| 67 |  |   /// Return the benefit (the inverse of "cost") of matching this pattern.  The | 
| 68 |  |   /// benefit of a Pattern is always static - rewrites that may have dynamic | 
| 69 |  |   /// benefit can be instantiated multiple times (different Pattern instances) | 
| 70 |  |   /// for each benefit that they may return, and be guarded by different match | 
| 71 |  |   /// condition predicates. | 
| 72 | 0 |   PatternBenefit getBenefit() const { return benefit; } | 
| 73 |  |  | 
| 74 |  |   /// Return the root node that this pattern matches.  Patterns that can | 
| 75 |  |   /// match multiple root types are instantiated once per root. | 
| 76 | 0 |   OperationName getRootKind() const { return rootKind; } | 
| 77 |  |  | 
| 78 |  |   //===--------------------------------------------------------------------===// | 
| 79 |  |   // Implementation hooks for patterns to implement. | 
| 80 |  |   //===--------------------------------------------------------------------===// | 
| 81 |  |  | 
| 82 |  |   /// Attempt to match against code rooted at the specified operation, | 
| 83 |  |   /// which is the same operation code as getRootKind(). | 
| 84 |  |   virtual LogicalResult match(Operation *op) const = 0; | 
| 85 |  |  | 
| 86 | 0 |   virtual ~Pattern() {} | 
| 87 |  |  | 
| 88 |  | protected: | 
| 89 |  |   /// Patterns must specify the root operation name they match against, and can | 
| 90 |  |   /// also specify the benefit of the pattern matching. | 
| 91 |  |   Pattern(StringRef rootName, PatternBenefit benefit, MLIRContext *context); | 
| 92 |  |  | 
| 93 |  | private: | 
| 94 |  |   const OperationName rootKind; | 
| 95 |  |   const PatternBenefit benefit; | 
| 96 |  |  | 
| 97 |  |   virtual void anchor(); | 
| 98 |  | }; | 
| 99 |  |  | 
| 100 |  | /// RewritePattern is the common base class for all DAG to DAG replacements. | 
| 101 |  | /// There are two possible usages of this class: | 
| 102 |  | ///   * Multi-step RewritePattern with "match" and "rewrite" | 
| 103 |  | ///     - By overloading the "match" and "rewrite" functions, the user can | 
| 104 |  | ///       separate the concerns of matching and rewriting. | 
| 105 |  | ///   * Single-step RewritePattern with "matchAndRewrite" | 
| 106 |  | ///     - By overloading the "matchAndRewrite" function, the user can perform | 
| 107 |  | ///       the rewrite in the same call as the match. | 
| 108 |  | /// | 
| 109 |  | class RewritePattern : public Pattern { | 
| 110 |  | public: | 
| 111 |  |   /// Rewrite the IR rooted at the specified operation with the result of | 
| 112 |  |   /// this pattern, generating any new operations with the specified | 
| 113 |  |   /// builder.  If an unexpected error is encountered (an internal | 
| 114 |  |   /// compiler error), it is emitted through the normal MLIR diagnostic | 
| 115 |  |   /// hooks and the IR is left in a valid state. | 
| 116 |  |   virtual void rewrite(Operation *op, PatternRewriter &rewriter) const; | 
| 117 |  |  | 
| 118 |  |   /// Attempt to match against code rooted at the specified operation, | 
| 119 |  |   /// which is the same operation code as getRootKind(). | 
| 120 |  |   LogicalResult match(Operation *op) const override; | 
| 121 |  |  | 
| 122 |  |   /// Attempt to match against code rooted at the specified operation, | 
| 123 |  |   /// which is the same operation code as getRootKind(). If successful, this | 
| 124 |  |   /// function will automatically perform the rewrite. | 
| 125 |  |   virtual LogicalResult matchAndRewrite(Operation *op, | 
| 126 | 0 |                                         PatternRewriter &rewriter) const { | 
| 127 | 0 |     if (succeeded(match(op))) { | 
| 128 | 0 |       rewrite(op, rewriter); | 
| 129 | 0 |       return success(); | 
| 130 | 0 |     } | 
| 131 | 0 |     return failure(); | 
| 132 | 0 |   } | 
| 133 |  |  | 
| 134 |  |   /// Returns true if this pattern is known to result in recursive application, | 
| 135 |  |   /// i.e. this pattern may generate IR that also matches this pattern, but is | 
| 136 |  |   /// known to bound the recursion. This signals to a rewriter that it is safe | 
| 137 |  |   /// to apply this pattern recursively to generated IR. | 
| 138 | 0 |   virtual bool hasBoundedRewriteRecursion() const { return false; } | 
| 139 |  |  | 
| 140 |  |   /// Return a list of operations that may be generated when rewriting an | 
| 141 |  |   /// operation instance with this pattern. | 
| 142 | 0 |   ArrayRef<OperationName> getGeneratedOps() const { return generatedOps; } | 
| 143 |  |  | 
| 144 |  | protected: | 
| 145 |  |   /// Patterns must specify the root operation name they match against, and can | 
| 146 |  |   /// also specify the benefit of the pattern matching. | 
| 147 |  |   RewritePattern(StringRef rootName, PatternBenefit benefit, | 
| 148 |  |                  MLIRContext *context) | 
| 149 | 0 |       : Pattern(rootName, benefit, context) {} | 
| 150 |  |   /// Patterns must specify the root operation name they match against, and can | 
| 151 |  |   /// also specify the benefit of the pattern matching. They can also specify | 
| 152 |  |   /// the names of operations that may be generated during a successful rewrite. | 
| 153 |  |   RewritePattern(StringRef rootName, ArrayRef<StringRef> generatedNames, | 
| 154 |  |                  PatternBenefit benefit, MLIRContext *context); | 
| 155 |  |  | 
| 156 |  |   /// A list of the potential operations that may be generated when rewriting | 
| 157 |  |   /// an op with this pattern. | 
| 158 |  |   SmallVector<OperationName, 2> generatedOps; | 
| 159 |  | }; | 
| 160 |  |  | 
| 161 |  | /// OpRewritePattern is a wrapper around RewritePattern that allows for | 
| 162 |  | /// matching and rewriting against an instance of a derived operation class as | 
| 163 |  | /// opposed to a raw Operation. | 
| 164 |  | template <typename SourceOp> struct OpRewritePattern : public RewritePattern { | 
| 165 |  |   /// Patterns must specify the root operation name they match against, and can | 
| 166 |  |   /// also specify the benefit of the pattern matching. | 
| 167 |  |   OpRewritePattern(MLIRContext *context, PatternBenefit benefit = 1) | 
| 168 | 0 |       : RewritePattern(SourceOp::getOperationName(), benefit, context) {}Unexecuted instantiation: _ZN4mlir16OpRewritePatternINS_13AffineApplyOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_11AffineForOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_10AffineIfOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_12AffineLoadOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_13AffineStoreOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_11AffineMinOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_11AffineMaxOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_16AffinePrefetchOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_7AllocOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_8AllocaOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_8BranchOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_14CallIndirectOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_12CondBranchOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_9DeallocOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_16ExtractElementOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_9SubViewOpEEC2EPNS_11MLIRContextENS_14PatternBenefitEUnexecuted instantiation: _ZN4mlir16OpRewritePatternINS_6ViewOpEEC2EPNS_11MLIRContextENS_14PatternBenefitE | 
| 169 |  |  | 
| 170 |  |   /// Wrappers around the RewritePattern methods that pass the derived op type. | 
| 171 | 0 |   void rewrite(Operation *op, PatternRewriter &rewriter) const final { | 
| 172 | 0 |     rewrite(cast<SourceOp>(op), rewriter); | 
| 173 | 0 |   } Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineApplyOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineForOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_10AffineIfOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12AffineLoadOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineStoreOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMinOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMaxOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16AffinePrefetchOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_7AllocOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8AllocaOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8BranchOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_14CallIndirectOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12CondBranchOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9DeallocOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16ExtractElementOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9SubViewOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_6ViewOpEE7rewriteEPNS_9OperationERNS_15PatternRewriterE | 
| 174 | 0 |   LogicalResult match(Operation *op) const final { | 
| 175 | 0 |     return match(cast<SourceOp>(op)); | 
| 176 | 0 |   } Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineApplyOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineForOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_10AffineIfOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12AffineLoadOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineStoreOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMinOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMaxOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16AffinePrefetchOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_7AllocOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8AllocaOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8BranchOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_14CallIndirectOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12CondBranchOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9DeallocOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16ExtractElementOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9SubViewOpEE5matchEPNS_9OperationEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_6ViewOpEE5matchEPNS_9OperationE | 
| 177 |  |   LogicalResult matchAndRewrite(Operation *op, | 
| 178 | 0 |                                 PatternRewriter &rewriter) const final { | 
| 179 | 0 |     return matchAndRewrite(cast<SourceOp>(op), rewriter); | 
| 180 | 0 |   } Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineApplyOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineForOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_10AffineIfOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12AffineLoadOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineStoreOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMinOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMaxOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16AffinePrefetchOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_7AllocOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8AllocaOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8BranchOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_14CallIndirectOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12CondBranchOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9DeallocOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16ExtractElementOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9SubViewOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_6ViewOpEE15matchAndRewriteEPNS_9OperationERNS_15PatternRewriterE | 
| 181 |  |  | 
| 182 |  |   /// Rewrite and Match methods that operate on the SourceOp type. These must be | 
| 183 |  |   /// overridden by the derived pattern class. | 
| 184 | 0 |   virtual void rewrite(SourceOp op, PatternRewriter &rewriter) const { | 
| 185 | 0 |     llvm_unreachable("must override rewrite or matchAndRewrite"); | 
| 186 | 0 |   } Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineApplyOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineForOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_10AffineIfOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12AffineLoadOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineStoreOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMinOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMaxOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16AffinePrefetchOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_7AllocOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8AllocaOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8BranchOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_14CallIndirectOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12CondBranchOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9DeallocOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16ExtractElementOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9SubViewOpEE7rewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_6ViewOpEE7rewriteES1_RNS_15PatternRewriterE | 
| 187 | 0 |   virtual LogicalResult match(SourceOp op) const { | 
| 188 | 0 |     llvm_unreachable("must override match or matchAndRewrite"); | 
| 189 | 0 |   } Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineApplyOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineForOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_10AffineIfOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12AffineLoadOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineStoreOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMinOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMaxOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16AffinePrefetchOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_7AllocOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8AllocaOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8BranchOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_14CallIndirectOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12CondBranchOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9DeallocOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16ExtractElementOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9SubViewOpEE5matchES1_Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_6ViewOpEE5matchES1_ | 
| 190 |  |   virtual LogicalResult matchAndRewrite(SourceOp op, | 
| 191 | 0 |                                         PatternRewriter &rewriter) const { | 
| 192 | 0 |     if (succeeded(match(op))) { | 
| 193 | 0 |       rewrite(op, rewriter); | 
| 194 | 0 |       return success(); | 
| 195 | 0 |     } | 
| 196 | 0 |     return failure(); | 
| 197 | 0 |   } Unexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineApplyOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineForOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_10AffineIfOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12AffineLoadOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_13AffineStoreOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMinOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_11AffineMaxOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16AffinePrefetchOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_7AllocOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8AllocaOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_8BranchOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_14CallIndirectOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_12CondBranchOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9DeallocOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_16ExtractElementOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_9SubViewOpEE15matchAndRewriteES1_RNS_15PatternRewriterEUnexecuted instantiation: _ZNK4mlir16OpRewritePatternINS_6ViewOpEE15matchAndRewriteES1_RNS_15PatternRewriterE | 
| 198 |  | }; | 
| 199 |  |  | 
| 200 |  | //===----------------------------------------------------------------------===// | 
| 201 |  | // PatternRewriter class | 
| 202 |  | //===----------------------------------------------------------------------===// | 
| 203 |  |  | 
| 204 |  | /// This class coordinates the application of a pattern to the current function, | 
| 205 |  | /// providing a way to create operations and keep track of what gets deleted. | 
| 206 |  | /// | 
| 207 |  | /// These class serves two purposes: | 
| 208 |  | ///  1) it is the interface that patterns interact with to make mutations to the | 
| 209 |  | ///     IR they are being applied to. | 
| 210 |  | ///  2) It is a base class that clients of the PatternMatcher use when they want | 
| 211 |  | ///     to apply patterns and observe their effects (e.g. to keep worklists or | 
| 212 |  | ///     other data structures up to date). | 
| 213 |  | /// | 
| 214 |  | class PatternRewriter : public OpBuilder, public OpBuilder::Listener { | 
| 215 |  | public: | 
| 216 |  |   /// Create operation of specific op type at the current insertion point | 
| 217 |  |   /// without verifying to see if it is valid. | 
| 218 |  |   template <typename OpTy, typename... Args> | 
| 219 | 0 |   OpTy create(Location location, Args... args) { | 
| 220 | 0 |     OperationState state(location, OpTy::getOperationName()); | 
| 221 | 0 |     OpTy::build(*this, state, args...); | 
| 222 | 0 |     auto *op = createOperation(state); | 
| 223 | 0 |     auto result = dyn_cast<OpTy>(op); | 
| 224 | 0 |     assert(result && "Builder didn't return the right type"); | 
| 225 | 0 |     return result; | 
| 226 | 0 |   } Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_13AffineApplyOpEJNS_9AffineMapEN4llvm8ArrayRefINS_5ValueEEEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_12AffineLoadOpEJNS_5ValueENS_9AffineMapEN4llvm8ArrayRefIS3_EEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_13AffineStoreOpEJNS_5ValueES3_NS_9AffineMapEN4llvm8ArrayRefIS3_EEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_11AffineMinOpEJNS_9AffineMapEN4llvm8ArrayRefINS_5ValueEEEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_11AffineMaxOpEJNS_9AffineMapEN4llvm8ArrayRefINS_5ValueEEEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_16AffinePrefetchOpEJNS_5ValueENS_9AffineMapEN4llvm8ArrayRefIS3_EEmbbEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_7AllocOpEJNS_10MemRefTypeEN4llvm11SmallVectorINS_5ValueELj4EEENS_11IntegerAttrEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_12MemRefCastOpEJNS_7AllocOpENS_10MemRefTypeEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_8AllocaOpEJNS_10MemRefTypeEN4llvm11SmallVectorINS_5ValueELj4EEENS_11IntegerAttrEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_12MemRefCastOpEJNS_8AllocaOpENS_10MemRefTypeEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_8BranchOpEJPNS_5BlockENS_10ValueRangeEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_6CallOpEJNS_13SymbolRefAttrEN4llvm8ArrayRefINS_4TypeEEENS_12OperandRangeEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_8BranchOpEJPNS_5BlockENS_12OperandRangeEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_12CondBranchOpEJNS_5ValueEPNS_5BlockENS_10ValueRangeES5_S6_EEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_8SelectOpEJNS_5ValueES3_S3_EEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_8BranchOpEJPNS_5BlockEN4llvm11SmallVectorINS_5ValueELj8EEEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_9SubViewOpEJNS_5ValueEN4llvm11SmallVectorIlLj8EEES6_S6_NS5_IS3_Lj8EEES7_S7_EEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_12MemRefCastOpEJNS_9SubViewOpENS_10MemRefTypeEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_9SubViewOpEJNS_4TypeENS_5ValueENS_12OperandRangeES5_S5_NS_9ArrayAttrES6_S6_EEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_12MemRefCastOpEJNS_10MemRefTypeENS_5ValueEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_6ViewOpEJNS_10MemRefTypeENS_5ValueES4_N4llvm11SmallVectorIS4_Lj4EEEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_12MemRefCastOpEJNS_6ViewOpENS_10MemRefTypeEEEET_NS_8LocationEDpT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter6createINS_6ViewOpEJNS_10MemRefTypeENS_5ValueES4_NS_12OperandRangeEEEET_NS_8LocationEDpT0_ | 
| 227 |  |  | 
| 228 |  |   /// Creates an operation of specific op type at the current insertion point. | 
| 229 |  |   /// If the result is an invalid op (the verifier hook fails), emit an error | 
| 230 |  |   /// and return null. | 
| 231 |  |   template <typename OpTy, typename... Args> | 
| 232 |  |   OpTy createChecked(Location location, Args... args) { | 
| 233 |  |     OperationState state(location, OpTy::getOperationName()); | 
| 234 |  |     OpTy::build(*this, state, args...); | 
| 235 |  |     auto *op = createOperation(state); | 
| 236 |  |  | 
| 237 |  |     // If the Operation we produce is valid, return it. | 
| 238 |  |     if (!OpTy::verifyInvariants(op)) { | 
| 239 |  |       auto result = dyn_cast<OpTy>(op); | 
| 240 |  |       assert(result && "Builder didn't return the right type"); | 
| 241 |  |       return result; | 
| 242 |  |     } | 
| 243 |  |  | 
| 244 |  |     // Otherwise, the error message got emitted.  Just remove the operation | 
| 245 |  |     // we made. | 
| 246 |  |     op->erase(); | 
| 247 |  |     return OpTy(); | 
| 248 |  |   } | 
| 249 |  |  | 
| 250 |  |   /// Move the blocks that belong to "region" before the given position in | 
| 251 |  |   /// another region "parent". The two regions must be different. The caller | 
| 252 |  |   /// is responsible for creating or updating the operation transferring flow | 
| 253 |  |   /// of control to the region and passing it the correct block arguments. | 
| 254 |  |   virtual void inlineRegionBefore(Region ®ion, Region &parent, | 
| 255 |  |                                   Region::iterator before); | 
| 256 |  |   void inlineRegionBefore(Region ®ion, Block *before); | 
| 257 |  |  | 
| 258 |  |   /// Clone the blocks that belong to "region" before the given position in | 
| 259 |  |   /// another region "parent". The two regions must be different. The caller is | 
| 260 |  |   /// responsible for creating or updating the operation transferring flow of | 
| 261 |  |   /// control to the region and passing it the correct block arguments. | 
| 262 |  |   virtual void cloneRegionBefore(Region ®ion, Region &parent, | 
| 263 |  |                                  Region::iterator before, | 
| 264 |  |                                  BlockAndValueMapping &mapping); | 
| 265 |  |   void cloneRegionBefore(Region ®ion, Region &parent, | 
| 266 |  |                          Region::iterator before); | 
| 267 |  |   void cloneRegionBefore(Region ®ion, Block *before); | 
| 268 |  |  | 
| 269 |  |   /// This method performs the final replacement for a pattern, where the | 
| 270 |  |   /// results of the operation are updated to use the specified list of SSA | 
| 271 |  |   /// values. | 
| 272 |  |   virtual void replaceOp(Operation *op, ValueRange newValues); | 
| 273 |  |  | 
| 274 |  |   /// Replaces the result op with a new op that is created without verification. | 
| 275 |  |   /// The result values of the two ops must be the same types. | 
| 276 |  |   template <typename OpTy, typename... Args> | 
| 277 | 0 |   void replaceOpWithNewOp(Operation *op, Args &&... args) { | 
| 278 | 0 |     auto newOp = create<OpTy>(op->getLoc(), std::forward<Args>(args)...); | 
| 279 | 0 |     replaceOpWithResultsOfAnotherOp(op, newOp.getOperation()); | 
| 280 | 0 |   } Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_13AffineApplyOpEJRNS_9AffineMapERN4llvm8ArrayRefINS_5ValueEEEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_12AffineLoadOpEJNS_5ValueERNS_9AffineMapERN4llvm8ArrayRefIS3_EEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_13AffineStoreOpEJNS_5ValueES3_RNS_9AffineMapERN4llvm8ArrayRefIS3_EEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_11AffineMinOpEJRNS_9AffineMapERN4llvm8ArrayRefINS_5ValueEEEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_11AffineMaxOpEJRNS_9AffineMapERN4llvm8ArrayRefINS_5ValueEEEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_16AffinePrefetchOpEJNS_5ValueERNS_9AffineMapERN4llvm8ArrayRefIS3_EEmbbEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_8BranchOpEJRPNS_5BlockERNS_10ValueRangeEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_6CallOpEJRNS_13SymbolRefAttrEN4llvm8ArrayRefINS_4TypeEEENS_12OperandRangeEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_8BranchOpEJPNS_5BlockENS_12OperandRangeEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_12CondBranchOpEJNS_5ValueERPNS_5BlockERNS_10ValueRangeES6_S8_EEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_8BranchOpEJRPNS_5BlockERNS_12OperandRangeEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_8BranchOpEJRPNS_5BlockERN4llvm11SmallVectorINS_5ValueELj8EEEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_12MemRefCastOpEJRNS_9SubViewOpENS_10MemRefTypeEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_12MemRefCastOpEJNS_10MemRefTypeERNS_5ValueEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_12MemRefCastOpEJRNS_6ViewOpENS_10MemRefTypeEEEEvPNS_9OperationEDpOT0_Unexecuted instantiation: _ZN4mlir15PatternRewriter18replaceOpWithNewOpINS_6ViewOpEJNS_10MemRefTypeERNS_5ValueES4_NS_12OperandRangeEEEEvPNS_9OperationEDpOT0_ | 
| 281 |  |  | 
| 282 |  |   /// This method erases an operation that is known to have no uses. | 
| 283 |  |   virtual void eraseOp(Operation *op); | 
| 284 |  |  | 
| 285 |  |   /// This method erases all operations in a block. | 
| 286 |  |   virtual void eraseBlock(Block *block); | 
| 287 |  |  | 
| 288 |  |   /// Merge the operations of block 'source' into the end of block 'dest'. | 
| 289 |  |   /// 'source's predecessors must either be empty or only contain 'dest`. | 
| 290 |  |   /// 'argValues' is used to replace the block arguments of 'source' after | 
| 291 |  |   /// merging. | 
| 292 |  |   virtual void mergeBlocks(Block *source, Block *dest, | 
| 293 |  |                            ValueRange argValues = llvm::None); | 
| 294 |  |  | 
| 295 |  |   /// Split the operations starting at "before" (inclusive) out of the given | 
| 296 |  |   /// block into a new block, and return it. | 
| 297 |  |   virtual Block *splitBlock(Block *block, Block::iterator before); | 
| 298 |  |  | 
| 299 |  |   /// This method is used to notify the rewriter that an in-place operation | 
| 300 |  |   /// modification is about to happen. A call to this function *must* be | 
| 301 |  |   /// followed by a call to either `finalizeRootUpdate` or `cancelRootUpdate`. | 
| 302 |  |   /// This is a minor efficiency win (it avoids creating a new operation and | 
| 303 |  |   /// removing the old one) but also often allows simpler code in the client. | 
| 304 | 0 |   virtual void startRootUpdate(Operation *op) {} | 
| 305 |  |  | 
| 306 |  |   /// This method is used to signal the end of a root update on the given | 
| 307 |  |   /// operation. This can only be called on operations that were provided to a | 
| 308 |  |   /// call to `startRootUpdate`. | 
| 309 | 0 |   virtual void finalizeRootUpdate(Operation *op) {} | 
| 310 |  |  | 
| 311 |  |   /// This method cancels a pending root update. This can only be called on | 
| 312 |  |   /// operations that were provided to a call to `startRootUpdate`. | 
| 313 | 0 |   virtual void cancelRootUpdate(Operation *op) {} | 
| 314 |  |  | 
| 315 |  |   /// This method is a utility wrapper around a root update of an operation. It | 
| 316 |  |   /// wraps calls to `startRootUpdate` and `finalizeRootUpdate` around the given | 
| 317 |  |   /// callable. | 
| 318 |  |   template <typename CallableT> | 
| 319 |  |   void updateRootInPlace(Operation *root, CallableT &&callable) { | 
| 320 |  |     startRootUpdate(root); | 
| 321 |  |     callable(); | 
| 322 |  |     finalizeRootUpdate(root); | 
| 323 |  |   } | 
| 324 |  |  | 
| 325 |  |   /// Notify the pattern rewriter that the pattern is failing to match the given | 
| 326 |  |   /// operation, and provide a callback to populate a diagnostic with the reason | 
| 327 |  |   /// why the failure occurred. This method allows for derived rewriters to | 
| 328 |  |   /// optionally hook into the reason why a pattern failed, and display it to | 
| 329 |  |   /// users. | 
| 330 |  |   template <typename CallbackT> | 
| 331 |  |   std::enable_if_t<!std::is_convertible<CallbackT, Twine>::value, LogicalResult> | 
| 332 | 0 |   notifyMatchFailure(Operation *op, CallbackT &&reasonCallback) { | 
| 333 | 0 | #ifndef NDEBUG | 
| 334 | 0 |     return notifyMatchFailure(op, | 
| 335 | 0 |                               function_ref<void(Diagnostic &)>(reasonCallback)); | 
| 336 | 0 | #else | 
| 337 | 0 |     return failure(); | 
| 338 | 0 | #endif | 
| 339 | 0 |   } | 
| 340 | 0 |   LogicalResult notifyMatchFailure(Operation *op, const Twine &msg) { | 
| 341 | 0 |     return notifyMatchFailure(op, [&](Diagnostic &diag) { diag << msg; }); | 
| 342 | 0 |   } | 
| 343 | 0 |   LogicalResult notifyMatchFailure(Operation *op, const char *msg) { | 
| 344 | 0 |     return notifyMatchFailure(op, Twine(msg)); | 
| 345 | 0 |   } | 
| 346 |  |  | 
| 347 |  | protected: | 
| 348 |  |   /// Initialize the builder with this rewriter as the listener. | 
| 349 |  |   explicit PatternRewriter(MLIRContext *ctx) | 
| 350 | 0 |       : OpBuilder(ctx, /*listener=*/this) {} | 
| 351 |  |   ~PatternRewriter() override; | 
| 352 |  |  | 
| 353 |  |   /// These are the callback methods that subclasses can choose to implement if | 
| 354 |  |   /// they would like to be notified about certain types of mutations. | 
| 355 |  |  | 
| 356 |  |   /// Notify the pattern rewriter that the specified operation is about to be | 
| 357 |  |   /// replaced with another set of operations.  This is called before the uses | 
| 358 |  |   /// of the operation have been changed. | 
| 359 | 0 |   virtual void notifyRootReplaced(Operation *op) {} | 
| 360 |  |  | 
| 361 |  |   /// This is called on an operation that a pattern match is removing, right | 
| 362 |  |   /// before the operation is deleted.  At this point, the operation has zero | 
| 363 |  |   /// uses. | 
| 364 | 0 |   virtual void notifyOperationRemoved(Operation *op) {} | 
| 365 |  |  | 
| 366 |  |   /// Notify the pattern rewriter that the pattern is failing to match the given | 
| 367 |  |   /// operation, and provide a callback to populate a diagnostic with the reason | 
| 368 |  |   /// why the failure occurred. This method allows for derived rewriters to | 
| 369 |  |   /// optionally hook into the reason why a pattern failed, and display it to | 
| 370 |  |   /// users. | 
| 371 |  |   virtual LogicalResult | 
| 372 |  |   notifyMatchFailure(Operation *op, | 
| 373 | 0 |                      function_ref<void(Diagnostic &)> reasonCallback) { | 
| 374 | 0 |     return failure(); | 
| 375 | 0 |   } | 
| 376 |  |  | 
| 377 |  | private: | 
| 378 |  |   /// 'op' and 'newOp' are known to have the same number of results, replace the | 
| 379 |  |   /// uses of op with uses of newOp. | 
| 380 |  |   void replaceOpWithResultsOfAnotherOp(Operation *op, Operation *newOp); | 
| 381 |  | }; | 
| 382 |  |  | 
| 383 |  | //===----------------------------------------------------------------------===// | 
| 384 |  | // Pattern-driven rewriters | 
| 385 |  | //===----------------------------------------------------------------------===// | 
| 386 |  |  | 
| 387 |  | class OwningRewritePatternList { | 
| 388 |  |   using PatternListT = std::vector<std::unique_ptr<RewritePattern>>; | 
| 389 |  |  | 
| 390 |  | public: | 
| 391 |  |   OwningRewritePatternList() = default; | 
| 392 |  |  | 
| 393 |  |   /// Construct a OwningRewritePatternList populated with the pattern `t` of | 
| 394 |  |   /// type `T`. | 
| 395 |  |   template <typename T> | 
| 396 |  |   OwningRewritePatternList(T &&t) { | 
| 397 |  |     patterns.emplace_back(std::make_unique<T>(std::forward<T>(t))); | 
| 398 |  |   } | 
| 399 |  |  | 
| 400 | 0 |   PatternListT::iterator begin() { return patterns.begin(); } | 
| 401 | 0 |   PatternListT::iterator end() { return patterns.end(); } | 
| 402 | 0 |   PatternListT::const_iterator begin() const { return patterns.begin(); } | 
| 403 | 0 |   PatternListT::const_iterator end() const { return patterns.end(); } | 
| 404 | 0 |   void clear() { patterns.clear(); } | 
| 405 |  |  | 
| 406 |  |   //===--------------------------------------------------------------------===// | 
| 407 |  |   // Pattern Insertion | 
| 408 |  |   //===--------------------------------------------------------------------===// | 
| 409 |  |  | 
| 410 |  |   /// Add an instance of each of the pattern types 'Ts' to the pattern list with | 
| 411 |  |   /// the given arguments. Return a reference to `this` for chaining insertions. | 
| 412 |  |   /// Note: ConstructorArg is necessary here to separate the two variadic lists. | 
| 413 |  |   template <typename... Ts, typename ConstructorArg, | 
| 414 |  |             typename... ConstructorArgs, | 
| 415 |  |             typename = std::enable_if_t<sizeof...(Ts) != 0>> | 
| 416 |  |   OwningRewritePatternList &insert(ConstructorArg &&arg, | 
| 417 | 0 |                                    ConstructorArgs &&... args) { | 
| 418 | 0 |     // The following expands a call to emplace_back for each of the pattern | 
| 419 | 0 |     // types 'Ts'. This magic is necessary due to a limitation in the places | 
| 420 | 0 |     // that a parameter pack can be expanded in c++11. | 
| 421 | 0 |     // FIXME: In c++17 this can be simplified by using 'fold expressions'. | 
| 422 | 0 |     using dummy = int[]; | 
| 423 | 0 |     (void)dummy{ | 
| 424 | 0 |         0, (patterns.emplace_back(std::make_unique<Ts>(arg, args...)), 0)...}; | 
| 425 | 0 |     return *this; | 
| 426 | 0 |   } Unexecuted instantiation: AffineOps.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_116SimplifyAffineOpINS_13AffineApplyOpEEEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: AffineOps.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_124AffineForEmptyLoopFolderEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: AffineOps.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_116SimplifyDeadElseEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: AffineOps.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_116SimplifyAffineOpINS_12AffineLoadOpEEEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: AffineOps.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_116SimplifyAffineOpINS_13AffineStoreOpEEEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: AffineOps.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_116SimplifyAffineOpINS_11AffineMinOpEEEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: AffineOps.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_116SimplifyAffineOpINS_11AffineMaxOpEEEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: AffineOps.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_116SimplifyAffineOpINS_16AffinePrefetchOpEEEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_118SimplifyAllocConstINS_7AllocOpEEENS2_17SimplifyDeadAllocEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_118SimplifyAllocConstINS_8AllocaOpEEEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_131SimplifyBrToBlockWithSinglePredENS2_21SimplifyPassThroughBrEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_135SimplifyIndirectCallWithKnownCalleeEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_127SimplifyConstCondBranchPredENS2_29SimplifyPassThroughCondBranchENS2_37SimplifyCondBranchIdenticalSuccessorsEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_119SimplifyDeadDeallocEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_136ExtractElementFromTensorFromElementsEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_131SubViewOpConstantArgumentFolderENS2_25SubViewOpMemRefCastFolderEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_Unexecuted instantiation: Ops.cpp:_ZN4mlir24OwningRewritePatternList6insertIJN12_GLOBAL__N_117ViewOpShapeFolderENS2_22ViewOpMemrefCastFolderEERPNS_11MLIRContextEJEvEERS0_OT0_DpOT1_ | 
| 427 |  |  | 
| 428 |  | private: | 
| 429 |  |   PatternListT patterns; | 
| 430 |  | }; | 
| 431 |  |  | 
| 432 |  | /// This class manages optimization and execution of a group of rewrite | 
| 433 |  | /// patterns, providing an API for finding and applying, the best match against | 
| 434 |  | /// a given node. | 
| 435 |  | /// | 
| 436 |  | class RewritePatternMatcher { | 
| 437 |  | public: | 
| 438 |  |   /// Create a RewritePatternMatcher with the specified set of patterns. | 
| 439 |  |   explicit RewritePatternMatcher(const OwningRewritePatternList &patterns); | 
| 440 |  |  | 
| 441 |  |   /// Try to match the given operation to a pattern and rewrite it. Return | 
| 442 |  |   /// true if any pattern matches. | 
| 443 |  |   bool matchAndRewrite(Operation *op, PatternRewriter &rewriter); | 
| 444 |  |  | 
| 445 |  | private: | 
| 446 |  |   RewritePatternMatcher(const RewritePatternMatcher &) = delete; | 
| 447 |  |   void operator=(const RewritePatternMatcher &) = delete; | 
| 448 |  |  | 
| 449 |  |   /// The group of patterns that are matched for optimization through this | 
| 450 |  |   /// matcher. | 
| 451 |  |   std::vector<RewritePattern *> patterns; | 
| 452 |  | }; | 
| 453 |  |  | 
| 454 |  | /// Rewrite the regions of the specified operation, which must be isolated from | 
| 455 |  | /// above, by repeatedly applying the highest benefit patterns in a greedy | 
| 456 |  | /// work-list driven manner. Return true if no more patterns can be matched in | 
| 457 |  | /// the result operation regions. | 
| 458 |  | /// Note: This does not apply patterns to the top-level operation itself. | 
| 459 |  | /// Note: These methods also perform folding and simple dead-code elimination | 
| 460 |  | ///       before attempting to match any of the provided patterns. | 
| 461 |  | /// | 
| 462 |  | bool applyPatternsAndFoldGreedily(Operation *op, | 
| 463 |  |                                   const OwningRewritePatternList &patterns); | 
| 464 |  | /// Rewrite the given regions, which must be isolated from above. | 
| 465 |  | bool applyPatternsAndFoldGreedily(MutableArrayRef<Region> regions, | 
| 466 |  |                                   const OwningRewritePatternList &patterns); | 
| 467 |  |  | 
| 468 |  | /// Applies the specified patterns on `op` alone while also trying to fold it, | 
| 469 |  | /// by selecting the highest benefits patterns in a greedy manner. Returns true | 
| 470 |  | /// if no more patterns can be matched. `erased` is set to true if `op` was | 
| 471 |  | /// folded away or erased as a result of becoming dead. Note: This does not | 
| 472 |  | /// apply any patterns recursively to the regions of `op`. | 
| 473 |  | bool applyOpPatternsAndFold(Operation *op, | 
| 474 |  |                             const OwningRewritePatternList &patterns, | 
| 475 |  |                             bool *erased = nullptr); | 
| 476 |  | } // end namespace mlir | 
| 477 |  |  | 
| 478 |  | #endif // MLIR_PATTERN_MATCH_H |