GlobalAlias.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //===-------- llvm/GlobalAlias.h - GlobalAlias 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. // This file contains the declaration of the GlobalAlias class, which
  10. // represents a single function or variable alias in the IR.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_IR_GLOBALALIAS_H
  14. #define LLVM_IR_GLOBALALIAS_H
  15. #include "llvm/ADT/ilist_node.h"
  16. #include "llvm/IR/GlobalIndirectSymbol.h"
  17. #include "llvm/IR/Value.h"
  18. namespace llvm {
  19. class Twine;
  20. class Module;
  21. template <typename ValueSubClass> class SymbolTableListTraits;
  22. class GlobalAlias : public GlobalIndirectSymbol,
  23. public ilist_node<GlobalAlias> {
  24. friend class SymbolTableListTraits<GlobalAlias>;
  25. GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
  26. const Twine &Name, Constant *Aliasee, Module *Parent);
  27. public:
  28. GlobalAlias(const GlobalAlias &) = delete;
  29. GlobalAlias &operator=(const GlobalAlias &) = delete;
  30. /// If a parent module is specified, the alias is automatically inserted into
  31. /// the end of the specified module's alias list.
  32. static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
  33. LinkageTypes Linkage, const Twine &Name,
  34. Constant *Aliasee, Module *Parent);
  35. // Without the Aliasee.
  36. static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
  37. LinkageTypes Linkage, const Twine &Name,
  38. Module *Parent);
  39. // The module is taken from the Aliasee.
  40. static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
  41. LinkageTypes Linkage, const Twine &Name,
  42. GlobalValue *Aliasee);
  43. // Type, Parent and AddressSpace taken from the Aliasee.
  44. static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
  45. GlobalValue *Aliasee);
  46. // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
  47. static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
  48. /// removeFromParent - This method unlinks 'this' from the containing module,
  49. /// but does not delete it.
  50. ///
  51. void removeFromParent();
  52. /// eraseFromParent - This method unlinks 'this' from the containing module
  53. /// and deletes it.
  54. ///
  55. void eraseFromParent();
  56. /// These methods retrieve and set alias target.
  57. void setAliasee(Constant *Aliasee);
  58. const Constant *getAliasee() const {
  59. return getIndirectSymbol();
  60. }
  61. Constant *getAliasee() {
  62. return getIndirectSymbol();
  63. }
  64. static bool isValidLinkage(LinkageTypes L) {
  65. return isExternalLinkage(L) || isLocalLinkage(L) ||
  66. isWeakLinkage(L) || isLinkOnceLinkage(L);
  67. }
  68. // Methods for support type inquiry through isa, cast, and dyn_cast:
  69. static bool classof(const Value *V) {
  70. return V->getValueID() == Value::GlobalAliasVal;
  71. }
  72. };
  73. } // end namespace llvm
  74. #endif // LLVM_IR_GLOBALALIAS_H