GlobalIndirectSymbol.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //===- llvm/GlobalIndirectSymbol.h - GlobalIndirectSymbol 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 GlobalIndirectSymbol class, which
  10. // is a base class for GlobalAlias and GlobalIFunc. It contains all common code
  11. // for aliases and ifuncs.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_IR_GLOBALINDIRECTSYMBOL_H
  15. #define LLVM_IR_GLOBALINDIRECTSYMBOL_H
  16. #include "llvm/IR/GlobalObject.h"
  17. #include "llvm/IR/GlobalValue.h"
  18. #include "llvm/IR/OperandTraits.h"
  19. #include "llvm/IR/User.h"
  20. #include "llvm/IR/Value.h"
  21. #include "llvm/Support/Casting.h"
  22. #include <cstddef>
  23. namespace llvm {
  24. class GlobalIndirectSymbol : public GlobalValue {
  25. protected:
  26. GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace,
  27. LinkageTypes Linkage, const Twine &Name, Constant *Symbol);
  28. public:
  29. GlobalIndirectSymbol(const GlobalIndirectSymbol &) = delete;
  30. GlobalIndirectSymbol &operator=(const GlobalIndirectSymbol &) = delete;
  31. // allocate space for exactly one operand
  32. void *operator new(size_t s) {
  33. return User::operator new(s, 1);
  34. }
  35. /// Provide fast operand accessors
  36. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
  37. void copyAttributesFrom(const GlobalValue *Src) {
  38. GlobalValue::copyAttributesFrom(Src);
  39. }
  40. /// These methods set and retrieve indirect symbol.
  41. void setIndirectSymbol(Constant *Symbol) {
  42. setOperand(0, Symbol);
  43. }
  44. const Constant *getIndirectSymbol() const {
  45. return getOperand(0);
  46. }
  47. Constant *getIndirectSymbol() {
  48. return const_cast<Constant *>(
  49. static_cast<const GlobalIndirectSymbol *>(this)->getIndirectSymbol());
  50. }
  51. const GlobalObject *getBaseObject() const;
  52. GlobalObject *getBaseObject() {
  53. return const_cast<GlobalObject *>(
  54. static_cast<const GlobalIndirectSymbol *>(this)->getBaseObject());
  55. }
  56. const GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) const {
  57. return dyn_cast<GlobalObject>(
  58. getIndirectSymbol()->stripAndAccumulateInBoundsConstantOffsets(DL,
  59. Offset));
  60. }
  61. GlobalObject *getBaseObject(const DataLayout &DL, APInt &Offset) {
  62. return const_cast<GlobalObject *>(
  63. static_cast<const GlobalIndirectSymbol *>(this)
  64. ->getBaseObject(DL, Offset));
  65. }
  66. // Methods for support type inquiry through isa, cast, and dyn_cast:
  67. static bool classof(const Value *V) {
  68. return V->getValueID() == Value::GlobalAliasVal ||
  69. V->getValueID() == Value::GlobalIFuncVal;
  70. }
  71. };
  72. template <>
  73. struct OperandTraits<GlobalIndirectSymbol> :
  74. public FixedNumOperandTraits<GlobalIndirectSymbol, 1> {
  75. };
  76. DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GlobalIndirectSymbol, Constant)
  77. } // end namespace llvm
  78. #endif // LLVM_IR_GLOBALINDIRECTSYMBOL_H