1 | //===- mlir-opt.cpp - MLIR Optimizer Driver -------------------------------===// |
---|---|
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 | // Main entry function for mlir-opt for when built as standalone binary. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "mlir/Config/mlir-config.h" |
14 | #include "mlir/IR/AsmState.h" |
15 | #include "mlir/IR/Dialect.h" |
16 | #include "mlir/IR/MLIRContext.h" |
17 | #include "mlir/InitAllDialects.h" |
18 | #include "mlir/InitAllExtensions.h" |
19 | #include "mlir/InitAllPasses.h" |
20 | #include "mlir/Pass/Pass.h" |
21 | #include "mlir/Pass/PassManager.h" |
22 | #include "mlir/Support/FileUtilities.h" |
23 | #include "mlir/Target/LLVMIR/Dialect/All.h" |
24 | #include "mlir/Tools/mlir-opt/MlirOptMain.h" |
25 | #include "llvm/Support/CommandLine.h" |
26 | #include "llvm/Support/InitLLVM.h" |
27 | #include "llvm/Support/SourceMgr.h" |
28 | #include "llvm/Support/ToolOutputFile.h" |
29 | |
30 | using namespace llvm; |
31 | using namespace mlir; |
32 | |
33 | // Defined in the test directory, no public header. |
34 | namespace mlir { |
35 | void registerConvertToTargetEnvPass(); |
36 | void registerCloneTestPasses(); |
37 | void registerLazyLoadingTestPasses(); |
38 | void registerPassManagerTestPass(); |
39 | void registerPrintSpirvAvailabilityPass(); |
40 | void registerLoopLikeInterfaceTestPasses(); |
41 | void registerShapeFunctionTestPasses(); |
42 | void registerSideEffectTestPasses(); |
43 | void registerSliceAnalysisTestPass(); |
44 | void registerSymbolTestPasses(); |
45 | void registerRegionTestPasses(); |
46 | void registerTestAffineDataCopyPass(); |
47 | void registerTestAffineAccessAnalysisPass(); |
48 | void registerTestAffineReifyValueBoundsPass(); |
49 | void registerTestAffineLoopUnswitchingPass(); |
50 | void registerTestAffineWalk(); |
51 | void registerTestBytecodeRoundtripPasses(); |
52 | void registerTestDecomposeAffineOpPass(); |
53 | void registerTestFunc(); |
54 | void registerTestGpuLoweringPasses(); |
55 | void registerTestGpuMemoryPromotionPass(); |
56 | void registerTestLoopPermutationPass(); |
57 | void registerTestMatchers(); |
58 | void registerTestOperationEqualPass(); |
59 | void registerTestPrintDefUsePass(); |
60 | void registerTestPrintInvalidPass(); |
61 | void registerTestPrintNestingPass(); |
62 | void registerTestPreserveUseListOrders(); |
63 | void registerTestReducer(); |
64 | void registerTestSpirvEntryPointABIPass(); |
65 | void registerTestSpirvModuleCombinerPass(); |
66 | void registerTestTraitsPass(); |
67 | void registerTosaTestQuantUtilAPIPass(); |
68 | void registerVectorizerTestPass(); |
69 | |
70 | namespace test { |
71 | void registerTestCompositePass(); |
72 | void registerCommutativityUtils(); |
73 | void registerConvertCallOpPass(); |
74 | void registerInliner(); |
75 | void registerMemRefBoundCheck(); |
76 | void registerPatternsTestPass(); |
77 | void registerSimpleParametricTilingPass(); |
78 | void registerTestAffineLoopParametricTilingPass(); |
79 | void registerTestArithEmulateWideIntPass(); |
80 | void registerTestAliasAnalysisPass(); |
81 | void registerTestBuiltinAttributeInterfaces(); |
82 | void registerTestBuiltinDistinctAttributes(); |
83 | void registerTestCallGraphPass(); |
84 | void registerTestCfAssertPass(); |
85 | void registerTestConstantFold(); |
86 | void registerTestControlFlowSink(); |
87 | void registerTestDataLayoutPropagation(); |
88 | void registerTestDataLayoutQuery(); |
89 | void registerTestDeadCodeAnalysisPass(); |
90 | void registerTestDecomposeCallGraphTypes(); |
91 | void registerTestDiagnosticsPass(); |
92 | void registerTestDominancePass(); |
93 | void registerTestDynamicPipelinePass(); |
94 | void registerTestEmulateNarrowTypePass(); |
95 | void registerTestExpandMathPass(); |
96 | void registerTestFooAnalysisPass(); |
97 | void registerTestComposeSubView(); |
98 | void registerTestMultiBuffering(); |
99 | void registerTestIntRangeInference(); |
100 | void registerTestIRVisitorsPass(); |
101 | void registerTestGenericIRVisitorsPass(); |
102 | void registerTestInterfaces(); |
103 | void registerTestLastModifiedPass(); |
104 | void registerTestLinalgDecomposeOps(); |
105 | void registerTestLinalgDropUnitDims(); |
106 | void registerTestLinalgElementwiseFusion(); |
107 | void registerTestLinalgGreedyFusion(); |
108 | void registerTestLinalgTransforms(); |
109 | void registerTestLivenessAnalysisPass(); |
110 | void registerTestLivenessPass(); |
111 | void registerTestLoopFusion(); |
112 | void registerTestCFGLoopInfoPass(); |
113 | void registerTestLoopMappingPass(); |
114 | void registerTestLoopUnrollingPass(); |
115 | void registerTestLowerToArmNeon(); |
116 | void registerTestLowerToArmSME(); |
117 | void registerTestLowerToLLVM(); |
118 | void registerTestMakeIsolatedFromAbovePass(); |
119 | void registerTestMatchReductionPass(); |
120 | void registerTestMathAlgebraicSimplificationPass(); |
121 | void registerTestMathPolynomialApproximationPass(); |
122 | void registerTestMathToVCIXPass(); |
123 | void registerTestMemRefDependenceCheck(); |
124 | void registerTestMemRefStrideCalculation(); |
125 | void registerTestMeshSimplificationsPass(); |
126 | void registerTestMeshReshardingSpmdizationPass(); |
127 | void registerTestOpLoweringPasses(); |
128 | void registerTestNextAccessPass(); |
129 | void registerTestOneToNTypeConversionPass(); |
130 | void registerTestOpaqueLoc(); |
131 | void registerTestPadFusion(); |
132 | void registerTestRecursiveTypesPass(); |
133 | void registerTestSCFUpliftWhileToFor(); |
134 | void registerTestSCFUtilsPass(); |
135 | void registerTestSCFWhileOpBuilderPass(); |
136 | void registerTestSCFWrapInZeroTripCheckPasses(); |
137 | void registerTestShapeMappingPass(); |
138 | void registerTestSliceAnalysisPass(); |
139 | void registerTestTensorCopyInsertionPass(); |
140 | void registerTestTensorTransforms(); |
141 | void registerTestTopologicalSortAnalysisPass(); |
142 | void registerTestTransformDialectEraseSchedulePass(); |
143 | void registerTestTransformDialectInterpreterPass(); |
144 | void registerTestWrittenToPass(); |
145 | void registerTestVectorLowerings(); |
146 | void registerTestVectorReductionToSPIRVDotProd(); |
147 | void registerTestNvgpuLowerings(); |
148 | #if MLIR_ENABLE_PDL_IN_PATTERNMATCH |
149 | void registerTestDialectConversionPasses(); |
150 | void registerTestPDLByteCodePass(); |
151 | void registerTestPDLLPasses(); |
152 | #endif |
153 | } // namespace test |
154 | } // namespace mlir |
155 | |
156 | namespace test { |
157 | void registerTestDialect(DialectRegistry &); |
158 | void registerTestDynDialect(DialectRegistry &); |
159 | void registerTestTilingInterfaceTransformDialectExtension(DialectRegistry &); |
160 | void registerTestTransformDialectExtension(DialectRegistry &); |
161 | } // namespace test |
162 | |
163 | #ifdef MLIR_INCLUDE_TESTS |
164 | void registerTestPasses() { |
165 | registerCloneTestPasses(); |
166 | registerConvertToTargetEnvPass(); |
167 | registerPassManagerTestPass(); |
168 | registerPrintSpirvAvailabilityPass(); |
169 | registerLazyLoadingTestPasses(); |
170 | registerLoopLikeInterfaceTestPasses(); |
171 | registerShapeFunctionTestPasses(); |
172 | registerSideEffectTestPasses(); |
173 | registerSliceAnalysisTestPass(); |
174 | registerSymbolTestPasses(); |
175 | registerRegionTestPasses(); |
176 | registerTestAffineDataCopyPass(); |
177 | registerTestAffineAccessAnalysisPass(); |
178 | registerTestAffineLoopUnswitchingPass(); |
179 | registerTestAffineReifyValueBoundsPass(); |
180 | registerTestAffineWalk(); |
181 | registerTestBytecodeRoundtripPasses(); |
182 | registerTestDecomposeAffineOpPass(); |
183 | registerTestFunc(); |
184 | registerTestGpuLoweringPasses(); |
185 | registerTestGpuMemoryPromotionPass(); |
186 | registerTestLoopPermutationPass(); |
187 | registerTestMatchers(); |
188 | registerTestOperationEqualPass(); |
189 | registerTestPrintDefUsePass(); |
190 | registerTestPrintInvalidPass(); |
191 | registerTestPrintNestingPass(); |
192 | registerTestPreserveUseListOrders(); |
193 | registerTestReducer(); |
194 | registerTestSpirvEntryPointABIPass(); |
195 | registerTestSpirvModuleCombinerPass(); |
196 | registerTestTraitsPass(); |
197 | registerVectorizerTestPass(); |
198 | registerTosaTestQuantUtilAPIPass(); |
199 | |
200 | mlir::test::registerTestCompositePass(); |
201 | mlir::test::registerCommutativityUtils(); |
202 | mlir::test::registerConvertCallOpPass(); |
203 | mlir::test::registerInliner(); |
204 | mlir::test::registerMemRefBoundCheck(); |
205 | mlir::test::registerPatternsTestPass(); |
206 | mlir::test::registerSimpleParametricTilingPass(); |
207 | mlir::test::registerTestAffineLoopParametricTilingPass(); |
208 | mlir::test::registerTestAliasAnalysisPass(); |
209 | mlir::test::registerTestArithEmulateWideIntPass(); |
210 | mlir::test::registerTestBuiltinAttributeInterfaces(); |
211 | mlir::test::registerTestBuiltinDistinctAttributes(); |
212 | mlir::test::registerTestCallGraphPass(); |
213 | mlir::test::registerTestCfAssertPass(); |
214 | mlir::test::registerTestConstantFold(); |
215 | mlir::test::registerTestControlFlowSink(); |
216 | mlir::test::registerTestDiagnosticsPass(); |
217 | mlir::test::registerTestDecomposeCallGraphTypes(); |
218 | mlir::test::registerTestDataLayoutPropagation(); |
219 | mlir::test::registerTestDataLayoutQuery(); |
220 | mlir::test::registerTestDeadCodeAnalysisPass(); |
221 | mlir::test::registerTestDominancePass(); |
222 | mlir::test::registerTestDynamicPipelinePass(); |
223 | mlir::test::registerTestEmulateNarrowTypePass(); |
224 | mlir::test::registerTestExpandMathPass(); |
225 | mlir::test::registerTestFooAnalysisPass(); |
226 | mlir::test::registerTestComposeSubView(); |
227 | mlir::test::registerTestMultiBuffering(); |
228 | mlir::test::registerTestIntRangeInference(); |
229 | mlir::test::registerTestIRVisitorsPass(); |
230 | mlir::test::registerTestGenericIRVisitorsPass(); |
231 | mlir::test::registerTestInterfaces(); |
232 | mlir::test::registerTestLastModifiedPass(); |
233 | mlir::test::registerTestLinalgDecomposeOps(); |
234 | mlir::test::registerTestLinalgDropUnitDims(); |
235 | mlir::test::registerTestLinalgElementwiseFusion(); |
236 | mlir::test::registerTestLinalgGreedyFusion(); |
237 | mlir::test::registerTestLinalgTransforms(); |
238 | mlir::test::registerTestLivenessAnalysisPass(); |
239 | mlir::test::registerTestLivenessPass(); |
240 | mlir::test::registerTestLoopFusion(); |
241 | mlir::test::registerTestCFGLoopInfoPass(); |
242 | mlir::test::registerTestLoopMappingPass(); |
243 | mlir::test::registerTestLoopUnrollingPass(); |
244 | mlir::test::registerTestLowerToArmNeon(); |
245 | mlir::test::registerTestLowerToArmSME(); |
246 | mlir::test::registerTestLowerToLLVM(); |
247 | mlir::test::registerTestMakeIsolatedFromAbovePass(); |
248 | mlir::test::registerTestMatchReductionPass(); |
249 | mlir::test::registerTestMathAlgebraicSimplificationPass(); |
250 | mlir::test::registerTestMathPolynomialApproximationPass(); |
251 | mlir::test::registerTestMathToVCIXPass(); |
252 | mlir::test::registerTestMemRefDependenceCheck(); |
253 | mlir::test::registerTestMemRefStrideCalculation(); |
254 | mlir::test::registerTestOpLoweringPasses(); |
255 | mlir::test::registerTestMeshSimplificationsPass(); |
256 | mlir::test::registerTestMeshReshardingSpmdizationPass(); |
257 | mlir::test::registerTestNextAccessPass(); |
258 | mlir::test::registerTestOneToNTypeConversionPass(); |
259 | mlir::test::registerTestOpaqueLoc(); |
260 | mlir::test::registerTestPadFusion(); |
261 | mlir::test::registerTestRecursiveTypesPass(); |
262 | mlir::test::registerTestSCFUpliftWhileToFor(); |
263 | mlir::test::registerTestSCFUtilsPass(); |
264 | mlir::test::registerTestSCFWhileOpBuilderPass(); |
265 | mlir::test::registerTestSCFWrapInZeroTripCheckPasses(); |
266 | mlir::test::registerTestShapeMappingPass(); |
267 | mlir::test::registerTestSliceAnalysisPass(); |
268 | mlir::test::registerTestTensorCopyInsertionPass(); |
269 | mlir::test::registerTestTensorTransforms(); |
270 | mlir::test::registerTestTopologicalSortAnalysisPass(); |
271 | mlir::test::registerTestTransformDialectEraseSchedulePass(); |
272 | mlir::test::registerTestTransformDialectInterpreterPass(); |
273 | mlir::test::registerTestVectorLowerings(); |
274 | mlir::test::registerTestVectorReductionToSPIRVDotProd(); |
275 | mlir::test::registerTestNvgpuLowerings(); |
276 | mlir::test::registerTestWrittenToPass(); |
277 | #if MLIR_ENABLE_PDL_IN_PATTERNMATCH |
278 | mlir::test::registerTestDialectConversionPasses(); |
279 | mlir::test::registerTestPDLByteCodePass(); |
280 | mlir::test::registerTestPDLLPasses(); |
281 | #endif |
282 | } |
283 | #endif |
284 | |
285 | int main(int argc, char **argv) { |
286 | registerAllPasses(); |
287 | #if MLIR_DEPRECATED_GPU_SERIALIZATION_ENABLE |
288 | registerGpuSerializeToCubinPass(); |
289 | registerGpuSerializeToHsacoPass(); |
290 | #endif |
291 | #ifdef MLIR_INCLUDE_TESTS |
292 | registerTestPasses(); |
293 | #endif |
294 | DialectRegistry registry; |
295 | registerAllDialects(registry); |
296 | registerAllExtensions(registry); |
297 | |
298 | // TODO: Remove this and the corresponding MLIRToLLVMIRTranslationRegistration |
299 | // cmake dependency when a safe dialect interface registration mechanism is |
300 | // implemented, see D157703 (and corresponding note on the declaration). |
301 | registerAllGPUToLLVMIRTranslations(registry); |
302 | |
303 | #ifdef MLIR_INCLUDE_TESTS |
304 | ::test::registerTestDialect(registry); |
305 | ::test::registerTestTransformDialectExtension(registry); |
306 | ::test::registerTestTilingInterfaceTransformDialectExtension(registry); |
307 | ::test::registerTestDynDialect(registry); |
308 | #endif |
309 | return mlir::asMainReturnCode(r: mlir::MlirOptMain( |
310 | argc, argv, toolName: "MLIR modular optimizer driver\n", registry)); |
311 | } |
312 |