| ... | @@ -1,12 +1,16 @@ | ... | @@ -1,12 +1,16 @@ |
| 1 | gpa: Allocator, | 1 | gpa: Allocator, |
| 2 | use_lib_llvm: bool, | 2 | use_lib_llvm: bool, |
| 3 | | 3 | |
| 4 | llvm_context: *llvm.Context, | 4 | llvm: if (build_options.have_llvm) struct { |
| 5 | llvm_module: *llvm.Module, | 5 | context: *llvm.Context, |
| 6 | di_builder: ?*llvm.DIBuilder = null, | 6 | module: ?*llvm.Module = null, |
| 7 | llvm_types: std.ArrayListUnmanaged(*llvm.Type) = .{}, | 7 | target: ?*llvm.Target = null, |
| 8 | llvm_globals: std.ArrayListUnmanaged(*llvm.Value) = .{}, | 8 | di_builder: ?*llvm.DIBuilder = null, |
| 9 | llvm_constants: std.ArrayListUnmanaged(*llvm.Value) = .{}, | 9 | di_compile_unit: ?*llvm.DICompileUnit = null, |
| | 10 | types: std.ArrayListUnmanaged(*llvm.Type) = .{}, |
| | 11 | globals: std.ArrayListUnmanaged(*llvm.Value) = .{}, |
| | 12 | constants: std.ArrayListUnmanaged(*llvm.Value) = .{}, |
| | 13 | } else void, |
| 10 | | 14 | |
| 11 | source_filename: String = .none, | 15 | source_filename: String = .none, |
| 12 | data_layout: String = .none, | 16 | data_layout: String = .none, |
| ... | @@ -38,6 +42,14 @@ constant_limbs: std.ArrayListUnmanaged(std.math.big.Limb) = .{}, | ... | @@ -38,6 +42,14 @@ constant_limbs: std.ArrayListUnmanaged(std.math.big.Limb) = .{}, |
| 38 | pub const expected_fields_len = 32; | 42 | pub const expected_fields_len = 32; |
| 39 | pub const expected_gep_indices_len = 8; | 43 | pub const expected_gep_indices_len = 8; |
| 40 | | 44 | |
| | 45 | pub const Options = struct { |
| | 46 | allocator: Allocator, |
| | 47 | use_lib_llvm: bool = false, |
| | 48 | name: []const u8 = &.{}, |
| | 49 | target: std.Target = builtin.target, |
| | 50 | triple: []const u8 = &.{}, |
| | 51 | }; |
| | 52 | |
| 41 | pub const String = enum(u32) { | 53 | pub const String = enum(u32) { |
| 42 | none = std.math.maxInt(u31), | 54 | none = std.math.maxInt(u31), |
| 43 | empty, | 55 | empty, |
| ... | @@ -481,7 +493,7 @@ pub const Type = enum(u32) { | ... | @@ -481,7 +493,7 @@ pub const Type = enum(u32) { |
| 481 | | 493 | |
| 482 | pub fn toLlvm(self: Type, builder: *const Builder) *llvm.Type { | 494 | pub fn toLlvm(self: Type, builder: *const Builder) *llvm.Type { |
| 483 | assert(builder.useLibLlvm()); | 495 | assert(builder.useLibLlvm()); |
| 484 | return builder.llvm_types.items[@intFromEnum(self)]; | 496 | return builder.llvm.types.items[@intFromEnum(self)]; |
| 485 | } | 497 | } |
| 486 | }; | 498 | }; |
| 487 | | 499 | |
| ... | @@ -751,7 +763,7 @@ pub const Global = struct { | ... | @@ -751,7 +763,7 @@ pub const Global = struct { |
| 751 | | 763 | |
| 752 | pub fn toLlvm(self: Index, builder: *const Builder) *llvm.Value { | 764 | pub fn toLlvm(self: Index, builder: *const Builder) *llvm.Value { |
| 753 | assert(builder.useLibLlvm()); | 765 | assert(builder.useLibLlvm()); |
| 754 | return builder.llvm_globals.items[@intFromEnum(self)]; | 766 | return builder.llvm.globals.items[@intFromEnum(self)]; |
| 755 | } | 767 | } |
| 756 | | 768 | |
| 757 | const FormatData = struct { | 769 | const FormatData = struct { |
| ... | @@ -780,9 +792,9 @@ pub const Global = struct { | ... | @@ -780,9 +792,9 @@ pub const Global = struct { |
| 780 | pub fn renameAssumeCapacity(self: Index, builder: *Builder, name: String) void { | 792 | pub fn renameAssumeCapacity(self: Index, builder: *Builder, name: String) void { |
| 781 | const index = @intFromEnum(self); | 793 | const index = @intFromEnum(self); |
| 782 | if (builder.globals.keys()[index] == name) return; | 794 | if (builder.globals.keys()[index] == name) return; |
| 783 | if (builder.useLibLlvm()) builder.llvm_globals.appendAssumeCapacity(builder.llvm_globals.items[index]); | 795 | if (builder.useLibLlvm()) builder.llvm.globals.appendAssumeCapacity(builder.llvm.globals.items[index]); |
| 784 | _ = builder.addGlobalAssumeCapacity(name, builder.globals.values()[index]); | 796 | _ = builder.addGlobalAssumeCapacity(name, builder.globals.values()[index]); |
| 785 | if (builder.useLibLlvm()) _ = builder.llvm_globals.pop(); | 797 | if (builder.useLibLlvm()) _ = builder.llvm.globals.pop(); |
| 786 | builder.globals.swapRemoveAt(index); | 798 | builder.globals.swapRemoveAt(index); |
| 787 | self.updateName(builder); | 799 | self.updateName(builder); |
| 788 | } | 800 | } |
| ... | @@ -802,7 +814,7 @@ pub const Global = struct { | ... | @@ -802,7 +814,7 @@ pub const Global = struct { |
| 802 | if (!builder.useLibLlvm()) return; | 814 | if (!builder.useLibLlvm()) return; |
| 803 | const index = @intFromEnum(self); | 815 | const index = @intFromEnum(self); |
| 804 | const slice = builder.globals.keys()[index].toSlice(builder) orelse ""; | 816 | const slice = builder.globals.keys()[index].toSlice(builder) orelse ""; |
| 805 | builder.llvm_globals.items[index].setValueName2(slice.ptr, slice.len); | 817 | builder.llvm.globals.items[index].setValueName2(slice.ptr, slice.len); |
| 806 | } | 818 | } |
| 807 | }; | 819 | }; |
| 808 | | 820 | |
| ... | @@ -1414,7 +1426,7 @@ pub const Constant = enum(u32) { | ... | @@ -1414,7 +1426,7 @@ pub const Constant = enum(u32) { |
| 1414 | pub fn toLlvm(self: Constant, builder: *const Builder) *llvm.Value { | 1426 | pub fn toLlvm(self: Constant, builder: *const Builder) *llvm.Value { |
| 1415 | assert(builder.useLibLlvm()); | 1427 | assert(builder.useLibLlvm()); |
| 1416 | return switch (self.unwrap()) { | 1428 | return switch (self.unwrap()) { |
| 1417 | .constant => |constant| builder.llvm_constants.items[constant], | 1429 | .constant => |constant| builder.llvm.constants.items[constant], |
| 1418 | .global => |global| global.toLlvm(builder), | 1430 | .global => |global| global.toLlvm(builder), |
| 1419 | }; | 1431 | }; |
| 1420 | } | 1432 | } |
| ... | @@ -1436,26 +1448,70 @@ pub const Value = enum(u32) { | ... | @@ -1436,26 +1448,70 @@ pub const Value = enum(u32) { |
| 1436 | } | 1448 | } |
| 1437 | }; | 1449 | }; |
| 1438 | | 1450 | |
| 1439 | pub fn init(self: *Builder) Allocator.Error!void { | 1451 | pub const InitError = error{ |
| | 1452 | InvalidLlvmTriple, |
| | 1453 | } || Allocator.Error; |
| | 1454 | |
| | 1455 | pub fn init(options: Options) InitError!Builder { |
| | 1456 | var self = Builder{ |
| | 1457 | .gpa = options.allocator, |
| | 1458 | .use_lib_llvm = options.use_lib_llvm, |
| | 1459 | .llvm = undefined, |
| | 1460 | }; |
| | 1461 | if (self.useLibLlvm()) self.llvm = .{ .context = llvm.Context.create() }; |
| | 1462 | errdefer self.deinit(); |
| | 1463 | |
| 1440 | try self.string_indices.append(self.gpa, 0); | 1464 | try self.string_indices.append(self.gpa, 0); |
| 1441 | assert(try self.string("") == .empty); | 1465 | assert(try self.string("") == .empty); |
| 1442 | | 1466 | |
| | 1467 | if (options.name.len > 0) self.source_filename = try self.string(options.name); |
| | 1468 | self.initializeLLVMTarget(options.target.cpu.arch); |
| | 1469 | if (self.useLibLlvm()) self.llvm.module = llvm.Module.createWithName( |
| | 1470 | (self.source_filename.toSlice(&self) orelse "").ptr, |
| | 1471 | self.llvm.context, |
| | 1472 | ); |
| | 1473 | |
| | 1474 | if (options.triple.len > 0) { |
| | 1475 | self.target_triple = try self.string(options.triple); |
| | 1476 | |
| | 1477 | if (self.useLibLlvm()) { |
| | 1478 | var error_message: [*:0]const u8 = undefined; |
| | 1479 | var target: *llvm.Target = undefined; |
| | 1480 | if (llvm.Target.getFromTriple( |
| | 1481 | self.target_triple.toSlice(&self).?.ptr, |
| | 1482 | &target, |
| | 1483 | &error_message, |
| | 1484 | ).toBool()) { |
| | 1485 | defer llvm.disposeMessage(error_message); |
| | 1486 | |
| | 1487 | log.err("LLVM failed to parse '{s}': {s}", .{ |
| | 1488 | self.target_triple.toSlice(&self).?, |
| | 1489 | error_message, |
| | 1490 | }); |
| | 1491 | return InitError.InvalidLlvmTriple; |
| | 1492 | } |
| | 1493 | self.llvm.target = target; |
| | 1494 | self.llvm.module.?.setTarget(self.target_triple.toSlice(&self).?.ptr); |
| | 1495 | } |
| | 1496 | } |
| | 1497 | |
| 1443 | { | 1498 | { |
| 1444 | const static_len = @typeInfo(Type).Enum.fields.len - 1; | 1499 | const static_len = @typeInfo(Type).Enum.fields.len - 1; |
| 1445 | try self.type_map.ensureTotalCapacity(self.gpa, static_len); | 1500 | try self.type_map.ensureTotalCapacity(self.gpa, static_len); |
| 1446 | try self.type_items.ensureTotalCapacity(self.gpa, static_len); | 1501 | try self.type_items.ensureTotalCapacity(self.gpa, static_len); |
| 1447 | if (self.useLibLlvm()) try self.llvm_types.ensureTotalCapacity(self.gpa, static_len); | 1502 | if (self.useLibLlvm()) try self.llvm.types.ensureTotalCapacity(self.gpa, static_len); |
| 1448 | inline for (@typeInfo(Type.Simple).Enum.fields) |simple_field| { | 1503 | inline for (@typeInfo(Type.Simple).Enum.fields) |simple_field| { |
| 1449 | const result = self.getOrPutTypeNoExtraAssumeCapacity( | 1504 | const result = self.getOrPutTypeNoExtraAssumeCapacity( |
| 1450 | .{ .tag = .simple, .data = simple_field.value }, | 1505 | .{ .tag = .simple, .data = simple_field.value }, |
| 1451 | ); | 1506 | ); |
| 1452 | assert(result.new and result.type == @field(Type, simple_field.name)); | 1507 | assert(result.new and result.type == @field(Type, simple_field.name)); |
| 1453 | if (self.useLibLlvm()) self.llvm_types.appendAssumeCapacity( | 1508 | if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity( |
| 1454 | @field(llvm.Context, simple_field.name ++ "Type")(self.llvm_context), | 1509 | @field(llvm.Context, simple_field.name ++ "Type")(self.llvm.context), |
| 1455 | ); | 1510 | ); |
| 1456 | } | 1511 | } |
| 1457 | inline for (.{ 1, 8, 16, 29, 32, 64, 80, 128 }) |bits| assert(self.intTypeAssumeCapacity(bits) == | 1512 | inline for (.{ 1, 8, 16, 29, 32, 64, 80, 128 }) |bits| |
| 1458 | @field(Type, std.fmt.comptimePrint("i{d}", .{bits}))); | 1513 | assert(self.intTypeAssumeCapacity(bits) == |
| | 1514 | @field(Type, std.fmt.comptimePrint("i{d}", .{bits}))); |
| 1459 | inline for (.{0}) |addr_space| | 1515 | inline for (.{0}) |addr_space| |
| 1460 | assert(self.ptrTypeAssumeCapacity(@enumFromInt(addr_space)) == .ptr); | 1516 | assert(self.ptrTypeAssumeCapacity(@enumFromInt(addr_space)) == .ptr); |
| 1461 | } | 1517 | } |
| ... | @@ -1463,13 +1519,11 @@ pub fn init(self: *Builder) Allocator.Error!void { | ... | @@ -1463,13 +1519,11 @@ pub fn init(self: *Builder) Allocator.Error!void { |
| 1463 | assert(try self.intConst(.i1, 0) == .false); | 1519 | assert(try self.intConst(.i1, 0) == .false); |
| 1464 | assert(try self.intConst(.i1, 1) == .true); | 1520 | assert(try self.intConst(.i1, 1) == .true); |
| 1465 | assert(try self.noneConst(.token) == .none); | 1521 | assert(try self.noneConst(.token) == .none); |
| | 1522 | |
| | 1523 | return self; |
| 1466 | } | 1524 | } |
| 1467 | | 1525 | |
| 1468 | pub fn deinit(self: *Builder) void { | 1526 | pub fn deinit(self: *Builder) void { |
| 1469 | self.llvm_types.deinit(self.gpa); | | |
| 1470 | self.llvm_globals.deinit(self.gpa); | | |
| 1471 | self.llvm_constants.deinit(self.gpa); | | |
| 1472 | | | |
| 1473 | self.string_map.deinit(self.gpa); | 1527 | self.string_map.deinit(self.gpa); |
| 1474 | self.string_bytes.deinit(self.gpa); | 1528 | self.string_bytes.deinit(self.gpa); |
| 1475 | self.string_indices.deinit(self.gpa); | 1529 | self.string_indices.deinit(self.gpa); |
| ... | @@ -1492,6 +1546,14 @@ pub fn deinit(self: *Builder) void { | ... | @@ -1492,6 +1546,14 @@ pub fn deinit(self: *Builder) void { |
| 1492 | self.constant_extra.deinit(self.gpa); | 1546 | self.constant_extra.deinit(self.gpa); |
| 1493 | self.constant_limbs.deinit(self.gpa); | 1547 | self.constant_limbs.deinit(self.gpa); |
| 1494 | | 1548 | |
| | 1549 | if (self.useLibLlvm()) { |
| | 1550 | self.llvm.constants.deinit(self.gpa); |
| | 1551 | self.llvm.globals.deinit(self.gpa); |
| | 1552 | self.llvm.types.deinit(self.gpa); |
| | 1553 | if (self.llvm.di_builder) |di_builder| di_builder.dispose(); |
| | 1554 | if (self.llvm.module) |module| module.dispose(); |
| | 1555 | self.llvm.context.dispose(); |
| | 1556 | } |
| 1495 | self.* = undefined; | 1557 | self.* = undefined; |
| 1496 | } | 1558 | } |
| 1497 | | 1559 | |
| ... | @@ -1807,7 +1869,7 @@ pub fn namedTypeSetBody( | ... | @@ -1807,7 +1869,7 @@ pub fn namedTypeSetBody( |
| 1807 | const llvm_fields = try self.gpa.alloc(*llvm.Type, body_fields.len); | 1869 | const llvm_fields = try self.gpa.alloc(*llvm.Type, body_fields.len); |
| 1808 | defer self.gpa.free(llvm_fields); | 1870 | defer self.gpa.free(llvm_fields); |
| 1809 | for (llvm_fields, body_fields) |*llvm_field, body_field| llvm_field.* = body_field.toLlvm(self); | 1871 | for (llvm_fields, body_fields) |*llvm_field, body_field| llvm_field.* = body_field.toLlvm(self); |
| 1810 | self.llvm_types.items[@intFromEnum(named_type)].structSetBody( | 1872 | self.llvm.types.items[@intFromEnum(named_type)].structSetBody( |
| 1811 | llvm_fields.ptr, | 1873 | llvm_fields.ptr, |
| 1812 | @intCast(llvm_fields.len), | 1874 | @intCast(llvm_fields.len), |
| 1813 | switch (body_item.tag) { | 1875 | switch (body_item.tag) { |
| ... | @@ -1869,7 +1931,7 @@ pub fn bigIntConst(self: *Builder, ty: Type, value: std.math.big.int.Const) Allo | ... | @@ -1869,7 +1931,7 @@ pub fn bigIntConst(self: *Builder, ty: Type, value: std.math.big.int.Const) Allo |
| 1869 | try self.constant_map.ensureUnusedCapacity(self.gpa, 1); | 1931 | try self.constant_map.ensureUnusedCapacity(self.gpa, 1); |
| 1870 | try self.constant_items.ensureUnusedCapacity(self.gpa, 1); | 1932 | try self.constant_items.ensureUnusedCapacity(self.gpa, 1); |
| 1871 | try self.constant_limbs.ensureUnusedCapacity(self.gpa, Constant.Integer.limbs + value.limbs.len); | 1933 | try self.constant_limbs.ensureUnusedCapacity(self.gpa, Constant.Integer.limbs + value.limbs.len); |
| 1872 | if (self.useLibLlvm()) try self.llvm_constants.ensureUnusedCapacity(self.gpa, 1); | 1934 | if (self.useLibLlvm()) try self.llvm.constants.ensureUnusedCapacity(self.gpa, 1); |
| 1873 | return self.bigIntConstAssumeCapacity(ty, value); | 1935 | return self.bigIntConstAssumeCapacity(ty, value); |
| 1874 | } | 1936 | } |
| 1875 | | 1937 | |
| ... | @@ -2166,7 +2228,7 @@ fn isValidIdentifier(id: []const u8) bool { | ... | @@ -2166,7 +2228,7 @@ fn isValidIdentifier(id: []const u8) bool { |
| 2166 | } | 2228 | } |
| 2167 | | 2229 | |
| 2168 | fn ensureUnusedCapacityGlobal(self: *Builder, name: String) Allocator.Error!void { | 2230 | fn ensureUnusedCapacityGlobal(self: *Builder, name: String) Allocator.Error!void { |
| 2169 | if (self.useLibLlvm()) try self.llvm_globals.ensureUnusedCapacity(self.gpa, 1); | 2231 | if (self.useLibLlvm()) try self.llvm.globals.ensureUnusedCapacity(self.gpa, 1); |
| 2170 | try self.string_map.ensureUnusedCapacity(self.gpa, 1); | 2232 | try self.string_map.ensureUnusedCapacity(self.gpa, 1); |
| 2171 | if (name.toSlice(self)) |id| try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + | 2233 | if (name.toSlice(self)) |id| try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + |
| 2172 | comptime std.fmt.count("{d}" ++ .{0}, .{std.math.maxInt(u32)})); | 2234 | comptime std.fmt.count("{d}" ++ .{0}, .{std.math.maxInt(u32)})); |
| ... | @@ -2222,7 +2284,7 @@ fn fnTypeAssumeCapacity( | ... | @@ -2222,7 +2284,7 @@ fn fnTypeAssumeCapacity( |
| 2222 | const llvm_params = try self.gpa.alloc(*llvm.Type, params.len); | 2284 | const llvm_params = try self.gpa.alloc(*llvm.Type, params.len); |
| 2223 | defer self.gpa.free(llvm_params); | 2285 | defer self.gpa.free(llvm_params); |
| 2224 | for (llvm_params, params) |*llvm_param, param| llvm_param.* = param.toLlvm(self); | 2286 | for (llvm_params, params) |*llvm_param, param| llvm_param.* = param.toLlvm(self); |
| 2225 | self.llvm_types.appendAssumeCapacity(llvm.functionType( | 2287 | self.llvm.types.appendAssumeCapacity(llvm.functionType( |
| 2226 | ret.toLlvm(self), | 2288 | ret.toLlvm(self), |
| 2227 | llvm_params.ptr, | 2289 | llvm_params.ptr, |
| 2228 | @intCast(llvm_params.len), | 2290 | @intCast(llvm_params.len), |
| ... | @@ -2240,7 +2302,7 @@ fn intTypeAssumeCapacity(self: *Builder, bits: u24) Type { | ... | @@ -2240,7 +2302,7 @@ fn intTypeAssumeCapacity(self: *Builder, bits: u24) Type { |
| 2240 | assert(bits > 0); | 2302 | assert(bits > 0); |
| 2241 | const result = self.getOrPutTypeNoExtraAssumeCapacity(.{ .tag = .integer, .data = bits }); | 2303 | const result = self.getOrPutTypeNoExtraAssumeCapacity(.{ .tag = .integer, .data = bits }); |
| 2242 | if (self.useLibLlvm() and result.new) | 2304 | if (self.useLibLlvm() and result.new) |
| 2243 | self.llvm_types.appendAssumeCapacity(self.llvm_context.intType(bits)); | 2305 | self.llvm.types.appendAssumeCapacity(self.llvm.context.intType(bits)); |
| 2244 | return result.type; | 2306 | return result.type; |
| 2245 | } | 2307 | } |
| 2246 | | 2308 | |
| ... | @@ -2249,7 +2311,7 @@ fn ptrTypeAssumeCapacity(self: *Builder, addr_space: AddrSpace) Type { | ... | @@ -2249,7 +2311,7 @@ fn ptrTypeAssumeCapacity(self: *Builder, addr_space: AddrSpace) Type { |
| 2249 | .{ .tag = .pointer, .data = @intFromEnum(addr_space) }, | 2311 | .{ .tag = .pointer, .data = @intFromEnum(addr_space) }, |
| 2250 | ); | 2312 | ); |
| 2251 | if (self.useLibLlvm() and result.new) | 2313 | if (self.useLibLlvm() and result.new) |
| 2252 | self.llvm_types.appendAssumeCapacity(self.llvm_context.pointerType(@intFromEnum(addr_space))); | 2314 | self.llvm.types.appendAssumeCapacity(self.llvm.context.pointerType(@intFromEnum(addr_space))); |
| 2253 | return result.type; | 2315 | return result.type; |
| 2254 | } | 2316 | } |
| 2255 | | 2317 | |
| ... | @@ -2286,7 +2348,7 @@ fn vectorTypeAssumeCapacity( | ... | @@ -2286,7 +2348,7 @@ fn vectorTypeAssumeCapacity( |
| 2286 | .tag = tag, | 2348 | .tag = tag, |
| 2287 | .data = self.addTypeExtraAssumeCapacity(data), | 2349 | .data = self.addTypeExtraAssumeCapacity(data), |
| 2288 | }); | 2350 | }); |
| 2289 | if (self.useLibLlvm()) self.llvm_types.appendAssumeCapacity(switch (kind) { | 2351 | if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(switch (kind) { |
| 2290 | .normal => &llvm.Type.vectorType, | 2352 | .normal => &llvm.Type.vectorType, |
| 2291 | .scalable => &llvm.Type.scalableVectorType, | 2353 | .scalable => &llvm.Type.scalableVectorType, |
| 2292 | }(child.toLlvm(self), @intCast(len))); | 2354 | }(child.toLlvm(self), @intCast(len))); |
| ... | @@ -2319,7 +2381,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type { | ... | @@ -2319,7 +2381,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type { |
| 2319 | .tag = .small_array, | 2381 | .tag = .small_array, |
| 2320 | .data = self.addTypeExtraAssumeCapacity(data), | 2382 | .data = self.addTypeExtraAssumeCapacity(data), |
| 2321 | }); | 2383 | }); |
| 2322 | if (self.useLibLlvm()) self.llvm_types.appendAssumeCapacity( | 2384 | if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity( |
| 2323 | child.toLlvm(self).arrayType(@intCast(len)), | 2385 | child.toLlvm(self).arrayType(@intCast(len)), |
| 2324 | ); | 2386 | ); |
| 2325 | } | 2387 | } |
| ... | @@ -2352,7 +2414,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type { | ... | @@ -2352,7 +2414,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type { |
| 2352 | .tag = .array, | 2414 | .tag = .array, |
| 2353 | .data = self.addTypeExtraAssumeCapacity(data), | 2415 | .data = self.addTypeExtraAssumeCapacity(data), |
| 2354 | }); | 2416 | }); |
| 2355 | if (self.useLibLlvm()) self.llvm_types.appendAssumeCapacity( | 2417 | if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity( |
| 2356 | child.toLlvm(self).arrayType(@intCast(len)), | 2418 | child.toLlvm(self).arrayType(@intCast(len)), |
| 2357 | ); | 2419 | ); |
| 2358 | } | 2420 | } |
| ... | @@ -2406,7 +2468,7 @@ fn structTypeAssumeCapacity( | ... | @@ -2406,7 +2468,7 @@ fn structTypeAssumeCapacity( |
| 2406 | defer allocator.free(llvm_fields); | 2468 | defer allocator.free(llvm_fields); |
| 2407 | for (llvm_fields, fields) |*llvm_field, field| llvm_field.* = field.toLlvm(self); | 2469 | for (llvm_fields, fields) |*llvm_field, field| llvm_field.* = field.toLlvm(self); |
| 2408 | | 2470 | |
| 2409 | self.llvm_types.appendAssumeCapacity(self.llvm_context.structType( | 2471 | self.llvm.types.appendAssumeCapacity(self.llvm.context.structType( |
| 2410 | llvm_fields.ptr, | 2472 | llvm_fields.ptr, |
| 2411 | @intCast(llvm_fields.len), | 2473 | @intCast(llvm_fields.len), |
| 2412 | switch (kind) { | 2474 | switch (kind) { |
| ... | @@ -2456,8 +2518,8 @@ fn opaqueTypeAssumeCapacity(self: *Builder, name: String) Type { | ... | @@ -2456,8 +2518,8 @@ fn opaqueTypeAssumeCapacity(self: *Builder, name: String) Type { |
| 2456 | }); | 2518 | }); |
| 2457 | const result: Type = @enumFromInt(gop.index); | 2519 | const result: Type = @enumFromInt(gop.index); |
| 2458 | type_gop.value_ptr.* = result; | 2520 | type_gop.value_ptr.* = result; |
| 2459 | if (self.useLibLlvm()) self.llvm_types.appendAssumeCapacity( | 2521 | if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity( |
| 2460 | self.llvm_context.structCreateNamed(id.toSlice(self) orelse ""), | 2522 | self.llvm.context.structCreateNamed(id.toSlice(self) orelse ""), |
| 2461 | ); | 2523 | ); |
| 2462 | return result; | 2524 | return result; |
| 2463 | } | 2525 | } |
| ... | @@ -2481,7 +2543,7 @@ fn ensureUnusedTypeCapacity( | ... | @@ -2481,7 +2543,7 @@ fn ensureUnusedTypeCapacity( |
| 2481 | self.gpa, | 2543 | self.gpa, |
| 2482 | count * (@typeInfo(E).Struct.fields.len + trail_len), | 2544 | count * (@typeInfo(E).Struct.fields.len + trail_len), |
| 2483 | ) else assert(trail_len == 0); | 2545 | ) else assert(trail_len == 0); |
| 2484 | if (self.useLibLlvm()) try self.llvm_types.ensureUnusedCapacity(self.gpa, count); | 2546 | if (self.useLibLlvm()) try self.llvm.types.ensureUnusedCapacity(self.gpa, count); |
| 2485 | } | 2547 | } |
| 2486 | | 2548 | |
| 2487 | fn getOrPutTypeNoExtraAssumeCapacity(self: *Builder, item: Type.Item) struct { new: bool, type: Type } { | 2549 | fn getOrPutTypeNoExtraAssumeCapacity(self: *Builder, item: Type.Item) struct { new: bool, type: Type } { |
| ... | @@ -2613,9 +2675,9 @@ fn bigIntConstAssumeCapacity( | ... | @@ -2613,9 +2675,9 @@ fn bigIntConstAssumeCapacity( |
| 2613 | if (self.useLibLlvm()) { | 2675 | if (self.useLibLlvm()) { |
| 2614 | const llvm_type = ty.toLlvm(self); | 2676 | const llvm_type = ty.toLlvm(self); |
| 2615 | if (canonical_value.to(c_longlong)) |small| { | 2677 | if (canonical_value.to(c_longlong)) |small| { |
| 2616 | self.llvm_constants.appendAssumeCapacity(llvm_type.constInt(@bitCast(small), .True)); | 2678 | self.llvm.constants.appendAssumeCapacity(llvm_type.constInt(@bitCast(small), .True)); |
| 2617 | } else |_| if (canonical_value.to(c_ulonglong)) |small| { | 2679 | } else |_| if (canonical_value.to(c_ulonglong)) |small| { |
| 2618 | self.llvm_constants.appendAssumeCapacity(llvm_type.constInt(small, .False)); | 2680 | self.llvm.constants.appendAssumeCapacity(llvm_type.constInt(small, .False)); |
| 2619 | } else |_| { | 2681 | } else |_| { |
| 2620 | const llvm_limbs = try allocator.alloc(u64, std.math.divCeil( | 2682 | const llvm_limbs = try allocator.alloc(u64, std.math.divCeil( |
| 2621 | usize, | 2683 | usize, |
| ... | @@ -2643,7 +2705,7 @@ fn bigIntConstAssumeCapacity( | ... | @@ -2643,7 +2705,7 @@ fn bigIntConstAssumeCapacity( |
| 2643 | } | 2705 | } |
| 2644 | result_limb.* = llvm_limb; | 2706 | result_limb.* = llvm_limb; |
| 2645 | } | 2707 | } |
| 2646 | self.llvm_constants.appendAssumeCapacity( | 2708 | self.llvm.constants.appendAssumeCapacity( |
| 2647 | llvm_type.constIntOfArbitraryPrecision(@intCast(llvm_limbs.len), llvm_limbs.ptr), | 2709 | llvm_type.constIntOfArbitraryPrecision(@intCast(llvm_limbs.len), llvm_limbs.ptr), |
| 2648 | ); | 2710 | ); |
| 2649 | } | 2711 | } |
| ... | @@ -2656,7 +2718,7 @@ fn halfConstAssumeCapacity(self: *Builder, val: f16) Constant { | ... | @@ -2656,7 +2718,7 @@ fn halfConstAssumeCapacity(self: *Builder, val: f16) Constant { |
| 2656 | const result = self.getOrPutConstantNoExtraAssumeCapacity( | 2718 | const result = self.getOrPutConstantNoExtraAssumeCapacity( |
| 2657 | .{ .tag = .half, .data = @as(u16, @bitCast(val)) }, | 2719 | .{ .tag = .half, .data = @as(u16, @bitCast(val)) }, |
| 2658 | ); | 2720 | ); |
| 2659 | if (self.useLibLlvm() and result.new) self.llvm_constants.appendAssumeCapacity( | 2721 | if (self.useLibLlvm() and result.new) self.llvm.constants.appendAssumeCapacity( |
| 2660 | if (std.math.isSignalNan(val)) | 2722 | if (std.math.isSignalNan(val)) |
| 2661 | Type.i16.toLlvm(self).constInt(@as(u16, @bitCast(val)), .False) | 2723 | Type.i16.toLlvm(self).constInt(@as(u16, @bitCast(val)), .False) |
| 2662 | .constBitCast(Type.half.toLlvm(self)) | 2724 | .constBitCast(Type.half.toLlvm(self)) |
| ... | @@ -2671,7 +2733,7 @@ fn bfloatConstAssumeCapacity(self: *Builder, val: f32) Constant { | ... | @@ -2671,7 +2733,7 @@ fn bfloatConstAssumeCapacity(self: *Builder, val: f32) Constant { |
| 2671 | const result = self.getOrPutConstantNoExtraAssumeCapacity( | 2733 | const result = self.getOrPutConstantNoExtraAssumeCapacity( |
| 2672 | .{ .tag = .bfloat, .data = @bitCast(val) }, | 2734 | .{ .tag = .bfloat, .data = @bitCast(val) }, |
| 2673 | ); | 2735 | ); |
| 2674 | if (self.useLibLlvm() and result.new) self.llvm_constants.appendAssumeCapacity( | 2736 | if (self.useLibLlvm() and result.new) self.llvm.constants.appendAssumeCapacity( |
| 2675 | if (std.math.isSignalNan(val)) | 2737 | if (std.math.isSignalNan(val)) |
| 2676 | Type.i16.toLlvm(self).constInt(@as(u32, @bitCast(val)) >> 16, .False) | 2738 | Type.i16.toLlvm(self).constInt(@as(u32, @bitCast(val)) >> 16, .False) |
| 2677 | .constBitCast(Type.bfloat.toLlvm(self)) | 2739 | .constBitCast(Type.bfloat.toLlvm(self)) |
| ... | @@ -2680,7 +2742,7 @@ fn bfloatConstAssumeCapacity(self: *Builder, val: f32) Constant { | ... | @@ -2680,7 +2742,7 @@ fn bfloatConstAssumeCapacity(self: *Builder, val: f32) Constant { |
| 2680 | ); | 2742 | ); |
| 2681 | | 2743 | |
| 2682 | if (self.useLibLlvm() and result.new) | 2744 | if (self.useLibLlvm() and result.new) |
| 2683 | self.llvm_constants.appendAssumeCapacity(Type.bfloat.toLlvm(self).constReal(val)); | 2745 | self.llvm.constants.appendAssumeCapacity(Type.bfloat.toLlvm(self).constReal(val)); |
| 2684 | return result.constant; | 2746 | return result.constant; |
| 2685 | } | 2747 | } |
| 2686 | | 2748 | |
| ... | @@ -2688,7 +2750,7 @@ fn floatConstAssumeCapacity(self: *Builder, val: f32) Constant { | ... | @@ -2688,7 +2750,7 @@ fn floatConstAssumeCapacity(self: *Builder, val: f32) Constant { |
| 2688 | const result = self.getOrPutConstantNoExtraAssumeCapacity( | 2750 | const result = self.getOrPutConstantNoExtraAssumeCapacity( |
| 2689 | .{ .tag = .float, .data = @bitCast(val) }, | 2751 | .{ .tag = .float, .data = @bitCast(val) }, |
| 2690 | ); | 2752 | ); |
| 2691 | if (self.useLibLlvm() and result.new) self.llvm_constants.appendAssumeCapacity( | 2753 | if (self.useLibLlvm() and result.new) self.llvm.constants.appendAssumeCapacity( |
| 2692 | if (std.math.isSignalNan(val)) | 2754 | if (std.math.isSignalNan(val)) |
| 2693 | Type.i32.toLlvm(self).constInt(@as(u32, @bitCast(val)), .False) | 2755 | Type.i32.toLlvm(self).constInt(@as(u32, @bitCast(val)), .False) |
| 2694 | .constBitCast(Type.float.toLlvm(self)) | 2756 | .constBitCast(Type.float.toLlvm(self)) |
| ... | @@ -2725,7 +2787,7 @@ fn doubleConstAssumeCapacity(self: *Builder, val: f64) Constant { | ... | @@ -2725,7 +2787,7 @@ fn doubleConstAssumeCapacity(self: *Builder, val: f64) Constant { |
| 2725 | .hi = @truncate(@as(u64, @bitCast(val))), | 2787 | .hi = @truncate(@as(u64, @bitCast(val))), |
| 2726 | }), | 2788 | }), |
| 2727 | }); | 2789 | }); |
| 2728 | if (self.useLibLlvm()) self.llvm_constants.appendAssumeCapacity( | 2790 | if (self.useLibLlvm()) self.llvm.constants.appendAssumeCapacity( |
| 2729 | if (std.math.isSignalNan(val)) | 2791 | if (std.math.isSignalNan(val)) |
| 2730 | Type.i64.toLlvm(self).constInt(@as(u64, @bitCast(val)), .False) | 2792 | Type.i64.toLlvm(self).constInt(@as(u64, @bitCast(val)), .False) |
| 2731 | .constBitCast(Type.double.toLlvm(self)) | 2793 | .constBitCast(Type.double.toLlvm(self)) |
| ... | @@ -2771,7 +2833,7 @@ fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant { | ... | @@ -2771,7 +2833,7 @@ fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant { |
| 2771 | @truncate(@as(u128, @bitCast(val))), | 2833 | @truncate(@as(u128, @bitCast(val))), |
| 2772 | @intCast(@as(u128, @bitCast(val)) >> 64), | 2834 | @intCast(@as(u128, @bitCast(val)) >> 64), |
| 2773 | }; | 2835 | }; |
| 2774 | self.llvm_constants.appendAssumeCapacity( | 2836 | self.llvm.constants.appendAssumeCapacity( |
| 2775 | Type.i128.toLlvm(self) | 2837 | Type.i128.toLlvm(self) |
| 2776 | .constIntOfArbitraryPrecision(@intCast(llvm_limbs.len), &llvm_limbs) | 2838 | .constIntOfArbitraryPrecision(@intCast(llvm_limbs.len), &llvm_limbs) |
| 2777 | .constBitCast(Type.fp128.toLlvm(self)), | 2839 | .constBitCast(Type.fp128.toLlvm(self)), |
| ... | @@ -2815,7 +2877,7 @@ fn x86_fp80ConstAssumeCapacity(self: *Builder, val: f80) Constant { | ... | @@ -2815,7 +2877,7 @@ fn x86_fp80ConstAssumeCapacity(self: *Builder, val: f80) Constant { |
| 2815 | @truncate(@as(u80, @bitCast(val))), | 2877 | @truncate(@as(u80, @bitCast(val))), |
| 2816 | @intCast(@as(u80, @bitCast(val)) >> 64), | 2878 | @intCast(@as(u80, @bitCast(val)) >> 64), |
| 2817 | }; | 2879 | }; |
| 2818 | self.llvm_constants.appendAssumeCapacity( | 2880 | self.llvm.constants.appendAssumeCapacity( |
| 2819 | Type.i80.toLlvm(self) | 2881 | Type.i80.toLlvm(self) |
| 2820 | .constIntOfArbitraryPrecision(@intCast(llvm_limbs.len), &llvm_limbs) | 2882 | .constIntOfArbitraryPrecision(@intCast(llvm_limbs.len), &llvm_limbs) |
| 2821 | .constBitCast(Type.x86_fp80.toLlvm(self)), | 2883 | .constBitCast(Type.x86_fp80.toLlvm(self)), |
| ... | @@ -2857,7 +2919,7 @@ fn ppc_fp128ConstAssumeCapacity(self: *Builder, val: [2]f64) Constant { | ... | @@ -2857,7 +2919,7 @@ fn ppc_fp128ConstAssumeCapacity(self: *Builder, val: [2]f64) Constant { |
| 2857 | }); | 2919 | }); |
| 2858 | if (self.useLibLlvm()) { | 2920 | if (self.useLibLlvm()) { |
| 2859 | const llvm_limbs: *const [2]u64 = @ptrCast(&val); | 2921 | const llvm_limbs: *const [2]u64 = @ptrCast(&val); |
| 2860 | self.llvm_constants.appendAssumeCapacity( | 2922 | self.llvm.constants.appendAssumeCapacity( |
| 2861 | Type.i128.toLlvm(self) | 2923 | Type.i128.toLlvm(self) |
| 2862 | .constIntOfArbitraryPrecision(@intCast(llvm_limbs.len), llvm_limbs) | 2924 | .constIntOfArbitraryPrecision(@intCast(llvm_limbs.len), llvm_limbs) |
| 2863 | .constBitCast(Type.ppc_fp128.toLlvm(self)), | 2925 | .constBitCast(Type.ppc_fp128.toLlvm(self)), |
| ... | @@ -2873,7 +2935,7 @@ fn nullConstAssumeCapacity(self: *Builder, ty: Type) Constant { | ... | @@ -2873,7 +2935,7 @@ fn nullConstAssumeCapacity(self: *Builder, ty: Type) Constant { |
| 2873 | .{ .tag = .null, .data = @intFromEnum(ty) }, | 2935 | .{ .tag = .null, .data = @intFromEnum(ty) }, |
| 2874 | ); | 2936 | ); |
| 2875 | if (self.useLibLlvm() and result.new) | 2937 | if (self.useLibLlvm() and result.new) |
| 2876 | self.llvm_constants.appendAssumeCapacity(ty.toLlvm(self).constNull()); | 2938 | self.llvm.constants.appendAssumeCapacity(ty.toLlvm(self).constNull()); |
| 2877 | return result.constant; | 2939 | return result.constant; |
| 2878 | } | 2940 | } |
| 2879 | | 2941 | |
| ... | @@ -2883,7 +2945,7 @@ fn noneConstAssumeCapacity(self: *Builder, ty: Type) Constant { | ... | @@ -2883,7 +2945,7 @@ fn noneConstAssumeCapacity(self: *Builder, ty: Type) Constant { |
| 2883 | .{ .tag = .none, .data = @intFromEnum(ty) }, | 2945 | .{ .tag = .none, .data = @intFromEnum(ty) }, |
| 2884 | ); | 2946 | ); |
| 2885 | if (self.useLibLlvm() and result.new) | 2947 | if (self.useLibLlvm() and result.new) |
| 2886 | self.llvm_constants.appendAssumeCapacity(ty.toLlvm(self).constNull()); | 2948 | self.llvm.constants.appendAssumeCapacity(ty.toLlvm(self).constNull()); |
| 2887 | return result.constant; | 2949 | return result.constant; |
| 2888 | } | 2950 | } |
| 2889 | | 2951 | |
| ... | @@ -2929,7 +2991,7 @@ fn structConstAssumeCapacity( | ... | @@ -2929,7 +2991,7 @@ fn structConstAssumeCapacity( |
| 2929 | defer allocator.free(llvm_vals); | 2991 | defer allocator.free(llvm_vals); |
| 2930 | for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self); | 2992 | for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self); |
| 2931 | | 2993 | |
| 2932 | self.llvm_constants.appendAssumeCapacity( | 2994 | self.llvm.constants.appendAssumeCapacity( |
| 2933 | ty.toLlvm(self).constNamedStruct(llvm_vals.ptr, @intCast(llvm_vals.len)), | 2995 | ty.toLlvm(self).constNamedStruct(llvm_vals.ptr, @intCast(llvm_vals.len)), |
| 2934 | ); | 2996 | ); |
| 2935 | } | 2997 | } |
| ... | @@ -2971,7 +3033,7 @@ fn arrayConstAssumeCapacity( | ... | @@ -2971,7 +3033,7 @@ fn arrayConstAssumeCapacity( |
| 2971 | defer allocator.free(llvm_vals); | 3033 | defer allocator.free(llvm_vals); |
| 2972 | for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self); | 3034 | for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self); |
| 2973 | | 3035 | |
| 2974 | self.llvm_constants.appendAssumeCapacity( | 3036 | self.llvm.constants.appendAssumeCapacity( |
| 2975 | type_extra.child.toLlvm(self).constArray(llvm_vals.ptr, @intCast(llvm_vals.len)), | 3037 | type_extra.child.toLlvm(self).constArray(llvm_vals.ptr, @intCast(llvm_vals.len)), |
| 2976 | ); | 3038 | ); |
| 2977 | } | 3039 | } |
| ... | @@ -2985,8 +3047,8 @@ fn stringConstAssumeCapacity(self: *Builder, val: String) Constant { | ... | @@ -2985,8 +3047,8 @@ fn stringConstAssumeCapacity(self: *Builder, val: String) Constant { |
| 2985 | const result = self.getOrPutConstantNoExtraAssumeCapacity( | 3047 | const result = self.getOrPutConstantNoExtraAssumeCapacity( |
| 2986 | .{ .tag = .string, .data = @intFromEnum(val) }, | 3048 | .{ .tag = .string, .data = @intFromEnum(val) }, |
| 2987 | ); | 3049 | ); |
| 2988 | if (self.useLibLlvm() and result.new) self.llvm_constants.appendAssumeCapacity( | 3050 | if (self.useLibLlvm() and result.new) self.llvm.constants.appendAssumeCapacity( |
| 2989 | self.llvm_context.constString(slice.ptr, @intCast(slice.len), .True), | 3051 | self.llvm.context.constString(slice.ptr, @intCast(slice.len), .True), |
| 2990 | ); | 3052 | ); |
| 2991 | return result.constant; | 3053 | return result.constant; |
| 2992 | } | 3054 | } |
| ... | @@ -2998,8 +3060,8 @@ fn stringNullConstAssumeCapacity(self: *Builder, val: String) Constant { | ... | @@ -2998,8 +3060,8 @@ fn stringNullConstAssumeCapacity(self: *Builder, val: String) Constant { |
| 2998 | const result = self.getOrPutConstantNoExtraAssumeCapacity( | 3060 | const result = self.getOrPutConstantNoExtraAssumeCapacity( |
| 2999 | .{ .tag = .string_null, .data = @intFromEnum(val) }, | 3061 | .{ .tag = .string_null, .data = @intFromEnum(val) }, |
| 3000 | ); | 3062 | ); |
| 3001 | if (self.useLibLlvm() and result.new) self.llvm_constants.appendAssumeCapacity( | 3063 | if (self.useLibLlvm() and result.new) self.llvm.constants.appendAssumeCapacity( |
| 3002 | self.llvm_context.constString(slice.ptr, @intCast(slice.len + 1), .True), | 3064 | self.llvm.context.constString(slice.ptr, @intCast(slice.len + 1), .True), |
| 3003 | ); | 3065 | ); |
| 3004 | return result.constant; | 3066 | return result.constant; |
| 3005 | } | 3067 | } |
| ... | @@ -3032,7 +3094,7 @@ fn vectorConstAssumeCapacity( | ... | @@ -3032,7 +3094,7 @@ fn vectorConstAssumeCapacity( |
| 3032 | defer allocator.free(llvm_vals); | 3094 | defer allocator.free(llvm_vals); |
| 3033 | for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self); | 3095 | for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self); |
| 3034 | | 3096 | |
| 3035 | self.llvm_constants.appendAssumeCapacity( | 3097 | self.llvm.constants.appendAssumeCapacity( |
| 3036 | llvm.constVector(llvm_vals.ptr, @intCast(llvm_vals.len)), | 3098 | llvm.constVector(llvm_vals.ptr, @intCast(llvm_vals.len)), |
| 3037 | ); | 3099 | ); |
| 3038 | } | 3100 | } |
| ... | @@ -3061,7 +3123,7 @@ fn zeroInitConstAssumeCapacity(self: *Builder, ty: Type) Constant { | ... | @@ -3061,7 +3123,7 @@ fn zeroInitConstAssumeCapacity(self: *Builder, ty: Type) Constant { |
| 3061 | .{ .tag = .zeroinitializer, .data = @intFromEnum(ty) }, | 3123 | .{ .tag = .zeroinitializer, .data = @intFromEnum(ty) }, |
| 3062 | ); | 3124 | ); |
| 3063 | if (self.useLibLlvm() and result.new) | 3125 | if (self.useLibLlvm() and result.new) |
| 3064 | self.llvm_constants.appendAssumeCapacity(ty.toLlvm(self).constNull()); | 3126 | self.llvm.constants.appendAssumeCapacity(ty.toLlvm(self).constNull()); |
| 3065 | return result.constant; | 3127 | return result.constant; |
| 3066 | } | 3128 | } |
| 3067 | | 3129 | |
| ... | @@ -3078,7 +3140,7 @@ fn undefConstAssumeCapacity(self: *Builder, ty: Type) Constant { | ... | @@ -3078,7 +3140,7 @@ fn undefConstAssumeCapacity(self: *Builder, ty: Type) Constant { |
| 3078 | .{ .tag = .undef, .data = @intFromEnum(ty) }, | 3140 | .{ .tag = .undef, .data = @intFromEnum(ty) }, |
| 3079 | ); | 3141 | ); |
| 3080 | if (self.useLibLlvm() and result.new) | 3142 | if (self.useLibLlvm() and result.new) |
| 3081 | self.llvm_constants.appendAssumeCapacity(ty.toLlvm(self).getUndef()); | 3143 | self.llvm.constants.appendAssumeCapacity(ty.toLlvm(self).getUndef()); |
| 3082 | return result.constant; | 3144 | return result.constant; |
| 3083 | } | 3145 | } |
| 3084 | | 3146 | |
| ... | @@ -3095,7 +3157,7 @@ fn poisonConstAssumeCapacity(self: *Builder, ty: Type) Constant { | ... | @@ -3095,7 +3157,7 @@ fn poisonConstAssumeCapacity(self: *Builder, ty: Type) Constant { |
| 3095 | .{ .tag = .poison, .data = @intFromEnum(ty) }, | 3157 | .{ .tag = .poison, .data = @intFromEnum(ty) }, |
| 3096 | ); | 3158 | ); |
| 3097 | if (self.useLibLlvm() and result.new) | 3159 | if (self.useLibLlvm() and result.new) |
| 3098 | self.llvm_constants.appendAssumeCapacity(ty.toLlvm(self).getUndef()); | 3160 | self.llvm.constants.appendAssumeCapacity(ty.toLlvm(self).getUndef()); |
| 3099 | return result.constant; | 3161 | return result.constant; |
| 3100 | } | 3162 | } |
| 3101 | | 3163 | |
| ... | @@ -3128,7 +3190,7 @@ fn blockAddrConstAssumeCapacity( | ... | @@ -3128,7 +3190,7 @@ fn blockAddrConstAssumeCapacity( |
| 3128 | .tag = .blockaddress, | 3190 | .tag = .blockaddress, |
| 3129 | .data = self.addConstantExtraAssumeCapacity(data), | 3191 | .data = self.addConstantExtraAssumeCapacity(data), |
| 3130 | }); | 3192 | }); |
| 3131 | if (self.useLibLlvm()) self.llvm_constants.appendAssumeCapacity( | 3193 | if (self.useLibLlvm()) self.llvm.constants.appendAssumeCapacity( |
| 3132 | function.toLlvm(self).blockAddress(block.toValue(self, function).toLlvm(self, function)), | 3194 | function.toLlvm(self).blockAddress(block.toValue(self, function).toLlvm(self, function)), |
| 3133 | ); | 3195 | ); |
| 3134 | } | 3196 | } |
| ... | @@ -3139,7 +3201,7 @@ fn dsoLocalEquivalentConstAssumeCapacity(self: *Builder, function: Function.Inde | ... | @@ -3139,7 +3201,7 @@ fn dsoLocalEquivalentConstAssumeCapacity(self: *Builder, function: Function.Inde |
| 3139 | const result = self.getOrPutConstantNoExtraAssumeCapacity( | 3201 | const result = self.getOrPutConstantNoExtraAssumeCapacity( |
| 3140 | .{ .tag = .dso_local_equivalent, .data = @intFromEnum(function) }, | 3202 | .{ .tag = .dso_local_equivalent, .data = @intFromEnum(function) }, |
| 3141 | ); | 3203 | ); |
| 3142 | if (self.useLibLlvm() and result.new) self.llvm_constants.appendAssumeCapacity(undefined); | 3204 | if (self.useLibLlvm() and result.new) self.llvm.constants.appendAssumeCapacity(undefined); |
| 3143 | return result.constant; | 3205 | return result.constant; |
| 3144 | } | 3206 | } |
| 3145 | | 3207 | |
| ... | @@ -3147,7 +3209,7 @@ fn noCfiConstAssumeCapacity(self: *Builder, function: Function.Index) Constant { | ... | @@ -3147,7 +3209,7 @@ fn noCfiConstAssumeCapacity(self: *Builder, function: Function.Index) Constant { |
| 3147 | const result = self.getOrPutConstantNoExtraAssumeCapacity( | 3209 | const result = self.getOrPutConstantNoExtraAssumeCapacity( |
| 3148 | .{ .tag = .no_cfi, .data = @intFromEnum(function) }, | 3210 | .{ .tag = .no_cfi, .data = @intFromEnum(function) }, |
| 3149 | ); | 3211 | ); |
| 3150 | if (self.useLibLlvm() and result.new) self.llvm_constants.appendAssumeCapacity(undefined); | 3212 | if (self.useLibLlvm() and result.new) self.llvm.constants.appendAssumeCapacity(undefined); |
| 3151 | return result.constant; | 3213 | return result.constant; |
| 3152 | } | 3214 | } |
| 3153 | | 3215 | |
| ... | @@ -3226,7 +3288,7 @@ fn castConstAssumeCapacity(self: *Builder, tag: Constant.Tag, arg: Constant, ty: | ... | @@ -3226,7 +3288,7 @@ fn castConstAssumeCapacity(self: *Builder, tag: Constant.Tag, arg: Constant, ty: |
| 3226 | .tag = tag, | 3288 | .tag = tag, |
| 3227 | .data = self.addConstantExtraAssumeCapacity(data.cast), | 3289 | .data = self.addConstantExtraAssumeCapacity(data.cast), |
| 3228 | }); | 3290 | }); |
| 3229 | if (self.useLibLlvm()) self.llvm_constants.appendAssumeCapacity(switch (tag) { | 3291 | if (self.useLibLlvm()) self.llvm.constants.appendAssumeCapacity(switch (tag) { |
| 3230 | .trunc => &llvm.Value.constTrunc, | 3292 | .trunc => &llvm.Value.constTrunc, |
| 3231 | .zext => &llvm.Value.constZExt, | 3293 | .zext => &llvm.Value.constZExt, |
| 3232 | .sext => &llvm.Value.constSExt, | 3294 | .sext => &llvm.Value.constSExt, |
| ... | @@ -3330,7 +3392,7 @@ fn gepConstAssumeCapacity( | ... | @@ -3330,7 +3392,7 @@ fn gepConstAssumeCapacity( |
| 3330 | defer allocator.free(llvm_indices); | 3392 | defer allocator.free(llvm_indices); |
| 3331 | for (llvm_indices, indices) |*llvm_index, index| llvm_index.* = index.toLlvm(self); | 3393 | for (llvm_indices, indices) |*llvm_index, index| llvm_index.* = index.toLlvm(self); |
| 3332 | | 3394 | |
| 3333 | self.llvm_constants.appendAssumeCapacity(switch (kind) { | 3395 | self.llvm.constants.appendAssumeCapacity(switch (kind) { |
| 3334 | .normal => &llvm.Type.constGEP, | 3396 | .normal => &llvm.Type.constGEP, |
| 3335 | .inbounds => &llvm.Type.constInBoundsGEP, | 3397 | .inbounds => &llvm.Type.constInBoundsGEP, |
| 3336 | }(ty.toLlvm(self), base.toLlvm(self), llvm_indices.ptr, @intCast(indices.len))); | 3398 | }(ty.toLlvm(self), base.toLlvm(self), llvm_indices.ptr, @intCast(indices.len))); |
| ... | @@ -3374,7 +3436,7 @@ fn binConstAssumeCapacity( | ... | @@ -3374,7 +3436,7 @@ fn binConstAssumeCapacity( |
| 3374 | .tag = tag, | 3436 | .tag = tag, |
| 3375 | .data = self.addConstantExtraAssumeCapacity(data.bin), | 3437 | .data = self.addConstantExtraAssumeCapacity(data.bin), |
| 3376 | }); | 3438 | }); |
| 3377 | if (self.useLibLlvm()) self.llvm_constants.appendAssumeCapacity(switch (tag) { | 3439 | if (self.useLibLlvm()) self.llvm.constants.appendAssumeCapacity(switch (tag) { |
| 3378 | .add => &llvm.Value.constAdd, | 3440 | .add => &llvm.Value.constAdd, |
| 3379 | .sub => &llvm.Value.constSub, | 3441 | .sub => &llvm.Value.constSub, |
| 3380 | .mul => &llvm.Value.constMul, | 3442 | .mul => &llvm.Value.constMul, |
| ... | @@ -3402,7 +3464,7 @@ fn ensureUnusedConstantCapacity( | ... | @@ -3402,7 +3464,7 @@ fn ensureUnusedConstantCapacity( |
| 3402 | self.gpa, | 3464 | self.gpa, |
| 3403 | count * (@typeInfo(E).Struct.fields.len + trail_len), | 3465 | count * (@typeInfo(E).Struct.fields.len + trail_len), |
| 3404 | ) else assert(trail_len == 0); | 3466 | ) else assert(trail_len == 0); |
| 3405 | if (self.useLibLlvm()) try self.llvm_constants.ensureUnusedCapacity(self.gpa, count); | 3467 | if (self.useLibLlvm()) try self.llvm.constants.ensureUnusedCapacity(self.gpa, count); |
| 3406 | } | 3468 | } |
| 3407 | | 3469 | |
| 3408 | fn getOrPutConstantNoExtraAssumeCapacity( | 3470 | fn getOrPutConstantNoExtraAssumeCapacity( |
| ... | @@ -3516,13 +3578,15 @@ fn constantExtraData(self: *const Builder, comptime T: type, index: Constant.Ite | ... | @@ -3516,13 +3578,15 @@ fn constantExtraData(self: *const Builder, comptime T: type, index: Constant.Ite |
| 3516 | return self.constantExtraDataTrail(T, index).data; | 3578 | return self.constantExtraDataTrail(T, index).data; |
| 3517 | } | 3579 | } |
| 3518 | | 3580 | |
| 3519 | inline fn useLibLlvm(self: *const Builder) bool { | 3581 | pub inline fn useLibLlvm(self: *const Builder) bool { |
| 3520 | return build_options.have_llvm and self.use_lib_llvm; | 3582 | return build_options.have_llvm and self.use_lib_llvm; |
| 3521 | } | 3583 | } |
| 3522 | | 3584 | |
| 3523 | const assert = std.debug.assert; | 3585 | const assert = std.debug.assert; |
| 3524 | const build_options = @import("build_options"); | 3586 | const build_options = @import("build_options"); |
| | 3587 | const builtin = @import("builtin"); |
| 3525 | const llvm = @import("bindings.zig"); | 3588 | const llvm = @import("bindings.zig"); |
| | 3589 | const log = std.log.scoped(.llvm); |
| 3526 | const std = @import("std"); | 3590 | const std = @import("std"); |
| 3527 | | 3591 | |
| 3528 | const Allocator = std.mem.Allocator; | 3592 | const Allocator = std.mem.Allocator; |