10 llvm::SmallDenseSet<Value, 16> seenValues;
11 while (!workList.empty()) {
13 Value current = workList.pop_back_val();
16 if (!seenValues.insert(current).second)
37static std::optional<SmallVector<Value>>
44 Block *predecessor = *it;
45 auto branchOp = dyn_cast<BranchOpInterface>(predecessor->
getTerminator());
49 branchOp.getSuccessorOperands(it.getSuccessorIndex());
53 predecessorOperands.push_back(operand);
56 return predecessorOperands;
59std::optional<SmallVector<Value>>
61 if (
OpResult opResult = dyn_cast<OpResult>(value)) {
62 if (
auto selectOp = opResult.getDefiningOp<SelectLikeOpInterface>())
64 {selectOp.getTrueValue(), selectOp.getFalseValue()});
65 auto regionOp = opResult.getDefiningOp<RegionBranchOpInterface>();
75 regionOp.getPredecessorValues(region, opResult.getResultNumber(),
77 return predecessorOperands;
80 auto blockArg = cast<BlockArgument>(value);
81 Block *block = blockArg.getOwner();
84 if (
auto regionBranchOp =
85 dyn_cast<RegionBranchOpInterface>(block->
getParentOp())) {
90 regionBranchOp.getPredecessorValues(region, blockArg.getArgNumber(),
92 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...
This class represents an argument of a Block.
unsigned getArgNumber() const
Returns the number of this argument.
Block * getOwner() const
Returns the block that owns 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 represents a successor of a region.
static RegionSuccessor parent()
Initialize a successor that branches after/out of the parent operation.
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.
mlir::function_ref< WalkContinuation(mlir::Value)> WalkCallback
A callback that is invoked for each value encountered during the walk of the slice.