MLIR  18.0.0git
Passes.h
Go to the documentation of this file.
1 //===- Passes.h - Sparse tensor pass entry points ---------------*- C++ -*-===//
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 header file defines prototypes of all sparse tensor passes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_PASSES_H_
14 #define MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_PASSES_H_
15 
16 #include "mlir/IR/PatternMatch.h"
17 #include "mlir/Pass/Pass.h"
19 
20 //===----------------------------------------------------------------------===//
21 // Include the generated pass header (which needs some early definitions).
22 //===----------------------------------------------------------------------===//
23 
24 namespace mlir {
25 
26 namespace bufferization {
27 struct OneShotBufferizationOptions;
28 } // namespace bufferization
29 
30 /// Defines a parallelization strategy. Any independent loop is a candidate
31 /// for parallelization. The loop is made parallel if (1) allowed by the
32 /// strategy (e.g., AnyStorageOuterLoop considers either a dense or sparse
33 /// outermost loop only), and (2) the generated code is an actual for-loop
34 /// (and not a co-iterating while-loop).
36  kNone,
41 };
42 
43 /// Defines a scope for reinterpret map pass.
44 enum class ReinterpretMapScope {
45  kAll, // reinterprets all applicable operations
46  kGenericOnly, // reinterprets only linalg.generic
47  kExceptGeneric, // reinterprets operation other than linalg.generic
48 };
49 
50 #define GEN_PASS_DECL
51 #include "mlir/Dialect/SparseTensor/Transforms/Passes.h.inc"
52 
53 //===----------------------------------------------------------------------===//
54 // The SparseReinterpretMap pass.
55 //===----------------------------------------------------------------------===//
56 
57 void populateSparseReinterpretMap(RewritePatternSet &patterns,
58  ReinterpretMapScope scope);
59 
60 std::unique_ptr<Pass> createSparseReinterpretMapPass();
61 std::unique_ptr<Pass> createSparseReinterpretMapPass(ReinterpretMapScope scope);
62 
63 //===----------------------------------------------------------------------===//
64 // The PreSparsificationRewriting pass.
65 //===----------------------------------------------------------------------===//
66 
67 void populatePreSparsificationRewriting(RewritePatternSet &patterns);
68 
69 std::unique_ptr<Pass> createPreSparsificationRewritePass();
70 
71 //===----------------------------------------------------------------------===//
72 // The Sparsification pass.
73 //===----------------------------------------------------------------------===//
74 
75 /// Options for the Sparsification pass.
83 };
84 
85 /// Sets up sparsification rewriting rules with the given options.
87  RewritePatternSet &patterns,
89 
90 std::unique_ptr<Pass> createSparsificationPass();
91 std::unique_ptr<Pass>
93 
94 //===----------------------------------------------------------------------===//
95 // The StageSparseOperations pass.
96 //===----------------------------------------------------------------------===//
97 
98 /// Sets up StageSparseOperation rewriting rules.
100 
101 std::unique_ptr<Pass> createStageSparseOperationsPass();
102 
103 //===----------------------------------------------------------------------===//
104 // The LowerSparseOpsToForeach pass.
105 //===----------------------------------------------------------------------===//
106 
108  bool enableRT, bool enableConvert);
109 
110 std::unique_ptr<Pass> createLowerSparseOpsToForeachPass();
111 std::unique_ptr<Pass> createLowerSparseOpsToForeachPass(bool enableRT,
112  bool enableConvert);
113 
114 //===----------------------------------------------------------------------===//
115 // The LowerForeachToSCF pass.
116 //===----------------------------------------------------------------------===//
117 
119 
120 std::unique_ptr<Pass> createLowerForeachToSCFPass();
121 
122 //===----------------------------------------------------------------------===//
123 // The SparseTensorConversion pass.
124 //===----------------------------------------------------------------------===//
125 
126 /// Sparse tensor type converter into an opaque pointer.
128 public:
130 };
131 
132 /// Sets up sparse tensor conversion rules.
134  RewritePatternSet &patterns);
135 
136 std::unique_ptr<Pass> createSparseTensorConversionPass();
137 
138 //===----------------------------------------------------------------------===//
139 // The SparseTensorCodegen pass.
140 //===----------------------------------------------------------------------===//
141 
142 /// Sparse tensor type converter into an actual buffer.
144 public:
146 };
147 
148 /// Sets up sparse tensor codegen rules.
150  RewritePatternSet &patterns,
151  bool createSparseDeallocs,
152  bool enableBufferInitialization);
153 
154 std::unique_ptr<Pass> createSparseTensorCodegenPass();
155 std::unique_ptr<Pass>
156 createSparseTensorCodegenPass(bool createSparseDeallocs,
157  bool enableBufferInitialization);
158 
159 //===----------------------------------------------------------------------===//
160 // The SparseBufferRewrite pass.
161 //===----------------------------------------------------------------------===//
162 
164  bool enableBufferInitialization);
165 
166 std::unique_ptr<Pass> createSparseBufferRewritePass();
167 std::unique_ptr<Pass>
168 createSparseBufferRewritePass(bool enableBufferInitialization);
169 
170 //===----------------------------------------------------------------------===//
171 // The SparseVectorization pass.
172 //===----------------------------------------------------------------------===//
173 
175  unsigned vectorLength,
176  bool enableVLAVectorization,
177  bool enableSIMDIndex32);
178 
179 std::unique_ptr<Pass> createSparseVectorizationPass();
180 std::unique_ptr<Pass> createSparseVectorizationPass(unsigned vectorLength,
181  bool enableVLAVectorization,
182  bool enableSIMDIndex32);
183 
184 //===----------------------------------------------------------------------===//
185 // The SparseGPU pass.
186 //===----------------------------------------------------------------------===//
187 
189  unsigned numThreads);
190 
192  bool enableRT);
193 
194 std::unique_ptr<Pass> createSparseGPUCodegenPass();
195 std::unique_ptr<Pass> createSparseGPUCodegenPass(unsigned numThreads,
196  bool enableRT);
197 
198 //===----------------------------------------------------------------------===//
199 // The SparseStorageSpecifierToLLVM pass.
200 //===----------------------------------------------------------------------===//
201 
203 public:
205 };
206 
208  RewritePatternSet &patterns);
209 std::unique_ptr<Pass> createStorageSpecifierToLLVMPass();
210 
211 //===----------------------------------------------------------------------===//
212 // The mini-pipeline for sparsification and bufferization.
213 //===----------------------------------------------------------------------===//
214 
217 
218 std::unique_ptr<Pass> createSparsificationAndBufferizationPass();
219 
220 std::unique_ptr<Pass> createSparsificationAndBufferizationPass(
221  const bufferization::OneShotBufferizationOptions &bufferizationOptions,
222  const SparsificationOptions &sparsificationOptions,
223  bool createSparseDeallocs, bool enableRuntimeLibrary,
224  bool enableBufferInitialization, unsigned vectorLength,
225  bool enableVLAVectorization, bool enableSIMDIndex32, bool enableGPULibgen);
226 
227 //===----------------------------------------------------------------------===//
228 // Registration.
229 //===----------------------------------------------------------------------===//
230 
231 /// Generate the code for registering passes.
232 #define GEN_PASS_REGISTRATION
233 #include "mlir/Dialect/SparseTensor/Transforms/Passes.h.inc"
234 
235 } // namespace mlir
236 
237 #endif // MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_PASSES_H_
static llvm::ManagedStatic< PassManagerOptions > options
Sparse tensor type converter into an actual buffer.
Definition: Passes.h:143
Sparse tensor type converter into an opaque pointer.
Definition: Passes.h:127
Type conversion class.
Include the generated interface declarations.
std::unique_ptr< Pass > createSparseVectorizationPass()
std::unique_ptr< Pass > createLowerSparseOpsToForeachPass()
std::unique_ptr< Pass > createSparseTensorCodegenPass()
std::unique_ptr< Pass > createSparseGPUCodegenPass()
bufferization::OneShotBufferizationOptions getBufferizationOptionsForSparsification(bool analysisOnly)
std::unique_ptr< Pass > createSparseReinterpretMapPass()
void populateSparseReinterpretMap(RewritePatternSet &patterns, ReinterpretMapScope scope)
void populateSparseGPULibgenPatterns(RewritePatternSet &patterns, bool enableRT)
std::unique_ptr< Pass > createSparseTensorConversionPass()
std::unique_ptr< Pass > createSparseBufferRewritePass()
std::unique_ptr< Pass > createSparsificationAndBufferizationPass()
void populateSparseBufferRewriting(RewritePatternSet &patterns, bool enableBufferInitialization)
void populatePreSparsificationRewriting(RewritePatternSet &patterns)
void populateSparseVectorizationPatterns(RewritePatternSet &patterns, unsigned vectorLength, bool enableVLAVectorization, bool enableSIMDIndex32)
Populates the given patterns list with vectorization rules.
SparseParallelizationStrategy
Defines a parallelization strategy.
Definition: Passes.h:35
void populateStorageSpecifierToLLVMPatterns(TypeConverter &converter, RewritePatternSet &patterns)
ReinterpretMapScope
Defines a scope for reinterpret map pass.
Definition: Passes.h:44
void populateSparsificationPatterns(RewritePatternSet &patterns, const SparsificationOptions &options=SparsificationOptions())
Sets up sparsification rewriting rules with the given options.
void populateLowerSparseOpsToForeachPatterns(RewritePatternSet &patterns, bool enableRT, bool enableConvert)
std::unique_ptr< Pass > createStorageSpecifierToLLVMPass()
std::unique_ptr< Pass > createPreSparsificationRewritePass()
std::unique_ptr< Pass > createLowerForeachToSCFPass()
void populateStageSparseOperationsPatterns(RewritePatternSet &patterns)
Sets up StageSparseOperation rewriting rules.
void populateSparseTensorConversionPatterns(TypeConverter &typeConverter, RewritePatternSet &patterns)
Sets up sparse tensor conversion rules.
void populateSparseGPUCodegenPatterns(RewritePatternSet &patterns, unsigned numThreads)
std::unique_ptr< Pass > createStageSparseOperationsPass()
void populateSparseTensorCodegenPatterns(TypeConverter &typeConverter, RewritePatternSet &patterns, bool createSparseDeallocs, bool enableBufferInitialization)
Sets up sparse tensor codegen rules.
std::unique_ptr< Pass > createSparsificationPass()
void populateLowerForeachToSCFPatterns(RewritePatternSet &patterns)
Options for the Sparsification pass.
Definition: Passes.h:76
SparseParallelizationStrategy parallelizationStrategy
Definition: Passes.h:81
SparsificationOptions(SparseParallelizationStrategy p, bool enableRT)
Definition: Passes.h:77
Options for analysis-enabled bufferization.