xref: /aosp_15_r20/external/llvm/include/llvm/IR/GlobalIFunc.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1 //===-------- llvm/GlobalIFunc.h - GlobalIFunc class ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \brief
11 /// This file contains the declaration of the GlobalIFunc class, which
12 /// represents a single indirect function in the IR. Indirect function uses
13 /// ELF symbol type extension to mark that the address of a declaration should
14 /// be resolved at runtime by calling a resolver function.
15 ///
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_IR_GLOBALIFUNC_H
19 #define LLVM_IR_GLOBALIFUNC_H
20 
21 #include "llvm/ADT/ilist_node.h"
22 #include "llvm/IR/GlobalIndirectSymbol.h"
23 
24 namespace llvm {
25 
26 class Twine;
27 class Module;
28 
29 // Traits class for using GlobalIFunc in symbol table in Module.
30 template <typename ValueSubClass> class SymbolTableListTraits;
31 
32 class GlobalIFunc final : public GlobalIndirectSymbol,
33                           public ilist_node<GlobalIFunc> {
34   friend class SymbolTableListTraits<GlobalIFunc>;
35   void operator=(const GlobalIFunc &) = delete;
36   GlobalIFunc(const GlobalIFunc &) = delete;
37 
38   void setParent(Module *parent);
39 
40   GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
41               const Twine &Name, Constant *Resolver, Module *Parent);
42 
43 public:
44   /// If a parent module is specified, the ifunc is automatically inserted into
45   /// the end of the specified module's ifunc list.
46   static GlobalIFunc *create(Type *Ty, unsigned AddressSpace,
47                              LinkageTypes Linkage, const Twine &Name,
48                              Constant *Resolver, Module *Parent);
49 
50   /// This method unlinks 'this' from the containing module, but does not
51   /// delete it.
52   void removeFromParent() final;
53 
54   /// This method unlinks 'this' from the containing module and deletes it.
55   void eraseFromParent() final;
56 
57   /// These methods retrieve and set ifunc resolver function.
setResolver(Constant * Resolver)58   void setResolver(Constant *Resolver) {
59     setIndirectSymbol(Resolver);
60   }
getResolver()61   const Constant *getResolver() const {
62     return getIndirectSymbol();
63   }
getResolver()64   Constant *getResolver() {
65     return getIndirectSymbol();
66   }
67 
68   // Methods for support type inquiry through isa, cast, and dyn_cast:
classof(const Value * V)69   static inline bool classof(const Value *V) {
70     return V->getValueID() == Value::GlobalIFuncVal;
71   }
72 };
73 
74 } // End llvm namespace
75 
76 #endif
77