LLVM  mainline
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_IR_GLOBALALIAS_H
00016 #define LLVM_IR_GLOBALALIAS_H
00017 
00018 #include "llvm/ADT/Twine.h"
00019 #include "llvm/ADT/ilist_node.h"
00020 #include "llvm/IR/GlobalValue.h"
00021 #include "llvm/IR/OperandTraits.h"
00022 
00023 namespace llvm {
00024 
00025 class Module;
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 &) = delete;
00032   GlobalAlias(const GlobalAlias &) = delete;
00033 
00034   void setParent(Module *parent);
00035 
00036   GlobalAlias(PointerType *Ty, LinkageTypes Linkage, const Twine &Name,
00037               Constant *Aliasee, Module *Parent);
00038 
00039 public:
00040   // allocate space for exactly one operand
00041   void *operator new(size_t s) {
00042     return User::operator new(s, 1);
00043   }
00044 
00045   /// If a parent module is specified, the alias is automatically inserted into
00046   /// the end of the specified module's alias list.
00047   static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
00048                              const Twine &Name, Constant *Aliasee,
00049                              Module *Parent);
00050 
00051   // Without the Aliasee.
00052   static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
00053                              const Twine &Name, Module *Parent);
00054 
00055   // The module is taken from the Aliasee.
00056   static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
00057                              const Twine &Name, GlobalValue *Aliasee);
00058 
00059   // Type, Parent and AddressSpace taken from the Aliasee.
00060   static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
00061                              GlobalValue *Aliasee);
00062 
00063   // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
00064   static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
00065 
00066   /// Provide fast operand accessors
00067   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00068 
00069   /// removeFromParent - This method unlinks 'this' from the containing module,
00070   /// but does not delete it.
00071   ///
00072   void removeFromParent() override;
00073 
00074   /// eraseFromParent - This method unlinks 'this' from the containing module
00075   /// and deletes it.
00076   ///
00077   void eraseFromParent() override;
00078 
00079   /// These methods retrive and set alias target.
00080   void setAliasee(Constant *Aliasee);
00081   const Constant *getAliasee() const {
00082     return const_cast<GlobalAlias *>(this)->getAliasee();
00083   }
00084   Constant *getAliasee() {
00085     return getOperand(0);
00086   }
00087 
00088   const GlobalObject *getBaseObject() const {
00089     return const_cast<GlobalAlias *>(this)->getBaseObject();
00090   }
00091   GlobalObject *getBaseObject() {
00092     return dyn_cast<GlobalObject>(getAliasee()->stripInBoundsOffsets());
00093   }
00094 
00095   const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
00096     return const_cast<GlobalAlias *>(this)->getBaseObject(DL, Offset);
00097   }
00098   GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
00099     return dyn_cast<GlobalObject>(
00100         getAliasee()->stripAndAccumulateInBoundsConstantOffsets(DL, Offset));
00101   }
00102 
00103   static bool isValidLinkage(LinkageTypes L) {
00104     return isExternalLinkage(L) || isLocalLinkage(L) ||
00105       isWeakLinkage(L) || isLinkOnceLinkage(L);
00106   }
00107 
00108   // Methods for support type inquiry through isa, cast, and dyn_cast:
00109   static inline bool classof(const Value *V) {
00110     return V->getValueID() == Value::GlobalAliasVal;
00111   }
00112 };
00113 
00114 template <>
00115 struct OperandTraits<GlobalAlias> :
00116   public FixedNumOperandTraits<GlobalAlias, 1> {
00117 };
00118 
00119 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
00120 
00121 } // End llvm namespace
00122 
00123 #endif