| ... | ... | @@ -7,6 +7,7 @@ const Allocator = std.mem.Allocator; |
| 7 | 7 | const assert = std.debug.assert; |
| 8 | 8 | const DW = std.dwarf; |
| 9 | 9 | const log = std.log.scoped(.llvm); |
| 10 | const maxInt = std.math.maxInt; |
| 10 | 11 | const Writer = std.Io.Writer; |
| 11 | 12 | |
| 12 | 13 | const bitcode_writer = @import("bitcode_writer.zig"); |
| ... | ... | @@ -55,6 +56,8 @@ constant_items: std.MultiArrayList(Constant.Item), |
| 55 | 56 | constant_extra: std.ArrayList(u32), |
| 56 | 57 | constant_limbs: std.ArrayList(std.math.big.Limb), |
| 57 | 58 | |
| 59 | alignment_forward_references: std.ArrayList(Alignment), |
| 60 | |
| 58 | 61 | metadata_map: std.AutoArrayHashMapUnmanaged(void, void), |
| 59 | 62 | metadata_items: std.MultiArrayList(Metadata.Item), |
| 60 | 63 | metadata_extra: std.ArrayList(u32), |
| ... | ... | @@ -85,7 +88,7 @@ pub const Options = struct { |
| 85 | 88 | }; |
| 86 | 89 | |
| 87 | 90 | pub const String = enum(u32) { |
| 88 | | none = std.math.maxInt(u31), |
| 91 | none = maxInt(u31), |
| 89 | 92 | empty, |
| 90 | 93 | _, |
| 91 | 94 | |
| ... | ... | @@ -245,7 +248,7 @@ pub const Type = enum(u32) { |
| 245 | 248 | ptr, |
| 246 | 249 | @"ptr addrspace(4)", |
| 247 | 250 | |
| 248 | | none = std.math.maxInt(u32), |
| 251 | none = maxInt(u32), |
| 249 | 252 | _, |
| 250 | 253 | |
| 251 | 254 | pub const ptr_amdgpu_constant = |
| ... | ... | @@ -941,7 +944,7 @@ pub const Attribute = union(Kind) { |
| 941 | 944 | inalloca: Type, |
| 942 | 945 | sret: Type, |
| 943 | 946 | elementtype: Type, |
| 944 | | @"align": Alignment, |
| 947 | @"align": Alignment.Lazy, |
| 945 | 948 | @"noalias", |
| 946 | 949 | nocapture, |
| 947 | 950 | nofree, |
| ... | ... | @@ -956,7 +959,7 @@ pub const Attribute = union(Kind) { |
| 956 | 959 | immarg, |
| 957 | 960 | noundef, |
| 958 | 961 | nofpclass: FpClass, |
| 959 | | alignstack: Alignment, |
| 962 | alignstack: Alignment.Lazy, |
| 960 | 963 | allocalign, |
| 961 | 964 | allocptr, |
| 962 | 965 | readnone, |
| ... | ... | @@ -964,7 +967,7 @@ pub const Attribute = union(Kind) { |
| 964 | 967 | writeonly, |
| 965 | 968 | |
| 966 | 969 | // Function Attributes |
| 967 | | //alignstack: Alignment, |
| 970 | //alignstack: Alignment.Lazy, |
| 968 | 971 | allockind: AllocKind, |
| 969 | 972 | allocsize: AllocSize, |
| 970 | 973 | alwaysinline, |
| ... | ... | @@ -1145,7 +1148,7 @@ pub const Attribute = union(Kind) { |
| 1145 | 1148 | return @unionInit(Attribute, field.name, switch (field.type) { |
| 1146 | 1149 | void => {}, |
| 1147 | 1150 | u32 => storage.value, |
| 1148 | | Alignment, String, Type, UwTable => @enumFromInt(storage.value), |
| 1151 | Alignment.Lazy, String, Type, UwTable => @enumFromInt(storage.value), |
| 1149 | 1152 | AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(storage.value), |
| 1150 | 1153 | else => @compileError("bad payload type: " ++ field.name ++ ": " ++ |
| 1151 | 1154 | @typeName(field.type)), |
| ... | ... | @@ -1246,7 +1249,7 @@ pub const Attribute = union(Kind) { |
| 1246 | 1249 | .sret, |
| 1247 | 1250 | .elementtype, |
| 1248 | 1251 | => |ty| try w.print(" {s}({f})", .{ @tagName(attribute), ty.fmt(data.builder, .percent) }), |
| 1249 | | .@"align" => |alignment| try w.print("{f}", .{alignment.fmt(" ")}), |
| 1252 | .@"align" => |alignment| try w.print("{f}", .{alignment.resolve(data.builder).fmt(" ")}), |
| 1250 | 1253 | .dereferenceable, |
| 1251 | 1254 | .dereferenceable_or_null, |
| 1252 | 1255 | => |size| try w.print(" {s}({d})", .{ @tagName(attribute), size }), |
| ... | ... | @@ -1270,7 +1273,7 @@ pub const Attribute = union(Kind) { |
| 1270 | 1273 | }, |
| 1271 | 1274 | .alignstack => |alignment| { |
| 1272 | 1275 | try w.print(" {t}", .{attribute}); |
| 1273 | | const alignment_bytes = alignment.toByteUnits() orelse return; |
| 1276 | const alignment_bytes = alignment.resolve(data.builder).toByteUnits() orelse return; |
| 1274 | 1277 | if (data.flags.pound) { |
| 1275 | 1278 | try w.print("={d}", .{alignment_bytes}); |
| 1276 | 1279 | } else { |
| ... | ... | @@ -1435,8 +1438,8 @@ pub const Attribute = union(Kind) { |
| 1435 | 1438 | //sanitize_memtag, |
| 1436 | 1439 | sanitize_address_dyninit = 102, |
| 1437 | 1440 | |
| 1438 | | string = std.math.maxInt(u31), |
| 1439 | | none = std.math.maxInt(u32), |
| 1441 | string = maxInt(u31), |
| 1442 | none = maxInt(u32), |
| 1440 | 1443 | _, |
| 1441 | 1444 | |
| 1442 | 1445 | pub const len = @typeInfo(Kind).@"enum".fields.len - 2; |
| ... | ... | @@ -1516,12 +1519,12 @@ pub const Attribute = union(Kind) { |
| 1516 | 1519 | elem_size: u16, |
| 1517 | 1520 | num_elems: u16, |
| 1518 | 1521 | |
| 1519 | | pub const none = std.math.maxInt(u16); |
| 1522 | pub const none = maxInt(u16); |
| 1520 | 1523 | |
| 1521 | 1524 | fn toLlvm(self: AllocSize) packed struct(u64) { num_elems: u32, elem_size: u32 } { |
| 1522 | 1525 | return .{ .num_elems = switch (self.num_elems) { |
| 1523 | 1526 | else => self.num_elems, |
| 1524 | | none => std.math.maxInt(u32), |
| 1527 | none => maxInt(u32), |
| 1525 | 1528 | }, .elem_size = self.elem_size }; |
| 1526 | 1529 | } |
| 1527 | 1530 | }; |
| ... | ... | @@ -1577,7 +1580,7 @@ pub const Attribute = union(Kind) { |
| 1577 | 1580 | inline else => |value, tag| .{ .kind = @as(Kind, self), .value = switch (@TypeOf(value)) { |
| 1578 | 1581 | void => 0, |
| 1579 | 1582 | u32 => value, |
| 1580 | | Alignment, String, Type, UwTable => @intFromEnum(value), |
| 1583 | Alignment.Lazy, String, Type, UwTable => @intFromEnum(value), |
| 1581 | 1584 | AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(value), |
| 1582 | 1585 | else => @compileError("bad payload type: " ++ @tagName(tag) ++ @typeName(@TypeOf(value))), |
| 1583 | 1586 | } }, |
| ... | ... | @@ -2017,9 +2020,32 @@ pub const ExternallyInitialized = enum { |
| 2017 | 2020 | }; |
| 2018 | 2021 | |
| 2019 | 2022 | pub const Alignment = enum(u6) { |
| 2020 | | default = std.math.maxInt(u6), |
| 2023 | default = maxInt(u6), |
| 2021 | 2024 | _, |
| 2022 | 2025 | |
| 2026 | pub const Lazy = enum(u32) { |
| 2027 | /// Values which fit in a `u6` are already-resolved `Alignment` values. Other values are |
| 2028 | /// indices into `Builder.alignment_forward_references`, offset by `maxInt(u6)`. |
| 2029 | _, |
| 2030 | |
| 2031 | pub fn wrap(a: Alignment) Lazy { |
| 2032 | return @enumFromInt(@intFromEnum(a)); |
| 2033 | } |
| 2034 | pub fn resolve(l: Lazy, b: *const Builder) Alignment { |
| 2035 | return switch (@intFromEnum(l)) { |
| 2036 | 0...maxInt(u6) => |raw| @enumFromInt(raw), |
| 2037 | else => |offset_index| b.alignment_forward_references.items[offset_index - maxInt(u6)], |
| 2038 | }; |
| 2039 | } |
| 2040 | |
| 2041 | fn fromFwdRefIndex(index: usize) Lazy { |
| 2042 | return @enumFromInt(index + maxInt(u6)); |
| 2043 | } |
| 2044 | fn toFwdRefIndex(l: Lazy) usize { |
| 2045 | return @intFromEnum(l) - maxInt(u6); |
| 2046 | } |
| 2047 | }; |
| 2048 | |
| 2023 | 2049 | pub fn fromByteUnits(bytes: u64) Alignment { |
| 2024 | 2050 | if (bytes == 0) return .default; |
| 2025 | 2051 | assert(std.math.isPowerOfTwo(bytes)); |
| ... | ... | @@ -2028,11 +2054,17 @@ pub const Alignment = enum(u6) { |
| 2028 | 2054 | } |
| 2029 | 2055 | |
| 2030 | 2056 | pub fn toByteUnits(self: Alignment) ?u64 { |
| 2031 | | return if (self == .default) null else @as(u64, 1) << @intFromEnum(self); |
| 2057 | return switch (self) { |
| 2058 | .default => null, |
| 2059 | else => @as(u64, 1) << @intFromEnum(self), |
| 2060 | }; |
| 2032 | 2061 | } |
| 2033 | 2062 | |
| 2034 | 2063 | pub fn toLlvm(self: Alignment) u6 { |
| 2035 | | return if (self == .default) 0 else (@intFromEnum(self) + 1); |
| 2064 | return switch (self) { |
| 2065 | .default => 0, |
| 2066 | else => @intFromEnum(self) + 1, |
| 2067 | }; |
| 2036 | 2068 | } |
| 2037 | 2069 | |
| 2038 | 2070 | pub const Prefixed = struct { |
| ... | ... | @@ -2180,7 +2212,7 @@ pub const CallConv = enum(u10) { |
| 2180 | 2212 | }; |
| 2181 | 2213 | |
| 2182 | 2214 | pub const StrtabString = enum(u32) { |
| 2183 | | none = std.math.maxInt(u31), |
| 2215 | none = maxInt(u31), |
| 2184 | 2216 | empty, |
| 2185 | 2217 | _, |
| 2186 | 2218 | |
| ... | ... | @@ -2308,7 +2340,7 @@ pub const Global = struct { |
| 2308 | 2340 | }, |
| 2309 | 2341 | |
| 2310 | 2342 | pub const Index = enum(u32) { |
| 2311 | | none = std.math.maxInt(u32), |
| 2343 | none = maxInt(u32), |
| 2312 | 2344 | _, |
| 2313 | 2345 | |
| 2314 | 2346 | pub fn unwrap(self: Index, builder: *const Builder) Index { |
| ... | ... | @@ -2478,7 +2510,7 @@ pub const Alias = struct { |
| 2478 | 2510 | aliasee: Constant = .no_init, |
| 2479 | 2511 | |
| 2480 | 2512 | pub const Index = enum(u32) { |
| 2481 | | none = std.math.maxInt(u32), |
| 2513 | none = maxInt(u32), |
| 2482 | 2514 | _, |
| 2483 | 2515 | |
| 2484 | 2516 | pub fn ptr(self: Index, builder: *Builder) *Alias { |
| ... | ... | @@ -2530,7 +2562,7 @@ pub const Variable = struct { |
| 2530 | 2562 | alignment: Alignment = .default, |
| 2531 | 2563 | |
| 2532 | 2564 | pub const Index = enum(u32) { |
| 2533 | | none = std.math.maxInt(u32), |
| 2565 | none = maxInt(u32), |
| 2534 | 2566 | _, |
| 2535 | 2567 | |
| 2536 | 2568 | pub fn ptr(self: Index, builder: *Builder) *Variable { |
| ... | ... | @@ -3949,7 +3981,7 @@ pub const Intrinsic = enum { |
| 3949 | 3981 | .params = &.{ |
| 3950 | 3982 | .{ |
| 3951 | 3983 | .kind = .{ .type = Type.ptr_amdgpu_constant }, |
| 3952 | | .attrs = &.{.{ .@"align" = Builder.Alignment.fromByteUnits(4) }}, |
| 3984 | .attrs = &.{.{ .@"align" = .wrap(.fromByteUnits(4)) }}, |
| 3953 | 3985 | }, |
| 3954 | 3986 | }, |
| 3955 | 3987 | .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } }, |
| ... | ... | @@ -4057,7 +4089,7 @@ pub const Function = struct { |
| 4057 | 4089 | extra: []const u32 = &.{}, |
| 4058 | 4090 | |
| 4059 | 4091 | pub const Index = enum(u32) { |
| 4060 | | none = std.math.maxInt(u32), |
| 4092 | none = maxInt(u32), |
| 4061 | 4093 | _, |
| 4062 | 4094 | |
| 4063 | 4095 | pub fn ptr(self: Index, builder: *Builder) *Function { |
| ... | ... | @@ -4411,7 +4443,7 @@ pub const Function = struct { |
| 4411 | 4443 | }; |
| 4412 | 4444 | |
| 4413 | 4445 | pub const Index = enum(u32) { |
| 4414 | | none = std.math.maxInt(u31), |
| 4446 | none = maxInt(u31), |
| 4415 | 4447 | _, |
| 4416 | 4448 | |
| 4417 | 4449 | pub fn name(self: Instruction.Index, function: *const Function) String { |
| ... | ... | @@ -5007,7 +5039,7 @@ pub const Function = struct { |
| 5007 | 5039 | fsub = 12, |
| 5008 | 5040 | fmax = 13, |
| 5009 | 5041 | fmin = 14, |
| 5010 | | none = std.math.maxInt(u5), |
| 5042 | none = maxInt(u5), |
| 5011 | 5043 | }; |
| 5012 | 5044 | }; |
| 5013 | 5045 | |
| ... | ... | @@ -6132,8 +6164,8 @@ pub const WipFunction = struct { |
| 6132 | 6164 | kind: MemoryAccessKind, |
| 6133 | 6165 | @"inline": bool, |
| 6134 | 6166 | ) Allocator.Error!Instruction.Index { |
| 6135 | | var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = dst_align })}; |
| 6136 | | var src_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = src_align })}; |
| 6167 | var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(dst_align) })}; |
| 6168 | var src_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(src_align) })}; |
| 6137 | 6169 | const value = try self.callIntrinsic( |
| 6138 | 6170 | .normal, |
| 6139 | 6171 | try self.builder.fnAttrs(&.{ |
| ... | ... | @@ -6162,8 +6194,8 @@ pub const WipFunction = struct { |
| 6162 | 6194 | len: Value, |
| 6163 | 6195 | kind: MemoryAccessKind, |
| 6164 | 6196 | ) Allocator.Error!Instruction.Index { |
| 6165 | | var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = dst_align })}; |
| 6166 | | var src_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = src_align })}; |
| 6197 | var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(dst_align) })}; |
| 6198 | var src_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(src_align) })}; |
| 6167 | 6199 | const value = try self.callIntrinsic( |
| 6168 | 6200 | .normal, |
| 6169 | 6201 | try self.builder.fnAttrs(&.{ |
| ... | ... | @@ -6192,7 +6224,7 @@ pub const WipFunction = struct { |
| 6192 | 6224 | kind: MemoryAccessKind, |
| 6193 | 6225 | @"inline": bool, |
| 6194 | 6226 | ) Allocator.Error!Instruction.Index { |
| 6195 | | var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = dst_align })}; |
| 6227 | var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(dst_align) })}; |
| 6196 | 6228 | const value = try self.callIntrinsic( |
| 6197 | 6229 | .normal, |
| 6198 | 6230 | try self.builder.fnAttrs(&.{ .none, .none, try self.builder.attrs(&dst_attrs) }), |
| ... | ... | @@ -7329,7 +7361,7 @@ pub const Constant = enum(u32) { |
| 7329 | 7361 | //indices: [info.indices_len]Constant, |
| 7330 | 7362 | |
| 7331 | 7363 | pub const Kind = enum { normal, inbounds }; |
| 7332 | | pub const InRangeIndex = enum(u16) { none = std.math.maxInt(u16), _ }; |
| 7364 | pub const InRangeIndex = enum(u16) { none = maxInt(u16), _ }; |
| 7333 | 7365 | pub const Info = packed struct(u32) { indices_len: u16, inrange: InRangeIndex }; |
| 7334 | 7366 | }; |
| 7335 | 7367 | |
| ... | ... | @@ -7579,7 +7611,7 @@ pub const Constant = enum(u32) { |
| 7579 | 7611 | string: [ |
| 7580 | 7612 | (std.math.big.int.Const{ |
| 7581 | 7613 | .limbs = &([1]std.math.big.Limb{ |
| 7582 | | std.math.maxInt(std.math.big.Limb), |
| 7614 | maxInt(std.math.big.Limb), |
| 7583 | 7615 | } ** expected_limbs), |
| 7584 | 7616 | .positive = false, |
| 7585 | 7617 | }).sizeInBaseUpperBound(10) |
| ... | ... | @@ -7643,7 +7675,7 @@ pub const Constant = enum(u32) { |
| 7643 | 7675 | std.math.minInt(Exponent64), |
| 7644 | 7676 | else => @as(Exponent64, repr.exponent) + |
| 7645 | 7677 | (std.math.floatExponentMax(f64) - std.math.floatExponentMax(f32)), |
| 7646 | | std.math.maxInt(Exponent32) => std.math.maxInt(Exponent64), |
| 7678 | maxInt(Exponent32) => maxInt(Exponent64), |
| 7647 | 7679 | }, |
| 7648 | 7680 | .sign = repr.sign, |
| 7649 | 7681 | }))}); |
| ... | ... | @@ -7820,7 +7852,7 @@ pub const Constant = enum(u32) { |
| 7820 | 7852 | }; |
| 7821 | 7853 | |
| 7822 | 7854 | pub const Value = enum(u32) { |
| 7823 | | none = std.math.maxInt(u31), |
| 7855 | none = maxInt(u31), |
| 7824 | 7856 | false = first_constant + @intFromEnum(Constant.false), |
| 7825 | 7857 | true = first_constant + @intFromEnum(Constant.true), |
| 7826 | 7858 | @"0" = first_constant + @intFromEnum(Constant.@"0"), |
| ... | ... | @@ -8688,6 +8720,8 @@ pub fn init(options: Options) Allocator.Error!Builder { |
| 8688 | 8720 | .constant_extra = .empty, |
| 8689 | 8721 | .constant_limbs = .empty, |
| 8690 | 8722 | |
| 8723 | .alignment_forward_references = .empty, |
| 8724 | |
| 8691 | 8725 | .metadata_map = .empty, |
| 8692 | 8726 | .metadata_items = .empty, |
| 8693 | 8727 | .metadata_extra = .empty, |
| ... | ... | @@ -8800,51 +8834,55 @@ pub fn clearAndFree(self: *Builder) void { |
| 8800 | 8834 | } |
| 8801 | 8835 | |
| 8802 | 8836 | pub fn deinit(self: *Builder) void { |
| 8803 | | self.module_asm.deinit(self.gpa); |
| 8837 | const gpa = self.gpa; |
| 8804 | 8838 | |
| 8805 | | self.string_map.deinit(self.gpa); |
| 8806 | | self.string_indices.deinit(self.gpa); |
| 8807 | | self.string_bytes.deinit(self.gpa); |
| 8839 | self.module_asm.deinit(gpa); |
| 8808 | 8840 | |
| 8809 | | self.types.deinit(self.gpa); |
| 8810 | | self.next_unique_type_id.deinit(self.gpa); |
| 8811 | | self.type_map.deinit(self.gpa); |
| 8812 | | self.type_items.deinit(self.gpa); |
| 8813 | | self.type_extra.deinit(self.gpa); |
| 8841 | self.string_map.deinit(gpa); |
| 8842 | self.string_indices.deinit(gpa); |
| 8843 | self.string_bytes.deinit(gpa); |
| 8814 | 8844 | |
| 8815 | | self.attributes.deinit(self.gpa); |
| 8816 | | self.attributes_map.deinit(self.gpa); |
| 8817 | | self.attributes_indices.deinit(self.gpa); |
| 8818 | | self.attributes_extra.deinit(self.gpa); |
| 8845 | self.types.deinit(gpa); |
| 8846 | self.next_unique_type_id.deinit(gpa); |
| 8847 | self.type_map.deinit(gpa); |
| 8848 | self.type_items.deinit(gpa); |
| 8849 | self.type_extra.deinit(gpa); |
| 8819 | 8850 | |
| 8820 | | self.function_attributes_set.deinit(self.gpa); |
| 8851 | self.attributes.deinit(gpa); |
| 8852 | self.attributes_map.deinit(gpa); |
| 8853 | self.attributes_indices.deinit(gpa); |
| 8854 | self.attributes_extra.deinit(gpa); |
| 8821 | 8855 | |
| 8822 | | self.globals.deinit(self.gpa); |
| 8823 | | self.next_unique_global_id.deinit(self.gpa); |
| 8824 | | self.aliases.deinit(self.gpa); |
| 8825 | | self.variables.deinit(self.gpa); |
| 8826 | | for (self.functions.items) |*function| function.deinit(self.gpa); |
| 8827 | | self.functions.deinit(self.gpa); |
| 8856 | self.function_attributes_set.deinit(gpa); |
| 8857 | |
| 8858 | self.globals.deinit(gpa); |
| 8859 | self.next_unique_global_id.deinit(gpa); |
| 8860 | self.aliases.deinit(gpa); |
| 8861 | self.variables.deinit(gpa); |
| 8862 | for (self.functions.items) |*function| function.deinit(gpa); |
| 8863 | self.functions.deinit(gpa); |
| 8828 | 8864 | |
| 8829 | | self.strtab_string_map.deinit(self.gpa); |
| 8830 | | self.strtab_string_indices.deinit(self.gpa); |
| 8831 | | self.strtab_string_bytes.deinit(self.gpa); |
| 8865 | self.strtab_string_map.deinit(gpa); |
| 8866 | self.strtab_string_indices.deinit(gpa); |
| 8867 | self.strtab_string_bytes.deinit(gpa); |
| 8832 | 8868 | |
| 8833 | | self.constant_map.deinit(self.gpa); |
| 8834 | | self.constant_items.deinit(self.gpa); |
| 8835 | | self.constant_extra.deinit(self.gpa); |
| 8836 | | self.constant_limbs.deinit(self.gpa); |
| 8869 | self.constant_map.deinit(gpa); |
| 8870 | self.constant_items.deinit(gpa); |
| 8871 | self.constant_extra.deinit(gpa); |
| 8872 | self.constant_limbs.deinit(gpa); |
| 8837 | 8873 | |
| 8838 | | self.metadata_map.deinit(self.gpa); |
| 8839 | | self.metadata_items.deinit(self.gpa); |
| 8840 | | self.metadata_extra.deinit(self.gpa); |
| 8841 | | self.metadata_limbs.deinit(self.gpa); |
| 8842 | | self.metadata_forward_references.deinit(self.gpa); |
| 8843 | | self.metadata_named.deinit(self.gpa); |
| 8874 | self.alignment_forward_references.deinit(gpa); |
| 8844 | 8875 | |
| 8845 | | self.metadata_string_map.deinit(self.gpa); |
| 8846 | | self.metadata_string_indices.deinit(self.gpa); |
| 8847 | | self.metadata_string_bytes.deinit(self.gpa); |
| 8876 | self.metadata_map.deinit(gpa); |
| 8877 | self.metadata_items.deinit(gpa); |
| 8878 | self.metadata_extra.deinit(gpa); |
| 8879 | self.metadata_limbs.deinit(gpa); |
| 8880 | self.metadata_forward_references.deinit(gpa); |
| 8881 | self.metadata_named.deinit(gpa); |
| 8882 | |
| 8883 | self.metadata_string_map.deinit(gpa); |
| 8884 | self.metadata_string_indices.deinit(gpa); |
| 8885 | self.metadata_string_bytes.deinit(gpa); |
| 8848 | 8886 | |
| 8849 | 8887 | self.* = undefined; |
| 8850 | 8888 | } |
| ... | ... | @@ -8962,7 +9000,7 @@ pub fn structType( |
| 8962 | 9000 | pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type { |
| 8963 | 9001 | try self.string_map.ensureUnusedCapacity(self.gpa, 1); |
| 8964 | 9002 | if (name.slice(self)) |id| { |
| 8965 | | const count: usize = comptime std.fmt.count("{d}", .{std.math.maxInt(u32)}); |
| 9003 | const count: usize = comptime std.fmt.count("{d}", .{maxInt(u32)}); |
| 8966 | 9004 | try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count); |
| 8967 | 9005 | } |
| 8968 | 9006 | try self.string_indices.ensureUnusedCapacity(self.gpa, 1); |
| ... | ... | @@ -9578,6 +9616,21 @@ pub fn asmValue( |
| 9578 | 9616 | return (try self.asmConst(ty, info, assembly, constraints)).toValue(); |
| 9579 | 9617 | } |
| 9580 | 9618 | |
| 9619 | /// The initial "resolved" value of the forward reference is `Alignment.default`. |
| 9620 | pub fn alignmentForwardReference(b: *Builder) Allocator.Error!Alignment.Lazy { |
| 9621 | const index = b.alignment_forward_references.items.len; |
| 9622 | try b.alignment_forward_references.append(b.gpa, .default); |
| 9623 | return .fromFwdRefIndex(index); |
| 9624 | } |
| 9625 | |
| 9626 | /// Updates the "resolved" value of the alignment forward reference `fwd_ref` to `value`. |
| 9627 | /// |
| 9628 | /// Asserts that `fwd_ref` is a forward reference, as opposed to a resolved alignment value. |
| 9629 | pub fn resolveAlignmentForwardReference(b: *Builder, fwd_ref: Alignment.Lazy, value: Alignment) void { |
| 9630 | const index = fwd_ref.toFwdRefIndex(); |
| 9631 | b.alignment_forward_references.items[index] = value; |
| 9632 | } |
| 9633 | |
| 9581 | 9634 | pub fn dump(b: *Builder, io: Io) void { |
| 9582 | 9635 | var buffer: [4000]u8 = undefined; |
| 9583 | 9636 | const stderr: Io.File = .stderr(); |
| ... | ... | @@ -10515,7 +10568,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10515 | 10568 | string: [ |
| 10516 | 10569 | (std.math.big.int.Const{ |
| 10517 | 10570 | .limbs = &([1]std.math.big.Limb{ |
| 10518 | | std.math.maxInt(std.math.big.Limb), |
| 10571 | maxInt(std.math.big.Limb), |
| 10519 | 10572 | } ** expected_limbs), |
| 10520 | 10573 | .positive = false, |
| 10521 | 10574 | }).sizeInBaseUpperBound(10) |
| ... | ... | @@ -10665,7 +10718,7 @@ fn printEscapedString(slice: []const u8, quotes: QuoteBehavior, w: *Writer) Writ |
| 10665 | 10718 | fn ensureUnusedGlobalCapacity(self: *Builder, name: StrtabString) Allocator.Error!void { |
| 10666 | 10719 | try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1); |
| 10667 | 10720 | if (name.slice(self)) |id| { |
| 10668 | | const count: usize = comptime std.fmt.count("{d}", .{std.math.maxInt(u32)}); |
| 10721 | const count: usize = comptime std.fmt.count("{d}", .{maxInt(u32)}); |
| 10669 | 10722 | try self.strtab_string_bytes.ensureUnusedCapacity(self.gpa, id.len + count); |
| 10670 | 10723 | } |
| 10671 | 10724 | try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1); |
| ... | ... | @@ -13518,7 +13571,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 13518 | 13571 | try record.ensureUnusedCapacity(self.gpa, 3); |
| 13519 | 13572 | record.appendAssumeCapacity(1); |
| 13520 | 13573 | record.appendAssumeCapacity(@intFromEnum(kind)); |
| 13521 | | record.appendAssumeCapacity(alignment.toByteUnits() orelse 0); |
| 13574 | record.appendAssumeCapacity(alignment.resolve(self).toByteUnits() orelse 0); |
| 13522 | 13575 | }, |
| 13523 | 13576 | .dereferenceable, |
| 13524 | 13577 | .dereferenceable_or_null, |