MLIR  19.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"
20 
21 //===----------------------------------------------------------------------===//
22 // Include the generated pass header (which needs some early definitions).
23 //===----------------------------------------------------------------------===//
24 
25 namespace mlir {
26 
27 namespace bufferization {
28 struct OneShotBufferizationOptions;
29 } // namespace bufferization
30 
31 /// Defines a parallelization strategy. Any independent loop is a candidate
32 /// for parallelization. The loop is made parallel if (1) allowed by the
33 /// strategy (e.g., AnyStorageOuterLoop considers either a dense or sparse
34 /// outermost loop only), and (2) the generated code is an actual for-loop
35 /// (and not a co-iterating while-loop).
37  kNone,
42 };
43 
44 /// Defines a scope for reinterpret map pass.
45 enum class ReinterpretMapScope {
46  kAll, // reinterprets all applicable operations
47  kGenericOnly, // reinterprets only linalg.generic
48  kExceptGeneric, // reinterprets operation other than linalg.generic
49 };
50 
51 /// Defines a scope for reinterpret map pass.
52 enum class SparseEmitStrategy {
53  kFunctional, // generate fully inlined (and functional) sparse iteration
54  kSparseIterator, // generate (experimental) loop using sparse iterator.
55  kDebugInterface, // generate only place-holder for sparse iteration
56 };
57 
58 #define GEN_PASS_DECL
59 #include "mlir/Dialect/SparseTensor/Transforms/Passes.h.inc"
60 
61 //===----------------------------------------------------------------------===//
62 // The SparseAssembler pass.
63 //===----------------------------------------------------------------------===//
64 
65 void populateSparseAssembler(RewritePatternSet &patterns, bool directOut);
66 
67 std::unique_ptr<Pass> createSparseAssembler();
68 std::unique_ptr<Pass> createSparseAssembler(bool directOut);
69 
70 //===----------------------------------------------------------------------===//
71 // The SparseReinterpretMap pass.
72 //===----------------------------------------------------------------------===//
73 
75  ReinterpretMapScope scope);
76 
77 std::unique_ptr<Pass> createSparseReinterpretMapPass();
78 std::unique_ptr<Pass> createSparseReinterpretMapPass(ReinterpretMapScope scope);
79 
80 //===----------------------------------------------------------------------===//
81 // The PreSparsificationRewriting pass.
82 //===----------------------------------------------------------------------===//
83 
85 
86 std::unique_ptr<Pass> createPreSparsificationRewritePass();
87 
88 //===----------------------------------------------------------------------===//
89 // The Sparsification pass.
90 //===----------------------------------------------------------------------===//
91 
92 /// Options for the Sparsification pass.
95  bool enableRT)
97  enableRuntimeLibrary(enableRT) {}
98 
101 
105 
109 };
110 
111 /// Sets up sparsification rewriting rules with the given options.
113  RewritePatternSet &patterns,
115 
116 std::unique_ptr<Pass> createSparsificationPass();
117 std::unique_ptr<Pass>
119 
120 //===----------------------------------------------------------------------===//
121 // The StageSparseOperations pass.
122 //===----------------------------------------------------------------------===//
123 
124 /// Sets up StageSparseOperation rewriting rules.
126 
127 std::unique_ptr<Pass> createStageSparseOperationsPass();
128 
129 //===----------------------------------------------------------------------===//
130 // The LowerSparseOpsToForeach pass.
131 //===----------------------------------------------------------------------===//
132 
134  bool enableRT, bool enableConvert);
135 
136 std::unique_ptr<Pass> createLowerSparseOpsToForeachPass();
137 std::unique_ptr<Pass> createLowerSparseOpsToForeachPass(bool enableRT,
138  bool enableConvert);
139 
140 //===----------------------------------------------------------------------===//
141 // The LowerForeachToSCF pass.
142 //===----------------------------------------------------------------------===//
143 
145 
146 std::unique_ptr<Pass> createLowerForeachToSCFPass();
147 
148 //===----------------------------------------------------------------------===//
149 // The LowerSparseIterationToSCF pass.
150 //===----------------------------------------------------------------------===//
151 
152 /// Type converter for iter_space and iterator.
155 };
156 
158  RewritePatternSet &patterns);
159 
160 std::unique_ptr<Pass> createLowerSparseIterationToSCFPass();
161 
162 //===----------------------------------------------------------------------===//
163 // The SparseTensorConversion pass.
164 //===----------------------------------------------------------------------===//
165 
166 /// Sparse tensor type converter into an opaque pointer.
168 public:
170 };
171 
172 /// Sets up sparse tensor conversion rules.
174  RewritePatternSet &patterns);
175 
176 std::unique_ptr<Pass> createSparseTensorConversionPass();
177 
178 //===----------------------------------------------------------------------===//
179 // The SparseTensorCodegen pass.
180 //===----------------------------------------------------------------------===//
181 
182 /// Sparse tensor type converter into an actual buffer.
184 public:
186 };
187 
188 /// Sets up sparse tensor codegen rules.
190  RewritePatternSet &patterns,
191  bool createSparseDeallocs,
192  bool enableBufferInitialization);
193 
194 std::unique_ptr<Pass> createSparseTensorCodegenPass();
195 std::unique_ptr<Pass>
196 createSparseTensorCodegenPass(bool createSparseDeallocs,
197  bool enableBufferInitialization);
198 
199 //===----------------------------------------------------------------------===//
200 // The SparseBufferRewrite pass.
201 //===----------------------------------------------------------------------===//
202 
204  bool enableBufferInitialization);
205 
206 std::unique_ptr<Pass> createSparseBufferRewritePass();
207 std::unique_ptr<Pass>
208 createSparseBufferRewritePass(bool enableBufferInitialization);
209 
210 //===----------------------------------------------------------------------===//
211 // The SparseVectorization pass.
212 //===----------------------------------------------------------------------===//
213 
215  unsigned vectorLength,
216  bool enableVLAVectorization,
217  bool enableSIMDIndex32);
218 
219 std::unique_ptr<Pass> createSparseVectorizationPass();
220 std::unique_ptr<Pass> createSparseVectorizationPass(unsigned vectorLength,
221  bool enableVLAVectorization,
222  bool enableSIMDIndex32);
223 
224 //===----------------------------------------------------------------------===//
225 // The SparseGPU pass.
226 //===----------------------------------------------------------------------===//
227 
229  unsigned numThreads);
230 
232  bool enableRT);
233 
234 std::unique_ptr<Pass> createSparseGPUCodegenPass();
235 std::unique_ptr<Pass> createSparseGPUCodegenPass(unsigned numThreads,
236  bool enableRT);
237 
238 //===----------------------------------------------------------------------===//
239 // The SparseStorageSpecifierToLLVM pass.
240 //===----------------------------------------------------------------------===//
241 
243 public:
245 };
246 
248  RewritePatternSet &patterns);
249 std::unique_ptr<Pass> createStorageSpecifierToLLVMPass();
250 
251 //===----------------------------------------------------------------------===//
252 // The mini-pipeline for sparsification and bufferization.
253 //===----------------------------------------------------------------------===//
254 
257 
258 std::unique_ptr<Pass> createSparsificationAndBufferizationPass();
259 
260 std::unique_ptr<Pass> createSparsificationAndBufferizationPass(
261  const bufferization::OneShotBufferizationOptions &bufferizationOptions,
262  const SparsificationOptions &sparsificationOptions,
263  bool createSparseDeallocs, bool enableRuntimeLibrary,
264  bool enableBufferInitialization, unsigned vectorLength,
265  bool enableVLAVectorization, bool enableSIMDIndex32, bool enableGPULibgen,
266  SparseEmitStrategy emitStrategy);
267 
268 //===----------------------------------------------------------------------===//
269 // Sparse Iteration Transform Passes
270 //===----------------------------------------------------------------------===//
271 
272 std::unique_ptr<Pass> createSparseSpaceCollapsePass();
273 
274 //===----------------------------------------------------------------------===//
275 // Registration.
276 //===----------------------------------------------------------------------===//
277 
278 /// Generate the code for registering passes.
279 #define GEN_PASS_REGISTRATION
280 #include "mlir/Dialect/SparseTensor/Transforms/Passes.h.inc"
281 
282 } // namespace mlir
283 
284 #endif // MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_PASSES_H_
static llvm::ManagedStatic< PassManagerOptions > options
Extends TypeConverter with 1:N target materializations.
Sparse tensor type converter into an actual buffer.
Definition: Passes.h:183
Sparse tensor type converter into an opaque pointer.
Definition: Passes.h:167
Type conversion class.
Include the generated interface declarations.
std::unique_ptr< Pass > createSparseVectorizationPass()
std::unique_ptr< Pass > createSparseAssembler()
std::unique_ptr< Pass > createLowerSparseOpsToForeachPass()
std::unique_ptr< Pass > createSparseTensorCodegenPass()
std::unique_ptr< Pass > createSparseGPUCodegenPass()
std::unique_ptr< Pass > createSparseSpaceCollapsePass()
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.
void populateLowerSparseIterationToSCFPatterns(TypeConverter &converter, RewritePatternSet &patterns)
SparseParallelizationStrategy
Defines a parallelization strategy.
Definition: Passes.h:36
void populateStorageSpecifierToLLVMPatterns(TypeConverter &converter, RewritePatternSet &patterns)
ReinterpretMapScope
Defines a scope for reinterpret map pass.
Definition: Passes.h:45
void populateSparsificationPatterns(RewritePatternSet &patterns, const SparsificationOptions &options=SparsificationOptions())
Sets up sparsification rewriting rules with the given options.
SparseEmitStrategy
Defines a scope for reinterpret map pass.
Definition: Passes.h:52
void populateLowerSparseOpsToForeachPatterns(RewritePatternSet &patterns, bool enableRT, bool enableConvert)
std::unique_ptr< Pass > createStorageSpecifierToLLVMPass()
std::unique_ptr< Pass > createPreSparsificationRewritePass()
std::unique_ptr< Pass > createLowerForeachToSCFPass()
void populateSparseAssembler(RewritePatternSet &patterns, bool directOut)
void populateStageSparseOperationsPatterns(RewritePatternSet &patterns)
Sets up StageSparseOperation rewriting rules.
std::unique_ptr< Pass > createLowerSparseIterationToSCFPass()
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)
Type converter for iter_space and iterator.
Definition: Passes.h:153
Options for the Sparsification pass.
Definition: Passes.h:93
SparseEmitStrategy sparseEmitStrategy
Definition: Passes.h:107
SparseParallelizationStrategy parallelizationStrategy
Definition: Passes.h:106
SparsificationOptions(SparseParallelizationStrategy p, SparseEmitStrategy d, bool enableRT)
Definition: Passes.h:94
SparsificationOptions(SparseParallelizationStrategy p, bool enableRT)
Definition: Passes.h:99
Options for analysis-enabled bufferization.