Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for LoongArch64 #4500

Merged
merged 7 commits into from
Oct 5, 2023

Conversation

liushuyu
Copy link
Contributor

This pull request ports the LDC compiler to LoongArch64 CPU architecture.

LoongArch64 is a new CPU architecture and has been supported by LLVM/Clang since LLVM 16.

You can find more information about this architecture here: https://loongson.github.io/LoongArch-Documentation/README-EN.html.


The port for D runtime is also in progress at dlang/dmd#15628.

@@ -765,6 +765,14 @@ void registerPredefinedTargetVersions() {
case llvm::Triple::wasm64:
VersionCondition::addPredefinedGlobalIdent("WebAssembly");
break;
case llvm::Triple::loongarch32:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have the 32-bit version here, but in most other locations you only support 64bit, e.g. in TargetABI::getTarget() and getTargetCPU

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have the 32-bit version here, but in most other locations you only support 64bit, e.g. in TargetABI::getTarget() and getTargetCPU

This is because 32-bit LoongArch is still tentative, and there is no real hardware for this specification.
I have added a tentative implementation for LoongArch32 now, but since the 32-bit ABI specification is not stable, I will not include an implementation for it in TargetABI::getTarget() .

@liushuyu liushuyu force-pushed the la64 branch 2 times, most recently from 7a53134 to a47e2e4 Compare September 24, 2023 20:34
@liushuyu
Copy link
Contributor Author

liushuyu commented Sep 24, 2023

New changes since the last push:

  • Gated LoongArch support behind LLVM >= 16.0.0 condition. Although the support for LoongArch was added in LLVM 15, the implementation was just a scaffold and was not useful for generating correct machine code.
  • Add the missing implementation for the LDC-specific osthread facility.

@liushuyu
Copy link
Contributor Author

All CI tests have successfully passed.

IndirectByvalRewrite indirectByvalRewrite{};

public:
auto returnInArg(TypeFunction *tf, bool) -> bool override {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: is there any benefit to this auto .... -> bool over bool ... ? We don't really use this syntax in LDC's codebase anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: is there any benefit to this auto .... -> bool over bool ... ? We don't really use this syntax in LDC's codebase anywhere else.

When I run clang-tidy on my changes, it tells me to use this expression instead of bool func_name(args...).
I do notice you have a .clang-tidy configuration in the project root. Perhaps that configuration makes clang-tidy to add this specific lint? (I am using Clang 16 on my system).

@JohanEngelen
Copy link
Member

The PR looks good to me.

Tests are missing, perhaps good to have at least one test for the triple and ABI ?

@liushuyu
Copy link
Contributor Author

Tests are missing, perhaps good to have at least one test for the triple and ABI ?

Will do in a bit.

@liushuyu
Copy link
Contributor Author

Tests are missing, perhaps good to have at least one test for the triple and ABI ?

Done. Let's see if CI will pick it up.

@liushuyu
Copy link
Contributor Author

CI passed without issue and the new test was picked up by CIs that running with LLVM 16

case "LoongArch32":
case "LoongArch64":
case "LoongArch_HardFloat":
case "LoongArch_SoftFloat":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[We'd get this with the next frontend merge automatically, after your upstream PR has been merged. But is okay (we usually guard LDC-specific frontends mods in version (IN_LLVM) for future merge conflicts).]

@liushuyu
Copy link
Contributor Author

liushuyu commented Oct 4, 2023

Hi,

DMD upstream has merged the LoongArch support for the D runtime. Do you want me to do a merge, or do you want to do it yourself?

@liushuyu liushuyu requested a review from JohanEngelen October 5, 2023 00:47
@JohanEngelen JohanEngelen merged commit a49db8e into ldc-developers:master Oct 5, 2023
17 of 21 checks passed
@JohanEngelen
Copy link
Member

not adding it to release notes, because runtime support is lacking and will only come with dlang 2.106

@zoujiaqing
Copy link

Thank u ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants