GlobalAlias.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file contains the declaration of the GlobalAlias class, which
  15. // represents a single function or variable alias in the IR.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_IR_GLOBALALIAS_H
  19. #define LLVM_IR_GLOBALALIAS_H
  20. #include "llvm/ADT/ilist_node.h"
  21. #include "llvm/IR/GlobalValue.h"
  22. #include "llvm/IR/OperandTraits.h"
  23. #include "llvm/IR/Value.h"
  24. namespace llvm {
  25. class Twine;
  26. class Module;
  27. template <typename ValueSubClass> class SymbolTableListTraits;
  28. class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
  29. friend class SymbolTableListTraits<GlobalAlias>;
  30. GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage,
  31. const Twine &Name, Constant *Aliasee, Module *Parent);
  32. public:
  33. GlobalAlias(const GlobalAlias &) = delete;
  34. GlobalAlias &operator=(const GlobalAlias &) = delete;
  35. /// If a parent module is specified, the alias is automatically inserted into
  36. /// the end of the specified module's alias list.
  37. static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
  38. LinkageTypes Linkage, const Twine &Name,
  39. Constant *Aliasee, Module *Parent);
  40. // Without the Aliasee.
  41. static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
  42. LinkageTypes Linkage, const Twine &Name,
  43. Module *Parent);
  44. // The module is taken from the Aliasee.
  45. static GlobalAlias *create(Type *Ty, unsigned AddressSpace,
  46. LinkageTypes Linkage, const Twine &Name,
  47. GlobalValue *Aliasee);
  48. // Type, Parent and AddressSpace taken from the Aliasee.
  49. static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
  50. GlobalValue *Aliasee);
  51. // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
  52. static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
  53. // allocate space for exactly one operand
  54. void *operator new(size_t S) { return User::operator new(S, 1); }
  55. void operator delete(void *Ptr) { User::operator delete(Ptr); }
  56. /// Provide fast operand accessors
  57. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
  58. void copyAttributesFrom(const GlobalAlias *Src) {
  59. GlobalValue::copyAttributesFrom(Src);
  60. }
  61. /// removeFromParent - This method unlinks 'this' from the containing module,
  62. /// but does not delete it.
  63. ///
  64. void removeFromParent();
  65. /// eraseFromParent - This method unlinks 'this' from the containing module
  66. /// and deletes it.
  67. ///
  68. void eraseFromParent();
  69. /// These methods retrieve and set alias target.
  70. void setAliasee(Constant *Aliasee);
  71. const Constant *getAliasee() const {
  72. return static_cast<Constant *>(Op<0>().get());
  73. }
  74. Constant *getAliasee() { return static_cast<Constant *>(Op<0>().get()); }
  75. const GlobalObject *getAliaseeObject() const;
  76. GlobalObject *getAliaseeObject() {
  77. return const_cast<GlobalObject *>(
  78. static_cast<const GlobalAlias *>(this)->getAliaseeObject());
  79. }
  80. static bool isValidLinkage(LinkageTypes L) {
  81. return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) ||
  82. isLinkOnceLinkage(L) || isAvailableExternallyLinkage(L);
  83. }
  84. // Methods for support type inquiry through isa, cast, and dyn_cast:
  85. static bool classof(const Value *V) {
  86. return V->getValueID() == Value::GlobalAliasVal;
  87. }
  88. };
  89. template <>
  90. struct OperandTraits<GlobalAlias>
  91. : public FixedNumOperandTraits<GlobalAlias, 1> {};
  92. DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
  93. } // end namespace llvm
  94. #endif // LLVM_IR_GLOBALALIAS_H
  95. #ifdef __GNUC__
  96. #pragma GCC diagnostic pop
  97. #endif