aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Option/OptTable.cpp
diff options
context:
space:
mode:
authorserge-sans-paille <sguelton@mozilla.com>2022-12-26 09:19:09 +0100
committerserge-sans-paille <sguelton@mozilla.com>2022-12-27 09:55:19 +0100
commitd9ab3e82f30d646deff054230b0c742704a1cf26 (patch)
treebc1265dff45eb195c81b781bd11a1e3edd0e28bb /llvm/lib/Option/OptTable.cpp
parentd065472c9ebca5efea7361c229ead7d5cb6f81b5 (diff)
downloadllvm-d9ab3e82f30d646deff054230b0c742704a1cf26.zip
llvm-d9ab3e82f30d646deff054230b0c742704a1cf26.tar.gz
llvm-d9ab3e82f30d646deff054230b0c742704a1cf26.tar.bz2
[clang] Use a StringRef instead of a raw char pointer to store builtin and call information
This avoids recomputing string length that is already known at compile time. It has a slight impact on preprocessing / compile time, see https://llvm-compile-time-tracker.com/compare.php?from=3f36d2d579d8b0e8824d9dd99bfa79f456858f88&to=e49640c507ddc6615b5e503144301c8e41f8f434&stat=instructions:u This a recommit of e953ae5bbc313fd0cc980ce021d487e5b5199ea4 and the subsequent fixes caa713559bd38f337d7d35de35686775e8fb5175 and 06b90e2e9c991e211fecc97948e533320a825470. The above patchset caused some version of GCC to take eons to compile clang/lib/Basic/Targets/AArch64.cpp, as spotted in aa171833ab0017d9732e82b8682c9848ab25ff9e. The fix is to make BuiltinInfo tables a compilation unit static variable, instead of a private static variable. Differential Revision: https://reviews.llvm.org/D139881
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r--llvm/lib/Option/OptTable.cpp40
1 files changed, 15 insertions, 25 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index 786760f..c21072b 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -62,12 +62,10 @@ static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) {
if (int N = StrCmpOptionName(A.Name, B.Name))
return N < 0;
- for (const char * const *APre = A.Prefixes,
- * const *BPre = B.Prefixes;
- *APre != nullptr && *BPre != nullptr; ++APre, ++BPre){
- if (int N = StrCmpOptionName(*APre, *BPre))
+ for (size_t I = 0, K = std::min(A.Prefixes.size(), B.Prefixes.size()); I != K;
+ ++I)
+ if (int N = StrCmpOptionName(A.Prefixes[I], B.Prefixes[I]))
return N < 0;
- }
// Names are the same, check that classes are in order; exactly one
// should be joined, and it should succeed the other.
@@ -131,11 +129,8 @@ OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase)
// Build prefixes.
for (unsigned i = FirstSearchableIndex + 1, e = getNumOptions() + 1;
i != e; ++i) {
- if (const char *const *P = getInfo(i).Prefixes) {
- for (; *P != nullptr; ++P) {
- PrefixesUnion.insert(*P);
- }
- }
+ const auto &P = getInfo(i).Prefixes;
+ PrefixesUnion.insert(P.begin(), P.end());
}
// Build prefix chars.
@@ -168,8 +163,7 @@ static bool isInput(const StringSet<> &Prefixes, StringRef Arg) {
/// \returns Matched size. 0 means no match.
static unsigned matchOption(const OptTable::Info *I, StringRef Str,
bool IgnoreCase) {
- for (const char * const *Pre = I->Prefixes; *Pre != nullptr; ++Pre) {
- StringRef Prefix(*Pre);
+ for (auto Prefix : I->Prefixes) {
if (Str.startswith(Prefix)) {
StringRef Rest = Str.substr(Prefix.size());
bool Matched = IgnoreCase ? Rest.startswith_insensitive(I->Name)
@@ -183,13 +177,10 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str,
// Returns true if one of the Prefixes + In.Names matches Option
static bool optionMatches(const OptTable::Info &In, StringRef Option) {
- if (In.Prefixes) {
- StringRef InName(In.Name);
- for (size_t I = 0; In.Prefixes[I]; I++)
- if (Option.endswith(InName))
- if (Option.slice(0, Option.size() - InName.size()) == In.Prefixes[I])
- return true;
- }
+ for (auto Prefix : In.Prefixes)
+ if (Option.endswith(In.Name))
+ if (Option.slice(0, Option.size() - In.Name.size()) == Prefix)
+ return true;
return false;
}
@@ -221,13 +212,13 @@ OptTable::findByPrefix(StringRef Cur, unsigned int DisableFlags) const {
std::vector<std::string> Ret;
for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
const Info &In = OptionInfos[I];
- if (!In.Prefixes || (!In.HelpText && !In.GroupID))
+ if (In.Prefixes.empty() || (!In.HelpText && !In.GroupID))
continue;
if (In.Flags & DisableFlags)
continue;
- for (int I = 0; In.Prefixes[I]; I++) {
- std::string S = std::string(In.Prefixes[I]) + std::string(In.Name) + "\t";
+ for (auto Prefix : In.Prefixes) {
+ std::string S = (Prefix + In.Name + "\t").str();
if (In.HelpText)
S += In.HelpText;
if (StringRef(S).startswith(Cur) && S != std::string(Cur) + "\t")
@@ -265,7 +256,7 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
// * Ignore positional argument option candidates (which do not
// have prefixes).
- if (!CandidateInfo.Prefixes)
+ if (CandidateInfo.Prefixes.empty())
continue;
// Now check if the candidate ends with a character commonly used when
@@ -285,8 +276,7 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
// Consider each possible prefix for each candidate to find the most
// appropriate one. For example, if a user asks for "--helm", suggest
// "--help" over "-help".
- for (int P = 0;
- const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) {
+ for (auto CandidatePrefix : CandidateInfo.Prefixes) {
std::string Candidate = (CandidatePrefix + CandidateName).str();
StringRef CandidateRef = Candidate;
unsigned Distance =