19 #include "llvm/ADT/SetVector.h"
20 #include "llvm/ADT/SmallPtrSet.h"
37 if (filter && !filter(op))
41 for (
Block &block : region)
43 if (forwardSlice->count(&blockOp) == 0)
47 if (forwardSlice->count(userOp) == 0)
51 forwardSlice->insert(op);
60 forwardSlice->remove(op);
67 forwardSlice->insert(v.rbegin(), v.rend());
79 forwardSlice->insert(v.rbegin(), v.rend());
95 auto operand = en.value();
96 if (
auto *definingOp = operand.getDefiningOp()) {
97 if (backwardSlice->count(definingOp) == 0)
99 }
else if (
auto blockArg = dyn_cast<BlockArgument>(operand)) {
100 if (
options.omitBlockArguments)
103 Block *block = blockArg.getOwner();
108 if (parentOp && backwardSlice->count(parentOp) == 0) {
114 llvm_unreachable(
"No definingOp and not a block argument.");
118 backwardSlice->insert(op);
129 backwardSlice->remove(op);
149 unsigned currentIndex = 0;
152 while (currentIndex != slice.size()) {
153 auto *currentOp = (slice)[currentIndex];
155 backwardSlice.clear();
157 slice.insert(backwardSlice.begin(), backwardSlice.end());
160 forwardSlice.clear();
162 slice.insert(forwardSlice.begin(), forwardSlice.end());
184 iterCarriedArgs.end());
185 if (iterCarriedValSet.contains(value))
190 if (iterCarriedValSet.contains(operand))
227 assert(redPos < iterCarriedArgs.size() &&
"'redPos' is out of bounds");
242 iterCarriedArgs.front().getOwner()->getParent()->getParentOp();
254 combinerOps.push_back(combinerOp);
255 combinerOp = *combinerOp->
getUsers().begin();
260 if (combinerOps.size() != 1)
266 if (terminatorOp->
getOperand(redPos) != combinerOps.back()->getResults()[0])
static llvm::ManagedStatic< PassManagerOptions > options
static void getForwardSliceImpl(Operation *op, SetVector< Operation * > *forwardSlice, const SliceOptions::TransitiveFilter &filter=nullptr)
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 getBackwardSliceImpl(Operation *op, SetVector< Operation * > *backwardSlice, const BackwardSliceOptions &options)
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 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.
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.
unsigned getNumOperands()
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
operand_range getOperands()
Returns an iterator on the underlying Value's.
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.
BlockListType & getBlocks()
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.
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Include the generated interface declarations.
void getBackwardSlice(Operation *op, SetVector< Operation * > *backwardSlice, const BackwardSliceOptions &options={})
Fills backwardSlice with the computed backward slice (i.e.
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...
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.