GlobalAlias.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //===-------- llvm/GlobalAlias.h - GlobalAlias class ------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file contains the declaration of the GlobalAlias class, which
  11. // represents a single function or variable alias in the IR.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_IR_GLOBALALIAS_H
  15. #define LLVM_IR_GLOBALALIAS_H
  16. #include "llvm/ADT/Twine.h"
  17. #include "llvm/ADT/ilist_node.h"
  18. #include "llvm/IR/GlobalValue.h"
  19. #include "llvm/IR/OperandTraits.h"
  20. namespace llvm {
  21. class Module;
  22. template<typename ValueSubClass, typename ItemParentClass>
  23. class SymbolTableListTraits;
  24. class GlobalAlias : public GlobalValue, public ilist_node<GlobalAlias> {
  25. friend class SymbolTableListTraits<GlobalAlias, Module>;
  26. void operator=(const GlobalAlias &) = delete;
  27. GlobalAlias(const GlobalAlias &) = delete;
  28. void setParent(Module *parent);
  29. GlobalAlias(PointerType *Ty, LinkageTypes Linkage, const Twine &Name,
  30. Constant *Aliasee, Module *Parent);
  31. public:
  32. // allocate space for exactly one operand
  33. void *operator new(size_t s) {
  34. return User::operator new(s, 1);
  35. }
  36. /// If a parent module is specified, the alias is automatically inserted into
  37. /// the end of the specified module's alias list.
  38. static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
  39. const Twine &Name, Constant *Aliasee,
  40. Module *Parent);
  41. // Without the Aliasee.
  42. static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
  43. const Twine &Name, Module *Parent);
  44. // The module is taken from the Aliasee.
  45. static GlobalAlias *create(PointerType *Ty, LinkageTypes Linkage,
  46. const Twine &Name, GlobalValue *Aliasee);
  47. // Type, Parent and AddressSpace taken from the Aliasee.
  48. static GlobalAlias *create(LinkageTypes Linkage, const Twine &Name,
  49. GlobalValue *Aliasee);
  50. // Linkage, Type, Parent and AddressSpace taken from the Aliasee.
  51. static GlobalAlias *create(const Twine &Name, GlobalValue *Aliasee);
  52. /// Provide fast operand accessors
  53. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
  54. /// removeFromParent - This method unlinks 'this' from the containing module,
  55. /// but does not delete it.
  56. ///
  57. void removeFromParent() override;
  58. /// eraseFromParent - This method unlinks 'this' from the containing module
  59. /// and deletes it.
  60. ///
  61. void eraseFromParent() override;
  62. /// These methods retrive and set alias target.
  63. void setAliasee(Constant *Aliasee);
  64. const Constant *getAliasee() const {
  65. return const_cast<GlobalAlias *>(this)->getAliasee();
  66. }
  67. Constant *getAliasee() {
  68. return getOperand(0);
  69. }
  70. const GlobalObject *getBaseObject() const {
  71. return const_cast<GlobalAlias *>(this)->getBaseObject();
  72. }
  73. GlobalObject *getBaseObject() {
  74. return dyn_cast<GlobalObject>(getAliasee()->stripInBoundsOffsets());
  75. }
  76. const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
  77. return const_cast<GlobalAlias *>(this)->getBaseObject(DL, Offset);
  78. }
  79. GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
  80. return dyn_cast<GlobalObject>(
  81. getAliasee()->stripAndAccumulateInBoundsConstantOffsets(DL, Offset));
  82. }
  83. static bool isValidLinkage(LinkageTypes L) {
  84. return isExternalLinkage(L) || isLocalLinkage(L) ||
  85. isWeakLinkage(L) || isLinkOnceLinkage(L);
  86. }
  87. // Methods for support type inquiry through isa, cast, and dyn_cast:
  88. static inline bool classof(const Value *V) {
  89. return V->getValueID() == Value::GlobalAliasVal;
  90. }
  91. };
  92. template <>
  93. struct OperandTraits<GlobalAlias> :
  94. public FixedNumOperandTraits<GlobalAlias, 1> {
  95. };
  96. DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalAlias, Constant)
  97. } // End llvm namespace
  98. #endif