1 //===- UnstructuredControlFlow.cpp - Op Interface Helpers ----------------===// 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 9 #include "mlir/Dialect/Bufferization/IR/UnstructuredControlFlow.h" 10 11 using namespace mlir; 12 13 SmallVector<OpOperand *> getCallerOpOperands(BlockArgument bbArg)14mlir::bufferization::detail::getCallerOpOperands(BlockArgument bbArg) { 15 SmallVector<OpOperand *> result; 16 Block *block = bbArg.getOwner(); 17 for (Operation *caller : block->getUsers()) { 18 auto branchOp = dyn_cast<BranchOpInterface>(caller); 19 assert(branchOp && "expected that all callers implement BranchOpInterface"); 20 auto it = llvm::find(caller->getSuccessors(), block); 21 assert(it != caller->getSuccessors().end() && "could not find successor"); 22 int64_t successorIdx = std::distance(caller->getSuccessors().begin(), it); 23 SuccessorOperands operands = branchOp.getSuccessorOperands(successorIdx); 24 assert(operands.getProducedOperandCount() == 0 && 25 "produced operands not supported"); 26 int64_t operandIndex = 27 operands.getForwardedOperands().getBeginOperandIndex() + 28 bbArg.getArgNumber(); 29 result.push_back(&caller->getOpOperand(operandIndex)); 30 } 31 return result; 32 } 33