1//===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the declaration of the GlobalAlias class, which
10// represents a single function or variable alias in the IR.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_GLOBALALIAS_H
15#define LLVM_IR_GLOBALALIAS_H
16
17#include "llvm/ADT/ilist_node.h"
18#include "llvm/IR/GlobalValue.h"
19#include "llvm/IR/OperandTraits.h"
20#include "llvm/IR/Value.h"
21#include "llvm/Support/Compiler.h"
22
23namespace llvm {
24
25class Twine;
26class Module;
27template <typename ValueSubClass, typename... Args> class SymbolTableListTraits;
28
29class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
30 friend class SymbolTableListTraits<GlobalAlias>;
31
32 constexpr static IntrusiveOperandsAllocMarker AllocMarker{.NumOps: 1};
33
34 GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
35 const Twine &Name, Constant *Aliasee, Module *Parent);
36
37public:
38 GlobalAlias(const GlobalAlias &) = delete;
39 GlobalAlias &operator=(const GlobalAlias &) = delete;
40
41 /// If a parent module is specified, the alias is automatically inserted into
42 /// the end of the specified module's alias list.
43 LLVM_ABI static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
44 LinkageTypes Linkage, const Twine &Name,
45 Constant *Aliasee, Module *Parent);
46
47 // Without the Aliasee.
48 LLVM_ABI static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
49 LinkageTypes Linkage, const Twine &Name,
50 Module *Parent);
51
52 // The module is taken from the Aliasee.
53 LLVM_ABI static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
54 LinkageTypes Linkage, const Twine &Name,
55 GlobalValue *Aliasee);
56
57 // Type, Parent and AddressSpace taken from the Aliasee.
58 LLVM_ABI static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
59 GlobalValue *Aliasee);
60
61 // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
62 LLVM_ABI static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
63
64 // allocate space for exactly one operand
65 void *operator new(size_t S) { return User::operator new(Size: S, allocTrait: AllocMarker); }
66 void operator delete(void *Ptr) { User::operator delete(Usr: Ptr); }
67
68 /// Provide fast operand accessors
69 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
70
71 void copyAttributesFrom(const GlobalAlias *Src) {
72 GlobalValue::copyAttributesFrom(Src);
73 }
74
75 /// removeFromParent - This method unlinks 'this' from the containing module,
76 /// but does not delete it.
77 ///
78 LLVM_ABI void removeFromParent();
79
80 /// eraseFromParent - This method unlinks 'this' from the containing module
81 /// and deletes it.
82 ///
83 LLVM_ABI void eraseFromParent();
84
85 /// These methods retrieve and set alias target.
86 LLVM_ABI void setAliasee(Constant *Aliasee);
87 const Constant *getAliasee() const {
88 return static_cast<Constant *>(Op<0>().get());
89 }
90 Constant *getAliasee() { return static_cast<Constant *>(Op<0>().get()); }
91
92 LLVM_ABI const GlobalObject *getAliaseeObject() const;
93 GlobalObject *getAliaseeObject() {
94 return const_cast<GlobalObject *>(
95 static_cast<const GlobalAlias *>(this)->getAliaseeObject());
96 }
97
98 static bool isValidLinkage(LinkageTypes L) {
99 return isExternalLinkage(Linkage: L) || isLocalLinkage(Linkage: L) || isWeakLinkage(Linkage: L) ||
100 isLinkOnceLinkage(Linkage: L) || isAvailableExternallyLinkage(Linkage: L);
101 }
102
103 // Methods for support type inquiry through isa, cast, and dyn_cast:
104 static bool classof(const Value *V) {
105 return V->getValueID() == Value::GlobalAliasVal;
106 }
107};
108
109template <>
110struct OperandTraits<GlobalAlias>
111 : public FixedNumOperandTraits<GlobalAlias, 1> {};
112
113DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
114
115} // end namespace llvm
116
117#endif // LLVM_IR_GLOBALALIAS_H
118

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of llvm/include/llvm/IR/GlobalAlias.h