1 //===- Passes.h - Linalg pass entry points ----------------------*- 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 // This header file defines prototypes that expose pass constructors. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef MLIR_DIALECT_LINALG_PASSES_H_ 14 #define MLIR_DIALECT_LINALG_PASSES_H_ 15 16 #include "mlir/Pass/Pass.h" 17 18 namespace mlir { 19 std::unique_ptr<OperationPass<FuncOp>> createConvertElementwiseToLinalgPass(); 20 21 std::unique_ptr<OperationPass<FuncOp>> createLinalgFoldUnitExtentDimsPass(); 22 23 std::unique_ptr<Pass> createLinalgFusionOfTensorOpsPass(); 24 std::unique_ptr<Pass> createFoldReshapeOpsByLinearizationPass(); 25 26 std::unique_ptr<OperationPass<FuncOp>> 27 createLinalgTilingPass(ArrayRef<int64_t> tileSizes = {}); 28 29 std::unique_ptr<OperationPass<FuncOp>> 30 createLinalgTilingToParallelLoopsPass(ArrayRef<int64_t> tileSizes = {}); 31 32 std::unique_ptr<OperationPass<FuncOp>> 33 createLinalgPromotionPass(bool dynamicBuffers, bool useAlloca); 34 std::unique_ptr<OperationPass<FuncOp>> createLinalgPromotionPass(); 35 36 /// Create a pass to convert Linalg operations to scf.for loops and 37 /// std.load/std.store accesses. 38 std::unique_ptr<OperationPass<FuncOp>> createConvertLinalgToLoopsPass(); 39 40 /// Create a pass to convert Linalg operations to scf.parallel loops and 41 /// std.load/std.store accesses. 42 std::unique_ptr<OperationPass<FuncOp>> createConvertLinalgToParallelLoopsPass(); 43 44 /// Create a pass to convert Linalg operations to affine.for loops and 45 /// affine_load/affine_store accesses. 46 /// Placeholder for now, this is NYI. 47 std::unique_ptr<OperationPass<FuncOp>> createConvertLinalgToAffineLoopsPass(); 48 49 /// Create a pass to convert Linalg operations which work on tensors to use 50 /// buffers instead. 51 std::unique_ptr<OperationPass<FuncOp>> createLinalgBufferizePass(); 52 53 /// Populate patterns that convert `ElementwiseMappable` ops to linalg 54 /// parallel loops. 55 void populateElementwiseToLinalgConversionPatterns( 56 OwningRewritePatternList &patterns, MLIRContext *ctx); 57 58 /// Create a pass to conver named Linalg operations to Linalg generic 59 /// operations. 60 std::unique_ptr<OperationPass<FuncOp>> createLinalgGeneralizationPass(); 61 62 /// Patterns to fold an expanding (collapsing) tensor_reshape operation with its 63 /// producer (consumer) generic operation by expanding the dimensionality of the 64 /// loop in the generic op. 65 void populateFoldReshapeOpsByExpansionPatterns( 66 MLIRContext *context, OwningRewritePatternList &patterns); 67 68 /// Patterns to fold a collapsing (expanding) tensor_reshape operation with its 69 /// producer (consumer) generic/indexed_generic operation by linearizing the 70 /// indexing map used to access the source (target) of the reshape operation in 71 /// the generic/indexed_generic operation. 72 void populateFoldReshapeOpsByLinearizationPatterns( 73 MLIRContext *context, OwningRewritePatternList &patterns); 74 75 /// Patterns for fusing linalg operation on tensors. 76 void populateLinalgTensorOpsFusionPatterns(MLIRContext *context, 77 OwningRewritePatternList &patterns); 78 79 /// Patterns to fold unit-extent dimensions in operands/results of linalg ops on 80 /// tensors. 81 void populateLinalgFoldUnitExtentDimsPatterns( 82 MLIRContext *context, OwningRewritePatternList &patterns); 83 84 //===----------------------------------------------------------------------===// 85 // Registration 86 //===----------------------------------------------------------------------===// 87 88 /// Generate the code for registering passes. 89 #define GEN_PASS_REGISTRATION 90 #include "mlir/Dialect/Linalg/Passes.h.inc" 91 92 } // namespace mlir 93 94 #endif // MLIR_DIALECT_LINALG_PASSES_H_ 95