1 //===- mlir-opt.cpp - MLIR Optimizer Driver -------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Main entry function for mlir-opt for when built as standalone binary.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/IR/AsmState.h"
14 #include "mlir/IR/Dialect.h"
15 #include "mlir/IR/MLIRContext.h"
16 #include "mlir/InitAllDialects.h"
17 #include "mlir/InitAllPasses.h"
18 #include "mlir/Pass/Pass.h"
19 #include "mlir/Pass/PassManager.h"
20 #include "mlir/Support/FileUtilities.h"
21 #include "mlir/Tools/mlir-opt/MlirOptMain.h"
22 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/InitLLVM.h"
24 #include "llvm/Support/SourceMgr.h"
25 #include "llvm/Support/ToolOutputFile.h"
30 // Defined in the test directory, no public header.
32 void registerConvertToTargetEnvPass();
33 void registerCloneTestPasses();
34 void registerLazyLoadingTestPasses();
35 void registerPassManagerTestPass();
36 void registerPrintSpirvAvailabilityPass();
37 void registerLoopLikeInterfaceTestPasses();
38 void registerShapeFunctionTestPasses();
39 void registerSideEffectTestPasses();
40 void registerSliceAnalysisTestPass();
41 void registerSymbolTestPasses();
42 void registerRegionTestPasses();
43 void registerTestAffineDataCopyPass();
44 void registerTestAffineReifyValueBoundsPass();
45 void registerTestDecomposeAffineOpPass();
46 void registerTestAffineLoopUnswitchingPass();
47 void registerTestAllReduceLoweringPass();
48 void registerTestFunc();
49 void registerTestGpuMemoryPromotionPass();
50 void registerTestLoopPermutationPass();
51 void registerTestMatchers();
52 void registerTestOperationEqualPass();
53 void registerTestPrintDefUsePass();
54 void registerTestPrintInvalidPass();
55 void registerTestPrintNestingPass();
56 void registerTestPreserveUseListOrders();
57 void registerTestReducer();
58 void registerTestSpirvEntryPointABIPass();
59 void registerTestSpirvModuleCombinerPass();
60 void registerTestTraitsPass();
61 void registerTosaTestQuantUtilAPIPass();
62 void registerVectorizerTestPass();
65 void registerCommutativityUtils();
66 void registerConvertCallOpPass();
67 void registerInliner();
68 void registerMemRefBoundCheck();
69 void registerPatternsTestPass();
70 void registerSimpleParametricTilingPass();
71 void registerTestAffineLoopParametricTilingPass();
72 void registerTestArithEmulateWideIntPass();
73 void registerTestAliasAnalysisPass();
74 void registerTestBuiltinAttributeInterfaces();
75 void registerTestCallGraphPass();
76 void registerTestCfAssertPass();
77 void registerTestConstantFold();
78 void registerTestControlFlowSink();
79 void registerTestGpuSerializeToCubinPass();
80 void registerTestGpuSerializeToHsacoPass();
81 void registerTestDataLayoutPropagation();
82 void registerTestDataLayoutQuery();
83 void registerTestDeadCodeAnalysisPass();
84 void registerTestDecomposeCallGraphTypes();
85 void registerTestDiagnosticsPass();
86 void registerTestDialectConversionPasses();
87 void registerTestDominancePass();
88 void registerTestDynamicPipelinePass();
89 void registerTestExpandMathPass();
90 void registerTestFooAnalysisPass();
91 void registerTestComposeSubView();
92 void registerTestMultiBuffering();
93 void registerTestIntRangeInference();
94 void registerTestIRVisitorsPass();
95 void registerTestGenericIRVisitorsPass();
96 void registerTestGenericIRVisitorsInterruptPass();
97 void registerTestInterfaces();
98 void registerTestLastModifiedPass();
99 void registerTestLinalgDecomposeOps();
100 void registerTestLinalgElementwiseFusion();
101 void registerTestLinalgGreedyFusion();
102 void registerTestLinalgTransforms();
103 void registerTestLivenessPass();
104 void registerTestLoopFusion();
105 void registerTestCFGLoopInfoPass();
106 void registerTestLoopMappingPass();
107 void registerTestLoopUnrollingPass();
108 void registerTestLowerToLLVM();
109 void registerTestMakeIsolatedFromAbovePass();
110 void registerTestMatchReductionPass();
111 void registerTestMathAlgebraicSimplificationPass();
112 void registerTestMathPolynomialApproximationPass();
113 void registerTestMemRefDependenceCheck();
114 void registerTestMemRefStrideCalculation();
115 void registerTestOneToNTypeConversionPass();
116 void registerTestOpaqueLoc();
117 void registerTestPadFusion();
118 void registerTestPDLByteCodePass();
119 void registerTestPDLLPasses();
120 void registerTestPreparationPassWithAllowedMemrefResults();
121 void registerTestRecursiveTypesPass();
122 void registerTestSCFUtilsPass();
123 void registerTestSCFWhileOpBuilderPass();
124 void registerTestShapeMappingPass();
125 void registerTestSliceAnalysisPass();
126 void registerTestTensorCopyInsertionPass();
127 void registerTestTensorTransforms();
128 void registerTestTilingInterface();
129 void registerTestTopologicalSortAnalysisPass();
130 void registerTestTransformDialectEraseSchedulePass();
131 void registerTestTransformDialectInterpreterPass();
132 void registerTestWrittenToPass();
133 void registerTestVectorLowerings();
134 void registerTestVectorReductionToSPIRVDotProd();
135 void registerTestNvgpuLowerings();
140 void registerTestDialect(DialectRegistry
&);
141 void registerTestTransformDialectExtension(DialectRegistry
&);
142 void registerTestDynDialect(DialectRegistry
&);
145 #ifdef MLIR_INCLUDE_TESTS
146 void registerTestPasses() {
147 registerCloneTestPasses();
148 registerConvertToTargetEnvPass();
149 registerPassManagerTestPass();
150 registerPrintSpirvAvailabilityPass();
151 registerLazyLoadingTestPasses();
152 registerLoopLikeInterfaceTestPasses();
153 registerShapeFunctionTestPasses();
154 registerSideEffectTestPasses();
155 registerSliceAnalysisTestPass();
156 registerSymbolTestPasses();
157 registerRegionTestPasses();
158 registerTestAffineDataCopyPass();
159 registerTestAffineReifyValueBoundsPass();
160 registerTestDecomposeAffineOpPass();
161 registerTestAffineLoopUnswitchingPass();
162 registerTestAllReduceLoweringPass();
164 registerTestGpuMemoryPromotionPass();
165 registerTestLoopPermutationPass();
166 registerTestMatchers();
167 registerTestOperationEqualPass();
168 registerTestPrintDefUsePass();
169 registerTestPrintInvalidPass();
170 registerTestPrintNestingPass();
171 registerTestPreserveUseListOrders();
172 registerTestReducer();
173 registerTestSpirvEntryPointABIPass();
174 registerTestSpirvModuleCombinerPass();
175 registerTestTraitsPass();
176 registerVectorizerTestPass();
177 registerTosaTestQuantUtilAPIPass();
179 mlir::test::registerCommutativityUtils();
180 mlir::test::registerConvertCallOpPass();
181 mlir::test::registerInliner();
182 mlir::test::registerMemRefBoundCheck();
183 mlir::test::registerPatternsTestPass();
184 mlir::test::registerSimpleParametricTilingPass();
185 mlir::test::registerTestAffineLoopParametricTilingPass();
186 mlir::test::registerTestAliasAnalysisPass();
187 mlir::test::registerTestArithEmulateWideIntPass();
188 mlir::test::registerTestBuiltinAttributeInterfaces();
189 mlir::test::registerTestCallGraphPass();
190 mlir::test::registerTestCfAssertPass();
191 mlir::test::registerTestConstantFold();
192 mlir::test::registerTestControlFlowSink();
193 mlir::test::registerTestDiagnosticsPass();
194 mlir::test::registerTestDialectConversionPasses();
195 #if MLIR_CUDA_CONVERSIONS_ENABLED
196 mlir::test::registerTestGpuSerializeToCubinPass();
198 #if MLIR_ROCM_CONVERSIONS_ENABLED
199 mlir::test::registerTestGpuSerializeToHsacoPass();
201 mlir::test::registerTestDecomposeCallGraphTypes();
202 mlir::test::registerTestDataLayoutPropagation();
203 mlir::test::registerTestDataLayoutQuery();
204 mlir::test::registerTestDeadCodeAnalysisPass();
205 mlir::test::registerTestDominancePass();
206 mlir::test::registerTestDynamicPipelinePass();
207 mlir::test::registerTestExpandMathPass();
208 mlir::test::registerTestFooAnalysisPass();
209 mlir::test::registerTestComposeSubView();
210 mlir::test::registerTestMultiBuffering();
211 mlir::test::registerTestIntRangeInference();
212 mlir::test::registerTestIRVisitorsPass();
213 mlir::test::registerTestGenericIRVisitorsPass();
214 mlir::test::registerTestInterfaces();
215 mlir::test::registerTestLastModifiedPass();
216 mlir::test::registerTestLinalgDecomposeOps();
217 mlir::test::registerTestLinalgElementwiseFusion();
218 mlir::test::registerTestLinalgGreedyFusion();
219 mlir::test::registerTestLinalgTransforms();
220 mlir::test::registerTestLivenessPass();
221 mlir::test::registerTestLoopFusion();
222 mlir::test::registerTestCFGLoopInfoPass();
223 mlir::test::registerTestLoopMappingPass();
224 mlir::test::registerTestLoopUnrollingPass();
225 mlir::test::registerTestLowerToLLVM();
226 mlir::test::registerTestMakeIsolatedFromAbovePass();
227 mlir::test::registerTestMatchReductionPass();
228 mlir::test::registerTestMathAlgebraicSimplificationPass();
229 mlir::test::registerTestMathPolynomialApproximationPass();
230 mlir::test::registerTestMemRefDependenceCheck();
231 mlir::test::registerTestMemRefStrideCalculation();
232 mlir::test::registerTestOneToNTypeConversionPass();
233 mlir::test::registerTestOpaqueLoc();
234 mlir::test::registerTestPadFusion();
235 mlir::test::registerTestPDLByteCodePass();
236 mlir::test::registerTestPDLLPasses();
237 mlir::test::registerTestRecursiveTypesPass();
238 mlir::test::registerTestSCFUtilsPass();
239 mlir::test::registerTestSCFWhileOpBuilderPass();
240 mlir::test::registerTestShapeMappingPass();
241 mlir::test::registerTestSliceAnalysisPass();
242 mlir::test::registerTestTensorCopyInsertionPass();
243 mlir::test::registerTestTensorTransforms();
244 mlir::test::registerTestTilingInterface();
245 mlir::test::registerTestTopologicalSortAnalysisPass();
246 mlir::test::registerTestTransformDialectEraseSchedulePass();
247 mlir::test::registerTestTransformDialectInterpreterPass();
248 mlir::test::registerTestVectorLowerings();
249 mlir::test::registerTestVectorReductionToSPIRVDotProd();
250 mlir::test::registerTestNvgpuLowerings();
251 mlir::test::registerTestWrittenToPass();
255 int main(int argc
, char **argv
) {
257 #ifdef MLIR_INCLUDE_TESTS
258 registerTestPasses();
260 DialectRegistry registry
;
261 registerAllDialects(registry
);
262 #ifdef MLIR_INCLUDE_TESTS
263 ::test::registerTestDialect(registry
);
264 ::test::registerTestTransformDialectExtension(registry
);
265 ::test::registerTestDynDialect(registry
);
267 return mlir::asMainReturnCode(
268 mlir::MlirOptMain(argc
, argv
, "MLIR modular optimizer driver\n", registry
));