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//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_IR_GLOBALIFUNC_H
18#define LLVM_IR_GLOBALIFUNC_H
19
20#include "llvm/ADT/ilist_node.h"
21#include "llvm/IR/GlobalIndirectSymbol.h"
22#include "llvm/IR/Value.h"
23
24namespace llvm {
25
26class Twine;
27class Module;
28
29// Traits class for using GlobalIFunc in symbol table in Module.
30template <typename ValueSubClass> class SymbolTableListTraits;
31
32class GlobalIFunc final : public GlobalIndirectSymbol,
33                          public ilist_node<GlobalIFunc> {
34  friend class SymbolTableListTraits<GlobalIFunc>;
35
36  GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
37              const Twine &Name, Constant *Resolver, Module *Parent);
38
39public:
40  GlobalIFunc(const GlobalIFunc &) = delete;
41  GlobalIFunc &operator=(const GlobalIFunc &) = delete;
42
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);
48
49  /// This method unlinks 'this' from the containing module, but does not
50  /// delete it.
51  void removeFromParent();
52
53  /// This method unlinks 'this' from the containing module and deletes it.
54  void eraseFromParent();
55
56  /// These methods retrieve and set ifunc resolver function.
57  void setResolver(Constant *Resolver) {
58    setIndirectSymbol(Resolver);
59  }
60  const Constant *getResolver() const {
61    return getIndirectSymbol();
62  }
63  Constant *getResolver() {
64    return getIndirectSymbol();
65  }
66
67  // Methods for support type inquiry through isa, cast, and dyn_cast:
68  static bool classof(const Value *V) {
69    return V->getValueID() == Value::GlobalIFuncVal;
70  }
71};
72
73} // end namespace llvm
74
75#endif // LLVM_IR_GLOBALIFUNC_H
76