GlobalIFunc.h 2.5 KB

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