/**
- * 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_free_ir(struct gallivm_state *gallivm)
{
if (gallivm->passmgr) {
LLVMDisposePassManager(gallivm->passmgr);
if (!USE_GLOBAL_CONTEXT && gallivm->context)
LLVMContextDispose(gallivm->context);
- lp_free_generated_code(gallivm->code);
-
gallivm->engine = NULL;
gallivm->target = NULL;
gallivm->module = NULL;
gallivm->passmgr = NULL;
gallivm->context = NULL;
gallivm->builder = NULL;
+}
+
+
+/**
+ * Free LLVM-generated code. Should be done AFTER gallivm_free_ir().
+ */
+static void
+gallivm_free_code(struct gallivm_state *gallivm)
+{
+ assert(!gallivm->module);
+ assert(!gallivm->engine);
+ lp_free_generated_code(gallivm->code);
gallivm->code = NULL;
}
return TRUE;
fail:
- free_gallivm_state(gallivm);
+ gallivm_free_ir(gallivm);
+ gallivm_free_code(gallivm);
return FALSE;
}
void
gallivm_destroy(struct gallivm_state *gallivm)
{
- free_gallivm_state(gallivm);
+ gallivm_free_ir(gallivm);
+ gallivm_free_code(gallivm);
FREE(gallivm);
}