1 //===- LinalgToStandard.h - Utils to convert from the linalg dialect ------===// 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_CONVERSION_LINALGTOSTANDARD_LINALGTOSTANDARD_H_ 10 #define MLIR_CONVERSION_LINALGTOSTANDARD_LINALGTOSTANDARD_H_ 11 12 #include "mlir/Dialect/Linalg/IR/Linalg.h" 13 #include "mlir/Transforms/DialectConversion.h" 14 15 namespace mlir { 16 class ModuleOp; 17 template <typename T> 18 class OperationPass; 19 20 #define GEN_PASS_DECL_CONVERTLINALGTOSTANDARD 21 #include "mlir/Conversion/Passes.h.inc" 22 23 namespace linalg { 24 25 //===----------------------------------------------------------------------===// 26 // Patterns to convert a LinalgOp to func.call @external library implementation. 27 //===----------------------------------------------------------------------===// 28 // These patterns are exposed individually because they are expected to be 29 // typically used individually. 30 31 // Create a new call to the type-canonicalized `LinalgOp::getLibraryCallName()` 32 // function. The implementation of the function can be either in the same module 33 // or in an externally linked library. 34 // This is a generic entry point for all LinalgOp, except for CopyOp, for which 35 // more specialized patterns are provided. 36 class LinalgOpToLibraryCallRewrite 37 : public OpInterfaceRewritePattern<LinalgOp> { 38 public: 39 using OpInterfaceRewritePattern<LinalgOp>::OpInterfaceRewritePattern; 40 41 LogicalResult matchAndRewrite(LinalgOp op, 42 PatternRewriter &rewriter) const override; 43 }; 44 45 /// Populate the given list with patterns that convert from Linalg to Standard. 46 void populateLinalgToStandardConversionPatterns(RewritePatternSet &patterns); 47 48 } // namespace linalg 49 50 /// Create a pass to convert Linalg operations to the Standard dialect. 51 std::unique_ptr<OperationPass<ModuleOp>> createConvertLinalgToStandardPass(); 52 53 } // namespace mlir 54 55 #endif // MLIR_CONVERSION_LINALGTOSTANDARD_LINALGTOSTANDARD_H_ 56