authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-11 16:41:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-19 09:37:31-07:00
log62a12e06315ce4c2eaadfc33bf32eb4af9417ba8
tree292516689088d985bb014be0a93b8f6fc1913f54
parent1861036f3b61828d0b7641dcce65f37e516fd3f6

LLVM 17 std lib updates and fixes

* some manual fixes to generated CPU features code. in the future it would be nice to make the script do those automatically. I suspect the sm_90a thing is a bug in LLVM. * add liteos to various target OS switches. I know nothing about this OS; someone will need to work specifically on support for this OS when the time comes to support it properly in zig. * while waiting for the compiler, I went ahead and made more conservative choices about when to use `inline` in std/Target.zig

7 files changed, 86 insertions(+), 20 deletions(-)

lib/std/target.zig+18-13
...@@ -260,6 +260,7 @@ pub const Target = struct {...@@ -260,6 +260,7 @@ pub const Target = struct {
260 .emscripten,260 .emscripten,
261 .driverkit,261 .driverkit,
262 .shadermodel,262 .shadermodel,
263 .liteos,
263 .uefi,264 .uefi,
264 .opencl, // TODO: OpenCL versions265 .opencl, // TODO: OpenCL versions
265 .glsl450, // TODO: GLSL versions266 .glsl450, // TODO: GLSL versions
...@@ -396,7 +397,7 @@ pub const Target = struct {...@@ -396,7 +397,7 @@ pub const Target = struct {
396 /// On Darwin, we always link libSystem which contains libc.397 /// On Darwin, we always link libSystem which contains libc.
397 /// Similarly on FreeBSD and NetBSD we always link system libc398 /// Similarly on FreeBSD and NetBSD we always link system libc
398 /// since this is the stable syscall interface.399 /// since this is the stable syscall interface.
399 pub inline fn requiresLibC(os: Os) bool {400 pub fn requiresLibC(os: Os) bool {
400 return switch (os.tag) {401 return switch (os.tag) {
401 .freebsd,402 .freebsd,
402 .netbsd,403 .netbsd,
...@@ -438,6 +439,7 @@ pub const Target = struct {...@@ -438,6 +439,7 @@ pub const Target = struct {
438 .emscripten,439 .emscripten,
439 .driverkit,440 .driverkit,
440 .shadermodel,441 .shadermodel,
442 .liteos,
441 .uefi,443 .uefi,
442 .opencl,444 .opencl,
443 .glsl450,445 .glsl450,
...@@ -566,6 +568,7 @@ pub const Target = struct {...@@ -566,6 +568,7 @@ pub const Target = struct {
566 .watchos,568 .watchos,
567 .driverkit,569 .driverkit,
568 .shadermodel,570 .shadermodel,
571 .liteos, // TODO: audit this
569 => return .none,572 => return .none,
570 }573 }
571 }574 }
...@@ -976,7 +979,7 @@ pub const Target = struct {...@@ -976,7 +979,7 @@ pub const Target = struct {
976 return error.UnknownCpuModel;979 return error.UnknownCpuModel;
977 }980 }
978981
979 pub inline fn toElfMachine(arch: Arch) std.elf.EM {982 pub fn toElfMachine(arch: Arch) std.elf.EM {
980 return switch (arch) {983 return switch (arch) {
981 .avr => .AVR,984 .avr => .AVR,
982 .msp430 => .MSP430,985 .msp430 => .MSP430,
...@@ -1041,7 +1044,7 @@ pub const Target = struct {...@@ -1041,7 +1044,7 @@ pub const Target = struct {
1041 };1044 };
1042 }1045 }
10431046
1044 pub inline fn toCoffMachine(arch: Arch) std.coff.MachineType {1047 pub fn toCoffMachine(arch: Arch) std.coff.MachineType {
1045 return switch (arch) {1048 return switch (arch) {
1046 .avr => .Unknown,1049 .avr => .Unknown,
1047 .msp430 => .Unknown,1050 .msp430 => .Unknown,
...@@ -1106,7 +1109,7 @@ pub const Target = struct {...@@ -1106,7 +1109,7 @@ pub const Target = struct {
1106 };1109 };
1107 }1110 }
11081111
1109 pub inline fn endian(arch: Arch) std.builtin.Endian {1112 pub fn endian(arch: Arch) std.builtin.Endian {
1110 return switch (arch) {1113 return switch (arch) {
1111 .avr,1114 .avr,
1112 .arm,1115 .arm,
...@@ -1177,7 +1180,7 @@ pub const Target = struct {...@@ -1177,7 +1180,7 @@ pub const Target = struct {
1177 }1180 }
11781181
1179 /// Returns whether this architecture supports the address space1182 /// Returns whether this architecture supports the address space
1180 pub inline fn supportsAddressSpace(arch: Arch, address_space: std.builtin.AddressSpace) bool {1183 pub fn supportsAddressSpace(arch: Arch, address_space: std.builtin.AddressSpace) bool {
1181 const is_nvptx = arch == .nvptx or arch == .nvptx64;1184 const is_nvptx = arch == .nvptx or arch == .nvptx64;
1182 const is_spirv = arch == .spirv32 or arch == .spirv64;1185 const is_spirv = arch == .spirv32 or arch == .spirv64;
1183 const is_gpu = is_nvptx or is_spirv or arch == .amdgcn;1186 const is_gpu = is_nvptx or is_spirv or arch == .amdgcn;
...@@ -1715,6 +1718,7 @@ pub const Target = struct {...@@ -1715,6 +1718,7 @@ pub const Target = struct {
1715 .hurd,1718 .hurd,
1716 .driverkit,1719 .driverkit,
1717 .shadermodel,1720 .shadermodel,
1721 .liteos,
1718 => return result,1722 => return result,
1719 }1723 }
1720 }1724 }
...@@ -1743,7 +1747,7 @@ pub const Target = struct {...@@ -1743,7 +1747,7 @@ pub const Target = struct {
1743 };1747 };
1744 }1748 }
17451749
1746 pub inline fn maxIntAlignment(target: Target) u16 {1750 pub fn maxIntAlignment(target: Target) u16 {
1747 return switch (target.cpu.arch) {1751 return switch (target.cpu.arch) {
1748 .avr => 1,1752 .avr => 1,
1749 .msp430 => 2,1753 .msp430 => 2,
...@@ -1833,7 +1837,7 @@ pub const Target = struct {...@@ -1833,7 +1837,7 @@ pub const Target = struct {
1833 };1837 };
1834 }1838 }
18351839
1836 pub inline fn ptrBitWidth(target: Target) u16 {1840 pub fn ptrBitWidth(target: Target) u16 {
1837 switch (target.abi) {1841 switch (target.abi) {
1838 .gnux32, .muslx32, .gnuabin32, .gnuilp32 => return 32,1842 .gnux32, .muslx32, .gnuabin32, .gnuilp32 => return 32,
1839 .gnuabi64 => return 64,1843 .gnuabi64 => return 64,
...@@ -1910,7 +1914,7 @@ pub const Target = struct {...@@ -1910,7 +1914,7 @@ pub const Target = struct {
1910 }1914 }
1911 }1915 }
19121916
1913 pub inline fn stackAlignment(target: Target) u16 {1917 pub fn stackAlignment(target: Target) u16 {
1914 return switch (target.cpu.arch) {1918 return switch (target.cpu.arch) {
1915 .m68k => 2,1919 .m68k => 2,
1916 .amdgcn => 4,1920 .amdgcn => 4,
...@@ -1955,7 +1959,7 @@ pub const Target = struct {...@@ -1955,7 +1959,7 @@ pub const Target = struct {
1955 /// Default signedness of `char` for the native C compiler for this target1959 /// Default signedness of `char` for the native C compiler for this target
1956 /// Note that char signedness is implementation-defined and many compilers provide1960 /// Note that char signedness is implementation-defined and many compilers provide
1957 /// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char1961 /// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char
1958 pub inline fn charSignedness(target: Target) std.builtin.Signedness {1962 pub fn charSignedness(target: Target) std.builtin.Signedness {
1959 switch (target.cpu.arch) {1963 switch (target.cpu.arch) {
1960 .aarch64,1964 .aarch64,
1961 .aarch64_32,1965 .aarch64_32,
...@@ -1994,7 +1998,7 @@ pub const Target = struct {...@@ -1994,7 +1998,7 @@ pub const Target = struct {
1994 longdouble,1998 longdouble,
1995 };1999 };
19962000
1997 pub inline fn c_type_byte_size(t: Target, c_type: CType) u16 {2001 pub fn c_type_byte_size(t: Target, c_type: CType) u16 {
1998 return switch (c_type) {2002 return switch (c_type) {
1999 .char,2003 .char,
2000 .short,2004 .short,
...@@ -2020,7 +2024,7 @@ pub const Target = struct {...@@ -2020,7 +2024,7 @@ pub const Target = struct {
2020 };2024 };
2021 }2025 }
20222026
2023 pub inline fn c_type_bit_size(target: Target, c_type: CType) u16 {2027 pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
2024 switch (target.os.tag) {2028 switch (target.os.tag) {
2025 .freestanding, .other => switch (target.cpu.arch) {2029 .freestanding, .other => switch (target.cpu.arch) {
2026 .msp430 => switch (c_type) {2030 .msp430 => switch (c_type) {
...@@ -2330,11 +2334,12 @@ pub const Target = struct {...@@ -2330,11 +2334,12 @@ pub const Target = struct {
2330 .vulkan,2334 .vulkan,
2331 .driverkit,2335 .driverkit,
2332 .shadermodel,2336 .shadermodel,
2337 .liteos,
2333 => @panic("TODO specify the C integer and float type sizes for this OS"),2338 => @panic("TODO specify the C integer and float type sizes for this OS"),
2334 }2339 }
2335 }2340 }
23362341
2337 pub inline fn c_type_alignment(target: Target, c_type: CType) u16 {2342 pub fn c_type_alignment(target: Target, c_type: CType) u16 {
2338 // Overrides for unusual alignments2343 // Overrides for unusual alignments
2339 switch (target.cpu.arch) {2344 switch (target.cpu.arch) {
2340 .avr => return 1,2345 .avr => return 1,
...@@ -2441,7 +2446,7 @@ pub const Target = struct {...@@ -2441,7 +2446,7 @@ pub const Target = struct {
2441 );2446 );
2442 }2447 }
24432448
2444 pub inline fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {2449 pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 {
2445 // Overrides for unusual alignments2450 // Overrides for unusual alignments
2446 switch (target.cpu.arch) {2451 switch (target.cpu.arch) {
2447 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {2452 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {
lib/std/target/csky.zig+1-1
...@@ -3079,7 +3079,7 @@ pub const cpu = struct {...@@ -3079,7 +3079,7 @@ pub const cpu = struct {
3079 .btst16,3079 .btst16,
3080 }),3080 }),
3081 };3081 };
3082 pub const i805 = CpuModel{3082 pub const @"i805" = CpuModel{
3083 .name = "i805",3083 .name = "i805",
3084 .llvm_name = "i805",3084 .llvm_name = "i805",
3085 .features = featureSet(&[_]Feature{3085 .features = featureSet(&[_]Feature{
lib/std/target/nvptx.zig+5-5
...@@ -47,7 +47,7 @@ pub const Feature = enum {...@@ -47,7 +47,7 @@ pub const Feature = enum {
47 sm_87,47 sm_87,
48 sm_89,48 sm_89,
49 sm_90,49 sm_90,
50 sm_90,50 sm_90a,
51};51};
5252
53pub const featureSet = CpuFeature.feature_set_fns(Feature).featureSet;53pub const featureSet = CpuFeature.feature_set_fns(Feature).featureSet;
...@@ -269,9 +269,9 @@ pub const all_features = blk: {...@@ -269,9 +269,9 @@ pub const all_features = blk: {
269 .description = "Target SM 90",269 .description = "Target SM 90",
270 .dependencies = featureSet(&[_]Feature{}),270 .dependencies = featureSet(&[_]Feature{}),
271 };271 };
272 result[@intFromEnum(Feature.sm_90)] = .{272 result[@intFromEnum(Feature.sm_90a)] = .{
273 .llvm_name = "sm_90",273 .llvm_name = "sm_90a",
274 .description = "Target SM 90",274 .description = "Target SM 90a",
275 .dependencies = featureSet(&[_]Feature{}),275 .dependencies = featureSet(&[_]Feature{}),
276 };276 };
277 const ti = @typeInfo(Feature);277 const ti = @typeInfo(Feature);
...@@ -447,7 +447,7 @@ pub const cpu = struct {...@@ -447,7 +447,7 @@ pub const cpu = struct {
447 .llvm_name = "sm_90a",447 .llvm_name = "sm_90a",
448 .features = featureSet(&[_]Feature{448 .features = featureSet(&[_]Feature{
449 .ptx80,449 .ptx80,
450 .sm_90,450 .sm_90a,
451 }),451 }),
452 };452 };
453};453};
lib/std/target/x86.zig+58
...@@ -3569,6 +3569,64 @@ pub const cpu = struct {...@@ -3569,6 +3569,64 @@ pub const cpu = struct {
3569 .xsaves,3569 .xsaves,
3570 }),3570 }),
3571 };3571 };
3572 pub const skylake_avx512 = CpuModel{
3573 .name = "skylake_avx512",
3574 .llvm_name = "skylake-avx512",
3575 .features = featureSet(&[_]Feature{
3576 .@"64bit",
3577 .adx,
3578 .aes,
3579 .allow_light_256_bit,
3580 .avx512bw,
3581 .avx512cd,
3582 .avx512dq,
3583 .avx512vl,
3584 .bmi,
3585 .bmi2,
3586 .clflushopt,
3587 .clwb,
3588 .cmov,
3589 .crc32,
3590 .cx16,
3591 .ermsb,
3592 .false_deps_popcnt,
3593 .fast_15bytenop,
3594 .fast_gather,
3595 .fast_scalar_fsqrt,
3596 .fast_shld_rotate,
3597 .fast_variable_crosslane_shuffle,
3598 .fast_variable_perlane_shuffle,
3599 .fast_vector_fsqrt,
3600 .faster_shift_than_shuffle,
3601 .fsgsbase,
3602 .fxsr,
3603 .idivq_to_divl,
3604 .invpcid,
3605 .lzcnt,
3606 .macrofusion,
3607 .mmx,
3608 .movbe,
3609 .no_bypass_delay_blend,
3610 .no_bypass_delay_mov,
3611 .no_bypass_delay_shuffle,
3612 .nopl,
3613 .pclmul,
3614 .pku,
3615 .popcnt,
3616 .prefer_256_bit,
3617 .prfchw,
3618 .rdrnd,
3619 .rdseed,
3620 .sahf,
3621 .slow_3ops_lea,
3622 .tuning_fast_imm_vector_shift,
3623 .vzeroupper,
3624 .x87,
3625 .xsavec,
3626 .xsaveopt,
3627 .xsaves,
3628 }),
3629 };
3572 pub const slm = CpuModel{3630 pub const slm = CpuModel{
3573 .name = "slm",3631 .name = "slm",
3574 .llvm_name = "slm",3632 .llvm_name = "slm",
lib/std/zig/CrossTarget.zig+2
...@@ -132,6 +132,7 @@ fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void {...@@ -132,6 +132,7 @@ fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void {
132 .emscripten,132 .emscripten,
133 .driverkit,133 .driverkit,
134 .shadermodel,134 .shadermodel,
135 .liteos,
135 .uefi,136 .uefi,
136 .opencl,137 .opencl,
137 .glsl450,138 .glsl450,
...@@ -734,6 +735,7 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const...@@ -734,6 +735,7 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const
734 .plan9,735 .plan9,
735 .driverkit,736 .driverkit,
736 .shadermodel,737 .shadermodel,
738 .liteos,
737 .other,739 .other,
738 => return error.InvalidOperatingSystemVersion,740 => return error.InvalidOperatingSystemVersion,
739741
src/codegen/llvm.zig+2
...@@ -148,6 +148,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {...@@ -148,6 +148,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
148 .watchos => "watchos",148 .watchos => "watchos",
149 .driverkit => "driverkit",149 .driverkit => "driverkit",
150 .shadermodel => "shadermodel",150 .shadermodel => "shadermodel",
151 .liteos => "liteos",
151 .opencl,152 .opencl,
152 .glsl450,153 .glsl450,
153 .vulkan,154 .vulkan,
...@@ -254,6 +255,7 @@ pub fn targetOs(os_tag: std.Target.Os.Tag) llvm.OSType {...@@ -254,6 +255,7 @@ pub fn targetOs(os_tag: std.Target.Os.Tag) llvm.OSType {
254 .emscripten => .Emscripten,255 .emscripten => .Emscripten,
255 .driverkit => .DriverKit,256 .driverkit => .DriverKit,
256 .shadermodel => .ShaderModel,257 .shadermodel => .ShaderModel,
258 .liteos => .LiteOS,
257 };259 };
258}260}
259261
tools/update_cpu_features.zig-1
...@@ -945,7 +945,6 @@ const llvm_targets = [_]LlvmTarget{...@@ -945,7 +945,6 @@ const llvm_targets = [_]LlvmTarget{
945 "core_5th_gen_avx_tsx",945 "core_5th_gen_avx_tsx",
946 "mic_avx512",946 "mic_avx512",
947 "skylake_avx512",947 "skylake_avx512",
948 "skylake-avx512",
949 "icelake_client",948 "icelake_client",
950 "icelake_server",949 "icelake_server",
951 "graniterapids_d",950 "graniterapids_d",