1 //===- FrozenRewritePatternList.h - FrozenRewritePatternList ----*- 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_FROZENREWRITEPATTERNLIST_H 10 #define MLIR_REWRITE_FROZENREWRITEPATTERNLIST_H 11 12 #include "mlir/IR/PatternMatch.h" 13 14 namespace mlir { 15 namespace detail { 16 class PDLByteCode; 17 } // end 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. 22 class FrozenRewritePatternList { 23 using NativePatternListT = std::vector<std::unique_ptr<RewritePattern>>; 24 25 public: 26 /// Freeze the patterns held in `patterns`, and take ownership. 27 FrozenRewritePatternList(OwningRewritePatternList &&patterns); 28 FrozenRewritePatternList(FrozenRewritePatternList &&patterns); 29 ~FrozenRewritePatternList(); 30 31 /// Return the native patterns held by this list. 32 iterator_range<llvm::pointee_iterator<NativePatternListT::const_iterator>> getNativePatterns()33 getNativePatterns() const { 34 return llvm::make_pointee_range(nativePatterns); 35 } 36 37 /// Return the compiled PDL bytecode held by this list. Returns null if 38 /// there are no PDL patterns within the list. getPDLByteCode()39 const detail::PDLByteCode *getPDLByteCode() const { 40 return pdlByteCode.get(); 41 } 42 43 private: 44 /// The set of. 45 std::vector<std::unique_ptr<RewritePattern>> nativePatterns; 46 47 /// The bytecode containing the compiled PDL patterns. 48 std::unique_ptr<detail::PDLByteCode> pdlByteCode; 49 }; 50 51 } // end namespace mlir 52 53 #endif // MLIR_REWRITE_FROZENREWRITEPATTERNLIST_H 54