1 //===- Bufferize.h - Bufferization utilities --------------------*- 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 // We use the term "bufferize" to mean conversion from tensor types to 10 // memref types. 11 // 12 // Generally speaking, for each op that operates on tensor types, a conversion 13 // pattern needs to be written. The infrastructure in this file assists in 14 // defining these conversion patterns in a composable way. 15 // 16 // Bufferization conversion patterns should generally use the ordinary 17 // conversion pattern classes (e.g. OpConversionPattern). A TypeConverter 18 // (accessible with getTypeConverter()) is available if needed for converting 19 // types. 20 // 21 //===----------------------------------------------------------------------===// 22 23 #ifndef MLIR_TRANSFORMS_BUFFERIZE_H 24 #define MLIR_TRANSFORMS_BUFFERIZE_H 25 26 #include "mlir/Analysis/BufferAliasAnalysis.h" 27 #include "mlir/Analysis/Liveness.h" 28 #include "mlir/Dialect/StandardOps/IR/Ops.h" 29 #include "mlir/IR/Builders.h" 30 #include "mlir/IR/BuiltinOps.h" 31 #include "mlir/IR/Dominance.h" 32 #include "mlir/IR/Operation.h" 33 #include "mlir/Transforms/DialectConversion.h" 34 35 namespace mlir { 36 37 /// A helper type converter class that automatically populates the relevant 38 /// materializations and type conversions for bufferization. 39 class BufferizeTypeConverter : public TypeConverter { 40 public: 41 BufferizeTypeConverter(); 42 }; 43 44 /// Marks ops used by bufferization for type conversion materializations as 45 /// "legal" in the given ConversionTarget. 46 /// 47 /// This function should be called by all bufferization passes using 48 /// BufferizeTypeConverter so that materializations work proprely. One exception 49 /// is bufferization passes doing "full" conversions, where it can be desirable 50 /// for even the materializations to remain illegal so that they are eliminated, 51 /// such as via the patterns in 52 /// populateEliminateBufferizeMaterializationsPatterns. 53 void populateBufferizeMaterializationLegality(ConversionTarget &target); 54 55 /// Populate patterns to eliminate bufferize materializations. 56 /// 57 /// In particular, these are the tensor_load/tensor_to_memref ops. 58 void populateEliminateBufferizeMaterializationsPatterns( 59 MLIRContext *context, BufferizeTypeConverter &typeConverter, 60 OwningRewritePatternList &patterns); 61 62 } // end namespace mlir 63 64 #endif // MLIR_TRANSFORMS_BUFFERIZE_H 65