Skip to content

loongarch: Scaffold self-hosted LoongArch backend #24182

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

Open
wants to merge 153 commits into
base: master
Choose a base branch
from

Conversation

xtexx
Copy link
Contributor

@xtexx xtexx commented Jun 14, 2025

This PR adds a self-hosted LoongArch64 backend.

The backend currently implements only a few features.

Test runner is working, but due to the very limited number of passing behavior tests, the backend is not added to the test target list.

Although it is foreseeable that I will not have much time to work on this backend in the coming one year due to my study, I will try to keep the backend working and expand its features.

xtexx added 30 commits June 9, 2025 08:56
@alexrp alexrp self-requested a review June 14, 2025 16:59
@xtexx xtexx changed the title loongarch64: Scaffold self-hosted LoongArch64 backend loongarch: Scaffold self-hosted LoongArch backend Jun 14, 2025
@@ -0,0 +1,790 @@
//! Inline assembly parser for LoongArch.
Copy link
Member

Choose a reason for hiding this comment

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

Also should rename this directory.

@@ -91,6 +94,7 @@ pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) ?*co
pub const AnyMir = union {
aarch64: @import("arch/aarch64/Mir.zig"),
arm: @import("arch/arm/Mir.zig"),
loongarch64: @import("arch/loongarch64/Mir.zig"),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
loongarch64: @import("arch/loongarch64/Mir.zig"),
loongarch: @import("arch/loongarch/Mir.zig"),

@@ -102,6 +106,7 @@ pub const AnyMir = union {
return switch (backend) {
.stage2_aarch64 => "aarch64",
.stage2_arm => "arm",
.stage2_loongarch => "loongarch64",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.stage2_loongarch => "loongarch64",
.stage2_loongarch => "loongarch",

@@ -44,6 +44,10 @@ pub const Env = enum {
/// - `zig build-* -fno-llvm -fno-lld -target wasm32-* --listen=-`
wasm,

/// - sema
/// - `zig build-* -fincremental -fno-llvm -fno-lld -target loongarch64-linux --listen=-`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// - `zig build-* -fincremental -fno-llvm -fno-lld -target loongarch64-linux --listen=-`
/// - `zig build-* -fincremental -fno-llvm -fno-lld -target loongarch(32,64)-linux --listen=-`

@@ -0,0 +1,514 @@
const std = @import("std");
Copy link
Member

Choose a reason for hiding this comment

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

Is this tool 64-bit only?

@@ -4128,7 +4128,7 @@ pub fn getTarget(self: Elf) std.Target {
fn requiresThunks(self: Elf) bool {
return switch (self.getTarget().cpu.arch) {
.aarch64 => true,
.x86_64, .riscv64 => false,
.x86_64, .riscv64, .loongarch64 => false,
Copy link
Member

Choose a reason for hiding this comment

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

Worth checking if all the added linker code is actually 64-bit only; I suspect not?

@xtexx
Copy link
Contributor Author

xtexx commented Jun 15, 2025 via email

@alexrp
Copy link
Member

alexrp commented Jun 16, 2025

cc @jacobly0 to review the general structure of the new backend.

@alexrp alexrp requested a review from jacobly0 June 16, 2025 05:30
@jacobly0
Copy link
Member

You might want to git mv src/arch/loongarch64 src/codegen/loongarch now to avoid annoying conflicts when somebody else does it later.

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.

3 participants