| ... | @@ -3994,6 +3994,7 @@ pub const Function = struct { | ... | @@ -3994,6 +3994,7 @@ pub const Function = struct { |
| 3994 | names: [*]const String = &[0]String{}, | 3994 | names: [*]const String = &[0]String{}, |
| 3995 | value_indices: [*]const u32 = &[0]u32{}, | 3995 | value_indices: [*]const u32 = &[0]u32{}, |
| 3996 | strip: bool, | 3996 | strip: bool, |
| | 3997 | any_nosanitize: bool, |
| 3997 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}, | 3998 | debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .{}, |
| 3998 | debug_values: []const Instruction.Index = &.{}, | 3999 | debug_values: []const Instruction.Index = &.{}, |
| 3999 | extra: []const u32 = &.{}, | 4000 | extra: []const u32 = &.{}, |
| ... | @@ -4090,6 +4091,7 @@ pub const Function = struct { | ... | @@ -4090,6 +4091,7 @@ pub const Function = struct { |
| 4090 | block, | 4091 | block, |
| 4091 | br, | 4092 | br, |
| 4092 | br_cond, | 4093 | br_cond, |
| | 4094 | br_cond_nosanitize, |
| 4093 | call, | 4095 | call, |
| 4094 | @"call fast", | 4096 | @"call fast", |
| 4095 | cmpxchg, | 4097 | cmpxchg, |
| ... | @@ -4345,6 +4347,13 @@ pub const Function = struct { | ... | @@ -4345,6 +4347,13 @@ pub const Function = struct { |
| 4345 | else => unreachable, | 4347 | else => unreachable, |
| 4346 | }; | 4348 | }; |
| 4347 | } | 4349 | } |
| | 4350 | |
| | 4351 | pub fn isNosanitize(self: Tag) bool { |
| | 4352 | return switch (self) { |
| | 4353 | .br_cond_nosanitize => true, |
| | 4354 | else => false, |
| | 4355 | }; |
| | 4356 | } |
| 4348 | }; | 4357 | }; |
| 4349 | | 4358 | |
| 4350 | pub const Index = enum(u32) { | 4359 | pub const Index = enum(u32) { |
| ... | @@ -4367,6 +4376,7 @@ pub const Function = struct { | ... | @@ -4367,6 +4376,7 @@ pub const Function = struct { |
| 4367 | return switch (wip.instructions.items(.tag)[@intFromEnum(self)]) { | 4376 | return switch (wip.instructions.items(.tag)[@intFromEnum(self)]) { |
| 4368 | .br, | 4377 | .br, |
| 4369 | .br_cond, | 4378 | .br_cond, |
| | 4379 | .br_cond_nosanitize, |
| 4370 | .ret, | 4380 | .ret, |
| 4371 | .@"ret void", | 4381 | .@"ret void", |
| 4372 | .@"switch", | 4382 | .@"switch", |
| ... | @@ -4380,6 +4390,7 @@ pub const Function = struct { | ... | @@ -4380,6 +4390,7 @@ pub const Function = struct { |
| 4380 | return switch (wip.instructions.items(.tag)[@intFromEnum(self)]) { | 4390 | return switch (wip.instructions.items(.tag)[@intFromEnum(self)]) { |
| 4381 | .br, | 4391 | .br, |
| 4382 | .br_cond, | 4392 | .br_cond, |
| | 4393 | .br_cond_nosanitize, |
| 4383 | .fence, | 4394 | .fence, |
| 4384 | .ret, | 4395 | .ret, |
| 4385 | .@"ret void", | 4396 | .@"ret void", |
| ... | @@ -4470,6 +4481,7 @@ pub const Function = struct { | ... | @@ -4470,6 +4481,7 @@ pub const Function = struct { |
| 4470 | .block => .label, | 4481 | .block => .label, |
| 4471 | .br, | 4482 | .br, |
| 4472 | .br_cond, | 4483 | .br_cond, |
| | 4484 | .br_cond_nosanitize, |
| 4473 | .fence, | 4485 | .fence, |
| 4474 | .ret, | 4486 | .ret, |
| 4475 | .@"ret void", | 4487 | .@"ret void", |
| ... | @@ -4656,6 +4668,7 @@ pub const Function = struct { | ... | @@ -4656,6 +4668,7 @@ pub const Function = struct { |
| 4656 | .block => .label, | 4668 | .block => .label, |
| 4657 | .br, | 4669 | .br, |
| 4658 | .br_cond, | 4670 | .br_cond, |
| | 4671 | .br_cond_nosanitize, |
| 4659 | .fence, | 4672 | .fence, |
| 4660 | .ret, | 4673 | .ret, |
| 4661 | .@"ret void", | 4674 | .@"ret void", |
| ... | @@ -5088,6 +5101,7 @@ pub const WipFunction = struct { | ... | @@ -5088,6 +5101,7 @@ pub const WipFunction = struct { |
| 5088 | instructions: std.MultiArrayList(Instruction), | 5101 | instructions: std.MultiArrayList(Instruction), |
| 5089 | names: std.ArrayListUnmanaged(String), | 5102 | names: std.ArrayListUnmanaged(String), |
| 5090 | strip: bool, | 5103 | strip: bool, |
| | 5104 | any_nosanitize: bool, |
| 5091 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation), | 5105 | debug_locations: std.AutoArrayHashMapUnmanaged(Instruction.Index, DebugLocation), |
| 5092 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), | 5106 | debug_values: std.AutoArrayHashMapUnmanaged(Instruction.Index, void), |
| 5093 | extra: std.ArrayListUnmanaged(u32), | 5107 | extra: std.ArrayListUnmanaged(u32), |
| ... | @@ -5134,6 +5148,7 @@ pub const WipFunction = struct { | ... | @@ -5134,6 +5148,7 @@ pub const WipFunction = struct { |
| 5134 | .instructions = .{}, | 5148 | .instructions = .{}, |
| 5135 | .names = .{}, | 5149 | .names = .{}, |
| 5136 | .strip = options.strip, | 5150 | .strip = options.strip, |
| | 5151 | .any_nosanitize = false, |
| 5137 | .debug_locations = .{}, | 5152 | .debug_locations = .{}, |
| 5138 | .debug_values = .{}, | 5153 | .debug_values = .{}, |
| 5139 | .extra = .{}, | 5154 | .extra = .{}, |
| ... | @@ -5201,11 +5216,34 @@ pub const WipFunction = struct { | ... | @@ -5201,11 +5216,34 @@ pub const WipFunction = struct { |
| 5201 | cond: Value, | 5216 | cond: Value, |
| 5202 | then: Block.Index, | 5217 | then: Block.Index, |
| 5203 | @"else": Block.Index, | 5218 | @"else": Block.Index, |
| | 5219 | ) Allocator.Error!Instruction.Index { |
| | 5220 | return brCondTag(self, cond, then, @"else", .br_cond); |
| | 5221 | } |
| | 5222 | |
| | 5223 | pub fn brCondNosanitize( |
| | 5224 | self: *WipFunction, |
| | 5225 | cond: Value, |
| | 5226 | then: Block.Index, |
| | 5227 | @"else": Block.Index, |
| | 5228 | ) Allocator.Error!Instruction.Index { |
| | 5229 | self.any_nosanitize = true; |
| | 5230 | return brCondTag(self, cond, then, @"else", .br_cond_nosanitize); |
| | 5231 | } |
| | 5232 | |
| | 5233 | pub fn brCondTag( |
| | 5234 | self: *WipFunction, |
| | 5235 | cond: Value, |
| | 5236 | then: Block.Index, |
| | 5237 | @"else": Block.Index, |
| | 5238 | /// Asserted to be either `.br_cond` or `.br_cond_nosanitize`. |
| | 5239 | tag: Instruction.Tag, |
| 5204 | ) Allocator.Error!Instruction.Index { | 5240 | ) Allocator.Error!Instruction.Index { |
| 5205 | assert(cond.typeOfWip(self) == .i1); | 5241 | assert(cond.typeOfWip(self) == .i1); |
| | 5242 | assert(tag == .br_cond or tag == .br_cond_nosanitize); |
| | 5243 | assert(tag != .br_cond_nosanitize or self.any_nosanitize); |
| 5206 | try self.ensureUnusedExtraCapacity(1, Instruction.BrCond, 0); | 5244 | try self.ensureUnusedExtraCapacity(1, Instruction.BrCond, 0); |
| 5207 | const instruction = try self.addInst(null, .{ | 5245 | const instruction = try self.addInst(null, .{ |
| 5208 | .tag = .br_cond, | 5246 | .tag = tag, |
| 5209 | .data = self.addExtraAssumeCapacity(Instruction.BrCond{ | 5247 | .data = self.addExtraAssumeCapacity(Instruction.BrCond{ |
| 5210 | .cond = cond, | 5248 | .cond = cond, |
| 5211 | .then = then, | 5249 | .then = then, |
| ... | @@ -6374,7 +6412,7 @@ pub const WipFunction = struct { | ... | @@ -6374,7 +6412,7 @@ pub const WipFunction = struct { |
| 6374 | .@"ret void", | 6412 | .@"ret void", |
| 6375 | .@"unreachable", | 6413 | .@"unreachable", |
| 6376 | => {}, | 6414 | => {}, |
| 6377 | .br_cond => { | 6415 | .br_cond, .br_cond_nosanitize => { |
| 6378 | const extra = self.extraData(Instruction.BrCond, instruction.data); | 6416 | const extra = self.extraData(Instruction.BrCond, instruction.data); |
| 6379 | instruction.data = wip_extra.addExtra(Instruction.BrCond{ | 6417 | instruction.data = wip_extra.addExtra(Instruction.BrCond{ |
| 6380 | .cond = instructions.map(extra.cond), | 6418 | .cond = instructions.map(extra.cond), |
| ... | @@ -6559,6 +6597,7 @@ pub const WipFunction = struct { | ... | @@ -6559,6 +6597,7 @@ pub const WipFunction = struct { |
| 6559 | function.names = names.ptr; | 6597 | function.names = names.ptr; |
| 6560 | function.value_indices = value_indices.ptr; | 6598 | function.value_indices = value_indices.ptr; |
| 6561 | function.strip = self.strip; | 6599 | function.strip = self.strip; |
| | 6600 | function.any_nosanitize = self.any_nosanitize; |
| 6562 | function.debug_locations = debug_locations; | 6601 | function.debug_locations = debug_locations; |
| 6563 | function.debug_values = debug_values; | 6602 | function.debug_values = debug_values; |
| 6564 | } | 6603 | } |
| ... | @@ -7697,6 +7736,7 @@ pub const MetadataString = enum(u32) { | ... | @@ -7697,6 +7736,7 @@ pub const MetadataString = enum(u32) { |
| 7697 | | 7736 | |
| 7698 | pub const Metadata = enum(u32) { | 7737 | pub const Metadata = enum(u32) { |
| 7699 | none = 0, | 7738 | none = 0, |
| | 7739 | empty_tuple = 1, |
| 7700 | _, | 7740 | _, |
| 7701 | | 7741 | |
| 7702 | const first_forward_reference = 1 << 29; | 7742 | const first_forward_reference = 1 << 29; |
| ... | @@ -8355,7 +8395,7 @@ pub const Metadata = enum(u32) { | ... | @@ -8355,7 +8395,7 @@ pub const Metadata = enum(u32) { |
| 8355 | }; | 8395 | }; |
| 8356 | | 8396 | |
| 8357 | pub fn init(options: Options) Allocator.Error!Builder { | 8397 | pub fn init(options: Options) Allocator.Error!Builder { |
| 8358 | var self = Builder{ | 8398 | var self: Builder = .{ |
| 8359 | .gpa = options.allocator, | 8399 | .gpa = options.allocator, |
| 8360 | .strip = options.strip, | 8400 | .strip = options.strip, |
| 8361 | | 8401 | |
| ... | @@ -8458,6 +8498,7 @@ pub fn init(options: Options) Allocator.Error!Builder { | ... | @@ -8458,6 +8498,7 @@ pub fn init(options: Options) Allocator.Error!Builder { |
| 8458 | | 8498 | |
| 8459 | try self.metadata_string_indices.append(self.gpa, 0); | 8499 | try self.metadata_string_indices.append(self.gpa, 0); |
| 8460 | assert(try self.metadataString("") == .none); | 8500 | assert(try self.metadataString("") == .none); |
| | 8501 | assert(try self.debugTuple(&.{}) == .empty_tuple); |
| 8461 | | 8502 | |
| 8462 | return self; | 8503 | return self; |
| 8463 | } | 8504 | } |
| ... | @@ -8855,6 +8896,7 @@ pub fn addFunctionAssumeCapacity( | ... | @@ -8855,6 +8896,7 @@ pub fn addFunctionAssumeCapacity( |
| 8855 | .kind = .{ .function = function_index }, | 8896 | .kind = .{ .function = function_index }, |
| 8856 | }), | 8897 | }), |
| 8857 | .strip = undefined, | 8898 | .strip = undefined, |
| | 8899 | .any_nosanitize = false, |
| 8858 | }); | 8900 | }); |
| 8859 | return function_index; | 8901 | return function_index; |
| 8860 | } | 8902 | } |
| ... | @@ -9502,6 +9544,12 @@ pub fn printUnbuffered( | ... | @@ -9502,6 +9544,12 @@ pub fn printUnbuffered( |
| 9502 | }); | 9544 | }); |
| 9503 | } | 9545 | } |
| 9504 | if (function.instructions.len > 0) { | 9546 | if (function.instructions.len > 0) { |
| | 9547 | const maybe_empty_tuple: ?u32 = if (!function.any_nosanitize) null else b: { |
| | 9548 | const gop = try metadata_formatter.map.getOrPut(self.gpa, .{ |
| | 9549 | .metadata = .empty_tuple, |
| | 9550 | }); |
| | 9551 | break :b @intCast(gop.index); |
| | 9552 | }; |
| 9505 | var block_incoming_len: u32 = undefined; | 9553 | var block_incoming_len: u32 = undefined; |
| 9506 | try writer.writeAll(" {\n"); | 9554 | try writer.writeAll(" {\n"); |
| 9507 | var maybe_dbg_index: ?u32 = null; | 9555 | var maybe_dbg_index: ?u32 = null; |
| ... | @@ -9684,6 +9732,14 @@ pub fn printUnbuffered( | ... | @@ -9684,6 +9732,14 @@ pub fn printUnbuffered( |
| 9684 | extra.@"else".toInst(&function).fmt(function_index, self), | 9732 | extra.@"else".toInst(&function).fmt(function_index, self), |
| 9685 | }); | 9733 | }); |
| 9686 | }, | 9734 | }, |
| | 9735 | .br_cond_nosanitize => { |
| | 9736 | const extra = function.extraData(Function.Instruction.BrCond, instruction.data); |
| | 9737 | try writer.print(" br {%}, {%}, {%}", .{ |
| | 9738 | extra.cond.fmt(function_index, self), |
| | 9739 | extra.then.toInst(&function).fmt(function_index, self), |
| | 9740 | extra.@"else".toInst(&function).fmt(function_index, self), |
| | 9741 | }); |
| | 9742 | }, |
| 9687 | .call, | 9743 | .call, |
| 9688 | .@"call fast", | 9744 | .@"call fast", |
| 9689 | .@"musttail call", | 9745 | .@"musttail call", |
| ... | @@ -9950,8 +10006,12 @@ pub fn printUnbuffered( | ... | @@ -9950,8 +10006,12 @@ pub fn printUnbuffered( |
| 9950 | } | 10006 | } |
| 9951 | | 10007 | |
| 9952 | if (maybe_dbg_index) |dbg_index| { | 10008 | if (maybe_dbg_index) |dbg_index| { |
| 9953 | try writer.print(", !dbg !{}\n", .{dbg_index}); | 10009 | try writer.print(", !dbg !{}", .{dbg_index}); |
| 9954 | } else try writer.writeByte('\n'); | 10010 | } |
| | 10011 | if (instruction.tag.isNosanitize()) { |
| | 10012 | try writer.print(", !nosanitize !{d}", .{maybe_empty_tuple.?}); |
| | 10013 | } |
| | 10014 | try writer.writeByte('\n'); |
| 9955 | } | 10015 | } |
| 9956 | try writer.writeByte('}'); | 10016 | try writer.writeByte('}'); |
| 9957 | } | 10017 | } |
| ... | @@ -13759,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -13759,7 +13819,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 13759 | const MetadataKindBlock = ir.MetadataKindBlock; | 13819 | const MetadataKindBlock = ir.MetadataKindBlock; |
| 13760 | var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true); | 13820 | var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true); |
| 13761 | | 13821 | |
| 13762 | inline for (@typeInfo(ir.MetadataKind).Enum.fields) |field| { | 13822 | inline for (@typeInfo(ir.FixedMetadataKind).Enum.fields) |field| { |
| 13763 | try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{ | 13823 | try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{ |
| 13764 | .id = field.value, | 13824 | .id = field.value, |
| 13765 | .name = field.name, | 13825 | .name = field.name, |
| ... | @@ -14046,7 +14106,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14046,7 +14106,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14046 | else | 14106 | else |
| 14047 | -%val << 1 | 1); | 14107 | -%val << 1 | 1); |
| 14048 | } | 14108 | } |
| 14049 | try metadata_block.writeUnabbrev(MetadataBlock.Enumerator.id, record.items); | 14109 | try metadata_block.writeUnabbrev(@intFromEnum(MetadataBlock.Enumerator.id), record.items); |
| 14050 | continue; | 14110 | continue; |
| 14051 | }; | 14111 | }; |
| 14052 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{ | 14112 | try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{ |
| ... | @@ -14177,7 +14237,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14177,7 +14237,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14177 | | 14237 | |
| 14178 | try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{ | 14238 | try metadata_block.writeAbbrev(MetadataBlock.GlobalDeclAttachment{ |
| 14179 | .value = @enumFromInt(constant_adapter.getConstantIndex(global.toConst())), | 14239 | .value = @enumFromInt(constant_adapter.getConstantIndex(global.toConst())), |
| 14180 | .kind = ir.MetadataKind.dbg, | 14240 | .kind = .dbg, |
| 14181 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(global_ptr.dbg) - 1), | 14241 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(global_ptr.dbg) - 1), |
| 14182 | }); | 14242 | }); |
| 14183 | } | 14243 | } |
| ... | @@ -14220,20 +14280,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14220,20 +14280,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14220 | constant_adapter: ConstantAdapter, | 14280 | constant_adapter: ConstantAdapter, |
| 14221 | metadata_adapter: MetadataAdapter, | 14281 | metadata_adapter: MetadataAdapter, |
| 14222 | func: *const Function, | 14282 | func: *const Function, |
| 14223 | instruction_index: u32 = 0, | 14283 | instruction_index: Function.Instruction.Index, |
| 14224 | | | |
| 14225 | pub fn init( | | |
| 14226 | const_adapter: ConstantAdapter, | | |
| 14227 | meta_adapter: MetadataAdapter, | | |
| 14228 | func: *const Function, | | |
| 14229 | ) @This() { | | |
| 14230 | return .{ | | |
| 14231 | .constant_adapter = const_adapter, | | |
| 14232 | .metadata_adapter = meta_adapter, | | |
| 14233 | .func = func, | | |
| 14234 | .instruction_index = 0, | | |
| 14235 | }; | | |
| 14236 | } | | |
| 14237 | | 14284 | |
| 14238 | pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) { | 14285 | pub fn get(adapter: @This(), value: anytype, comptime field_name: []const u8) @TypeOf(value) { |
| 14239 | _ = field_name; | 14286 | _ = field_name; |
| ... | @@ -14282,19 +14329,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14282,19 +14329,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14282 | } | 14329 | } |
| 14283 | | 14330 | |
| 14284 | pub fn offset(adapter: @This()) u32 { | 14331 | pub fn offset(adapter: @This()) u32 { |
| 14285 | return @as( | 14332 | return adapter.instruction_index.valueIndex(adapter.func) + adapter.firstInstr(); |
| 14286 | Function.Instruction.Index, | | |
| 14287 | @enumFromInt(adapter.instruction_index), | | |
| 14288 | ).valueIndex(adapter.func) + adapter.firstInstr(); | | |
| 14289 | } | 14333 | } |
| 14290 | | 14334 | |
| 14291 | fn firstInstr(adapter: @This()) u32 { | 14335 | fn firstInstr(adapter: @This()) u32 { |
| 14292 | return adapter.constant_adapter.numConstants(); | 14336 | return adapter.constant_adapter.numConstants(); |
| 14293 | } | 14337 | } |
| 14294 | | | |
| 14295 | pub fn next(adapter: *@This()) void { | | |
| 14296 | adapter.instruction_index += 1; | | |
| 14297 | } | | |
| 14298 | }; | 14338 | }; |
| 14299 | | 14339 | |
| 14300 | for (self.functions.items, 0..) |func, func_index| { | 14340 | for (self.functions.items, 0..) |func, func_index| { |
| ... | @@ -14307,7 +14347,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14307,7 +14347,12 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14307 | | 14347 | |
| 14308 | try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len }); | 14348 | try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len }); |
| 14309 | | 14349 | |
| 14310 | var adapter = FunctionAdapter.init(constant_adapter, metadata_adapter, &func); | 14350 | var adapter: FunctionAdapter = .{ |
| | 14351 | .constant_adapter = constant_adapter, |
| | 14352 | .metadata_adapter = metadata_adapter, |
| | 14353 | .func = &func, |
| | 14354 | .instruction_index = @enumFromInt(0), |
| | 14355 | }; |
| 14311 | | 14356 | |
| 14312 | // Emit function level metadata block | 14357 | // Emit function level metadata block |
| 14313 | if (!func.strip and func.debug_values.len > 0) { | 14358 | if (!func.strip and func.debug_values.len > 0) { |
| ... | @@ -14330,21 +14375,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14330,21 +14375,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14330 | var has_location = false; | 14375 | var has_location = false; |
| 14331 | | 14376 | |
| 14332 | var block_incoming_len: u32 = undefined; | 14377 | var block_incoming_len: u32 = undefined; |
| 14333 | for (0..func.instructions.len) |instr_index| { | 14378 | for (tags, datas, 0..) |tag, data, instr_index| { |
| 14334 | const tag = tags[instr_index]; | 14379 | adapter.instruction_index = @enumFromInt(instr_index); |
| 14335 | | | |
| 14336 | record.clearRetainingCapacity(); | 14380 | record.clearRetainingCapacity(); |
| 14337 | | 14381 | |
| 14338 | switch (tag) { | 14382 | switch (tag) { |
| 14339 | .block => block_incoming_len = datas[instr_index], | 14383 | .arg => continue, |
| 14340 | .arg => {}, | 14384 | .block => { |
| | 14385 | block_incoming_len = data; |
| | 14386 | continue; |
| | 14387 | }, |
| 14341 | .@"unreachable" => try function_block.writeAbbrev(FunctionBlock.Unreachable{}), | 14388 | .@"unreachable" => try function_block.writeAbbrev(FunctionBlock.Unreachable{}), |
| 14342 | .call, | 14389 | .call, |
| 14343 | .@"musttail call", | 14390 | .@"musttail call", |
| 14344 | .@"notail call", | 14391 | .@"notail call", |
| 14345 | .@"tail call", | 14392 | .@"tail call", |
| 14346 | => |kind| { | 14393 | => |kind| { |
| 14347 | var extra = func.extraDataTrail(Function.Instruction.Call, datas[instr_index]); | 14394 | var extra = func.extraDataTrail(Function.Instruction.Call, data); |
| 14348 | | 14395 | |
| 14349 | const call_conv = extra.data.info.call_conv; | 14396 | const call_conv = extra.data.info.call_conv; |
| 14350 | const args = extra.trail.next(extra.data.args_len, Value, &func); | 14397 | const args = extra.trail.next(extra.data.args_len, Value, &func); |
| ... | @@ -14367,7 +14414,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14367,7 +14414,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14367 | .@"notail call fast", | 14414 | .@"notail call fast", |
| 14368 | .@"tail call fast", | 14415 | .@"tail call fast", |
| 14369 | => |kind| { | 14416 | => |kind| { |
| 14370 | var extra = func.extraDataTrail(Function.Instruction.Call, datas[instr_index]); | 14417 | var extra = func.extraDataTrail(Function.Instruction.Call, data); |
| 14371 | | 14418 | |
| 14372 | const call_conv = extra.data.info.call_conv; | 14419 | const call_conv = extra.data.info.call_conv; |
| 14373 | const args = extra.trail.next(extra.data.args_len, Value, &func); | 14420 | const args = extra.trail.next(extra.data.args_len, Value, &func); |
| ... | @@ -14405,7 +14452,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14405,7 +14452,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14405 | .srem, | 14452 | .srem, |
| 14406 | .ashr, | 14453 | .ashr, |
| 14407 | => |kind| { | 14454 | => |kind| { |
| 14408 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); | 14455 | const extra = func.extraData(Function.Instruction.Binary, data); |
| 14409 | try function_block.writeAbbrev(FunctionBlock.Binary{ | 14456 | try function_block.writeAbbrev(FunctionBlock.Binary{ |
| 14410 | .opcode = kind.toBinaryOpcode(), | 14457 | .opcode = kind.toBinaryOpcode(), |
| 14411 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14458 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| ... | @@ -14417,7 +14464,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14417,7 +14464,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14417 | .@"lshr exact", | 14464 | .@"lshr exact", |
| 14418 | .@"ashr exact", | 14465 | .@"ashr exact", |
| 14419 | => |kind| { | 14466 | => |kind| { |
| 14420 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); | 14467 | const extra = func.extraData(Function.Instruction.Binary, data); |
| 14421 | try function_block.writeAbbrev(FunctionBlock.BinaryExact{ | 14468 | try function_block.writeAbbrev(FunctionBlock.BinaryExact{ |
| 14422 | .opcode = kind.toBinaryOpcode(), | 14469 | .opcode = kind.toBinaryOpcode(), |
| 14423 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14470 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| ... | @@ -14437,7 +14484,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14437,7 +14484,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14437 | .@"shl nuw", | 14484 | .@"shl nuw", |
| 14438 | .@"shl nuw nsw", | 14485 | .@"shl nuw nsw", |
| 14439 | => |kind| { | 14486 | => |kind| { |
| 14440 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); | 14487 | const extra = func.extraData(Function.Instruction.Binary, data); |
| 14441 | try function_block.writeAbbrev(FunctionBlock.BinaryNoWrap{ | 14488 | try function_block.writeAbbrev(FunctionBlock.BinaryNoWrap{ |
| 14442 | .opcode = kind.toBinaryOpcode(), | 14489 | .opcode = kind.toBinaryOpcode(), |
| 14443 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14490 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| ... | @@ -14468,7 +14515,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14468,7 +14515,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14468 | .@"frem fast", | 14515 | .@"frem fast", |
| 14469 | .@"fsub fast", | 14516 | .@"fsub fast", |
| 14470 | => |kind| { | 14517 | => |kind| { |
| 14471 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); | 14518 | const extra = func.extraData(Function.Instruction.Binary, data); |
| 14472 | try function_block.writeAbbrev(FunctionBlock.BinaryFast{ | 14519 | try function_block.writeAbbrev(FunctionBlock.BinaryFast{ |
| 14473 | .opcode = kind.toBinaryOpcode(), | 14520 | .opcode = kind.toBinaryOpcode(), |
| 14474 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14521 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| ... | @@ -14479,7 +14526,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14479,7 +14526,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14479 | .alloca, | 14526 | .alloca, |
| 14480 | .@"alloca inalloca", | 14527 | .@"alloca inalloca", |
| 14481 | => |kind| { | 14528 | => |kind| { |
| 14482 | const extra = func.extraData(Function.Instruction.Alloca, datas[instr_index]); | 14529 | const extra = func.extraData(Function.Instruction.Alloca, data); |
| 14483 | const alignment = extra.info.alignment.toLlvm(); | 14530 | const alignment = extra.info.alignment.toLlvm(); |
| 14484 | try function_block.writeAbbrev(FunctionBlock.Alloca{ | 14531 | try function_block.writeAbbrev(FunctionBlock.Alloca{ |
| 14485 | .inst_type = extra.type, | 14532 | .inst_type = extra.type, |
| ... | @@ -14508,7 +14555,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14508,7 +14555,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14508 | .sext, | 14555 | .sext, |
| 14509 | .zext, | 14556 | .zext, |
| 14510 | => |kind| { | 14557 | => |kind| { |
| 14511 | const extra = func.extraData(Function.Instruction.Cast, datas[instr_index]); | 14558 | const extra = func.extraData(Function.Instruction.Cast, data); |
| 14512 | try function_block.writeAbbrev(FunctionBlock.Cast{ | 14559 | try function_block.writeAbbrev(FunctionBlock.Cast{ |
| 14513 | .val = adapter.getOffsetValueIndex(extra.val), | 14560 | .val = adapter.getOffsetValueIndex(extra.val), |
| 14514 | .type_index = extra.type, | 14561 | .type_index = extra.type, |
| ... | @@ -14542,7 +14589,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14542,7 +14589,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14542 | .@"icmp ule", | 14589 | .@"icmp ule", |
| 14543 | .@"icmp ult", | 14590 | .@"icmp ult", |
| 14544 | => |kind| { | 14591 | => |kind| { |
| 14545 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); | 14592 | const extra = func.extraData(Function.Instruction.Binary, data); |
| 14546 | try function_block.writeAbbrev(FunctionBlock.Cmp{ | 14593 | try function_block.writeAbbrev(FunctionBlock.Cmp{ |
| 14547 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14594 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 14548 | .rhs = adapter.getOffsetValueIndex(extra.rhs), | 14595 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| ... | @@ -14566,7 +14613,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14566,7 +14613,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14566 | .@"fcmp fast une", | 14613 | .@"fcmp fast une", |
| 14567 | .@"fcmp fast uno", | 14614 | .@"fcmp fast uno", |
| 14568 | => |kind| { | 14615 | => |kind| { |
| 14569 | const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]); | 14616 | const extra = func.extraData(Function.Instruction.Binary, data); |
| 14570 | try function_block.writeAbbrev(FunctionBlock.CmpFast{ | 14617 | try function_block.writeAbbrev(FunctionBlock.CmpFast{ |
| 14571 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14618 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 14572 | .rhs = adapter.getOffsetValueIndex(extra.rhs), | 14619 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| ... | @@ -14575,14 +14622,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14575,14 +14622,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14575 | }); | 14622 | }); |
| 14576 | }, | 14623 | }, |
| 14577 | .fneg => try function_block.writeAbbrev(FunctionBlock.FNeg{ | 14624 | .fneg => try function_block.writeAbbrev(FunctionBlock.FNeg{ |
| 14578 | .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])), | 14625 | .val = adapter.getOffsetValueIndex(@enumFromInt(data)), |
| 14579 | }), | 14626 | }), |
| 14580 | .@"fneg fast" => try function_block.writeAbbrev(FunctionBlock.FNegFast{ | 14627 | .@"fneg fast" => try function_block.writeAbbrev(FunctionBlock.FNegFast{ |
| 14581 | .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])), | 14628 | .val = adapter.getOffsetValueIndex(@enumFromInt(data)), |
| 14582 | .fast_math = FastMath.fast, | 14629 | .fast_math = FastMath.fast, |
| 14583 | }), | 14630 | }), |
| 14584 | .extractvalue => { | 14631 | .extractvalue => { |
| 14585 | var extra = func.extraDataTrail(Function.Instruction.ExtractValue, datas[instr_index]); | 14632 | var extra = func.extraDataTrail(Function.Instruction.ExtractValue, data); |
| 14586 | const indices = extra.trail.next(extra.data.indices_len, u32, &func); | 14633 | const indices = extra.trail.next(extra.data.indices_len, u32, &func); |
| 14587 | try function_block.writeAbbrev(FunctionBlock.ExtractValue{ | 14634 | try function_block.writeAbbrev(FunctionBlock.ExtractValue{ |
| 14588 | .val = adapter.getOffsetValueIndex(extra.data.val), | 14635 | .val = adapter.getOffsetValueIndex(extra.data.val), |
| ... | @@ -14590,7 +14637,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14590,7 +14637,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14590 | }); | 14637 | }); |
| 14591 | }, | 14638 | }, |
| 14592 | .insertvalue => { | 14639 | .insertvalue => { |
| 14593 | var extra = func.extraDataTrail(Function.Instruction.InsertValue, datas[instr_index]); | 14640 | var extra = func.extraDataTrail(Function.Instruction.InsertValue, data); |
| 14594 | const indices = extra.trail.next(extra.data.indices_len, u32, &func); | 14641 | const indices = extra.trail.next(extra.data.indices_len, u32, &func); |
| 14595 | try function_block.writeAbbrev(FunctionBlock.InsertValue{ | 14642 | try function_block.writeAbbrev(FunctionBlock.InsertValue{ |
| 14596 | .val = adapter.getOffsetValueIndex(extra.data.val), | 14643 | .val = adapter.getOffsetValueIndex(extra.data.val), |
| ... | @@ -14599,14 +14646,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14599,14 +14646,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14599 | }); | 14646 | }); |
| 14600 | }, | 14647 | }, |
| 14601 | .extractelement => { | 14648 | .extractelement => { |
| 14602 | const extra = func.extraData(Function.Instruction.ExtractElement, datas[instr_index]); | 14649 | const extra = func.extraData(Function.Instruction.ExtractElement, data); |
| 14603 | try function_block.writeAbbrev(FunctionBlock.ExtractElement{ | 14650 | try function_block.writeAbbrev(FunctionBlock.ExtractElement{ |
| 14604 | .val = adapter.getOffsetValueIndex(extra.val), | 14651 | .val = adapter.getOffsetValueIndex(extra.val), |
| 14605 | .index = adapter.getOffsetValueIndex(extra.index), | 14652 | .index = adapter.getOffsetValueIndex(extra.index), |
| 14606 | }); | 14653 | }); |
| 14607 | }, | 14654 | }, |
| 14608 | .insertelement => { | 14655 | .insertelement => { |
| 14609 | const extra = func.extraData(Function.Instruction.InsertElement, datas[instr_index]); | 14656 | const extra = func.extraData(Function.Instruction.InsertElement, data); |
| 14610 | try function_block.writeAbbrev(FunctionBlock.InsertElement{ | 14657 | try function_block.writeAbbrev(FunctionBlock.InsertElement{ |
| 14611 | .val = adapter.getOffsetValueIndex(extra.val), | 14658 | .val = adapter.getOffsetValueIndex(extra.val), |
| 14612 | .elem = adapter.getOffsetValueIndex(extra.elem), | 14659 | .elem = adapter.getOffsetValueIndex(extra.elem), |
| ... | @@ -14614,7 +14661,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14614,7 +14661,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14614 | }); | 14661 | }); |
| 14615 | }, | 14662 | }, |
| 14616 | .select => { | 14663 | .select => { |
| 14617 | const extra = func.extraData(Function.Instruction.Select, datas[instr_index]); | 14664 | const extra = func.extraData(Function.Instruction.Select, data); |
| 14618 | try function_block.writeAbbrev(FunctionBlock.Select{ | 14665 | try function_block.writeAbbrev(FunctionBlock.Select{ |
| 14619 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14666 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 14620 | .rhs = adapter.getOffsetValueIndex(extra.rhs), | 14667 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| ... | @@ -14622,7 +14669,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14622,7 +14669,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14622 | }); | 14669 | }); |
| 14623 | }, | 14670 | }, |
| 14624 | .@"select fast" => { | 14671 | .@"select fast" => { |
| 14625 | const extra = func.extraData(Function.Instruction.Select, datas[instr_index]); | 14672 | const extra = func.extraData(Function.Instruction.Select, data); |
| 14626 | try function_block.writeAbbrev(FunctionBlock.SelectFast{ | 14673 | try function_block.writeAbbrev(FunctionBlock.SelectFast{ |
| 14627 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14674 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 14628 | .rhs = adapter.getOffsetValueIndex(extra.rhs), | 14675 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| ... | @@ -14631,7 +14678,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14631,7 +14678,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14631 | }); | 14678 | }); |
| 14632 | }, | 14679 | }, |
| 14633 | .shufflevector => { | 14680 | .shufflevector => { |
| 14634 | const extra = func.extraData(Function.Instruction.ShuffleVector, datas[instr_index]); | 14681 | const extra = func.extraData(Function.Instruction.ShuffleVector, data); |
| 14635 | try function_block.writeAbbrev(FunctionBlock.ShuffleVector{ | 14682 | try function_block.writeAbbrev(FunctionBlock.ShuffleVector{ |
| 14636 | .lhs = adapter.getOffsetValueIndex(extra.lhs), | 14683 | .lhs = adapter.getOffsetValueIndex(extra.lhs), |
| 14637 | .rhs = adapter.getOffsetValueIndex(extra.rhs), | 14684 | .rhs = adapter.getOffsetValueIndex(extra.rhs), |
| ... | @@ -14641,7 +14688,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14641,7 +14688,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14641 | .getelementptr, | 14688 | .getelementptr, |
| 14642 | .@"getelementptr inbounds", | 14689 | .@"getelementptr inbounds", |
| 14643 | => |kind| { | 14690 | => |kind| { |
| 14644 | var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, datas[instr_index]); | 14691 | var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, data); |
| 14645 | const indices = extra.trail.next(extra.data.indices_len, Value, &func); | 14692 | const indices = extra.trail.next(extra.data.indices_len, Value, &func); |
| 14646 | try function_block.writeAbbrevAdapted( | 14693 | try function_block.writeAbbrevAdapted( |
| 14647 | FunctionBlock.GetElementPtr{ | 14694 | FunctionBlock.GetElementPtr{ |
| ... | @@ -14654,7 +14701,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14654,7 +14701,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14654 | ); | 14701 | ); |
| 14655 | }, | 14702 | }, |
| 14656 | .load => { | 14703 | .load => { |
| 14657 | const extra = func.extraData(Function.Instruction.Load, datas[instr_index]); | 14704 | const extra = func.extraData(Function.Instruction.Load, data); |
| 14658 | try function_block.writeAbbrev(FunctionBlock.Load{ | 14705 | try function_block.writeAbbrev(FunctionBlock.Load{ |
| 14659 | .ptr = adapter.getOffsetValueIndex(extra.ptr), | 14706 | .ptr = adapter.getOffsetValueIndex(extra.ptr), |
| 14660 | .ty = extra.type, | 14707 | .ty = extra.type, |
| ... | @@ -14663,7 +14710,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14663,7 +14710,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14663 | }); | 14710 | }); |
| 14664 | }, | 14711 | }, |
| 14665 | .@"load atomic" => { | 14712 | .@"load atomic" => { |
| 14666 | const extra = func.extraData(Function.Instruction.Load, datas[instr_index]); | 14713 | const extra = func.extraData(Function.Instruction.Load, data); |
| 14667 | try function_block.writeAbbrev(FunctionBlock.LoadAtomic{ | 14714 | try function_block.writeAbbrev(FunctionBlock.LoadAtomic{ |
| 14668 | .ptr = adapter.getOffsetValueIndex(extra.ptr), | 14715 | .ptr = adapter.getOffsetValueIndex(extra.ptr), |
| 14669 | .ty = extra.type, | 14716 | .ty = extra.type, |
| ... | @@ -14674,7 +14721,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14674,7 +14721,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14674 | }); | 14721 | }); |
| 14675 | }, | 14722 | }, |
| 14676 | .store => { | 14723 | .store => { |
| 14677 | const extra = func.extraData(Function.Instruction.Store, datas[instr_index]); | 14724 | const extra = func.extraData(Function.Instruction.Store, data); |
| 14678 | try function_block.writeAbbrev(FunctionBlock.Store{ | 14725 | try function_block.writeAbbrev(FunctionBlock.Store{ |
| 14679 | .ptr = adapter.getOffsetValueIndex(extra.ptr), | 14726 | .ptr = adapter.getOffsetValueIndex(extra.ptr), |
| 14680 | .val = adapter.getOffsetValueIndex(extra.val), | 14727 | .val = adapter.getOffsetValueIndex(extra.val), |
| ... | @@ -14683,7 +14730,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14683,7 +14730,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14683 | }); | 14730 | }); |
| 14684 | }, | 14731 | }, |
| 14685 | .@"store atomic" => { | 14732 | .@"store atomic" => { |
| 14686 | const extra = func.extraData(Function.Instruction.Store, datas[instr_index]); | 14733 | const extra = func.extraData(Function.Instruction.Store, data); |
| 14687 | try function_block.writeAbbrev(FunctionBlock.StoreAtomic{ | 14734 | try function_block.writeAbbrev(FunctionBlock.StoreAtomic{ |
| 14688 | .ptr = adapter.getOffsetValueIndex(extra.ptr), | 14735 | .ptr = adapter.getOffsetValueIndex(extra.ptr), |
| 14689 | .val = adapter.getOffsetValueIndex(extra.val), | 14736 | .val = adapter.getOffsetValueIndex(extra.val), |
| ... | @@ -14695,11 +14742,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14695,11 +14742,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14695 | }, | 14742 | }, |
| 14696 | .br => { | 14743 | .br => { |
| 14697 | try function_block.writeAbbrev(FunctionBlock.BrUnconditional{ | 14744 | try function_block.writeAbbrev(FunctionBlock.BrUnconditional{ |
| 14698 | .block = datas[instr_index], | 14745 | .block = data, |
| 14699 | }); | 14746 | }); |
| 14700 | }, | 14747 | }, |
| 14701 | .br_cond => { | 14748 | .br_cond, .br_cond_nosanitize => { |
| 14702 | const extra = func.extraData(Function.Instruction.BrCond, datas[instr_index]); | 14749 | const extra = func.extraData(Function.Instruction.BrCond, data); |
| 14703 | try function_block.writeAbbrev(FunctionBlock.BrConditional{ | 14750 | try function_block.writeAbbrev(FunctionBlock.BrConditional{ |
| 14704 | .then_block = @intFromEnum(extra.then), | 14751 | .then_block = @intFromEnum(extra.then), |
| 14705 | .else_block = @intFromEnum(extra.@"else"), | 14752 | .else_block = @intFromEnum(extra.@"else"), |
| ... | @@ -14707,7 +14754,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14707,7 +14754,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14707 | }); | 14754 | }); |
| 14708 | }, | 14755 | }, |
| 14709 | .@"switch" => { | 14756 | .@"switch" => { |
| 14710 | var extra = func.extraDataTrail(Function.Instruction.Switch, datas[instr_index]); | 14757 | var extra = func.extraDataTrail(Function.Instruction.Switch, data); |
| 14711 | | 14758 | |
| 14712 | try record.ensureUnusedCapacity(self.gpa, 3 + extra.data.cases_len * 2); | 14759 | try record.ensureUnusedCapacity(self.gpa, 3 + extra.data.cases_len * 2); |
| 14713 | | 14760 | |
| ... | @@ -14730,7 +14777,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14730,7 +14777,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14730 | try function_block.writeUnabbrev(12, record.items); | 14777 | try function_block.writeUnabbrev(12, record.items); |
| 14731 | }, | 14778 | }, |
| 14732 | .va_arg => { | 14779 | .va_arg => { |
| 14733 | const extra = func.extraData(Function.Instruction.VaArg, datas[instr_index]); | 14780 | const extra = func.extraData(Function.Instruction.VaArg, data); |
| 14734 | try function_block.writeAbbrev(FunctionBlock.VaArg{ | 14781 | try function_block.writeAbbrev(FunctionBlock.VaArg{ |
| 14735 | .list_type = extra.list.typeOf(@enumFromInt(func_index), self), | 14782 | .list_type = extra.list.typeOf(@enumFromInt(func_index), self), |
| 14736 | .list = adapter.getOffsetValueIndex(extra.list), | 14783 | .list = adapter.getOffsetValueIndex(extra.list), |
| ... | @@ -14740,7 +14787,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14740,7 +14787,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14740 | .phi, | 14787 | .phi, |
| 14741 | .@"phi fast", | 14788 | .@"phi fast", |
| 14742 | => |kind| { | 14789 | => |kind| { |
| 14743 | var extra = func.extraDataTrail(Function.Instruction.Phi, datas[instr_index]); | 14790 | var extra = func.extraDataTrail(Function.Instruction.Phi, data); |
| 14744 | const vals = extra.trail.next(block_incoming_len, Value, &func); | 14791 | const vals = extra.trail.next(block_incoming_len, Value, &func); |
| 14745 | const blocks = extra.trail.next(block_incoming_len, Function.Block.Index, &func); | 14792 | const blocks = extra.trail.next(block_incoming_len, Function.Block.Index, &func); |
| 14746 | | 14793 | |
| ... | @@ -14764,11 +14811,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14764,11 +14811,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14764 | try function_block.writeUnabbrev(16, record.items); | 14811 | try function_block.writeUnabbrev(16, record.items); |
| 14765 | }, | 14812 | }, |
| 14766 | .ret => try function_block.writeAbbrev(FunctionBlock.Ret{ | 14813 | .ret => try function_block.writeAbbrev(FunctionBlock.Ret{ |
| 14767 | .val = adapter.getOffsetValueIndex(@enumFromInt(datas[instr_index])), | 14814 | .val = adapter.getOffsetValueIndex(@enumFromInt(data)), |
| 14768 | }), | 14815 | }), |
| 14769 | .@"ret void" => try function_block.writeAbbrev(FunctionBlock.RetVoid{}), | 14816 | .@"ret void" => try function_block.writeAbbrev(FunctionBlock.RetVoid{}), |
| 14770 | .atomicrmw => { | 14817 | .atomicrmw => { |
| 14771 | const extra = func.extraData(Function.Instruction.AtomicRmw, datas[instr_index]); | 14818 | const extra = func.extraData(Function.Instruction.AtomicRmw, data); |
| 14772 | try function_block.writeAbbrev(FunctionBlock.AtomicRmw{ | 14819 | try function_block.writeAbbrev(FunctionBlock.AtomicRmw{ |
| 14773 | .ptr = adapter.getOffsetValueIndex(extra.ptr), | 14820 | .ptr = adapter.getOffsetValueIndex(extra.ptr), |
| 14774 | .val = adapter.getOffsetValueIndex(extra.val), | 14821 | .val = adapter.getOffsetValueIndex(extra.val), |
| ... | @@ -14782,7 +14829,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14782,7 +14829,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14782 | .cmpxchg, | 14829 | .cmpxchg, |
| 14783 | .@"cmpxchg weak", | 14830 | .@"cmpxchg weak", |
| 14784 | => |kind| { | 14831 | => |kind| { |
| 14785 | const extra = func.extraData(Function.Instruction.CmpXchg, datas[instr_index]); | 14832 | const extra = func.extraData(Function.Instruction.CmpXchg, data); |
| 14786 | | 14833 | |
| 14787 | try function_block.writeAbbrev(FunctionBlock.CmpXchg{ | 14834 | try function_block.writeAbbrev(FunctionBlock.CmpXchg{ |
| 14788 | .ptr = adapter.getOffsetValueIndex(extra.ptr), | 14835 | .ptr = adapter.getOffsetValueIndex(extra.ptr), |
| ... | @@ -14797,7 +14844,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14797,7 +14844,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14797 | }); | 14844 | }); |
| 14798 | }, | 14845 | }, |
| 14799 | .fence => { | 14846 | .fence => { |
| 14800 | const info: MemoryAccessInfo = @bitCast(datas[instr_index]); | 14847 | const info: MemoryAccessInfo = @bitCast(data); |
| 14801 | try function_block.writeAbbrev(FunctionBlock.Fence{ | 14848 | try function_block.writeAbbrev(FunctionBlock.Fence{ |
| 14802 | .ordering = info.success_ordering, | 14849 | .ordering = info.success_ordering, |
| 14803 | .sync_scope = info.sync_scope, | 14850 | .sync_scope = info.sync_scope, |
| ... | @@ -14806,7 +14853,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14806,7 +14853,7 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14806 | } | 14853 | } |
| 14807 | | 14854 | |
| 14808 | if (!func.strip) { | 14855 | if (!func.strip) { |
| 14809 | if (func.debug_locations.get(@enumFromInt(instr_index))) |debug_location| { | 14856 | if (func.debug_locations.get(adapter.instruction_index)) |debug_location| { |
| 14810 | switch (debug_location) { | 14857 | switch (debug_location) { |
| 14811 | .no_location => has_location = false, | 14858 | .no_location => has_location = false, |
| 14812 | .location => |location| { | 14859 | .location => |location| { |
| ... | @@ -14823,8 +14870,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14823,8 +14870,6 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14823 | try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{}); | 14870 | try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{}); |
| 14824 | } | 14871 | } |
| 14825 | } | 14872 | } |
| 14826 | | | |
| 14827 | adapter.next(); | | |
| 14828 | } | 14873 | } |
| 14829 | | 14874 | |
| 14830 | // VALUE_SYMTAB | 14875 | // VALUE_SYMTAB |
| ... | @@ -14850,18 +14895,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co | ... | @@ -14850,18 +14895,34 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co |
| 14850 | } | 14895 | } |
| 14851 | | 14896 | |
| 14852 | // METADATA_ATTACHMENT_BLOCK | 14897 | // METADATA_ATTACHMENT_BLOCK |
| 14853 | if (!func.strip) blk: { | 14898 | if (!func.strip or func.any_nosanitize) { |
| 14854 | const dbg = func.global.ptrConst(self).dbg; | | |
| 14855 | | | |
| 14856 | if (dbg == .none) break :blk; | | |
| 14857 | | | |
| 14858 | const MetadataAttachmentBlock = ir.MetadataAttachmentBlock; | 14899 | const MetadataAttachmentBlock = ir.MetadataAttachmentBlock; |
| 14859 | var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false); | 14900 | var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false); |
| 14860 | | 14901 | |
| 14861 | try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentSingle{ | 14902 | if (!func.strip) blk: { |
| 14862 | .kind = ir.MetadataKind.dbg, | 14903 | const dbg = func.global.ptrConst(self).dbg; |
| 14863 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1), | 14904 | if (dbg == .none) break :blk; |
| 14864 | }); | 14905 | try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentGlobalSingle{ |
| | 14906 | .kind = .dbg, |
| | 14907 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(dbg) - 1), |
| | 14908 | }); |
| | 14909 | } |
| | 14910 | |
| | 14911 | var instr_index: u32 = 0; |
| | 14912 | for (func.instructions.items(.tag)) |instr_tag| switch (instr_tag) { |
| | 14913 | .arg, .block => {}, |
| | 14914 | .br_cond_nosanitize => { |
| | 14915 | try metadata_attach_block.writeAbbrev(MetadataAttachmentBlock.AttachmentInstructionSingle{ |
| | 14916 | .inst = instr_index, |
| | 14917 | .kind = .nosanitize, |
| | 14918 | .metadata = @enumFromInt(metadata_adapter.getMetadataIndex(.empty_tuple) - 1), |
| | 14919 | }); |
| | 14920 | instr_index += 1; |
| | 14921 | }, |
| | 14922 | else => { |
| | 14923 | instr_index += 1; |
| | 14924 | }, |
| | 14925 | }; |
| 14865 | | 14926 | |
| 14866 | try metadata_attach_block.end(); | 14927 | try metadata_attach_block.end(); |
| 14867 | } | 14928 | } |