| 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 | 164 | pub const Error = std.mem.Allocator.Error; |
| 165 | 165 | |
| 166 | 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 | 169 | var l: Legalize = .{ |
| 168 | 170 | .pt = pt, |
| 169 | 171 | .air_instructions = air.instructions.toMultiArrayList(), |
| 170 | 172 | .air_extra = air.extra, |
| 171 | 173 | .features = features, |
| 172 | 174 | }; |
| 173 | if (l.features.bits.eql(.initEmpty())) return; | |
| 174 | 175 | defer air.* = l.getTmpAir(); |
| 175 | 176 | const main_extra = l.extraData(Air.Block, l.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)]); |
| 176 | 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 | 846 | |
| 846 | 847 | const Air = @import("../Air.zig"); |
| 847 | 848 | const assert = std.debug.assert; |
| 849 | const dev = @import("../dev.zig"); | |
| 848 | 850 | const Legalize = @This(); |
| 849 | 851 | const std = @import("std"); |
| 850 | 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 | 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 | 1748 | var liveness = try Air.Liveness.analyze(gpa, air.*, ip); |
| 1747 | 1749 | defer liveness.deinit(gpa); |
src/arch/aarch64/CodeGen.zig+2-2| ... | ... | @@ -40,8 +40,8 @@ const gp = abi.RegisterClass.gp; |
| 40 | 40 | |
| 41 | 41 | const InnerError = CodeGenError || error{OutOfRegisters}; |
| 42 | 42 | |
| 43 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 44 | return comptime &.initEmpty(); | |
| 43 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 44 | return null; | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | gpa: Allocator, |
src/arch/arm/CodeGen.zig+2-2| ... | ... | @@ -41,8 +41,8 @@ const gp = abi.RegisterClass.gp; |
| 41 | 41 | |
| 42 | 42 | const InnerError = CodeGenError || error{OutOfRegisters}; |
| 43 | 43 | |
| 44 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 45 | return comptime &.initEmpty(); | |
| 44 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 45 | return null; | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | gpa: Allocator, |
src/arch/powerpc/CodeGen.zig+2-2| ... | ... | @@ -10,8 +10,8 @@ const Zcu = @import("../../Zcu.zig"); |
| 10 | 10 | const assert = std.debug.assert; |
| 11 | 11 | const log = std.log.scoped(.codegen); |
| 12 | 12 | |
| 13 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 14 | return comptime &.initEmpty(); | |
| 13 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 14 | return null; | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | pub fn generate( |
src/arch/riscv64/CodeGen.zig+2-2| ... | ... | @@ -51,8 +51,8 @@ const Instruction = encoding.Instruction; |
| 51 | 51 | |
| 52 | 52 | const InnerError = CodeGenError || error{OutOfRegisters}; |
| 53 | 53 | |
| 54 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 55 | return comptime &.initEmpty(); | |
| 54 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 55 | return null; | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | pt: Zcu.PerThread, |
src/arch/sparc64/CodeGen.zig+2-2| ... | ... | @@ -41,8 +41,8 @@ const Self = @This(); |
| 41 | 41 | |
| 42 | 42 | const InnerError = CodeGenError || error{OutOfRegisters}; |
| 43 | 43 | |
| 44 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 45 | return comptime &.initEmpty(); | |
| 44 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 45 | return null; | |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | const RegisterView = enum(u1) { |
src/arch/wasm/CodeGen.zig+2-2| ... | ... | @@ -31,8 +31,8 @@ const libcFloatSuffix = target_util.libcFloatSuffix; |
| 31 | 31 | const compilerRtFloatAbbrev = target_util.compilerRtFloatAbbrev; |
| 32 | 32 | const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev; |
| 33 | 33 | |
| 34 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 35 | return comptime &.initEmpty(); | |
| 34 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 35 | return null; | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /// Reference to the function declaration the code |
src/codegen.zig+23-7| ... | ... | @@ -27,9 +27,22 @@ pub const CodeGenError = GenerateSymbolError || error{ |
| 27 | 27 | CodegenFail, |
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Feature { | |
| 31 | comptime assert(mem.startsWith(u8, @tagName(backend), "stage2_")); | |
| 32 | return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend"); | |
| 30 | fn devFeatureForBackend(backend: std.builtin.CompilerBackend) dev.Feature { | |
| 31 | return switch (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 | 48 | 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 | 66 | const zcu = pt.zcu; |
| 54 | 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 | 69 | else => unreachable, |
| 57 | 70 | inline .stage2_llvm, |
| 58 | 71 | .stage2_c, |
| ... | ... | @@ -65,8 +78,11 @@ pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) *con |
| 65 | 78 | .stage2_sparc64, |
| 66 | 79 | .stage2_spirv64, |
| 67 | 80 | .stage2_powerpc, |
| 68 | => |backend| importBackend(backend).legalizeFeatures(target), | |
| 69 | }; | |
| 81 | => |backend| { | |
| 82 | dev.check(devFeatureForBackend(backend)); | |
| 83 | return importBackend(backend).legalizeFeatures(target); | |
| 84 | }, | |
| 85 | } | |
| 70 | 86 | } |
| 71 | 87 | |
| 72 | 88 | pub fn generateFunction( |
src/codegen/c.zig+7-3| ... | ... | @@ -20,8 +20,8 @@ const Alignment = InternPool.Alignment; |
| 20 | 20 | const BigIntLimb = std.math.big.Limb; |
| 21 | 21 | const BigInt = std.math.big.int; |
| 22 | 22 | |
| 23 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 24 | return comptime &.initEmpty(); | |
| 23 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 24 | return null; | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | pub const CType = @import("c/Type.zig"); |
| ... | ... | @@ -210,7 +210,6 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{ |
| 210 | 210 | .{ "atomic_ushort", {} }, |
| 211 | 211 | .{ "atomic_wchar_t", {} }, |
| 212 | 212 | .{ "auto", {} }, |
| 213 | .{ "bool", {} }, | |
| 214 | 213 | .{ "break", {} }, |
| 215 | 214 | .{ "case", {} }, |
| 216 | 215 | .{ "char", {} }, |
| ... | ... | @@ -270,6 +269,11 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{ |
| 270 | 269 | .{ "va_end", {} }, |
| 271 | 270 | .{ "va_copy", {} }, |
| 272 | 271 | |
| 272 | // stdbool.h | |
| 273 | .{ "bool", {} }, | |
| 274 | .{ "false", {} }, | |
| 275 | .{ "true", {} }, | |
| 276 | ||
| 273 | 277 | // stddef.h |
| 274 | 278 | .{ "offsetof", {} }, |
| 275 | 279 |
src/codegen/llvm.zig+2-2| ... | ... | @@ -36,8 +36,8 @@ const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev; |
| 36 | 36 | |
| 37 | 37 | const Error = error{ OutOfMemory, CodegenFail }; |
| 38 | 38 | |
| 39 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 40 | return comptime &.initEmpty(); | |
| 39 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 40 | return null; | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 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 | 28 | |
| 29 | 29 | const InstMap = std.AutoHashMapUnmanaged(Air.Inst.Index, IdRef); |
| 30 | 30 | |
| 31 | pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features { | |
| 32 | return comptime &.initEmpty(); | |
| 31 | pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features { | |
| 32 | return null; | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | pub const zig_call_abi_ver = 3; |
src/dev.zig+3| ... | ... | @@ -67,6 +67,7 @@ pub const Env = enum { |
| 67 | 67 | .incremental, |
| 68 | 68 | .ast_gen, |
| 69 | 69 | .sema, |
| 70 | .legalize, | |
| 70 | 71 | .llvm_backend, |
| 71 | 72 | .c_backend, |
| 72 | 73 | .wasm_backend, |
| ... | ... | @@ -144,6 +145,7 @@ pub const Env = enum { |
| 144 | 145 | .build_command, |
| 145 | 146 | .stdio_listen, |
| 146 | 147 | .incremental, |
| 148 | .legalize, | |
| 147 | 149 | .x86_64_backend, |
| 148 | 150 | .elf_linker, |
| 149 | 151 | => true, |
| ... | ... | @@ -222,6 +224,7 @@ pub const Feature = enum { |
| 222 | 224 | incremental, |
| 223 | 225 | ast_gen, |
| 224 | 226 | sema, |
| 227 | legalize, | |
| 225 | 228 | |
| 226 | 229 | llvm_backend, |
| 227 | 230 | c_backend, |