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