brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · a628126 Raw
68 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir/Dialect/ControlFlow/Transforms/BufferizableOpInterfaceImpl.h"10 11#include "mlir/Dialect/Bufferization/IR/UnstructuredControlFlow.h"12#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"13#include "mlir/IR/Operation.h"14 15using namespace mlir;16using namespace mlir::bufferization;17 18namespace mlir {19namespace cf {20namespace {21 22template <typename ConcreteModel, typename ConcreteOp>23struct BranchLikeOpInterface24    : 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,42                          const BufferizationOptions &options,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.50struct BranchOpInterface51    : public BranchLikeOpInterface<BranchOpInterface, cf::BranchOp> {};52 53/// Bufferization of cf.cond_br.54struct CondBranchOpInterface55    : public BranchLikeOpInterface<CondBranchOpInterface, cf::CondBranchOp> {};56 57} // namespace58} // namespace cf59} // namespace mlir60 61void mlir::cf::registerBufferizableOpInterfaceExternalModels(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}68