| ... | ... | @@ -448,8 +448,6 @@ pub const Object = struct { |
| 448 | 448 | .args = args.toOwnedSlice(), |
| 449 | 449 | .arg_index = 0, |
| 450 | 450 | .func_inst_table = .{}, |
| 451 | | .entry_block = entry_block, |
| 452 | | .latest_alloca_inst = null, |
| 453 | 451 | .llvm_func = llvm_func, |
| 454 | 452 | .blocks = .{}, |
| 455 | 453 | .single_threaded = module.comp.bin_file.options.single_threaded, |
| ... | ... | @@ -1285,11 +1283,6 @@ pub const FuncGen = struct { |
| 1285 | 1283 | args: []*const llvm.Value, |
| 1286 | 1284 | arg_index: usize, |
| 1287 | 1285 | |
| 1288 | | entry_block: *const llvm.BasicBlock, |
| 1289 | | /// This fields stores the last alloca instruction, such that we can append |
| 1290 | | /// more alloca instructions to the top of the function. |
| 1291 | | latest_alloca_inst: ?*const llvm.Value, |
| 1292 | | |
| 1293 | 1286 | llvm_func: *const llvm.Value, |
| 1294 | 1287 | |
| 1295 | 1288 | /// This data structure is used to implement breaking to blocks. |
| ... | ... | @@ -2658,26 +2651,19 @@ pub const FuncGen = struct { |
| 2658 | 2651 | |
| 2659 | 2652 | /// Use this instead of builder.buildAlloca, because this function makes sure to |
| 2660 | 2653 | /// put the alloca instruction at the top of the function! |
| 2661 | | fn buildAlloca(self: *FuncGen, t: *const llvm.Type) *const llvm.Value { |
| 2654 | fn buildAlloca(self: *FuncGen, llvm_ty: *const llvm.Type) *const llvm.Value { |
| 2662 | 2655 | const prev_block = self.builder.getInsertBlock(); |
| 2663 | | defer self.builder.positionBuilderAtEnd(prev_block); |
| 2664 | 2656 | |
| 2665 | | if (self.latest_alloca_inst) |latest_alloc| { |
| 2666 | | // builder.positionBuilder adds it before the instruction, |
| 2667 | | // but we want to put it after the last alloca instruction. |
| 2668 | | self.builder.positionBuilder(self.entry_block, latest_alloc.getNextInstruction().?); |
| 2657 | const entry_block = self.llvm_func.getFirstBasicBlock().?; |
| 2658 | if (entry_block.getFirstInstruction()) |first_inst| { |
| 2659 | self.builder.positionBuilder(entry_block, first_inst); |
| 2669 | 2660 | } else { |
| 2670 | | // There might have been other instructions emitted before the |
| 2671 | | // first alloca has been generated. However the alloca should still |
| 2672 | | // be first in the function. |
| 2673 | | if (self.entry_block.getFirstInstruction()) |first_inst| { |
| 2674 | | self.builder.positionBuilder(self.entry_block, first_inst); |
| 2675 | | } |
| 2661 | self.builder.positionBuilderAtEnd(entry_block); |
| 2676 | 2662 | } |
| 2677 | 2663 | |
| 2678 | | const val = self.builder.buildAlloca(t, ""); |
| 2679 | | self.latest_alloca_inst = val; |
| 2680 | | return val; |
| 2664 | const alloca = self.builder.buildAlloca(llvm_ty, ""); |
| 2665 | self.builder.positionBuilderAtEnd(prev_block); |
| 2666 | return alloca; |
| 2681 | 2667 | } |
| 2682 | 2668 | |
| 2683 | 2669 | fn airStore(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { |