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
30using namespace llvm;
31using namespace mlir;
32
33// Defined in the test directory, no public header.
34namespace mlir {
35void registerConvertToTargetEnvPass();
36void registerCloneTestPasses();
37void registerLazyLoadingTestPasses();
38void registerPassManagerTestPass();
39void registerPrintSpirvAvailabilityPass();
40void registerLoopLikeInterfaceTestPasses();
41void registerShapeFunctionTestPasses();
42void registerSideEffectTestPasses();
43void registerSliceAnalysisTestPass();
44void registerSymbolTestPasses();
45void registerRegionTestPasses();
46void registerTestAffineDataCopyPass();
47void registerTestAffineAccessAnalysisPass();
48void registerTestAffineReifyValueBoundsPass();
49void registerTestAffineLoopUnswitchingPass();
50void registerTestAffineWalk();
51void registerTestBytecodeRoundtripPasses();
52void registerTestDecomposeAffineOpPass();
53void registerTestFunc();
54void registerTestGpuLoweringPasses();
55void registerTestGpuMemoryPromotionPass();
56void registerTestLoopPermutationPass();
57void registerTestMatchers();
58void registerTestOperationEqualPass();
59void registerTestPrintDefUsePass();
60void registerTestPrintInvalidPass();
61void registerTestPrintNestingPass();
62void registerTestPreserveUseListOrders();
63void registerTestReducer();
64void registerTestSpirvEntryPointABIPass();
65void registerTestSpirvModuleCombinerPass();
66void registerTestTraitsPass();
67void registerTosaTestQuantUtilAPIPass();
68void registerVectorizerTestPass();
69
70namespace test {
71void registerTestCompositePass();
72void registerCommutativityUtils();
73void registerConvertCallOpPass();
74void registerInliner();
75void registerMemRefBoundCheck();
76void registerPatternsTestPass();
77void registerSimpleParametricTilingPass();
78void registerTestAffineLoopParametricTilingPass();
79void registerTestArithEmulateWideIntPass();
80void registerTestAliasAnalysisPass();
81void registerTestBuiltinAttributeInterfaces();
82void registerTestBuiltinDistinctAttributes();
83void registerTestCallGraphPass();
84void registerTestCfAssertPass();
85void registerTestConstantFold();
86void registerTestControlFlowSink();
87void registerTestDataLayoutPropagation();
88void registerTestDataLayoutQuery();
89void registerTestDeadCodeAnalysisPass();
90void registerTestDecomposeCallGraphTypes();
91void registerTestDiagnosticsPass();
92void registerTestDominancePass();
93void registerTestDynamicPipelinePass();
94void registerTestEmulateNarrowTypePass();
95void registerTestExpandMathPass();
96void registerTestFooAnalysisPass();
97void registerTestComposeSubView();
98void registerTestMultiBuffering();
99void registerTestIntRangeInference();
100void registerTestIRVisitorsPass();
101void registerTestGenericIRVisitorsPass();
102void registerTestInterfaces();
103void registerTestLastModifiedPass();
104void registerTestLinalgDecomposeOps();
105void registerTestLinalgDropUnitDims();
106void registerTestLinalgElementwiseFusion();
107void registerTestLinalgGreedyFusion();
108void registerTestLinalgTransforms();
109void registerTestLivenessAnalysisPass();
110void registerTestLivenessPass();
111void registerTestLoopFusion();
112void registerTestCFGLoopInfoPass();
113void registerTestLoopMappingPass();
114void registerTestLoopUnrollingPass();
115void registerTestLowerToArmNeon();
116void registerTestLowerToArmSME();
117void registerTestLowerToLLVM();
118void registerTestMakeIsolatedFromAbovePass();
119void registerTestMatchReductionPass();
120void registerTestMathAlgebraicSimplificationPass();
121void registerTestMathPolynomialApproximationPass();
122void registerTestMathToVCIXPass();
123void registerTestMemRefDependenceCheck();
124void registerTestMemRefStrideCalculation();
125void registerTestMeshSimplificationsPass();
126void registerTestMeshReshardingSpmdizationPass();
127void registerTestOpLoweringPasses();
128void registerTestNextAccessPass();
129void registerTestOneToNTypeConversionPass();
130void registerTestOpaqueLoc();
131void registerTestPadFusion();
132void registerTestRecursiveTypesPass();
133void registerTestSCFUpliftWhileToFor();
134void registerTestSCFUtilsPass();
135void registerTestSCFWhileOpBuilderPass();
136void registerTestSCFWrapInZeroTripCheckPasses();
137void registerTestShapeMappingPass();
138void registerTestSliceAnalysisPass();
139void registerTestTensorCopyInsertionPass();
140void registerTestTensorTransforms();
141void registerTestTopologicalSortAnalysisPass();
142void registerTestTransformDialectEraseSchedulePass();
143void registerTestTransformDialectInterpreterPass();
144void registerTestWrittenToPass();
145void registerTestVectorLowerings();
146void registerTestVectorReductionToSPIRVDotProd();
147void registerTestNvgpuLowerings();
148#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
149void registerTestDialectConversionPasses();
150void registerTestPDLByteCodePass();
151void registerTestPDLLPasses();
152#endif
153} // namespace test
154} // namespace mlir
155
156namespace test {
157void registerTestDialect(DialectRegistry &);
158void registerTestDynDialect(DialectRegistry &);
159void registerTestTilingInterfaceTransformDialectExtension(DialectRegistry &);
160void registerTestTransformDialectExtension(DialectRegistry &);
161} // namespace test
162
163#ifdef MLIR_INCLUDE_TESTS
164void 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
285int 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

source code of mlir/tools/mlir-opt/mlir-opt.cpp