Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / IR / GlobalIFunc.h
blobbc0d3c053cce26e5c22f8321054b908470e1041d
1 //===-------- llvm/GlobalIFunc.h - GlobalIFunc 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 /// \brief
10 /// This file contains the declaration of the GlobalIFunc class, which
11 /// represents a single indirect function in the IR. Indirect function uses
12 /// ELF symbol type extension to mark that the address of a declaration should
13 /// be resolved at runtime by calling a resolver function.
14 ///
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_IR_GLOBALIFUNC_H
18 #define LLVM_IR_GLOBALIFUNC_H
20 #include "llvm/ADT/ilist_node.h"
21 #include "llvm/IR/GlobalIndirectSymbol.h"
22 #include "llvm/IR/Value.h"
24 namespace llvm {
26 class Twine;
27 class Module;
29 // Traits class for using GlobalIFunc in symbol table in Module.
30 template <typename ValueSubClass> class SymbolTableListTraits;
32 class GlobalIFunc final : public GlobalIndirectSymbol,
33 public ilist_node<GlobalIFunc> {
34 friend class SymbolTableListTraits<GlobalIFunc>;
36 GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
37 const Twine &Name, Constant *Resolver, Module *Parent);
39 public:
40 GlobalIFunc(const GlobalIFunc &) = delete;
41 GlobalIFunc &operator=(const GlobalIFunc &) = delete;
43 /// If a parent module is specified, the ifunc is automatically inserted into
44 /// the end of the specified module's ifunc list.
45 static GlobalIFunc *create(Type *Ty, unsigned AddressSpace,
46 LinkageTypes Linkage, const Twine &Name,
47 Constant *Resolver, Module *Parent);
49 void copyAttributesFrom(const GlobalIFunc *Src) {
50 GlobalValue::copyAttributesFrom(Src);
53 /// This method unlinks 'this' from the containing module, but does not
54 /// delete it.
55 void removeFromParent();
57 /// This method unlinks 'this' from the containing module and deletes it.
58 void eraseFromParent();
60 /// These methods retrieve and set ifunc resolver function.
61 void setResolver(Constant *Resolver) {
62 setIndirectSymbol(Resolver);
64 const Constant *getResolver() const {
65 return getIndirectSymbol();
67 Constant *getResolver() {
68 return getIndirectSymbol();
71 // Methods for support type inquiry through isa, cast, and dyn_cast:
72 static bool classof(const Value *V) {
73 return V->getValueID() == Value::GlobalIFuncVal;
77 } // end namespace llvm
79 #endif // LLVM_IR_GLOBALIFUNC_H