MLIR  22.0.0git
BufferizableOpInterfaceImpl.cpp
Go to the documentation of this file.
1 //===- BufferizableOpInterfaceImpl.cpp - Impl. of BufferizableOpInterface -===//
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 
13 #include "mlir/IR/Operation.h"
14 
15 using namespace mlir;
16 using namespace mlir::bufferization;
17 
18 namespace mlir {
19 namespace cf {
20 namespace {
21 
22 template <typename ConcreteModel, typename ConcreteOp>
23 struct BranchLikeOpInterface
24  : public BranchOpBufferizableOpInterfaceExternalModel<ConcreteModel,
25  ConcreteOp> {
26  bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
27  const AnalysisState &state) const {
28  return false;
29  }
30 
31  bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
32  const AnalysisState &state) const {
33  return false;
34  }
35 
36  LogicalResult verifyAnalysis(Operation *op,
37  const AnalysisState &state) const {
38  return success();
39  }
40 
41  LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
43  BufferizationState &state) const {
44  // The operands of this op are bufferized together with the block signature.
45  return success();
46  }
47 };
48 
49 /// Bufferization of cf.br.
50 struct BranchOpInterface
51  : public BranchLikeOpInterface<BranchOpInterface, cf::BranchOp> {};
52 
53 /// Bufferization of cf.cond_br.
54 struct CondBranchOpInterface
55  : public BranchLikeOpInterface<CondBranchOpInterface, cf::CondBranchOp> {};
56 
57 } // namespace
58 } // namespace cf
59 } // namespace mlir
60 
62  DialectRegistry &registry) {
63  registry.addExtension(+[](MLIRContext *ctx, cf::ControlFlowDialect *dialect) {
64  cf::BranchOp::attachInterface<BranchOpInterface>(*ctx);
65  cf::CondBranchOp::attachInterface<CondBranchOpInterface>(*ctx);
66  });
67 }
static llvm::ManagedStatic< PassManagerOptions > options
Base class for generic analysis states.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
This class represents an operand of an operation.
Definition: Value.h:257
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Definition: PatternMatch.h:358
BufferizationState provides information about the state of the IR during the bufferization process.
void registerBufferizableOpInterfaceExternalModels(DialectRegistry &registry)
Include the generated interface declarations.
A template that provides a default implementation of getAliasingValues for ops that implement the Bra...
Options for BufferizableOpInterface-based bufferization.