[LLVMdev] global optimizer precision
Gordon Haak
gordon.haak at googlemail.com
Thu Oct 28 05:54:02 PDT 2010
Hi all,
I had a look at the interprocedural optimizer. In my opinion the
routine 'GlobalOpt::ProcessInternalGlobal' is a little bit to
conservative. It removes global variables if the only routine using
this variable is main. Typically this condition is valid only for very
few global variables.
Here is a code snippet containing the test before the transformation:
file: llvm\lib\Transforms\IPO\GlobalOpt.cpp
// If this is a first class global and has only one accessing function
// and this function is main (which we know is not recursive we can make
// this global a local variable) we replace the global with a local alloca
// in this function.
//
// NOTE: It doesn't make sense to promote non single-value types since we
// are just replacing static memory to stack memory.
//
// If the global is in different address space, don't bring it to stack.
if (!GS.HasMultipleAccessingFunctions &&
GS.AccessingFunction && !GS.HasNonInstructionUser &&
GV->getType()->getElementType()->isSingleValueType() &&
GS.AccessingFunction->getName() == "main" &&
GS.AccessingFunction->hasExternalLinkage() &&
GV->getType()->getAddressSpace() == 0) {
The comment above the test states the reason for the check for main
which is: main is not recursive.
My proposal is to introduce a routine to check if a function is
recursiv (returning false, only if its not recursiv for
sure). Than one can replace the check for main with the call to the
'isrecursiv'-Function. The implemention of 'isrecursiv' can first
check for main and later improve the precision by inspecting the call
graph. This finally would lead to a more aggressiv interprocedural
optimizer.
Whats your opinion?
kind regards,
Gordon Haak
More information about the llvm-dev
mailing list