1 //===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the GlobalAlias class, which
11 // represents a single function or variable alias in the IR.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_GLOBALALIAS_H
16 #define LLVM_IR_GLOBALALIAS_H
18 #include "llvm/ADT/Twine.h"
19 #include "llvm/ADT/ilist_node.h"
20 #include "llvm/IR/GlobalValue.h"
21 #include "llvm/IR/OperandTraits.h"
26 template<typename ValueSubClass, typename ItemParentClass>
27 class SymbolTableListTraits;
29 class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
30 friend class SymbolTableListTraits<GlobalAlias, Module>;
31 void operator=(const GlobalAlias &) = delete;
32 GlobalAlias(const GlobalAlias &) = delete;
34 void setParent(Module *parent);
36 GlobalAlias(PointerType *Ty, LinkageTypes Linkage, const Twine &Name,
37 Constant *Aliasee, Module *Parent);
40 // allocate space for exactly one operand
41 void *operator new(size_t s) {
42 return User::operator new(s, 1);
45 /// If a parent module is specified, the alias is automatically inserted into
46 /// the end of the specified module's alias list.
47 static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
48 const Twine &Name, Constant *Aliasee,
51 // Without the Aliasee.
52 static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
53 const Twine &Name, Module *Parent);
55 // The module is taken from the Aliasee.
56 static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
57 const Twine &Name, GlobalValue *Aliasee);
59 // Type, Parent and AddressSpace taken from the Aliasee.
60 static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
61 GlobalValue *Aliasee);
63 // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
64 static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
66 /// Provide fast operand accessors
67 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
69 /// removeFromParent - This method unlinks 'this' from the containing module,
70 /// but does not delete it.
72 void removeFromParent() override;
74 /// eraseFromParent - This method unlinks 'this' from the containing module
77 void eraseFromParent() override;
79 /// These methods retrive and set alias target.
80 void setAliasee(Constant *Aliasee);
81 const Constant *getAliasee() const {
82 return const_cast<GlobalAlias *>(this)->getAliasee();
84 Constant *getAliasee() {
88 const GlobalObject *getBaseObject() const {
89 return const_cast<GlobalAlias *>(this)->getBaseObject();
91 GlobalObject *getBaseObject() {
92 return dyn_cast<GlobalObject>(getAliasee()->stripInBoundsOffsets());
95 const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
96 return const_cast<GlobalAlias *>(this)->getBaseObject(DL, Offset);
98 GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
99 return dyn_cast<GlobalObject>(
100 getAliasee()->stripAndAccumulateInBoundsConstantOffsets(DL, Offset));
103 static bool isValidLinkage(LinkageTypes L) {
104 return isExternalLinkage(L) || isLocalLinkage(L) ||
105 isWeakLinkage(L) || isLinkOnceLinkage(L);
108 // Methods for support type inquiry through isa, cast, and dyn_cast:
109 static inline bool classof(const Value *V) {
110 return V->getValueID() == Value::GlobalAliasVal;
115 struct OperandTraits<GlobalAlias> :
116 public FixedNumOperandTraits<GlobalAlias, 1> {
119 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
121 } // End llvm namespace