19#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/SetVector.h"
38 if (filter && !filter(op))
42 for (
Block &block : region)
44 if (forwardSlice->count(&blockOp) == 0) {
50 visited.insert(&blockOp);
52 visited.erase(&blockOp);
65 if (forwardSlice->count(userOp) == 0 && visited.insert(userOp).second) {
67 visited.erase(userOp);
71 forwardSlice->insert(op);
82 forwardSlice->remove(op);
84 assert(visited.size() == 1 &&
"visited set should only contain op");
90 forwardSlice->insert(v.rbegin(), v.rend());
101 assert(visited.empty() &&
"visited set should be empty");
107 forwardSlice->insert(v.rbegin(), v.rend());
124 if (
auto *definingOp = value.getDefiningOp()) {
125 if (backwardSlice->count(definingOp) == 0 &&
126 visited.insert(definingOp).second) {
129 visited.erase(definingOp);
132 }
else if (
auto blockArg = dyn_cast<BlockArgument>(value)) {
133 if (
options.omitBlockArguments)
136 Block *block = blockArg.getOwner();
141 if (parentOp && backwardSlice->count(parentOp) == 0) {
155 bool succeeded =
true;
157 if (!
options.omitUsesFromAbove &&
162 SmallPtrSet<Region *, 4> descendents;
164 [&](Region *childRegion) { descendents.insert(childRegion); });
167 if (!descendents.contains(operand.get().getParentRegion()))
178 backwardSlice->insert(op);
189 assert(visited.size() == 1 &&
"visited set should only contain op");
194 backwardSlice->remove(op);
215 unsigned currentIndex = 0;
218 while (currentIndex != slice.size()) {
219 auto *currentOp = (slice)[currentIndex];
221 backwardSlice.clear();
224 assert(
result.succeeded());
226 slice.insert_range(backwardSlice);
229 forwardSlice.clear();
231 slice.insert_range(forwardSlice);
249 assert(
result.succeeded());
255 if (iterCarriedValSet.contains(value))
259 for (
Value operand : op->getOperands())
260 if (iterCarriedValSet.contains(operand))
297 assert(redPos < iterCarriedArgs.size() &&
"'redPos' is out of bounds");
312 iterCarriedArgs.front().getOwner()->getParent()->getParentOp();
324 combinerOps.push_back(combinerOp);
325 combinerOp = *combinerOp->
getUsers().begin();
330 if (combinerOps.size() != 1)
337 terminatorOp->
getOperand(redPos) != combinerOps.back()->getResults()[0])
static llvm::ManagedStatic< PassManagerOptions > options
static void processValue(Value value, LiveMap &liveMap)
static LogicalResult getBackwardSliceImpl(Operation *op, DenseSet< Operation * > &visited, SetVector< Operation * > *backwardSlice, const BackwardSliceOptions &options)
static bool dependsOnCarriedVals(Value value, ArrayRef< BlockArgument > iterCarriedArgs, Operation *ancestorOp)
Returns true if value (transitively) depends on iteration-carried values of the given ancestorOp.
static void getForwardSliceImpl(Operation *op, DenseSet< Operation * > &visited, SetVector< Operation * > *forwardSlice, const SliceOptions::TransitiveFilter &filter=nullptr)
This class represents an argument of a Block.
Block represents an ordered list of Operations.
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
This class represents an operand of an operation.
This class provides the API for ops that are known to be isolated from above.
This class provides the API for ops that are known to be terminators.
Operation is the basic unit of execution within MLIR.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
Value getOperand(unsigned idx)
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
bool mightHaveTrait()
Returns true if the operation might have the provided trait.
bool hasOneUse()
Returns true if this operation has exactly one use.
unsigned getNumRegions()
Returns the number of regions held by this operation.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
MutableArrayRef< OpOperand > getOpOperands()
unsigned getNumOperands()
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
bool isAncestor(Operation *other)
Return true if this operation is an ancestor of the other operation.
user_range getUsers()
Returns a range of all users.
result_range getResults()
unsigned getNumResults()
Return the number of results held by this operation.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
bool hasOneBlock()
Return true if this region has exactly one block.
RetT walk(FnT &&callback)
Walk all nested operations, blocks or regions (including this region), depending on the type of callb...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
user_range getUsers() const
bool hasOneUse() const
Returns true if this value has exactly one use.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
static WalkResult advance()
static WalkResult interrupt()
Include the generated interface declarations.
LogicalResult getBackwardSlice(Operation *op, SetVector< Operation * > *backwardSlice, const BackwardSliceOptions &options={})
Fills backwardSlice with the computed backward slice (i.e.
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
bool isMemoryEffectFree(Operation *op)
Returns true if the given operation is free of memory effects.
Value matchReduction(ArrayRef< BlockArgument > iterCarriedArgs, unsigned redPos, SmallVectorImpl< Operation * > &combinerOps)
Utility to match a generic reduction given a list of iteration-carried arguments, iterCarriedArgs and...
llvm::SetVector< T, Vector, Set, N > SetVector
SliceOptions ForwardSliceOptions
SetVector< Operation * > getSlice(Operation *op, const BackwardSliceOptions &backwardSliceOptions={}, const ForwardSliceOptions &forwardSliceOptions={})
Iteratively computes backward slices and forward slices until a fixed point is reached.
SetVector< Operation * > topologicalSort(const SetVector< Operation * > &toSort)
Sorts all operations in toSort topologically while also considering region semantics.
void getForwardSlice(Operation *op, SetVector< Operation * > *forwardSlice, const ForwardSliceOptions &options={})
Fills forwardSlice with the computed forward slice (i.e.
std::function< bool(Operation *)> TransitiveFilter
Type of the condition to limit the propagation of transitive use-defs.