MLIR  20.0.0git
UnstructuredControlFlow.cpp
Go to the documentation of this file.
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 
10 
11 using namespace mlir;
12 
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 =
28  bbArg.getArgNumber();
29  result.push_back(&caller->getOpOperand(operandIndex));
30  }
31  return result;
32 }
This class represents an argument of a Block.
Definition: Value.h:319
Block * getOwner() const
Returns the block that owns this argument.
Definition: Value.h:328
unsigned getArgNumber() const
Returns the number of this argument.
Definition: Value.h:331
Block represents an ordered list of Operations.
Definition: Block.h:33
user_range getUsers() const
Returns a range of all users.
Definition: UseDefLists.h:274
unsigned getBeginOperandIndex() const
Return the operand index of the first element of this range.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
This class models how operands are forwarded to block arguments in control flow.
unsigned getProducedOperandCount() const
Returns the amount of operands that are produced internally by the operation.
OperandRange getForwardedOperands() const
Get the range of operands that are simply forwarded to the successor.
SmallVector< OpOperand * > getCallerOpOperands(BlockArgument bbArg)
Return a list of operands that are forwarded to the given block argument.
Include the generated interface declarations.