[llvm-commits] [llvm] r71717 - /llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
Dale Johannesen
dalej at apple.com
Thu May 14 11:42:34 PDT 2009
On May 14, 2009, at 12:57 AMPDT, Duncan Sands wrote:
> 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->getUnderlyingObject() does.
Sure does. Thanks, I thought that functionality must be there
somewhere. Rewritten appropriately.
>> + 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?
What other possibilities are you thinking of?
More information about the llvm-commits
mailing list