This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add --print-supported-extensions support
ClosedPublic

Authored by 4vtomat on Mar 14 2023, 8:17 AM.

Details

Summary

This revision supports --print-supported-extensions,
it prints out all of the extensions and corresponding version supported.

Diff Detail

Event Timeline

4vtomat created this revision.Mar 14 2023, 8:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2023, 8:17 AM
4vtomat requested review of this revision.Mar 14 2023, 8:17 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 14 2023, 8:17 AM
4vtomat edited the summary of this revision. (Show Details)Mar 14 2023, 8:20 AM
craig.topper added inline comments.
clang/lib/Driver/Driver.cpp
107

Can we declare this in RISCVISAInfo.h and include that here?

llvm/lib/Support/RISCVISAInfo.cpp
200

This function is not in the llvm namespace or a namespace nested under it.

craig.topper added inline comments.Mar 15 2023, 6:30 PM
llvm/lib/Support/RISCVISAInfo.cpp
210

Question for the community. Should we maintain SupportedExtensions in the order we want printed instead of sorting?

kito-cheng added inline comments.Mar 16 2023, 12:18 AM
clang/lib/Driver/Driver.cpp
4305–4309

Plz did the similar action like what OPT_print_supported_cpus did instead of just exti 0

And check the triple to make sure only invoke that for riscv

llvm/lib/Support/RISCVISAInfo.cpp
209

I would prefer that print by canonical order *IF* we want to print in some order.

And then you can just use RISCVISAInfo::OrderedExtensionMap here.

asb added inline comments.Mar 16 2023, 11:59 AM
llvm/lib/Support/RISCVISAInfo.cpp
210

+1 on Kito's suggestion to print by the canonical order.

4vtomat updated this revision to Diff 506062.Mar 17 2023, 6:19 AM

Resolved Craig and Kito's comments.

craig.topper added inline comments.Mar 20 2023, 10:27 AM
llvm/lib/Support/RISCVISAInfo.cpp
201

void llvm::RISCVMarchHelp and remove the namespace llvm {

MaskRay requested changes to this revision.Mar 20 2023, 10:28 AM
MaskRay added inline comments.
clang/test/Driver/print-supported-marchs.c
17 ↗(On Diff #506062)

Use -NEXT: whenever applicable so that new extensions can be caught by the test.

clang/tools/driver/cc1_main.cpp
197

The check should be added to lib/Driver

201

riscvMarchHelp

Use camelCase for new function names.

llvm/lib/Support/RISCVISAInfo.cpp
220

Move '\n' into the "Use -march to specify the target's extension.\n..." string.

This revision now requires changes to proceed.Mar 20 2023, 10:28 AM
craig.topper added inline comments.Mar 20 2023, 10:33 AM
clang/tools/driver/cc1_main.cpp
197

RISCV -> RISC-V in user facing messages.

4vtomat updated this revision to Diff 508461.Mar 26 2023, 7:54 PM

Resolved MaskRay and Craig's comments.

craig.topper added inline comments.Mar 26 2023, 8:23 PM
clang/tools/driver/cc1_main.cpp
189

Why do we need to lookup the TargetRegistry?

craig.topper added inline comments.Mar 26 2023, 8:27 PM
clang/include/clang/Driver/Options.td
5254

Maybe this should be -print-supported-extensions to match RISC-V terminology?

5257

There's no default target behavior. It's always RISC-V.

clang/lib/Driver/Driver.cpp
4308

"-march=help is only supported for RISC-V"

4vtomat updated this revision to Diff 508475.Mar 26 2023, 9:41 PM

Resolved Craig's comments.

MaskRay requested changes to this revision.Mar 30 2023, 9:34 PM

Aliasing -march=help to --print-supported-extensions looks weird. I think this patch should remove -march=help.

clang/test/Driver/print-supported-marchs.c
1 ↗(On Diff #508475)

The filename should be fixed.

This revision now requires changes to proceed.Mar 30 2023, 9:34 PM

Created a GCC feature request: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109349

The subject and summary should be fixed and -march=help references should be removed.

clang/lib/Driver/Driver.cpp
4308

The convention is to use Diag(...).

4312

Why is the code needed? Can --print-supported-extensions reuse the approach of OPT_print_supported_cpus?

I would support have -march=help, but I know it's really not make scene to alias -march=help to --print-supported-extensions for other targets, what about redirect that in Driver.cpp for RISC-V only?

craig.topper added inline comments.Apr 7 2023, 12:56 PM
clang/lib/Driver/Driver.cpp
4312

@MaskRay are you just asking to use the same block of code for both cases?

MaskRay added inline comments.Apr 11 2023, 5:31 PM
clang/lib/Driver/Driver.cpp
4312

Yes, this should reuse some code with the OPT_print_supported_cpus handler.

4vtomat updated this revision to Diff 514302.EditedApr 17 2023, 10:36 AM

Resolved MaskRay's comments.
Should we use @kito-cheng's approach to deal with -march=help? what do you think, @MaskRay ?

I hope that we add just one option, instead of aliases. Aliases are usually added for compatibility when something is deprecated or changed, not for new options.

My "Request Changes" status still holds. The patch hasn't fixed something obvious: the description mentions print-supported-marchs (well, it should really name the exact name, --print-supported-marchs, don't omit dashes) while the implementation uses ...extensions.

4vtomat retitled this revision from [RISCV] Add -print-supported-marchs and -march=help support to [RISCV] Add --print-supported-extensions and -march=help support.Apr 23 2023, 2:10 AM
4vtomat edited the summary of this revision. (Show Details)
4vtomat updated this revision to Diff 516708.Apr 25 2023, 1:49 AM

Rename clang/test/Driver/print-supported-marchs.c to clang/test/Driver/print-supported-extensions.c

kito-cheng added inline comments.Apr 28 2023, 5:10 AM
clang/tools/driver/cc1_main.cpp
187–188

Plz make sure only RISC-V print that, x86 or other target print RISC-V's ext is really weird.

4vtomat added inline comments.May 2 2023, 5:13 PM
clang/lib/Driver/Driver.cpp
107

Yes, we can.

clang/tools/driver/cc1_main.cpp
187–188

The check is in clang/lib/Driver/Driver.cpp:4225~

189

I forgot to remove lol~

kito-cheng accepted this revision.May 3 2023, 12:38 AM

LGTM, consider about the GNU compatibility, I would that has -march=help form for that.

LGTM, consider about the GNU compatibility, I would that has -march=help form for that.

Are you saying gcc supports march=help? Is that recent?

-march= -mcpu= -mtune= are from GCC and they traditionally have many opinions on the features.
If GCC is going to have -march=help, I think adding -march=help to Clang to match is fine.
But I'd really like to avoid aliases for non-compatibility reasons. They just cause confusion and make users undecided about which one is canonical.

4vtomat updated this revision to Diff 520904.May 9 2023, 9:38 PM

Remove -march=help alias.

GCC ins't implement yet, but planed, so add it later I think?

@4vtomat already drop -march=help, @MaskRay did you mind take a look again?

GCC ins't implement yet, but planed, so add it later I think?

@4vtomat already drop -march=help, @MaskRay did you mind take a look again?

Done. But this update still doesn't look quite polished. If -march=help is dropped, at the very least the subject needs to updated.

clang/tools/driver/cc1_main.cpp
187

Use camelCase for new function names. StringRef TargetStr?

llvm/include/llvm/Support/RISCVISAInfo.h
25

This naming does not match the --print-supported-extensions option name.

llvm/lib/Support/RISCVISAInfo.cpp
201

For most --print-* options, the output goes to stdout instead of stderr.

4vtomat updated this revision to Diff 522411.May 15 2023, 7:49 PM

Resolved MaskRay's comments.

4vtomat retitled this revision from [RISCV] Add --print-supported-extensions and -march=help support to [RISCV] Add --print-supported-extensions support.May 15 2023, 7:49 PM
4vtomat edited the summary of this revision. (Show Details)
evandro removed a subscriber: evandro.May 17 2023, 3:56 PM

Please also mark resolved comments as done, otherwise reviewers can presume that some comments are unresolved and don't necessarily give another round of reviews.

clang/test/Driver/print-supported-extensions.c
6 ↗(On Diff #522411)

Use --implicit-check-not=warning: instead of // CHECK-NOT: warning: argument unused during compilation.

We additionally check that there is no warning and the warning doesn't come after the output from --print-supported-extensions.

6 ↗(On Diff #522411)

For a file with just one prefix, conventionally we just use the default CHECK and omit --check-prefix.

Have you ever checked that the test detects issues? CHECK below are ignored with --check-prefix=CHECK-RISCV.

MaskRay requested changes to this revision.May 18 2023, 11:02 AM
MaskRay added inline comments.
clang/test/Driver/print-supported-extensions.c
1 ↗(On Diff #522411)

Some newer tests use /// to distinguish non-CHECK-non-RUN comments from others. This helps automation tools to catch wrong prefixes (e.g. with a typo) in comments and helps auto-generating checks in the future while retaining manual comments.

3 ↗(On Diff #522411)

If you remove all and RISCV from LLVM_TARGETS_TO_BUILD, you can test whether this feature works without lib/Target/RISCV support. I suspect it works, so you may need another build for verification.

10 ↗(On Diff #522411)

The formatting matters here. To test formatting see --strict-whitespace --match-full-lines (example: See llvm/test/tools/llvm-readobj/ELF/gnu-sections.txt): https://llvm.org/docs/CommandGuide/FileCheck.html

This revision now requires changes to proceed.May 18 2023, 11:02 AM
4vtomat updated this revision to Diff 536947.Jul 3 2023, 9:53 PM
4vtomat marked 27 inline comments as done.

Sorry for late update.
Resolved MaskRay's comments, thanks for detailed review!

4vtomat added inline comments.Jul 3 2023, 9:53 PM
clang/test/Driver/print-supported-extensions.c
6 ↗(On Diff #522411)

Oh, I missed it, CHECK-NEXT are all ignored...
thanks!!

4vtomat marked an inline comment as done.Jul 3 2023, 9:56 PM
4vtomat added inline comments.
clang/test/Driver/print-supported-extensions.c
3 ↗(On Diff #522411)

No it cause an error if I use the command with the target without riscv such as:

bin/clang --target=aarch64 --print-supported-extensions
or
bin/clang --target=x86 --print-supported-extensions
4vtomat marked an inline comment as done.EditedJul 11 2023, 2:29 AM

Hi @MaskRay if you are available, please help me to check the revision, thanks!!

Sorry for the delay.

clang/include/clang/Frontend/FrontendOptions.h
286
290

stray change?

clang/test/Driver/print-supported-extensions.c
6 ↗(On Diff #536947)
10 ↗(On Diff #536947)

For --strict-whitespace --match-full-lines testing, we usually right align CHECK and CHECK-NEXT.

clang/tools/driver/cc1_main.cpp
187

printSupportedExtensions. Why does this function return a dummy return value?

You can do return printSupportedExtensions(), 0 below to save some lines.

llvm/lib/Support/RISCVISAInfo.cpp
214

I think outs() is more conventional. Most gcc --print-* options go to stdout. clang --print-supported-cpus deviates and we should not copy its issue.

4vtomat updated this revision to Diff 545411.Jul 30 2023, 12:21 AM
4vtomat marked 6 inline comments as done.

Resolved MaskRay's comments, thanks for reviewing!!

MaskRay added inline comments.Jul 30 2023, 7:28 PM
clang/lib/Driver/Driver.cpp
4301

no blank line here

clang/test/Driver/print-supported-extensions.c
93 ↗(On Diff #545412)

//CHECK-EMPTY:

120 ↗(On Diff #545412)

//CHECK-EMPTY:

clang/tools/driver/cc1_main.cpp
187

The call site should just call riscvExtensionsHelp so that this internal linkage function can be avoided.

190

one blank line

190

one blank line

llvm/lib/Support/RISCVISAInfo.cpp
219

clang-format will remove the space after {

4vtomat updated this revision to Diff 545499.Jul 30 2023, 7:45 PM
4vtomat marked 6 inline comments as done.

Resolved MaskRay's comments.

clang/include/clang/Frontend/FrontendOptions.h
290

Oh, maybe it was added accidentally during rebase lol~

clang/test/Driver/print-supported-extensions.c
10 ↗(On Diff #536947)

Oh, I got it, thanks!

clang/tools/driver/cc1_main.cpp
187

This is a good idea, return in its caller is much clear for it's intension!

187

Yeah, good idea!

llvm/lib/Support/RISCVISAInfo.cpp
214

Sure, I agree to keep it conventional, since I was following --print-supported-cpus so I made it this way, thank you for pointing out this!

4vtomat updated this revision to Diff 545500.Jul 30 2023, 7:59 PM

Updated test case.

MaskRay added a comment.EditedAug 14 2023, 11:57 AM

I think the best place to test RISCVISAInfo.cpp is llvm/unittests/Support/RISCVISAInfoTest.cpp.

clang/test/Driver/print-supported-extensions.c can test just a few lines (there will be some overlap with the testing in llvm/unittests/Support/RISCVISAInfoTest.cpp), so that changes to RISC-V extensions will generally not require updates to clang/test/Driver/print-supported-extensions.c

clang/test/Driver/print-supported-extensions.c
6 ↗(On Diff #545500)

Now that D156363 is stable, we can replace FileCheck --implicit-check-not=warning: with %clang -Werror.

llvm/lib/Support/RISCVISAInfo.cpp
219

Not done.

4vtomat marked 2 inline comments as done.Aug 14 2023, 8:06 PM

I think the best place to test RISCVISAInfo.cpp is llvm/unittests/Support/RISCVISAInfoTest.cpp.

clang/test/Driver/print-supported-extensions.c can test just a few lines (there will be some overlap with the testing in llvm/unittests/Support/RISCVISAInfoTest.cpp), so that changes to RISC-V extensions will generally not require updates to clang/test/Driver/print-supported-extensions.c

The goal of this patch is to list the supported extensions and their versions by providing an option, so I guess clang/test/Driver/print-supported-extensions.c aims differently with llvm/unittests/Support/RISCVISAInfoTest.cpp which is testing the functionalities in RISCVISAInfoTest.cpp.
clang/test/Driver/print-supported-extensions.c only tracks the extensions added and the their version changes and riscvExtensionsHelp in llvm/lib/Support/RISCVISAInfo.cpp doesn't have any input or output as well as any side effect, it only reads SupportedExtensions and SupportedExperimentalExtensions and dump the information.
So I think clang/test/Driver/print-supported-extensions.c is enough for this patch?

4vtomat updated this revision to Diff 550185.Aug 14 2023, 8:59 PM
  1. Apply clang-format for this patch
  2. Replace FileCheck --implicit-check-not=warning: with %clang -Werror

I think the best place to test RISCVISAInfo.cpp is llvm/unittests/Support/RISCVISAInfoTest.cpp.

clang/test/Driver/print-supported-extensions.c can test just a few lines (there will be some overlap with the testing in llvm/unittests/Support/RISCVISAInfoTest.cpp), so that changes to RISC-V extensions will generally not require updates to clang/test/Driver/print-supported-extensions.c

The goal of this patch is to list the supported extensions and their versions by providing an option, so I guess clang/test/Driver/print-supported-extensions.c aims differently with llvm/unittests/Support/RISCVISAInfoTest.cpp which is testing the functionalities in RISCVISAInfoTest.cpp.
clang/test/Driver/print-supported-extensions.c only tracks the extensions added and the their version changes and riscvExtensionsHelp in llvm/lib/Support/RISCVISAInfo.cpp doesn't have any input or output as well as any side effect, it only reads SupportedExtensions and SupportedExperimentalExtensions and dump the information.
So I think clang/test/Driver/print-supported-extensions.c is enough for this patch?

My comment is about: the test is placed at the wrong layer. See https://maskray.me/blog/2021-08-08-toolchain-testing#the-test-checks-at-the-wrong-layer

I don't want that RISC-V development in LLVM causes repeated changes to clang/test/Driver.

I think the best place to test RISCVISAInfo.cpp is llvm/unittests/Support/RISCVISAInfoTest.cpp.

clang/test/Driver/print-supported-extensions.c can test just a few lines (there will be some overlap with the testing in llvm/unittests/Support/RISCVISAInfoTest.cpp), so that changes to RISC-V extensions will generally not require updates to clang/test/Driver/print-supported-extensions.c

The goal of this patch is to list the supported extensions and their versions by providing an option, so I guess clang/test/Driver/print-supported-extensions.c aims differently with llvm/unittests/Support/RISCVISAInfoTest.cpp which is testing the functionalities in RISCVISAInfoTest.cpp.
clang/test/Driver/print-supported-extensions.c only tracks the extensions added and the their version changes and riscvExtensionsHelp in llvm/lib/Support/RISCVISAInfo.cpp doesn't have any input or output as well as any side effect, it only reads SupportedExtensions and SupportedExperimentalExtensions and dump the information.
So I think clang/test/Driver/print-supported-extensions.c is enough for this patch?

My comment is about: the test is placed at the wrong layer. See https://maskray.me/blog/2021-08-08-toolchain-testing#the-test-checks-at-the-wrong-layer

I don't want that RISC-V development in LLVM causes repeated changes to clang/test/Driver.

Got it, thanks!

4vtomat updated this revision to Diff 554609.Aug 30 2023, 12:39 AM

Resolved MaskRay's comments.

MaskRay accepted this revision.Aug 30 2023, 3:37 PM
MaskRay added inline comments.
clang/include/clang/Driver/Options.td
5255

CC1Option/CoreOption has been removed. Please rebase. Visibility<[ClangOption, CC1Option, CLOption]>,

Remove Group<CompileOnly_Group>. We don't need a workaround to claim the option in the case of clang -xxx a.o

This revision is now accepted and ready to land.Aug 30 2023, 3:37 PM
4vtomat marked an inline comment as done.Aug 31 2023, 12:25 AM
This revision was landed with ongoing or failed builds.Aug 31 2023, 12:25 AM
This revision was automatically updated to reflect the committed changes.