Skip to content

Commit

Permalink
LLVM backend: loongarch64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jun 5, 2024
1 parent 332fbb4 commit ac3faa6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@ pub const Cpu = struct {
.x86 => &x86.cpu.pentium4,
.nvptx, .nvptx64 => &nvptx.cpu.sm_20,
.sparc, .sparcel => &sparc.cpu.v8,
.loongarch64 => &loongarch.cpu.loongarch64,

else => generic(arch),
};
Expand Down Expand Up @@ -1986,6 +1987,7 @@ pub fn stackAlignment(target: Target) u16 {
.ve,
.wasm32,
.wasm64,
.loongarch64,
=> 16,
.powerpc64,
.powerpc64le,
Expand Down
22 changes: 19 additions & 3 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ const DataLayoutBuilder = struct {
};
if (self.target.cpu.arch == .aarch64_32) continue;
if (!info.force_in_data_layout and matches_default and
self.target.cpu.arch != .riscv64 and !(self.target.cpu.arch == .aarch64 and
self.target.cpu.arch != .riscv64 and
self.target.cpu.arch != .loongarch64 and
!(self.target.cpu.arch == .aarch64 and
(self.target.os.tag == .uefi or self.target.os.tag == .windows)) and
self.target.cpu.arch != .bpfeb and self.target.cpu.arch != .bpfel) continue;
try writer.writeAll("-p");
Expand Down Expand Up @@ -535,6 +537,7 @@ const DataLayoutBuilder = struct {
.nvptx64,
=> &.{ 16, 32, 64 },
.x86_64 => &.{ 8, 16, 32, 64 },
.loongarch64 => &.{64},
else => &.{},
}), 0..) |natural, index| switch (index) {
0 => try writer.print("-n{d}", .{natural}),
Expand Down Expand Up @@ -686,6 +689,14 @@ const DataLayoutBuilder = struct {
},
else => {},
},
.loongarch64 => switch (size) {
128 => {
abi = size;
pref = size;
force_abi = true;
},
else => {},
},
else => {},
}
},
Expand Down Expand Up @@ -12039,6 +12050,13 @@ pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
// There is no LLVMInitializeARCAsmParser function.
}
},
.loongarch32, .loongarch64 => {
llvm.LLVMInitializeLoongArchTarget();
llvm.LLVMInitializeLoongArchTargetInfo();
llvm.LLVMInitializeLoongArchTargetMC();
llvm.LLVMInitializeLoongArchAsmPrinter();
llvm.LLVMInitializeLoongArchAsmParser();
},

// LLVM backends that have no initialization functions.
.tce,
Expand All @@ -12060,8 +12078,6 @@ pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
.renderscript32,
.renderscript64,
.dxil,
.loongarch32,
.loongarch64,
=> {},

.spu_2 => unreachable, // LLVM does not support this backend
Expand Down
5 changes: 5 additions & 0 deletions src/codegen/llvm/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub extern fn LLVMInitializeM68kTargetInfo() void;
pub extern fn LLVMInitializeCSKYTargetInfo() void;
pub extern fn LLVMInitializeVETargetInfo() void;
pub extern fn LLVMInitializeARCTargetInfo() void;
pub extern fn LLVMInitializeLoongArchTargetInfo() void;

pub extern fn LLVMInitializeAArch64Target() void;
pub extern fn LLVMInitializeAMDGPUTarget() void;
Expand All @@ -200,6 +201,7 @@ pub extern fn LLVMInitializeM68kTarget() void;
pub extern fn LLVMInitializeVETarget() void;
pub extern fn LLVMInitializeCSKYTarget() void;
pub extern fn LLVMInitializeARCTarget() void;
pub extern fn LLVMInitializeLoongArchTarget() void;

pub extern fn LLVMInitializeAArch64TargetMC() void;
pub extern fn LLVMInitializeAMDGPUTargetMC() void;
Expand All @@ -223,6 +225,7 @@ pub extern fn LLVMInitializeM68kTargetMC() void;
pub extern fn LLVMInitializeCSKYTargetMC() void;
pub extern fn LLVMInitializeVETargetMC() void;
pub extern fn LLVMInitializeARCTargetMC() void;
pub extern fn LLVMInitializeLoongArchTargetMC() void;

pub extern fn LLVMInitializeAArch64AsmPrinter() void;
pub extern fn LLVMInitializeAMDGPUAsmPrinter() void;
Expand All @@ -244,6 +247,7 @@ pub extern fn LLVMInitializeXCoreAsmPrinter() void;
pub extern fn LLVMInitializeM68kAsmPrinter() void;
pub extern fn LLVMInitializeVEAsmPrinter() void;
pub extern fn LLVMInitializeARCAsmPrinter() void;
pub extern fn LLVMInitializeLoongArchAsmPrinter() void;

pub extern fn LLVMInitializeAArch64AsmParser() void;
pub extern fn LLVMInitializeAMDGPUAsmParser() void;
Expand All @@ -264,6 +268,7 @@ pub extern fn LLVMInitializeXtensaAsmParser() void;
pub extern fn LLVMInitializeM68kAsmParser() void;
pub extern fn LLVMInitializeCSKYAsmParser() void;
pub extern fn LLVMInitializeVEAsmParser() void;
pub extern fn LLVMInitializeLoongArchAsmParser() void;

extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) bool;
extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) bool;
Expand Down

0 comments on commit ac3faa6

Please sign in to comment.