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