MLIR  19.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 
16 #include "mlir/IR/Dialect.h"
17 #include "mlir/IR/Operation.h"
18 
19 using namespace mlir;
20 using namespace mlir::bufferization;
21 
22 namespace mlir {
23 namespace cf {
24 namespace {
25 
26 template <typename ConcreteModel, typename ConcreteOp>
27 struct BranchLikeOpInterface
28  : public BranchOpBufferizableOpInterfaceExternalModel<ConcreteModel,
29  ConcreteOp> {
30  bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
31  const AnalysisState &state) const {
32  return false;
33  }
34 
35  bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
36  const AnalysisState &state) const {
37  return false;
38  }
39 
40  LogicalResult verifyAnalysis(Operation *op,
41  const AnalysisState &state) const {
42  return success();
43  }
44 
45  LogicalResult bufferize(Operation *op, RewriterBase &rewriter,
46  const BufferizationOptions &options) const {
47  // The operands of this op are bufferized together with the block signature.
48  return success();
49  }
50 };
51 
52 /// Bufferization of cf.br.
53 struct BranchOpInterface
54  : public BranchLikeOpInterface<BranchOpInterface, cf::BranchOp> {};
55 
56 /// Bufferization of cf.cond_br.
57 struct CondBranchOpInterface
58  : public BranchLikeOpInterface<CondBranchOpInterface, cf::CondBranchOp> {};
59 
60 } // namespace
61 } // namespace cf
62 } // namespace mlir
63 
65  DialectRegistry &registry) {
66  registry.addExtension(+[](MLIRContext *ctx, cf::ControlFlowDialect *dialect) {
67  cf::BranchOp::attachInterface<BranchOpInterface>(*ctx);
68  cf::CondBranchOp::attachInterface<CondBranchOpInterface>(*ctx);
69  });
70 }
static llvm::ManagedStatic< PassManagerOptions > options
Base class for generic analysis states.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void addExtension(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:267
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:400
void registerBufferizableOpInterfaceExternalModels(DialectRegistry &registry)
Include the generated interface declarations.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
A template that provides a default implementation of getAliasingValues for ops that implement the Bra...
Options for BufferizableOpInterface-based bufferization.