authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-01 11:53:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-01 11:53:47-07:00
logde14fba2478019ba6070407502b422d349ebf754
treeef1fa7d3bc65db85b8df3347801b8518fe9819e4
parent69323fc1432146bf166175060dea9d0248dbeba4

LLVM: convert two ArrayLists into a MultiArrayList


1 files changed, 17 insertions(+), 19 deletions(-)

src/codegen/llvm.zig+17-19
......@@ -3893,15 +3893,16 @@ pub const FuncGen = struct {
38933893 /// This data structure is used to implement breaking to blocks.
38943894 blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, struct {
38953895 parent_bb: *const llvm.BasicBlock,
3896 break_bbs: *BreakBasicBlocks,
3897 break_vals: *BreakValues,
3896 breaks: *BreakList,
38983897 }),
38993898
39003899 single_threaded: bool,
39013900
39023901 const DbgState = struct { loc: *llvm.DILocation, scope: *llvm.DIScope, base_line: u32 };
3903 const BreakBasicBlocks = std.ArrayListUnmanaged(*const llvm.BasicBlock);
3904 const BreakValues = std.ArrayListUnmanaged(*const llvm.Value);
3902 const BreakList = std.MultiArrayList(struct {
3903 bb: *const llvm.BasicBlock,
3904 val: *const llvm.Value,
3905 });
39053906
39063907 fn deinit(self: *FuncGen) void {
39073908 self.builder.dispose();
......@@ -4649,16 +4650,12 @@ pub const FuncGen = struct {
46494650 return null;
46504651 }
46514652
4652 var break_bbs: BreakBasicBlocks = .{};
4653 defer break_bbs.deinit(self.gpa);
4654
4655 var break_vals: BreakValues = .{};
4656 defer break_vals.deinit(self.gpa);
4653 var breaks: BreakList = .{};
4654 defer breaks.deinit(self.gpa);
46574655
46584656 try self.blocks.putNoClobber(self.gpa, inst, .{
46594657 .parent_bb = parent_bb,
4660 .break_bbs = &break_bbs,
4661 .break_vals = &break_vals,
4658 .breaks = &breaks,
46624659 });
46634660 defer assert(self.blocks.remove(inst));
46644661
......@@ -4667,7 +4664,7 @@ pub const FuncGen = struct {
46674664 self.llvm_func.appendExistingBasicBlock(parent_bb);
46684665 self.builder.positionBuilderAtEnd(parent_bb);
46694666
4670 // If the block does not return a value, we dont have to create a phi node.
4667 // Create a phi node only if the block returns a value.
46714668 const is_body = inst_ty.zigTypeTag() == .Fn;
46724669 if (!is_body and !inst_ty.hasRuntimeBitsIgnoreComptime()) return null;
46734670
......@@ -4686,9 +4683,9 @@ pub const FuncGen = struct {
46864683
46874684 const phi_node = self.builder.buildPhi(llvm_ty, "");
46884685 phi_node.addIncoming(
4689 break_vals.items.ptr,
4690 break_bbs.items.ptr,
4691 @intCast(c_uint, break_vals.items.len),
4686 breaks.items(.val).ptr,
4687 breaks.items(.bb).ptr,
4688 @intCast(c_uint, breaks.len),
46924689 );
46934690 return phi_node;
46944691 }
......@@ -4697,16 +4694,17 @@ pub const FuncGen = struct {
46974694 const branch = self.air.instructions.items(.data)[inst].br;
46984695 const block = self.blocks.get(branch.block_inst).?;
46994696
4700 // If the break doesn't break a value, then we don't have to add
4701 // the values to the lists.
4697 // Add the values to the lists only if the break provides a value.
47024698 const operand_ty = self.air.typeOf(branch.operand);
47034699 if (operand_ty.hasRuntimeBitsIgnoreComptime() or operand_ty.zigTypeTag() == .Fn) {
47044700 const val = try self.resolveInst(branch.operand);
47054701
47064702 // For the phi node, we need the basic blocks and the values of the
47074703 // break instructions.
4708 try block.break_bbs.append(self.gpa, self.builder.getInsertBlock());
4709 try block.break_vals.append(self.gpa, val);
4704 try block.breaks.append(self.gpa, .{
4705 .bb = self.builder.getInsertBlock(),
4706 .val = val,
4707 });
47104708 }
47114709 _ = self.builder.buildBr(block.parent_bb);
47124710 return null;