This is an archive of the discontinued LLVM Phabricator instance.

[clang] SimpleMFlag helper in Options.td
ClosedPublic

Authored by rampitec on Feb 19 2021, 11:04 AM.

Details

Summary

This is the new helper to create a boolean -m and -mno-
options.

Diff Detail

Event Timeline

rampitec created this revision.Feb 19 2021, 11:04 AM
rampitec requested review of this revision.Feb 19 2021, 11:04 AM

If folks are ok with this approach, we probably will need to update other targets' *m* flags (e.g. -m[no-]unimplemented_simd128, -m[no-]fix_cortex_a53_835769, etc.)

jansvoboda11 requested changes to this revision.Feb 22 2021, 12:13 AM
jansvoboda11 added inline comments.
clang/include/clang/Driver/Options.td
436

Can you please rename this to BoolMFlag and model it after BoolFFlag?

The Bool?Option multiclasses were created for fine-grained control of cc1 flag marshalling, which your implementation doesn't do/need. https://clang.llvm.org/docs/InternalsManual.html#option-marshalling-infrastructure

This revision now requires changes to proceed.Feb 22 2021, 12:14 AM
rampitec added inline comments.Feb 22 2021, 10:25 AM
clang/include/clang/Driver/Options.td
436

It does not seem that BoolFFlag exists?

jansvoboda11 added inline comments.Feb 23 2021, 12:35 AM
clang/include/clang/Driver/Options.td
436

Ah, sorry, I meant OptInFFlag and OptOutFFlag.

You probably won't need the KeyPathAndMacro and enablers parameters, as you're not targeting cc1.

rampitec added inline comments.Feb 23 2021, 1:10 PM
clang/include/clang/Driver/Options.td
436

It end up with the same multiclass, just different name? After OptInFFlag is cleaned from marshalling, kpm, enablers and CC1 stuff it looks more or less the same as this one. Plus to get the same behavior as now we need separate help strings and optional group.

jansvoboda11 added inline comments.Feb 24 2021, 1:03 AM
clang/include/clang/Driver/Options.td
436

My concern here is that naming this class BoolMOption will cause confusion. We already have BoolFOption and BoolGOption that are used for different purpose (automatic option marshalling in cc1).

Note: I'm in the process of converting Opt{In,Out}FFlag instances that perform marshalling via the kpm and enablers parameters to BoolFOption instances. My end-goal is to have clear distinction between marshalling multiclasses (ending with Option) and simple multiclasses that don't do marshalling (ending with Flag).

Since your multiclass doesn't perform marshalling, I'd strongly prefer the name to end with Flag. And since it's neither opt-in or opt-out (because it doesn't target cc1), how about naming it SimpleMFlag, PlainMFlag or something similar?

I also think keeping the API similar to existing multiclasses would be nice from user perspective. How about using the existing the Opt{In,Out}FFlag signature (stripped of kpm and enablers?

string name, string pos_prefix, string neg_prefix="", string help="", list<OptionFlag> flags=[]

It supports separate help strings and you can append OptionGroup OptGroup = m_Group at the end to fit your use-case.

I understand it will end up looking a lot like Opt{In,Out}FFlag, but the absence of CC1Option is pretty important, so I think it's fine.

jansvoboda11 added inline comments.Feb 24 2021, 2:31 AM
clang/include/clang/Driver/Options.td
436

See D97370.

kzhuravl added inline comments.Feb 24 2021, 6:50 AM
clang/include/clang/Driver/Options.td
436

Would it make sense to rename OptInFFlag to OptInFlag, and take common prefix as a template arg, something like:

multiclass OptInFlag<**string prefix**, string name, string pos_prefix, string neg_prefix="",
                      string help="", list<OptionFlag> flags=[]> {

Then we will have existing "optin flags" as

defm cuda_short_ptr : OptInFlag<"f", "cuda-short-ptr",

And new "optin flags" as

defm tgsplit : OptInFlag<"m", "tgsplit",

?

jansvoboda11 added inline comments.Feb 24 2021, 9:59 AM
clang/include/clang/Driver/Options.td
436

Extracting the prefix parameter is certainly possible, but I don't see how OptInFlag or OptOutFlag could be used for the options in this patch.

Opt-in means that the driver recognizes two flags (the positive and the negative), while cc1 recognizes only the positive flag. The value in CompilerInvocation controlled by the flag defaults to false and can be set to true by the positive flag (the user can "opt-in" to some behavior). Opt-out means the opposite.

If I'm not mistaken, neither of the options in this patch are recognized by cc1, so the concept of opt-in/opt-out doesn't apply here.

rampitec updated this revision to Diff 326244.Feb 24 2021, 4:55 PM

Renamed macro as SimpleMFlag.

clang/include/clang/Driver/Options.td
436

My concern here is that naming this class BoolMOption will cause confusion. We already have BoolFOption and BoolGOption that are used for different purpose (automatic option marshalling in cc1).

Note: I'm in the process of converting Opt{In,Out}FFlag instances that perform marshalling via the kpm and enablers parameters to BoolFOption instances. My end-goal is to have clear distinction between marshalling multiclasses (ending with Option) and simple multiclasses that don't do marshalling (ending with Flag).

Since your multiclass doesn't perform marshalling, I'd strongly prefer the name to end with Flag. And since it's neither opt-in or opt-out (because it doesn't target cc1), how about naming it SimpleMFlag, PlainMFlag or something similar?

I also think keeping the API similar to existing multiclasses would be nice from user perspective. How about using the existing the Opt{In,Out}FFlag signature (stripped of kpm and enablers?

string name, string pos_prefix, string neg_prefix="", string help="", list<OptionFlag> flags=[]

It supports separate help strings and you can append OptionGroup OptGroup = m_Group at the end to fit your use-case.

I understand it will end up looking a lot like Opt{In,Out}FFlag, but the absence of CC1Option is pretty important, so I think it's fine.

I have renamed it.

With the help it is not so easy to have a single string. Look at the uses, positive and negative options have sufficiently different text.

I am also not sure about "list<OptionFlag> flags", it does not seem to have any use for the -m options.

jansvoboda11 accepted this revision.Feb 26 2021, 10:01 AM

Thanks for renaming the multiclass.

LGTM with the typo fixed. Decision on the final signature is up to you.

clang/include/clang/Driver/Options.td
436

The suggested signature doesn't have one help string, it has three: the pos_prefix, neg_prefix and common suffix help.
It could simplify some of your options (e.g. "Enable", "Disable" , " threadgroup split execution mode (AMDGPU only)").

I'm fine with leaving flags out as there's no need for them right now.

3160

Small typo.

This revision is now accepted and ready to land.Feb 26 2021, 10:01 AM
rampitec updated this revision to Diff 326747.Feb 26 2021, 11:12 AM
rampitec marked an inline comment as done.

Fixed typo.
Made it more like OptInFFlag with 3 help strings and parameter naming.

clang/include/clang/Driver/Options.td
436

Right, I missed I can combine anything out of 3 strings. Added 3 strings like in OptInFFlag.

rampitec marked an inline comment as done.Feb 26 2021, 11:12 AM
rampitec retitled this revision from [clang] BoolMOption helper in Options.td to [clang] SimpleMFlag helper in Options.td.Mar 1 2021, 8:59 AM
This revision was landed with ongoing or failed builds.Mar 1 2021, 9:03 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2021, 9:03 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript