[LLVMdev] Localizing Globals ?

Sanjiv Gupta sanjiv.gupta at microchip.com
Tue Jun 16 02:35:18 PDT 2009


The code excerpt is from 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 (!GS.HasMultipleAccessingFunctions &&
        GS.AccessingFunction && !GS.HasNonInstructionUser &&
        GV->getType()->getElementType()->isSingleValueType() &&
        GS.AccessingFunction->getName() == "main" &&
        GS.AccessingFunction->hasExternalLinkage()) {
      DOUT << "LOCALIZING GLOBAL: " << *GV;

What if my global variable was into a different address space than stack?
How do I deny this optimization in that case? Can I find address space 
for stack from AllocaInst and then compare the address spaces for two?

- Sanjiv




More information about the llvm-dev mailing list