Skip to content

Commit 9338f3a

Browse files
committed
[clang][cli] Accept strings instead of options in ImpliedByAnyOf
To be able to refer to constant keypaths (e.g. `defvar cplusplus = LangOpts<"CPlusPlus">`) inside `ImpliedByAnyOf`, let's accept strings instead of `Option` instances. This somewhat weakens the guarantees that we're referring to an existing (option) record, but we can still use the option.KeyPath syntax to simulate this. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D95344
1 parent 956d8e0 commit 9338f3a

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class MigratorOpts<string base>
272272
multiclass OptInFFlag<string name, string pos_prefix, string neg_prefix="",
273273
string help="", list<OptionFlag> flags=[],
274274
KeyPathAndMacro kpm = EmptyKPM,
275-
list<Option> enablers = []> {
275+
list<string> enablers = []> {
276276
def f#NAME : Flag<["-"], "f"#name>, Flags<!listconcat([CC1Option], flags)>,
277277
Group<f_Group>, HelpText<!strconcat(pos_prefix, help)>,
278278
MarshallingInfoFlag<kpm, "false">,
@@ -286,7 +286,7 @@ multiclass OptInFFlag<string name, string pos_prefix, string neg_prefix="",
286286
multiclass OptOutFFlag<string name, string pos_prefix, string neg_prefix,
287287
string help="", list<OptionFlag> flags=[],
288288
KeyPathAndMacro kpm = EmptyKPM,
289-
list<Option> disablers = []> {
289+
list<string> disablers = []> {
290290
def f#NAME : Flag<["-"], "f"#name>, Flags<flags>,
291291
Group<f_Group>, HelpText<!strconcat(pos_prefix, help)>;
292292
def fno_#NAME : Flag<["-"], "fno-"#name>, Flags<!listconcat([CC1Option], flags)>,
@@ -314,7 +314,7 @@ def SetFalse : Set<false> {}
314314
// Definition of single command line flag. This is an implementation detail, use
315315
// SetTrueBy or SetFalseBy instead.
316316
class FlagDef<bit polarity, bit value, list<OptionFlag> option_flags,
317-
string help, list<Option> implied_by_options = []> {
317+
string help, list<code> implied_by_expressions = []> {
318318
// The polarity. Besides spelling, this also decides whether the TableGen
319319
// record will be prefixed with "no_".
320320
bit Polarity = polarity;
@@ -328,8 +328,8 @@ class FlagDef<bit polarity, bit value, list<OptionFlag> option_flags,
328328
// The help text associated with the flag.
329329
string Help = help;
330330

331-
// Options that imply this flag when present on command line.
332-
list<Option> ImpliedBy = implied_by_options;
331+
// List of expressions that, when true, imply this flag.
332+
list<code> ImpliedBy = implied_by_expressions;
333333
}
334334

335335
// Additional information to be appended to both positive and negative flag.
@@ -348,13 +348,13 @@ class ApplySuffix<FlagDef flag, BothFlags suffix> {
348348

349349
// Definition of the command line flag with positive spelling, e.g. "-ffoo".
350350
class PosFlag<Set value, list<OptionFlag> flags = [], string help = "",
351-
list<Option> implied_by_options = []>
352-
: FlagDef<true, value.Value, flags, help, implied_by_options> {}
351+
list<code> implied_by_expressions = []>
352+
: FlagDef<true, value.Value, flags, help, implied_by_expressions> {}
353353

354354
// Definition of the command line flag with negative spelling, e.g. "-fno-foo".
355355
class NegFlag<Set value, list<OptionFlag> flags = [], string help = "",
356-
list<Option> implied_by_options = []>
357-
: FlagDef<false, value.Value, flags, help, implied_by_options> {}
356+
list<code> implied_by_expressions = []>
357+
: FlagDef<false, value.Value, flags, help, implied_by_expressions> {}
358358

359359
// Expanded FlagDef that's convenient for creation of TableGen records.
360360
class FlagDefExpanded<FlagDef flag, string prefix, string name, string spelling>
@@ -790,7 +790,7 @@ def cl_fast_relaxed_math : Flag<["-"], "cl-fast-relaxed-math">, Group<opencl_Gro
790790
def cl_mad_enable : Flag<["-"], "cl-mad-enable">, Group<opencl_Group>, Flags<[CC1Option]>,
791791
HelpText<"OpenCL only. Allow use of less precise MAD computations in the generated binary.">,
792792
MarshallingInfoFlag<CodeGenOpts<"LessPreciseFPMAD">>,
793-
ImpliedByAnyOf<[cl_unsafe_math_optimizations, cl_fast_relaxed_math]>;
793+
ImpliedByAnyOf<[cl_unsafe_math_optimizations.KeyPath, cl_fast_relaxed_math.KeyPath]>;
794794
def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, Group<opencl_Group>, Flags<[CC1Option]>,
795795
HelpText<"OpenCL only. Allow use of less precise no signed zeros computations in the generated binary.">,
796796
MarshallingInfoFlag<LangOpts<"CLNoSignedZero">>;
@@ -1331,11 +1331,11 @@ def ffp_model_EQ : Joined<["-"], "ffp-model=">, Group<f_Group>, Flags<[NoXarchOp
13311331
def ffp_exception_behavior_EQ : Joined<["-"], "ffp-exception-behavior=">, Group<f_Group>, Flags<[CC1Option]>,
13321332
HelpText<"Specifies the exception behavior of floating-point operations.">;
13331333
defm fast_math : OptInFFlag<"fast-math", "Allow aggressive, lossy floating-point optimizations", "", "", [],
1334-
LangOpts<"FastMath">, [cl_fast_relaxed_math]>;
1334+
LangOpts<"FastMath">, [cl_fast_relaxed_math.KeyPath]>;
13351335
def menable_unsafe_fp_math : Flag<["-"], "menable-unsafe-fp-math">, Flags<[CC1Option]>,
13361336
HelpText<"Allow unsafe floating-point math optimizations which may decrease precision">,
13371337
MarshallingInfoFlag<LangOpts<"UnsafeFPMath">>,
1338-
ImpliedByAnyOf<[cl_unsafe_math_optimizations, ffast_math]>;
1338+
ImpliedByAnyOf<[cl_unsafe_math_optimizations.KeyPath, ffast_math.KeyPath]>;
13391339
defm math_errno : OptInFFlag<"math-errno", "Require math functions to indicate errors by setting errno">;
13401340
def fbracket_depth_EQ : Joined<["-"], "fbracket-depth=">, Group<f_Group>, Flags<[CoreOption]>;
13411341
def fsignaling_math : Flag<["-"], "fsignaling-math">, Group<f_Group>;
@@ -1550,15 +1550,15 @@ def fno_unsafe_math_optimizations : Flag<["-"], "fno-unsafe-math-optimizations">
15501550
def fassociative_math : Flag<["-"], "fassociative-math">, Group<f_Group>;
15511551
def fno_associative_math : Flag<["-"], "fno-associative-math">, Group<f_Group>;
15521552
defm reciprocal_math : OptInFFlag<"reciprocal-math", "Allow division operations to be reassociated", "", "", [],
1553-
LangOpts<"AllowRecip">, [menable_unsafe_fp_math]>;
1553+
LangOpts<"AllowRecip">, [menable_unsafe_fp_math.KeyPath]>;
15541554
def fapprox_func : Flag<["-"], "fapprox-func">, Group<f_Group>, Flags<[CC1Option, NoDriverOption]>,
1555-
MarshallingInfoFlag<LangOpts<"ApproxFunc">>, ImpliedByAnyOf<[menable_unsafe_fp_math]>;
1555+
MarshallingInfoFlag<LangOpts<"ApproxFunc">>, ImpliedByAnyOf<[menable_unsafe_fp_math.KeyPath]>;
15561556
defm finite_math_only : OptInFFlag<"finite-math-only", "", "", "", [],
1557-
LangOpts<"FiniteMathOnly">, [cl_finite_math_only, ffast_math]>;
1557+
LangOpts<"FiniteMathOnly">, [cl_finite_math_only.KeyPath, ffast_math.KeyPath]>;
15581558
defm signed_zeros : BoolFOption<"signed-zeros",
15591559
LangOpts<"NoSignedZero">, DefaultFalse,
15601560
NegFlag<SetTrue, [CC1Option], "Allow optimizations that ignore the sign of floating point zeros",
1561-
[cl_no_signed_zeros, menable_unsafe_fp_math]>,
1561+
[cl_no_signed_zeros.KeyPath, menable_unsafe_fp_math.KeyPath]>,
15621562
PosFlag<SetFalse>>;
15631563
def fhonor_nans : Flag<["-"], "fhonor-nans">, Group<f_Group>;
15641564
def fno_honor_nans : Flag<["-"], "fno-honor-nans">, Group<f_Group>;
@@ -4503,13 +4503,13 @@ def mdisable_tail_calls : Flag<["-"], "mdisable-tail-calls">,
45034503
MarshallingInfoFlag<CodeGenOpts<"DisableTailCalls">>;
45044504
def menable_no_infinities : Flag<["-"], "menable-no-infs">,
45054505
HelpText<"Allow optimization to assume there are no infinities.">,
4506-
MarshallingInfoFlag<LangOpts<"NoHonorInfs">>, ImpliedByAnyOf<[ffinite_math_only]>;
4506+
MarshallingInfoFlag<LangOpts<"NoHonorInfs">>, ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
45074507
def menable_no_nans : Flag<["-"], "menable-no-nans">,
45084508
HelpText<"Allow optimization to assume there are no NaNs.">,
4509-
MarshallingInfoFlag<LangOpts<"NoHonorNaNs">>, ImpliedByAnyOf<[ffinite_math_only]>;
4509+
MarshallingInfoFlag<LangOpts<"NoHonorNaNs">>, ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
45104510
def mreassociate : Flag<["-"], "mreassociate">,
45114511
HelpText<"Allow reassociation transformations for floating-point instructions">,
4512-
MarshallingInfoFlag<LangOpts<"AllowFPReassoc">>, ImpliedByAnyOf<[menable_unsafe_fp_math]>;
4512+
MarshallingInfoFlag<LangOpts<"AllowFPReassoc">>, ImpliedByAnyOf<[menable_unsafe_fp_math.KeyPath]>;
45134513
def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
45144514
HelpText<"Use IEEE 754 quadruple-precision for long double">,
45154515
MarshallingInfoFlag<LangOpts<"PPCIEEELongDouble">>;
@@ -5080,7 +5080,7 @@ def fallow_pcm_with_errors : Flag<["-"], "fallow-pcm-with-compiler-errors">,
50805080
def fallow_pch_with_errors : Flag<["-"], "fallow-pch-with-compiler-errors">,
50815081
HelpText<"Accept a PCH file that was created with compiler errors">,
50825082
MarshallingInfoFlag<PreprocessorOpts<"AllowPCHWithCompilerErrors">>,
5083-
ImpliedByAnyOf<[fallow_pcm_with_errors]>;
5083+
ImpliedByAnyOf<[fallow_pcm_with_errors.KeyPath]>;
50845084
def dump_deserialized_pch_decls : Flag<["-"], "dump-deserialized-decls">,
50855085
HelpText<"Dump declarations that are deserialized from PCH, for testing">,
50865086
MarshallingInfoFlag<PreprocessorOpts<"DumpDeserializedPCHDecls">>;

llvm/include/llvm/Option/OptParser.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ class KeyPathAndMacro<string key_path_prefix, string key_path_base,
154154

155155
def EmptyKPM : KeyPathAndMacro<"", "">;
156156

157-
class ImpliedByAnyOf<list<Option> options, code value = "true"> {
158-
code ImpliedCheck = !foldl("false", options, accumulator, option,
159-
!strconcat(accumulator, " || ", option.KeyPath));
157+
class ImpliedByAnyOf<list<string> key_paths, code value = "true"> {
158+
code ImpliedCheck = !foldl("false", key_paths, accumulator, key_path,
159+
!strconcat(accumulator, " || ", key_path));
160160
code ImpliedValue = value;
161161
}
162162

llvm/unittests/Option/Opts.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ def marshalled_flag_d : Flag<["-"], "marshalled-flag-d">,
5151
MarshallingInfoFlag<XOpts<"MarshalledFlagD">>;
5252
def marshalled_flag_c : Flag<["-"], "marshalled-flag-c">,
5353
MarshallingInfoFlag<XOpts<"MarshalledFlagC">>,
54-
ImpliedByAnyOf<[marshalled_flag_d], "true">;
54+
ImpliedByAnyOf<[marshalled_flag_d.KeyPath], "true">;
5555
def marshalled_flag_b : Flag<["-"], "marshalled-flag-b">,
5656
MarshallingInfoFlag<XOpts<"MarshalledFlagB">>,
57-
ImpliedByAnyOf<[marshalled_flag_d], "true">;
57+
ImpliedByAnyOf<[marshalled_flag_d.KeyPath], "true">;
5858
def marshalled_flag_a : Flag<["-"], "marshalled-flag-a">,
5959
MarshallingInfoFlag<XOpts<"MarshalledFlagA">>,
60-
ImpliedByAnyOf<[marshalled_flag_c, marshalled_flag_b]>;
60+
ImpliedByAnyOf<[marshalled_flag_c.KeyPath, marshalled_flag_b.KeyPath]>;

0 commit comments

Comments
 (0)