GlobalAlias.h revision 249259
1169689Skan//===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===// 2169689Skan// 3169689Skan// The LLVM Compiler Infrastructure 4169689Skan// 5169689Skan// This file is distributed under the University of Illinois Open Source 6169689Skan// License. See LICENSE.TXT for details. 7169689Skan// 8169689Skan//===----------------------------------------------------------------------===// 9169689Skan// 10169689Skan// This file contains the declaration of the GlobalAlias class, which 11169689Skan// represents a single function or variable alias in the IR. 12169689Skan// 13169689Skan//===----------------------------------------------------------------------===// 14169689Skan 15169689Skan#ifndef LLVM_IR_GLOBALALIAS_H 16169689Skan#define LLVM_IR_GLOBALALIAS_H 17169689Skan 18169689Skan#include "llvm/ADT/Twine.h" 19169689Skan#include "llvm/ADT/ilist_node.h" 20169689Skan#include "llvm/IR/GlobalValue.h" 21169689Skan#include "llvm/IR/OperandTraits.h" 22169689Skan 23169689Skannamespace llvm { 24169689Skan 25169689Skanclass Module; 26169689Skantemplate<typename ValueSubClass, typename ItemParentClass> 27169689Skan class SymbolTableListTraits; 28169689Skan 29169689Skanclass GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> { 30169689Skan friend class SymbolTableListTraits<GlobalAlias, Module>; 31169689Skan void operator=(const GlobalAlias &) LLVM_DELETED_FUNCTION; 32169689Skan GlobalAlias(const GlobalAlias &) LLVM_DELETED_FUNCTION; 33169689Skan 34169689Skan void setParent(Module *parent); 35169689Skan 36169689Skanpublic: 37169689Skan // allocate space for exactly one operand 38169689Skan void *operator new(size_t s) { 39169689Skan return User::operator new(s, 1); 40169689Skan } 41169689Skan /// GlobalAlias ctor - If a parent module is specified, the alias is 42169689Skan /// automatically inserted into the end of the specified module's alias list. 43169689Skan GlobalAlias(Type *Ty, LinkageTypes Linkage, const Twine &Name = "", 44169689Skan Constant* Aliasee = 0, Module *Parent = 0); 45169689Skan 46169689Skan /// Provide fast operand accessors 47169689Skan DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 48169689Skan 49169689Skan /// removeFromParent - This method unlinks 'this' from the containing module, 50169689Skan /// but does not delete it. 51169689Skan /// 52169689Skan virtual void removeFromParent(); 53169689Skan 54169689Skan /// eraseFromParent - This method unlinks 'this' from the containing module 55169689Skan /// and deletes it. 56169689Skan /// 57169689Skan virtual void eraseFromParent(); 58169689Skan 59169689Skan /// set/getAliasee - These methods retrive and set alias target. 60169689Skan void setAliasee(Constant *GV); 61169689Skan const Constant *getAliasee() const { 62169689Skan return getOperand(0); 63169689Skan } 64169689Skan Constant *getAliasee() { 65169689Skan return getOperand(0); 66169689Skan } 67169689Skan /// getAliasedGlobal() - Aliasee can be either global or bitcast of 68169689Skan /// global. This method retrives the global for both aliasee flavours. 69169689Skan const GlobalValue *getAliasedGlobal() const; 70169689Skan 71169689Skan /// resolveAliasedGlobal() - This method tries to ultimately resolve the alias 72169689Skan /// by going through the aliasing chain and trying to find the very last 73169689Skan /// global. Returns NULL if a cycle was found. If stopOnWeak is false, then 74169689Skan /// the whole chain aliasing chain is traversed, otherwise - only strong 75169689Skan /// aliases. 76169689Skan const GlobalValue *resolveAliasedGlobal(bool stopOnWeak = true) const; 77169689Skan 78169689Skan // Methods for support type inquiry through isa, cast, and dyn_cast: 79169689Skan static inline bool classof(const Value *V) { 80169689Skan return V->getValueID() == Value::GlobalAliasVal; 81169689Skan } 82169689Skan}; 83169689Skan 84169689Skantemplate <> 85169689Skanstruct OperandTraits<GlobalAlias> : 86169689Skan public FixedNumOperandTraits<GlobalAlias, 1> { 87169689Skan}; 88169689Skan 89169689SkanDEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant) 90169689Skan 91169689Skan} // End llvm namespace 92169689Skan 93169689Skan#endif 94169689Skan