authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-21 19:18:07+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-21 19:18:34+01:00
log48bd0ed7f3f5d6c1c0f2046a791e7367ba0672ad
treeb6a570adf83741159751f7d7f776a8e9113b6d18
parent713a555aa157ae6f8d55f7bd381f414b54028637

llvm: fix builds that don't link with libllvm


3 files changed, 61 insertions(+), 81 deletions(-)

src/codegen/llvm.zig+11-12
...@@ -1212,7 +1212,7 @@ pub const Object = struct {...@@ -1212,7 +1212,7 @@ pub const Object = struct {
1212 try file.writeAll(ptr[0..(bitcode.len * 4)]);1212 try file.writeAll(ptr[0..(bitcode.len * 4)]);
1213 }1213 }
12141214
1215 if (!self.module.comp.config.use_lib_llvm) {1215 if (!build_options.have_llvm or !self.module.comp.config.use_lib_llvm) {
1216 log.err("emitting without libllvm not implemented", .{});1216 log.err("emitting without libllvm not implemented", .{});
1217 return error.FailedToEmit;1217 return error.FailedToEmit;
1218 }1218 }
...@@ -1647,7 +1647,7 @@ pub const Object = struct {...@@ -1647,7 +1647,7 @@ pub const Object = struct {
1647 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and1647 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
1648 !zcu.decl_exports.contains(decl_index);1648 !zcu.decl_exports.contains(decl_index);
1649 const noret_bit: u29 = if (fn_info.return_type == .noreturn_type)1649 const noret_bit: u29 = if (fn_info.return_type == .noreturn_type)
1650 llvm.DIFlags.NoReturn1650 Builder.DIFlags.NoReturn
1651 else1651 else
1652 0;1652 0;
1653 const debug_decl_type = try o.lowerDebugType(decl.ty);1653 const debug_decl_type = try o.lowerDebugType(decl.ty);
...@@ -1663,7 +1663,7 @@ pub const Object = struct {...@@ -1663,7 +1663,7 @@ pub const Object = struct {
1663 .optimized = owner_mod.optimize_mode != .Debug,1663 .optimized = owner_mod.optimize_mode != .Debug,
1664 .definition = true,1664 .definition = true,
1665 .local = is_internal_linkage,1665 .local = is_internal_linkage,
1666 .debug_info_flags = llvm.DIFlags.StaticMember | noret_bit,1666 .debug_info_flags = Builder.DIFlags.StaticMember | noret_bit,
1667 },1667 },
1668 o.debug_compile_unit,1668 o.debug_compile_unit,
1669 );1669 );
...@@ -3372,7 +3372,7 @@ pub const Object = struct {...@@ -3372,7 +3372,7 @@ pub const Object = struct {
3372 const ty = try o.builder.opaqueType(name);3372 const ty = try o.builder.opaqueType(name);
3373 try o.type_map.put(o.gpa, t.toIntern(), ty);3373 try o.type_map.put(o.gpa, t.toIntern(), ty);
33743374
3375 try o.builder.namedTypeSetBody(3375 o.builder.namedTypeSetBody(
3376 ty,3376 ty,
3377 try o.builder.structType(struct_kind, llvm_field_types.items),3377 try o.builder.structType(struct_kind, llvm_field_types.items),
3378 );3378 );
...@@ -3483,7 +3483,7 @@ pub const Object = struct {...@@ -3483,7 +3483,7 @@ pub const Object = struct {
3483 const ty = try o.builder.opaqueType(name);3483 const ty = try o.builder.opaqueType(name);
3484 try o.type_map.put(o.gpa, t.toIntern(), ty);3484 try o.type_map.put(o.gpa, t.toIntern(), ty);
34853485
3486 try o.builder.namedTypeSetBody(3486 o.builder.namedTypeSetBody(
3487 ty,3487 ty,
3488 try o.builder.structType(.normal, &.{payload_ty}),3488 try o.builder.structType(.normal, &.{payload_ty}),
3489 );3489 );
...@@ -3511,7 +3511,7 @@ pub const Object = struct {...@@ -3511,7 +3511,7 @@ pub const Object = struct {
3511 const ty = try o.builder.opaqueType(name);3511 const ty = try o.builder.opaqueType(name);
3512 try o.type_map.put(o.gpa, t.toIntern(), ty);3512 try o.type_map.put(o.gpa, t.toIntern(), ty);
35133513
3514 try o.builder.namedTypeSetBody(3514 o.builder.namedTypeSetBody(
3515 ty,3515 ty,
3516 try o.builder.structType(.normal, llvm_fields[0..llvm_fields_len]),3516 try o.builder.structType(.normal, llvm_fields[0..llvm_fields_len]),
3517 );3517 );
...@@ -4773,7 +4773,6 @@ pub const FuncGen = struct {...@@ -4773,7 +4773,6 @@ pub const FuncGen = struct {
47734773
4774 sync_scope: Builder.SyncScope,4774 sync_scope: Builder.SyncScope,
47754775
4776 const DbgState = if (build_options.have_llvm) struct { loc: *llvm.DILocation, scope: *llvm.DIScope, base_line: u32 } else struct {};
4777 const BreakList = union {4776 const BreakList = union {
4778 list: std.MultiArrayList(struct {4777 list: std.MultiArrayList(struct {
4779 bb: Builder.Function.Block.Index,4778 bb: Builder.Function.Block.Index,
...@@ -5760,7 +5759,7 @@ pub const FuncGen = struct {...@@ -5760,7 +5759,7 @@ pub const FuncGen = struct {
5760 };5759 };
57615760
5762 const phi = try self.wip.phi(.i1, "");5761 const phi = try self.wip.phi(.i1, "");
5763 try phi.finish(5762 phi.finish(
5764 &incoming_values,5763 &incoming_values,
5765 &.{ both_null_block, mixed_block, both_pl_block_end },5764 &.{ both_null_block, mixed_block, both_pl_block_end },
5766 &self.wip,5765 &self.wip,
...@@ -5827,7 +5826,7 @@ pub const FuncGen = struct {...@@ -5827,7 +5826,7 @@ pub const FuncGen = struct {
58275826
5828 parent_bb.ptr(&self.wip).incoming = @intCast(breaks.list.len);5827 parent_bb.ptr(&self.wip).incoming = @intCast(breaks.list.len);
5829 const phi = try self.wip.phi(llvm_ty, "");5828 const phi = try self.wip.phi(llvm_ty, "");
5830 try phi.finish(breaks.list.items(.val), breaks.list.items(.bb), &self.wip);5829 phi.finish(breaks.list.items(.val), breaks.list.items(.bb), &self.wip);
5831 return phi.toValue();5830 return phi.toValue();
5832 } else {5831 } else {
5833 parent_bb.ptr(&self.wip).incoming = @intCast(breaks.len);5832 parent_bb.ptr(&self.wip).incoming = @intCast(breaks.len);
...@@ -6615,7 +6614,7 @@ pub const FuncGen = struct {...@@ -6615,7 +6614,7 @@ pub const FuncGen = struct {
6615 .optimized = owner_mod.optimize_mode != .Debug,6614 .optimized = owner_mod.optimize_mode != .Debug,
6616 .local = is_internal_linkage,6615 .local = is_internal_linkage,
6617 .definition = true,6616 .definition = true,
6618 .debug_info_flags = llvm.DIFlags.StaticMember,6617 .debug_info_flags = Builder.DIFlags.StaticMember,
6619 },6618 },
6620 o.debug_compile_unit,6619 o.debug_compile_unit,
6621 );6620 );
...@@ -9350,7 +9349,7 @@ pub const FuncGen = struct {...@@ -9350,7 +9349,7 @@ pub const FuncGen = struct {
9350 _ = try self.wip.br(loop_block);9349 _ = try self.wip.br(loop_block);
93519350
9352 self.wip.cursor = .{ .block = end_block };9351 self.wip.cursor = .{ .block = end_block };
9353 try it_ptr.finish(&.{ next_ptr, dest_ptr }, &.{ body_block, entry_block }, &self.wip);9352 it_ptr.finish(&.{ next_ptr, dest_ptr }, &.{ body_block, entry_block }, &self.wip);
9354 return .none;9353 return .none;
9355 }9354 }
93569355
...@@ -9585,7 +9584,7 @@ pub const FuncGen = struct {...@@ -9585,7 +9584,7 @@ pub const FuncGen = struct {
95859584
9586 self.wip.cursor = .{ .block = end_block };9585 self.wip.cursor = .{ .block = end_block };
9587 const phi = try self.wip.phi(.i1, "");9586 const phi = try self.wip.phi(.i1, "");
9588 try phi.finish(&.{ .true, .false }, &.{ valid_block, invalid_block }, &self.wip);9587 phi.finish(&.{ .true, .false }, &.{ valid_block, invalid_block }, &self.wip);
9589 return phi.toValue();9588 return phi.toValue();
9590 }9589 }
95919590
src/codegen/llvm/Builder.zig+50-31
...@@ -4264,7 +4264,7 @@ pub const Function = struct {...@@ -4264,7 +4264,7 @@ pub const Function = struct {
4264 => wip.builder.structTypeAssumeCapacity(.normal, &.{4264 => wip.builder.structTypeAssumeCapacity(.normal, &.{
4265 wip.extraData(CmpXchg, instruction.data).cmp.typeOfWip(wip),4265 wip.extraData(CmpXchg, instruction.data).cmp.typeOfWip(wip),
4266 .i1,4266 .i1,
4267 }) catch unreachable,4267 }),
4268 .extractelement => wip.extraData(ExtractElement, instruction.data)4268 .extractelement => wip.extraData(ExtractElement, instruction.data)
4269 .val.typeOfWip(wip).childType(wip.builder),4269 .val.typeOfWip(wip).childType(wip.builder),
4270 .extractvalue => {4270 .extractvalue => {
...@@ -4451,7 +4451,7 @@ pub const Function = struct {...@@ -4451,7 +4451,7 @@ pub const Function = struct {
4451 function.extraData(CmpXchg, instruction.data)4451 function.extraData(CmpXchg, instruction.data)
4452 .cmp.typeOf(function_index, builder),4452 .cmp.typeOf(function_index, builder),
4453 .i1,4453 .i1,
4454 }) catch unreachable,4454 }),
4455 .extractelement => function.extraData(ExtractElement, instruction.data)4455 .extractelement => function.extraData(ExtractElement, instruction.data)
4456 .val.typeOf(function_index, builder).childType(builder),4456 .val.typeOf(function_index, builder).childType(builder),
4457 .extractvalue => {4457 .extractvalue => {
...@@ -4840,6 +4840,44 @@ pub const DebugLocation = struct {...@@ -4840,6 +4840,44 @@ pub const DebugLocation = struct {
4840 inlined_at: Metadata,4840 inlined_at: Metadata,
4841};4841};
48424842
4843pub const DIFlags = opaque {
4844 pub const Zero = 0;
4845 pub const Private = 1;
4846 pub const Protected = 2;
4847 pub const Public = 3;
4848
4849 pub const FwdDecl = 1 << 2;
4850 pub const AppleBlock = 1 << 3;
4851 pub const BlockByrefStruct = 1 << 4;
4852 pub const Virtual = 1 << 5;
4853 pub const Artificial = 1 << 6;
4854 pub const Explicit = 1 << 7;
4855 pub const Prototyped = 1 << 8;
4856 pub const ObjcClassComplete = 1 << 9;
4857 pub const ObjectPointer = 1 << 10;
4858 pub const Vector = 1 << 11;
4859 pub const StaticMember = 1 << 12;
4860 pub const LValueReference = 1 << 13;
4861 pub const RValueReference = 1 << 14;
4862 pub const Reserved = 1 << 15;
4863
4864 pub const SingleInheritance = 1 << 16;
4865 pub const MultipleInheritance = 2 << 16;
4866 pub const VirtualInheritance = 3 << 16;
4867
4868 pub const IntroducedVirtual = 1 << 18;
4869 pub const BitField = 1 << 19;
4870 pub const NoReturn = 1 << 20;
4871 pub const TypePassByValue = 1 << 22;
4872 pub const TypePassByReference = 1 << 23;
4873 pub const EnumClass = 1 << 24;
4874 pub const Thunk = 1 << 25;
4875 pub const NonTrivial = 1 << 26;
4876 pub const BigEndian = 1 << 27;
4877 pub const LittleEndian = 1 << 28;
4878 pub const AllCallsDescribed = 1 << 29;
4879};
4880
4843pub const WipFunction = struct {4881pub const WipFunction = struct {
4844 builder: *Builder,4882 builder: *Builder,
4845 function: Function.Index,4883 function: Function.Index,
...@@ -5610,7 +5648,7 @@ pub const WipFunction = struct {...@@ -5610,7 +5648,7 @@ pub const WipFunction = struct {
5610 vals: []const Value,5648 vals: []const Value,
5611 blocks: []const Block.Index,5649 blocks: []const Block.Index,
5612 wip: *WipFunction,5650 wip: *WipFunction,
5613 ) (if (build_options.have_llvm) Allocator.Error else error{})!void {5651 ) void {
5614 const incoming_len = self.block.ptrConst(wip).incoming;5652 const incoming_len = self.block.ptrConst(wip).incoming;
5615 assert(vals.len == incoming_len and blocks.len == incoming_len);5653 assert(vals.len == incoming_len and blocks.len == incoming_len);
5616 const instruction = wip.instructions.get(@intFromEnum(self.instruction));5654 const instruction = wip.instructions.get(@intFromEnum(self.instruction));
...@@ -8007,7 +8045,7 @@ pub fn namedTypeSetBody(...@@ -8007,7 +8045,7 @@ pub fn namedTypeSetBody(
8007 self: *Builder,8045 self: *Builder,
8008 named_type: Type,8046 named_type: Type,
8009 body_type: Type,8047 body_type: Type,
8010) (if (build_options.have_llvm) Allocator.Error else error{})!void {8048) void {
8011 const named_item = self.type_items.items[@intFromEnum(named_type)];8049 const named_item = self.type_items.items[@intFromEnum(named_type)];
8012 self.type_extra.items[named_item.data + std.meta.fieldIndex(Type.NamedStructure, "body").?] =8050 self.type_extra.items[named_item.data + std.meta.fieldIndex(Type.NamedStructure, "body").?] =
8013 @intFromEnum(body_type);8051 @intFromEnum(body_type);
...@@ -9372,7 +9410,7 @@ fn fnTypeAssumeCapacity(...@@ -9372,7 +9410,7 @@ fn fnTypeAssumeCapacity(
9372 ret: Type,9410 ret: Type,
9373 params: []const Type,9411 params: []const Type,
9374 comptime kind: Type.Function.Kind,9412 comptime kind: Type.Function.Kind,
9375) (if (build_options.have_llvm) Allocator.Error else error{})!Type {9413) Type {
9376 const tag: Type.Tag = switch (kind) {9414 const tag: Type.Tag = switch (kind) {
9377 .normal => .function,9415 .normal => .function,
9378 .vararg => .vararg_function,9416 .vararg => .vararg_function,
...@@ -9528,7 +9566,7 @@ fn structTypeAssumeCapacity(...@@ -9528,7 +9566,7 @@ fn structTypeAssumeCapacity(
9528 self: *Builder,9566 self: *Builder,
9529 comptime kind: Type.Structure.Kind,9567 comptime kind: Type.Structure.Kind,
9530 fields: []const Type,9568 fields: []const Type,
9531) (if (build_options.have_llvm) Allocator.Error else error{})!Type {9569) Type {
9532 const tag: Type.Tag = switch (kind) {9570 const tag: Type.Tag = switch (kind) {
9533 .normal => .structure,9571 .normal => .structure,
9534 .@"packed" => .packed_structure,9572 .@"packed" => .packed_structure,
...@@ -9739,10 +9777,7 @@ fn bigIntConstAssumeCapacity(...@@ -9739,10 +9777,7 @@ fn bigIntConstAssumeCapacity(
9739 assert(type_item.tag == .integer);9777 assert(type_item.tag == .integer);
9740 const bits = type_item.data;9778 const bits = type_item.data;
97419779
9742 const ExpectedContents = extern struct {9780 const ExpectedContents = [64 / @sizeOf(std.math.big.Limb)]std.math.big.Limb;
9743 limbs: [64 / @sizeOf(std.math.big.Limb)]std.math.big.Limb,
9744 llvm_limbs: if (build_options.have_llvm) [64 / @sizeOf(u64)]u64 else void,
9745 };
9746 var stack align(@alignOf(ExpectedContents)) =9781 var stack align(@alignOf(ExpectedContents)) =
9747 std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);9782 std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);
9748 const allocator = stack.get();9783 const allocator = stack.get();
...@@ -9973,11 +10008,7 @@ fn noneConstAssumeCapacity(self: *Builder, ty: Type) Constant {...@@ -9973,11 +10008,7 @@ fn noneConstAssumeCapacity(self: *Builder, ty: Type) Constant {
9973 return result.constant;10008 return result.constant;
9974}10009}
997510010
9976fn structConstAssumeCapacity(10011fn structConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
9977 self: *Builder,
9978 ty: Type,
9979 vals: []const Constant,
9980) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
9981 const type_item = self.type_items.items[@intFromEnum(ty)];10012 const type_item = self.type_items.items[@intFromEnum(ty)];
9982 var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) {10013 var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) {
9983 .structure, .packed_structure => type_item.data,10014 .structure, .packed_structure => type_item.data,
...@@ -10007,11 +10038,7 @@ fn structConstAssumeCapacity(...@@ -10007,11 +10038,7 @@ fn structConstAssumeCapacity(
10007 return result.constant;10038 return result.constant;
10008}10039}
1000910040
10010fn arrayConstAssumeCapacity(10041fn arrayConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
10011 self: *Builder,
10012 ty: Type,
10013 vals: []const Constant,
10014) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10015 const type_item = self.type_items.items[@intFromEnum(ty)];10042 const type_item = self.type_items.items[@intFromEnum(ty)];
10016 const type_extra: struct { len: u64, child: Type } = switch (type_item.tag) {10043 const type_extra: struct { len: u64, child: Type } = switch (type_item.tag) {
10017 inline .small_array, .array => |kind| extra: {10044 inline .small_array, .array => |kind| extra: {
...@@ -10055,11 +10082,7 @@ fn stringNullConstAssumeCapacity(self: *Builder, val: String) Constant {...@@ -10055,11 +10082,7 @@ fn stringNullConstAssumeCapacity(self: *Builder, val: String) Constant {
10055 return result.constant;10082 return result.constant;
10056}10083}
1005710084
10058fn vectorConstAssumeCapacity(10085fn vectorConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
10059 self: *Builder,
10060 ty: Type,
10061 vals: []const Constant,
10062) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10063 assert(ty.isVector(self));10086 assert(ty.isVector(self));
10064 assert(ty.vectorLen(self) == vals.len);10087 assert(ty.vectorLen(self) == vals.len);
10065 for (vals) |val| assert(ty.childType(self) == val.typeOf(self));10088 for (vals) |val| assert(ty.childType(self) == val.typeOf(self));
...@@ -10075,11 +10098,7 @@ fn vectorConstAssumeCapacity(...@@ -10075,11 +10098,7 @@ fn vectorConstAssumeCapacity(
10075 return result.constant;10098 return result.constant;
10076}10099}
1007710100
10078fn splatConstAssumeCapacity(10101fn splatConstAssumeCapacity(self: *Builder, ty: Type, val: Constant) Constant {
10079 self: *Builder,
10080 ty: Type,
10081 val: Constant,
10082) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10083 assert(ty.scalarType(self) == val.typeOf(self));10102 assert(ty.scalarType(self) == val.typeOf(self));
1008410103
10085 if (!ty.isVector(self)) return val;10104 if (!ty.isVector(self)) return val;
...@@ -10327,7 +10346,7 @@ fn gepConstAssumeCapacity(...@@ -10327,7 +10346,7 @@ fn gepConstAssumeCapacity(
10327 base: Constant,10346 base: Constant,
10328 inrange: ?u16,10347 inrange: ?u16,
10329 indices: []const Constant,10348 indices: []const Constant,
10330) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {10349) Constant {
10331 const tag: Constant.Tag = switch (kind) {10350 const tag: Constant.Tag = switch (kind) {
10332 .normal => .getelementptr,10351 .normal => .getelementptr,
10333 .inbounds => .@"getelementptr inbounds",10352 .inbounds => .@"getelementptr inbounds",
src/codegen/llvm/bindings.zig-38
...@@ -394,41 +394,3 @@ extern fn ZigLLVMWriteImportLibrary(...@@ -394,41 +394,3 @@ extern fn ZigLLVMWriteImportLibrary(
394 output_lib_path: [*:0]const u8,394 output_lib_path: [*:0]const u8,
395 kill_at: bool,395 kill_at: bool,
396) bool;396) bool;
397
398pub const DIFlags = opaque {
399 pub const Zero = 0;
400 pub const Private = 1;
401 pub const Protected = 2;
402 pub const Public = 3;
403
404 pub const FwdDecl = 1 << 2;
405 pub const AppleBlock = 1 << 3;
406 pub const BlockByrefStruct = 1 << 4;
407 pub const Virtual = 1 << 5;
408 pub const Artificial = 1 << 6;
409 pub const Explicit = 1 << 7;
410 pub const Prototyped = 1 << 8;
411 pub const ObjcClassComplete = 1 << 9;
412 pub const ObjectPointer = 1 << 10;
413 pub const Vector = 1 << 11;
414 pub const StaticMember = 1 << 12;
415 pub const LValueReference = 1 << 13;
416 pub const RValueReference = 1 << 14;
417 pub const Reserved = 1 << 15;
418
419 pub const SingleInheritance = 1 << 16;
420 pub const MultipleInheritance = 2 << 16;
421 pub const VirtualInheritance = 3 << 16;
422
423 pub const IntroducedVirtual = 1 << 18;
424 pub const BitField = 1 << 19;
425 pub const NoReturn = 1 << 20;
426 pub const TypePassByValue = 1 << 22;
427 pub const TypePassByReference = 1 << 23;
428 pub const EnumClass = 1 << 24;
429 pub const Thunk = 1 << 25;
430 pub const NonTrivial = 1 << 26;
431 pub const BigEndian = 1 << 27;
432 pub const LittleEndian = 1 << 28;
433 pub const AllCallsDescribed = 1 << 29;
434};