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