[PATCH] A new HeapToStack allocation promotion pass

Stephen Checkoway s at pahtak.org
Sat Oct 5 13:37:44 PDT 2013


On Oct 5, 2013, at 4:30 PM, Hal Finkel <hfinkel at anl.gov> wrote:

> 
> ----- Stephen Checkoway <s at pahtak.org> wrote:
>> 
>> In addition to not working with standard library functions that except things in the heap (malloc_usable_size, mallinfo) as I mentioned previously, it also doesn't work if the allocated memory escapes via exceptions (I think someone else mentioned that previously).
> 
> Yep, Nick also pointed this out; thanks for confirming!

No problem. Here's one with longjmp().

#include <setjmp.h>
#include <stdlib.h>

static void *q;
static jmp_buf env;

static __attribute__((noinline)) void bar(int a)
{
  if (a > 1)
    longjmp(env, 1);
}
static __attribute__((noinline)) void foo(int a)
{
  void *p = malloc(10);
  q = p;
  bar(a);
  free(p);
}

int main(int argc, char *argv[])
{
  if (!setjmp(env))
    foo(argc);
  if (argc > 1)
    free(q);
}

> I'll work up a more conservative version and post it soon.


Great! This seems like a useful optimization.

-- 
Stephen Checkoway









More information about the llvm-commits mailing list