[llvm-dev] why is llvm.stacksave() necessary?
alex via llvm-dev
llvm-dev at lists.llvm.org
Tue Jul 25 02:04:27 PDT 2017
Hi all,
the language reference for the alloca instruction states:
The ‘alloca‘ instruction allocates memory on the stack frame of the
currently executing function, to be automatically released when this
function returns to its caller.
when using come c code like
void myfunc(void){
int i=4;
double d[i];
}
the ir shows enclosing llvm.stackSave & restore constructs, enclosing
the alloca related to 'd'.
thellvm.stacksafe reference explains:
This intrinsic is used to remember the current state of the function
stack...
In practice, this pops any alloca blocks from the stack that were
allocated after the llvm.stacksave was executed.
shouldn't the alloca block related to 'd' be automatically released when
the function returns to its caller?
isn't the 'stack frame of the currently executing function'=='the
function stack'?
Can I programmatically decide when to insert calls to stacksafe/restore?
Suppose I would have a pass which sometimes would introduce such dynamic
alloca's - do I need to explicitely track this and insert
stacksave/restore? Or could I check for dynamic alloca (one ore several)
afterwards, and then introduce stacksave/restore once (enclosing the
complete function code) after the completed pass?
Thx
Alex
More information about the llvm-dev
mailing list