This is an archive of the discontinued LLVM Phabricator instance.

[clang][mips] Set __mips_fpr correctly for -mfpxx
ClosedPublic

Authored by smaksimovic on Aug 10 2018, 4:15 AM.

Details

Summary

Set __mips_fpr to 0 if o32 ABI is used with either -mfpxx or none of -mfp32, -mfpxx, -mfp64 being specified.

Introduce additional checks:

  • -mfpxx is only to be used in conjunction with the o32 ABI.
  • report an error when incompatible options are provided.

Formerly no errors were raised when combining n32/n64 ABIs with -mfp32 and -mfpxx.

There are other cases when __mips_fpr should be set to 0 that are not covered, ex. using o32 on a mips64 cpu which is valid but not supported in the backend as of yet.

Diff Detail

Repository
rL LLVM

Event Timeline

smaksimovic created this revision.Aug 10 2018, 4:15 AM

Any test cases?

lib/Basic/Targets/Mips.cpp
62 ↗(On Diff #160085)

The CPU argument looks unused. We can either remove it or make this routine a non-member static function. Probably we can change the CPU’s type to StringRef.

97 ↗(On Diff #160085)

Is this change required for the fix? It looks like a refactoring and maybe done by a separate commit.

lib/Basic/Targets/Mips.h
61 ↗(On Diff #160085)

Maybe replace these two boolean flags by a single enumeration. Something like FPXX, FP32, FP64.

Added test cases.

smaksimovic added inline comments.Aug 17 2018, 6:56 AM
lib/Basic/Targets/Mips.cpp
62 ↗(On Diff #160085)

I opted to remove the argument.

97 ↗(On Diff #160085)

Since I took the code that originally was here in order to reuse it down below, I changed this line because the new function returns an int instead, as it was easier to do comparisons at line 264.

atanasyan added inline comments.Aug 20 2018, 7:04 AM
lib/Basic/Targets/Mips.cpp
141 ↗(On Diff #161233)

What do you think about this variant of the code? It's longer, but imho looks more clear.

switch (FPMode) {
case FPXX:
  Builder.defineMacro("__mips_fpr", Twine(0));
  break;
case FP32:
  Builder.defineMacro("__mips_fpr", Twine(32));
  break;
case FP64:
  Builder.defineMacro("__mips_fpr", Twine(64));
  break;
}

if (FPMode == FP64 || IsSingleFloat)
  Builder.defineMacro("_MIPS_FPSET", Twine(32));
else
  Builder.defineMacro("_MIPS_FPSET", Twine(16));

Expanded a piece of code using switch cases as suggested.

This revision is now accepted and ready to land.Aug 21 2018, 6:28 AM
This revision was automatically updated to reflect the committed changes.