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 {
10271027 return error.TargetRequiresSingleThreaded;
10281028 }
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: {
10311031 var buf = std.ArrayList(u8).init(arena);
10321032 for (options.target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| {
10331033 const index = @as(Target.Cpu.Feature.Set.Index, @intCast(index_usize));
......@@ -5182,7 +5182,7 @@ pub fn dump_argv(argv: []const []const u8) void {
51825182}
51835183
51845184pub 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;
51865186 const target = comp.bin_file.options.target;
51875187 if (target.ofmt == .c) return .stage2_c;
51885188 return switch (target.cpu.arch) {
src/codegen/llvm.zig+42-33
......@@ -8,7 +8,7 @@ const native_endian = builtin.cpu.arch.endian();
88const DW = std.dwarf;
99
1010const Builder = @import("llvm/Builder.zig");
11const llvm = if (build_options.have_llvm or true)
11const llvm = if (build_options.have_llvm)
1212 @import("llvm/bindings.zig")
1313else
1414 @compileError("LLVM unavailable");
......@@ -764,15 +764,37 @@ pub const Object = struct {
764764 builder: Builder,
765765
766766 module: *Module,
767 di_builder: ?*llvm.DIBuilder,
767 di_builder: ?if (build_options.have_llvm) *llvm.DIBuilder else noreturn,
768768 /// One of these mappings:
769769 /// - *Module.File => *DIFile
770770 /// - *Module.Decl (Fn) => *DISubprogram
771771 /// - *Module.Decl (Non-Fn) => *DIGlobalVariable
772 di_map: std.AutoHashMapUnmanaged(*const anyopaque, *llvm.DINode),
773 di_compile_unit: ?*llvm.DICompileUnit,
774 target_machine: *llvm.TargetMachine,
775 target_data: *llvm.TargetData,
772 di_map: if (build_options.have_llvm) std.AutoHashMapUnmanaged(*const anyopaque, *llvm.DINode) else struct {
773 const K = *const anyopaque;
774 const V = noreturn;
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,
776798 target: std.Target,
777799 /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function,
778800 /// but that has some downsides:
......@@ -830,8 +852,8 @@ pub const Object = struct {
830852 });
831853 errdefer builder.deinit();
832854
833 var target_machine: *llvm.TargetMachine = undefined;
834 var target_data: *llvm.TargetData = undefined;
855 var target_machine: if (build_options.have_llvm) *llvm.TargetMachine else void = undefined;
856 var target_data: if (build_options.have_llvm) *llvm.TargetData else void = undefined;
835857 if (builder.useLibLlvm()) {
836858 if (!options.strip) {
837859 switch (options.target.ofmt) {
......@@ -946,7 +968,7 @@ pub const Object = struct {
946968 .module = options.module.?,
947969 .di_map = .{},
948970 .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,
950972 .target_machine = target_machine,
951973 .target_data = target_data,
952974 .target = options.target,
......@@ -961,9 +983,9 @@ pub const Object = struct {
961983 }
962984
963985 pub fn deinit(self: *Object, gpa: Allocator) void {
986 self.di_map.deinit(gpa);
987 self.di_type_map.deinit(gpa);
964988 if (self.builder.useLibLlvm()) {
965 self.di_map.deinit(gpa);
966 self.di_type_map.deinit(gpa);
967989 self.target_data.dispose();
968990 self.target_machine.dispose();
969991 }
......@@ -1519,8 +1541,8 @@ pub const Object = struct {
15191541
15201542 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);
15211543
1522 var di_file: ?*llvm.DIFile = null;
1523 var di_scope: ?*llvm.DIScope = null;
1544 var di_file: ?if (build_options.have_llvm) *llvm.DIFile else noreturn = null;
1545 var di_scope: ?if (build_options.have_llvm) *llvm.DIScope else noreturn = null;
15241546
15251547 if (o.di_builder) |dib| {
15261548 di_file = try o.getDIFile(gpa, mod.namespacePtr(decl.src_namespace).file_scope);
......@@ -4425,7 +4447,8 @@ pub const DeclGen = struct {
44254447 }, &o.builder);
44264448
44274449 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
44304453 const line_number = decl.src_line + 1;
44314454 const is_internal_linkage = !o.module.decl_exports.contains(decl_index);
......@@ -4453,18 +4476,18 @@ pub const FuncGen = struct {
44534476 air: Air,
44544477 liveness: Liveness,
44554478 wip: Builder.WipFunction,
4456 di_scope: ?*llvm.DIScope,
4457 di_file: ?*llvm.DIFile,
4479 di_scope: ?if (build_options.have_llvm) *llvm.DIScope else noreturn,
4480 di_file: ?if (build_options.have_llvm) *llvm.DIFile else noreturn,
44584481 base_line: u32,
44594482 prev_dbg_line: c_uint,
44604483 prev_dbg_column: c_uint,
44614484
44624485 /// 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
44654488 /// Stack of `DILexicalBlock`s. dbg_block instructions cannot happend accross
44664489 /// 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
44694492 /// This stores the LLVM values used in a function, such that they can be referred to
44704493 /// in other instructions. This table is cleared before every function is generated.
......@@ -4495,7 +4518,7 @@ pub const FuncGen = struct {
44954518
44964519 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 {};
44994522 const BreakList = union {
45004523 list: std.MultiArrayList(struct {
45014524 bb: Builder.Function.Block.Index,
......@@ -6230,8 +6253,6 @@ pub const FuncGen = struct {
62306253 }
62316254
62326255 fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6233 if (!self.dg.object.builder.useLibLlvm()) return .none;
6234
62356256 const di_scope = self.di_scope orelse return .none;
62366257 const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt;
62376258 self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1);
......@@ -6251,8 +6272,6 @@ pub const FuncGen = struct {
62516272
62526273 fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
62536274 const o = self.dg.object;
6254 if (!o.builder.useLibLlvm()) return .none;
6255
62566275 const dib = o.di_builder orelse return .none;
62576276 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;
62586277
......@@ -6311,8 +6330,6 @@ pub const FuncGen = struct {
63116330
63126331 fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
63136332 const o = self.dg.object;
6314 if (!o.builder.useLibLlvm()) return .none;
6315
63166333 if (o.di_builder == null) return .none;
63176334 const ty_fn = self.air.instructions.items(.data)[inst].ty_fn;
63186335
......@@ -6328,8 +6345,6 @@ pub const FuncGen = struct {
63286345
63296346 fn airDbgBlockBegin(self: *FuncGen) !Builder.Value {
63306347 const o = self.dg.object;
6331 if (!o.builder.useLibLlvm()) return .none;
6332
63336348 const dib = o.di_builder orelse return .none;
63346349 const old_scope = self.di_scope.?;
63356350 try self.dbg_block_stack.append(self.gpa, old_scope);
......@@ -6340,8 +6355,6 @@ pub const FuncGen = struct {
63406355
63416356 fn airDbgBlockEnd(self: *FuncGen) !Builder.Value {
63426357 const o = self.dg.object;
6343 if (!o.builder.useLibLlvm()) return .none;
6344
63456358 if (o.di_builder == null) return .none;
63466359 self.di_scope = self.dbg_block_stack.pop();
63476360 return .none;
......@@ -6349,8 +6362,6 @@ pub const FuncGen = struct {
63496362
63506363 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
63516364 const o = self.dg.object;
6352 if (!o.builder.useLibLlvm()) return .none;
6353
63546365 const mod = o.module;
63556366 const dib = o.di_builder orelse return .none;
63566367 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
......@@ -6379,8 +6390,6 @@ pub const FuncGen = struct {
63796390
63806391 fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
63816392 const o = self.dg.object;
6382 if (!o.builder.useLibLlvm()) return .none;
6383
63846393 const dib = o.di_builder orelse return .none;
63856394 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
63866395 const operand = try self.resolveInst(pl_op.operand);
src/codegen/llvm/Builder.zig+19-19
......@@ -5868,7 +5868,7 @@ pub const WipFunction = struct {
58685868 vals: []const Value,
58695869 blocks: []const Block.Index,
58705870 wip: *WipFunction,
5871 ) if (build_options.have_llvm) Allocator.Error!void else void {
5871 ) (if (build_options.have_llvm) Allocator.Error else error{})!void {
58725872 const incoming_len = self.block.ptrConst(wip).incoming;
58735873 assert(vals.len == incoming_len and blocks.len == incoming_len);
58745874 const instruction = wip.instructions.get(@intFromEnum(self.instruction));
......@@ -8389,9 +8389,9 @@ pub fn fnType(
83898389 kind: Type.Function.Kind,
83908390) Allocator.Error!Type {
83918391 try self.ensureUnusedTypeCapacity(1, Type.Function, params.len);
8392 return switch (kind) {
8393 inline else => |comptime_kind| self.fnTypeAssumeCapacity(ret, params, comptime_kind),
8394 };
8392 switch (kind) {
8393 inline else => |comptime_kind| return self.fnTypeAssumeCapacity(ret, params, comptime_kind),
8394 }
83958395}
83968396
83978397pub fn intType(self: *Builder, bits: u24) Allocator.Error!Type {
......@@ -8411,9 +8411,9 @@ pub fn vectorType(
84118411 child: Type,
84128412) Allocator.Error!Type {
84138413 try self.ensureUnusedTypeCapacity(1, Type.Vector, 0);
8414 return switch (kind) {
8415 inline else => |comptime_kind| self.vectorTypeAssumeCapacity(comptime_kind, len, child),
8416 };
8414 switch (kind) {
8415 inline else => |comptime_kind| return self.vectorTypeAssumeCapacity(comptime_kind, len, child),
8416 }
84178417}
84188418
84198419pub fn arrayType(self: *Builder, len: u64, child: Type) Allocator.Error!Type {
......@@ -8428,9 +8428,9 @@ pub fn structType(
84288428 fields: []const Type,
84298429) Allocator.Error!Type {
84308430 try self.ensureUnusedTypeCapacity(1, Type.Structure, fields.len);
8431 return switch (kind) {
8432 inline else => |comptime_kind| self.structTypeAssumeCapacity(comptime_kind, fields),
8433 };
8431 switch (kind) {
8432 inline else => |comptime_kind| return self.structTypeAssumeCapacity(comptime_kind, fields),
8433 }
84348434}
84358435
84368436pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type {
......@@ -8450,7 +8450,7 @@ pub fn namedTypeSetBody(
84508450 self: *Builder,
84518451 named_type: Type,
84528452 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 {
84548454 const named_item = self.type_items.items[@intFromEnum(named_type)];
84558455 self.type_extra.items[named_item.data + std.meta.fieldIndex(Type.NamedStructure, "body").?] =
84568456 @intFromEnum(body_type);
......@@ -9985,7 +9985,7 @@ fn fnTypeAssumeCapacity(
99859985 ret: Type,
99869986 params: []const Type,
99879987 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 {
99899989 const tag: Type.Tag = switch (kind) {
99909990 .normal => .function,
99919991 .vararg => .vararg_function,
......@@ -10169,7 +10169,7 @@ fn structTypeAssumeCapacity(
1016910169 self: *Builder,
1017010170 comptime kind: Type.Structure.Kind,
1017110171 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 {
1017310173 const tag: Type.Tag = switch (kind) {
1017410174 .normal => .structure,
1017510175 .@"packed" => .packed_structure,
......@@ -10397,7 +10397,7 @@ fn bigIntConstAssumeCapacity(
1039710397 self: *Builder,
1039810398 ty: Type,
1039910399 value: std.math.big.int.Const,
10400) if (build_options.have_llvm) Allocator.Error!Constant else Constant {
10400) Allocator.Error!Constant {
1040110401 const type_item = self.type_items.items[@intFromEnum(ty)];
1040210402 assert(type_item.tag == .integer);
1040310403 const bits = type_item.data;
......@@ -10743,7 +10743,7 @@ fn structConstAssumeCapacity(
1074310743 self: *Builder,
1074410744 ty: Type,
1074510745 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 {
1074710747 const type_item = self.type_items.items[@intFromEnum(ty)];
1074810748 var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) {
1074910749 .structure, .packed_structure => type_item.data,
......@@ -10791,7 +10791,7 @@ fn arrayConstAssumeCapacity(
1079110791 self: *Builder,
1079210792 ty: Type,
1079310793 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 {
1079510795 const type_item = self.type_items.items[@intFromEnum(ty)];
1079610796 const type_extra: struct { len: u64, child: Type } = switch (type_item.tag) {
1079710797 inline .small_array, .array => |kind| extra: {
......@@ -10859,7 +10859,7 @@ fn vectorConstAssumeCapacity(
1085910859 self: *Builder,
1086010860 ty: Type,
1086110861 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 {
1086310863 assert(ty.isVector(self));
1086410864 assert(ty.vectorLen(self) == vals.len);
1086510865 for (vals) |val| assert(ty.childType(self) == val.typeOf(self));
......@@ -10893,7 +10893,7 @@ fn splatConstAssumeCapacity(
1089310893 self: *Builder,
1089410894 ty: Type,
1089510895 val: Constant,
10896) if (build_options.have_llvm) Allocator.Error!Constant else Constant {
10896) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
1089710897 assert(ty.scalarType(self) == val.typeOf(self));
1089810898
1089910899 if (!ty.isVector(self)) return val;
......@@ -11182,7 +11182,7 @@ fn gepConstAssumeCapacity(
1118211182 base: Constant,
1118311183 inrange: ?u16,
1118411184 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 {
1118611186 const tag: Constant.Tag = switch (kind) {
1118711187 .normal => .getelementptr,
1118811188 .inbounds => .@"getelementptr inbounds",
src/link/Coff.zig+14-27
......@@ -225,7 +225,7 @@ pub const min_text_capacity = padToIdeal(minimum_text_block_size);
225225pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Coff {
226226 assert(options.target.ofmt == .coff);
227227
228 if (build_options.have_llvm and options.use_llvm) {
228 if (options.use_llvm) {
229229 return createEmpty(allocator, options);
230230 }
231231
......@@ -267,8 +267,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {
267267 .data_directories = comptime mem.zeroes([coff.IMAGE_NUMBEROF_DIRECTORY_ENTRIES]coff.ImageDataDirectory),
268268 };
269269
270 const use_llvm = build_options.have_llvm and options.use_llvm;
271 if (use_llvm) {
270 if (options.use_llvm) {
272271 self.llvm_object = try LlvmObject.create(gpa, options);
273272 }
274273 return self;
......@@ -277,9 +276,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff {
277276pub fn deinit(self: *Coff) void {
278277 const gpa = self.base.allocator;
279278
280 if (build_options.have_llvm) {
281 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
282 }
279 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
283280
284281 for (self.objects.items) |*object| {
285282 object.deinit(gpa);
......@@ -1036,10 +1033,8 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
10361033 if (build_options.skip_non_native and builtin.object_format != .coff) {
10371034 @panic("Attempted to compile for object format that was disabled by build configuration");
10381035 }
1039 if (build_options.have_llvm) {
1040 if (self.llvm_object) |llvm_object| {
1041 return llvm_object.updateFunc(mod, func_index, air, liveness);
1042 }
1036 if (self.llvm_object) |llvm_object| {
1037 return llvm_object.updateFunc(mod, func_index, air, liveness);
10431038 }
10441039 const tracy = trace(@src());
10451040 defer tracy.end();
......@@ -1147,9 +1142,7 @@ pub fn updateDecl(
11471142 if (build_options.skip_non_native and builtin.object_format != .coff) {
11481143 @panic("Attempted to compile for object format that was disabled by build configuration");
11491144 }
1150 if (build_options.have_llvm) {
1151 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1152 }
1145 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
11531146 const tracy = trace(@src());
11541147 defer tracy.end();
11551148
......@@ -1390,9 +1383,7 @@ fn freeUnnamedConsts(self: *Coff, decl_index: Module.Decl.Index) void {
13901383}
13911384
13921385pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void {
1393 if (build_options.have_llvm) {
1394 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
1395 }
1386 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
13961387
13971388 const mod = self.base.options.module.?;
13981389 const decl = mod.declPtr(decl_index);
......@@ -1419,7 +1410,7 @@ pub fn updateDeclExports(
14191410
14201411 const ip = &mod.intern_pool;
14211412
1422 if (build_options.have_llvm) {
1413 if (self.base.options.use_llvm) {
14231414 // Even in the case of LLVM, we need to notice certain exported symbols in order to
14241415 // detect the default subsystem.
14251416 for (exports) |exp| {
......@@ -1448,10 +1439,10 @@ pub fn updateDeclExports(
14481439 }
14491440 }
14501441 }
1451
1452 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
14531442 }
14541443
1444 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
1445
14551446 if (self.base.options.emit == null) return;
14561447
14571448 const gpa = self.base.allocator;
......@@ -1583,10 +1574,8 @@ fn resolveGlobalSymbol(self: *Coff, current: SymbolWithLoc) !void {
15831574
15841575pub fn flush(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
15851576 if (self.base.options.emit == null) {
1586 if (build_options.have_llvm) {
1587 if (self.llvm_object) |llvm_object| {
1588 return try llvm_object.flushModule(comp, prog_node);
1589 }
1577 if (self.llvm_object) |llvm_object| {
1578 return try llvm_object.flushModule(comp, prog_node);
15901579 }
15911580 return;
15921581 }
......@@ -1604,10 +1593,8 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
16041593 const tracy = trace(@src());
16051594 defer tracy.end();
16061595
1607 if (build_options.have_llvm) {
1608 if (self.llvm_object) |llvm_object| {
1609 return try llvm_object.flushModule(comp, prog_node);
1610 }
1596 if (self.llvm_object) |llvm_object| {
1597 return try llvm_object.flushModule(comp, prog_node);
16111598 }
16121599
16131600 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 };
225225pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Elf {
226226 assert(options.target.ofmt == .elf);
227227
228 if (build_options.have_llvm and options.use_llvm) {
228 if (options.use_llvm) {
229229 return createEmpty(allocator, options);
230230 }
231231
......@@ -304,7 +304,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
304304 .ptr_width = ptr_width,
305305 .page_size = page_size,
306306 };
307 const use_llvm = build_options.have_llvm and options.use_llvm;
307 const use_llvm = options.use_llvm;
308308 if (use_llvm) {
309309 self.llvm_object = try LlvmObject.create(gpa, options);
310310 }
......@@ -314,9 +314,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf {
314314pub fn deinit(self: *Elf) void {
315315 const gpa = self.base.allocator;
316316
317 if (build_options.have_llvm) {
318 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
319 }
317 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
320318
321319 for (self.sections.items(.free_list)) |*free_list| {
322320 free_list.deinit(gpa);
......@@ -1005,10 +1003,8 @@ pub fn markDirty(self: *Elf, shdr_index: u16, phdr_index: ?u16) void {
10051003
10061004pub fn flush(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
10071005 if (self.base.options.emit == null) {
1008 if (build_options.have_llvm) {
1009 if (self.llvm_object) |llvm_object| {
1010 return try llvm_object.flushModule(comp, prog_node);
1011 }
1006 if (self.llvm_object) |llvm_object| {
1007 return try llvm_object.flushModule(comp, prog_node);
10121008 }
10131009 return;
10141010 }
......@@ -1026,10 +1022,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
10261022 const tracy = trace(@src());
10271023 defer tracy.end();
10281024
1029 if (build_options.have_llvm) {
1030 if (self.llvm_object) |llvm_object| {
1031 return try llvm_object.flushModule(comp, prog_node);
1032 }
1025 if (self.llvm_object) |llvm_object| {
1026 return try llvm_object.flushModule(comp, prog_node);
10331027 }
10341028
10351029 const gpa = self.base.allocator;
......@@ -2392,9 +2386,7 @@ fn freeUnnamedConsts(self: *Elf, decl_index: Module.Decl.Index) void {
23922386}
23932387
23942388pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {
2395 if (build_options.have_llvm) {
2396 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
2397 }
2389 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
23982390
23992391 const mod = self.base.options.module.?;
24002392 const decl = mod.declPtr(decl_index);
......@@ -2577,9 +2569,7 @@ pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: A
25772569 if (build_options.skip_non_native and builtin.object_format != .elf) {
25782570 @panic("Attempted to compile for object format that was disabled by build configuration");
25792571 }
2580 if (build_options.have_llvm) {
2581 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
2582 }
2572 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
25832573
25842574 const tracy = trace(@src());
25852575 defer tracy.end();
......@@ -2637,9 +2627,7 @@ pub fn updateDecl(
26372627 if (build_options.skip_non_native and builtin.object_format != .elf) {
26382628 @panic("Attempted to compile for object format that was disabled by build configuration");
26392629 }
2640 if (build_options.have_llvm) {
2641 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
2642 }
2630 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
26432631
26442632 const tracy = trace(@src());
26452633 defer tracy.end();
......@@ -2859,9 +2847,7 @@ pub fn updateDeclExports(
28592847 if (build_options.skip_non_native and builtin.object_format != .elf) {
28602848 @panic("Attempted to compile for object format that was disabled by build configuration");
28612849 }
2862 if (build_options.have_llvm) {
2863 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
2864 }
2850 if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
28652851
28662852 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 {
422422pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
423423 const cpu_arch = options.target.cpu.arch;
424424 const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000;
425 const use_llvm = build_options.have_llvm and options.use_llvm;
426425
427426 const self = try gpa.create(MachO);
428427 errdefer gpa.destroy(self);
......@@ -435,13 +434,13 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
435434 .file = null,
436435 },
437436 .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)
439438 .zld
440439 else
441440 .incremental,
442441 };
443442
444 if (use_llvm) {
443 if (options.use_llvm) {
445444 self.llvm_object = try LlvmObject.create(gpa, options);
446445 }
447446
......@@ -452,10 +451,8 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
452451
453452pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
454453 if (self.base.options.emit == null) {
455 if (build_options.have_llvm) {
456 if (self.llvm_object) |llvm_object| {
457 try llvm_object.flushModule(comp, prog_node);
458 }
454 if (self.llvm_object) |llvm_object| {
455 try llvm_object.flushModule(comp, prog_node);
459456 }
460457 return;
461458 }
......@@ -479,10 +476,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
479476 const tracy = trace(@src());
480477 defer tracy.end();
481478
482 if (build_options.have_llvm) {
483 if (self.llvm_object) |llvm_object| {
484 return try llvm_object.flushModule(comp, prog_node);
485 }
479 if (self.llvm_object) |llvm_object| {
480 return try llvm_object.flushModule(comp, prog_node);
486481 }
487482
488483 var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator);
......@@ -1622,9 +1617,7 @@ fn resolveSymbolsInDylibs(self: *MachO, actions: *std.ArrayList(ResolveAction))
16221617pub fn deinit(self: *MachO) void {
16231618 const gpa = self.base.allocator;
16241619
1625 if (build_options.have_llvm) {
1626 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
1627 }
1620 if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa);
16281621
16291622 if (self.d_sym) |*d_sym| {
16301623 d_sym.deinit();
......@@ -1855,9 +1848,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air:
18551848 if (build_options.skip_non_native and builtin.object_format != .macho) {
18561849 @panic("Attempted to compile for object format that was disabled by build configuration");
18571850 }
1858 if (build_options.have_llvm) {
1859 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
1860 }
1851 if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
18611852 const tracy = trace(@src());
18621853 defer tracy.end();
18631854
......@@ -1979,9 +1970,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo
19791970 if (build_options.skip_non_native and builtin.object_format != .macho) {
19801971 @panic("Attempted to compile for object format that was disabled by build configuration");
19811972 }
1982 if (build_options.have_llvm) {
1983 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1984 }
1973 if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
19851974 const tracy = trace(@src());
19861975 defer tracy.end();
19871976
......@@ -2387,10 +2376,8 @@ pub fn updateDeclExports(
23872376 if (build_options.skip_non_native and builtin.object_format != .macho) {
23882377 @panic("Attempted to compile for object format that was disabled by build configuration");
23892378 }
2390 if (build_options.have_llvm) {
2391 if (self.llvm_object) |llvm_object|
2392 return llvm_object.updateDeclExports(mod, decl_index, exports);
2393 }
2379 if (self.llvm_object) |llvm_object|
2380 return llvm_object.updateDeclExports(mod, decl_index, exports);
23942381
23952382 if (self.base.options.emit == null) return;
23962383
......@@ -2542,9 +2529,7 @@ fn freeUnnamedConsts(self: *MachO, decl_index: Module.Decl.Index) void {
25422529}
25432530
25442531pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void {
2545 if (build_options.have_llvm) {
2546 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
2547 }
2532 if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
25482533 const mod = self.base.options.module.?;
25492534 const decl = mod.declPtr(decl_index);
25502535
src/link/NvPtx.zig-8
......@@ -27,7 +27,6 @@ llvm_object: *LlvmObject,
2727ptx_file_name: []const u8,
2828
2929pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
30 if (!build_options.have_llvm) return error.PtxArchNotSupported;
3130 if (!options.use_llvm) return error.PtxArchNotSupported;
3231
3332 if (!options.target.cpu.arch.isNvptx()) return error.PtxArchNotSupported;
......@@ -55,7 +54,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx {
5554}
5655
5756pub 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.");
5957 if (!options.use_llvm) return error.PtxArchNotSupported;
6058 assert(options.target.ofmt == .nvptx);
6159
......@@ -64,18 +62,15 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
6462}
6563
6664pub fn deinit(self: *NvPtx) void {
67 if (!build_options.have_llvm) return;
6865 self.llvm_object.destroy(self.base.allocator);
6966 self.base.allocator.free(self.ptx_file_name);
7067}
7168
7269pub fn updateFunc(self: *NvPtx, module: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void {
73 if (!build_options.have_llvm) return;
7470 try self.llvm_object.updateFunc(module, func_index, air, liveness);
7571}
7672
7773pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void {
78 if (!build_options.have_llvm) return;
7974 return self.llvm_object.updateDecl(module, decl_index);
8075}
8176
......@@ -85,7 +80,6 @@ pub fn updateDeclExports(
8580 decl_index: Module.Decl.Index,
8681 exports: []const *Module.Export,
8782) !void {
88 if (!build_options.have_llvm) return;
8983 if (build_options.skip_non_native and builtin.object_format != .nvptx) {
9084 @panic("Attempted to compile for object format that was disabled by build configuration");
9185 }
......@@ -93,7 +87,6 @@ pub fn updateDeclExports(
9387}
9488
9589pub fn freeDecl(self: *NvPtx, decl_index: Module.Decl.Index) void {
96 if (!build_options.have_llvm) return;
9790 return self.llvm_object.freeDecl(decl_index);
9891}
9992
......@@ -102,7 +95,6 @@ pub fn flush(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.Node) li
10295}
10396
10497pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
105 if (!build_options.have_llvm) return;
10698 if (build_options.skip_non_native) {
10799 @panic("Attempted to compile for architecture that was disabled by build configuration");
108100 }
src/link/Wasm.zig+12-27
......@@ -360,7 +360,7 @@ pub const StringTable = struct {
360360pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Wasm {
361361 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) {
364364 return createEmpty(allocator, options);
365365 }
366366
......@@ -522,8 +522,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm {
522522 .name = undefined,
523523 };
524524
525 const use_llvm = build_options.have_llvm and options.use_llvm;
526 if (use_llvm) {
525 if (options.use_llvm) {
527526 wasm.llvm_object = try LlvmObject.create(gpa, options);
528527 }
529528 return wasm;
......@@ -1273,9 +1272,7 @@ fn checkUndefinedSymbols(wasm: *const Wasm) !void {
12731272
12741273pub fn deinit(wasm: *Wasm) void {
12751274 const gpa = wasm.base.allocator;
1276 if (build_options.have_llvm) {
1277 if (wasm.llvm_object) |llvm_object| llvm_object.destroy(gpa);
1278 }
1275 if (wasm.llvm_object) |llvm_object| llvm_object.destroy(gpa);
12791276
12801277 for (wasm.func_types.items) |*func_type| {
12811278 func_type.deinit(gpa);
......@@ -1354,9 +1351,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: InternPool.Index, air:
13541351 if (build_options.skip_non_native and builtin.object_format != .wasm) {
13551352 @panic("Attempted to compile for object format that was disabled by build configuration");
13561353 }
1357 if (build_options.have_llvm) {
1358 if (wasm.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
1359 }
1354 if (wasm.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
13601355
13611356 const tracy = trace(@src());
13621357 defer tracy.end();
......@@ -1422,9 +1417,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
14221417 if (build_options.skip_non_native and builtin.object_format != .wasm) {
14231418 @panic("Attempted to compile for object format that was disabled by build configuration");
14241419 }
1425 if (build_options.have_llvm) {
1426 if (wasm.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
1427 }
1420 if (wasm.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index);
14281421
14291422 const tracy = trace(@src());
14301423 defer tracy.end();
......@@ -1708,9 +1701,7 @@ pub fn updateDeclExports(
17081701 if (build_options.skip_non_native and builtin.object_format != .wasm) {
17091702 @panic("Attempted to compile for object format that was disabled by build configuration");
17101703 }
1711 if (build_options.have_llvm) {
1712 if (wasm.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
1713 }
1704 if (wasm.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
17141705
17151706 if (wasm.base.options.emit == null) return;
17161707
......@@ -1811,9 +1802,7 @@ pub fn updateDeclExports(
18111802}
18121803
18131804pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void {
1814 if (build_options.have_llvm) {
1815 if (wasm.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
1816 }
1805 if (wasm.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index);
18171806 const mod = wasm.base.options.module.?;
18181807 const decl = mod.declPtr(decl_index);
18191808 const atom_index = wasm.decls.get(decl_index).?;
......@@ -3137,17 +3126,15 @@ fn resetState(wasm: *Wasm) void {
31373126
31383127pub fn flush(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void {
31393128 if (wasm.base.options.emit == null) {
3140 if (build_options.have_llvm) {
3141 if (wasm.llvm_object) |llvm_object| {
3142 return try llvm_object.flushModule(comp, prog_node);
3143 }
3129 if (wasm.llvm_object) |llvm_object| {
3130 return try llvm_object.flushModule(comp, prog_node);
31443131 }
31453132 return;
31463133 }
31473134
31483135 if (build_options.have_llvm and wasm.base.options.use_lld) {
31493136 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) {
31513138 return wasm.linkWithZld(comp, prog_node);
31523139 } else {
31533140 return wasm.flushModule(comp, prog_node);
......@@ -3365,10 +3352,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
33653352 const tracy = trace(@src());
33663353 defer tracy.end();
33673354
3368 if (build_options.have_llvm) {
3369 if (wasm.llvm_object) |llvm_object| {
3370 return try llvm_object.flushModule(comp, prog_node);
3371 }
3355 if (wasm.llvm_object) |llvm_object| {
3356 return try llvm_object.flushModule(comp, prog_node);
33723357 }
33733358
33743359 var sub_prog_node = prog_node.start("Wasm Flush", 0);