llvm.org GIT mirror llvm / a21cd04
[PM] Add a nice low-tech registry of passes as a boring macro expansion file. This will make it easy to scale up the number of passes supported. Currently, it just supports the function and module transformation passes that were already supported in the opt tool explicitly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206737 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
2 changed file(s) with 52 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
0 //===- PassRegistry.def - Registry of passes --------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is used as the registry of passes that are part of the core LLVM
10 // libraries. This file describes both transformation passes and analyses
11 // Analyses are registered while transformation passes have names registered
12 // that can be used when providing a textual pass pipeline.
13 //
14 //===----------------------------------------------------------------------===//
15
16 // NOTE: NO INCLUDE GUARD DESIRED!
17
18 #ifndef MODULE_PASS
19 #define MODULE_PASS(NAME, CREATE_PASS)
20 #endif
21 MODULE_PASS("print", PrintModulePass(dbgs()))
22 MODULE_PASS("print-cg", LazyCallGraphPrinterPass(dbgs()))
23 #undef MODULE_PASS
24
25 #ifndef FUNCTION_PASS
26 #define FUNCTION_PASS(NAME, CREATE_PASS)
27 #endif
28 FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
29 #undef FUNCTION_PASS
3838
3939 } // End anonymous namespace.
4040
41 // FIXME: Factor all of the parsing logic into a .def file that we include
42 // under different macros.
4341 static bool isModulePassName(StringRef Name) {
4442 if (Name == "no-op-module") return true;
45 if (Name == "print") return true;
46 if (Name == "print-cg") return true;
43
44 #define MODULE_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
45 #include "PassRegistry.def"
4746
4847 return false;
4948 }
5049
5150 static bool isFunctionPassName(StringRef Name) {
5251 if (Name == "no-op-function") return true;
53 if (Name == "print") return true;
52
53 #define FUNCTION_PASS(NAME, CREATE_PASS) if (Name == NAME) return true;
54 #include "PassRegistry.def"
5455
5556 return false;
5657 }
6061 MPM.addPass(NoOpModulePass());
6162 return true;
6263 }
63 if (Name == "print") {
64 MPM.addPass(PrintModulePass(dbgs()));
65 return true;
66 }
67 if (Name == "print-cg") {
68 MPM.addPass(LazyCallGraphPrinterPass(dbgs()));
69 return true;
70 }
64
65 #define MODULE_PASS(NAME, CREATE_PASS) \
66 if (Name == NAME) { \
67 MPM.addPass(CREATE_PASS); \
68 return true; \
69 }
70 #include "PassRegistry.def"
71
7172 return false;
7273 }
7374
7677 FPM.addPass(NoOpFunctionPass());
7778 return true;
7879 }
79 if (Name == "print") {
80 FPM.addPass(PrintFunctionPass(dbgs()));
81 return true;
82 }
80
81 #define FUNCTION_PASS(NAME, CREATE_PASS) \
82 if (Name == NAME) { \
83 FPM.addPass(CREATE_PASS); \
84 return true; \
85 }
86 #include "PassRegistry.def"
87
8388 return false;
8489 }
8590