1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
21 #include "llvm/MC/SectionKind.h"
24 class MachineModuleInfo;
30 class MCSymbolRefExpr;
37 class TargetLoweringObjectFile : public MCObjectFileInfo {
40 TargetLoweringObjectFile(
41 const TargetLoweringObjectFile&) = delete;
42 void operator=(const TargetLoweringObjectFile&) = delete;
45 bool SupportIndirectSymViaGOTPCRel;
46 bool SupportGOTPCRelWithOffset;
49 MCContext &getContext() const { return *Ctx; }
51 TargetLoweringObjectFile()
52 : MCObjectFileInfo(), Ctx(nullptr), SupportIndirectSymViaGOTPCRel(false),
53 SupportGOTPCRelWithOffset(true) {}
55 virtual ~TargetLoweringObjectFile();
57 /// This method must be called before any actual lowering is done. This
58 /// specifies the current context for codegen, and gives the lowering
59 /// implementations a chance to set up their default sections.
60 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
62 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
63 const MCSymbol *Sym) const;
65 /// Emit the module flags that the platform cares about.
66 virtual void emitModuleFlags(MCStreamer &Streamer,
67 ArrayRef<Module::ModuleFlagEntry> Flags,
68 Mangler &Mang, const TargetMachine &TM) const {}
70 /// Given a constant with the SectionKind, return a section that it should be
72 virtual MCSection *getSectionForConstant(const DataLayout &DL,
74 const Constant *C) const;
76 /// Classify the specified global variable into a set of target independent
77 /// categories embodied in SectionKind.
78 static SectionKind getKindForGlobal(const GlobalValue *GV,
79 const TargetMachine &TM);
81 /// This method computes the appropriate section to emit the specified global
82 /// variable or function definition. This should not be passed external (or
83 /// available externally) globals.
84 MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
85 Mangler &Mang, const TargetMachine &TM) const;
87 /// This method computes the appropriate section to emit the specified global
88 /// variable or function definition. This should not be passed external (or
89 /// available externally) globals.
90 MCSection *SectionForGlobal(const GlobalValue *GV, Mangler &Mang,
91 const TargetMachine &TM) const {
92 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
95 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
96 const GlobalValue *GV,
97 bool CannotUsePrivateLabel, Mangler &Mang,
98 const TargetMachine &TM) const;
100 virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
101 const TargetMachine &TM) const;
103 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
104 const Function &F) const;
106 /// Targets should implement this method to assign a section to globals with
107 /// an explicit section specfied. The implementation of this method can
108 /// assume that GV->hasSection() is true.
110 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
111 Mangler &Mang, const TargetMachine &TM) const = 0;
113 /// Allow the target to completely override section assignment of a global.
114 virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
116 Mangler &Mang) const {
120 /// Return an MCExpr to use for a reference to the specified global variable
121 /// from exception handling information.
122 virtual const MCExpr *
123 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
124 Mangler &Mang, const TargetMachine &TM,
125 MachineModuleInfo *MMI, MCStreamer &Streamer) const;
127 /// Return the MCSymbol for a private symbol with global value name as its
128 /// base, with the specified suffix.
129 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
130 StringRef Suffix, Mangler &Mang,
131 const TargetMachine &TM) const;
133 // The symbol that gets passed to .cfi_personality.
134 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
136 const TargetMachine &TM,
137 MachineModuleInfo *MMI) const;
140 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
141 MCStreamer &Streamer) const;
143 virtual MCSection *getStaticCtorSection(unsigned Priority,
144 const MCSymbol *KeySym) const {
145 return StaticCtorSection;
148 virtual MCSection *getStaticDtorSection(unsigned Priority,
149 const MCSymbol *KeySym) const {
150 return StaticDtorSection;
153 /// \brief Create a symbol reference to describe the given TLS variable when
154 /// emitting the address in debug info.
155 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
157 virtual const MCExpr *
158 getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
159 const TargetMachine &TM) const {
163 /// \brief Target supports replacing a data "PC"-relative access to a symbol
164 /// through another symbol, by accessing the later via a GOT entry instead?
165 bool supportIndirectSymViaGOTPCRel() const {
166 return SupportIndirectSymViaGOTPCRel;
169 /// \brief Target GOT "PC"-relative relocation supports encoding an additional
170 /// binary expression with an offset?
171 bool supportGOTPCRelWithOffset() const {
172 return SupportGOTPCRelWithOffset;
175 /// \brief Get the target specific PC relative GOT entry relocation
176 virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
179 MachineModuleInfo *MMI,
180 MCStreamer &Streamer) const {
184 virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
185 const Mangler &Mang) const {}
188 virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
189 SectionKind Kind, Mangler &Mang,
190 const TargetMachine &TM) const = 0;
193 } // end namespace llvm