[llvm-commits] CVS: llvm/include/llvm/Support/CommandLine.h PassNameParser.h

Chris Lattner sabre at nondot.org
Fri Apr 6 14:07:17 PDT 2007



Changes in directory llvm/include/llvm/Support:

CommandLine.h updated: 1.62 -> 1.63
PassNameParser.h updated: 1.16 -> 1.17
---
Log message:

rearchitect the registration mechanism used by the command line option stuff.
This dramatically reduce the amount of memory allocated by the commandline stuff
at static init time, changing it to build local data structures when ParseCommandLineOptions
is called.  In a dummy empty program that links some llvm libraries, this reduces
the number of malloc'd bytes from 4864 to 3360 on entry to main.  Most of that
memory is now allocated by non-commandline related stuff.



---
Diffs of the changes:  (+38 -21)

 CommandLine.h    |   58 ++++++++++++++++++++++++++++++++++++-------------------
 PassNameParser.h |    1 
 2 files changed, 38 insertions(+), 21 deletions(-)


Index: llvm/include/llvm/Support/CommandLine.h
diff -u llvm/include/llvm/Support/CommandLine.h:1.62 llvm/include/llvm/Support/CommandLine.h:1.63
--- llvm/include/llvm/Support/CommandLine.h:1.62	Fri Apr  6 13:36:18 2007
+++ llvm/include/llvm/Support/CommandLine.h	Fri Apr  6 16:06:55 2007
@@ -142,16 +142,18 @@
   virtual enum ValueExpected getValueExpectedFlagDefault() const {
     return ValueOptional;
   }
+  
   // Out of line virtual function to provide home for the class.
   virtual void anchor();
   
-  int NumOccurrences;   // The number of times specified
-  int Flags;            // Flags for the argument
-  unsigned Position;    // Position of last occurrence of the option
-public:
-  const char *ArgStr;   // The argument string itself (ex: "help", "o")
-  const char *HelpStr;  // The descriptive text message for --help
-  const char *ValueStr; // String describing what the value of this option is
+  int NumOccurrences;     // The number of times specified
+  int Flags;              // Flags for the argument
+  unsigned Position;      // Position of last occurrence of the option
+  Option *NextRegistered; // Singly linked list of registered options.
+public:
+  const char *ArgStr;     // The argument string itself (ex: "help", "o")
+  const char *HelpStr;    // The descriptive text message for --help
+  const char *ValueStr;   // String describing what the value of this option is
 
   inline enum NumOccurrences getNumOccurrencesFlag() const {
     return static_cast<enum NumOccurrences>(Flags & OccurrencesMask);
@@ -198,16 +200,17 @@
 protected:
   Option(unsigned DefaultFlags)
     : NumOccurrences(0), Flags(DefaultFlags | NormalFormatting), Position(0),
-      ArgStr(""), HelpStr(""), ValueStr("") {
+      NextRegistered(0), ArgStr(""), HelpStr(""), ValueStr("") {
     assert(getNumOccurrencesFlag() != 0 &&
            getOptionHiddenFlag() != 0 && "Not all default flags specified!");
   }
 
 public:
-  // addArgument - Tell the system that this Option subclass will handle all
-  // occurrences of -ArgStr on the command line.
+  // addArgument - Register this argument with the commandline system.
   //
-  void addArgument(const char *ArgStr);
+  void addArgument();
+  
+  Option *getNextRegisteredOption() const { return NextRegistered; }
 
   // Return the width of the option tag for printing...
   virtual unsigned getOptionWidth() const = 0;
@@ -217,6 +220,8 @@
   //
   virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
 
+  virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {}
+  
   // addOccurrence - Wrapper around handleOccurrence that enforces Flags
   //
   bool addOccurrence(unsigned pos, const char *ArgName,
@@ -379,16 +384,18 @@
     // argstr field should be stable, copy it down now.
     //
     hasArgStr = O.hasArgStr();
-
+  }
+  
+  void getExtraOptionNames(std::vector<const char*> &OptionNames) {
     // If there has been no argstr specified, that means that we need to add an
     // argument for every possible option.  This ensures that our options are
     // vectored to us.
-    //
     if (!hasArgStr)
       for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
-        O.addArgument(getOption(i));
+        OptionNames.push_back(getOption(i));
   }
 
+
   enum ValueExpected getValueExpectedFlagDefault() const {
     // If there is an ArgStr specified, then we are of the form:
     //
@@ -483,6 +490,8 @@
     return ValueRequired;
   }
 
+  void getExtraOptionNames(std::vector<const char*> &OptionNames) {}
+
   void initialize(Option &O) {}
 
   // Return the width of the option tag for printing...
@@ -772,6 +781,9 @@
   virtual enum ValueExpected getValueExpectedFlagDefault() const {
     return Parser.getValueExpectedFlagDefault();
   }
+  virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
+    return Parser.getExtraOptionNames(OptionNames);
+  }
 
   // Forward printing stuff to the parser...
   virtual unsigned getOptionWidth() const {return Parser.getOptionWidth(*this);}
@@ -780,7 +792,7 @@
   }
 
   void done() {
-    addArgument(ArgStr);
+    addArgument();
     Parser.initialize(*this);
   }
 public:
@@ -923,7 +935,10 @@
   virtual enum ValueExpected getValueExpectedFlagDefault() const {
     return Parser.getValueExpectedFlagDefault();
   }
-
+  virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
+    return Parser.getExtraOptionNames(OptionNames);
+  }
+  
   virtual bool handleOccurrence(unsigned pos, const char *ArgName,
                                 const std::string &Arg) {
     typename ParserClass::parser_data_type Val =
@@ -943,7 +958,7 @@
   }
 
   void done() {
-    addArgument(ArgStr);
+    addArgument();
     Parser.initialize(*this);
   }
 public:
@@ -1106,7 +1121,10 @@
   virtual enum ValueExpected getValueExpectedFlagDefault() const {
     return Parser.getValueExpectedFlagDefault();
   }
-
+  virtual void getExtraOptionNames(std::vector<const char*> &OptionNames) {
+    return Parser.getExtraOptionNames(OptionNames);
+  }
+  
   virtual bool handleOccurrence(unsigned pos, const char *ArgName,
                                 const std::string &Arg) {
     typename ParserClass::parser_data_type Val =
@@ -1126,7 +1144,7 @@
   }
 
   void done() {
-    addArgument(ArgStr);
+    addArgument();
     Parser.initialize(*this);
   }
 public:
@@ -1221,7 +1239,7 @@
       error(": cl::alias must have argument name specified!");
     if (AliasFor == 0)
       error(": cl::alias must have an cl::aliasopt(option) specified!");
-    addArgument(ArgStr);
+      addArgument();
   }
 public:
   void setAliasFor(Option &O) {


Index: llvm/include/llvm/Support/PassNameParser.h
diff -u llvm/include/llvm/Support/PassNameParser.h:1.16 llvm/include/llvm/Support/PassNameParser.h:1.17
--- llvm/include/llvm/Support/PassNameParser.h:1.16	Wed Dec  6 19:30:31 2006
+++ llvm/include/llvm/Support/PassNameParser.h	Fri Apr  6 16:06:55 2007
@@ -70,7 +70,6 @@
       abort();
     }
     addLiteralOption(P->getPassArgument(), P, P->getPassName());
-    Opt->addArgument(P->getPassArgument());
   }
   virtual void passEnumerate(const PassInfo *P) { passRegistered(P); }
 






More information about the llvm-commits mailing list