TargetLoweringObjectFileImpl.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //==-- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info -*- 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 implements classes used to handle lowerings specific to common
  11. // object file formats.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
  15. #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/MC/SectionKind.h"
  18. #include "llvm/Target/TargetLoweringObjectFile.h"
  19. namespace llvm {
  20. class MachineModuleInfo;
  21. class Mangler;
  22. class MCAsmInfo;
  23. class MCExpr;
  24. class MCSection;
  25. class MCSectionMachO;
  26. class MCSymbol;
  27. class MCContext;
  28. class GlobalValue;
  29. class TargetMachine;
  30. class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
  31. bool UseInitArray;
  32. mutable unsigned NextUniqueID = 0;
  33. public:
  34. TargetLoweringObjectFileELF() : UseInitArray(false) {}
  35. ~TargetLoweringObjectFileELF() override {}
  36. void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM,
  37. const MCSymbol *Sym) const override;
  38. /// Given a constant with the SectionKind, return a section that it should be
  39. /// placed in.
  40. MCSection *getSectionForConstant(SectionKind Kind,
  41. const Constant *C) const override;
  42. MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
  43. Mangler &Mang,
  44. const TargetMachine &TM) const override;
  45. MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
  46. Mangler &Mang,
  47. const TargetMachine &TM) const override;
  48. MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
  49. const TargetMachine &TM) const override;
  50. bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
  51. const Function &F) const override;
  52. /// Return an MCExpr to use for a reference to the specified type info global
  53. /// variable from exception handling information.
  54. const MCExpr *
  55. getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
  56. Mangler &Mang, const TargetMachine &TM,
  57. MachineModuleInfo *MMI,
  58. MCStreamer &Streamer) const override;
  59. // The symbol that gets passed to .cfi_personality.
  60. MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
  61. const TargetMachine &TM,
  62. MachineModuleInfo *MMI) const override;
  63. void InitializeELF(bool UseInitArray_);
  64. MCSection *getStaticCtorSection(unsigned Priority,
  65. const MCSymbol *KeySym) const override;
  66. MCSection *getStaticDtorSection(unsigned Priority,
  67. const MCSymbol *KeySym) const override;
  68. };
  69. class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
  70. public:
  71. ~TargetLoweringObjectFileMachO() override {}
  72. TargetLoweringObjectFileMachO();
  73. /// Emit the module flags that specify the garbage collection information.
  74. void emitModuleFlags(MCStreamer &Streamer,
  75. ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
  76. Mangler &Mang, const TargetMachine &TM) const override;
  77. MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
  78. Mangler &Mang,
  79. const TargetMachine &TM) const override;
  80. MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
  81. Mangler &Mang,
  82. const TargetMachine &TM) const override;
  83. MCSection *getSectionForConstant(SectionKind Kind,
  84. const Constant *C) const override;
  85. /// The mach-o version of this method defaults to returning a stub reference.
  86. const MCExpr *
  87. getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
  88. Mangler &Mang, const TargetMachine &TM,
  89. MachineModuleInfo *MMI,
  90. MCStreamer &Streamer) const override;
  91. // The symbol that gets passed to .cfi_personality.
  92. MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
  93. const TargetMachine &TM,
  94. MachineModuleInfo *MMI) const override;
  95. /// Get MachO PC relative GOT entry relocation
  96. const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
  97. const MCValue &MV, int64_t Offset,
  98. MachineModuleInfo *MMI,
  99. MCStreamer &Streamer) const override;
  100. };
  101. class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
  102. public:
  103. ~TargetLoweringObjectFileCOFF() override {}
  104. MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
  105. Mangler &Mang,
  106. const TargetMachine &TM) const override;
  107. MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
  108. Mangler &Mang,
  109. const TargetMachine &TM) const override;
  110. void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
  111. bool CannotUsePrivateLabel, Mangler &Mang,
  112. const TargetMachine &TM) const override;
  113. MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
  114. const TargetMachine &TM) const override;
  115. /// Emit Obj-C garbage collection and linker options. Only linker option
  116. /// emission is implemented for COFF.
  117. void emitModuleFlags(MCStreamer &Streamer,
  118. ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
  119. Mangler &Mang, const TargetMachine &TM) const override;
  120. MCSection *getStaticCtorSection(unsigned Priority,
  121. const MCSymbol *KeySym) const override;
  122. MCSection *getStaticDtorSection(unsigned Priority,
  123. const MCSymbol *KeySym) const override;
  124. void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
  125. const Mangler &Mang) const override;
  126. };
  127. } // end namespace llvm
  128. #endif