[llvm-commits] [llvm] r71717 - /llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Duncan Sands baldrick at free.fr
Thu May 14 00:57:54 PDT 2009


Hi Dale,

> +/// findGlobalVariableBase - Recurse into a ConstantExpr to find the underlying
> +/// GlobalVariable, if there is one.
> +static GlobalVariable* findGlobalVariableBase(ConstantExpr* CE) {
> +  if (isa<GlobalVariable>(CE))
> +    return dyn_cast<GlobalVariable>(CE);
> +  if (CE->getOpcode()==Instruction::GetElementPtr ||
> +      CE->getOpcode()==Instruction::BitCast) {
> +    if (isa<GlobalVariable>(CE->getOperand(0)))
> +      return dyn_cast<GlobalVariable>(CE->getOperand(0));
> +    if (ConstantExpr *CE2 = dyn_cast<ConstantExpr>(CE->getOperand(0)))
> +      return findGlobalVariableBase(CE2);
> +  }
> +  return NULL;
> +}

this looks very similar to what CE->stripPointerCasts() does.

> +        GlobalVariable* GV = dyn_cast<GlobalVariable>(I->getOperand(0));
> +        if (GV && GV->hasExternalWeakLinkage())
> +          return false;

How about adding an "address of this global value may be null" method to
GlobalValue (which would currently just check the linkage type) and use
that instead?

Ciao,

Duncan.



More information about the llvm-commits mailing list