23 #include "mlir/Dialect/Affine/Passes.h.inc"
26 #include "llvm/Support/Debug.h"
31 #define GEN_PASS_DEF_AFFINEPARALLELIZE
32 #include "mlir/Dialect/Affine/Passes.h.inc"
36 #define DEBUG_TYPE "affine-parallel"
43 struct AffineParallelize
44 :
public affine::impl::AffineParallelizeBase<AffineParallelize> {
45 void runOnOperation()
override;
49 struct ParallelizationCandidate {
51 : loop(l), reductions(std::move(r)) {}
60 void AffineParallelize::runOnOperation() {
61 func::FuncOp f = getOperation();
65 std::vector<ParallelizationCandidate> parallelizableLoops;
68 if (
isLoopParallel(loop, parallelReductions ? &reductions :
nullptr))
69 parallelizableLoops.emplace_back(loop, std::move(reductions));
72 for (
const ParallelizationCandidate &candidate : parallelizableLoops) {
73 unsigned numParentParallelOps = 0;
74 AffineForOp loop = candidate.loop;
77 op = op->getParentOp()) {
78 if (isa<AffineParallelOp>(op))
79 ++numParentParallelOps;
82 if (numParentParallelOps < maxNested) {
84 LLVM_DEBUG(llvm::dbgs() <<
"[" DEBUG_TYPE "] failed to parallelize\n"
88 LLVM_DEBUG(llvm::dbgs() <<
"[" DEBUG_TYPE "] too many nested loops\n"
94 std::unique_ptr<OperationPass<func::FuncOp>>
96 return std::make_unique<AffineParallelize>();
A trait of region holding operations that defines a new scope for polyhedral optimization purposes.
Operation is the basic unit of execution within MLIR.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
LogicalResult affineParallelize(AffineForOp forOp, ArrayRef< LoopReduction > parallelReductions={}, AffineParallelOp *resOp=nullptr)
Replaces a parallel affine.for op with a 1-d affine.parallel op.
std::unique_ptr< OperationPass< func::FuncOp > > createAffineParallelizePass()
Creates a pass to convert all parallel affine.for's into 1-d affine.parallel ops.
bool isLoopParallel(AffineForOp forOp, SmallVectorImpl< LoopReduction > *parallelReductions=nullptr)
Returns true if ‘forOp’ is a parallel loop.
Include the generated interface declarations.