[PATCH] D62091: [CommandLine] Reduce size of Option class by moving more members into bit field

Don Hinton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 17:39:26 PDT 2019


hintonda created this revision.
hintonda added reviewers: dblaikie, beanz.
Herald added a project: LLVM.

Reduce size of Option class from 184 bytes to 168 bytes by
placing more member variables in Bit Field.  Saves about 16k for
bin/opt.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62091

Files:
  llvm/include/llvm/Support/CommandLine.h


Index: llvm/include/llvm/Support/CommandLine.h
===================================================================
--- llvm/include/llvm/Support/CommandLine.h
+++ llvm/include/llvm/Support/CommandLine.h
@@ -265,18 +265,19 @@
   // Out of line virtual function to provide home for the class.
   virtual void anchor();
 
-  int NumOccurrences = 0; // The number of times specified
+  uint64_t NumOccurrences : 16; // The number of times specified
   // Occurrences, HiddenFlag, and Formatting are all enum types but to avoid
   // problems with signed enums in bitfields.
-  unsigned Occurrences : 3; // enum NumOccurrencesFlag
+  uint64_t Occurrences : 3; // enum NumOccurrencesFlag
   // not using the enum type for 'Value' because zero is an implementation
   // detail representing the non-value
-  unsigned Value : 2;
-  unsigned HiddenFlag : 2; // enum OptionHidden
-  unsigned Formatting : 2; // enum FormattingFlags
-  unsigned Misc : 5;
-  unsigned Position = 0;       // Position of last occurrence of the option
-  unsigned AdditionalVals = 0; // Greater than 0 for multi-valued option.
+  uint64_t Value : 2;
+  uint64_t HiddenFlag : 2; // enum OptionHidden
+  uint64_t Formatting : 2; // enum FormattingFlags
+  uint64_t Misc : 5;
+  uint64_t Position : 16;       // Position of last occurrence of the option
+  uint64_t AdditionalVals : 16; // Greater than 0 for multi-valued option.
+  uint64_t FullyInitialized : 1; // Has addArgument been called?
 
 public:
   StringRef ArgStr;   // The argument string itself (ex: "help", "o")
@@ -285,7 +286,6 @@
   SmallVector<OptionCategory *, 2>
       Categories;                    // The Categories this option belongs to
   SmallPtrSet<SubCommand *, 4> Subs; // The subcommands this option belongs to.
-  bool FullyInitialized = false; // Has addArgument been called?
 
   inline enum NumOccurrencesFlag getNumOccurrencesFlag() const {
     return (enum NumOccurrencesFlag)Occurrences;
@@ -341,8 +341,9 @@
 protected:
   explicit Option(enum NumOccurrencesFlag OccurrencesFlag,
                   enum OptionHidden Hidden)
-      : Occurrences(OccurrencesFlag), Value(0), HiddenFlag(Hidden),
-        Formatting(NormalFormatting), Misc(0) {
+      : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0),
+        HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0), Position(0),
+        AdditionalVals(0), FullyInitialized(false) {
     Categories.push_back(&GeneralCategory);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62091.200122.patch
Type: text/x-patch
Size: 2454 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190518/32d4f42d/attachment.bin>


More information about the llvm-commits mailing list