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 {
12121212 try file.writeAll(ptr[0..(bitcode.len * 4)]);
12131213 }
12141214
1215 if (!self.module.comp.config.use_lib_llvm) {
1215 if (!build_options.have_llvm or !self.module.comp.config.use_lib_llvm) {
12161216 log.err("emitting without libllvm not implemented", .{});
12171217 return error.FailedToEmit;
12181218 }
......@@ -1647,7 +1647,7 @@ pub const Object = struct {
16471647 const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
16481648 !zcu.decl_exports.contains(decl_index);
16491649 const noret_bit: u29 = if (fn_info.return_type == .noreturn_type)
1650 llvm.DIFlags.NoReturn
1650 Builder.DIFlags.NoReturn
16511651 else
16521652 0;
16531653 const debug_decl_type = try o.lowerDebugType(decl.ty);
......@@ -1663,7 +1663,7 @@ pub const Object = struct {
16631663 .optimized = owner_mod.optimize_mode != .Debug,
16641664 .definition = true,
16651665 .local = is_internal_linkage,
1666 .debug_info_flags = llvm.DIFlags.StaticMember | noret_bit,
1666 .debug_info_flags = Builder.DIFlags.StaticMember | noret_bit,
16671667 },
16681668 o.debug_compile_unit,
16691669 );
......@@ -3372,7 +3372,7 @@ pub const Object = struct {
33723372 const ty = try o.builder.opaqueType(name);
33733373 try o.type_map.put(o.gpa, t.toIntern(), ty);
33743374
3375 try o.builder.namedTypeSetBody(
3375 o.builder.namedTypeSetBody(
33763376 ty,
33773377 try o.builder.structType(struct_kind, llvm_field_types.items),
33783378 );
......@@ -3483,7 +3483,7 @@ pub const Object = struct {
34833483 const ty = try o.builder.opaqueType(name);
34843484 try o.type_map.put(o.gpa, t.toIntern(), ty);
34853485
3486 try o.builder.namedTypeSetBody(
3486 o.builder.namedTypeSetBody(
34873487 ty,
34883488 try o.builder.structType(.normal, &.{payload_ty}),
34893489 );
......@@ -3511,7 +3511,7 @@ pub const Object = struct {
35113511 const ty = try o.builder.opaqueType(name);
35123512 try o.type_map.put(o.gpa, t.toIntern(), ty);
35133513
3514 try o.builder.namedTypeSetBody(
3514 o.builder.namedTypeSetBody(
35153515 ty,
35163516 try o.builder.structType(.normal, llvm_fields[0..llvm_fields_len]),
35173517 );
......@@ -4773,7 +4773,6 @@ pub const FuncGen = struct {
47734773
47744774 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 {};
47774776 const BreakList = union {
47784777 list: std.MultiArrayList(struct {
47794778 bb: Builder.Function.Block.Index,
......@@ -5760,7 +5759,7 @@ pub const FuncGen = struct {
57605759 };
57615760
57625761 const phi = try self.wip.phi(.i1, "");
5763 try phi.finish(
5762 phi.finish(
57645763 &incoming_values,
57655764 &.{ both_null_block, mixed_block, both_pl_block_end },
57665765 &self.wip,
......@@ -5827,7 +5826,7 @@ pub const FuncGen = struct {
58275826
58285827 parent_bb.ptr(&self.wip).incoming = @intCast(breaks.list.len);
58295828 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);
58315830 return phi.toValue();
58325831 } else {
58335832 parent_bb.ptr(&self.wip).incoming = @intCast(breaks.len);
......@@ -6615,7 +6614,7 @@ pub const FuncGen = struct {
66156614 .optimized = owner_mod.optimize_mode != .Debug,
66166615 .local = is_internal_linkage,
66176616 .definition = true,
6618 .debug_info_flags = llvm.DIFlags.StaticMember,
6617 .debug_info_flags = Builder.DIFlags.StaticMember,
66196618 },
66206619 o.debug_compile_unit,
66216620 );
......@@ -9350,7 +9349,7 @@ pub const FuncGen = struct {
93509349 _ = try self.wip.br(loop_block);
93519350
93529351 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);
93549353 return .none;
93559354 }
93569355
......@@ -9585,7 +9584,7 @@ pub const FuncGen = struct {
95859584
95869585 self.wip.cursor = .{ .block = end_block };
95879586 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);
95899588 return phi.toValue();
95909589 }
95919590
src/codegen/llvm/Builder.zig+50-31
......@@ -4264,7 +4264,7 @@ pub const Function = struct {
42644264 => wip.builder.structTypeAssumeCapacity(.normal, &.{
42654265 wip.extraData(CmpXchg, instruction.data).cmp.typeOfWip(wip),
42664266 .i1,
4267 }) catch unreachable,
4267 }),
42684268 .extractelement => wip.extraData(ExtractElement, instruction.data)
42694269 .val.typeOfWip(wip).childType(wip.builder),
42704270 .extractvalue => {
......@@ -4451,7 +4451,7 @@ pub const Function = struct {
44514451 function.extraData(CmpXchg, instruction.data)
44524452 .cmp.typeOf(function_index, builder),
44534453 .i1,
4454 }) catch unreachable,
4454 }),
44554455 .extractelement => function.extraData(ExtractElement, instruction.data)
44564456 .val.typeOf(function_index, builder).childType(builder),
44574457 .extractvalue => {
......@@ -4840,6 +4840,44 @@ pub const DebugLocation = struct {
48404840 inlined_at: Metadata,
48414841};
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
48434881pub const WipFunction = struct {
48444882 builder: *Builder,
48454883 function: Function.Index,
......@@ -5610,7 +5648,7 @@ pub const WipFunction = struct {
56105648 vals: []const Value,
56115649 blocks: []const Block.Index,
56125650 wip: *WipFunction,
5613 ) (if (build_options.have_llvm) Allocator.Error else error{})!void {
5651 ) void {
56145652 const incoming_len = self.block.ptrConst(wip).incoming;
56155653 assert(vals.len == incoming_len and blocks.len == incoming_len);
56165654 const instruction = wip.instructions.get(@intFromEnum(self.instruction));
......@@ -8007,7 +8045,7 @@ pub fn namedTypeSetBody(
80078045 self: *Builder,
80088046 named_type: Type,
80098047 body_type: Type,
8010) (if (build_options.have_llvm) Allocator.Error else error{})!void {
8048) void {
80118049 const named_item = self.type_items.items[@intFromEnum(named_type)];
80128050 self.type_extra.items[named_item.data + std.meta.fieldIndex(Type.NamedStructure, "body").?] =
80138051 @intFromEnum(body_type);
......@@ -9372,7 +9410,7 @@ fn fnTypeAssumeCapacity(
93729410 ret: Type,
93739411 params: []const Type,
93749412 comptime kind: Type.Function.Kind,
9375) (if (build_options.have_llvm) Allocator.Error else error{})!Type {
9413) Type {
93769414 const tag: Type.Tag = switch (kind) {
93779415 .normal => .function,
93789416 .vararg => .vararg_function,
......@@ -9528,7 +9566,7 @@ fn structTypeAssumeCapacity(
95289566 self: *Builder,
95299567 comptime kind: Type.Structure.Kind,
95309568 fields: []const Type,
9531) (if (build_options.have_llvm) Allocator.Error else error{})!Type {
9569) Type {
95329570 const tag: Type.Tag = switch (kind) {
95339571 .normal => .structure,
95349572 .@"packed" => .packed_structure,
......@@ -9739,10 +9777,7 @@ fn bigIntConstAssumeCapacity(
97399777 assert(type_item.tag == .integer);
97409778 const bits = type_item.data;
97419779
9742 const ExpectedContents = extern struct {
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 };
9780 const ExpectedContents = [64 / @sizeOf(std.math.big.Limb)]std.math.big.Limb;
97469781 var stack align(@alignOf(ExpectedContents)) =
97479782 std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);
97489783 const allocator = stack.get();
......@@ -9973,11 +10008,7 @@ fn noneConstAssumeCapacity(self: *Builder, ty: Type) Constant {
997310008 return result.constant;
997410009}
997510010
9976fn structConstAssumeCapacity(
9977 self: *Builder,
9978 ty: Type,
9979 vals: []const Constant,
9980) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10011fn structConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
998110012 const type_item = self.type_items.items[@intFromEnum(ty)];
998210013 var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) {
998310014 .structure, .packed_structure => type_item.data,
......@@ -10007,11 +10038,7 @@ fn structConstAssumeCapacity(
1000710038 return result.constant;
1000810039}
1000910040
10010fn arrayConstAssumeCapacity(
10011 self: *Builder,
10012 ty: Type,
10013 vals: []const Constant,
10014) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10041fn arrayConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
1001510042 const type_item = self.type_items.items[@intFromEnum(ty)];
1001610043 const type_extra: struct { len: u64, child: Type } = switch (type_item.tag) {
1001710044 inline .small_array, .array => |kind| extra: {
......@@ -10055,11 +10082,7 @@ fn stringNullConstAssumeCapacity(self: *Builder, val: String) Constant {
1005510082 return result.constant;
1005610083}
1005710084
10058fn vectorConstAssumeCapacity(
10059 self: *Builder,
10060 ty: Type,
10061 vals: []const Constant,
10062) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10085fn vectorConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
1006310086 assert(ty.isVector(self));
1006410087 assert(ty.vectorLen(self) == vals.len);
1006510088 for (vals) |val| assert(ty.childType(self) == val.typeOf(self));
......@@ -10075,11 +10098,7 @@ fn vectorConstAssumeCapacity(
1007510098 return result.constant;
1007610099}
1007710100
10078fn splatConstAssumeCapacity(
10079 self: *Builder,
10080 ty: Type,
10081 val: Constant,
10082) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10101fn splatConstAssumeCapacity(self: *Builder, ty: Type, val: Constant) Constant {
1008310102 assert(ty.scalarType(self) == val.typeOf(self));
1008410103
1008510104 if (!ty.isVector(self)) return val;
......@@ -10327,7 +10346,7 @@ fn gepConstAssumeCapacity(
1032710346 base: Constant,
1032810347 inrange: ?u16,
1032910348 indices: []const Constant,
10330) (if (build_options.have_llvm) Allocator.Error else error{})!Constant {
10349) Constant {
1033110350 const tag: Constant.Tag = switch (kind) {
1033210351 .normal => .getelementptr,
1033310352 .inbounds => .@"getelementptr inbounds",
src/codegen/llvm/bindings.zig-38
......@@ -394,41 +394,3 @@ extern fn ZigLLVMWriteImportLibrary(
394394 output_lib_path: [*:0]const u8,
395395 kill_at: bool,
396396) 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};