LLVM 20.0.0git
GlobalAlias.h
Go to the documentation of this file.
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"
20#include "llvm/IR/Value.h"
21
22namespace llvm {
23
24class Twine;
25class Module;
26template <typename ValueSubClass, typename... Args> class SymbolTableListTraits;
27
28class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
30
31 constexpr static IntrusiveOperandsAllocMarker AllocMarker{1};
32
34 const Twine &Name, Constant *Aliasee, Module *Parent);
35
36public:
37 GlobalAlias(const GlobalAlias &) = delete;
38 GlobalAlias &operator=(const GlobalAlias &) = delete;
39
40 /// If a parent module is specified, the alias is automatically inserted into
41 /// the end of the specified module's alias list.
42 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
44 Constant *Aliasee, Module *Parent);
45
46 // Without the Aliasee.
47 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
49 Module *Parent);
50
51 // The module is taken from the Aliasee.
52 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
54 GlobalValue *Aliasee);
55
56 // Type, Parent and AddressSpace taken from the Aliasee.
58 GlobalValue *Aliasee);
59
60 // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
61 static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
62
63 // allocate space for exactly one operand
64 void *operator new(size_t S) { return User::operator new(S, AllocMarker); }
65 void operator delete(void *Ptr) { User::operator delete(Ptr); }
66
67 /// Provide fast operand accessors
69
72 }
73
74 /// removeFromParent - This method unlinks 'this' from the containing module,
75 /// but does not delete it.
76 ///
77 void removeFromParent();
78
79 /// eraseFromParent - This method unlinks 'this' from the containing module
80 /// and deletes it.
81 ///
82 void eraseFromParent();
83
84 /// These methods retrieve and set alias target.
85 void setAliasee(Constant *Aliasee);
86 const Constant *getAliasee() const {
87 return static_cast<Constant *>(Op<0>().get());
88 }
89 Constant *getAliasee() { return static_cast<Constant *>(Op<0>().get()); }
90
91 const GlobalObject *getAliaseeObject() const;
93 return const_cast<GlobalObject *>(
94 static_cast<const GlobalAlias *>(this)->getAliaseeObject());
95 }
96
98 return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) ||
100 }
101
102 // Methods for support type inquiry through isa, cast, and dyn_cast:
103 static bool classof(const Value *V) {
104 return V->getValueID() == Value::GlobalAliasVal;
105 }
106};
107
108template <>
110 : public FixedNumOperandTraits<GlobalAlias, 1> {};
111
113
114} // end namespace llvm
115
116#endif // LLVM_IR_GLOBALALIAS_H
std::string Name
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
This is an important base class in LLVM.
Definition: Constant.h:42
This class represents an Operation in the Expression.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:587
static bool isValidLinkage(LinkageTypes L)
Definition: GlobalAlias.h:97
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:595
GlobalAlias & operator=(const GlobalAlias &)=delete
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant)
Provide fast operand accessors.
void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Definition: Globals.cpp:589
Constant * getAliasee()
Definition: GlobalAlias.h:89
const Constant * getAliasee() const
Definition: GlobalAlias.h:86
static bool classof(const Value *V)
Definition: GlobalAlias.h:103
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
Definition: Globals.cpp:557
GlobalAlias(const GlobalAlias &)=delete
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:585
GlobalObject * getAliaseeObject()
Definition: GlobalAlias.h:92
void copyAttributesFrom(const GlobalAlias *Src)
Definition: GlobalAlias.h:70
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:409
static bool isLinkOnceLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:388
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:379
static bool isExternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:376
void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
Definition: Globals.cpp:62
static bool isWeakLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:397
unsigned Linkage
Definition: GlobalValue.h:98
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:51
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This file defines the ilist_node class template, which is a convenient base class for creating classe...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
Definition: OperandTraits.h:30
Compile-time customization of User operands.
Definition: User.h:42
Indicates this User has operands co-allocated.
Definition: User.h:60