[Mesa-dev] [PATCH 08/12] gallivm: Separate freeing LLVM intermediate data from freeing final code.

Jose Fonseca jfonseca at vmware.com
Tue May 13 10:02:47 PDT 2014



----- Original Message -----
> Am 13.05.2014 14:01, schrieb jfonseca at vmware.com:
> > From: Frank Henigman <fjhenigman at google.com>
> > 
> > Split free_gallivm_state() into two steps.  First step is
> > gallivm_free_ir() 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.
> > 
> > v2: s/gallivm_teardown/gallivm_free_ir/ (Jose)
> > 
> > Signed-off-by: José Fonseca <jfonseca at vmware.com>
> > ---
> >  src/gallium/auxiliary/gallivm/lp_bld_init.c | 27
> >  ++++++++++++++++++++-------
> >  src/gallium/auxiliary/gallivm/lp_bld_init.h |  2 ++
> >  2 files changed, 22 insertions(+), 7 deletions(-)
> > 
> > diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c
> > b/src/gallium/auxiliary/gallivm/lp_bld_init.c
> > index 982d1db..6feec70 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_free_ir(struct gallivm_state *gallivm)
> >  {
> >     if (gallivm->passmgr) {
> >        LLVMDisposePassManager(gallivm->passmgr);
> > @@ -212,14 +213,24 @@ free_gallivm_state(struct gallivm_state *gallivm)
> >     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;
> >  }
> >  
> > @@ -366,7 +377,8 @@ init_gallivm_state(struct gallivm_state *gallivm)
> >     return TRUE;
> >  
> >  fail:
> > -   free_gallivm_state(gallivm);
> > +   gallivm_free_ir(gallivm);
> > +   gallivm_free_code(gallivm);
> >     return FALSE;
> >  }
> >  
> > @@ -497,7 +509,8 @@ gallivm_create(void)
> >  void
> >  gallivm_destroy(struct gallivm_state *gallivm)
> >  {
> > -   free_gallivm_state(gallivm);
> > +   gallivm_free_ir(gallivm);
> > +   gallivm_free_code(gallivm);
> >     FREE(gallivm);
> >  }
> >  
> > diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h
> > b/src/gallium/auxiliary/gallivm/lp_bld_init.h
> > index e405b8a..b11e986 100644
> > --- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
> > +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
> > @@ -59,6 +59,8 @@ gallivm_create(void);
> >  void
> >  gallivm_destroy(struct gallivm_state *gallivm);
> >  
> > +void
> > +gallivm_free_ir(struct gallivm_state *gallivm);
> >  
> >  void
> >  gallivm_verify_function(struct gallivm_state *gallivm,
> > 
> 
> 8-12 also look good to me, still looking at 7.

Thanks for the reviews.

> Now that we should have to keep much less memory per shader, should we
> increase the limits before we start destroying variants?

Maybe, eventually.  But that needs further investigation.

Per-shader consumption went down on master (where we have multiple modules, multiple engines), but I'm not sure it's down compared with LLVM 2.6 era (where we had 1 module, 1 engine). 

My testing focused on the maximum memory consumed by LLVM.  And the peak tended to happen more during compilations, so I don't have good values on average shader sizes.

Jose


More information about the mesa-dev mailing list