[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
Sat May 18 12:19:14 PDT 2019
hintonda marked an inline comment as done.
hintonda added inline comments.
================
Comment at: llvm/include/llvm/Support/CommandLine.h:288
Categories; // The Categories this option belongs to
SmallPtrSet<SubCommand *, 4> Subs; // The subcommands this option belongs to.
----------------
hintonda wrote:
> beanz wrote:
> > beanz wrote:
> > > Side note: I wonder how many members actually get put into this. The common-case for most options is surely 0.
> > From eyeballing (not an exhaustive search), I don't see anywhere that more than one Sub command is set. You might be able to save more space by shrinking the inline size here. If I read the code right, SmallPtrSet is 32 bytes + (sizeof (T) * N). In this case that should be 64 bytes. Changing the size to 2, would save another 16 bytes per option.
> Actually, it's empty about 99% or the time and defaults to TopLevelSubCommand at that point. This is how all the options in passes are setup -- well over 1,000. Only a few tools currently use SubCommands -- the most I've seen is 4 by llvm-pdbutil.
>
> So, I was considering something a bit more radical. Instead of each Option keeping track of SubCommand, and Category, membership, why not let the SubCommand's and Category's do it instead?
>
>
So as a quick test, I set both to 1 and reduced the overall size down to 136 bytes -- Categories always has at least 1, but rarely more, and Subs is almost always empty:
```--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -283,9 +283,9 @@ public:
StringRef ArgStr; // The argument string itself (ex: "help", "o")
StringRef HelpStr; // The descriptive text message for -help
StringRef ValueStr; // String describing what the value of this option is
- SmallVector<OptionCategory *, 2>
+ SmallVector<OptionCategory *, 1>
Categories; // The Categories this option belongs to
- SmallPtrSet<SubCommand *, 4> Subs; // The subcommands this option belongs to.
+ SmallPtrSet<SubCommand *, 1> Subs; // The subcommands this option belongs to.
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62091/new/
https://reviews.llvm.org/D62091
More information about the llvm-commits
mailing list