1 //===- SparseTensorPipelines.cpp - Pipelines for sparse tensor code -------===// 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 #include "mlir/Dialect/SparseTensor/Pipelines/Passes.h" 10 11 #include "mlir/Conversion/Passes.h" 12 #include "mlir/Dialect/Arithmetic/Transforms/Passes.h" 13 #include "mlir/Dialect/Bufferization/Transforms/Passes.h" 14 #include "mlir/Dialect/Func/Transforms/Passes.h" 15 #include "mlir/Dialect/Linalg/Passes.h" 16 #include "mlir/Dialect/SparseTensor/IR/SparseTensor.h" 17 #include "mlir/Dialect/SparseTensor/Transforms/Passes.h" 18 #include "mlir/Dialect/Tensor/Transforms/Passes.h" 19 #include "mlir/Dialect/Vector/Transforms/Passes.h" 20 #include "mlir/Pass/PassManager.h" 21 22 using namespace mlir; 23 using namespace mlir::sparse_tensor; 24 25 //===----------------------------------------------------------------------===// 26 // Pipeline implementation. 27 //===----------------------------------------------------------------------===// 28 29 void mlir::sparse_tensor::buildSparseCompiler( 30 OpPassManager &pm, const SparseCompilerOptions &options) { 31 // TODO(wrengr): ensure the original `pm` is for ModuleOp 32 pm.addNestedPass<FuncOp>(createLinalgGeneralizationPass()); 33 pm.addPass(createLinalgElementwiseOpFusionPass()); 34 pm.addPass(createSparsificationPass(options.sparsificationOptions())); 35 pm.addPass(createSparseTensorConversionPass()); 36 pm.addNestedPass<FuncOp>(createLinalgBufferizePass()); 37 pm.addNestedPass<FuncOp>(vector::createVectorBufferizePass()); 38 pm.addNestedPass<FuncOp>(createConvertLinalgToLoopsPass()); 39 pm.addNestedPass<FuncOp>(createConvertVectorToSCFPass()); 40 pm.addNestedPass<FuncOp>(createConvertSCFToCFPass()); 41 pm.addPass(func::createFuncBufferizePass()); 42 pm.addPass(arith::createConstantBufferizePass()); 43 pm.addNestedPass<FuncOp>(createTensorBufferizePass()); 44 pm.addNestedPass<FuncOp>( 45 mlir::bufferization::createFinalizingBufferizePass()); 46 pm.addPass(createLowerAffinePass()); 47 pm.addPass(createConvertVectorToLLVMPass(options.lowerVectorToLLVMOptions())); 48 pm.addPass(createMemRefToLLVMPass()); 49 pm.addNestedPass<FuncOp>(createConvertMathToLLVMPass()); 50 pm.addPass(createConvertFuncToLLVMPass()); 51 pm.addPass(createReconcileUnrealizedCastsPass()); 52 } 53 54 //===----------------------------------------------------------------------===// 55 // Pipeline registration. 56 //===----------------------------------------------------------------------===// 57 58 void mlir::sparse_tensor::registerSparseTensorPipelines() { 59 PassPipelineRegistration<SparseCompilerOptions>( 60 "sparse-compiler", 61 "The standard pipeline for taking sparsity-agnostic IR using the" 62 " sparse-tensor type, and lowering it to LLVM IR with concrete" 63 " representations and algorithms for sparse tensors.", 64 buildSparseCompiler); 65 } 66