authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-09 00:24:17-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-09 05:47:13-04:00
logc4848694d20c19b78657ee46f18028737290c829
treeaca82d4ff8c67dd985dead2c09be2ba9a9f956cb
parent151c06cce40f33649fa96937d53926a7769491b9

llvm: enable even without libllvm linked


8 files changed, 112 insertions(+), 168 deletions(-)

src/Compilation.zig+2-2
...@@ -1027,7 +1027,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1027,7 +1027,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1027 return error.TargetRequiresSingleThreaded;1027 return error.TargetRequiresSingleThreaded;
1028 }1028 }
10291029
1030 const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: {1030 const llvm_cpu_features: ?[*:0]const u8 = if (use_llvm) blk: {
1031 var buf = std.ArrayList(u8).init(arena);1031 var buf = std.ArrayList(u8).init(arena);
1032 for (options.target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| {1032 for (options.target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| {
1033 const index = @as(Target.Cpu.Feature.Set.Index, @intCast(index_usize));1033 const index = @as(Target.Cpu.Feature.Set.Index, @intCast(index_usize));
...@@ -5182,7 +5182,7 @@ pub fn dump_argv(argv: []const []const u8) void {...@@ -5182,7 +5182,7 @@ pub fn dump_argv(argv: []const []const u8) void {
5182}5182}
51835183
5184pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend {5184pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend {
5185 if (build_options.have_llvm and comp.bin_file.options.use_llvm) return .stage2_llvm;5185 if (comp.bin_file.options.use_llvm) return .stage2_llvm;
5186 const target = comp.bin_file.options.target;5186 const target = comp.bin_file.options.target;
5187 if (target.ofmt == .c) return .stage2_c;5187 if (target.ofmt == .c) return .stage2_c;
5188 return switch (target.cpu.arch) {5188 return switch (target.cpu.arch) {
src/codegen/llvm.zig+42-33
...@@ -8,7 +8,7 @@ const native_endian = builtin.cpu.arch.endian();...@@ -8,7 +8,7 @@ const native_endian = builtin.cpu.arch.endian();
8const DW = std.dwarf;8const DW = std.dwarf;
99
10const Builder = @import("llvm/Builder.zig");10const Builder = @import("llvm/Builder.zig");
11const llvm = if (build_options.have_llvm or true)11const llvm = if (build_options.have_llvm)
12 @import("llvm/bindings.zig")12 @import("llvm/bindings.zig")
13else13else
14 @compileError("LLVM unavailable");14 @compileError("LLVM unavailable");
...@@ -764,15 +764,37 @@ pub const Object = struct {...@@ -764,15 +764,37 @@ pub const Object = struct {
764 builder: Builder,764 builder: Builder,
765765
766 module: *Module,766 module: *Module,
767 di_builder: ?*llvm.DIBuilder,767 di_builder: ?if (build_options.have_llvm) *llvm.DIBuilder else noreturn,
768 /// One of these mappings:768 /// One of these mappings:
769 /// - *Module.File => *DIFile769 /// - *Module.File => *DIFile
770 /// - *Module.Decl (Fn) => *DISubprogram770 /// - *Module.Decl (Fn) => *DISubprogram
771 /// - *Module.Decl (Non-Fn) => *DIGlobalVariable771 /// - *Module.Decl (Non-Fn) => *DIGlobalVariable
772 di_map: std.AutoHashMapUnmanaged(*const anyopaque, *llvm.DINode),772 di_map: if (build_options.have_llvm) std.AutoHashMapUnmanaged(*const anyopaque, *llvm.DINode) else struct {
773 di_compile_unit: ?*llvm.DICompileUnit,773 const K = *const anyopaque;
774 target_machine: *llvm.TargetMachine,774 const V = noreturn;
775 target_data: *llvm.TargetData,775
776 const Self = @This();
777
778 metadata: ?noreturn = null,
779 size: Size = 0,
780 available: Size = 0,
781
782 pub const Size = u0;
783
784 pub fn deinit(self: *Self, allocator: Allocator) void {
785 _ = allocator;
786 self.* = undefined;
787 }
788
789 pub fn get(self: Self, key: K) ?V {
790 _ = self;
791 _ = key;
792 return null;
793 }
794 },
795 di_compile_unit: ?if (build_options.have_llvm) *llvm.DICompileUnit else noreturn,
796 target_machine: if (build_options.have_llvm) *llvm.TargetMachine else void,
797 target_data: if (build_options.have_llvm) *llvm.TargetData else void,
776 target: std.Target,798 target: std.Target,
777 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,799 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,
778 /// but that has some downsides:800 /// but that has some downsides:
...@@ -830,8 +852,8 @@ pub const Object = struct {...@@ -830,8 +852,8 @@ pub const Object = struct {
830 });852 });
831 errdefer builder.deinit();853 errdefer builder.deinit();
832854
833 var target_machine: *llvm.TargetMachine = undefined;855 var target_machine: if (build_options.have_llvm) *llvm.TargetMachine else void = undefined;
834 var target_data: *llvm.TargetData = undefined;856 var target_data: if (build_options.have_llvm) *llvm.TargetData else void = undefined;
835 if (builder.useLibLlvm()) {857 if (builder.useLibLlvm()) {
836 if (!options.strip) {858 if (!options.strip) {
837 switch (options.target.ofmt) {859 switch (options.target.ofmt) {
...@@ -946,7 +968,7 @@ pub const Object = struct {...@@ -946,7 +968,7 @@ pub const Object = struct {
946 .module = options.module.?,968 .module = options.module.?,
947 .di_map = .{},969 .di_map = .{},
948 .di_builder = if (builder.useLibLlvm()) builder.llvm.di_builder else null, // TODO970 .di_builder = if (builder.useLibLlvm()) builder.llvm.di_builder else null, // TODO
949 .di_compile_unit = builder.llvm.di_compile_unit,971 .di_compile_unit = if (builder.useLibLlvm()) builder.llvm.di_compile_unit else null,
950 .target_machine = target_machine,972 .target_machine = target_machine,
951 .target_data = target_data,973 .target_data = target_data,
952 .target = options.target,974 .target = options.target,
...@@ -961,9 +983,9 @@ pub const Object = struct {...@@ -961,9 +983,9 @@ pub const Object = struct {
961 }983 }
962984
963 pub fn deinit(self: *Object, gpa: Allocator) void {985 pub fn deinit(self: *Object, gpa: Allocator) void {
986 self.di_map.deinit(gpa);
987 self.di_type_map.deinit(gpa);
964 if (self.builder.useLibLlvm()) {988 if (self.builder.useLibLlvm()) {
965 self.di_map.deinit(gpa);
966 self.di_type_map.deinit(gpa);
967 self.target_data.dispose();989 self.target_data.dispose();
968 self.target_machine.dispose();990 self.target_machine.dispose();
969 }991 }
...@@ -1519,8 +1541,8 @@ pub const Object = struct {...@@ -1519,8 +1541,8 @@ pub const Object = struct {
15191541
1520 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);1542 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);
15211543
1522 var di_file: ?*llvm.DIFile = null;1544 var di_file: ?if (build_options.have_llvm) *llvm.DIFile else noreturn = null;
1523 var di_scope: ?*llvm.DIScope = null;1545 var di_scope: ?if (build_options.have_llvm) *llvm.DIScope else noreturn = null;
15241546
1525 if (o.di_builder) |dib| {1547 if (o.di_builder) |dib| {
1526 di_file = try o.getDIFile(gpa, mod.namespacePtr(decl.src_namespace).file_scope);1548 di_file = try o.getDIFile(gpa, mod.namespacePtr(decl.src_namespace).file_scope);
...@@ -4425,7 +4447,8 @@ pub const DeclGen = struct {...@@ -4425,7 +4447,8 @@ pub const DeclGen = struct {
4425 }, &o.builder);4447 }, &o.builder);
44264448
4427 if (o.di_builder) |dib| {4449 if (o.di_builder) |dib| {
4428 const di_file = try o.getDIFile(o.gpa, mod.namespacePtr(decl.src_namespace).file_scope);4450 const di_file =
4451 try o.getDIFile(o.gpa, mod.namespacePtr(decl.src_namespace).file_scope);
44294452
4430 const line_number = decl.src_line + 1;4453 const line_number = decl.src_line + 1;
4431 const is_internal_linkage = !o.module.decl_exports.contains(decl_index);4454 const is_internal_linkage = !o.module.decl_exports.contains(decl_index);
...@@ -4453,18 +4476,18 @@ pub const FuncGen = struct {...@@ -4453,18 +4476,18 @@ pub const FuncGen = struct {
4453 air: Air,4476 air: Air,
4454 liveness: Liveness,4477 liveness: Liveness,
4455 wip: Builder.WipFunction,4478 wip: Builder.WipFunction,
4456 di_scope: ?*llvm.DIScope,4479 di_scope: ?if (build_options.have_llvm) *llvm.DIScope else noreturn,
4457 di_file: ?*llvm.DIFile,4480 di_file: ?if (build_options.have_llvm) *llvm.DIFile else noreturn,
4458 base_line: u32,4481 base_line: u32,
4459 prev_dbg_line: c_uint,4482 prev_dbg_line: c_uint,
4460 prev_dbg_column: c_uint,4483 prev_dbg_column: c_uint,
44614484
4462 /// Stack of locations where a call was inlined.4485 /// Stack of locations where a call was inlined.
4463 dbg_inlined: std.ArrayListUnmanaged(DbgState) = .{},4486 dbg_inlined: std.ArrayListUnmanaged(if (build_options.have_llvm) DbgState else void) = .{},
44644487
4465 /// Stack of `DILexicalBlock`s. dbg_block instructions cannot happend accross4488 /// Stack of `DILexicalBlock`s. dbg_block instructions cannot happend accross
4466 /// dbg_inline instructions so no special handling there is required.4489 /// dbg_inline instructions so no special handling there is required.
4467 dbg_block_stack: std.ArrayListUnmanaged(*llvm.DIScope) = .{},4490 dbg_block_stack: std.ArrayListUnmanaged(if (build_options.have_llvm) *llvm.DIScope else void) = .{},
44684491
4469 /// This stores the LLVM values used in a function, such that they can be referred to4492 /// This stores the LLVM values used in a function, such that they can be referred to
4470 /// in other instructions. This table is cleared before every function is generated.4493 /// in other instructions. This table is cleared before every function is generated.
...@@ -4495,7 +4518,7 @@ pub const FuncGen = struct {...@@ -4495,7 +4518,7 @@ pub const FuncGen = struct {
44954518
4496 sync_scope: Builder.SyncScope,4519 sync_scope: Builder.SyncScope,
44974520
4498 const DbgState = struct { loc: *llvm.DILocation, scope: *llvm.DIScope, base_line: u32 };4521 const DbgState = if (build_options.have_llvm) struct { loc: *llvm.DILocation, scope: *llvm.DIScope, base_line: u32 } else struct {};
4499 const BreakList = union {4522 const BreakList = union {
4500 list: std.MultiArrayList(struct {4523 list: std.MultiArrayList(struct {
4501 bb: Builder.Function.Block.Index,4524 bb: Builder.Function.Block.Index,
...@@ -6230,8 +6253,6 @@ pub const FuncGen = struct {...@@ -6230,8 +6253,6 @@ pub const FuncGen = struct {
6230 }6253 }
62316254
6232 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6255 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6233 if (!self.dg.object.builder.useLibLlvm()) return .none;
6234
6235 const di_scope = self.di_scope orelse return .none;6256 const di_scope = self.di_scope orelse return .none;
6236 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;6257 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;
6237 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);6258 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);
...@@ -6251,8 +6272,6 @@ pub const FuncGen = struct {...@@ -6251,8 +6272,6 @@ pub const FuncGen = struct {
62516272
6252 fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6273 fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6253 const o = self.dg.object;6274 const o = self.dg.object;
6254 if (!o.builder.useLibLlvm()) return .none;
6255
6256 const dib = o.di_builder orelse return .none;6275 const dib = o.di_builder orelse return .none;
6257 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;6276 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;
62586277
...@@ -6311,8 +6330,6 @@ pub const FuncGen = struct {...@@ -6311,8 +6330,6 @@ pub const FuncGen = struct {
63116330
6312 fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6331 fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6313 const o = self.dg.object;6332 const o = self.dg.object;
6314 if (!o.builder.useLibLlvm()) return .none;
6315
6316 if (o.di_builder == null) return .none;6333 if (o.di_builder == null) return .none;
6317 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;6334 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;
63186335
...@@ -6328,8 +6345,6 @@ pub const FuncGen = struct {...@@ -6328,8 +6345,6 @@ pub const FuncGen = struct {
63286345
6329 fn airDbgBlockBegin(self: *FuncGen) !Builder.Value {6346 fn airDbgBlockBegin(self: *FuncGen) !Builder.Value {
6330 const o = self.dg.object;6347 const o = self.dg.object;
6331 if (!o.builder.useLibLlvm()) return .none;
6332
6333 const dib = o.di_builder orelse return .none;6348 const dib = o.di_builder orelse return .none;
6334 const old_scope = self.di_scope.?;6349 const old_scope = self.di_scope.?;
6335 try self.dbg_block_stack.append(self.gpa, old_scope);6350 try self.dbg_block_stack.append(self.gpa, old_scope);
...@@ -6340,8 +6355,6 @@ pub const FuncGen = struct {...@@ -6340,8 +6355,6 @@ pub const FuncGen = struct {
63406355
6341 fn airDbgBlockEnd(self: *FuncGen) !Builder.Value {6356 fn airDbgBlockEnd(self: *FuncGen) !Builder.Value {
6342 const o = self.dg.object;6357 const o = self.dg.object;
6343 if (!o.builder.useLibLlvm()) return .none;
6344
6345 if (o.di_builder == null) return .none;6358 if (o.di_builder == null) return .none;
6346 self.di_scope = self.dbg_block_stack.pop();6359 self.di_scope = self.dbg_block_stack.pop();
6347 return .none;6360 return .none;
...@@ -6349,8 +6362,6 @@ pub const FuncGen = struct {...@@ -6349,8 +6362,6 @@ pub const FuncGen = struct {
63496362
6350 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6363 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6351 const o = self.dg.object;6364 const o = self.dg.object;
6352 if (!o.builder.useLibLlvm()) return .none;
6353
6354 const mod = o.module;6365 const mod = o.module;
6355 const dib = o.di_builder orelse return .none;6366 const dib = o.di_builder orelse return .none;
6356 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6367 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
...@@ -6379,8 +6390,6 @@ pub const FuncGen = struct {...@@ -6379,8 +6390,6 @@ pub const FuncGen = struct {
63796390
6380 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6391 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6381 const o = self.dg.object;6392 const o = self.dg.object;
6382 if (!o.builder.useLibLlvm()) return .none;
6383
6384 const dib = o.di_builder orelse return .none;6393 const dib = o.di_builder orelse return .none;
6385 const pl_op = self.air.instructions.items(.data)[inst].pl_op;6394 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
6386 const operand = try self.resolveInst(pl_op.operand);6395 const operand = try self.resolveInst(pl_op.operand);
src/codegen/llvm/Builder.zig+19-19
...@@ -5868,7 +5868,7 @@ pub const WipFunction = struct {...@@ -5868,7 +5868,7 @@ pub const WipFunction = struct {
5868 vals: []const Value,5868 vals: []const Value,
5869 blocks: []const Block.Index,5869 blocks: []const Block.Index,
5870 wip: *WipFunction,5870 wip: *WipFunction,
5871 ) if (build_options.have_llvm) Allocator.Error!void else void {5871 ) (if (build_options.have_llvm) Allocator.Error else error{})!void {
5872 const incoming_len = self.block.ptrConst(wip).incoming;5872 const incoming_len = self.block.ptrConst(wip).incoming;
5873 assert(vals.len == incoming_len and blocks.len == incoming_len);5873 assert(vals.len == incoming_len and blocks.len == incoming_len);
5874 const instruction = wip.instructions.get(@intFromEnum(self.instruction));5874 const instruction = wip.instructions.get(@intFromEnum(self.instruction));
...@@ -8389,9 +8389,9 @@ pub fn fnType(...@@ -8389,9 +8389,9 @@ pub fn fnType(
8389 kind: Type.Function.Kind,8389 kind: Type.Function.Kind,
8390) Allocator.Error!Type {8390) Allocator.Error!Type {
8391 try self.ensureUnusedTypeCapacity(1, Type.Function, params.len);8391 try self.ensureUnusedTypeCapacity(1, Type.Function, params.len);
8392 return switch (kind) {8392 switch (kind) {
8393 inline else => |comptime_kind| self.fnTypeAssumeCapacity(ret, params, comptime_kind),8393 inline else => |comptime_kind| return self.fnTypeAssumeCapacity(ret, params, comptime_kind),
8394 };8394 }
8395}8395}
83968396
8397pub fn intType(self: *Builder, bits: u24) Allocator.Error!Type {8397pub fn intType(self: *Builder, bits: u24) Allocator.Error!Type {
...@@ -8411,9 +8411,9 @@ pub fn vectorType(...@@ -8411,9 +8411,9 @@ pub fn vectorType(
8411 child: Type,8411 child: Type,
8412) Allocator.Error!Type {8412) Allocator.Error!Type {
8413 try self.ensureUnusedTypeCapacity(1, Type.Vector, 0);8413 try self.ensureUnusedTypeCapacity(1, Type.Vector, 0);
8414 return switch (kind) {8414 switch (kind) {
8415 inline else => |comptime_kind| self.vectorTypeAssumeCapacity(comptime_kind, len, child),8415 inline else => |comptime_kind| return self.vectorTypeAssumeCapacity(comptime_kind, len, child),
8416 };8416 }
8417}8417}
84188418
8419pub fn arrayType(self: *Builder, len: u64, child: Type) Allocator.Error!Type {8419pub fn arrayType(self: *Builder, len: u64, child: Type) Allocator.Error!Type {
...@@ -8428,9 +8428,9 @@ pub fn structType(...@@ -8428,9 +8428,9 @@ pub fn structType(
8428 fields: []const Type,8428 fields: []const Type,
8429) Allocator.Error!Type {8429) Allocator.Error!Type {
8430 try self.ensureUnusedTypeCapacity(1, Type.Structure, fields.len);8430 try self.ensureUnusedTypeCapacity(1, Type.Structure, fields.len);
8431 return switch (kind) {8431 switch (kind) {
8432 inline else => |comptime_kind| self.structTypeAssumeCapacity(comptime_kind, fields),8432 inline else => |comptime_kind| return self.structTypeAssumeCapacity(comptime_kind, fields),
8433 };8433 }
8434}8434}
84358435
8436pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type {8436pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type {
...@@ -8450,7 +8450,7 @@ pub fn namedTypeSetBody(...@@ -8450,7 +8450,7 @@ pub fn namedTypeSetBody(
8450 self: *Builder,8450 self: *Builder,
8451 named_type: Type,8451 named_type: Type,
8452 body_type: Type,8452 body_type: Type,
8453) if (build_options.have_llvm) Allocator.Error!void else void {8453) (if (build_options.have_llvm) Allocator.Error else error{})!void {
8454 const named_item = self.type_items.items[@intFromEnum(named_type)];8454 const named_item = self.type_items.items[@intFromEnum(named_type)];
8455 self.type_extra.items[named_item.data + std.meta.fieldIndex(Type.NamedStructure, "body").?] =8455 self.type_extra.items[named_item.data + std.meta.fieldIndex(Type.NamedStructure, "body").?] =
8456 @intFromEnum(body_type);8456 @intFromEnum(body_type);
...@@ -9985,7 +9985,7 @@ fn fnTypeAssumeCapacity(...@@ -9985,7 +9985,7 @@ fn fnTypeAssumeCapacity(
9985 ret: Type,9985 ret: Type,
9986 params: []const Type,9986 params: []const Type,
9987 comptime kind: Type.Function.Kind,9987 comptime kind: Type.Function.Kind,
9988) if (build_options.have_llvm) Allocator.Error!Type else Type {9988) (if (build_options.have_llvm) Allocator.Error else error{})!Type {
9989 const tag: Type.Tag = switch (kind) {9989 const tag: Type.Tag = switch (kind) {
9990 .normal => .function,9990 .normal => .function,
9991 .vararg => .vararg_function,9991 .vararg => .vararg_function,
...@@ -10169,7 +10169,7 @@ fn structTypeAssumeCapacity(...@@ -10169,7 +10169,7 @@ fn structTypeAssumeCapacity(
10169 self: *Builder,10169 self: *Builder,
10170 comptime kind: Type.Structure.Kind,10170 comptime kind: Type.Structure.Kind,
10171 fields: []const Type,10171 fields: []const Type,
10172) if (build_options.have_llvm) Allocator.Error!Type else Type {10172) (if (build_options.have_llvm) Allocator.Error else error{})!Type {
10173 const tag: Type.Tag = switch (kind) {10173 const tag: Type.Tag = switch (kind) {
10174 .normal => .structure,10174 .normal => .structure,
10175 .@"packed" => .packed_structure,10175 .@"packed" => .packed_structure,
...@@ -10397,7 +10397,7 @@ fn bigIntConstAssumeCapacity(...@@ -10397,7 +10397,7 @@ fn bigIntConstAssumeCapacity(
10397 self: *Builder,10397 self: *Builder,
10398 ty: Type,10398 ty: Type,
10399 value: std.math.big.int.Const,10399 value: std.math.big.int.Const,
10400) if (build_options.have_llvm) Allocator.Error!Constant else Constant {10400) Allocator.Error!Constant {
10401 const type_item = self.type_items.items[@intFromEnum(ty)];10401 const type_item = self.type_items.items[@intFromEnum(ty)];
10402 assert(type_item.tag == .integer);10402 assert(type_item.tag == .integer);
10403 const bits = type_item.data;10403 const bits = type_item.data;
...@@ -10743,7 +10743,7 @@ fn structConstAssumeCapacity(...@@ -10743,7 +10743,7 @@ fn structConstAssumeCapacity(
10743 self: *Builder,10743 self: *Builder,
10744 ty: Type,10744 ty: Type,
10745 vals: []const Constant,10745 vals: []const Constant,
10746) if (build_options.have_llvm) Allocator.Error!Constant else Constant {10746) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10747 const type_item = self.type_items.items[@intFromEnum(ty)];10747 const type_item = self.type_items.items[@intFromEnum(ty)];
10748 var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) {10748 var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) {
10749 .structure, .packed_structure => type_item.data,10749 .structure, .packed_structure => type_item.data,
...@@ -10791,7 +10791,7 @@ fn arrayConstAssumeCapacity(...@@ -10791,7 +10791,7 @@ fn arrayConstAssumeCapacity(
10791 self: *Builder,10791 self: *Builder,
10792 ty: Type,10792 ty: Type,
10793 vals: []const Constant,10793 vals: []const Constant,
10794) if (build_options.have_llvm) Allocator.Error!Constant else Constant {10794) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10795 const type_item = self.type_items.items[@intFromEnum(ty)];10795 const type_item = self.type_items.items[@intFromEnum(ty)];
10796 const type_extra: struct { len: u64, child: Type } = switch (type_item.tag) {10796 const type_extra: struct { len: u64, child: Type } = switch (type_item.tag) {
10797 inline .small_array, .array => |kind| extra: {10797 inline .small_array, .array => |kind| extra: {
...@@ -10859,7 +10859,7 @@ fn vectorConstAssumeCapacity(...@@ -10859,7 +10859,7 @@ fn vectorConstAssumeCapacity(
10859 self: *Builder,10859 self: *Builder,
10860 ty: Type,10860 ty: Type,
10861 vals: []const Constant,10861 vals: []const Constant,
10862) if (build_options.have_llvm) Allocator.Error!Constant else Constant {10862) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10863 assert(ty.isVector(self));10863 assert(ty.isVector(self));
10864 assert(ty.vectorLen(self) == vals.len);10864 assert(ty.vectorLen(self) == vals.len);
10865 for (vals) |val| assert(ty.childType(self) == val.typeOf(self));10865 for (vals) |val| assert(ty.childType(self) == val.typeOf(self));
...@@ -10893,7 +10893,7 @@ fn splatConstAssumeCapacity(...@@ -10893,7 +10893,7 @@ fn splatConstAssumeCapacity(
10893 self: *Builder,10893 self: *Builder,
10894 ty: Type,10894 ty: Type,
10895 val: Constant,10895 val: Constant,
10896) if (build_options.have_llvm) Allocator.Error!Constant else Constant {10896) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10897 assert(ty.scalarType(self) == val.typeOf(self));10897 assert(ty.scalarType(self) == val.typeOf(self));
1089810898
10899 if (!ty.isVector(self)) return val;10899 if (!ty.isVector(self)) return val;
...@@ -11182,7 +11182,7 @@ fn gepConstAssumeCapacity(...@@ -11182,7 +11182,7 @@ fn gepConstAssumeCapacity(
11182 base: Constant,11182 base: Constant,
11183 inrange: ?u16,11183 inrange: ?u16,
11184 indices: []const Constant,11184 indices: []const Constant,
11185) if (build_options.have_llvm) Allocator.Error!Constant else Constant {11185) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
11186 const tag: Constant.Tag = switch (kind) {11186 const tag: Constant.Tag = switch (kind) {
11187 .normal => .getelementptr,11187 .normal => .getelementptr,
11188 .inbounds => .@"getelementptr inbounds",11188 .inbounds => .@"getelementptr inbounds",
src/link/Coff.zig+14-27
...@@ -225,7 +225,7 @@ pub const min_text_capacity = padToIdeal(minimum_text_block_size);...@@ -225,7 +225,7 @@ pub const min_text_capacity = padToIdeal(minimum_text_block_size);
225pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Coff {225pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Coff {
226 assert(options.target.ofmt == .coff);226 assert(options.target.ofmt == .coff);
227227
228 if (build_options.have_llvm and options.use_llvm) {228 if (options.use_llvm) {
229 return createEmpty(allocator, options);229 return createEmpty(allocator, options);
230 }230 }
231231
...@@ -267,8 +267,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {...@@ -267,8 +267,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {
267 .data_directories = comptime mem.zeroes([coff.IMAGE_NUMBEROF_DIRECTORY_ENTRIES]coff.ImageDataDirectory),267 .data_directories = comptime mem.zeroes([coff.IMAGE_NUMBEROF_DIRECTORY_ENTRIES]coff.ImageDataDirectory),
268 };268 };
269269
270 const use_llvm = build_options.have_llvm and options.use_llvm;270 if (options.use_llvm) {
271 if (use_llvm) {
272 self.llvm_object = try LlvmObject.create(gpa, options);271 self.llvm_object = try LlvmObject.create(gpa, options);
273 }272 }
274 return self;273 return self;
...@@ -277,9 +276,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {...@@ -277,9 +276,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {
277pub fn deinit(self: *Coff) void {276pub fn deinit(self: *Coff) void {
278 const gpa = self.base.allocator;277 const gpa = self.base.allocator;
279278
280 if (build_options.have_llvm) {279 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
281 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
282 }
283280
284 for (self.objects.items) |*object| {281 for (self.objects.items) |*object| {
285 object.deinit(gpa);282 object.deinit(gpa);
...@@ -1036,10 +1033,8 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:...@@ -1036,10 +1033,8 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
1036 if (build_options.skip_non_native and builtin.object_format != .coff) {1033 if (build_options.skip_non_native and builtin.object_format != .coff) {
1037 @panic("Attempted to compile for object format that was disabled by build configuration");1034 @panic("Attempted to compile for object format that was disabled by build configuration");
1038 }1035 }
1039 if (build_options.have_llvm) {1036 if (self.llvm_object) |llvm_object| {
1040 if (self.llvm_object) |llvm_object| {1037 return llvm_object.updateFunc(mod, func_index, air, liveness);
1041 return llvm_object.updateFunc(mod, func_index, air, liveness);
1042 }
1043 }1038 }
1044 const tracy = trace(@src());1039 const tracy = trace(@src());
1045 defer tracy.end();1040 defer tracy.end();
...@@ -1147,9 +1142,7 @@ pub fn updateDecl(...@@ -1147,9 +1142,7 @@ pub fn updateDecl(
1147 if (build_options.skip_non_native and builtin.object_format != .coff) {1142 if (build_options.skip_non_native and builtin.object_format != .coff) {
1148 @panic("Attempted to compile for object format that was disabled by build configuration");1143 @panic("Attempted to compile for object format that was disabled by build configuration");
1149 }1144 }
1150 if (build_options.have_llvm) {1145 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1151 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1152 }
1153 const tracy = trace(@src());1146 const tracy = trace(@src());
1154 defer tracy.end();1147 defer tracy.end();
11551148
...@@ -1390,9 +1383,7 @@ fn freeUnnamedConsts(self: *Coff, decl_index: Module.Decl.Index) void {...@@ -1390,9 +1383,7 @@ fn freeUnnamedConsts(self: *Coff, decl_index: Module.Decl.Index) void {
1390}1383}
13911384
1392pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void {1385pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void {
1393 if (build_options.have_llvm) {1386 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
1394 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
1395 }
13961387
1397 const mod = self.base.options.module.?;1388 const mod = self.base.options.module.?;
1398 const decl = mod.declPtr(decl_index);1389 const decl = mod.declPtr(decl_index);
...@@ -1419,7 +1410,7 @@ pub fn updateDeclExports(...@@ -1419,7 +1410,7 @@ pub fn updateDeclExports(
14191410
1420 const ip = &mod.intern_pool;1411 const ip = &mod.intern_pool;
14211412
1422 if (build_options.have_llvm) {1413 if (self.base.options.use_llvm) {
1423 // Even in the case of LLVM, we need to notice certain exported symbols in order to1414 // Even in the case of LLVM, we need to notice certain exported symbols in order to
1424 // detect the default subsystem.1415 // detect the default subsystem.
1425 for (exports) |exp| {1416 for (exports) |exp| {
...@@ -1448,10 +1439,10 @@ pub fn updateDeclExports(...@@ -1448,10 +1439,10 @@ pub fn updateDeclExports(
1448 }1439 }
1449 }1440 }
1450 }1441 }
1451
1452 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
1453 }1442 }
14541443
1444 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
1445
1455 if (self.base.options.emit == null) return;1446 if (self.base.options.emit == null) return;
14561447
1457 const gpa = self.base.allocator;1448 const gpa = self.base.allocator;
...@@ -1583,10 +1574,8 @@ fn resolveGlobalSymbol(self: *Coff, current: SymbolWithLoc) !void {...@@ -1583,10 +1574,8 @@ fn resolveGlobalSymbol(self: *Coff, current: SymbolWithLoc) !void {
15831574
1584pub fn flush(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {1575pub fn flush(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
1585 if (self.base.options.emit == null) {1576 if (self.base.options.emit == null) {
1586 if (build_options.have_llvm) {1577 if (self.llvm_object) |llvm_object| {
1587 if (self.llvm_object) |llvm_object| {1578 return try llvm_object.flushModule(comp, prog_node);
1588 return try llvm_object.flushModule(comp, prog_node);
1589 }
1590 }1579 }
1591 return;1580 return;
1592 }1581 }
...@@ -1604,10 +1593,8 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -1604,10 +1593,8 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
1604 const tracy = trace(@src());1593 const tracy = trace(@src());
1605 defer tracy.end();1594 defer tracy.end();
16061595
1607 if (build_options.have_llvm) {1596 if (self.llvm_object) |llvm_object| {
1608 if (self.llvm_object) |llvm_object| {1597 return try llvm_object.flushModule(comp, prog_node);
1609 return try llvm_object.flushModule(comp, prog_node);
1610 }
1611 }1598 }
16121599
1613 var sub_prog_node = prog_node.start("COFF Flush", 0);1600 var sub_prog_node = prog_node.start("COFF Flush", 0);
src/link/Elf.zig+11-25
...@@ -225,7 +225,7 @@ pub const PtrWidth = enum { p32, p64 };...@@ -225,7 +225,7 @@ pub const PtrWidth = enum { p32, p64 };
225pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Elf {225pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Elf {
226 assert(options.target.ofmt == .elf);226 assert(options.target.ofmt == .elf);
227227
228 if (build_options.have_llvm and options.use_llvm) {228 if (options.use_llvm) {
229 return createEmpty(allocator, options);229 return createEmpty(allocator, options);
230 }230 }
231231
...@@ -304,7 +304,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {...@@ -304,7 +304,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
304 .ptr_width = ptr_width,304 .ptr_width = ptr_width,
305 .page_size = page_size,305 .page_size = page_size,
306 };306 };
307 const use_llvm = build_options.have_llvm and options.use_llvm;307 const use_llvm = options.use_llvm;
308 if (use_llvm) {308 if (use_llvm) {
309 self.llvm_object = try LlvmObject.create(gpa, options);309 self.llvm_object = try LlvmObject.create(gpa, options);
310 }310 }
...@@ -314,9 +314,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {...@@ -314,9 +314,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
314pub fn deinit(self: *Elf) void {314pub fn deinit(self: *Elf) void {
315 const gpa = self.base.allocator;315 const gpa = self.base.allocator;
316316
317 if (build_options.have_llvm) {317 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
318 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
319 }
320318
321 for (self.sections.items(.free_list)) |*free_list| {319 for (self.sections.items(.free_list)) |*free_list| {
322 free_list.deinit(gpa);320 free_list.deinit(gpa);
...@@ -1005,10 +1003,8 @@ pub fn markDirty(self: *Elf, shdr_index: u16, phdr_index: ?u16) void {...@@ -1005,10 +1003,8 @@ pub fn markDirty(self: *Elf, shdr_index: u16, phdr_index: ?u16) void {
10051003
1006pub fn flush(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {1004pub fn flush(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
1007 if (self.base.options.emit == null) {1005 if (self.base.options.emit == null) {
1008 if (build_options.have_llvm) {1006 if (self.llvm_object) |llvm_object| {
1009 if (self.llvm_object) |llvm_object| {1007 return try llvm_object.flushModule(comp, prog_node);
1010 return try llvm_object.flushModule(comp, prog_node);
1011 }
1012 }1008 }
1013 return;1009 return;
1014 }1010 }
...@@ -1026,10 +1022,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1026,10 +1022,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1026 const tracy = trace(@src());1022 const tracy = trace(@src());
1027 defer tracy.end();1023 defer tracy.end();
10281024
1029 if (build_options.have_llvm) {1025 if (self.llvm_object) |llvm_object| {
1030 if (self.llvm_object) |llvm_object| {1026 return try llvm_object.flushModule(comp, prog_node);
1031 return try llvm_object.flushModule(comp, prog_node);
1032 }
1033 }1027 }
10341028
1035 const gpa = self.base.allocator;1029 const gpa = self.base.allocator;
...@@ -2392,9 +2386,7 @@ fn freeUnnamedConsts(self: *Elf, decl_index: Module.Decl.Index) void {...@@ -2392,9 +2386,7 @@ fn freeUnnamedConsts(self: *Elf, decl_index: Module.Decl.Index) void {
2392}2386}
23932387
2394pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {2388pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {
2395 if (build_options.have_llvm) {2389 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
2396 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
2397 }
23982390
2399 const mod = self.base.options.module.?;2391 const mod = self.base.options.module.?;
2400 const decl = mod.declPtr(decl_index);2392 const decl = mod.declPtr(decl_index);
...@@ -2577,9 +2569,7 @@ pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: A...@@ -2577,9 +2569,7 @@ pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: A
2577 if (build_options.skip_non_native and builtin.object_format != .elf) {2569 if (build_options.skip_non_native and builtin.object_format != .elf) {
2578 @panic("Attempted to compile for object format that was disabled by build configuration");2570 @panic("Attempted to compile for object format that was disabled by build configuration");
2579 }2571 }
2580 if (build_options.have_llvm) {2572 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
2581 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
2582 }
25832573
2584 const tracy = trace(@src());2574 const tracy = trace(@src());
2585 defer tracy.end();2575 defer tracy.end();
...@@ -2637,9 +2627,7 @@ pub fn updateDecl(...@@ -2637,9 +2627,7 @@ pub fn updateDecl(
2637 if (build_options.skip_non_native and builtin.object_format != .elf) {2627 if (build_options.skip_non_native and builtin.object_format != .elf) {
2638 @panic("Attempted to compile for object format that was disabled by build configuration");2628 @panic("Attempted to compile for object format that was disabled by build configuration");
2639 }2629 }
2640 if (build_options.have_llvm) {2630 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
2641 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
2642 }
26432631
2644 const tracy = trace(@src());2632 const tracy = trace(@src());
2645 defer tracy.end();2633 defer tracy.end();
...@@ -2859,9 +2847,7 @@ pub fn updateDeclExports(...@@ -2859,9 +2847,7 @@ pub fn updateDeclExports(
2859 if (build_options.skip_non_native and builtin.object_format != .elf) {2847 if (build_options.skip_non_native and builtin.object_format != .elf) {
2860 @panic("Attempted to compile for object format that was disabled by build configuration");2848 @panic("Attempted to compile for object format that was disabled by build configuration");
2861 }2849 }
2862 if (build_options.have_llvm) {2850 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
2863 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
2864 }
28652851
2866 if (self.base.options.emit == null) return;2852 if (self.base.options.emit == null) return;
28672853
src/link/MachO.zig+12-27
...@@ -422,7 +422,6 @@ pub fn openPath(allocator: Allocator, options: link.Options) !*MachO {...@@ -422,7 +422,6 @@ pub fn openPath(allocator: Allocator, options: link.Options) !*MachO {
422pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {422pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
423 const cpu_arch = options.target.cpu.arch;423 const cpu_arch = options.target.cpu.arch;
424 const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000;424 const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000;
425 const use_llvm = build_options.have_llvm and options.use_llvm;
426425
427 const self = try gpa.create(MachO);426 const self = try gpa.create(MachO);
428 errdefer gpa.destroy(self);427 errdefer gpa.destroy(self);
...@@ -435,13 +434,13 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {...@@ -435,13 +434,13 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
435 .file = null,434 .file = null,
436 },435 },
437 .page_size = page_size,436 .page_size = page_size,
438 .mode = if (use_llvm or options.module == null or options.cache_mode == .whole)437 .mode = if (options.use_llvm or options.module == null or options.cache_mode == .whole)
439 .zld438 .zld
440 else439 else
441 .incremental,440 .incremental,
442 };441 };
443442
444 if (use_llvm) {443 if (options.use_llvm) {
445 self.llvm_object = try LlvmObject.create(gpa, options);444 self.llvm_object = try LlvmObject.create(gpa, options);
446 }445 }
447446
...@@ -452,10 +451,8 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {...@@ -452,10 +451,8 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
452451
453pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {452pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
454 if (self.base.options.emit == null) {453 if (self.base.options.emit == null) {
455 if (build_options.have_llvm) {454 if (self.llvm_object) |llvm_object| {
456 if (self.llvm_object) |llvm_object| {455 try llvm_object.flushModule(comp, prog_node);
457 try llvm_object.flushModule(comp, prog_node);
458 }
459 }456 }
460 return;457 return;
461 }458 }
...@@ -479,10 +476,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -479,10 +476,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
479 const tracy = trace(@src());476 const tracy = trace(@src());
480 defer tracy.end();477 defer tracy.end();
481478
482 if (build_options.have_llvm) {479 if (self.llvm_object) |llvm_object| {
483 if (self.llvm_object) |llvm_object| {480 return try llvm_object.flushModule(comp, prog_node);
484 return try llvm_object.flushModule(comp, prog_node);
485 }
486 }481 }
487482
488 var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);483 var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);
...@@ -1622,9 +1617,7 @@ fn resolveSymbolsInDylibs(self: *MachO, actions: *std.ArrayList(ResolveAction))...@@ -1622,9 +1617,7 @@ fn resolveSymbolsInDylibs(self: *MachO, actions: *std.ArrayList(ResolveAction))
1622pub fn deinit(self: *MachO) void {1617pub fn deinit(self: *MachO) void {
1623 const gpa = self.base.allocator;1618 const gpa = self.base.allocator;
16241619
1625 if (build_options.have_llvm) {1620 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
1626 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
1627 }
16281621
1629 if (self.d_sym) |*d_sym| {1622 if (self.d_sym) |*d_sym| {
1630 d_sym.deinit();1623 d_sym.deinit();
...@@ -1855,9 +1848,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air:...@@ -1855,9 +1848,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air:
1855 if (build_options.skip_non_native and builtin.object_format != .macho) {1848 if (build_options.skip_non_native and builtin.object_format != .macho) {
1856 @panic("Attempted to compile for object format that was disabled by build configuration");1849 @panic("Attempted to compile for object format that was disabled by build configuration");
1857 }1850 }
1858 if (build_options.have_llvm) {1851 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
1859 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
1860 }
1861 const tracy = trace(@src());1852 const tracy = trace(@src());
1862 defer tracy.end();1853 defer tracy.end();
18631854
...@@ -1979,9 +1970,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo...@@ -1979,9 +1970,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo
1979 if (build_options.skip_non_native and builtin.object_format != .macho) {1970 if (build_options.skip_non_native and builtin.object_format != .macho) {
1980 @panic("Attempted to compile for object format that was disabled by build configuration");1971 @panic("Attempted to compile for object format that was disabled by build configuration");
1981 }1972 }
1982 if (build_options.have_llvm) {1973 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1983 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1984 }
1985 const tracy = trace(@src());1974 const tracy = trace(@src());
1986 defer tracy.end();1975 defer tracy.end();
19871976
...@@ -2387,10 +2376,8 @@ pub fn updateDeclExports(...@@ -2387,10 +2376,8 @@ pub fn updateDeclExports(
2387 if (build_options.skip_non_native and builtin.object_format != .macho) {2376 if (build_options.skip_non_native and builtin.object_format != .macho) {
2388 @panic("Attempted to compile for object format that was disabled by build configuration");2377 @panic("Attempted to compile for object format that was disabled by build configuration");
2389 }2378 }
2390 if (build_options.have_llvm) {2379 if (self.llvm_object) |llvm_object|
2391 if (self.llvm_object) |llvm_object|2380 return llvm_object.updateDeclExports(mod, decl_index, exports);
2392 return llvm_object.updateDeclExports(mod, decl_index, exports);
2393 }
23942381
2395 if (self.base.options.emit == null) return;2382 if (self.base.options.emit == null) return;
23962383
...@@ -2542,9 +2529,7 @@ fn freeUnnamedConsts(self: *MachO, decl_index: Module.Decl.Index) void {...@@ -2542,9 +2529,7 @@ fn freeUnnamedConsts(self: *MachO, decl_index: Module.Decl.Index) void {
2542}2529}
25432530
2544pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {2531pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {
2545 if (build_options.have_llvm) {2532 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
2546 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
2547 }
2548 const mod = self.base.options.module.?;2533 const mod = self.base.options.module.?;
2549 const decl = mod.declPtr(decl_index);2534 const decl = mod.declPtr(decl_index);
25502535
src/link/NvPtx.zig-8
...@@ -27,7 +27,6 @@ llvm_object: *LlvmObject,...@@ -27,7 +27,6 @@ llvm_object: *LlvmObject,
27ptx_file_name: []const u8,27ptx_file_name: []const u8,
2828
29pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {29pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
30 if (!build_options.have_llvm) return error.PtxArchNotSupported;
31 if (!options.use_llvm) return error.PtxArchNotSupported;30 if (!options.use_llvm) return error.PtxArchNotSupported;
3231
33 if (!options.target.cpu.arch.isNvptx()) return error.PtxArchNotSupported;32 if (!options.target.cpu.arch.isNvptx()) return error.PtxArchNotSupported;
...@@ -55,7 +54,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {...@@ -55,7 +54,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
55}54}
5655
57pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*NvPtx {56pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*NvPtx {
58 if (!build_options.have_llvm) @panic("nvptx target requires a zig compiler with llvm enabled.");
59 if (!options.use_llvm) return error.PtxArchNotSupported;57 if (!options.use_llvm) return error.PtxArchNotSupported;
60 assert(options.target.ofmt == .nvptx);58 assert(options.target.ofmt == .nvptx);
6159
...@@ -64,18 +62,15 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option...@@ -64,18 +62,15 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
64}62}
6563
66pub fn deinit(self: *NvPtx) void {64pub fn deinit(self: *NvPtx) void {
67 if (!build_options.have_llvm) return;
68 self.llvm_object.destroy(self.base.allocator);65 self.llvm_object.destroy(self.base.allocator);
69 self.base.allocator.free(self.ptx_file_name);66 self.base.allocator.free(self.ptx_file_name);
70}67}
7168
72pub fn updateFunc(self: *NvPtx, module: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void {69pub fn updateFunc(self: *NvPtx, module: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void {
73 if (!build_options.have_llvm) return;
74 try self.llvm_object.updateFunc(module, func_index, air, liveness);70 try self.llvm_object.updateFunc(module, func_index, air, liveness);
75}71}
7672
77pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void {73pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void {
78 if (!build_options.have_llvm) return;
79 return self.llvm_object.updateDecl(module, decl_index);74 return self.llvm_object.updateDecl(module, decl_index);
80}75}
8176
...@@ -85,7 +80,6 @@ pub fn updateDeclExports(...@@ -85,7 +80,6 @@ pub fn updateDeclExports(
85 decl_index: Module.Decl.Index,80 decl_index: Module.Decl.Index,
86 exports: []const *Module.Export,81 exports: []const *Module.Export,
87) !void {82) !void {
88 if (!build_options.have_llvm) return;
89 if (build_options.skip_non_native and builtin.object_format != .nvptx) {83 if (build_options.skip_non_native and builtin.object_format != .nvptx) {
90 @panic("Attempted to compile for object format that was disabled by build configuration");84 @panic("Attempted to compile for object format that was disabled by build configuration");
91 }85 }
...@@ -93,7 +87,6 @@ pub fn updateDeclExports(...@@ -93,7 +87,6 @@ pub fn updateDeclExports(
93}87}
9488
95pub fn freeDecl(self: *NvPtx, decl_index: Module.Decl.Index) void {89pub fn freeDecl(self: *NvPtx, decl_index: Module.Decl.Index) void {
96 if (!build_options.have_llvm) return;
97 return self.llvm_object.freeDecl(decl_index);90 return self.llvm_object.freeDecl(decl_index);
98}91}
9992
...@@ -102,7 +95,6 @@ pub fn flush(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.Node) li...@@ -102,7 +95,6 @@ pub fn flush(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.Node) li
102}95}
10396
104pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {97pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
105 if (!build_options.have_llvm) return;
106 if (build_options.skip_non_native) {98 if (build_options.skip_non_native) {
107 @panic("Attempted to compile for architecture that was disabled by build configuration");99 @panic("Attempted to compile for architecture that was disabled by build configuration");
108 }100 }
src/link/Wasm.zig+12-27
...@@ -360,7 +360,7 @@ pub const StringTable = struct {...@@ -360,7 +360,7 @@ pub const StringTable = struct {
360pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Wasm {360pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Wasm {
361 assert(options.target.ofmt == .wasm);361 assert(options.target.ofmt == .wasm);
362362
363 if (build_options.have_llvm and options.use_llvm and options.use_lld) {363 if (options.use_llvm and options.use_lld) {
364 return createEmpty(allocator, options);364 return createEmpty(allocator, options);
365 }365 }
366366
...@@ -522,8 +522,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {...@@ -522,8 +522,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {
522 .name = undefined,522 .name = undefined,
523 };523 };
524524
525 const use_llvm = build_options.have_llvm and options.use_llvm;525 if (options.use_llvm) {
526 if (use_llvm) {
527 wasm.llvm_object = try LlvmObject.create(gpa, options);526 wasm.llvm_object = try LlvmObject.create(gpa, options);
528 }527 }
529 return wasm;528 return wasm;
...@@ -1273,9 +1272,7 @@ fn checkUndefinedSymbols(wasm: *const Wasm) !void {...@@ -1273,9 +1272,7 @@ fn checkUndefinedSymbols(wasm: *const Wasm) !void {
12731272
1274pub fn deinit(wasm: *Wasm) void {1273pub fn deinit(wasm: *Wasm) void {
1275 const gpa = wasm.base.allocator;1274 const gpa = wasm.base.allocator;
1276 if (build_options.have_llvm) {1275 if (wasm.llvm_object) |llvm_object| llvm_object.destroy(gpa);
1277 if (wasm.llvm_object) |llvm_object| llvm_object.destroy(gpa);
1278 }
12791276
1280 for (wasm.func_types.items) |*func_type| {1277 for (wasm.func_types.items) |*func_type| {
1281 func_type.deinit(gpa);1278 func_type.deinit(gpa);
...@@ -1354,9 +1351,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: InternPool.Index, air:...@@ -1354,9 +1351,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: InternPool.Index, air:
1354 if (build_options.skip_non_native and builtin.object_format != .wasm) {1351 if (build_options.skip_non_native and builtin.object_format != .wasm) {
1355 @panic("Attempted to compile for object format that was disabled by build configuration");1352 @panic("Attempted to compile for object format that was disabled by build configuration");
1356 }1353 }
1357 if (build_options.have_llvm) {1354 if (wasm.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
1358 if (wasm.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
1359 }
13601355
1361 const tracy = trace(@src());1356 const tracy = trace(@src());
1362 defer tracy.end();1357 defer tracy.end();
...@@ -1422,9 +1417,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi...@@ -1422,9 +1417,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
1422 if (build_options.skip_non_native and builtin.object_format != .wasm) {1417 if (build_options.skip_non_native and builtin.object_format != .wasm) {
1423 @panic("Attempted to compile for object format that was disabled by build configuration");1418 @panic("Attempted to compile for object format that was disabled by build configuration");
1424 }1419 }
1425 if (build_options.have_llvm) {1420 if (wasm.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1426 if (wasm.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1427 }
14281421
1429 const tracy = trace(@src());1422 const tracy = trace(@src());
1430 defer tracy.end();1423 defer tracy.end();
...@@ -1708,9 +1701,7 @@ pub fn updateDeclExports(...@@ -1708,9 +1701,7 @@ pub fn updateDeclExports(
1708 if (build_options.skip_non_native and builtin.object_format != .wasm) {1701 if (build_options.skip_non_native and builtin.object_format != .wasm) {
1709 @panic("Attempted to compile for object format that was disabled by build configuration");1702 @panic("Attempted to compile for object format that was disabled by build configuration");
1710 }1703 }
1711 if (build_options.have_llvm) {1704 if (wasm.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
1712 if (wasm.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
1713 }
17141705
1715 if (wasm.base.options.emit == null) return;1706 if (wasm.base.options.emit == null) return;
17161707
...@@ -1811,9 +1802,7 @@ pub fn updateDeclExports(...@@ -1811,9 +1802,7 @@ pub fn updateDeclExports(
1811}1802}
18121803
1813pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {1804pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {
1814 if (build_options.have_llvm) {1805 if (wasm.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
1815 if (wasm.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
1816 }
1817 const mod = wasm.base.options.module.?;1806 const mod = wasm.base.options.module.?;
1818 const decl = mod.declPtr(decl_index);1807 const decl = mod.declPtr(decl_index);
1819 const atom_index = wasm.decls.get(decl_index).?;1808 const atom_index = wasm.decls.get(decl_index).?;
...@@ -3137,17 +3126,15 @@ fn resetState(wasm: *Wasm) void {...@@ -3137,17 +3126,15 @@ fn resetState(wasm: *Wasm) void {
31373126
3138pub fn flush(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {3127pub fn flush(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
3139 if (wasm.base.options.emit == null) {3128 if (wasm.base.options.emit == null) {
3140 if (build_options.have_llvm) {3129 if (wasm.llvm_object) |llvm_object| {
3141 if (wasm.llvm_object) |llvm_object| {3130 return try llvm_object.flushModule(comp, prog_node);
3142 return try llvm_object.flushModule(comp, prog_node);
3143 }
3144 }3131 }
3145 return;3132 return;
3146 }3133 }
31473134
3148 if (build_options.have_llvm and wasm.base.options.use_lld) {3135 if (build_options.have_llvm and wasm.base.options.use_lld) {
3149 return wasm.linkWithLLD(comp, prog_node);3136 return wasm.linkWithLLD(comp, prog_node);
3150 } else if (build_options.have_llvm and wasm.base.options.use_llvm and !wasm.base.options.use_lld) {3137 } else if (wasm.base.options.use_llvm and !wasm.base.options.use_lld) {
3151 return wasm.linkWithZld(comp, prog_node);3138 return wasm.linkWithZld(comp, prog_node);
3152 } else {3139 } else {
3153 return wasm.flushModule(comp, prog_node);3140 return wasm.flushModule(comp, prog_node);
...@@ -3365,10 +3352,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod...@@ -3365,10 +3352,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
3365 const tracy = trace(@src());3352 const tracy = trace(@src());
3366 defer tracy.end();3353 defer tracy.end();
33673354
3368 if (build_options.have_llvm) {3355 if (wasm.llvm_object) |llvm_object| {
3369 if (wasm.llvm_object) |llvm_object| {3356 return try llvm_object.flushModule(comp, prog_node);
3370 return try llvm_object.flushModule(comp, prog_node);
3371 }
3372 }3357 }
33733358
3374 var sub_prog_node = prog_node.start("Wasm Flush", 0);3359 var sub_prog_node = prog_node.start("Wasm Flush", 0);