[Mesa-dev] [PATCH v3 2/3] gallivm: separate LLVM teardown from freeing code

Frank Henigman fjhenigman at google.com
Wed Nov 27 15:00:44 PST 2013


Split free_gallivm_state() into two steps.  First step is
gallivm_teardown() which cleans up the LLVM scaffolding used to generate
code while preserving the code itself.  Second step is gallivm_free_code()
to free the memory occupied by the code.
---
 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 9537a60..30f1941 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -187,10 +187,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 */
@@ -237,8 +238,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;
@@ -246,6 +245,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;
 }
 
@@ -418,7 +427,8 @@ init_gallivm_state(struct gallivm_state *gallivm)
    return TRUE;
 
 fail:
-   free_gallivm_state(gallivm);
+   gallivm_teardown(gallivm);
+   gallivm_free_code(gallivm);
    return FALSE;
 }
 
@@ -563,7 +573,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.4.1



More information about the mesa-dev mailing list