From abd37961d55680e5e946b9e336ce14b4ac56f830 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 19 Aug 2013 23:13:33 +0000 Subject: [PATCH] Introduce non-const overloads for GlobalAlias::{get,resolve}AliasedGlobal. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188725 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/GlobalAlias.h | 10 ++++++++-- lib/IR/Globals.cpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/llvm/IR/GlobalAlias.h b/include/llvm/IR/GlobalAlias.h index 883814a3237..e09fb6a4f18 100644 --- a/include/llvm/IR/GlobalAlias.h +++ b/include/llvm/IR/GlobalAlias.h @@ -66,14 +66,20 @@ public: } /// 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(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(this)->resolveAliasedGlobal(stopOnWeak); + } // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Value *V) { diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index 6d547f3edf3..da3b02a0fa6 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -229,14 +229,14 @@ 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(C)) + if (GlobalValue *GV = dyn_cast(C)) return GV; - const ConstantExpr *CE = cast(C); + ConstantExpr *CE = cast(C); assert((CE->getOpcode() == Instruction::BitCast || CE->getOpcode() == Instruction::GetElementPtr) && "Unsupported aliasee"); @@ -244,18 +244,18 @@ const GlobalValue *GlobalAlias::getAliasedGlobal() const { return cast(CE->getOperand(0)); } -const GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) const { - SmallPtrSet Visited; +GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) { + SmallPtrSet 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(GV)) { + while (GlobalAlias *GA = dyn_cast(GV)) { if (stopOnWeak && GA->mayBeOverridden()) break; -- 2.34.1