Skip to content

Commit ff4b76d

Browse files
committed
[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
1 parent 9895c70 commit ff4b76d

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,8 @@ def mwatchos_simulator_version_min_EQ : Joined<["-"], "mwatchos-simulator-versio
26902690
def mwatchsimulator_version_min_EQ : Joined<["-"], "mwatchsimulator-version-min=">, Alias<mwatchos_simulator_version_min_EQ>;
26912691
def march_EQ : Joined<["-"], "march=">, Group<m_Group>, Flags<[CoreOption]>;
26922692
def masm_EQ : Joined<["-"], "masm=">, Group<m_Group>, Flags<[NoXarchOption]>;
2693-
def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>, Flags<[CC1Option]>;
2693+
def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>, Flags<[CC1Option]>,
2694+
MarshallingInfoString<"TargetOpts->CodeModel", [{"default"}]>;
26942695
def mtls_size_EQ : Joined<["-"], "mtls-size=">, Group<m_Group>, Flags<[NoXarchOption, CC1Option]>,
26952696
HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
26962697
"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
27602761
def mthread_model : Separate<["-"], "mthread-model">, Group<m_Group>, Flags<[CC1Option]>,
27612762
HelpText<"The thread model to use, e.g. posix, single (posix by default)">, Values<"posix,single">;
27622763
def meabi : Separate<["-"], "meabi">, Group<m_Group>, Flags<[CC1Option]>,
2763-
HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, Values<"default,4,5,gnu">;
2764+
HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, Values<"default,4,5,gnu">,
2765+
MarshallingInfoString<"TargetOpts->EABIVersion", "Default">,
2766+
NormalizedValuesScope<"llvm::EABI">,
2767+
NormalizedValues<["Default", "EABI4", "EABI5", "GNU"]>, AutoNormalizeEnum;
27642768

27652769
def mno_constant_cfstrings : Flag<["-"], "mno-constant-cfstrings">, Group<m_Group>;
27662770
def mno_global_merge : Flag<["-"], "mno-global-merge">, Group<m_Group>, Flags<[CC1Option]>,
@@ -4052,27 +4056,32 @@ let Flags = [CC1Option, NoDriverOption] in {
40524056
let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
40534057

40544058
def target_cpu : Separate<["-"], "target-cpu">,
4055-
HelpText<"Target a specific cpu type">;
4059+
HelpText<"Target a specific cpu type">,
4060+
MarshallingInfoString<"TargetOpts->CPU">;
40564061
def tune_cpu : Separate<["-"], "tune-cpu">,
4057-
HelpText<"Tune for a specific cpu type">;
4062+
HelpText<"Tune for a specific cpu type">,
4063+
MarshallingInfoString<"TargetOpts->TuneCPU">;
40584064
def target_feature : Separate<["-"], "target-feature">,
40594065
HelpText<"Target specific attributes">;
40604066
def triple : Separate<["-"], "triple">,
40614067
HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
40624068
MarshallingInfoString<"TargetOpts->Triple", "llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
40634069
AlwaysEmit, Normalizer<"normalizeTriple">;
40644070
def target_abi : Separate<["-"], "target-abi">,
4065-
HelpText<"Target a particular ABI type">;
4071+
HelpText<"Target a particular ABI type">,
4072+
MarshallingInfoString<"TargetOpts->ABI">;
40664073
def target_sdk_version_EQ : Joined<["-"], "target-sdk-version=">,
40674074
HelpText<"The version of target SDK used for compilation">;
40684075

40694076
}
40704077

40714078
def target_linker_version : Separate<["-"], "target-linker-version">,
4072-
HelpText<"Target linker version">;
4079+
HelpText<"Target linker version">,
4080+
MarshallingInfoString<"TargetOpts->LinkerVersion">;
40734081
def triple_EQ : Joined<["-"], "triple=">, Alias<triple>;
40744082
def mfpmath : Separate<["-"], "mfpmath">,
4075-
HelpText<"Which unit to use for fp math">;
4083+
HelpText<"Which unit to use for fp math">,
4084+
MarshallingInfoString<"TargetOpts->FPMath">;
40764085

40774086
def fpadding_on_unsigned_fixed_point : Flag<["-"], "fpadding-on-unsigned-fixed-point">,
40784087
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">;

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ static llvm::Optional<unsigned> normalizeSimpleEnum(OptSpecifier Opt,
244244
return None;
245245
}
246246

247-
static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
248-
const char *Spelling,
249-
CompilerInvocation::StringAllocator SA,
250-
unsigned TableIndex, unsigned Value) {
247+
static void denormalizeSimpleEnumImpl(SmallVectorImpl<const char *> &Args,
248+
const char *Spelling,
249+
CompilerInvocation::StringAllocator SA,
250+
unsigned TableIndex, unsigned Value) {
251251
assert(TableIndex < SimpleEnumValueTablesSize);
252252
const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
253253
if (auto MaybeEnumVal = findValueTableByValue(Table, Value)) {
@@ -259,6 +259,15 @@ static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
259259
}
260260
}
261261

262+
template <typename T>
263+
static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
264+
const char *Spelling,
265+
CompilerInvocation::StringAllocator SA,
266+
unsigned TableIndex, T Value) {
267+
return denormalizeSimpleEnumImpl(Args, Spelling, SA, TableIndex,
268+
static_cast<unsigned>(Value));
269+
}
270+
262271
static void denormalizeSimpleEnumJoined(SmallVectorImpl<const char *> &Args,
263272
const char *Spelling,
264273
CompilerInvocation::StringAllocator SA,
@@ -3357,28 +3366,7 @@ static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
33573366

33583367
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
33593368
DiagnosticsEngine &Diags) {
3360-
Opts.CodeModel = std::string(Args.getLastArgValue(OPT_mcmodel_EQ, "default"));
3361-
Opts.ABI = std::string(Args.getLastArgValue(OPT_target_abi));
3362-
if (Arg *A = Args.getLastArg(OPT_meabi)) {
3363-
StringRef Value = A->getValue();
3364-
llvm::EABI EABIVersion = llvm::StringSwitch<llvm::EABI>(Value)
3365-
.Case("default", llvm::EABI::Default)
3366-
.Case("4", llvm::EABI::EABI4)
3367-
.Case("5", llvm::EABI::EABI5)
3368-
.Case("gnu", llvm::EABI::GNU)
3369-
.Default(llvm::EABI::Unknown);
3370-
if (EABIVersion == llvm::EABI::Unknown)
3371-
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
3372-
<< Value;
3373-
else
3374-
Opts.EABIVersion = EABIVersion;
3375-
}
3376-
Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu));
3377-
Opts.TuneCPU = std::string(Args.getLastArgValue(OPT_tune_cpu));
3378-
Opts.FPMath = std::string(Args.getLastArgValue(OPT_mfpmath));
33793369
Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature);
3380-
Opts.LinkerVersion =
3381-
std::string(Args.getLastArgValue(OPT_target_linker_version));
33823370
Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
33833371
Opts.AllowAMDGPUUnsafeFPAtomics =
33843372
Args.hasFlag(options::OPT_munsafe_fp_atomics,

0 commit comments

Comments
 (0)