llvm.org GIT mirror llvm / dc022ba
[IFUNC] Introduce GlobalIndirectSymbol as a base class for alias and ifunc This patch is a part of http://reviews.llvm.org/D15525 GlobalIndirectSymbol class contains common implementation for both aliases and ifuncs. This patch should be NFC change that just prepare common code for ifunc support. Differential Revision: http://reviews.llvm.org/D18433 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265016 91177308-0d34-0410-b5e6-96231b3b80d8 Dmitry Polukhin 3 years ago
4 changed file(s) with 97 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
1616
1717 #include "llvm/ADT/Twine.h"
1818 #include "llvm/ADT/ilist_node.h"
19 #include "llvm/IR/GlobalValue.h"
20 #include "llvm/IR/OperandTraits.h"
19 #include "llvm/IR/GlobalIndirectSymbol.h"
2120
2221 namespace llvm {
2322
2423 class Module;
2524 template class SymbolTableListTraits;
2625
27 class GlobalAlias : public GlobalValue, public ilist_node {
26 class GlobalAlias : public GlobalIndirectSymbol,
27 public ilist_node {
2828 friend class SymbolTableListTraits;
2929 void operator=(const GlobalAlias &) = delete;
3030 GlobalAlias(const GlobalAlias &) = delete;
3535 const Twine &Name, Constant *Aliasee, Module *Parent);
3636
3737 public:
38 // allocate space for exactly one operand
39 void *operator new(size_t s) {
40 return User::operator new(s, 1);
41 }
42
4338 /// If a parent module is specified, the alias is automatically inserted into
4439 /// the end of the specified module's alias list.
4540 static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
6358 // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
6459 static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
6560
66 /// Provide fast operand accessors
67 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
68
6961 /// removeFromParent - This method unlinks 'this' from the containing module,
7062 /// but does not delete it.
7163 ///
7668 ///
7769 void eraseFromParent() override;
7870
79 /// These methods retrive and set alias target.
71 /// These methods retrieve and set alias target.
8072 void setAliasee(Constant *Aliasee);
8173 const Constant *getAliasee() const {
82 return const_cast(this)->getAliasee();
74 return getIndirectSymbol();
8375 }
8476 Constant *getAliasee() {
85 return getOperand(0);
77 return getIndirectSymbol();
8678 }
8779
8880 const GlobalObject *getBaseObject() const {
111103 }
112104 };
113105
114 template <>
115 struct OperandTraits :
116 public FixedNumOperandTraits {
117 };
118
119 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
120
121106 } // End llvm namespace
122107
123108 #endif
0 //===- llvm/GlobalIndirectSymbol.h - GlobalIndirectSymbol class -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the declaration of the GlobalIndirectSymbol class, which
10 // is a base class for GlobalAlias and GlobalIFunc. It contains all common code
11 // for aliases and ifuncs.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IR_GLOBALINDIRECTSYMBOL_H
16 #define LLVM_IR_GLOBALINDIRECTSYMBOL_H
17
18 #include "llvm/IR/GlobalValue.h"
19 #include "llvm/IR/OperandTraits.h"
20
21 namespace llvm {
22
23 class GlobalIndirectSymbol : public GlobalValue {
24 void operator=(const GlobalIndirectSymbol &) = delete;
25 GlobalIndirectSymbol(const GlobalIndirectSymbol &) = delete;
26
27 protected:
28 GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace,
29 LinkageTypes Linkage, const Twine &Name, Constant *Symbol);
30
31 public:
32 // allocate space for exactly one operand
33 void *operator new(size_t s) {
34 return User::operator new(s, 1);
35 }
36
37 /// Provide fast operand accessors
38 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
39
40 /// These methods set and retrieve indirect symbol.
41 void setIndirectSymbol(Constant *Symbol) {
42 setOperand(0, Symbol);
43 }
44 const Constant *getIndirectSymbol() const {
45 return const_cast(this)->getIndirectSymbol();
46 }
47 Constant *getIndirectSymbol() {
48 return getOperand(0);
49 }
50
51 // Methods for support type inquiry through isa, cast, and dyn_cast:
52 static inline bool classof(const Value *V) {
53 return V->getValueID() == Value::GlobalAliasVal;
54 }
55 };
56
57 template <>
58 struct OperandTraits :
59 public FixedNumOperandTraits {
60 };
61
62 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant)
63
64 } // End llvm namespace
65
66 #endif
3030 class DataLayout;
3131 class Function;
3232 class GlobalAlias;
33 class GlobalIndirectSymbol;
3334 class GlobalObject;
3435 class GlobalValue;
3536 class GlobalVariable;
741742 }
742743 };
743744
745 template <> struct isa_impl {
746 static inline bool doit(const Value &Val) {
747 return isa(Val);
748 }
749 };
750
744751 template <> struct isa_impl {
745752 static inline bool doit(const Value &Val) {
746 return isa(Val) || isaAlias>(Val);
753 return isa(Val) || isaIndirectSymbol>(Val);
747754 }
748755 };
749756
293293
294294
295295 //===----------------------------------------------------------------------===//
296 // GlobalIndirectSymbol Implementation
297 //===----------------------------------------------------------------------===//
298
299 GlobalIndirectSymbol::GlobalIndirectSymbol(Type *Ty, ValueTy VTy,
300 unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name,
301 Constant *Symbol)
302 : GlobalValue(Ty, VTy, &Op<0>(), 1, Linkage, Name, AddressSpace) {
303 Op<0>() = Symbol;
304 }
305
306
307 //===----------------------------------------------------------------------===//
296308 // GlobalAlias Implementation
297309 //===----------------------------------------------------------------------===//
298310
299311 GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
300312 const Twine &Name, Constant *Aliasee,
301313 Module *ParentModule)
302 : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name,
303 AddressSpace) {
304 Op<0>() = Aliasee;
305
314 : GlobalIndirectSymbol(Ty, Value::GlobalAliasVal, AddressSpace, Link, Name,
315 Aliasee) {
306316 if (ParentModule)
307317 ParentModule->getAliasList().push_back(this);
308318 }
351361 void GlobalAlias::setAliasee(Constant *Aliasee) {
352362 assert((!Aliasee || Aliasee->getType() == getType()) &&
353363 "Alias and aliasee types should match!");
354 setOperand(0, Aliasee);
355 }
364 setIndirectSymbol(Aliasee);
365 }