| ... | ... | @@ -3899,6 +3899,7 @@ pub const Function = struct { |
| 3899 | 3899 | blocks: []const Block = &.{}, |
| 3900 | 3900 | instructions: std.MultiArrayList(Instruction) = .{}, |
| 3901 | 3901 | names: [*]const String = &[0]String{}, |
| 3902 | value_indices: [*]const u32 = &[0]u32{}, |
| 3902 | 3903 | metadata: ?[*]const Metadata = null, |
| 3903 | 3904 | extra: []const u32 = &.{}, |
| 3904 | 3905 | |
| ... | ... | @@ -4335,6 +4336,10 @@ pub const Function = struct { |
| 4335 | 4336 | return function.names[@intFromEnum(self)]; |
| 4336 | 4337 | } |
| 4337 | 4338 | |
| 4339 | pub fn valueIndex(self: Instruction.Index, function: *const Function) u32 { |
| 4340 | return function.value_indices[@intFromEnum(self)]; |
| 4341 | } |
| 4342 | |
| 4338 | 4343 | pub fn toValue(self: Instruction.Index) Value { |
| 4339 | 4344 | return @enumFromInt(@intFromEnum(self)); |
| 4340 | 4345 | } |
| ... | ... | @@ -4993,6 +4998,7 @@ pub const Function = struct { |
| 4993 | 4998 | pub fn deinit(self: *Function, gpa: Allocator) void { |
| 4994 | 4999 | gpa.free(self.extra); |
| 4995 | 5000 | if (self.metadata) |metadata| gpa.free(metadata[0..self.instructions.len]); |
| 5001 | gpa.free(self.value_indices[0..self.instructions.len]); |
| 4996 | 5002 | gpa.free(self.names[0..self.instructions.len]); |
| 4997 | 5003 | self.instructions.deinit(gpa); |
| 4998 | 5004 | gpa.free(self.blocks); |
| ... | ... | @@ -6382,6 +6388,9 @@ pub const WipFunction = struct { |
| 6382 | 6388 | const names = try gpa.alloc(String, final_instructions_len); |
| 6383 | 6389 | errdefer gpa.free(names); |
| 6384 | 6390 | |
| 6391 | const value_indices = try gpa.alloc(u32, final_instructions_len); |
| 6392 | errdefer gpa.free(value_indices); |
| 6393 | |
| 6385 | 6394 | const metadata = |
| 6386 | 6395 | if (self.builder.strip) null else try gpa.alloc(Metadata, final_instructions_len); |
| 6387 | 6396 | errdefer if (metadata) |new_metadata| gpa.free(new_metadata); |
| ... | ... | @@ -6475,12 +6484,15 @@ pub const WipFunction = struct { |
| 6475 | 6484 | return new_name; |
| 6476 | 6485 | } |
| 6477 | 6486 | } = .{}; |
| 6487 | var value_index: u32 = 0; |
| 6478 | 6488 | for (0..params_len) |param_index| { |
| 6479 | 6489 | const old_argument_index: Instruction.Index = @enumFromInt(param_index); |
| 6480 | 6490 | const new_argument_index: Instruction.Index = @enumFromInt(function.instructions.len); |
| 6481 | 6491 | const argument = self.instructions.get(@intFromEnum(old_argument_index)); |
| 6482 | 6492 | assert(argument.tag == .arg); |
| 6483 | 6493 | assert(argument.data == param_index); |
| 6494 | value_indices[function.instructions.len] = value_index; |
| 6495 | value_index += 1; |
| 6484 | 6496 | function.instructions.appendAssumeCapacity(argument); |
| 6485 | 6497 | names[@intFromEnum(new_argument_index)] = wip_name.map( |
| 6486 | 6498 | if (self.builder.strip) .empty else self.names.items[@intFromEnum(old_argument_index)], |
| ... | ... | @@ -6488,6 +6500,7 @@ pub const WipFunction = struct { |
| 6488 | 6500 | } |
| 6489 | 6501 | for (self.blocks.items) |current_block| { |
| 6490 | 6502 | const new_block_index: Instruction.Index = @enumFromInt(function.instructions.len); |
| 6503 | value_indices[function.instructions.len] = value_index; |
| 6491 | 6504 | function.instructions.appendAssumeCapacity(.{ |
| 6492 | 6505 | .tag = .block, |
| 6493 | 6506 | .data = current_block.incoming, |
| ... | ... | @@ -6797,6 +6810,9 @@ pub const WipFunction = struct { |
| 6797 | 6810 | if (old_instruction_index.hasResultWip(self)) .empty else .none |
| 6798 | 6811 | else |
| 6799 | 6812 | self.names.items[@intFromEnum(old_instruction_index)]); |
| 6813 | |
| 6814 | value_indices[@intFromEnum(new_instruction_index)] = value_index; |
| 6815 | if (old_instruction_index.hasResultWip(self)) value_index += 1; |
| 6800 | 6816 | } |
| 6801 | 6817 | } |
| 6802 | 6818 | |
| ... | ... | @@ -6804,6 +6820,7 @@ pub const WipFunction = struct { |
| 6804 | 6820 | function.extra = wip_extra.finish(); |
| 6805 | 6821 | function.blocks = blocks; |
| 6806 | 6822 | function.names = names.ptr; |
| 6823 | function.value_indices = value_indices.ptr; |
| 6807 | 6824 | function.metadata = if (metadata) |new_metadata| new_metadata.ptr else null; |
| 6808 | 6825 | } |
| 6809 | 6826 | |