Skip to content

Commit f708c87

Browse files
committed
Introduce non-const overloads for GlobalAlias::{get,resolve}AliasedGlobal.
llvm-svn: 188725
1 parent 53e2f27 commit f708c87

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

llvm/include/llvm/IR/GlobalAlias.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,20 @@ class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
6666
}
6767
/// getAliasedGlobal() - Aliasee can be either global or bitcast of
6868
/// global. This method retrives the global for both aliasee flavours.
69-
const GlobalValue *getAliasedGlobal() const;
69+
GlobalValue *getAliasedGlobal();
70+
const GlobalValue *getAliasedGlobal() const {
71+
return const_cast<GlobalAlias *>(this)->getAliasedGlobal();
72+
}
7073

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

7884
// Methods for support type inquiry through isa, cast, and dyn_cast:
7985
static inline bool classof(const Value *V) {

llvm/lib/IR/Globals.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,33 +229,33 @@ void GlobalAlias::setAliasee(Constant *Aliasee) {
229229
setOperand(0, Aliasee);
230230
}
231231

232-
const GlobalValue *GlobalAlias::getAliasedGlobal() const {
233-
const Constant *C = getAliasee();
232+
GlobalValue *GlobalAlias::getAliasedGlobal() {
233+
Constant *C = getAliasee();
234234
if (C == 0) return 0;
235235

236-
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
236+
if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
237237
return GV;
238238

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

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

247-
const GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) const {
248-
SmallPtrSet<const GlobalValue*, 3> Visited;
247+
GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) {
248+
SmallPtrSet<GlobalValue*, 3> Visited;
249249

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

254-
const GlobalValue *GV = getAliasedGlobal();
254+
GlobalValue *GV = getAliasedGlobal();
255255
Visited.insert(GV);
256256

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

0 commit comments

Comments
 (0)