1249259Sdim//===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===// 2249259Sdim// 3249259Sdim// The LLVM Compiler Infrastructure 4249259Sdim// 5249259Sdim// This file is distributed under the University of Illinois Open Source 6249259Sdim// License. See LICENSE.TXT for details. 7249259Sdim// 8249259Sdim//===----------------------------------------------------------------------===// 9249259Sdim// 10249259Sdim// This file contains the declaration of the GlobalAlias class, which 11249259Sdim// represents a single function or variable alias in the IR. 12249259Sdim// 13249259Sdim//===----------------------------------------------------------------------===// 14249259Sdim 15249259Sdim#ifndef LLVM_IR_GLOBALALIAS_H 16249259Sdim#define LLVM_IR_GLOBALALIAS_H 17249259Sdim 18249259Sdim#include "llvm/ADT/Twine.h" 19249259Sdim#include "llvm/ADT/ilist_node.h" 20249259Sdim#include "llvm/IR/GlobalValue.h" 21249259Sdim#include "llvm/IR/OperandTraits.h" 22249259Sdim 23249259Sdimnamespace llvm { 24249259Sdim 25249259Sdimclass Module; 26249259Sdimtemplate<typename ValueSubClass, typename ItemParentClass> 27249259Sdim class SymbolTableListTraits; 28249259Sdim 29249259Sdimclass GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> { 30249259Sdim friend class SymbolTableListTraits<GlobalAlias, Module>; 31249259Sdim void operator=(const GlobalAlias &) LLVM_DELETED_FUNCTION; 32249259Sdim GlobalAlias(const GlobalAlias &) LLVM_DELETED_FUNCTION; 33249259Sdim 34249259Sdim void setParent(Module *parent); 35249259Sdim 36249259Sdimpublic: 37249259Sdim // allocate space for exactly one operand 38249259Sdim void *operator new(size_t s) { 39249259Sdim return User::operator new(s, 1); 40249259Sdim } 41249259Sdim /// GlobalAlias ctor - If a parent module is specified, the alias is 42249259Sdim /// automatically inserted into the end of the specified module's alias list. 43249259Sdim GlobalAlias(Type *Ty, LinkageTypes Linkage, const Twine &Name = "", 44249259Sdim Constant* Aliasee = 0, Module *Parent = 0); 45249259Sdim 46249259Sdim /// Provide fast operand accessors 47249259Sdim DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 48249259Sdim 49249259Sdim /// removeFromParent - This method unlinks 'this' from the containing module, 50249259Sdim /// but does not delete it. 51249259Sdim /// 52249259Sdim virtual void removeFromParent(); 53249259Sdim 54249259Sdim /// eraseFromParent - This method unlinks 'this' from the containing module 55249259Sdim /// and deletes it. 56249259Sdim /// 57249259Sdim virtual void eraseFromParent(); 58249259Sdim 59249259Sdim /// set/getAliasee - These methods retrive and set alias target. 60249259Sdim void setAliasee(Constant *GV); 61249259Sdim const Constant *getAliasee() const { 62249259Sdim return getOperand(0); 63249259Sdim } 64249259Sdim Constant *getAliasee() { 65249259Sdim return getOperand(0); 66249259Sdim } 67249259Sdim /// getAliasedGlobal() - Aliasee can be either global or bitcast of 68249259Sdim /// global. This method retrives the global for both aliasee flavours. 69263508Sdim GlobalValue *getAliasedGlobal(); 70263508Sdim const GlobalValue *getAliasedGlobal() const { 71263508Sdim return const_cast<GlobalAlias *>(this)->getAliasedGlobal(); 72263508Sdim } 73249259Sdim 74249259Sdim /// resolveAliasedGlobal() - This method tries to ultimately resolve the alias 75249259Sdim /// by going through the aliasing chain and trying to find the very last 76249259Sdim /// global. Returns NULL if a cycle was found. If stopOnWeak is false, then 77249259Sdim /// the whole chain aliasing chain is traversed, otherwise - only strong 78249259Sdim /// aliases. 79263508Sdim GlobalValue *resolveAliasedGlobal(bool stopOnWeak = true); 80263508Sdim const GlobalValue *resolveAliasedGlobal(bool stopOnWeak = true) const { 81263508Sdim return const_cast<GlobalAlias *>(this)->resolveAliasedGlobal(stopOnWeak); 82263508Sdim } 83249259Sdim 84263508Sdim static bool isValidLinkage(LinkageTypes L) { 85263508Sdim return isExternalLinkage(L) || isLocalLinkage(L) || 86263508Sdim isWeakLinkage(L) || isLinkOnceLinkage(L); 87263508Sdim } 88263508Sdim 89249259Sdim // Methods for support type inquiry through isa, cast, and dyn_cast: 90249259Sdim static inline bool classof(const Value *V) { 91249259Sdim return V->getValueID() == Value::GlobalAliasVal; 92249259Sdim } 93249259Sdim}; 94249259Sdim 95249259Sdimtemplate <> 96249259Sdimstruct OperandTraits<GlobalAlias> : 97249259Sdim public FixedNumOperandTraits<GlobalAlias, 1> { 98249259Sdim}; 99249259Sdim 100249259SdimDEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant) 101249259Sdim 102249259Sdim} // End llvm namespace 103249259Sdim 104249259Sdim#endif 105