43#include "llvm/Support/Debug.h"
48#define GEN_PASS_DEF_ACCLOOPCOLLAPSE
49#include "mlir/Dialect/OpenACC/Transforms/Passes.h.inc"
53#define DEBUG_TYPE "acc-loop-collapse"
60void collapseParallelOp(
IRRewriter &rewriter, scf::ParallelOp parallelOp) {
61 unsigned collapseDepth = parallelOp.getNumLoops();
63 LLVM_DEBUG(llvm::dbgs() <<
"Collapsing loop with " << collapseDepth
67 std::vector<unsigned> combinedDims;
68 combinedDims.reserve(collapseDepth);
69 for (
unsigned i = 0; i < collapseDepth; ++i)
70 combinedDims.push_back(i);
75 parallelOp->getDiscardableAttrs().end());
77 scf::ParallelOp collapsedOp =
81 collapsedOp->setDiscardableAttr(attr.getName(), attr.getValue());
89 using ACCLoopCollapseBase<ACCLoopCollapse>::ACCLoopCollapseBase;
91 void runOnOperation()
override {
92 LLVM_DEBUG(llvm::dbgs() <<
"Enter ACCLoopCollapse()\n");
99 getOperation().walk([&](acc::ComputeRegionOp computeRegion) {
100 computeRegion.walk([&](scf::ParallelOp op) {
101 if (op.getNumLoops() > 1)
102 collapseParallelOp(rewriter, op);
106 LLVM_DEBUG(llvm::dbgs() <<
"Exit ACCLoopCollapse()\n");
This class coordinates rewriting a piece of IR outside of a pattern rewrite, providing a way to keep ...
NamedAttribute represents a combination of a name and an Attribute value.
void setCollapseCountAttr(Operation *op, uint64_t count)
Record on a collapsed loop how many original loops were folded into it.
Include the generated interface declarations.
scf::ParallelOp collapseParallelLoops(RewriterBase &rewriter, scf::ParallelOp loops, ArrayRef< std::vector< unsigned > > combinedDimensions)
Take the ParallelLoop and for each set of dimension indices, combine them into a single dimension.