1 //===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the GlobalAlias class, which
11 // represents a single function or variable alias in the IR.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_GLOBAL_ALIAS_H
16 #define LLVM_GLOBAL_ALIAS_H
18 #include "llvm/GlobalValue.h"
25 template<typename ValueSubClass, typename ItemParentClass>
26 class SymbolTableListTraits;
28 class GlobalAlias : public GlobalValue {
29 friend class SymbolTableListTraits<GlobalAlias, Module>;
30 void operator=(const GlobalAlias &); // Do not implement
31 GlobalAlias(const GlobalAlias &); // Do not implement
33 void setParent(Module *parent);
35 GlobalAlias *Prev, *Next;
36 void setNext(GlobalAlias *N) { Next = N; }
37 void setPrev(GlobalAlias *N) { Prev = N; }
39 // getNext/Prev - Return the next or previous alias in the list.
40 GlobalAlias *getNext() { return Next; }
41 const GlobalAlias *getNext() const { return Next; }
42 GlobalAlias *getPrev() { return Prev; }
43 const GlobalAlias *getPrev() const { return Prev; }
47 // allocate space for exactly zero operands
48 void *operator new(size_t s) {
49 return User::operator new(s, 0);
51 /// GlobalAlias ctor - If a parent module is specified, the alias is
52 /// automatically inserted into the end of the specified module's alias list.
53 GlobalAlias(const Type *Ty, LinkageTypes Linkage, const std::string &Name = "",
54 Constant* Aliasee = 0, Module *Parent = 0);
56 /// isDeclaration - Is this global variable lacking an initializer? If so,
57 /// the global variable is defined in some other translation unit, and is thus
58 /// only a declaration here.
59 virtual bool isDeclaration() const;
61 /// removeFromParent - This method unlinks 'this' from the containing module,
62 /// but does not delete it.
64 void removeFromParent();
66 /// eraseFromParent - This method unlinks 'this' from the containing module
69 void eraseFromParent();
71 virtual void print(std::ostream &OS) const;
72 void print(std::ostream *OS) const { if (OS) print(*OS); }
74 /// set/getAliasee - These methods retrive and set alias target.
75 void setAliasee(Constant* GV);
76 const Constant* getAliasee() const {
77 return cast_or_null<Constant>(getOperand(0));
79 Constant* getAliasee() {
80 return cast_or_null<Constant>(getOperand(0));
82 /// getAliasedGlobal() - Aliasee can be either global or bitcast of
83 /// global. This method retrives the global for both aliasee flavours.
84 const GlobalValue* getAliasedGlobal() const;
86 /// resolveAliasedGlobal() - This method tries to ultimately resolve the alias
87 /// by going through the aliasing chain and trying to find the very last
88 /// global. Returns NULL if a cycle was found.
89 const GlobalValue* resolveAliasedGlobal() const;
91 // Methods for support type inquiry through isa, cast, and dyn_cast:
92 static inline bool classof(const GlobalAlias *) { return true; }
93 static inline bool classof(const Value *V) {
94 return V->getValueID() == Value::GlobalAliasVal;
98 } // End llvm namespace