LLVM API Documentation

GlobalAlias.h

Go to the documentation of this file.
00001 //===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains the declaration of the GlobalAlias class, which
00011 // represents a single function or variable alias in the IR.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_GLOBAL_ALIAS_H
00016 #define LLVM_GLOBAL_ALIAS_H
00017 
00018 #include "llvm/GlobalValue.h"
00019 #include "llvm/OperandTraits.h"
00020 #include "llvm/ADT/ilist_node.h"
00021 
00022 namespace llvm {
00023 
00024 class Module;
00025 class Constant;
00026 template<typename ValueSubClass, typename ItemParentClass>
00027   class SymbolTableListTraits;
00028 
00029 class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
00030   friend class SymbolTableListTraits<GlobalAlias, Module>;
00031   void operator=(const GlobalAlias &);     // Do not implement
00032   GlobalAlias(const GlobalAlias &);     // Do not implement
00033 
00034   void setParent(Module *parent);
00035 
00036 public:
00037   // allocate space for exactly one operand
00038   void *operator new(size_t s) {
00039     return User::operator new(s, 1);
00040   }
00041   /// GlobalAlias ctor - If a parent module is specified, the alias is
00042   /// automatically inserted into the end of the specified module's alias list.
00043   GlobalAlias(const Type *Ty, LinkageTypes Linkage, const std::string &Name = "",
00044               Constant* Aliasee = 0, Module *Parent = 0);
00045 
00046   /// Provide fast operand accessors
00047   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
00048 
00049   /// isDeclaration - Is this global variable lacking an initializer?  If so, 
00050   /// the global variable is defined in some other translation unit, and is thus
00051   /// only a declaration here.
00052   virtual bool isDeclaration() const;
00053 
00054   /// removeFromParent - This method unlinks 'this' from the containing module,
00055   /// but does not delete it.
00056   ///
00057   virtual void removeFromParent();
00058 
00059   /// eraseFromParent - This method unlinks 'this' from the containing module
00060   /// and deletes it.
00061   ///
00062   virtual void eraseFromParent();
00063 
00064   /// set/getAliasee - These methods retrive and set alias target.
00065   void setAliasee(Constant* GV);
00066   const Constant* getAliasee() const {
00067     return cast_or_null<Constant>(getOperand(0));
00068   }
00069   Constant* getAliasee() {
00070     return cast_or_null<Constant>(getOperand(0));
00071   }
00072   /// getAliasedGlobal() - Aliasee can be either global or bitcast of
00073   /// global. This method retrives the global for both aliasee flavours.
00074   const GlobalValue* getAliasedGlobal() const;
00075 
00076   /// resolveAliasedGlobal() - This method tries to ultimately resolve the alias
00077   /// by going through the aliasing chain and trying to find the very last
00078   /// global. Returns NULL if a cycle was found. If stopOnWeak is false, then
00079   /// the whole chain aliasing chain is traversed, otherwise - only strong
00080   /// aliases.
00081   const GlobalValue* resolveAliasedGlobal(bool stopOnWeak = true) const;
00082 
00083   // Methods for support type inquiry through isa, cast, and dyn_cast:
00084   static inline bool classof(const GlobalAlias *) { return true; }
00085   static inline bool classof(const Value *V) {
00086     return V->getValueID() == Value::GlobalAliasVal;
00087   }
00088 };
00089 
00090 template <>
00091 struct OperandTraits<GlobalAlias> : FixedNumOperandTraits<1> {
00092 };
00093 
00094 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Value)
00095 
00096 } // End llvm namespace
00097 
00098 #endif