MLIR  16.0.0git
SparseTensorPipelines.cpp
Go to the documentation of this file.
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 
10 
11 #include "mlir/Conversion/Passes.h"
20 #include "mlir/Pass/PassManager.h"
21 
22 using namespace mlir;
23 using namespace mlir::sparse_tensor;
24 
25 /// Return configuration options for One-Shot Bufferize.
27 getBufferizationOptions(bool analysisOnly) {
28  using namespace bufferization;
29  OneShotBufferizationOptions options;
30  options.bufferizeFunctionBoundaries = true;
31  // TODO(springerm): To spot memory leaks more easily, returning dense allocs
32  // should be disallowed.
33  options.allowReturnAllocs = true;
34  options.functionBoundaryTypeConversion =
35  BufferizationOptions::LayoutMapOption::IdentityLayoutMap;
36  options.unknownTypeConverterFn = [](Value value, unsigned memorySpace,
37  const BufferizationOptions &options) {
39  value.getType().cast<TensorType>(), memorySpace);
40  };
41  if (analysisOnly) {
42  options.testAnalysisOnly = true;
43  options.printConflicts = true;
44  }
45  return options;
46 }
47 
48 //===----------------------------------------------------------------------===//
49 // Pipeline implementation.
50 //===----------------------------------------------------------------------===//
51 
54  // TODO(wrengr): ensure the original `pm` is for ModuleOp
56  pm.addPass(
58  /*analysisOnly=*/options.testBufferizationAnalysisOnly)));
60  return;
65  getBufferizationOptions(/*analysisOnly=*/false)));
66  pm.addNestedPass<func::FuncOp>(
68  // TODO(springerm): Add sparse support to the BufferDeallocation pass and add
69  // it to this pipeline.
71  pm.addNestedPass<func::FuncOp>(createConvertVectorToSCFPass());
72  pm.addNestedPass<func::FuncOp>(createConvertSCFToCFPass());
77  pm.addNestedPass<mlir::func::FuncOp>(
79  pm.addNestedPass<func::FuncOp>(createConvertMathToLLVMPass());
85 }
86 
87 //===----------------------------------------------------------------------===//
88 // Pipeline registration.
89 //===----------------------------------------------------------------------===//
90 
93  "sparse-compiler",
94  "The standard pipeline for taking sparsity-agnostic IR using the"
95  " sparse-tensor type, and lowering it to LLVM IR with concrete"
96  " representations and algorithms for sparse tensors.",
98 }
Include the generated interface declarations.
std::unique_ptr< Pass > createMemRefToLLVMPass()
std::unique_ptr< Pass > createConvertSCFToCFPass()
Creates a pass to convert SCF operations to CFG branch-based operation in the ControlFlow dialect...
static bufferization::OneShotBufferizationOptions getBufferizationOptions(bool analysisOnly)
Return configuration options for One-Shot Bufferize.
std::unique_ptr< Pass > createConvertMathToLLVMPass()
Definition: MathToLLVM.cpp:296
std::unique_ptr< Pass > createTensorCopyInsertionPass()
Create a pass that resolves out-of-place tensor OpOperands with copies.
std::unique_ptr< OperationPass< func::FuncOp > > createConvertLinalgToLoopsPass()
Create a pass to convert Linalg operations to scf.for loops and memref.load/memref.store accesses.
Definition: Loops.cpp:342
std::unique_ptr< OperationPass< ModuleOp > > createConvertVectorToLLVMPass(const LowerVectorToLLVMOptions &options=LowerVectorToLLVMOptions())
Create a pass to convert vector operations to the LLVMIR dialect.
static constexpr const bool value
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
Definition: PassManager.h:120
PassOptions::Option< bool > testBufferizationAnalysisOnly
Definition: Passes.h:47
BaseMemRefType getMemRefTypeWithStaticIdentityLayout(TensorType tensorType, unsigned memorySpace=0)
Return a MemRef type with a static identity layout (i.e., no layout map).
std::unique_ptr< OperationPass< ModuleOp > > createConvertMathToLibmPass()
Create a pass to convert Math operations to libm calls.
Definition: MathToLibm.cpp:194
void buildSparseCompiler(OpPassManager &pm, const SparseCompilerOptions &options)
Adds the "sparse-compiler" pipeline to the OpPassManager.
std::unique_ptr< Pass > createDenseBufferizationPass(const bufferization::OneShotBufferizationOptions &options)
std::unique_ptr< Pass > createConvertComplexToStandardPass()
Create a pass to convert Complex operations to the Standard dialect.
SparseTensorConversionOptions sparseTensorConversionOptions() const
Projects out the options for createSparsificationPass.
Definition: Passes.h:65
std::unique_ptr< OperationPass< func::FuncOp > > createLinalgGeneralizationPass()
Create a pass to convert named Linalg operations to Linalg generic operations.
std::unique_ptr< Pass > createLowerAffinePass()
Lowers affine control flow operations (ForStmt, IfStmt and AffineApplyOp) to equivalent lower-level c...
std::unique_ptr< Pass > createConvertVectorToSCFPass(const VectorTransferToSCFOptions &options=VectorTransferToSCFOptions())
Create a pass to convert a subset of vector ops to SCF.
std::unique_ptr< Pass > createReconcileUnrealizedCastsPass()
Creates a pass that eliminates noop unrealized_conversion_cast operation sequences.
void registerSparseTensorPipelines()
Registers all pipelines for the sparse_tensor dialect.
std::unique_ptr< Pass > createSparseTensorConversionPass()
Tensor types represent multi-dimensional arrays, and have two variants: RankedTensorType and Unranked...
Definition: BuiltinTypes.h:76
std::unique_ptr< OperationPass< ModuleOp > > createConvertComplexToLibmPass()
Create a pass to convert Complex operations to libm calls.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:85
std::unique_ptr< Pass > createConvertComplexToLLVMPass()
Create a pass to convert Complex operations to the LLVMIR dialect.
std::unique_ptr< OperationPass< ModuleOp > > createConvertFuncToLLVMPass()
Creates a pass to convert the Func dialect into the LLVMIR dialect.
Definition: FuncToLLVM.cpp:729
static llvm::ManagedStatic< PassManagerOptions > options
std::unique_ptr< Pass > createArithmeticExpandOpsPass()
Create a pass to legalize Arithmetic ops for LLVM lowering.
Definition: ExpandOps.cpp:238
Options for the "sparse-compiler" pipeline.
Definition: Passes.h:30
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...
Definition: PassRegistry.h:166
Type getType() const
Return the type of this value.
Definition: Value.h:118
std::unique_ptr< OperationPass< func::FuncOp > > createFinalizingBufferizePass()
Creates a pass that finalizes a partial bufferization by removing remaining bufferization.to_tensor and bufferization.to_memref operations.
Definition: Bufferize.cpp:288
SparsificationOptions sparsificationOptions() const
Projects out the options for createSparsificationPass.
Definition: Passes.h:52
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Definition: Pass.cpp:333
LowerVectorToLLVMOptions lowerVectorToLLVMOptions() const
Projects out the options for createConvertVectorToLLVMPass.
Definition: Passes.h:100
std::unique_ptr< Pass > createSparsificationPass()
Options for analysis-enabled bufferization.
This class represents a pass manager that runs passes on either a specific operation type...
Definition: PassManager.h:52
U cast() const
Definition: Types.h:278