From e7776a989221a6abf06fcbf0172f966974649cf4 Mon Sep 17 00:00:00 2001 From: YANG Xudong Date: Fri, 9 Aug 2024 19:28:57 +0800 Subject: [PATCH 1/8] loongarch: 16 bit float is not supported on LLVM 18. --- src/codegen/llvm.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 8b13b1f2055a..3dabdf95b1c4 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11786,6 +11786,7 @@ fn backendSupportsF16(target: std.Target) bool { .mipsel, .mips64, .mips64el, + .loongarch64, => false, .aarch64 => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), else => true, From fe14f1070c673df4d0c9c106547e38d40597835f Mon Sep 17 00:00:00 2001 From: YANG Xudong Date: Fri, 9 Aug 2024 20:22:04 +0800 Subject: [PATCH 2/8] add clear cache. --- lib/compiler_rt/clear_cache.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/compiler_rt/clear_cache.zig b/lib/compiler_rt/clear_cache.zig index 5e5f20292849..2a94e2c7e4cd 100644 --- a/lib/compiler_rt/clear_cache.zig +++ b/lib/compiler_rt/clear_cache.zig @@ -28,6 +28,10 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void { .aarch64, .aarch64_be => true, else => false, }; + const loongarch64 = switch(arch) { + .loongarch64 => true, + else => false, + }; const mips = switch (arch) { .mips, .mipsel, .mips64, .mips64el => true, else => false, @@ -159,6 +163,11 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void { // On Darwin, sys_icache_invalidate() provides this functionality sys_icache_invalidate(start, end - start); exportIt(); + } else if (os == .linux and loongarch64) { + asm volatile ( + \\ ibar 0 + ); + exportIt(); } } From d1a461a0a2161c62e4c356ab2e689ea556e54f87 Mon Sep 17 00:00:00 2001 From: YANG Xudong Date: Fri, 9 Aug 2024 21:55:27 +0800 Subject: [PATCH 3/8] add comment --- lib/compiler_rt/clear_cache.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/compiler_rt/clear_cache.zig b/lib/compiler_rt/clear_cache.zig index 2a94e2c7e4cd..3a8db100f73f 100644 --- a/lib/compiler_rt/clear_cache.zig +++ b/lib/compiler_rt/clear_cache.zig @@ -164,6 +164,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void { sys_icache_invalidate(start, end - start); exportIt(); } else if (os == .linux and loongarch64) { + // See: https://github.com/llvm/llvm-project/blob/cf54cae26b65fc3201eff7200ffb9b0c9e8f9a13/compiler-rt/lib/builtins/clear_cache.c#L94-L95 asm volatile ( \\ ibar 0 ); From 944644bdc3a5d3c786a2f96e9dda35c2e82d32bd Mon Sep 17 00:00:00 2001 From: YANG Xudong Date: Fri, 9 Aug 2024 21:55:50 +0800 Subject: [PATCH 4/8] disable lto for loongarch --- src/Compilation/Config.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index 3f2e5809d496..26f46d0d58f6 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -302,6 +302,12 @@ pub fn resolve(options: Options) ResolveError!Config { break :b false; } + if (target.cpu.arch.isLoongArch()) { + // FIXME: + // loongarch LTO might have problem on LLVM 18. + break :b false; + } + break :b switch (options.output_mode) { .Lib, .Obj => false, .Exe => switch (root_optimize_mode) { From 58de99dab4ff9d553b4dbfe4b45c708cb9ce6b18 Mon Sep 17 00:00:00 2001 From: YANG Xudong Date: Fri, 9 Aug 2024 23:54:00 +0800 Subject: [PATCH 5/8] Add comment. --- src/codegen/llvm.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 3dabdf95b1c4..77edfdf42648 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11786,7 +11786,7 @@ fn backendSupportsF16(target: std.Target) bool { .mipsel, .mips64, .mips64el, - .loongarch64, + .loongarch64, // FIXME: See: https://github.com/llvm/llvm-project/issues/93894 => false, .aarch64 => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), else => true, From 52b53b712091f133387adf6f1f40f6408b37adfb Mon Sep 17 00:00:00 2001 From: YANG Xudong Date: Sat, 10 Aug 2024 00:41:35 +0800 Subject: [PATCH 6/8] remove lto related logic --- src/Compilation/Config.zig | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index 26f46d0d58f6..3f2e5809d496 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -302,12 +302,6 @@ pub fn resolve(options: Options) ResolveError!Config { break :b false; } - if (target.cpu.arch.isLoongArch()) { - // FIXME: - // loongarch LTO might have problem on LLVM 18. - break :b false; - } - break :b switch (options.output_mode) { .Lib, .Obj => false, .Exe => switch (root_optimize_mode) { From 7e615f8e71982316440dd9593be467df0486a780 Mon Sep 17 00:00:00 2001 From: YANG Xudong Date: Sat, 10 Aug 2024 01:00:17 +0800 Subject: [PATCH 7/8] remove unneeded f16 related fix. --- src/codegen/llvm.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 77edfdf42648..8b13b1f2055a 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11786,7 +11786,6 @@ fn backendSupportsF16(target: std.Target) bool { .mipsel, .mips64, .mips64el, - .loongarch64, // FIXME: See: https://github.com/llvm/llvm-project/issues/93894 => false, .aarch64 => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8), else => true, From 5b6ffff8440f22dba479ea95056391080b66a186 Mon Sep 17 00:00:00 2001 From: YANG Xudong Date: Sat, 10 Aug 2024 08:09:32 +0800 Subject: [PATCH 8/8] fmt it. --- lib/compiler_rt/clear_cache.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compiler_rt/clear_cache.zig b/lib/compiler_rt/clear_cache.zig index 3a8db100f73f..0ec36c5eb9f5 100644 --- a/lib/compiler_rt/clear_cache.zig +++ b/lib/compiler_rt/clear_cache.zig @@ -28,7 +28,7 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void { .aarch64, .aarch64_be => true, else => false, }; - const loongarch64 = switch(arch) { + const loongarch64 = switch (arch) { .loongarch64 => true, else => false, };