10 llvm::SmallDenseSet<Value, 16> seenValues;
11 while (!workList.empty()) {
13 Value current = workList.pop_back_val();
16 if (!seenValues.insert(current).second)
40 unsigned operandNumber) {
46 auto *it = llvm::find_if(successors, [&successor](
RegionSuccessor curr) {
49 return it != successors.end();
55 regionOp.getEntrySuccessorRegions(operandAttributes, successors);
56 if (isContained(successors, successor)) {
57 OperandRange operands = regionOp.getEntrySuccessorOperands(successor);
58 predecessorOperands.push_back(operands[operandNumber]);
62 for (
Region ®ion : regionOp->getRegions()) {
63 for (
Block &block : region) {
65 dyn_cast<RegionBranchTerminatorOpInterface>(block.getTerminator());
70 terminatorOp.getSuccessorRegions(operandAttributes, successors);
71 if (isContained(successors, successor)) {
72 OperandRange operands = terminatorOp.getSuccessorOperands(successor);
73 predecessorOperands.push_back(operands[operandNumber]);
78 return predecessorOperands;
83 static std::optional<SmallVector<Value>>
90 Block *predecessor = *it;
91 auto branchOp = dyn_cast<BranchOpInterface>(predecessor->
getTerminator());
95 branchOp.getSuccessorOperands(it.getSuccessorIndex());
99 predecessorOperands.push_back(operand);
102 return predecessorOperands;
105 std::optional<SmallVector<Value>>
107 if (
OpResult opResult = dyn_cast<OpResult>(value)) {
108 if (
auto selectOp = opResult.getDefiningOp<SelectLikeOpInterface>())
110 {selectOp.getTrueValue(), selectOp.getFalseValue()});
111 auto regionOp = opResult.getDefiningOp<RegionBranchOpInterface>();
119 regionOp, region, opResult.getResultNumber());
120 return predecessorOperands;
123 auto blockArg = cast<BlockArgument>(value);
124 Block *block = blockArg.getOwner();
127 if (
auto regionBranchOp =
128 dyn_cast<RegionBranchOpInterface>(block->
getParentOp())) {
131 regionBranchOp, region, blockArg.getArgNumber());
132 return predecessorOperands;
static std::optional< SmallVector< Value > > getBlockPredecessorOperands(BlockArgument blockArg)
Returns the predecessor branch operands that match blockArg, or nullopt if some of the predecessor te...
static SmallVector< Value > getRegionPredecessorOperands(RegionBranchOpInterface regionOp, RegionSuccessor successor, unsigned operandNumber)
Returns the operands from all predecessor regions that match operandNumber for the successor region w...
This class represents an argument of a Block.
Block * getOwner() const
Returns the block that owns this argument.
unsigned getArgNumber() const
Returns the number of this argument.
Block represents an ordered list of Operations.
pred_iterator pred_begin()
Operation * getTerminator()
Get the terminator operation of this block.
bool isEntryBlock()
Return if this block is the entry block in the parent region.
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
This is a value defined by a result of an operation.
This class implements the operand iterators for the Operation class.
This class represents a successor of a region.
Region * getSuccessor() const
Return the given region successor.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This class models how operands are forwarded to block arguments in control flow.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
A class to signal how to proceed with the walk of the backward slice:
bool wasInterrupted() const
Returns true if the walk was interrupted.
bool wasAdvancedTo() const
Returns true if the walk was advanced to user-specified values.
static WalkContinuation skip()
Creates a continuation that advances the walk without adding any predecessor values to the work list.
mlir::ArrayRef< mlir::Value > getNextValues() const
Returns the next values to continue the walk with.
bool wasSkipped() const
Returns true if the walk was skipped.
Include the generated interface declarations.
std::optional< SmallVector< Value > > getControlFlowPredecessors(Value value)
Computes a vector of all control predecessors of value.
WalkContinuation walkSlice(mlir::ValueRange rootValues, WalkCallback walkCallback)
Walks the slice starting from the rootValues using a depth-first traversal.