[llvm-dev] why is llvm.stacksave() necessary?

alex via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 25 09:26:15 PDT 2017


> Unless your source language permits flow control, in which case you must insert the stack restore in the block that unifies flow control at the end of the scope.  Consider this example:
> 
> void myfunc(void)
> {
> 	for (int i=0 ; i<4; i++)
> 	{
> 		double d[i];
> 		if (i % 2)
> 			doSomethingWith(d);
> 		else
> 			doSomethingElseWith(d);
> 	}
> }
> 
> The IR that clang generates for this is quite hard to read, but the key point is that the stack save and stack restore are in different basic blocks.  
> 
> David

Another good example, thanks.
I had a look at the ll and found that the restore is in the if.end block.
I think it could also go into the for.inc block (just before jumping
back to cond).

Is there any way (from AST in C++) to easily identify 'the block that
unifies flow control at the end of the scope'? does it have any special
attribute one could search for?

Alex



More information about the llvm-dev mailing list