This is the mail archive of the
mailing list for the GCC project.
Re: Avoid calls to realloc for nvptx
- From: Jakub Jelinek <jakub at redhat dot com>
- To: FX <fxcoudert at gmail dot com>
- Cc: Bernd Schmidt <bernds at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Wed, 22 Oct 2014 10:04:48 +0200
- Subject: Re: Avoid calls to realloc for nvptx
- Authentication-results: sourceware.org; auth=none
- References: <5446D752 dot 9010405 at codesourcery dot com> <C6BA9188-026E-46B4-9BA4-DA9856CB35C8 at gmail dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Oct 22, 2014 at 09:45:29AM +0200, FX wrote:
> Iâm afraid I donât understand the reasoning here:
> > Since malloc and free are magically provided by the ptx environment, but realloc is missing, it's nontrivial to provide an implementation for it. The Fortran frontend likes to generate calls to realloc, but in one case it seems like we can compute the old size, and call a function that does malloc/memcpy/free instead.
> Does "nontrivial to provideâ mean that you donât provide a realloc() implementation in libc or libgcc? If so, Iâm afraid the Fortran compiler will be terminally broken, and fixing just one of the use cases is not sufficient.
Yeah, I wonder why can't you just wrap the PTX "malloc"/"free" by allocating
small header in front of the allocated area where your wrapping
implementation will deal with everything you need (remember the size of the
allocation, so realloc can work, or if PTX malloc doesn't support alignment,
also bias so that you can support aligned_alloc or posix_memalign).
As an optimization, if the compiler could prove that certain allocations are
never realloced, never need aligned memory etc., you could optimize it to
avoid the wrappers and use PTX "malloc"/"free" directly.