-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][clang] Add Visibility specific help text for options #81869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang Author: David Spickett (DavidSpickett) ChangesAnd use it to print the correct default OpenMP version for flang. This change adds an optional HelpTextForVisibility to options. This allows you to change the help text (shown in documentation and --help) for one specific visibility. It could be generalised to a list, but we only need to pick out flang right now so I've kept it simple but not so simple that it's "if flang else". For example the OpenMP option will show one default value for Clang and another for Flang. Clang will use the existing HelpText string. I have not applied this to group descriptions just because I don't know of one that needs changing. It could easily be enabled for those too if needed. There are minor changes to them just to get it all to compile. This approach of storing many help strings per option in the 1 driver library seemed preferrable to making a whole new library for Flang (even if that would mostly be including stuff from Clang). Patch is 23.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/81869.diff 13 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 53f23f9abb4c96..17004c66841e87 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,10 @@ def fno_openmp : Flag<["-"], "fno-openmp">, Group<f_Group>,
def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group<f_Group>,
Flags<[NoArgumentUnused]>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
- HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang">;
+ HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang">,
+ HelpForVisibility<HelpTextForVisibility<FlangOption,
+ "Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang"
+ >>;
defm openmp_extensions: BoolFOption<"openmp-extensions",
LangOpts<"OpenMPExtensions">, DefaultTrue,
PosFlag<SetTrue, [NoArgumentUnused], [ClangOption, CC1Option],
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index bcb31243056b7e..87e53c421defe3 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -525,10 +525,10 @@ static T extractMaskValue(T KeyPath) {
#define PARSE_OPTION_WITH_MARSHALLING( \
ARGS, DIAGS, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, \
- ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, \
- NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
- if ((VISIBILITY)&options::CC1Option) { \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \
+ IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ if ((VISIBILITY) & options::CC1Option) { \
KEYPATH = MERGER(KEYPATH, DEFAULT_VALUE); \
if (IMPLIED_CHECK) \
KEYPATH = MERGER(KEYPATH, IMPLIED_VALUE); \
@@ -542,10 +542,10 @@ static T extractMaskValue(T KeyPath) {
// with lifetime extension of the reference.
#define GENERATE_OPTION_WITH_MARSHALLING( \
CONSUMER, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, ALWAYS_EMIT, \
- KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \
- DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
- if ((VISIBILITY)&options::CC1Option) { \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUES, \
+ SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \
+ IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ if ((VISIBILITY) & options::CC1Option) { \
[&](const auto &Extracted) { \
if (ALWAYS_EMIT || \
(Extracted != \
diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
index 3fe98909940749..1ad3fcc3d76b82 100644
--- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -359,8 +359,25 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
// Emit the description, if we have one.
const Record *R = Option.Option;
- std::string Description =
- getRSTStringWithTextFallback(R, "DocBrief", "HelpText");
+ std::string Description;
+
+ // Prefer a program specific help string.
+ if (!isa<UnsetInit>(R->getValueInit("HelpTextForVisibility"))) {
+ const Record *VisibilityHelp = R->getValueAsDef("HelpTextForVisibility");
+ std::string VisibilityStr =
+ VisibilityHelp->getValue("Visibility")->getValue()->getAsString();
+
+ for (StringRef Mask : DocInfo->getValueAsListOfStrings("VisibilityMask")) {
+ if (VisibilityStr == Mask) {
+ Description = escapeRST(VisibilityHelp->getValueAsString("Text"));
+ break;
+ }
+ }
+ }
+
+ // If there's not a program specific string, use the default one.
+ if (Description.empty())
+ Description = getRSTStringWithTextFallback(R, "DocBrief", "HelpText");
if (!isa<UnsetInit>(R->getValueInit("Values"))) {
if (!Description.empty() && Description.back() != '.')
diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 44dbac44772b29..94f2f4d1f522ec 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -83,7 +83,7 @@
! CHECK-NEXT: -fopenmp-targets=<value>
! CHECK-NEXT: Specify comma-separated list of triples OpenMP offloading targets to be supported
! CHECK-NEXT: -fopenmp-version=<value>
-! CHECK-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
+! CHECK-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang
! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! CHECK-NEXT: -foptimization-record-file=<file>
! CHECK-NEXT: Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch <arch> options.
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index b4280a454e3128..31bc67e1742482 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -69,7 +69,7 @@
! HELP-NEXT: -fopenmp-targets=<value>
! HELP-NEXT: Specify comma-separated list of triples OpenMP offloading targets to be supported
! HELP-NEXT: -fopenmp-version=<value>
-! HELP-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
+! HELP-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang
! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! HELP-NEXT: -foptimization-record-file=<file>
! HELP-NEXT: Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch <arch> options.
diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index d6f18ecb85b8a8..ea86b8074b146b 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -45,11 +45,21 @@ using namespace lld::macho;
// Create table mapping all options defined in Options.td
static constexpr OptTable::Info optInfo[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index efd643f9a32203..3a1eb082d9df2b 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -69,11 +69,21 @@ enum {
// Create table mapping all options defined in Options.td
static constexpr opt::OptTable::Info infoTable[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 635f19f78b15e6..79dda5a41a4001 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -132,11 +132,21 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
// Create table mapping all options defined in Options.td
static constexpr opt::OptTable::Info optInfo[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td
index 7bbee1da643b8c..67757ad91b8a5d 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -93,6 +93,11 @@ class OptionGroup<string name> {
// Define the option class.
+class HelpTextForVisibility<OptionVisibility visibility, string text> {
+ OptionVisibility Visibility = visibility;
+ string Text = text;
+}
+
class Option<list<string> prefixes, string name, OptionKind kind> {
string EnumName = ?; // Uses the def name if undefined.
list<string> Prefixes = prefixes;
@@ -101,6 +106,7 @@ class Option<list<string> prefixes, string name, OptionKind kind> {
// Used by MultiArg option kind.
int NumArgs = 0;
string HelpText = ?;
+ HelpTextForVisibility HelpTextForVisibility = ?;
string MetaVarName = ?;
string Values = ?;
code ValuesCode = ?;
@@ -155,6 +161,10 @@ class Visibility<list<OptionVisibility> visibility> {
}
class Group<OptionGroup group> { OptionGroup Group = group; }
class HelpText<string text> { string HelpText = text; }
+class HelpForVisibility<HelpTextForVisibility text> {
+ HelpTextForVisibility HelpTextForVisibility = text;
+}
+
class MetaVarName<string name> { string MetaVarName = name; }
class Values<string value> { string Values = value; }
class ValuesCode<code valuecode> { code ValuesCode = valuecode; }
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index bb3b665a16319f..457a46a269c83a 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -58,6 +58,7 @@ class OptTable {
ArrayRef<StringLiteral> Prefixes;
StringLiteral PrefixedName;
const char *HelpText;
+ std::pair<unsigned int, const char *> HelpForVisibility;
const char *MetaVar;
unsigned ID;
unsigned char Kind;
@@ -145,7 +146,18 @@ class OptTable {
/// Get the help text to use to describe this option.
const char *getOptionHelpText(OptSpecifier id) const {
- return getInfo(id).HelpText;
+ return getOptionHelpText(id, Visibility(0));
+ }
+
+ // Get the help text to use to describe this option.
+ // If it has Visibility specific help text and that visibility is in the
+ // visibility mask, use that text instead of the generic text.
+ const char *getOptionHelpText(OptSpecifier id,
+ Visibility VisibilityMask) const {
+ auto Info = getInfo(id);
+ if (VisibilityMask & Info.HelpForVisibility.first)
+ return Info.HelpForVisibility.second;
+ return Info.HelpText;
}
/// Get the meta-variable name to use when describing
@@ -323,7 +335,8 @@ class OptTable {
private:
void internalPrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
bool ShowHidden, bool ShowAllAliases,
- std::function<bool(const Info &)> ExcludeOption) const;
+ std::function<bool(const Info &)> ExcludeOption,
+ Visibility VisibilityMask) const;
};
/// Specialization of OptTable
@@ -358,30 +371,32 @@ class PrecomputedOptTable : public OptTable {
#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
ID_PREFIX##ID
#define LLVM_MAKE_OPT_ID(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
- METAVAR, VALUES) \
- LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(OPT_, PREFIX, PREFIXED_NAME, ID, KIND, \
- GROUP, ALIAS, ALIASARGS, FLAGS, VISIBILITY, \
- PARAM, HELPTEXT, METAVAR, VALUE)
+ HELPTEXTFORVISIBILITY, METAVAR, VALUES) \
+ LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
+ OPT_, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUE)
#define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \
ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
llvm::opt::OptTable::Info { \
- PREFIX, PREFIXED_NAME, HELPTEXT, METAVAR, ID_PREFIX##ID, \
- llvm::opt::Option::KIND##Class, PARAM, FLAGS, VISIBILITY, \
- ID_PREFIX##GROUP, ID_PREFIX##ALIAS, ALIASARGS, VALUES \
+ PREFIX, PREFIXED_NAME, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ ID_PREFIX##ID, llvm::opt::Option::KIND##Class, PARAM, FLAGS, \
+ VISIBILITY, ID_PREFIX##GROUP, ID_PREFIX##ALIAS, ALIASARGS, VALUES \
}
#define LLVM_CONSTRUCT_OPT_INFO(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
- METAVAR, VALUES) \
+ HELPTEXTFORVISIBILITY, METAVAR, VALUES) \
LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \
OPT_, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES)
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUES)
#endif // LLVM_OPTION_OPTTABLE_H
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index cf69f6173b6d41..b8b6b90c253f23 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -710,7 +710,8 @@ void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
OS, Usage, Title, ShowHidden, ShowAllAliases,
[VisibilityMask](const Info &CandidateInfo) -> bool {
return (CandidateInfo.Visibility & VisibilityMask) == 0;
- });
+ },
+ VisibilityMask);
}
void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
@@ -726,13 +727,14 @@ void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
if (CandidateInfo.Flags & FlagsToExclude)
return true;
return false;
- });
+ },
+ Visibility(0));
}
void OptTable::internalPrintHelp(
raw_ostream &OS, const char *Usage, const char *Title, bool ShowHidden,
- bool ShowAllAliases,
- std::function<bool(const Info &)> ExcludeOp...
[truncated]
|
@llvm/pr-subscribers-lld-macho Author: David Spickett (DavidSpickett) ChangesAnd use it to print the correct default OpenMP version for flang. This change adds an optional HelpTextForVisibility to options. This allows you to change the help text (shown in documentation and --help) for one specific visibility. It could be generalised to a list, but we only need to pick out flang right now so I've kept it simple but not so simple that it's "if flang else". For example the OpenMP option will show one default value for Clang and another for Flang. Clang will use the existing HelpText string. I have not applied this to group descriptions just because I don't know of one that needs changing. It could easily be enabled for those too if needed. There are minor changes to them just to get it all to compile. This approach of storing many help strings per option in the 1 driver library seemed preferrable to making a whole new library for Flang (even if that would mostly be including stuff from Clang). Patch is 23.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/81869.diff 13 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 53f23f9abb4c96..17004c66841e87 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,10 @@ def fno_openmp : Flag<["-"], "fno-openmp">, Group<f_Group>,
def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group<f_Group>,
Flags<[NoArgumentUnused]>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
- HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang">;
+ HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang">,
+ HelpForVisibility<HelpTextForVisibility<FlangOption,
+ "Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang"
+ >>;
defm openmp_extensions: BoolFOption<"openmp-extensions",
LangOpts<"OpenMPExtensions">, DefaultTrue,
PosFlag<SetTrue, [NoArgumentUnused], [ClangOption, CC1Option],
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index bcb31243056b7e..87e53c421defe3 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -525,10 +525,10 @@ static T extractMaskValue(T KeyPath) {
#define PARSE_OPTION_WITH_MARSHALLING( \
ARGS, DIAGS, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, \
- ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, \
- NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
- if ((VISIBILITY)&options::CC1Option) { \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \
+ IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ if ((VISIBILITY) & options::CC1Option) { \
KEYPATH = MERGER(KEYPATH, DEFAULT_VALUE); \
if (IMPLIED_CHECK) \
KEYPATH = MERGER(KEYPATH, IMPLIED_VALUE); \
@@ -542,10 +542,10 @@ static T extractMaskValue(T KeyPath) {
// with lifetime extension of the reference.
#define GENERATE_OPTION_WITH_MARSHALLING( \
CONSUMER, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, ALWAYS_EMIT, \
- KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \
- DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
- if ((VISIBILITY)&options::CC1Option) { \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUES, \
+ SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \
+ IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ if ((VISIBILITY) & options::CC1Option) { \
[&](const auto &Extracted) { \
if (ALWAYS_EMIT || \
(Extracted != \
diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
index 3fe98909940749..1ad3fcc3d76b82 100644
--- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -359,8 +359,25 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
// Emit the description, if we have one.
const Record *R = Option.Option;
- std::string Description =
- getRSTStringWithTextFallback(R, "DocBrief", "HelpText");
+ std::string Description;
+
+ // Prefer a program specific help string.
+ if (!isa<UnsetInit>(R->getValueInit("HelpTextForVisibility"))) {
+ const Record *VisibilityHelp = R->getValueAsDef("HelpTextForVisibility");
+ std::string VisibilityStr =
+ VisibilityHelp->getValue("Visibility")->getValue()->getAsString();
+
+ for (StringRef Mask : DocInfo->getValueAsListOfStrings("VisibilityMask")) {
+ if (VisibilityStr == Mask) {
+ Description = escapeRST(VisibilityHelp->getValueAsString("Text"));
+ break;
+ }
+ }
+ }
+
+ // If there's not a program specific string, use the default one.
+ if (Description.empty())
+ Description = getRSTStringWithTextFallback(R, "DocBrief", "HelpText");
if (!isa<UnsetInit>(R->getValueInit("Values"))) {
if (!Description.empty() && Description.back() != '.')
diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 44dbac44772b29..94f2f4d1f522ec 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -83,7 +83,7 @@
! CHECK-NEXT: -fopenmp-targets=<value>
! CHECK-NEXT: Specify comma-separated list of triples OpenMP offloading targets to be supported
! CHECK-NEXT: -fopenmp-version=<value>
-! CHECK-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
+! CHECK-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang
! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! CHECK-NEXT: -foptimization-record-file=<file>
! CHECK-NEXT: Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch <arch> options.
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index b4280a454e3128..31bc67e1742482 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -69,7 +69,7 @@
! HELP-NEXT: -fopenmp-targets=<value>
! HELP-NEXT: Specify comma-separated list of triples OpenMP offloading targets to be supported
! HELP-NEXT: -fopenmp-version=<value>
-! HELP-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
+! HELP-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang
! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! HELP-NEXT: -foptimization-record-file=<file>
! HELP-NEXT: Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch <arch> options.
diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index d6f18ecb85b8a8..ea86b8074b146b 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -45,11 +45,21 @@ using namespace lld::macho;
// Create table mapping all options defined in Options.td
static constexpr OptTable::Info optInfo[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index efd643f9a32203..3a1eb082d9df2b 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -69,11 +69,21 @@ enum {
// Create table mapping all options defined in Options.td
static constexpr opt::OptTable::Info infoTable[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 635f19f78b15e6..79dda5a41a4001 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -132,11 +132,21 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
// Create table mapping all options defined in Options.td
static constexpr opt::OptTable::Info optInfo[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td
index 7bbee1da643b8c..67757ad91b8a5d 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -93,6 +93,11 @@ class OptionGroup<string name> {
// Define the option class.
+class HelpTextForVisibility<OptionVisibility visibility, string text> {
+ OptionVisibility Visibility = visibility;
+ string Text = text;
+}
+
class Option<list<string> prefixes, string name, OptionKind kind> {
string EnumName = ?; // Uses the def name if undefined.
list<string> Prefixes = prefixes;
@@ -101,6 +106,7 @@ class Option<list<string> prefixes, string name, OptionKind kind> {
// Used by MultiArg option kind.
int NumArgs = 0;
string HelpText = ?;
+ HelpTextForVisibility HelpTextForVisibility = ?;
string MetaVarName = ?;
string Values = ?;
code ValuesCode = ?;
@@ -155,6 +161,10 @@ class Visibility<list<OptionVisibility> visibility> {
}
class Group<OptionGroup group> { OptionGroup Group = group; }
class HelpText<string text> { string HelpText = text; }
+class HelpForVisibility<HelpTextForVisibility text> {
+ HelpTextForVisibility HelpTextForVisibility = text;
+}
+
class MetaVarName<string name> { string MetaVarName = name; }
class Values<string value> { string Values = value; }
class ValuesCode<code valuecode> { code ValuesCode = valuecode; }
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index bb3b665a16319f..457a46a269c83a 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -58,6 +58,7 @@ class OptTable {
ArrayRef<StringLiteral> Prefixes;
StringLiteral PrefixedName;
const char *HelpText;
+ std::pair<unsigned int, const char *> HelpForVisibility;
const char *MetaVar;
unsigned ID;
unsigned char Kind;
@@ -145,7 +146,18 @@ class OptTable {
/// Get the help text to use to describe this option.
const char *getOptionHelpText(OptSpecifier id) const {
- return getInfo(id).HelpText;
+ return getOptionHelpText(id, Visibility(0));
+ }
+
+ // Get the help text to use to describe this option.
+ // If it has Visibility specific help text and that visibility is in the
+ // visibility mask, use that text instead of the generic text.
+ const char *getOptionHelpText(OptSpecifier id,
+ Visibility VisibilityMask) const {
+ auto Info = getInfo(id);
+ if (VisibilityMask & Info.HelpForVisibility.first)
+ return Info.HelpForVisibility.second;
+ return Info.HelpText;
}
/// Get the meta-variable name to use when describing
@@ -323,7 +335,8 @@ class OptTable {
private:
void internalPrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
bool ShowHidden, bool ShowAllAliases,
- std::function<bool(const Info &)> ExcludeOption) const;
+ std::function<bool(const Info &)> ExcludeOption,
+ Visibility VisibilityMask) const;
};
/// Specialization of OptTable
@@ -358,30 +371,32 @@ class PrecomputedOptTable : public OptTable {
#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
ID_PREFIX##ID
#define LLVM_MAKE_OPT_ID(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
- METAVAR, VALUES) \
- LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(OPT_, PREFIX, PREFIXED_NAME, ID, KIND, \
- GROUP, ALIAS, ALIASARGS, FLAGS, VISIBILITY, \
- PARAM, HELPTEXT, METAVAR, VALUE)
+ HELPTEXTFORVISIBILITY, METAVAR, VALUES) \
+ LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
+ OPT_, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUE)
#define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \
ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
llvm::opt::OptTable::Info { \
- PREFIX, PREFIXED_NAME, HELPTEXT, METAVAR, ID_PREFIX##ID, \
- llvm::opt::Option::KIND##Class, PARAM, FLAGS, VISIBILITY, \
- ID_PREFIX##GROUP, ID_PREFIX##ALIAS, ALIASARGS, VALUES \
+ PREFIX, PREFIXED_NAME, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ ID_PREFIX##ID, llvm::opt::Option::KIND##Class, PARAM, FLAGS, \
+ VISIBILITY, ID_PREFIX##GROUP, ID_PREFIX##ALIAS, ALIASARGS, VALUES \
}
#define LLVM_CONSTRUCT_OPT_INFO(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
- METAVAR, VALUES) \
+ HELPTEXTFORVISIBILITY, METAVAR, VALUES) \
LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \
OPT_, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES)
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUES)
#endif // LLVM_OPTION_OPTTABLE_H
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index cf69f6173b6d41..b8b6b90c253f23 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -710,7 +710,8 @@ void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
OS, Usage, Title, ShowHidden, ShowAllAliases,
[VisibilityMask](const Info &CandidateInfo) -> bool {
return (CandidateInfo.Visibility & VisibilityMask) == 0;
- });
+ },
+ VisibilityMask);
}
void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
@@ -726,13 +727,14 @@ void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
if (CandidateInfo.Flags & FlagsToExclude)
return true;
return false;
- });
+ },
+ Visibility(0));
}
void OptTable::internalPrintHelp(
raw_ostream &OS, const char *Usage, const char *Title, bool ShowHidden,
- bool ShowAllAliases,
- std::function<bool(const Info &)> ExcludeOp...
[truncated]
|
@llvm/pr-subscribers-lld Author: David Spickett (DavidSpickett) ChangesAnd use it to print the correct default OpenMP version for flang. This change adds an optional HelpTextForVisibility to options. This allows you to change the help text (shown in documentation and --help) for one specific visibility. It could be generalised to a list, but we only need to pick out flang right now so I've kept it simple but not so simple that it's "if flang else". For example the OpenMP option will show one default value for Clang and another for Flang. Clang will use the existing HelpText string. I have not applied this to group descriptions just because I don't know of one that needs changing. It could easily be enabled for those too if needed. There are minor changes to them just to get it all to compile. This approach of storing many help strings per option in the 1 driver library seemed preferrable to making a whole new library for Flang (even if that would mostly be including stuff from Clang). Patch is 23.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/81869.diff 13 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 53f23f9abb4c96..17004c66841e87 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,10 @@ def fno_openmp : Flag<["-"], "fno-openmp">, Group<f_Group>,
def fopenmp_version_EQ : Joined<["-"], "fopenmp-version=">, Group<f_Group>,
Flags<[NoArgumentUnused]>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
- HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang">;
+ HelpText<"Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang">,
+ HelpForVisibility<HelpTextForVisibility<FlangOption,
+ "Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang"
+ >>;
defm openmp_extensions: BoolFOption<"openmp-extensions",
LangOpts<"OpenMPExtensions">, DefaultTrue,
PosFlag<SetTrue, [NoArgumentUnused], [ClangOption, CC1Option],
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index bcb31243056b7e..87e53c421defe3 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -525,10 +525,10 @@ static T extractMaskValue(T KeyPath) {
#define PARSE_OPTION_WITH_MARSHALLING( \
ARGS, DIAGS, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, \
- ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, \
- NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
- if ((VISIBILITY)&options::CC1Option) { \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \
+ IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ if ((VISIBILITY) & options::CC1Option) { \
KEYPATH = MERGER(KEYPATH, DEFAULT_VALUE); \
if (IMPLIED_CHECK) \
KEYPATH = MERGER(KEYPATH, IMPLIED_VALUE); \
@@ -542,10 +542,10 @@ static T extractMaskValue(T KeyPath) {
// with lifetime extension of the reference.
#define GENERATE_OPTION_WITH_MARSHALLING( \
CONSUMER, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, ALWAYS_EMIT, \
- KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \
- DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
- if ((VISIBILITY)&options::CC1Option) { \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUES, \
+ SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \
+ IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ if ((VISIBILITY) & options::CC1Option) { \
[&](const auto &Extracted) { \
if (ALWAYS_EMIT || \
(Extracted != \
diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
index 3fe98909940749..1ad3fcc3d76b82 100644
--- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -359,8 +359,25 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
// Emit the description, if we have one.
const Record *R = Option.Option;
- std::string Description =
- getRSTStringWithTextFallback(R, "DocBrief", "HelpText");
+ std::string Description;
+
+ // Prefer a program specific help string.
+ if (!isa<UnsetInit>(R->getValueInit("HelpTextForVisibility"))) {
+ const Record *VisibilityHelp = R->getValueAsDef("HelpTextForVisibility");
+ std::string VisibilityStr =
+ VisibilityHelp->getValue("Visibility")->getValue()->getAsString();
+
+ for (StringRef Mask : DocInfo->getValueAsListOfStrings("VisibilityMask")) {
+ if (VisibilityStr == Mask) {
+ Description = escapeRST(VisibilityHelp->getValueAsString("Text"));
+ break;
+ }
+ }
+ }
+
+ // If there's not a program specific string, use the default one.
+ if (Description.empty())
+ Description = getRSTStringWithTextFallback(R, "DocBrief", "HelpText");
if (!isa<UnsetInit>(R->getValueInit("Values"))) {
if (!Description.empty() && Description.back() != '.')
diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 44dbac44772b29..94f2f4d1f522ec 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -83,7 +83,7 @@
! CHECK-NEXT: -fopenmp-targets=<value>
! CHECK-NEXT: Specify comma-separated list of triples OpenMP offloading targets to be supported
! CHECK-NEXT: -fopenmp-version=<value>
-! CHECK-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
+! CHECK-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang
! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! CHECK-NEXT: -foptimization-record-file=<file>
! CHECK-NEXT: Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch <arch> options.
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index b4280a454e3128..31bc67e1742482 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -69,7 +69,7 @@
! HELP-NEXT: -fopenmp-targets=<value>
! HELP-NEXT: Specify comma-separated list of triples OpenMP offloading targets to be supported
! HELP-NEXT: -fopenmp-version=<value>
-! HELP-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 51 for Clang
+! HELP-NEXT: Set OpenMP version (e.g. 45 for OpenMP 4.5, 51 for OpenMP 5.1). Default value is 11 for Flang
! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! HELP-NEXT: -foptimization-record-file=<file>
! HELP-NEXT: Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch <arch> options.
diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index d6f18ecb85b8a8..ea86b8074b146b 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -45,11 +45,21 @@ using namespace lld::macho;
// Create table mapping all options defined in Options.td
static constexpr OptTable::Info optInfo[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index efd643f9a32203..3a1eb082d9df2b 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -69,11 +69,21 @@ enum {
// Create table mapping all options defined in Options.td
static constexpr opt::OptTable::Info infoTable[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 635f19f78b15e6..79dda5a41a4001 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -132,11 +132,21 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
// Create table mapping all options defined in Options.td
static constexpr opt::OptTable::Info optInfo[] = {
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
- {PREFIX, NAME, HELPTEXT, \
- METAVAR, OPT_##ID, opt::Option::KIND##Class, \
- PARAM, FLAGS, VISIBILITY, \
- OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
+ {PREFIX, \
+ NAME, \
+ HELPTEXT, \
+ HELPTEXTFORVISIBILITY, \
+ METAVAR, \
+ OPT_##ID, \
+ opt::Option::KIND##Class, \
+ PARAM, \
+ FLAGS, \
+ VISIBILITY, \
+ OPT_##GROUP, \
+ OPT_##ALIAS, \
+ ALIASARGS, \
VALUES},
#include "Options.inc"
#undef OPTION
diff --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td
index 7bbee1da643b8c..67757ad91b8a5d 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -93,6 +93,11 @@ class OptionGroup<string name> {
// Define the option class.
+class HelpTextForVisibility<OptionVisibility visibility, string text> {
+ OptionVisibility Visibility = visibility;
+ string Text = text;
+}
+
class Option<list<string> prefixes, string name, OptionKind kind> {
string EnumName = ?; // Uses the def name if undefined.
list<string> Prefixes = prefixes;
@@ -101,6 +106,7 @@ class Option<list<string> prefixes, string name, OptionKind kind> {
// Used by MultiArg option kind.
int NumArgs = 0;
string HelpText = ?;
+ HelpTextForVisibility HelpTextForVisibility = ?;
string MetaVarName = ?;
string Values = ?;
code ValuesCode = ?;
@@ -155,6 +161,10 @@ class Visibility<list<OptionVisibility> visibility> {
}
class Group<OptionGroup group> { OptionGroup Group = group; }
class HelpText<string text> { string HelpText = text; }
+class HelpForVisibility<HelpTextForVisibility text> {
+ HelpTextForVisibility HelpTextForVisibility = text;
+}
+
class MetaVarName<string name> { string MetaVarName = name; }
class Values<string value> { string Values = value; }
class ValuesCode<code valuecode> { code ValuesCode = valuecode; }
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index bb3b665a16319f..457a46a269c83a 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -58,6 +58,7 @@ class OptTable {
ArrayRef<StringLiteral> Prefixes;
StringLiteral PrefixedName;
const char *HelpText;
+ std::pair<unsigned int, const char *> HelpForVisibility;
const char *MetaVar;
unsigned ID;
unsigned char Kind;
@@ -145,7 +146,18 @@ class OptTable {
/// Get the help text to use to describe this option.
const char *getOptionHelpText(OptSpecifier id) const {
- return getInfo(id).HelpText;
+ return getOptionHelpText(id, Visibility(0));
+ }
+
+ // Get the help text to use to describe this option.
+ // If it has Visibility specific help text and that visibility is in the
+ // visibility mask, use that text instead of the generic text.
+ const char *getOptionHelpText(OptSpecifier id,
+ Visibility VisibilityMask) const {
+ auto Info = getInfo(id);
+ if (VisibilityMask & Info.HelpForVisibility.first)
+ return Info.HelpForVisibility.second;
+ return Info.HelpText;
}
/// Get the meta-variable name to use when describing
@@ -323,7 +335,8 @@ class OptTable {
private:
void internalPrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
bool ShowHidden, bool ShowAllAliases,
- std::function<bool(const Info &)> ExcludeOption) const;
+ std::function<bool(const Info &)> ExcludeOption,
+ Visibility VisibilityMask) const;
};
/// Specialization of OptTable
@@ -358,30 +371,32 @@ class PrecomputedOptTable : public OptTable {
#define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
ID_PREFIX##ID
#define LLVM_MAKE_OPT_ID(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
- METAVAR, VALUES) \
- LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(OPT_, PREFIX, PREFIXED_NAME, ID, KIND, \
- GROUP, ALIAS, ALIASARGS, FLAGS, VISIBILITY, \
- PARAM, HELPTEXT, METAVAR, VALUE)
+ HELPTEXTFORVISIBILITY, METAVAR, VALUES) \
+ LLVM_MAKE_OPT_ID_WITH_ID_PREFIX( \
+ OPT_, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUE)
#define LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \
ID_PREFIX, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
- FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
+ FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ VALUES) \
llvm::opt::OptTable::Info { \
- PREFIX, PREFIXED_NAME, HELPTEXT, METAVAR, ID_PREFIX##ID, \
- llvm::opt::Option::KIND##Class, PARAM, FLAGS, VISIBILITY, \
- ID_PREFIX##GROUP, ID_PREFIX##ALIAS, ALIASARGS, VALUES \
+ PREFIX, PREFIXED_NAME, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, \
+ ID_PREFIX##ID, llvm::opt::Option::KIND##Class, PARAM, FLAGS, \
+ VISIBILITY, ID_PREFIX##GROUP, ID_PREFIX##ALIAS, ALIASARGS, VALUES \
}
#define LLVM_CONSTRUCT_OPT_INFO(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, \
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
- METAVAR, VALUES) \
+ HELPTEXTFORVISIBILITY, METAVAR, VALUES) \
LLVM_CONSTRUCT_OPT_INFO_WITH_ID_PREFIX( \
OPT_, PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
- VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES)
+ VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVISIBILITY, METAVAR, VALUES)
#endif // LLVM_OPTION_OPTTABLE_H
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index cf69f6173b6d41..b8b6b90c253f23 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -710,7 +710,8 @@ void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
OS, Usage, Title, ShowHidden, ShowAllAliases,
[VisibilityMask](const Info &CandidateInfo) -> bool {
return (CandidateInfo.Visibility & VisibilityMask) == 0;
- });
+ },
+ VisibilityMask);
}
void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
@@ -726,13 +727,14 @@ void OptTable::printHelp(raw_ostream &OS, const char *Usage, const char *Title,
if (CandidateInfo.Flags & FlagsToExclude)
return true;
return false;
- });
+ },
+ Visibility(0));
}
void OptTable::internalPrintHelp(
raw_ostream &OS, const char *Usage, const char *Title, bool ShowHidden,
- bool ShowAllAliases,
- std::function<bool(const Info &)> ExcludeOp...
[truncated]
|
This is a bit of an RFC given that there's only one flang option that requires this that I know of. So this could be too much complication now. Since I was in the area I figured I'd try it anyway, we can always attach this to an issue for later use if necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be useful, to make it possible to customize flang help messages, even though only one flang option requires it at the moment.
And use it to print the correct default OpenMP version for flang. This change adds an optional HelpTextForVisibility to options. This allows you to change the help text (shown in documentation and --help) for one specific visibility. It could be generalised to a list, but we only need to pick out flang right now so I've kept it simple but not so simple that it's "if flang else". For example the OpenMP option will show one default value for Clang and another for Flang. Clang will use the existing HelpText string. I have not applied this to group descriptions just because I don't know of one that needs changing. It could easily be enabled for those too if needed. There are minor changes to them just to get it all to compile. This approach of storing many help strings per option in the 1 driver library seemed perferrable to making a whole new library for Flang (even if that would mostly be including stuff from Clang).
0e864bf
to
f53898a
Compare
@banach-space Your thoughts as the Flang driver owner? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
I've been thinking about something similar for a while now, but I've never had the cycles to try implementing it. Thanks for working on this! The OpenMP option is an excellent example for "why" to do this. I don't expect that many options requiring this, but IMHO that's secondary. The "help" text should be accurate and this feels like the only way to achieve this.
While you are here, I would consider looking into DocBrief
. This one in particular:
That's another place that would benefit from something similar.
I'm a bit short on spare cycles for reviewing stuff :( @luporl , do you have time to go over this? I'll bump this on my list regardless.
@banach-space, yes, I can go over this in more details. |
I've also tested this with increased array sizes. You can check the .inc files to see that they are intialised properly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for addressing all my comments!
And use it to print the correct default OpenMP version for flang and flang -fc1.
This change adds an optional
HelpTextsForVariants
to options. This allows you to change the help text that gets shown in documentation and--help
based on the program its being generated for.As
OptTable
needs to be constexpr compatible, I have used a std::array of help text variants. Each entry is:(list of visibilities) - > help text string
So for the OpenMP version we have (flang, fc1) -> "OpenMP version for flang is...".
So you can have multiple visibilities use the same string. The number of entries is currently set to 1, and the number of visibilities per entry is 2, because that's the maximum we need for now. The code is written so we can increase these numbers
later, and the unused elements will be initialised.
I have not applied this to group descriptions just because I don't know of one that needs changing. It could easily be enabled for those too if needed. There are minor changes to them just to get it all to compile.
This approach of storing many help strings per option in the 1 driver library seemed preferable to making a whole new library for Flang (even if that would mostly be including stuff from Clang).