[clang] 5e696d8 - [clang][cli] Remove NormalizerRetTy and use the decltype of the KeyPath instead
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 18 02:31:28 PST 2020
Author: Jan Svoboda
Date: 2020-11-18T11:31:13+01:00
New Revision: 5e696d895bde1eb584a9de5c9feba1a98c6bb487
URL: https://github.com/llvm/llvm-project/commit/5e696d895bde1eb584a9de5c9feba1a98c6bb487
DIFF: https://github.com/llvm/llvm-project/commit/5e696d895bde1eb584a9de5c9feba1a98c6bb487.diff
LOG: [clang][cli] Remove NormalizerRetTy and use the decltype of the KeyPath instead
Depends on D83315
Reviewed By: Bigcheese
Original patch by Daniel Grumberg.
Differential Revision: https://reviews.llvm.org/D83406
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/Option/OptParser.td
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index cd5cb37c93cd..01d90a47101b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3639,7 +3639,7 @@ def target_feature : Separate<["-"], "target-feature">,
HelpText<"Target specific attributes">;
def triple : Separate<["-"], "triple">,
HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
- MarshallingInfoString<"TargetOpts->Triple", "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())", "std::string">,
+ MarshallingInfoString<"TargetOpts->Triple", "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
AlwaysEmit, Normalizer<"normalizeTriple">, DenormalizeString;
def target_abi : Separate<["-"], "target-abi">,
HelpText<"Target a particular ABI type">;
@@ -3832,7 +3832,7 @@ def mrelocation_model : Separate<["-"], "mrelocation-model">,
HelpText<"The relocation model to use">, Values<"static,pic,ropi,rwpi,ropi-rwpi,dynamic-no-pic">,
NormalizedValuesScope<"llvm::Reloc">,
NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", "DynamicNoPIC"]>,
- MarshallingInfoString<"CodeGenOpts.RelocationModel", "PIC_", "llvm::Reloc::Model">,
+ MarshallingInfoString<"CodeGenOpts.RelocationModel", "PIC_">,
AutoNormalizeEnum;
def fno_math_builtin : Flag<["-"], "fno-math-builtin">,
HelpText<"Disable implicit builtin knowledge of math functions">;
@@ -4267,7 +4267,7 @@ def arcmt_action_EQ : Joined<["-"], "arcmt-action=">, Flags<[CC1Option, NoDriver
HelpText<"The ARC migration action to take">, Values<"check,modify,migrate">,
NormalizedValuesScope<"FrontendOptions">,
NormalizedValues<["ARCMT_Check", "ARCMT_Modify", "ARCMT_Migrate"]>,
- MarshallingInfoString<"FrontendOpts.ARCMTAction", "ARCMT_None", "unsigned">,
+ MarshallingInfoString<"FrontendOpts.ARCMTAction", "ARCMT_None">,
AutoNormalizeEnumJoined;
def opt_record_file : Separate<["-"], "opt-record-file">,
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 8916fe6a4756..2c54611e4912 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -256,7 +256,7 @@ static Optional<std::string> normalizeTriple(OptSpecifier Opt, int TableIndex,
template <typename T, typename U>
static T mergeForwardValue(T KeyPath, U Value) {
- return static_cast<T>(Value);
+ return Value;
}
template <typename T, typename U> static T mergeMaskValue(T KeyPath, U Value) {
@@ -3773,22 +3773,24 @@ bool CompilerInvocation::parseSimpleArgs(const ArgList &Args,
#define OPTION_WITH_MARSHALLING( \
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
- TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
{ \
this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE); \
if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags)) \
- this->KEYPATH = MERGER(this->KEYPATH, static_cast<TYPE>(*MaybeValue)); \
+ this->KEYPATH = MERGER( \
+ this->KEYPATH, static_cast<decltype(this->KEYPATH)>(*MaybeValue)); \
}
#define OPTION_WITH_MARSHALLING_BOOLEAN( \
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
- TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID, \
+ NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID, \
NEG_SPELLING) \
{ \
if (auto MaybeValue = \
NORMALIZER(OPT_##ID, OPT_##NEG_ID, TABLE_INDEX, Args, Diags)) \
- this->KEYPATH = MERGER(this->KEYPATH, static_cast<TYPE>(*MaybeValue)); \
+ this->KEYPATH = MERGER( \
+ this->KEYPATH, static_cast<decltype(this->KEYPATH)>(*MaybeValue)); \
else \
this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE); \
}
@@ -4048,7 +4050,7 @@ void CompilerInvocation::generateCC1CommandLine(
#define OPTION_WITH_MARSHALLING( \
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
- TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
if (((FLAGS) & options::CC1Option) && \
(ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != (DEFAULT_VALUE))) { \
DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH)); \
@@ -4057,7 +4059,7 @@ void CompilerInvocation::generateCC1CommandLine(
#define OPTION_WITH_MARSHALLING_BOOLEAN( \
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
- TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID, \
+ NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID, \
NEG_SPELLING) \
if (((FLAGS)&options::CC1Option) && \
(ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) { \
diff --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td
index 12d2286ed89d..ea94abdff40a 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -156,20 +156,17 @@ class MarshallingInfo<code keypath, code defaultvalue> {
code DefaultValue = defaultvalue;
}
-class MarshallingInfoString<code keypath, code defaultvalue, code normalizerretty>
- : MarshallingInfo<keypath, defaultvalue> {
- code NormalizerRetTy = normalizerretty;
-}
+class MarshallingInfoString<code keypath, code defaultvalue>
+ : MarshallingInfo<keypath, defaultvalue> {}
-class MarshallingInfoFlag<code keypath, DefaultAnyOf defaults = DefaultAnyOf<[]>, code ty="unsigned">
+class MarshallingInfoFlag<code keypath, DefaultAnyOf defaults = DefaultAnyOf<[]>>
: MarshallingInfo<keypath, defaults.DefaultValue> {
- code NormalizerRetTy = ty;
code Normalizer = "normalizeSimpleFlag";
code Denormalizer = "denormalizeSimpleFlag";
}
class MarshallingInfoBitfieldFlag<code keypath, code value>
- : MarshallingInfoFlag<keypath, DefaultAnyOf<[], "0u", " | ">, "unsigned"> {
+ : MarshallingInfoFlag<keypath, DefaultAnyOf<[], "0u", " | ">> {
code Normalizer = "(normalizeFlagToValue<unsigned, "#value#">)";
code ValueMerger = "mergeMaskValue";
code ValueExtractor = "(extractMaskValue<unsigned, decltype("#value#"), "#value#">)";
diff --git a/llvm/unittests/Option/OptionMarshallingTest.cpp b/llvm/unittests/Option/OptionMarshallingTest.cpp
index e8582f1bbbd0..4b53d047be89 100644
--- a/llvm/unittests/Option/OptionMarshallingTest.cpp
+++ b/llvm/unittests/Option/OptionMarshallingTest.cpp
@@ -18,7 +18,7 @@ static const OptionWithMarshallingInfo MarshallingTable[] = {
#define OPTION_WITH_MARSHALLING( \
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
- TYPE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
+ NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
{NAME, #KEYPATH, #DEFAULT_VALUE},
#include "Opts.inc"
#undef OPTION_WITH_MARSHALLING
diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp
index 4e164fe28353..91d9aeb104fb 100644
--- a/llvm/utils/TableGen/OptParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptParserEmitter.cpp
@@ -71,7 +71,6 @@ class MarshallingInfo {
StringRef KeyPath;
StringRef DefaultValue;
StringRef NormalizedValuesScope;
- StringRef NormalizerRetTy;
StringRef Normalizer;
StringRef Denormalizer;
StringRef ValueMerger;
@@ -114,8 +113,6 @@ struct SimpleEnumValueTable {
OS << ", ";
emitScopedNormalizedValue(OS, DefaultValue);
OS << ", ";
- OS << NormalizerRetTy;
- OS << ", ";
OS << Normalizer;
OS << ", ";
OS << Denormalizer;
@@ -174,9 +171,9 @@ class MarshallingInfoBooleanFlag : public MarshallingInfo {
static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
assert(!isa<UnsetInit>(R.getValueInit("KeyPath")) &&
!isa<UnsetInit>(R.getValueInit("DefaultValue")) &&
- !isa<UnsetInit>(R.getValueInit("NormalizerRetTy")) &&
!isa<UnsetInit>(R.getValueInit("ValueMerger")) &&
- "MarshallingInfo must have a type");
+ "MarshallingInfo must have a provide a keypath, default value and a "
+ "value merger");
MarshallingInfo::Ptr Ret;
StringRef KindString = R.getValueAsString("MarshallingInfoKind");
@@ -191,7 +188,6 @@ static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
Ret->KeyPath = R.getValueAsString("KeyPath");
Ret->DefaultValue = R.getValueAsString("DefaultValue");
Ret->NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
- Ret->NormalizerRetTy = R.getValueAsString("NormalizerRetTy");
Ret->Normalizer = R.getValueAsString("Normalizer");
Ret->Denormalizer = R.getValueAsString("Denormalizer");
More information about the cfe-commits
mailing list