[llvm-commits] [llvm] r41192 - /llvm/trunk/include/llvm/Support/PassNameParser.h

David Greene greened at obbligato.org
Mon Aug 20 12:54:03 PDT 2007


Author: greened
Date: Mon Aug 20 14:54:01 2007
New Revision: 41192

URL: http://llvm.org/viewvc/llvm-project?rev=41192&view=rev
Log:

Add FilteredPassNameParser along with PassArgFilter to filter passes
based on their Arg members.



Modified:
    llvm/trunk/include/llvm/Support/PassNameParser.h

Modified: llvm/trunk/include/llvm/Support/PassNameParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PassNameParser.h?rev=41192&r1=41191&r2=41192&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/PassNameParser.h (original)
+++ llvm/trunk/include/llvm/Support/PassNameParser.h Mon Aug 20 14:54:01 2007
@@ -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 @@
   }
 };
 
-} // 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





More information about the llvm-commits mailing list