[Mesa-dev] [PATCH 2/3] gallivm: separate LLVM teardown from freeing code
Frank Henigman
fjhenigman at google.com
Fri Jun 14 12:08:19 PDT 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 11d69d9..00cfe7f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -186,10 +186,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 */
@@ -236,8 +237,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;
@@ -245,6 +244,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;
}
@@ -555,7 +565,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.3
More information about the mesa-dev
mailing list