17 #include "llvm/Support/Debug.h"
20 #define GEN_PASS_DEF_SCFPARALLELFORTONESTEDFORS
21 #include "mlir/Dialect/SCF/Transforms/Passes.h.inc"
24 #define DEBUG_TYPE "parallel-for-to-nested-fors"
27 FailureOr<scf::LoopNest>
29 scf::ParallelOp parallelOp) {
31 if (!parallelOp.getResults().empty())
33 parallelOp,
"Currently scf.parallel to scf.for conversion doesn't "
34 "support scf.parallel with results.");
43 assert(lowerBounds.size() == upperBounds.size() &&
44 lowerBounds.size() == steps.size() &&
45 "Mismatched parallel loop bounds");
52 loopNest.
loops, [](scf::ForOp forOp) { return forOp.getInductionVar(); });
53 Block *linearizedBody = loopNest.
loops.back().getBody();
54 Block *parallelBody = parallelOp.getBody();
63 struct ParallelForToNestedFors final
64 :
public impl::SCFParallelForToNestedForsBase<ParallelForToNestedFors> {
65 void runOnOperation()
override {
70 [&](scf::ParallelOp parallelOp) {
74 <<
"Failed to convert scf.parallel to nested scf.for ops for:\n"
75 << parallelOp <<
"\n");
85 return std::make_unique<ParallelForToNestedFors>();
Block represents an ordered list of Operations.
Operation * getTerminator()
Get the terminator operation of this block.
This class coordinates rewriting a piece of IR outside of a pattern rewrite, providing a way to keep ...
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Operation is the basic unit of execution within MLIR.
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),...
MLIRContext * getContext()
Return the context this operation is associated with.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
virtual void eraseOp(Operation *op)
This method erases an operation that is known to have no uses.
virtual void inlineBlockBefore(Block *source, Block *dest, Block::iterator before, ValueRange argValues={})
Inline the operations of block 'source' into block 'dest' before the given position.
static WalkResult advance()
FailureOr< scf::LoopNest > parallelForToNestedFors(RewriterBase &rewriter, ParallelOp parallelOp)
Try converting scf.forall into an scf.parallel loop.
LoopNest buildLoopNest(OpBuilder &builder, Location loc, ValueRange lbs, ValueRange ubs, ValueRange steps, ValueRange iterArgs, function_ref< ValueVector(OpBuilder &, Location, ValueRange, ValueRange)> bodyBuilder=nullptr)
Creates a perfect nest of "for" loops, i.e.
Include the generated interface declarations.
std::unique_ptr< Pass > createParallelForToNestedForsPass()
Creates a pass that converts SCF forall loops to SCF parallel loops.