mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-23 14:25:07 +00:00
Add helper for ultimate aliasee resoltion
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48255 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -79,6 +79,11 @@ public:
|
|||||||
/// global. This method retrives the global for both aliasee flavours.
|
/// global. This method retrives the global for both aliasee flavours.
|
||||||
const GlobalValue* getAliasedGlobal() const;
|
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:
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
static inline bool classof(const GlobalAlias *) { return true; }
|
static inline bool classof(const GlobalAlias *) { return true; }
|
||||||
static inline bool classof(const Value *V) {
|
static inline bool classof(const Value *V) {
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include "llvm/GlobalAlias.h"
|
#include "llvm/GlobalAlias.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/Support/LeakDetector.h"
|
#include "llvm/Support/LeakDetector.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@@ -230,3 +231,18 @@ const GlobalValue *GlobalAlias::getAliasedGlobal() const {
|
|||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user