diff options
| author | Michael Dusan <michael.dusan@gmail.com> | 2020-02-20 02:45:58 -0500 |
|---|---|---|
| committer | Michael Dusan <michael.dusan@gmail.com> | 2020-02-20 21:05:37 -0500 |
| commit | 770631cc79a655bc5e21184ca15bdb6192e905de (patch) | |
| tree | 9d9952d5e25df9891217a99f2d0f9aff2ef14caf /src/ir.cpp | |
| parent | e381a42de9c0f0c5439a926b0ac99026a0373f49 (diff) | |
| download | zig-770631cc79a655bc5e21184ca15bdb6192e905de.tar.gz zig-770631cc79a655bc5e21184ca15bdb6192e905de.zip | |
stage1: free more heap after analysis
- immediately free dangling IrInstGenConst after analysis
- fixup mem::List params `&Allocator` → `*Allocator`
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 5f50586f72..aa46b37d4f 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -14,6 +14,7 @@ #include "range_set.hpp" #include "softfloat.hpp" #include "util.hpp" +#include "mem_list.hpp" #include <errno.h> @@ -28,6 +29,9 @@ struct IrBuilderGen { CodeGen *codegen; IrExecutableGen *exec; IrBasicBlockGen *current_basic_block; + + // track for immediate post-analysis destruction + mem::List<IrInstGenConst *> constants; }; struct IrAnalyze { @@ -741,6 +745,10 @@ static void ira_ref(IrAnalyze *ira) { static void ira_deref(IrAnalyze *ira) { if (ira->ref_count > 1) { ira->ref_count -= 1; + + // immediate destruction of dangling IrInstGenConst is not possible + // free tracking memory because it will never be used + ira->new_irb.constants.deinit(&heap::c_allocator); return; } assert(ira->ref_count != 0); @@ -758,6 +766,15 @@ static void ira_deref(IrAnalyze *ira) { heap::c_allocator.destroy(ira->old_irb.exec); ira->src_implicit_return_type_list.deinit(); ira->resume_stack.deinit(); + + // destroy dangling IrInstGenConst + for (size_t i = 0; i < ira->new_irb.constants.length; i += 1) { + auto constant = ira->new_irb.constants.items[i]; + if (constant->base.base.ref_count == 0 && !ir_inst_gen_has_side_effects(&constant->base)) + destroy_instruction_gen(&constant->base); + } + ira->new_irb.constants.deinit(&heap::c_allocator); + heap::c_allocator.destroy(ira); } @@ -12746,12 +12763,14 @@ static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) { IrInstGen *new_instruction = &const_instruction->base; new_instruction->value->type = ty; new_instruction->value->special = ConstValSpecialStatic; + ira->new_irb.constants.append(&heap::c_allocator, const_instruction); return new_instruction; } static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) { IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb, old_instruction->scope, old_instruction->source_node); + ira->new_irb.constants.append(&heap::c_allocator, const_instruction); return &const_instruction->base; } |
