GlobalObject.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //===-- llvm/GlobalObject.h - Class to represent global objects -*- 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 represents an independent object. That is, a function or a global
  11. // variable, but not an alias.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_IR_GLOBALOBJECT_H
  15. #define LLVM_IR_GLOBALOBJECT_H
  16. #include "llvm/IR/Constant.h"
  17. #include "llvm/IR/DerivedTypes.h"
  18. #include "llvm/IR/GlobalValue.h"
  19. namespace llvm {
  20. class Comdat;
  21. class Module;
  22. class GlobalObject : public GlobalValue {
  23. GlobalObject(const GlobalObject &) = delete;
  24. protected:
  25. GlobalObject(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
  26. LinkageTypes Linkage, const Twine &Name)
  27. : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name), ObjComdat(nullptr) {
  28. setGlobalValueSubClassData(0);
  29. }
  30. std::string Section; // Section to emit this into, empty means default
  31. Comdat *ObjComdat;
  32. static const unsigned AlignmentBits = 5;
  33. static const unsigned GlobalObjectSubClassDataBits =
  34. GlobalValueSubClassDataBits - AlignmentBits;
  35. private:
  36. static const unsigned AlignmentMask = (1 << AlignmentBits) - 1;
  37. public:
  38. unsigned getAlignment() const {
  39. unsigned Data = getGlobalValueSubClassData();
  40. unsigned AlignmentData = Data & AlignmentMask;
  41. return (1u << AlignmentData) >> 1;
  42. }
  43. void setAlignment(unsigned Align);
  44. unsigned getGlobalObjectSubClassData() const;
  45. void setGlobalObjectSubClassData(unsigned Val);
  46. bool hasSection() const { return !StringRef(getSection()).empty(); }
  47. const char *getSection() const { return Section.c_str(); }
  48. void setSection(StringRef S);
  49. bool hasComdat() const { return getComdat() != nullptr; }
  50. const Comdat *getComdat() const { return ObjComdat; }
  51. Comdat *getComdat() { return ObjComdat; }
  52. void setComdat(Comdat *C) { ObjComdat = C; }
  53. void copyAttributesFrom(const GlobalValue *Src) override;
  54. // Methods for support type inquiry through isa, cast, and dyn_cast:
  55. static inline bool classof(const Value *V) {
  56. return V->getValueID() == Value::FunctionVal ||
  57. V->getValueID() == Value::GlobalVariableVal;
  58. }
  59. };
  60. } // End llvm namespace
  61. #endif