MLIR  18.0.0git
Bufferize.cpp
Go to the documentation of this file.
1 //===- Bufferize.cpp - Bufferization of linalg ops ------------------------===//
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 
10 
19 #include "mlir/IR/BuiltinDialect.h"
20 #include "mlir/IR/Operation.h"
21 #include "mlir/Pass/Pass.h"
22 
23 namespace mlir {
24 #define GEN_PASS_DEF_LINALGBUFFERIZE
25 #include "mlir/Dialect/Linalg/Passes.h.inc"
26 } // namespace mlir
27 
28 using namespace mlir;
29 using namespace bufferization;
30 
31 namespace {
32 /// Converts Linalg operations that work on tensor-type operands or results to
33 /// work on buffers.
34 struct LinalgBufferizePass
35  : public impl::LinalgBufferizeBase<LinalgBufferizePass> {
36  void runOnOperation() override {
38  options.opFilter.allowDialect<linalg::LinalgDialect>();
39 
40  if (failed(bufferizeOp(getOperation(), options)))
41  signalPassFailure();
42  }
43 
44  void getDependentDialects(DialectRegistry &registry) const override {
45  registry.insert<bufferization::BufferizationDialect, memref::MemRefDialect,
46  tensor::TensorDialect, linalg::LinalgDialect>();
48  }
49 };
50 } // namespace
51 
52 std::unique_ptr<Pass> mlir::createLinalgBufferizePass() {
53  return std::make_unique<LinalgBufferizePass>();
54 }
static llvm::ManagedStatic< PassManagerOptions > options
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
LogicalResult bufferizeOp(Operation *op, const BufferizationOptions &options, BufferizationStatistics *statistics=nullptr)
Bufferize op and its nested ops that implement BufferizableOpInterface.
Definition: Bufferize.cpp:451
BufferizationOptions getPartialBufferizationOptions()
Return BufferizationOptions such that the bufferizeOp behaves like the old (deprecated) partial,...
Definition: Bufferize.cpp:653
void registerBufferizableOpInterfaceExternalModels(DialectRegistry &registry)
Include the generated interface declarations.
std::unique_ptr< Pass > createLinalgBufferizePass()
Create a pass to convert Linalg operations which work on tensors to use buffers instead.
Definition: Bufferize.cpp:52
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72
Options for BufferizableOpInterface-based bufferization.