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> class SymbolTableListTraits;
28 class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
29 friend class SymbolTableListTraits<GlobalAlias>;
30 void operator=(const GlobalAlias &) = delete;
31 GlobalAlias(const GlobalAlias &) = delete;
33 void setParent(Module *parent);
35 GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
36 const Twine &Name, Constant *Aliasee, Module *Parent);
39 // allocate space for exactly one operand
40 void *operator new(size_t s) {
41 return User::operator new(s, 1);
44 /// If a parent module is specified, the alias is automatically inserted into
45 /// the end of the specified module's alias list.
46 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
47 LinkageTypes Linkage, const Twine &Name,
48 Constant *Aliasee, Module *Parent);
50 // Without the Aliasee.
51 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
52 LinkageTypes Linkage, const Twine &Name,
55 // The module is taken from the Aliasee.
56 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
57 LinkageTypes Linkage, const Twine &Name,
58 GlobalValue *Aliasee);
60 // Type, Parent and AddressSpace taken from the Aliasee.
61 static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
62 GlobalValue *Aliasee);
64 // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
65 static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
67 /// Provide fast operand accessors
68 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
70 /// removeFromParent - This method unlinks 'this' from the containing module,
71 /// but does not delete it.
73 void removeFromParent() override;
75 /// eraseFromParent - This method unlinks 'this' from the containing module
78 void eraseFromParent() override;
80 /// These methods retrive and set alias target.
81 void setAliasee(Constant *Aliasee);
82 const Constant *getAliasee() const {
83 return const_cast<GlobalAlias *>(this)->getAliasee();
85 Constant *getAliasee() {
89 const GlobalObject *getBaseObject() const {
90 return const_cast<GlobalAlias *>(this)->getBaseObject();
92 GlobalObject *getBaseObject() {
93 return dyn_cast<GlobalObject>(getAliasee()->stripInBoundsOffsets());
96 const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
97 return const_cast<GlobalAlias *>(this)->getBaseObject(DL, Offset);
99 GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
100 return dyn_cast<GlobalObject>(
101 getAliasee()->stripAndAccumulateInBoundsConstantOffsets(DL, Offset));
104 static bool isValidLinkage(LinkageTypes L) {
105 return isExternalLinkage(L) || isLocalLinkage(L) ||
106 isWeakLinkage(L) || isLinkOnceLinkage(L);
109 // Methods for support type inquiry through isa, cast, and dyn_cast:
110 static inline bool classof(const Value *V) {
111 return V->getValueID() == Value::GlobalAliasVal;
116 struct OperandTraits<GlobalAlias> :
117 public FixedNumOperandTraits<GlobalAlias, 1> {
120 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
122 } // End llvm namespace