This is an archive of the discontinued LLVM Phabricator instance.

[Clang][LoongArch] Define more LoongArch specific built-in macros
ClosedPublic

Authored by SixWeining on Oct 20 2022, 6:55 PM.

Details

Summary

Define below macros according to LoongArch toolchain conventions [1].

  • __loongarch_grlen
  • __loongarch_frlen
  • __loongarch_lp64
  • __loongarch_hard_float
  • __loongarch_soft_float
  • __loongarch_single_float
  • __loongarch_double_float

And __loongarch64 for compatibility with existing code.

Note:

  1. __loongarch__ is already covered.
  2. __loongarch_arch is not defined because I don't know how to access the arch name specified by -march in TargetInfo.
  3. __loongarch_tune will be defined in the future.

[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html

Depends on D136146

Diff Detail

Event Timeline

SixWeining created this revision.Oct 20 2022, 6:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2022, 6:55 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
SixWeining requested review of this revision.Oct 20 2022, 6:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2022, 6:55 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Do we support --target=loongarch64 -mabi=ilp32d or -mfpu=64 -mabi=lp64s combinations now? If true I think we'll need test cases for such combinations.

Do we support --target=loongarch64 -mabi=ilp32d or -mfpu=64 -mabi=lp64s combinations now? If true I think we'll need test cases for such combinations.

For --target=loongarch64 -mabi=ilp32d, I'm not sure about this. The ABI document doesn't clearly describe this. But in current llvm implementation, it is NOT supported. In clang/lib/Basic/Targets/LoongArch.h:LoongArch64TargetInfo:setABI:

bool setABI(const std::string &Name) override {
  if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
    ABI = Name;
    return true;
  }
  return false;
}

For -mfpu=64 -mabi=lp64s, I think it is valid and I will add some tests. Similarly, -mfpu=32 -mabi=lp64s.

How about -mfpu=64 -mabi=lp64f?

Do we need to add the definition of the __loongarch64 macro? gcc has that definition (but it is not recommended to use it, just for compatibility with previous code).
It has been used in some projects before, such as linux kernel, libunwind etc.

Add tests for more -mfpu and -mabi combinations.

xen0n edited the summary of this revision. (Show Details)Oct 20 2022, 11:10 PM

I've formatted the patch summary for you. Please familiarize yourself with Markdown syntax so next time your rendering would look better.

Do we need to add the definition of the __loongarch64 macro? gcc has that definition (but it is not recommended to use it, just for compatibility with previous code).
It has been used in some projects before, such as linux kernel, libunwind etc.

For minimum churn and hassle, I'm afraid we have to add it for now. I didn't realize [[ https://github.com/loongson/LoongArch-Documentation/pull/28#discussion_r917367794 | it's the equivalent of __mips64 ]] until too much software has been ported with it...

xen0n edited the summary of this revision. (Show Details)Oct 20 2022, 11:17 PM
xen0n edited the summary of this revision. (Show Details)

I've formatted the patch summary for you. Please familiarize yourself with Markdown syntax so next time your rendering would look better.

Thanks. Got it.

For minimum churn and hassle, I'm afraid we have to add it for now. I didn't realize [[ https://github.com/loongson/LoongArch-Documentation/pull/28#discussion_r917367794 | it's the equivalent of __mips64 ]] until too much software has been ported with it...

OK.

Define __loongarch64 which is equal to __loongarch_grlen == 64.

xen0n accepted this revision.Oct 30 2022, 6:42 PM
This revision is now accepted and ready to land.Oct 30 2022, 6:42 PM
xen0n edited the summary of this revision. (Show Details)Oct 30 2022, 6:44 PM

Amended the patch summary a little for grammatical fixes and mentioning __loongarch64 too.

Amended the patch summary a little for grammatical fixes and mentioning __loongarch64 too.

Thanks.

BTW, this patch depends on D136146. Could you help to have a look? :)