From ff4b76d74f38a3816495c9914789e87a95525cf4 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Wed, 16 Dec 2020 13:17:24 +0100 Subject: [PATCH] [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 --- clang/include/clang/Driver/Options.td | 23 +++++++++++++------ clang/lib/Frontend/CompilerInvocation.cpp | 38 +++++++++++-------------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7275e84..b92244f 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; def march_EQ : Joined<["-"], "march=">, Group, Flags<[CoreOption]>; def masm_EQ : Joined<["-"], "masm=">, Group, Flags<[NoXarchOption]>; -def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group, Flags<[CC1Option]>; +def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group, Flags<[CC1Option]>, + MarshallingInfoString<"TargetOpts->CodeModel", [{"default"}]>; def mtls_size_EQ : Joined<["-"], "mtls-size=">, 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, Fl def mthread_model : Separate<["-"], "mthread-model">, Group, Flags<[CC1Option]>, HelpText<"The thread model to use, e.g. posix, single (posix by default)">, Values<"posix,single">; def meabi : Separate<["-"], "meabi">, 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; def mno_global_merge : Flag<["-"], "mno-global-merge">, 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; 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 f7bb230..ea0cc74 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -244,10 +244,10 @@ static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt, return None; } -static void denormalizeSimpleEnum(SmallVectorImpl &Args, - const char *Spelling, - CompilerInvocation::StringAllocator SA, - unsigned TableIndex, unsigned Value) { +static void denormalizeSimpleEnumImpl(SmallVectorImpl &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 &Args, } } +template +static void denormalizeSimpleEnum(SmallVectorImpl &Args, + const char *Spelling, + CompilerInvocation::StringAllocator SA, + unsigned TableIndex, T Value) { + return denormalizeSimpleEnumImpl(Args, Spelling, SA, TableIndex, + static_cast(Value)); +} + static void denormalizeSimpleEnumJoined(SmallVectorImpl &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(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, -- 2.7.4