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/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/Support/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"
26 
27 using namespace llvm;
28 using namespace mlir;
29 
30 // Defined in the test directory, no public header.
31 namespace mlir {
32 void registerConvertToTargetEnvPass();
33 void registerPassManagerTestPass();
34 void registerPrintOpAvailabilityPass();
35 void registerShapeFunctionTestPasses();
36 void registerSideEffectTestPasses();
37 void registerSliceAnalysisTestPass();
38 void registerSymbolTestPasses();
39 void registerTestAffineDataCopyPass();
40 void registerTestAffineLoopUnswitchingPass();
41 void registerTestAllReduceLoweringPass();
42 void registerTestFunc();
43 void registerTestGpuMemoryPromotionPass();
44 void registerTestLoopPermutationPass();
45 void registerTestMatchers();
46 void registerTestPrintDefUsePass();
47 void registerTestPrintNestingPass();
48 void registerTestReducer();
49 void registerTestSpirvEntryPointABIPass();
50 void registerTestSpirvModuleCombinerPass();
51 void registerTestTraitsPass();
52 void registerTosaTestQuantUtilAPIPass();
53 void registerVectorizerTestPass();
54 
55 namespace test {
56 void registerConvertCallOpPass();
57 void registerInliner();
58 void registerMemRefBoundCheck();
59 void registerPatternsTestPass();
60 void registerSimpleParametricTilingPass();
61 void registerTestAffineLoopParametricTilingPass();
62 void registerTestCallGraphPass();
63 void registerTestConstantFold();
64 void registerTestConvVectorization();
65 void registerTestConvertGPUKernelToCubinPass();
66 void registerTestConvertGPUKernelToHsacoPass();
67 void registerTestDecomposeCallGraphTypes();
68 void registerTestDialect(DialectRegistry &);
69 void registerTestDominancePass();
70 void registerTestDynamicPipelinePass();
71 void registerTestExpandTanhPass();
72 void registerTestGpuParallelLoopMappingPass();
73 void registerTestInterfaces();
74 void registerTestLinalgCodegenStrategy();
75 void registerTestLinalgFusionTransforms();
76 void registerTestLinalgGreedyFusion();
77 void registerTestLinalgHoisting();
78 void registerTestLinalgTileAndFuseSequencePass();
79 void registerTestLinalgTransforms();
80 void registerTestLivenessPass();
81 void registerTestLoopFusion();
82 void registerTestLoopMappingPass();
83 void registerTestLoopUnrollingPass();
84 void registerTestMemRefDependenceCheck();
85 void registerTestMemRefStrideCalculation();
86 void registerTestNumberOfBlockExecutionsPass();
87 void registerTestNumberOfOperationExecutionsPass();
88 void registerTestOpaqueLoc();
89 void registerTestPDLByteCodePass();
90 void registerTestPreparationPassWithAllowedMemrefResults();
91 void registerTestRecursiveTypesPass();
92 void registerTestSCFUtilsPass();
93 void registerTestSparsification();
94 void registerTestVectorConversions();
95 } // namespace test
96 } // namespace mlir
97 
98 #ifdef MLIR_INCLUDE_TESTS
registerTestPasses()99 void registerTestPasses() {
100   registerConvertToTargetEnvPass();
101   registerPassManagerTestPass();
102   registerPrintOpAvailabilityPass();
103   registerShapeFunctionTestPasses();
104   registerSideEffectTestPasses();
105   registerSliceAnalysisTestPass();
106   registerSymbolTestPasses();
107   registerTestAffineDataCopyPass();
108   registerTestAffineLoopUnswitchingPass();
109   registerTestAllReduceLoweringPass();
110   registerTestFunc();
111   registerTestGpuMemoryPromotionPass();
112   registerTestLoopPermutationPass();
113   registerTestMatchers();
114   registerTestPrintDefUsePass();
115   registerTestPrintNestingPass();
116   registerTestReducer();
117   registerTestSpirvEntryPointABIPass();
118   registerTestSpirvModuleCombinerPass();
119   registerTestTraitsPass();
120   registerVectorizerTestPass();
121   registerTosaTestQuantUtilAPIPass();
122 
123   test::registerConvertCallOpPass();
124   test::registerInliner();
125   test::registerMemRefBoundCheck();
126   test::registerPatternsTestPass();
127   test::registerSimpleParametricTilingPass();
128   test::registerTestAffineLoopParametricTilingPass();
129   test::registerTestCallGraphPass();
130   test::registerTestConstantFold();
131 #if MLIR_CUDA_CONVERSIONS_ENABLED
132   test::registerTestConvertGPUKernelToCubinPass();
133 #endif
134 #if MLIR_ROCM_CONVERSIONS_ENABLED
135   test::registerTestConvertGPUKernelToHsacoPass();
136 #endif
137   test::registerTestConvVectorization();
138   test::registerTestDecomposeCallGraphTypes();
139   test::registerTestDominancePass();
140   test::registerTestDynamicPipelinePass();
141   test::registerTestExpandTanhPass();
142   test::registerTestGpuParallelLoopMappingPass();
143   test::registerTestInterfaces();
144   test::registerTestLinalgCodegenStrategy();
145   test::registerTestLinalgFusionTransforms();
146   test::registerTestLinalgGreedyFusion();
147   test::registerTestLinalgHoisting();
148   test::registerTestLinalgTileAndFuseSequencePass();
149   test::registerTestLinalgTransforms();
150   test::registerTestLivenessPass();
151   test::registerTestLoopFusion();
152   test::registerTestLoopMappingPass();
153   test::registerTestLoopUnrollingPass();
154   test::registerTestMemRefDependenceCheck();
155   test::registerTestMemRefStrideCalculation();
156   test::registerTestNumberOfBlockExecutionsPass();
157   test::registerTestNumberOfOperationExecutionsPass();
158   test::registerTestOpaqueLoc();
159   test::registerTestPDLByteCodePass();
160   test::registerTestRecursiveTypesPass();
161   test::registerTestSCFUtilsPass();
162   test::registerTestSparsification();
163   test::registerTestVectorConversions();
164 }
165 #endif
166 
main(int argc,char ** argv)167 int main(int argc, char **argv) {
168   registerAllPasses();
169 #ifdef MLIR_INCLUDE_TESTS
170   registerTestPasses();
171 #endif
172   DialectRegistry registry;
173   registerAllDialects(registry);
174 #ifdef MLIR_INCLUDE_TESTS
175   test::registerTestDialect(registry);
176 #endif
177   return failed(MlirOptMain(argc, argv, "MLIR modular optimizer driver\n",
178                             registry,
179                             /*preloadDialectsInContext=*/false));
180 }
181