----- Original Message ----- > On 05/13/2014 06:01 AM, jfons...@vmware.com wrote: > > From: José Fonseca <jfons...@vmware.com> > > > > I saw that LLVM internally uses its global context for some things, even > > when we use our own. Given ours is also global, might as well use > > LLVM's. > > > > However, sepearate contexts can still be enabled with a simple source > > code modification, for when the need/benefit arises. > > --- > > src/gallium/auxiliary/gallivm/lp_bld_init.c | 40 > > ++++++++++++----------------- > > 1 file changed, 17 insertions(+), 23 deletions(-) > > > > diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c > > b/src/gallium/auxiliary/gallivm/lp_bld_init.c > > index 6934a28..2d854e9 100644 > > --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c > > +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c > > @@ -68,6 +68,16 @@ > > void LLVMLinkInMCJIT(); > > #endif > > > > +/* > > + * LLVM has several global caches which pointing/derived from objects > > + * owned by the context, so if we freeing contexts causes > > + * memory leaks and false cache hits when these objects are destroyed. > > I can't quite parse that comment.
I tweaked the comment (was below) but indeed did a poor job. I think I'll just put the original back: "We must never free LLVM contexts, because LLVM has several global caches which pointing/derived from objects owned by the context, causing false memory leaks and false cache hits when these objects are destroyed." Jose > > + * > > + * TODO: For thread safety on multi-threaded OpenGL we should use one LLVM > > + * context per thread, and put them in a pool when threads are destroyed. > > + */ > > +#define USE_GLOBAL_CONTEXT 1 > > + > > > > #ifdef DEBUG > > unsigned gallivm_debug = 0; > > @@ -196,16 +206,12 @@ free_gallivm_state(struct gallivm_state *gallivm) > > } > > #endif > > > > - /* Never free the LLVM context. > > - */ > > -#if 0 > > - if (gallivm->context) > > - LLVMContextDispose(gallivm->context); > > -#endif > > - > > if (gallivm->builder) > > LLVMDisposeBuilder(gallivm->builder); > > > > + if (!USE_GLOBAL_CONTEXT && gallivm->context) > > + LLVMContextDispose(gallivm->context); > > + > > gallivm->engine = NULL; > > gallivm->target = NULL; > > gallivm->module = NULL; > > @@ -277,19 +283,6 @@ fail: > > > > > > /** > > - * Singleton > > - * > > - * We must never free LLVM contexts, because LLVM has several global > > caches > > - * which pointing/derived from objects owned by the context, causing false > > - * memory leaks and false cache hits when these objects are destroyed. > > - * > > - * TODO: For thread safety on multi-threaded OpenGL we should use one LLVM > > - * context per thread, and put them in a pool when threads are destroyed. > > - */ > > -static LLVMContextRef gallivm_context = NULL; > > - > > - > > -/** > > * Allocate gallivm LLVM objects. > > * \return TRUE for success, FALSE for failure > > */ > > @@ -301,10 +294,11 @@ init_gallivm_state(struct gallivm_state *gallivm) > > > > lp_build_init(); > > > > - if (!gallivm_context) { > > - gallivm_context = LLVMContextCreate(); > > + if (USE_GLOBAL_CONTEXT) { > > + gallivm->context = LLVMGetGlobalContext(); > > + } else { > > + gallivm->context = LLVMContextCreate(); > > } > > - gallivm->context = gallivm_context; > > if (!gallivm->context) > > goto fail; > > > > > > _______________________________________________ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/mesa-dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=NMr9uy2iTjWVixC0wOcYCWEIYhfo80qKwRgdodpoDzA%3D%0A&m=kRO9KvwmjrXoEWeoBbmyfPh66F8KIgozbcuTmRLaxB0%3D%0A&s=4f4a6fcf6d37e893fa7ff739d30cb01db6842f68809634cfd1eda122f5404071 > _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev