llvm.lifetime.start; what does it do exactly?

Esentially, I’m working on a translator someone started building for llvm2.9 that translates an optimized .lln file to another intermediate language, and I’m porting it to 3.1.

There is a new intrinsic that pops up in our test cases’ lln files that never used to, llvm.lifetime.start. I looked up the description: “The ‘llvm.lifetime.start’ intrinsic specifies the start of a memory object’s lifetime.” However, it’s still not clear to me what exactly i should do; should this actually be translated to anything (like a call to malloc or something), or is it just used to keep information about the memory object?

Dear Ryan,

I think the lifetime works more like a hint for certain optimizations. For example, if inliner pass sees two variables with non-untersecting lifetimes, it may decide to make them to share the same chunk of stack space (alloca). So, it would not be any error, if you completely ignore it.

  • D.

2012/7/13 ryan baird <ryanrbaird@gmail.com>

Hi Ryan,

Esentially, I'm working on a translator someone started building for llvm2.9
that translates an optimized .lln file to another intermediate language, and I'm
porting it to 3.1.

There is a new intrinsic that pops up in our test cases' lln files that never
used to, llvm.lifetime.start. I looked up the description: "The
'llvm.lifetime.start' intrinsic specifies the start of a memory object's
lifetime." However, it's still not clear to me what exactly i should do;
  should this actually be translated to anything (like a call to malloc or
something), or is it just used to keep information about the memory object?

you can safely ignore it. The basic use case is this: function A calls function
B, and the optimizers inline the call. Local variables of (the inlined) B now
get a declaration at the start of A, but they are only actually used in the
inlined B code, not before nor after. Adding a lifetime.start just before the
inlined code, and a lifetime.end just after, explains this to the optimizers
and code generators, which makes it easier for them to exploit this information.

Ciao, Duncan.