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 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(Type *Ty, LinkageTypes Linkage, const Twine &Name = "",
00044               Constant* Aliasee = nullptr, Module *Parent = nullptr);
00045 
00046   /// Provide fast operand accessors
00047   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
00048 
00049   /// removeFromParent - This method unlinks 'this' from the containing module,
00050   /// but does not delete it.
00051   ///
00052   void removeFromParent() override;
00053 
00054   /// eraseFromParent - This method unlinks 'this' from the containing module
00055   /// and deletes it.
00056   ///
00057   void eraseFromParent() override;
00058 
00059   /// set/getAliasee - These methods retrive and set alias target.
00060   void setAliasee(Constant *GV);
00061   const Constant *getAliasee() const {
00062     return getOperand(0);
00063   }
00064   Constant *getAliasee() {
00065     return getOperand(0);
00066   }
00067 
00068   /// This method tries to ultimately resolve the alias by going through the
00069   /// aliasing chain and trying to find the very last global. Returns NULL if a
00070   /// cycle was found.
00071   GlobalValue *getAliasedGlobal();
00072   const GlobalValue *getAliasedGlobal() const {
00073     return const_cast<GlobalAlias *>(this)->getAliasedGlobal();
00074   }
00075 
00076   static bool isValidLinkage(LinkageTypes L) {
00077     return isExternalLinkage(L) || isLocalLinkage(L) ||
00078       isWeakLinkage(L) || isLinkOnceLinkage(L);
00079   }
00080 
00081   // Methods for support type inquiry through isa, cast, and dyn_cast:
00082   static inline bool classof(const Value *V) {
00083     return V->getValueID() == Value::GlobalAliasVal;
00084   }
00085 };
00086 
00087 template <>
00088 struct OperandTraits<GlobalAlias> :
00089   public FixedNumOperandTraits<GlobalAlias, 1> {
00090 };
00091 
00092 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
00093 
00094 } // End llvm namespace
00095 
00096 #endif