• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the GlobalAlias class, which
11 // represents a single function or variable alias in the IR.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_GLOBALALIAS_H
16 #define LLVM_IR_GLOBALALIAS_H
17 
18 #include "llvm/ADT/ilist_node.h"
19 #include "llvm/IR/GlobalIndirectSymbol.h"
20 
21 namespace llvm {
22 
23 class Twine;
24 class Module;
25 template <typename ValueSubClass> class SymbolTableListTraits;
26 
27 class GlobalAlias : public GlobalIndirectSymbol,
28                     public ilist_node<GlobalAlias> {
29   friend class SymbolTableListTraits<GlobalAlias>;
30   void operator=(const GlobalAlias &) = delete;
31   GlobalAlias(const GlobalAlias &) = delete;
32 
33   void setParent(Module *parent);
34 
35   GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
36               const Twine &Name, Constant *Aliasee, Module *Parent);
37 
38 public:
39   /// If a parent module is specified, the alias is automatically inserted into
40   /// the end of the specified module's alias list.
41   static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
42                              LinkageTypes Linkage, const Twine &Name,
43                              Constant *Aliasee, Module *Parent);
44 
45   // Without the Aliasee.
46   static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
47                              LinkageTypes Linkage, const Twine &Name,
48                              Module *Parent);
49 
50   // The module is taken from the Aliasee.
51   static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
52                              LinkageTypes Linkage, const Twine &Name,
53                              GlobalValue *Aliasee);
54 
55   // Type, Parent and AddressSpace taken from the Aliasee.
56   static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
57                              GlobalValue *Aliasee);
58 
59   // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
60   static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
61 
62   /// removeFromParent - This method unlinks 'this' from the containing module,
63   /// but does not delete it.
64   ///
65   void removeFromParent() override;
66 
67   /// eraseFromParent - This method unlinks 'this' from the containing module
68   /// and deletes it.
69   ///
70   void eraseFromParent() override;
71 
72   /// These methods retrieve and set alias target.
73   void setAliasee(Constant *Aliasee);
getAliasee()74   const Constant *getAliasee() const {
75     return getIndirectSymbol();
76   }
getAliasee()77   Constant *getAliasee() {
78     return getIndirectSymbol();
79   }
80 
isValidLinkage(LinkageTypes L)81   static bool isValidLinkage(LinkageTypes L) {
82     return isExternalLinkage(L) || isLocalLinkage(L) ||
83       isWeakLinkage(L) || isLinkOnceLinkage(L);
84   }
85 
86   // Methods for support type inquiry through isa, cast, and dyn_cast:
classof(const Value * V)87   static inline bool classof(const Value *V) {
88     return V->getValueID() == Value::GlobalAliasVal;
89   }
90 };
91 
92 } // End llvm namespace
93 
94 #endif
95