Optimize away memory allocations?

You need to annotate your allocation and freeing functions with appropriate attributes. It should look roughly like this:

declare noalias ptr @my.malloc(i64 %size, i64 allocalign %align) allocsize(0) allockind("alloc,aligned,uninitialized") "alloc-family"="my.malloc"
declare void @my.free(ptr allocptr %ptr) allockind("free") "alloc-family"="my.malloc"

See LangRef for an explanation of these attributes.

4 Likes