MLIR  17.0.0git
Bufferize.cpp
Go to the documentation of this file.
1 //===- Bufferize.cpp - Bufferization for Arith ops ---------*- 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 
10 
17 
18 namespace mlir {
19 namespace arith {
20 #define GEN_PASS_DEF_ARITHBUFFERIZE
21 #include "mlir/Dialect/Arith/Transforms/Passes.h.inc"
22 } // namespace arith
23 } // namespace mlir
24 
25 using namespace mlir;
26 using namespace bufferization;
27 
28 namespace {
29 /// Pass to bufferize Arith ops.
30 struct ArithBufferizePass
31  : public arith::impl::ArithBufferizeBase<ArithBufferizePass> {
32  ArithBufferizePass(uint64_t alignment = 0, bool constantOpOnly = false)
33  : constantOpOnly(constantOpOnly) {
34  this->alignment = alignment;
35  }
36 
37  void runOnOperation() override {
39  if (constantOpOnly) {
40  options.opFilter.allowOperation<arith::ConstantOp>();
41  } else {
42  options.opFilter.allowDialect<arith::ArithDialect>();
43  }
44  options.bufferAlignment = alignment;
45 
46  if (failed(bufferizeOp(getOperation(), options)))
47  signalPassFailure();
48  }
49 
50  void getDependentDialects(DialectRegistry &registry) const override {
51  registry.insert<bufferization::BufferizationDialect, memref::MemRefDialect,
52  arith::ArithDialect>();
54  }
55 
56 private:
57  bool constantOpOnly;
58 };
59 } // namespace
60 
61 std::unique_ptr<Pass> mlir::arith::createArithBufferizePass() {
62  return std::make_unique<ArithBufferizePass>();
63 }
64 
65 std::unique_ptr<Pass>
67  return std::make_unique<ArithBufferizePass>(alignment,
68  /*constantOpOnly=*/true);
69 }
static llvm::ManagedStatic< PassManagerOptions > options
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
std::unique_ptr< Pass > createArithBufferizePass()
Create a pass to bufferize Arith ops.
Definition: Bufferize.cpp:61
void registerBufferizableOpInterfaceExternalModels(DialectRegistry &registry)
std::unique_ptr< Pass > createConstantBufferizePass(uint64_t alignment=0)
Create a pass to bufferize arith.constant ops.
Definition: Bufferize.cpp:66
LogicalResult bufferizeOp(Operation *op, const BufferizationOptions &options, bool copyBeforeWrite=true, const OpFilter *opFilter=nullptr, BufferizationStatistics *statistics=nullptr)
Bufferize op and its nested ops that implement BufferizableOpInterface.
Definition: Bufferize.cpp:421
BufferizationOptions getPartialBufferizationOptions()
Definition: Bufferize.cpp:529
Include the generated interface declarations.
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.