diff options
author | David Greene <greened@obbligato.org> | 2007-08-20 19:54:01 +0000 |
---|---|---|
committer | David Greene <greened@obbligato.org> | 2007-08-20 19:54:01 +0000 |
commit | 94c510c63176bf5d43c35886640df25adffd5448 (patch) | |
tree | f8a9e97cf841d69651d552683e420fbee00bc611 /include/llvm/Support/PassNameParser.h | |
parent | 8d1bfad00b1ebff5b140b6e1bd7e26bad697d6e1 (diff) | |
download | external_llvm-94c510c63176bf5d43c35886640df25adffd5448.tar.gz external_llvm-94c510c63176bf5d43c35886640df25adffd5448.tar.bz2 external_llvm-94c510c63176bf5d43c35886640df25adffd5448.zip |
Add FilteredPassNameParser along with PassArgFilter to filter passes
based on their Arg members.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41192 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/PassNameParser.h')
-rw-r--r-- | include/llvm/Support/PassNameParser.h | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/include/llvm/Support/PassNameParser.h b/include/llvm/Support/PassNameParser.h index e87e16a21b..37f0797271 100644 --- a/include/llvm/Support/PassNameParser.h +++ b/include/llvm/Support/PassNameParser.h @@ -24,9 +24,9 @@ #define LLVM_SUPPORT_PASS_NAME_PARSER_H #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Debug.h" #include "llvm/Pass.h" #include <algorithm> +#include <cstring> namespace llvm { @@ -89,6 +89,44 @@ public: } }; -} // End llvm namespace +//===----------------------------------------------------------------------===// +// FilteredPassNameParser class - Make use of the pass registration +// mechanism to automatically add a command line argument to opt for +// each pass that satisfies a filter criteria. Filter should return +// true for passes to be registered as command-line options. +// +template<typename Filter> +class FilteredPassNameParser : public PassNameParser { +private: + Filter filter; +public: + bool ignorablePassImpl(const PassInfo *P) const { return !filter(*P); } +}; + +//===----------------------------------------------------------------------===// +// PassArgFilter - A filter for use with PassNameFilterParser that only +// accepts a Pass whose Arg matches certain strings. +// +// Use like this: +// +// extern const char AllowedPassArgs[] = "-anders_aa -dse"; +// +// static cl::list< +// const PassInfo*, +// bool, +// FilteredPassNameParser<PassArgFilter<AllowedPassArgs> > > +// PassList(cl::desc("LLVM optimizations available:")); +// +// Only the -anders_aa and -dse options will be available to the user. +// +template<const char *Args> +class PassArgFilter { +public: + bool operator()(const PassInfo &P) const { + return(std::strstr(Args, P.getPassArgument())); + } +}; + +} // End llvm namespace #endif |