Go to the documentation of this file.
40 const char *
X = A, *
Y =
B;
41 char a = tolower(*A),
b = tolower(*
B);
56 return (
a <
b) ? -1 : 1;
73 for (
const char *
const *APre = A.Prefixes,
74 *
const *BPre =
B.Prefixes;
75 *APre !=
nullptr && *BPre !=
nullptr; ++APre, ++BPre){
83 "Unexpected classes for options with same name.");
99 : OptionInfos(OptionInfos), IgnoreCase(IgnoreCase) {
107 assert(!InputOptionID &&
"Cannot have multiple input options!");
108 InputOptionID = getInfo(
i + 1).
ID;
110 assert(!UnknownOptionID &&
"Cannot have multiple unknown options!");
111 UnknownOptionID = getInfo(
i + 1).
ID;
113 FirstSearchableIndex =
i;
117 assert(FirstSearchableIndex != 0 &&
"No searchable options?");
126 "Special options should be defined first!");
131 if (!(getInfo(
i) < getInfo(
i + 1))) {
142 if (
const char *
const *
P = getInfo(
i).Prefixes) {
143 for (; *
P !=
nullptr; ++
P) {
151 E = PrefixesUnion.
end();
I !=
E; ++
I) {
155 PrefixChars.push_back(
C);
162 unsigned id = Opt.
getID();
164 return Option(
nullptr,
nullptr);
166 return Option(&getInfo(
id),
this);
173 E = Prefixes.
end();
I !=
E; ++
I)
174 if (
Arg.startswith(
I->getKey()))
182 for (
const char *
const *Pre =
I->Prefixes; *Pre !=
nullptr; ++Pre) {
184 if (Str.startswith(
Prefix)) {
199 for (
size_t I = 0;
In.Prefixes[
I];
I++)
200 if (
Option.endswith(InName))
210 std::vector<std::string>
213 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
214 const Info &
In = OptionInfos[
I];
221 std::vector<std::string> Result;
223 if (Val.startswith(
Arg) &&
Arg.compare(Val))
224 Result.push_back(std::string(Val));
230 std::vector<std::string>
232 std::vector<std::string>
Ret;
233 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
234 const Info &
In = OptionInfos[
I];
235 if (!
In.Prefixes || (!
In.HelpText && !
In.GroupID))
237 if (
In.Flags & DisableFlags)
240 for (
int I = 0;
In.Prefixes[
I];
I++) {
241 std::string
S = std::string(
In.Prefixes[
I]) + std::string(
In.Name) +
"\t";
252 unsigned FlagsToInclude,
unsigned FlagsToExclude,
253 unsigned MinimumLength)
const {
258 unsigned BestDistance = UINT_MAX;
259 for (
const Info &CandidateInfo :
261 StringRef CandidateName = CandidateInfo.Name;
266 if (CandidateName.
empty() || CandidateName.
size() < MinimumLength)
271 if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude))
274 if (CandidateInfo.Flags & FlagsToExclude)
279 if (!CandidateInfo.Prefixes)
286 char Last = CandidateName.
back();
287 bool CandidateHasDelimiter = Last ==
'=' || Last ==
':';
288 std::string NormalizedName = std::string(
Option);
289 if (CandidateHasDelimiter) {
291 NormalizedName = std::string(
LHS);
293 NormalizedName += Last;
300 const char *
const CandidatePrefix = CandidateInfo.Prefixes[
P];
P++) {
301 std::string Candidate = (CandidatePrefix + CandidateName).str();
306 if (
RHS.empty() && CandidateHasDelimiter) {
315 if (Distance < BestDistance) {
316 BestDistance = Distance;
317 NearestString = (Candidate +
RHS).str();
325 for (
size_t I = FirstSearchableIndex,
E = OptionInfos.size();
I <
E;
I++) {
340 unsigned &
Index)
const {
343 const char *CStr =
Args.getArgString(
Index);
345 if (
isInput(PrefixesUnion, Str))
346 return std::make_unique<Arg>(
getOption(InputOptionID), Str,
Index++, CStr);
348 const Info *End = OptionInfos.data() + OptionInfos.size();
351 OptionInfos.data() + FirstSearchableIndex, End,
Name.data());
353 unsigned Prev =
Index;
356 for (; Start != End; ++Start) {
357 unsigned ArgSize =
matchOption(Start, Str, IgnoreCase);
362 if (std::unique_ptr<Arg> A =
381 return std::make_unique<Arg>(
getOption(UnknownOptionID), Str,
Index++,
384 if (std::unique_ptr<Arg> A = Opt.accept(
394 CStr =
Args.MakeArgString(Str.substr(0, 2));
396 return std::make_unique<Arg>(
getOption(UnknownOptionID), CStr,
Index, CStr);
399 return std::make_unique<Arg>(
getOption(UnknownOptionID), Str,
Index++, CStr);
403 unsigned FlagsToInclude,
404 unsigned FlagsToExclude)
const {
405 unsigned Prev =
Index;
406 const char *Str =
Args.getArgString(
Index);
410 if (
isInput(PrefixesUnion, Str))
411 return std::make_unique<Arg>(
getOption(InputOptionID), Str,
Index++, Str);
413 const Info *Start = OptionInfos.data() + FirstSearchableIndex;
414 const Info *End = OptionInfos.data() + OptionInfos.size();
428 for (; Start != End; ++Start) {
429 unsigned ArgSize = 0;
431 for (; Start != End; ++Start)
432 if ((ArgSize =
matchOption(Start, Str, IgnoreCase)))
439 if (FlagsToInclude && !Opt.
hasFlag(FlagsToInclude))
441 if (Opt.
hasFlag(FlagsToExclude))
445 if (std::unique_ptr<Arg> A =
458 return std::make_unique<Arg>(
getOption(InputOptionID), Str,
Index++, Str);
460 return std::make_unique<Arg>(
getOption(UnknownOptionID), Str,
Index++, Str);
464 unsigned &MissingArgIndex,
465 unsigned &MissingArgCount,
466 unsigned FlagsToInclude,
467 unsigned FlagsToExclude)
const {
472 MissingArgIndex = MissingArgCount = 0;
474 while (
Index < End) {
476 if (
Args.getArgString(
Index) ==
nullptr) {
487 unsigned Prev =
Index;
488 std::unique_ptr<Arg> A = GroupedShortOptions
492 "Parser failed to consume argument.");
496 assert(
Index >= End &&
"Unexpected parser error.");
497 assert(
Index - Prev - 1 &&
"No missing arguments!");
498 MissingArgIndex = Prev;
499 MissingArgCount =
Index - Prev - 1;
503 Args.append(A.release());
520 ErrorFn((
Twine(
Args.getArgString(MAI)) +
": missing argument").str());
526 std::string Spelling = A->getAsString(
Args);
528 ErrorFn(
"unknown argument '" + A->getAsString(
Args) +
"'");
530 ErrorFn(
"unknown argument '" + A->getAsString(
Args) +
531 "', did you mean '" + Nearest +
"'?");
538 std::string
Name =
O.getPrefixedName();
541 switch (
O.getKind()) {
553 for (
unsigned i=0,
e=
O.getNumArgs();
i<
e; ++
i) {
589 std::vector<OptionInfo> &OptionHelp) {
590 OS << Title <<
":\n";
593 unsigned OptionFieldWidth = 0;
594 for (
const OptionInfo &Opt : OptionHelp) {
596 unsigned Length = Opt.Name.
size();
598 OptionFieldWidth =
std::max(OptionFieldWidth, Length);
601 const unsigned InitialPad = 2;
602 for (
const OptionInfo &Opt : OptionHelp) {
603 const std::string &
Option = Opt.Name;
604 int Pad = OptionFieldWidth -
int(
Option.size());
610 Pad = OptionFieldWidth + InitialPad;
612 OS.
indent(Pad + 1) << Opt.HelpText <<
'\n';
635 bool ShowHidden,
bool ShowAllAliases)
const {
637 (ShowHidden ? 0 :
HelpHidden), ShowAllAliases);
641 unsigned FlagsToInclude,
unsigned FlagsToExclude,
642 bool ShowAllAliases)
const {
643 OS <<
"OVERVIEW: " << Title <<
"\n\n";
644 OS <<
"USAGE: " << Usage <<
"\n\n";
648 std::map<std::string, std::vector<OptionInfo>> GroupedOptionHelp;
655 unsigned Flags = getInfo(
Id).
Flags;
656 if (FlagsToInclude && !(Flags & FlagsToInclude))
658 if (Flags & FlagsToExclude)
664 if (!HelpText && ShowAllAliases) {
670 if (HelpText && (strlen(HelpText) != 0)) {
673 GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
677 for (
auto& OptionGroup : GroupedOptionHelp) {
678 if (OptionGroup.first != GroupedOptionHelp.begin()->first)
static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool IgnoreCase)
Provide access to the Option info table.
LLVM_NODISCARD char back() const
back - Get the last character in the string.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
const Option getOption(OptSpecifier Opt) const
Get the given Opt's Option instance, lazily creating it if necessary.
This is an optimization pass for GlobalISel generic memory operations.
A concrete instance of a particular driver option.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
ArgList - Ordered collection of driver arguments.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM_NODISCARD StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
void printHelp(raw_ostream &OS, const char *Usage, const char *Title, unsigned FlagsToInclude, unsigned FlagsToExclude, bool ShowAllAliases) const
Render the help text for an option table.
static bool startswith(StringRef Magic, const char(&S)[N])
static bool optionMatches(const OptTable::Info &In, StringRef Option)
InputArgList parseArgs(int Argc, char *const *Argv, OptSpecifier Unknown, StringSaver &Saver, function_ref< void(StringRef)> ErrorFn) const
A convenience helper which handles optional initial options populated from an environment variable,...
unsigned findNearest(StringRef Option, std::string &NearestString, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0, unsigned MinimumLength=4) const
Find the OptTable option that most closely matches the given string.
bool expandResponseFiles(int Argc, const char *const *Argv, const char *EnvVar, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv)
A convenience helper which concatenates the options specified by the environment variable EnvVar and ...
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
std::pair< typename Base::iterator, bool > insert(StringRef key)
std::unique_ptr< Arg > accept(const ArgList &Args, StringRef CurArg, bool GroupedShortOption, unsigned &Index) const
Potentially accept the current argument, returning a new Arg instance, or 0 if the option does not ac...
std::vector< std::string > findByPrefix(StringRef Cur, unsigned int DisableFlags) const
Find flags from OptTable which starts with Cur.
unsigned getOptionKind(OptSpecifier id) const
Get the kind of the given option.
unsigned getOptionGroupID(OptSpecifier id) const
Get the group id for the given option.
=0.0 ? 0.0 :(a > 0.0 ? 1.0 :-1.0) a
static int StrCmpOptionName(const char *A, const char *B)
static const char * getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id)
static void PrintHelpOptionList(raw_ostream &OS, StringRef Title, std::vector< OptionInfo > &OptionHelp)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
(vector float) vec_cmpeq(*A, *B) C
LLVM_NODISCARD bool startswith_insensitive(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
@ RemainingArgsJoinedClass
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int b
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This class implements an extremely fast bulk output stream that can only output to a stream.
Analysis containing CSE Info
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
OptSpecifier - Wrapper class for abstracting references to option IDs.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
An efficient, type-erasing, non-owning reference to a callable.
bool addValues(const char *Option, const char *Values)
Add Values to Option's Values class.
std::unique_ptr< Arg > ParseOneArg(const ArgList &Args, unsigned &Index, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const
Parse a single argument; returning the new argument and updating Index.
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
const char * getOptionMetaVar(OptSpecifier id) const
Get the meta-variable name to use when describing this options values in the help text.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::vector< std::string > suggestValueCompletions(StringRef Option, StringRef Arg) const
Find possible value for given flags.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id)
StringSet - A wrapper for StringMap that provides set-like functionality.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const char * getOptionHelpText(OptSpecifier id) const
Get the help text to use to describe this option.
static bool operator<(const OptTable::Info &A, const OptTable::Info &B)
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
static int StrCmpOptionNameIgnoreCase(const char *A, const char *B)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
InputArgList ParseArgs(ArrayRef< const char * > Args, unsigned &MissingArgIndex, unsigned &MissingArgCount, unsigned FlagsToInclude=0, unsigned FlagsToExclude=0) const
Parse an list of arguments into an InputArgList.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
OptTable(ArrayRef< Info > OptionInfos, bool IgnoreCase=false)
bool hasFlag(unsigned Val) const
Test if this option has the flag Val.
Option - Abstract representation for a single form of driver argument.
static bool isInput(const StringSet<> &Prefixes, StringRef Arg)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
size_t size() const
size - Get the array size.
Entry for a single option instance in the option data table.
LLVM_NODISCARD unsigned edit_distance(StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
const Option getAlias() const
unsigned getNumOptions() const
Return the total number of option classes.