This is an archive of the discontinued LLVM Phabricator instance.

[Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present
ClosedPublic

Authored by xen0n on Jun 24 2023, 11:04 AM.

Details

Summary

This kind of CLI flags duplication can sometimes be convenient for build
systems that may have to tinker with these.

For example, in the Linux kernel we almost always want to ensure no FP
instruction is emitted, so -msoft-float is present by default; but
sometimes we do want to allow FPU usage (e.g. certain parts of amdgpu DC
code), in which case we want the -msoft-float stripped and -mfpu=64
added. Here we face a dilemma without this change:

  • Either -mabi is not supplied by arch/loongarch Makefile, in which case the correct ABI has to be supplied by the driver Makefile (otherwise the ABI will become double-float due to -mfpu), which is arguably not appropriate for a driver;
  • Or -mabi is still supplied by arch/loongarch Makefile, and the build immediately errors out because -Werror=unused-command-line-argument is unconditionally set for Clang builds.

To solve this, simply make sure to check -mabi and -mfpu (and gain
some useful diagnostics in case of conflicting settings) when
-m*-float is successfully parsed.

Diff Detail

Event Timeline

xen0n created this revision.Jun 24 2023, 11:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2023, 11:04 AM
Herald added a subscriber: tpr. · View Herald Transcript
xen0n requested review of this revision.Jun 24 2023, 11:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2023, 11:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
xen0n updated this revision to Diff 534241.Jun 24 2023, 11:21 AM

Fix faulty refactor (unintended always-error case).

SixWeining accepted this revision.Jun 25 2023, 2:08 AM

LGTM. Thanks.

clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
72

Seems that this condition is always true.

91–97

Without default, there may be compiling warning?

This revision is now accepted and ready to land.Jun 25 2023, 2:08 AM
xen0n added inline comments.Jun 25 2023, 2:46 AM
clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
72

Yes you're right. I'll simplify it (and add comment detailing why it's safe to assume non-emptiness) shortly.

91–97

I didn't remember seeing such warnings; plus the case's body would be empty anyway...

xen0n updated this revision to Diff 534325.Jun 25 2023, 3:20 AM

Refactored to reduce duplication of flag processing logic and save one level of indent.

xen0n updated this revision to Diff 534326.Jun 25 2023, 3:33 AM
xen0n marked an inline comment as done.

Grammatical fix of comment text ("is" -> "are").

xen0n marked an inline comment as done.Jun 25 2023, 3:51 AM
xen0n edited the summary of this revision. (Show Details)Jun 25 2023, 3:54 AM
MaskRay requested changes to this revision.Jun 25 2023, 9:53 AM
MaskRay added inline comments.
clang/include/clang/Basic/DiagnosticDriverKinds.td
732

This is not called setting. Use value

It seems that ignoring -mabi value '%0' as it conflicts ... is more conventional.

clang/test/Driver/loongarch-msingle-float.c
10–12

Just use NOWARN-NOT: warning: to assert that there is no diagnostic

This revision now requires changes to proceed.Jun 25 2023, 9:53 AM
xen0n updated this revision to Diff 534365.Jun 25 2023, 11:06 AM

Address @MaskRay's review comments.

xen0n marked 2 inline comments as done.Jun 25 2023, 11:19 AM
xen0n added inline comments.
clang/include/clang/Basic/DiagnosticDriverKinds.td
732

Sounds reasonable. I've checked other similar diagnostics text and it seems your suggestion is stylistically more consistent.

MaskRay added inline comments.Jun 25 2023, 9:00 PM
clang/include/clang/Basic/DiagnosticDriverKinds.td
732

You can make -mabi/-mfpu an argument as well so that we can create just one def.
It would be good to expand -m*-float.

xen0n updated this revision to Diff 534427.Jun 25 2023, 10:39 PM
xen0n marked an inline comment as done.

Unify the diagnostic messages and show the actual -m*-float option being passed.

xen0n updated this revision to Diff 534430.Jun 25 2023, 11:00 PM

Refactor more to be able to show the exact -mabi and -mfpu argument given.

MaskRay accepted this revision.Jun 26 2023, 12:03 AM
This revision is now accepted and ready to land.Jun 26 2023, 12:03 AM