[llvm-branch-commits] [clang] ff4b76d - [clang][cli] Port TargetOpts simple string based options to new option parsing system
Jan Svoboda via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Dec 18 00:45:32 PST 2020
Author: Jan Svoboda
Date: 2020-12-18T09:40:56+01:00
New Revision: ff4b76d74f38a3816495c9914789e87a95525cf4
URL: https://github.com/llvm/llvm-project/commit/ff4b76d74f38a3816495c9914789e87a95525cf4
DIFF: https://github.com/llvm/llvm-project/commit/ff4b76d74f38a3816495c9914789e87a95525cf4.diff
LOG: [clang][cli] Port TargetOpts simple string based options to new option parsing system
Depends on D84190
Reviewed By: Bigcheese
Original patch by Daniel Grumberg.
Differential Revision: https://reviews.llvm.org/D84668
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 7275e84d7c53..b92244fd2f18 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2690,7 +2690,8 @@ def mwatchos_simulator_version_min_EQ : Joined<["-"], "mwatchos-simulator-versio
def mwatchsimulator_version_min_EQ : Joined<["-"], "mwatchsimulator-version-min=">, Alias<mwatchos_simulator_version_min_EQ>;
def march_EQ : Joined<["-"], "march=">, Group<m_Group>, Flags<[CoreOption]>;
def masm_EQ : Joined<["-"], "masm=">, Group<m_Group>, Flags<[NoXarchOption]>;
-def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>, Flags<[CC1Option]>;
+def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>, Flags<[CC1Option]>,
+ MarshallingInfoString<"TargetOpts->CodeModel", [{"default"}]>;
def mtls_size_EQ : Joined<["-"], "mtls-size=">, Group<m_Group>, Flags<[NoXarchOption, CC1Option]>,
HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
"12 (for 4KB) | 24 (for 16MB, default) | 32 (for 4GB) | 48 (for 256TB, needs -mcmodel=large)">;
@@ -2760,7 +2761,10 @@ def mno_stack_arg_probe : Flag<["-"], "mno-stack-arg-probe">, Group<m_Group>, Fl
def mthread_model : Separate<["-"], "mthread-model">, Group<m_Group>, Flags<[CC1Option]>,
HelpText<"The thread model to use, e.g. posix, single (posix by default)">, Values<"posix,single">;
def meabi : Separate<["-"], "meabi">, Group<m_Group>, Flags<[CC1Option]>,
- HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, Values<"default,4,5,gnu">;
+ HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, Values<"default,4,5,gnu">,
+ MarshallingInfoString<"TargetOpts->EABIVersion", "Default">,
+ NormalizedValuesScope<"llvm::EABI">,
+ NormalizedValues<["Default", "EABI4", "EABI5", "GNU"]>, AutoNormalizeEnum;
def mno_constant_cfstrings : Flag<["-"], "mno-constant-cfstrings">, Group<m_Group>;
def mno_global_merge : Flag<["-"], "mno-global-merge">, Group<m_Group>, Flags<[CC1Option]>,
@@ -4052,9 +4056,11 @@ let Flags = [CC1Option, NoDriverOption] in {
let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
def target_cpu : Separate<["-"], "target-cpu">,
- HelpText<"Target a specific cpu type">;
+ HelpText<"Target a specific cpu type">,
+ MarshallingInfoString<"TargetOpts->CPU">;
def tune_cpu : Separate<["-"], "tune-cpu">,
- HelpText<"Tune for a specific cpu type">;
+ HelpText<"Tune for a specific cpu type">,
+ MarshallingInfoString<"TargetOpts->TuneCPU">;
def target_feature : Separate<["-"], "target-feature">,
HelpText<"Target specific attributes">;
def triple : Separate<["-"], "triple">,
@@ -4062,17 +4068,20 @@ def triple : Separate<["-"], "triple">,
MarshallingInfoString<"TargetOpts->Triple", "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
AlwaysEmit, Normalizer<"normalizeTriple">;
def target_abi : Separate<["-"], "target-abi">,
- HelpText<"Target a particular ABI type">;
+ HelpText<"Target a particular ABI type">,
+ MarshallingInfoString<"TargetOpts->ABI">;
def target_sdk_version_EQ : Joined<["-"], "target-sdk-version=">,
HelpText<"The version of target SDK used for compilation">;
}
def target_linker_version : Separate<["-"], "target-linker-version">,
- HelpText<"Target linker version">;
+ HelpText<"Target linker version">,
+ MarshallingInfoString<"TargetOpts->LinkerVersion">;
def triple_EQ : Joined<["-"], "triple=">, Alias<triple>;
def mfpmath : Separate<["-"], "mfpmath">,
- HelpText<"Which unit to use for fp math">;
+ HelpText<"Which unit to use for fp math">,
+ MarshallingInfoString<"TargetOpts->FPMath">;
def fpadding_on_unsigned_fixed_point : Flag<["-"], "fpadding-on-unsigned-fixed-point">,
HelpText<"Force each unsigned fixed point type to have an extra bit of padding to align their scales with those of signed fixed point types">;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index f7bb2308953f..ea0cc74217ff 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -244,10 +244,10 @@ static llvm::Optional<unsigned> normalizeSimpleEnum(OptSpecifier Opt,
return None;
}
-static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
- const char *Spelling,
- CompilerInvocation::StringAllocator SA,
- unsigned TableIndex, unsigned Value) {
+static void denormalizeSimpleEnumImpl(SmallVectorImpl<const char *> &Args,
+ const char *Spelling,
+ CompilerInvocation::StringAllocator SA,
+ unsigned TableIndex, unsigned Value) {
assert(TableIndex < SimpleEnumValueTablesSize);
const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
if (auto MaybeEnumVal = findValueTableByValue(Table, Value)) {
@@ -259,6 +259,15 @@ static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
}
}
+template <typename T>
+static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
+ const char *Spelling,
+ CompilerInvocation::StringAllocator SA,
+ unsigned TableIndex, T Value) {
+ return denormalizeSimpleEnumImpl(Args, Spelling, SA, TableIndex,
+ static_cast<unsigned>(Value));
+}
+
static void denormalizeSimpleEnumJoined(SmallVectorImpl<const char *> &Args,
const char *Spelling,
CompilerInvocation::StringAllocator SA,
@@ -3357,28 +3366,7 @@ static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) {
- Opts.CodeModel = std::string(Args.getLastArgValue(OPT_mcmodel_EQ, "default"));
- Opts.ABI = std::string(Args.getLastArgValue(OPT_target_abi));
- if (Arg *A = Args.getLastArg(OPT_meabi)) {
- StringRef Value = A->getValue();
- llvm::EABI EABIVersion = llvm::StringSwitch<llvm::EABI>(Value)
- .Case("default", llvm::EABI::Default)
- .Case("4", llvm::EABI::EABI4)
- .Case("5", llvm::EABI::EABI5)
- .Case("gnu", llvm::EABI::GNU)
- .Default(llvm::EABI::Unknown);
- if (EABIVersion == llvm::EABI::Unknown)
- Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
- << Value;
- else
- Opts.EABIVersion = EABIVersion;
- }
- Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu));
- Opts.TuneCPU = std::string(Args.getLastArgValue(OPT_tune_cpu));
- Opts.FPMath = std::string(Args.getLastArgValue(OPT_mfpmath));
Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature);
- Opts.LinkerVersion =
- std::string(Args.getLastArgValue(OPT_target_linker_version));
Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
Opts.AllowAMDGPUUnsafeFPAtomics =
Args.hasFlag(options::OPT_munsafe_fp_atomics,
More information about the llvm-branch-commits
mailing list