[llvm-commits] [llvm] r48255 - in /llvm/trunk: include/llvm/GlobalAlias.h lib/VMCore/Globals.cpp
Anton Korobeynikov
asl at math.spbu.ru
Tue Mar 11 15:28:56 PDT 2008
Author: asl
Date: Tue Mar 11 17:28:56 2008
New Revision: 48255
URL: http://llvm.org/viewvc/llvm-project?rev=48255&view=rev
Log:
Add helper for ultimate aliasee resoltion
Modified:
llvm/trunk/include/llvm/GlobalAlias.h
llvm/trunk/lib/VMCore/Globals.cpp
Modified: llvm/trunk/include/llvm/GlobalAlias.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalAlias.h?rev=48255&r1=48254&r2=48255&view=diff
==============================================================================
--- llvm/trunk/include/llvm/GlobalAlias.h (original)
+++ llvm/trunk/include/llvm/GlobalAlias.h Tue Mar 11 17:28:56 2008
@@ -78,7 +78,12 @@
/// getAliasedGlobal() - Aliasee can be either global or bitcast of
/// global. This method retrives the global for both aliasee flavours.
const GlobalValue* getAliasedGlobal() const;
-
+
+ /// resolveAliasedGlobal() - This method tries to ultimately resolve alias by
+ /// going through aliasing chain and trying to find the very last
+ /// global. Return NULL is cycle was found.
+ const GlobalValue* resolveAliasedGlobal() const;
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const GlobalAlias *) { return true; }
static inline bool classof(const Value *V) {
Modified: llvm/trunk/lib/VMCore/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Globals.cpp?rev=48255&r1=48254&r2=48255&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Globals.cpp (original)
+++ llvm/trunk/lib/VMCore/Globals.cpp Tue Mar 11 17:28:56 2008
@@ -17,6 +17,7 @@
#include "llvm/GlobalAlias.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/LeakDetector.h"
using namespace llvm;
@@ -230,3 +231,18 @@
return 0;
}
+const GlobalValue *GlobalAlias::resolveAliasedGlobal() const {
+ SmallPtrSet<const GlobalValue*, 1> Visited;
+
+ const GlobalValue *GV = getAliasedGlobal();
+ Visited.insert(GV);
+
+ while (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) {
+ GV = GA->getAliasedGlobal();
+
+ if (!Visited.insert(GV))
+ return NULL;
+ }
+
+ return GV;
+}
More information about the llvm-commits
mailing list