TargetLoweringObjectFile.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //===-- llvm/Target/TargetLoweringObjectFile.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_TARGET_TARGETLOWERINGOBJECTFILE_H
  15. #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
  16. #include "llvm/ADT/ArrayRef.h"
  17. #include "llvm/IR/Module.h"
  18. #include "llvm/MC/MCObjectFileInfo.h"
  19. #include "llvm/MC/SectionKind.h"
  20. namespace llvm {
  21. class MachineModuleInfo;
  22. class Mangler;
  23. class MCContext;
  24. class MCExpr;
  25. class MCSection;
  26. class MCSymbol;
  27. class MCSymbolRefExpr;
  28. class MCStreamer;
  29. class MCValue;
  30. class ConstantExpr;
  31. class GlobalValue;
  32. class TargetMachine;
  33. class TargetLoweringObjectFile : public MCObjectFileInfo {
  34. MCContext *Ctx;
  35. TargetLoweringObjectFile(
  36. const TargetLoweringObjectFile&) = delete;
  37. void operator=(const TargetLoweringObjectFile&) = delete;
  38. protected:
  39. const DataLayout *DL;
  40. bool SupportIndirectSymViaGOTPCRel;
  41. bool SupportGOTPCRelWithOffset;
  42. public:
  43. MCContext &getContext() const { return *Ctx; }
  44. TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr),
  45. SupportIndirectSymViaGOTPCRel(false),
  46. SupportGOTPCRelWithOffset(true) {}
  47. virtual ~TargetLoweringObjectFile();
  48. /// This method must be called before any actual lowering is done. This
  49. /// specifies the current context for codegen, and gives the lowering
  50. /// implementations a chance to set up their default sections.
  51. virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
  52. virtual void emitPersonalityValue(MCStreamer &Streamer,
  53. const TargetMachine &TM,
  54. const MCSymbol *Sym) const;
  55. /// Emit the module flags that the platform cares about.
  56. virtual void emitModuleFlags(MCStreamer &Streamer,
  57. ArrayRef<Module::ModuleFlagEntry> Flags,
  58. Mangler &Mang, const TargetMachine &TM) const {}
  59. /// Given a constant with the SectionKind, return a section that it should be
  60. /// placed in.
  61. virtual MCSection *getSectionForConstant(SectionKind Kind,
  62. const Constant *C) const;
  63. /// Classify the specified global variable into a set of target independent
  64. /// categories embodied in SectionKind.
  65. static SectionKind getKindForGlobal(const GlobalValue *GV,
  66. const TargetMachine &TM);
  67. /// This method computes the appropriate section to emit the specified global
  68. /// variable or function definition. This should not be passed external (or
  69. /// available externally) globals.
  70. MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
  71. Mangler &Mang, const TargetMachine &TM) const;
  72. /// This method computes the appropriate section to emit the specified global
  73. /// variable or function definition. This should not be passed external (or
  74. /// available externally) globals.
  75. MCSection *SectionForGlobal(const GlobalValue *GV, Mangler &Mang,
  76. const TargetMachine &TM) const {
  77. return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
  78. }
  79. virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
  80. const GlobalValue *GV,
  81. bool CannotUsePrivateLabel, Mangler &Mang,
  82. const TargetMachine &TM) const;
  83. virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
  84. const TargetMachine &TM) const;
  85. virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
  86. const Function &F) const;
  87. /// Targets should implement this method to assign a section to globals with
  88. /// an explicit section specfied. The implementation of this method can
  89. /// assume that GV->hasSection() is true.
  90. virtual MCSection *
  91. getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
  92. Mangler &Mang, const TargetMachine &TM) const = 0;
  93. /// Allow the target to completely override section assignment of a global.
  94. virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
  95. SectionKind Kind,
  96. Mangler &Mang) const {
  97. return nullptr;
  98. }
  99. /// Return an MCExpr to use for a reference to the specified global variable
  100. /// from exception handling information.
  101. virtual const MCExpr *
  102. getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
  103. Mangler &Mang, const TargetMachine &TM,
  104. MachineModuleInfo *MMI, MCStreamer &Streamer) const;
  105. /// Return the MCSymbol for a private symbol with global value name as its
  106. /// base, with the specified suffix.
  107. MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
  108. StringRef Suffix, Mangler &Mang,
  109. const TargetMachine &TM) const;
  110. // The symbol that gets passed to .cfi_personality.
  111. virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
  112. Mangler &Mang,
  113. const TargetMachine &TM,
  114. MachineModuleInfo *MMI) const;
  115. const MCExpr *
  116. getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
  117. MCStreamer &Streamer) const;
  118. virtual MCSection *getStaticCtorSection(unsigned Priority,
  119. const MCSymbol *KeySym) const {
  120. return StaticCtorSection;
  121. }
  122. virtual MCSection *getStaticDtorSection(unsigned Priority,
  123. const MCSymbol *KeySym) const {
  124. return StaticDtorSection;
  125. }
  126. /// \brief Create a symbol reference to describe the given TLS variable when
  127. /// emitting the address in debug info.
  128. virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
  129. virtual const MCExpr *
  130. getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
  131. const TargetMachine &TM) const {
  132. return nullptr;
  133. }
  134. /// \brief Target supports replacing a data "PC"-relative access to a symbol
  135. /// through another symbol, by accessing the later via a GOT entry instead?
  136. bool supportIndirectSymViaGOTPCRel() const {
  137. return SupportIndirectSymViaGOTPCRel;
  138. }
  139. /// \brief Target GOT "PC"-relative relocation supports encoding an additional
  140. /// binary expression with an offset?
  141. bool supportGOTPCRelWithOffset() const {
  142. return SupportGOTPCRelWithOffset;
  143. }
  144. /// \brief Get the target specific PC relative GOT entry relocation
  145. virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
  146. const MCValue &MV,
  147. int64_t Offset,
  148. MachineModuleInfo *MMI,
  149. MCStreamer &Streamer) const {
  150. return nullptr;
  151. }
  152. virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
  153. const Mangler &Mang) const {}
  154. protected:
  155. virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
  156. SectionKind Kind, Mangler &Mang,
  157. const TargetMachine &TM) const = 0;
  158. };
  159. } // end namespace llvm
  160. #endif