llvm.org GIT mirror llvm / f7591dd
[Modules] Move the PassNameParser to the IR library as it deals in the PassInfo structures of the legacy pass manager. Also give it the Legacy prefix as it is not a particularly widely used header. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202839 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 5 years ago
7 changed file(s) with 144 addition(s) and 141 deletion(s). Raw diff Collapse all Expand all
0 //===- LegacyPassNameParser.h -----------------------------------*- 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 contains the PassNameParser and FilteredPassNameParser<> classes,
10 // which are used to add command line arguments to a utility for all of the
11 // passes that have been registered into the system.
12 //
13 // The PassNameParser class adds ALL passes linked into the system (that are
14 // creatable) as command line arguments to the tool (when instantiated with the
15 // appropriate command line option template). The FilteredPassNameParser<>
16 // template is used for the same purposes as PassNameParser, except that it only
17 // includes passes that have a PassType that are compatible with the filter
18 // (which is the template argument).
19 //
20 // Note that this is part of the legacy pass manager infrastructure and will be
21 // (eventually) going away.
22 //
23 //===----------------------------------------------------------------------===//
24
25 #ifndef LLVM_IR_LEGACYPASSNAMEPARSER_H
26 #define LLVM_IR_LEGACYPASSNAMEPARSER_H
27
28 #include "llvm/ADT/STLExtras.h"
29 #include "llvm/Pass.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/raw_ostream.h"
33 #include
34
35 namespace llvm {
36
37 //===----------------------------------------------------------------------===//
38 // PassNameParser class - Make use of the pass registration mechanism to
39 // automatically add a command line argument to opt for each pass.
40 //
41 class PassNameParser : public PassRegistrationListener,
42 public cl::parser {
43 cl::Option *Opt;
44 public:
45 PassNameParser() : Opt(0) {}
46 virtual ~PassNameParser();
47
48 void initialize(cl::Option &O) {
49 Opt = &O;
50 cl::parser::initialize(O);
51
52 // Add all of the passes to the map that got initialized before 'this' did.
53 enumeratePasses();
54 }
55
56 // ignorablePassImpl - Can be overriden in subclasses to refine the list of
57 // which passes we want to include.
58 //
59 virtual bool ignorablePassImpl(const PassInfo *P) const { return false; }
60
61 inline bool ignorablePass(const PassInfo *P) const {
62 // Ignore non-selectable and non-constructible passes! Ignore
63 // non-optimizations.
64 return P->getPassArgument() == 0 || *P->getPassArgument() == 0 ||
65 P->getNormalCtor() == 0 || ignorablePassImpl(P);
66 }
67
68 // Implement the PassRegistrationListener callbacks used to populate our map
69 //
70 virtual void passRegistered(const PassInfo *P) {
71 if (ignorablePass(P) || !Opt) return;
72 if (findOption(P->getPassArgument()) != getNumOptions()) {
73 errs() << "Two passes with the same argument (-"
74 << P->getPassArgument() << ") attempted to be registered!\n";
75 llvm_unreachable(0);
76 }
77 addLiteralOption(P->getPassArgument(), P, P->getPassName());
78 }
79 virtual void passEnumerate(const PassInfo *P) { passRegistered(P); }
80
81 // printOptionInfo - Print out information about this option. Override the
82 // default implementation to sort the table before we print...
83 virtual void printOptionInfo(const cl::Option &O, size_t GlobalWidth) const {
84 PassNameParser *PNP = const_cast(this);
85 array_pod_sort(PNP->Values.begin(), PNP->Values.end(), ValLessThan);
86 cl::parser::printOptionInfo(O, GlobalWidth);
87 }
88
89 private:
90 // ValLessThan - Provide a sorting comparator for Values elements...
91 static int ValLessThan(const PassNameParser::OptionInfo *VT1,
92 const PassNameParser::OptionInfo *VT2) {
93 return std::strcmp(VT1->Name, VT2->Name);
94 }
95 };
96
97 ///===----------------------------------------------------------------------===//
98 /// FilteredPassNameParser class - Make use of the pass registration
99 /// mechanism to automatically add a command line argument to opt for
100 /// each pass that satisfies a filter criteria. Filter should return
101 /// true for passes to be registered as command-line options.
102 ///
103 template
104 class FilteredPassNameParser : public PassNameParser {
105 private:
106 Filter filter;
107
108 public:
109 bool ignorablePassImpl(const PassInfo *P) const { return !filter(*P); }
110 };
111
112 ///===----------------------------------------------------------------------===//
113 /// PassArgFilter - A filter for use with PassNameFilterParser that only
114 /// accepts a Pass whose Arg matches certain strings.
115 ///
116 /// Use like this:
117 ///
118 /// extern const char AllowedPassArgs[] = "-anders_aa -dse";
119 ///
120 /// static cl::list<
121 /// const PassInfo*,
122 /// bool,
123 /// FilteredPassNameParser > >
124 /// PassList(cl::desc("Passes available:"));
125 ///
126 /// Only the -anders_aa and -dse options will be available to the user.
127 ///
128 template
129 class PassArgFilter {
130 public:
131 bool operator()(const PassInfo &P) const {
132 return(std::strstr(Args, P.getPassArgument()));
133 }
134 };
135
136 } // End llvm namespace
137
138 #endif
+0
-136
include/llvm/Support/PassNameParser.h less more
None //===- llvm/Support/PassNameParser.h ----------------------------*- 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 contains the PassNameParser and FilteredPassNameParser<> classes,
10 // which are used to add command line arguments to a utility for all of the
11 // passes that have been registered into the system.
12 //
13 // The PassNameParser class adds ALL passes linked into the system (that are
14 // creatable) as command line arguments to the tool (when instantiated with the
15 // appropriate command line option template). The FilteredPassNameParser<>
16 // template is used for the same purposes as PassNameParser, except that it only
17 // includes passes that have a PassType that are compatible with the filter
18 // (which is the template argument).
19 //
20 //===----------------------------------------------------------------------===//
21
22 #ifndef LLVM_SUPPORT_PASSNAMEPARSER_H
23 #define LLVM_SUPPORT_PASSNAMEPARSER_H
24
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/Pass.h"
27 #include "llvm/Support/CommandLine.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include
31
32 namespace llvm {
33
34 //===----------------------------------------------------------------------===//
35 // PassNameParser class - Make use of the pass registration mechanism to
36 // automatically add a command line argument to opt for each pass.
37 //
38 class PassNameParser : public PassRegistrationListener,
39 public cl::parser {
40 cl::Option *Opt;
41 public:
42 PassNameParser() : Opt(0) {}
43 virtual ~PassNameParser();
44
45 void initialize(cl::Option &O) {
46 Opt = &O;
47 cl::parser::initialize(O);
48
49 // Add all of the passes to the map that got initialized before 'this' did.
50 enumeratePasses();
51 }
52
53 // ignorablePassImpl - Can be overriden in subclasses to refine the list of
54 // which passes we want to include.
55 //
56 virtual bool ignorablePassImpl(const PassInfo *P) const { return false; }
57
58 inline bool ignorablePass(const PassInfo *P) const {
59 // Ignore non-selectable and non-constructible passes! Ignore
60 // non-optimizations.
61 return P->getPassArgument() == 0 || *P->getPassArgument() == 0 ||
62 P->getNormalCtor() == 0 || ignorablePassImpl(P);
63 }
64
65 // Implement the PassRegistrationListener callbacks used to populate our map
66 //
67 virtual void passRegistered(const PassInfo *P) {
68 if (ignorablePass(P) || !Opt) return;
69 if (findOption(P->getPassArgument()) != getNumOptions()) {
70 errs() << "Two passes with the same argument (-"
71 << P->getPassArgument() << ") attempted to be registered!\n";
72 llvm_unreachable(0);
73 }
74 addLiteralOption(P->getPassArgument(), P, P->getPassName());
75 }
76 virtual void passEnumerate(const PassInfo *P) { passRegistered(P); }
77
78 // printOptionInfo - Print out information about this option. Override the
79 // default implementation to sort the table before we print...
80 virtual void printOptionInfo(const cl::Option &O, size_t GlobalWidth) const {
81 PassNameParser *PNP = const_cast(this);
82 array_pod_sort(PNP->Values.begin(), PNP->Values.end(), ValLessThan);
83 cl::parser::printOptionInfo(O, GlobalWidth);
84 }
85
86 private:
87 // ValLessThan - Provide a sorting comparator for Values elements...
88 static int ValLessThan(const PassNameParser::OptionInfo *VT1,
89 const PassNameParser::OptionInfo *VT2) {
90 return std::strcmp(VT1->Name, VT2->Name);
91 }
92 };
93
94 ///===----------------------------------------------------------------------===//
95 /// FilteredPassNameParser class - Make use of the pass registration
96 /// mechanism to automatically add a command line argument to opt for
97 /// each pass that satisfies a filter criteria. Filter should return
98 /// true for passes to be registered as command-line options.
99 ///
100 template
101 class FilteredPassNameParser : public PassNameParser {
102 private:
103 Filter filter;
104
105 public:
106 bool ignorablePassImpl(const PassInfo *P) const { return !filter(*P); }
107 };
108
109 ///===----------------------------------------------------------------------===//
110 /// PassArgFilter - A filter for use with PassNameFilterParser that only
111 /// accepts a Pass whose Arg matches certain strings.
112 ///
113 /// Use like this:
114 ///
115 /// extern const char AllowedPassArgs[] = "-anders_aa -dse";
116 ///
117 /// static cl::list<
118 /// const PassInfo*,
119 /// bool,
120 /// FilteredPassNameParser > >
121 /// PassList(cl::desc("Passes available:"));
122 ///
123 /// Only the -anders_aa and -dse options will be available to the user.
124 ///
125 template
126 class PassArgFilter {
127 public:
128 bool operator()(const PassInfo &P) const {
129 return(std::strstr(Args, P.getPassArgument()));
130 }
131 };
132
133 } // End llvm namespace
134
135 #endif
1414 #include "llvm/IR/IRPrintingPasses.h"
1515 #include "llvm/IR/LegacyPassManager.h"
1616 #include "llvm/IR/LegacyPassManagers.h"
17 #include "llvm/IR/LegacyPassNameParser.h"
1718 #include "llvm/IR/Module.h"
1819 #include "llvm/Support/CommandLine.h"
1920 #include "llvm/Support/Debug.h"
2021 #include "llvm/Support/ErrorHandling.h"
2122 #include "llvm/Support/ManagedStatic.h"
2223 #include "llvm/Support/Mutex.h"
23 #include "llvm/Support/PassNameParser.h"
2424 #include "llvm/Support/Timer.h"
2525 #include "llvm/Support/raw_ostream.h"
2626 #include
1515 #include "llvm/Pass.h"
1616 #include "llvm/IR/Function.h"
1717 #include "llvm/IR/IRPrintingPasses.h"
18 #include "llvm/IR/LegacyPassNameParser.h"
1819 #include "llvm/PassRegistry.h"
1920 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/PassNameParser.h"
2121 #include "llvm/Support/raw_ostream.h"
2222 using namespace llvm;
2323
1515 #include "BugDriver.h"
1616 #include "ToolRunner.h"
1717 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/IR/LegacyPassNameParser.h"
1819 #include "llvm/LinkAllIR.h"
1920 #include "llvm/LinkAllPasses.h"
2021 #include "llvm/PassManager.h"
2122 #include "llvm/Support/CommandLine.h"
2223 #include "llvm/Support/ManagedStatic.h"
23 #include "llvm/Support/PassNameParser.h"
2424 #include "llvm/Support/PluginLoader.h"
2525 #include "llvm/Support/PrettyStackTrace.h"
2626 #include "llvm/Support/Process.h"
1616 #include "llvm/IR/IRPrintingPasses.h"
1717 #include "llvm/IR/Instruction.h"
1818 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/IR/LegacyPassNameParser.h"
1920 #include "llvm/IR/Module.h"
2021 #include "llvm/IR/Verifier.h"
2122 #include "llvm/PassManager.h"
2223 #include "llvm/Support/Debug.h"
2324 #include "llvm/Support/ManagedStatic.h"
24 #include "llvm/Support/PassNameParser.h"
2525 #include "llvm/Support/PluginLoader.h"
2626 #include "llvm/Support/PrettyStackTrace.h"
2727 #include "llvm/Support/ToolOutputFile.h"
2424 #include "llvm/IR/DataLayout.h"
2525 #include "llvm/IR/IRPrintingPasses.h"
2626 #include "llvm/IR/LLVMContext.h"
27 #include "llvm/IR/LegacyPassNameParser.h"
2728 #include "llvm/IR/Module.h"
2829 #include "llvm/IR/Verifier.h"
2930 #include "llvm/IRReader/IRReader.h"
3435 #include "llvm/PassManager.h"
3536 #include "llvm/Support/Debug.h"
3637 #include "llvm/Support/ManagedStatic.h"
37 #include "llvm/Support/PassNameParser.h"
3838 #include "llvm/Support/PluginLoader.h"
3939 #include "llvm/Support/PrettyStackTrace.h"
4040 #include "llvm/Support/Signals.h"