MLIR  19.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_ARITHBUFFERIZEPASS
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::ArithBufferizePassBase<ArithBufferizePass> {
32  using ArithBufferizePassBase::ArithBufferizePassBase;
33 
34  ArithBufferizePass(uint64_t alignment = 0, bool constantOpOnly = false)
35  : constantOpOnly(constantOpOnly) {
36  this->alignment = alignment;
37  }
38 
39  void runOnOperation() override {
41  if (constantOpOnly) {
42  options.opFilter.allowOperation<arith::ConstantOp>();
43  } else {
44  options.opFilter.allowDialect<arith::ArithDialect>();
45  }
46  options.bufferAlignment = alignment;
47 
48  if (failed(bufferizeOp(getOperation(), options)))
49  signalPassFailure();
50  }
51 
52  void getDependentDialects(DialectRegistry &registry) const override {
53  registry.insert<bufferization::BufferizationDialect, memref::MemRefDialect,
54  arith::ArithDialect>();
56  }
57 
58 private:
59  bool constantOpOnly;
60 };
61 } // namespace
62 
63 std::unique_ptr<Pass>
65  return std::make_unique<ArithBufferizePass>(alignment,
66  /*constantOpOnly=*/true);
67 }
static llvm::ManagedStatic< PassManagerOptions > options
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void registerBufferizableOpInterfaceExternalModels(DialectRegistry &registry)
std::unique_ptr< Pass > createConstantBufferizePass(uint64_t alignment=0)
Create a pass to bufferize arith.constant ops.
Definition: Bufferize.cpp:64
LogicalResult bufferizeOp(Operation *op, const BufferizationOptions &options, BufferizationStatistics *statistics=nullptr)
Bufferize op and its nested ops that implement BufferizableOpInterface.
Definition: Bufferize.cpp:441
BufferizationOptions getPartialBufferizationOptions()
Return BufferizationOptions such that the bufferizeOp behaves like the old (deprecated) partial,...
Definition: Bufferize.cpp:645
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.