19 const auto isReady = [&](
Value value) {
21 if (isOperandReady && isOperandReady(value, op))
23 Operation *parent = value.getDefiningOp();
33 if (unscheduledOps.contains(parent))
44 [&](
Value operand) { return isReady(operand); })
61 unscheduledOps.insert(&op);
66 bool allOpsScheduled =
true;
67 while (!unscheduledOps.empty()) {
68 bool scheduledAtLeastOnce =
false;
74 llvm::make_early_inc_range(llvm::make_range(nextScheduledOp, end))) {
75 if (!
isOpReady(&op, unscheduledOps, isOperandReady))
79 unscheduledOps.erase(&op);
81 scheduledAtLeastOnce =
true;
83 if (&op == &*nextScheduledOp)
87 if (!scheduledAtLeastOnce) {
88 allOpsScheduled =
false;
89 unscheduledOps.erase(&*nextScheduledOp);
94 return allOpsScheduled;
118 unscheduledOps.insert(op);
120 unsigned nextScheduledOp = 0;
122 bool allOpsScheduled =
true;
123 while (!unscheduledOps.empty()) {
124 bool scheduledAtLeastOnce =
false;
129 for (
unsigned i = nextScheduledOp; i < ops.size(); ++i) {
130 if (!
isOpReady(ops[i], unscheduledOps, isOperandReady))
134 unscheduledOps.erase(ops[i]);
135 std::swap(ops[i], ops[nextScheduledOp]);
136 scheduledAtLeastOnce =
true;
141 if (!scheduledAtLeastOnce) {
142 allOpsScheduled =
false;
143 unscheduledOps.erase(ops[nextScheduledOp++]);
147 return allOpsScheduled;
static bool isOpReady(Operation *op, DenseSet< Operation * > &unscheduledOps, function_ref< bool(Value, Operation *)> isOperandReady)
Return true if the given operation is ready to be scheduled.
Block represents an ordered list of Operations.
OpListType::iterator iterator
iterator_range< iterator > without_terminator()
Return an iterator range over the operation within this block excluding the terminator operation at t...
This class provides the API for ops that are known to be terminators.
Operation is the basic unit of execution within MLIR.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
operand_range getOperands()
Returns an iterator on the underlying Value's.
void moveBefore(Operation *existingOp)
Unlink this operation from its current block and insert it right before existingOp which may be in th...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
bool wasInterrupted() const
Returns true if the walk was interrupted.
static WalkResult interrupt()
Include the generated interface declarations.
bool computeTopologicalSorting(MutableArrayRef< Operation * > ops, function_ref< bool(Value, Operation *)> isOperandReady=nullptr)
Compute a topological ordering of the given ops.
bool sortTopologically(Block *block, iterator_range< Block::iterator > ops, function_ref< bool(Value, Operation *)> isOperandReady=nullptr)
Given a block, sort a range operations in said block in topological order.