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