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 using AffineParallelizeBase<AffineParallelize>::AffineParallelizeBase;
47 void runOnOperation()
override;
51 struct ParallelizationCandidate {
53 : loop(l), reductions(std::move(r)) {}
62 void AffineParallelize::runOnOperation() {
63 func::FuncOp f = getOperation();
67 std::vector<ParallelizationCandidate> parallelizableLoops;
70 if (
isLoopParallel(loop, parallelReductions ? &reductions :
nullptr))
71 parallelizableLoops.emplace_back(loop, std::move(reductions));
74 for (
const ParallelizationCandidate &candidate : parallelizableLoops) {
75 unsigned numParentParallelOps = 0;
76 AffineForOp loop = candidate.loop;
79 op = op->getParentOp()) {
80 if (isa<AffineParallelOp>(op))
81 ++numParentParallelOps;
84 if (numParentParallelOps < maxNested) {
86 LLVM_DEBUG(llvm::dbgs() <<
"[" DEBUG_TYPE "] failed to parallelize\n"
90 LLVM_DEBUG(llvm::dbgs() <<
"[" DEBUG_TYPE "] too many nested loops\n"
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.
bool isLoopParallel(AffineForOp forOp, SmallVectorImpl< LoopReduction > *parallelReductions=nullptr)
Returns true if ‘forOp’ is a parallel loop.
Include the generated interface declarations.