| author | |
| committer | |
| log | 77e6513030a6258a893c2f11ad9708c9612b7715 |
| tree | d6821410ab84c13ba0a440bc499422d430b03f7a |
| parent | 6198f7afb76b7a5a6d359bfd24f8fbdabc77939b |
Also remove the legalize pass from zig1.13 files changed, 55 insertions(+), 28 deletions(-)
src/Air/Legalize.zig+3-1| ... | @@ -164,13 +164,14 @@ pub const Features = std.enums.EnumSet(Feature); | ... | @@ -164,13 +164,14 @@ pub const Features = std.enums.EnumSet(Feature); |
| 164 | pub const Error = std.mem.Allocator.Error; | 164 | pub const Error = std.mem.Allocator.Error; |
| 165 | 165 | ||
| 166 | pub fn legalize(air: *Air, pt: Zcu.PerThread, features: *const Features) Error!void { | 166 | pub fn legalize(air: *Air, pt: Zcu.PerThread, features: *const Features) Error!void { |
| 167 | dev.check(.legalize); | ||
| 168 | assert(!features.bits.eql(.initEmpty())); // backend asked to run legalize, but no features were enabled | ||
| 167 | var l: Legalize = .{ | 169 | var l: Legalize = .{ |
| 168 | .pt = pt, | 170 | .pt = pt, |
| 169 | .air_instructions = air.instructions.toMultiArrayList(), | 171 | .air_instructions = air.instructions.toMultiArrayList(), |
| 170 | .air_extra = air.extra, | 172 | .air_extra = air.extra, |
| 171 | .features = features, | 173 | .features = features, |
| 172 | }; | 174 | }; |
| 173 | if (l.features.bits.eql(.initEmpty())) return; | ||
| 174 | defer air.* = l.getTmpAir(); | 175 | defer air.* = l.getTmpAir(); |
| 175 | const main_extra = l.extraData(Air.Block, l.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)]); | 176 | const main_extra = l.extraData(Air.Block, l.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)]); |
| 176 | try l.legalizeBody(main_extra.end, main_extra.data.body_len); | 177 | try l.legalizeBody(main_extra.end, main_extra.data.body_len); |
| ... | @@ -845,6 +846,7 @@ inline fn replaceInst(l: *Legalize, inst: Air.Inst.Index, tag: Air.Inst.Tag, dat | ... | @@ -845,6 +846,7 @@ inline fn replaceInst(l: *Legalize, inst: Air.Inst.Index, tag: Air.Inst.Tag, dat |
| 845 | 846 | ||
| 846 | const Air = @import("../Air.zig"); | 847 | const Air = @import("../Air.zig"); |
| 847 | const assert = std.debug.assert; | 848 | const assert = std.debug.assert; |
| 849 | const dev = @import("../dev.zig"); | ||
| 848 | const Legalize = @This(); | 850 | const Legalize = @This(); |
| 849 | const std = @import("std"); | 851 | const std = @import("std"); |
| 850 | const Type = @import("../Type.zig"); | 852 | const Type = @import("../Type.zig"); |
src/Zcu/PerThread.zig+3-1| ... | @@ -1741,7 +1741,9 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: *A | ... | @@ -1741,7 +1741,9 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: *A |
| 1741 | return; | 1741 | return; |
| 1742 | } | 1742 | } |
| 1743 | 1743 | ||
| 1744 | try air.legalize(pt, @import("../codegen.zig").legalizeFeatures(pt, nav_index)); | 1744 | legalize: { |
| 1745 | try air.legalize(pt, @import("../codegen.zig").legalizeFeatures(pt, nav_index) orelse break :legalize); | ||
| 1746 | } | ||
| 1745 | 1747 | ||
| 1746 | var liveness = try Air.Liveness.analyze(gpa, air.*, ip); | 1748 | var liveness = try Air.Liveness.analyze(gpa, air.*, ip); |
| 1747 | defer liveness.deinit(gpa); | 1749 | defer liveness.deinit(gpa); |
src/arch/aarch64/CodeGen.zig+2-2| ... | @@ -40,8 +40,8 @@ const gp = abi.RegisterClass.gp; | ... | @@ -40,8 +40,8 @@ const gp = abi.RegisterClass.gp; |
| 40 | 40 | ||
| 41 | const InnerError = CodeGenError || error{OutOfRegisters}; | 41 | const InnerError = CodeGenError || error{OutOfRegisters}; |
| 42 | 42 | ||
| 43 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 43 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 44 | return comptime &.initEmpty(); | 44 | return null; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | gpa: Allocator, | 47 | gpa: Allocator, |
src/arch/arm/CodeGen.zig+2-2| ... | @@ -41,8 +41,8 @@ const gp = abi.RegisterClass.gp; | ... | @@ -41,8 +41,8 @@ const gp = abi.RegisterClass.gp; |
| 41 | 41 | ||
| 42 | const InnerError = CodeGenError || error{OutOfRegisters}; | 42 | const InnerError = CodeGenError || error{OutOfRegisters}; |
| 43 | 43 | ||
| 44 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 44 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 45 | return comptime &.initEmpty(); | 45 | return null; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | gpa: Allocator, | 48 | gpa: Allocator, |
src/arch/powerpc/CodeGen.zig+2-2| ... | @@ -10,8 +10,8 @@ const Zcu = @import("../../Zcu.zig"); | ... | @@ -10,8 +10,8 @@ const Zcu = @import("../../Zcu.zig"); |
| 10 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const log = std.log.scoped(.codegen); | 11 | const log = std.log.scoped(.codegen); |
| 12 | 12 | ||
| 13 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 13 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 14 | return comptime &.initEmpty(); | 14 | return null; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | pub fn generate( | 17 | pub fn generate( |
src/arch/riscv64/CodeGen.zig+2-2| ... | @@ -51,8 +51,8 @@ const Instruction = encoding.Instruction; | ... | @@ -51,8 +51,8 @@ const Instruction = encoding.Instruction; |
| 51 | 51 | ||
| 52 | const InnerError = CodeGenError || error{OutOfRegisters}; | 52 | const InnerError = CodeGenError || error{OutOfRegisters}; |
| 53 | 53 | ||
| 54 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 54 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 55 | return comptime &.initEmpty(); | 55 | return null; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | pt: Zcu.PerThread, | 58 | pt: Zcu.PerThread, |
src/arch/sparc64/CodeGen.zig+2-2| ... | @@ -41,8 +41,8 @@ const Self = @This(); | ... | @@ -41,8 +41,8 @@ const Self = @This(); |
| 41 | 41 | ||
| 42 | const InnerError = CodeGenError || error{OutOfRegisters}; | 42 | const InnerError = CodeGenError || error{OutOfRegisters}; |
| 43 | 43 | ||
| 44 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 44 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 45 | return comptime &.initEmpty(); | 45 | return null; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | const RegisterView = enum(u1) { | 48 | const RegisterView = enum(u1) { |
src/arch/wasm/CodeGen.zig+2-2| ... | @@ -31,8 +31,8 @@ const libcFloatSuffix = target_util.libcFloatSuffix; | ... | @@ -31,8 +31,8 @@ const libcFloatSuffix = target_util.libcFloatSuffix; |
| 31 | const compilerRtFloatAbbrev = target_util.compilerRtFloatAbbrev; | 31 | const compilerRtFloatAbbrev = target_util.compilerRtFloatAbbrev; |
| 32 | const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev; | 32 | const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev; |
| 33 | 33 | ||
| 34 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 34 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 35 | return comptime &.initEmpty(); | 35 | return null; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | /// Reference to the function declaration the code | 38 | /// Reference to the function declaration the code |
src/codegen.zig+23-7| ... | @@ -27,9 +27,22 @@ pub const CodeGenError = GenerateSymbolError || error{ | ... | @@ -27,9 +27,22 @@ pub const CodeGenError = GenerateSymbolError || error{ |
| 27 | CodegenFail, | 27 | CodegenFail, |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Feature { | 30 | fn devFeatureForBackend(backend: std.builtin.CompilerBackend) dev.Feature { |
| 31 | comptime assert(mem.startsWith(u8, @tagName(backend), "stage2_")); | 31 | return switch (backend) { |
| 32 | return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend"); | 32 | .other, .stage1 => unreachable, |
| 33 | .stage2_aarch64 => .aarch64_backend, | ||
| 34 | .stage2_arm => .arm_backend, | ||
| 35 | .stage2_c => .c_backend, | ||
| 36 | .stage2_llvm => .llvm_backend, | ||
| 37 | .stage2_powerpc => .powerpc_backend, | ||
| 38 | .stage2_riscv64 => .riscv64_backend, | ||
| 39 | .stage2_sparc64 => .sparc64_backend, | ||
| 40 | .stage2_spirv64 => .spirv64_backend, | ||
| 41 | .stage2_wasm => .wasm_backend, | ||
| 42 | .stage2_x86 => .x86_backend, | ||
| 43 | .stage2_x86_64 => .x86_64_backend, | ||
| 44 | _ => unreachable, | ||
| 45 | }; | ||
| 33 | } | 46 | } |
| 34 | 47 | ||
| 35 | fn importBackend(comptime backend: std.builtin.CompilerBackend) type { | 48 | fn importBackend(comptime backend: std.builtin.CompilerBackend) type { |
| ... | @@ -49,10 +62,10 @@ fn importBackend(comptime backend: std.builtin.CompilerBackend) type { | ... | @@ -49,10 +62,10 @@ fn importBackend(comptime backend: std.builtin.CompilerBackend) type { |
| 49 | }; | 62 | }; |
| 50 | } | 63 | } |
| 51 | 64 | ||
| 52 | pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) *const Air.Legalize.Features { | 65 | pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) ?*const Air.Legalize.Features { |
| 53 | const zcu = pt.zcu; | 66 | const zcu = pt.zcu; |
| 54 | const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result; | 67 | const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result; |
| 55 | return switch (target_util.zigBackend(target.*, zcu.comp.config.use_llvm)) { | 68 | switch (target_util.zigBackend(target.*, zcu.comp.config.use_llvm)) { |
| 56 | else => unreachable, | 69 | else => unreachable, |
| 57 | inline .stage2_llvm, | 70 | inline .stage2_llvm, |
| 58 | .stage2_c, | 71 | .stage2_c, |
| ... | @@ -65,8 +78,11 @@ pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) *con | ... | @@ -65,8 +78,11 @@ pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) *con |
| 65 | .stage2_sparc64, | 78 | .stage2_sparc64, |
| 66 | .stage2_spirv64, | 79 | .stage2_spirv64, |
| 67 | .stage2_powerpc, | 80 | .stage2_powerpc, |
| 68 | => |backend| importBackend(backend).legalizeFeatures(target), | 81 | => |backend| { |
| 69 | }; | 82 | dev.check(devFeatureForBackend(backend)); |
| 83 | return importBackend(backend).legalizeFeatures(target); | ||
| 84 | }, | ||
| 85 | } | ||
| 70 | } | 86 | } |
| 71 | 87 | ||
| 72 | pub fn generateFunction( | 88 | pub fn generateFunction( |
src/codegen/c.zig+7-3| ... | @@ -20,8 +20,8 @@ const Alignment = InternPool.Alignment; | ... | @@ -20,8 +20,8 @@ const Alignment = InternPool.Alignment; |
| 20 | const BigIntLimb = std.math.big.Limb; | 20 | const BigIntLimb = std.math.big.Limb; |
| 21 | const BigInt = std.math.big.int; | 21 | const BigInt = std.math.big.int; |
| 22 | 22 | ||
| 23 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 23 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 24 | return comptime &.initEmpty(); | 24 | return null; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | pub const CType = @import("c/Type.zig"); | 27 | pub const CType = @import("c/Type.zig"); |
| ... | @@ -210,7 +210,6 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{ | ... | @@ -210,7 +210,6 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{ |
| 210 | .{ "atomic_ushort", {} }, | 210 | .{ "atomic_ushort", {} }, |
| 211 | .{ "atomic_wchar_t", {} }, | 211 | .{ "atomic_wchar_t", {} }, |
| 212 | .{ "auto", {} }, | 212 | .{ "auto", {} }, |
| 213 | .{ "bool", {} }, | ||
| 214 | .{ "break", {} }, | 213 | .{ "break", {} }, |
| 215 | .{ "case", {} }, | 214 | .{ "case", {} }, |
| 216 | .{ "char", {} }, | 215 | .{ "char", {} }, |
| ... | @@ -270,6 +269,11 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{ | ... | @@ -270,6 +269,11 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{ |
| 270 | .{ "va_end", {} }, | 269 | .{ "va_end", {} }, |
| 271 | .{ "va_copy", {} }, | 270 | .{ "va_copy", {} }, |
| 272 | 271 | ||
| 272 | // stdbool.h | ||
| 273 | .{ "bool", {} }, | ||
| 274 | .{ "false", {} }, | ||
| 275 | .{ "true", {} }, | ||
| 276 | |||
| 273 | // stddef.h | 277 | // stddef.h |
| 274 | .{ "offsetof", {} }, | 278 | .{ "offsetof", {} }, |
| 275 | 279 |
src/codegen/llvm.zig+2-2| ... | @@ -36,8 +36,8 @@ const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev; | ... | @@ -36,8 +36,8 @@ const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev; |
| 36 | 36 | ||
| 37 | const Error = error{ OutOfMemory, CodegenFail }; | 37 | const Error = error{ OutOfMemory, CodegenFail }; |
| 38 | 38 | ||
| 39 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 39 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 40 | return comptime &.initEmpty(); | 40 | return null; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | fn subArchName(features: std.Target.Cpu.Feature.Set, arch: anytype, mappings: anytype) ?[]const u8 { | 43 | fn subArchName(features: std.Target.Cpu.Feature.Set, arch: anytype, mappings: anytype) ?[]const u8 { |
src/codegen/spirv.zig+2-2| ... | @@ -28,8 +28,8 @@ const SpvAssembler = @import("spirv/Assembler.zig"); | ... | @@ -28,8 +28,8 @@ const SpvAssembler = @import("spirv/Assembler.zig"); |
| 28 | 28 | ||
| 29 | const InstMap = std.AutoHashMapUnmanaged(Air.Inst.Index, IdRef); | 29 | const InstMap = std.AutoHashMapUnmanaged(Air.Inst.Index, IdRef); |
| 30 | 30 | ||
| 31 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | 31 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { |
| 32 | return comptime &.initEmpty(); | 32 | return null; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | pub const zig_call_abi_ver = 3; | 35 | pub const zig_call_abi_ver = 3; |
src/dev.zig+3| ... | @@ -67,6 +67,7 @@ pub const Env = enum { | ... | @@ -67,6 +67,7 @@ pub const Env = enum { |
| 67 | .incremental, | 67 | .incremental, |
| 68 | .ast_gen, | 68 | .ast_gen, |
| 69 | .sema, | 69 | .sema, |
| 70 | .legalize, | ||
| 70 | .llvm_backend, | 71 | .llvm_backend, |
| 71 | .c_backend, | 72 | .c_backend, |
| 72 | .wasm_backend, | 73 | .wasm_backend, |
| ... | @@ -144,6 +145,7 @@ pub const Env = enum { | ... | @@ -144,6 +145,7 @@ pub const Env = enum { |
| 144 | .build_command, | 145 | .build_command, |
| 145 | .stdio_listen, | 146 | .stdio_listen, |
| 146 | .incremental, | 147 | .incremental, |
| 148 | .legalize, | ||
| 147 | .x86_64_backend, | 149 | .x86_64_backend, |
| 148 | .elf_linker, | 150 | .elf_linker, |
| 149 | => true, | 151 | => true, |
| ... | @@ -222,6 +224,7 @@ pub const Feature = enum { | ... | @@ -222,6 +224,7 @@ pub const Feature = enum { |
| 222 | incremental, | 224 | incremental, |
| 223 | ast_gen, | 225 | ast_gen, |
| 224 | sema, | 226 | sema, |
| 227 | legalize, | ||
| 225 | 228 | ||
| 226 | llvm_backend, | 229 | llvm_backend, |
| 227 | c_backend, | 230 | c_backend, |