Skip to content

Commit

Permalink
Introduce non-const overloads for GlobalAlias::{get,resolve}AliasedGl…
Browse files Browse the repository at this point in the history
…obal.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188725 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
pcc committed Aug 19, 2013
1 parent c2d722e commit abd3796
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 8 additions & 2 deletions include/llvm/IR/GlobalAlias.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
}
/// getAliasedGlobal() - Aliasee can be either global or bitcast of
/// global. This method retrives the global for both aliasee flavours.
const GlobalValue *getAliasedGlobal() const;
GlobalValue *getAliasedGlobal();
const GlobalValue *getAliasedGlobal() const {
return const_cast<GlobalAlias *>(this)->getAliasedGlobal();
}

/// resolveAliasedGlobal() - This method tries to ultimately resolve the alias
/// by going through the aliasing chain and trying to find the very last
/// global. Returns NULL if a cycle was found. If stopOnWeak is false, then
/// the whole chain aliasing chain is traversed, otherwise - only strong
/// aliases.
const GlobalValue *resolveAliasedGlobal(bool stopOnWeak = true) const;
GlobalValue *resolveAliasedGlobal(bool stopOnWeak = true);
const GlobalValue *resolveAliasedGlobal(bool stopOnWeak = true) const {
return const_cast<GlobalAlias *>(this)->resolveAliasedGlobal(stopOnWeak);
}

// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Value *V) {
Expand Down
16 changes: 8 additions & 8 deletions lib/IR/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,33 +229,33 @@ void GlobalAlias::setAliasee(Constant *Aliasee) {
setOperand(0, Aliasee);
}

const GlobalValue *GlobalAlias::getAliasedGlobal() const {
const Constant *C = getAliasee();
GlobalValue *GlobalAlias::getAliasedGlobal() {
Constant *C = getAliasee();
if (C == 0) return 0;

if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
return GV;

const ConstantExpr *CE = cast<ConstantExpr>(C);
ConstantExpr *CE = cast<ConstantExpr>(C);
assert((CE->getOpcode() == Instruction::BitCast ||
CE->getOpcode() == Instruction::GetElementPtr) &&
"Unsupported aliasee");

return cast<GlobalValue>(CE->getOperand(0));
}

const GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) const {
SmallPtrSet<const GlobalValue*, 3> Visited;
GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) {
SmallPtrSet<GlobalValue*, 3> Visited;

// Check if we need to stop early.
if (stopOnWeak && mayBeOverridden())
return this;

const GlobalValue *GV = getAliasedGlobal();
GlobalValue *GV = getAliasedGlobal();
Visited.insert(GV);

// Iterate over aliasing chain, stopping on weak alias if necessary.
while (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) {
while (GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) {
if (stopOnWeak && GA->mayBeOverridden())
break;

Expand Down

0 comments on commit abd3796

Please sign in to comment.