[PATCH] D139274: Store OptTable::Info::Name as a StringRef
serge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 4 09:41:45 PST 2022
serge-sans-paille created this revision.
serge-sans-paille added reviewers: thakis, aaron.ballman, nikic.
Herald added a subscriber: hiraditya.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.
This avoids implicit conversion to StringRef at several points, which in
turns avoid redundant calls to strlen.
It also eventually gives a consistent, humble speedup in compilation
time
https://llvm-compile-time-tracker.com/compare.php?from=5f5b942823474e98e43a27d515a87ce140396c53&to=60e13b778119fc32d50dc38ff1a564a87146e9c6&stat=instructions:u
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D139274
Files:
clang/lib/Driver/ToolChains/Gnu.cpp
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/utils/TableGen/OptParserEmitter.cpp
Index: llvm/utils/TableGen/OptParserEmitter.cpp
===================================================================
--- llvm/utils/TableGen/OptParserEmitter.cpp
+++ llvm/utils/TableGen/OptParserEmitter.cpp
@@ -54,9 +54,9 @@
static void emitNameUsingSpelling(raw_ostream &OS, const Record &R) {
size_t PrefixLength;
- OS << "&";
+ OS << "llvm::StringRef(";
write_cstring(OS, StringRef(getOptionSpelling(R, PrefixLength)));
- OS << "[" << PrefixLength << "]";
+ OS << ").substr(" << PrefixLength << ")";
}
class MarshallingInfo {
Index: llvm/lib/Option/OptTable.cpp
===================================================================
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -87,7 +87,7 @@
// Support lower_bound between info and an option name.
static inline bool operator<(const OptTable::Info &I, const char *Name) {
- return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
+ return StrCmpOptionNameIgnoreCase(I.Name.data(), Name) < 0;
}
} // end namespace opt
@@ -321,7 +321,7 @@
return BestDistance;
}
-bool OptTable::addValues(const char *Option, const char *Values) {
+bool OptTable::addValues(StringRef Option, const char *Values) {
for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
Info &In = OptionInfos[I];
if (optionMatches(In, Option)) {
Index: llvm/include/llvm/Option/OptTable.h
===================================================================
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -44,7 +44,7 @@
/// A null terminated array of prefix strings to apply to name while
/// matching.
const char *const *Prefixes;
- const char *Name;
+ StringRef Name;
const char *HelpText;
const char *MetaVar;
unsigned ID;
@@ -102,9 +102,7 @@
const Option getOption(OptSpecifier Opt) const;
/// Lookup the name of the given option.
- const char *getOptionName(OptSpecifier id) const {
- return getInfo(id).Name;
- }
+ StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
/// Get the kind of the given option.
unsigned getOptionKind(OptSpecifier id) const {
@@ -184,7 +182,7 @@
/// takes
///
/// \return true in success, and false in fail.
- bool addValues(const char *Option, const char *Values);
+ bool addValues(StringRef Option, const char *Values);
/// Parse a single argument; returning the new argument and
/// updating Index.
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -331,8 +331,8 @@
if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
const Driver &D = TC.getDriver();
const llvm::opt::OptTable &Opts = D.getOpts();
- const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
- const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
+ StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+ StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
}
return HasStaticPIE;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139274.479929.patch
Type: text/x-patch
Size: 3229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221204/408b3f3e/attachment-0001.bin>
More information about the cfe-commits
mailing list