1 //===- AffineParallelize.cpp - Affineparallelize Pass---------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements a parallelizer for affine loop nests that is able to 10 // perform inner or outer loop parallelization. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "PassDetail.h" 15 #include "mlir/Analysis/AffineStructures.h" 16 #include "mlir/Analysis/LoopAnalysis.h" 17 #include "mlir/Analysis/Utils.h" 18 #include "mlir/Dialect/Affine/IR/AffineOps.h" 19 #include "mlir/Dialect/Affine/IR/AffineValueMap.h" 20 #include "mlir/Dialect/Affine/Passes.h" 21 #include "mlir/Dialect/Affine/Passes.h.inc" 22 #include "mlir/Dialect/Affine/Utils.h" 23 #include "mlir/Transforms/LoopUtils.h" 24 #include "llvm/Support/Debug.h" 25 26 #define DEBUG_TYPE "affine-parallel" 27 28 using namespace mlir; 29 30 namespace { 31 /// Convert all parallel affine.for op into 1-D affine.parallel op. 32 struct AffineParallelize : public AffineParallelizeBase<AffineParallelize> { 33 void runOnFunction() override; 34 }; 35 } // namespace 36 37 void AffineParallelize::runOnFunction() { 38 FuncOp f = getFunction(); 39 SmallVector<AffineForOp, 8> parallelizableLoops; 40 f.walk([&](AffineForOp loop) { 41 if (isLoopParallel(loop)) 42 parallelizableLoops.push_back(loop); 43 }); 44 for (AffineForOp loop : parallelizableLoops) 45 affineParallelize(loop); 46 } 47 48 std::unique_ptr<OperationPass<FuncOp>> mlir::createAffineParallelizePass() { 49 return std::make_unique<AffineParallelize>(); 50 } 51