| From fdd4bc34f42474108f520fd0cd34a81dd26bf070 Mon Sep 17 00:00:00 2001 |
| From: Frank Henigman <fjhenigman@chromium.org> |
| Date: Mon, 11 Mar 2013 17:00:12 -0400 |
| Subject: [PATCH 2/6] gallivm: separate LLVM teardown from freeing code |
| |
| With LLVM >= 3.1 it is now possible to tear down the LLVM scaffolding |
| used to generate code while preserving the code itself, thus freeing |
| up memory. |
| Add gallivm_teardown() to clean up LLVM except generated code and |
| gallivm_free_code() to free the code. They should be called in that |
| order. |
| With older LLVM teardown does both things and free_code does nothing. |
| --- |
| src/gallium/auxiliary/gallivm/lp_bld_init.c | 25 ++++++++++++++++++------- |
| src/gallium/auxiliary/gallivm/lp_bld_init.h | 5 +++++ |
| 2 files changed, 23 insertions(+), 7 deletions(-) |
| |
| diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c |
| index b4a4340..ed328d1 100644 |
| --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c |
| +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c |
| @@ -182,10 +182,11 @@ create_pass_manager(struct gallivm_state *gallivm) |
| |
| |
| /** |
| - * Free gallivm object's LLVM allocations, but not the gallivm object itself. |
| + * Free gallivm object's LLVM allocations, but not any generated code |
| + * nor the gallivm object itself. |
| */ |
| -static void |
| -free_gallivm_state(struct gallivm_state *gallivm) |
| +void |
| +gallivm_teardown(struct gallivm_state *gallivm) |
| { |
| #if HAVE_LLVM >= 0x207 /* XXX or 0x208? */ |
| /* This leads to crashes w/ some versions of LLVM */ |
| @@ -232,8 +233,6 @@ free_gallivm_state(struct gallivm_state *gallivm) |
| if (gallivm->builder) |
| LLVMDisposeBuilder(gallivm->builder); |
| |
| - lp_free_generated_code(gallivm->code); |
| - |
| gallivm->engine = NULL; |
| gallivm->target = NULL; |
| gallivm->module = NULL; |
| @@ -241,6 +240,16 @@ free_gallivm_state(struct gallivm_state *gallivm) |
| gallivm->passmgr = NULL; |
| gallivm->context = NULL; |
| gallivm->builder = NULL; |
| +} |
| + |
| + |
| +/** |
| + * Free LLVM-generated code. Should be done AFTER gallivm_teardown(). |
| + */ |
| +void |
| +gallivm_free_code(struct gallivm_state *gallivm) |
| +{ |
| + lp_free_generated_code(gallivm->code); |
| gallivm->code = NULL; |
| } |
| |
| @@ -417,7 +426,8 @@ init_gallivm_state(struct gallivm_state *gallivm) |
| return TRUE; |
| |
| fail: |
| - free_gallivm_state(gallivm); |
| + gallivm_teardown(gallivm); |
| + gallivm_free_code(gallivm); |
| return FALSE; |
| } |
| |
| @@ -545,7 +555,8 @@ gallivm_destroy(struct gallivm_state *gallivm) |
| /* No-op: don't destroy the singleton */ |
| (void) gallivm; |
| #else |
| - free_gallivm_state(gallivm); |
| + gallivm_teardown(gallivm); |
| + gallivm_free_code(gallivm); |
| FREE(gallivm); |
| #endif |
| } |
| diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h |
| index 1e78d05..129e7a9 100644 |
| --- a/src/gallium/auxiliary/gallivm/lp_bld_init.h |
| +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h |
| @@ -60,6 +60,11 @@ gallivm_create(void); |
| void |
| gallivm_destroy(struct gallivm_state *gallivm); |
| |
| +void |
| +gallivm_teardown(struct gallivm_state *gallivm); |
| + |
| +void |
| +gallivm_free_code(struct gallivm_state *gallivm); |
| |
| void |
| gallivm_verify_function(struct gallivm_state *gallivm, |
| -- |
| 1.8.1.3 |
| |