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 &) LLVM_DELETED_FUNCTION;
32 GlobalAlias(const GlobalAlias &) LLVM_DELETED_FUNCTION;
34 void setParent(Module *parent);
36 GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
37 const Twine &Name, 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(Type *Ty, unsigned AddressSpace,
48 LinkageTypes Linkage, const Twine &Name,
49 Constant *Aliasee, Module *Parent);
51 // Without the Aliasee.
52 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
53 LinkageTypes Linkage, const Twine &Name,
56 // The module is taken from the Aliasee.
57 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
58 LinkageTypes Linkage, const Twine &Name,
59 GlobalValue *Aliasee);
61 // Type, Parent and AddressSpace taken from the Aliasee.
62 static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
63 GlobalValue *Aliasee);
65 // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
66 static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
68 /// Provide fast operand accessors
69 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
71 /// removeFromParent - This method unlinks 'this' from the containing module,
72 /// but does not delete it.
74 void removeFromParent() override;
76 /// eraseFromParent - This method unlinks 'this' from the containing module
79 void eraseFromParent() override;
81 /// These methods retrive and set alias target.
82 void setAliasee(Constant *Aliasee);
83 const Constant *getAliasee() const {
84 return const_cast<GlobalAlias *>(this)->getAliasee();
86 Constant *getAliasee() {
90 const GlobalObject *getBaseObject() const {
91 return const_cast<GlobalAlias *>(this)->getBaseObject();
93 GlobalObject *getBaseObject() {
94 return dyn_cast<GlobalObject>(getAliasee()->stripInBoundsOffsets());
97 const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
98 return const_cast<GlobalAlias *>(this)->getBaseObject(DL, Offset);
100 GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
101 return dyn_cast<GlobalObject>(
102 getAliasee()->stripAndAccumulateInBoundsConstantOffsets(DL, Offset));
105 static bool isValidLinkage(LinkageTypes L) {
106 return isExternalLinkage(L) || isLocalLinkage(L) ||
107 isWeakLinkage(L) || isLinkOnceLinkage(L);
110 // Methods for support type inquiry through isa, cast, and dyn_cast:
111 static inline bool classof(const Value *V) {
112 return V->getValueID() == Value::GlobalAliasVal;
117 struct OperandTraits<GlobalAlias> :
118 public FixedNumOperandTraits<GlobalAlias, 1> {
121 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
123 } // End llvm namespace