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;
46 bool SupportIndirectSymViaGOTPCRel;
47 bool SupportGOTPCRelWithOffset;
50 MCContext &getContext() const { return *Ctx; }
52 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr),
53 SupportIndirectSymViaGOTPCRel(false),
54 SupportGOTPCRelWithOffset(true) {}
56 virtual ~TargetLoweringObjectFile();
58 /// This method must be called before any actual lowering is done. This
59 /// specifies the current context for codegen, and gives the lowering
60 /// implementations a chance to set up their default sections.
61 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
63 virtual void emitPersonalityValue(MCStreamer &Streamer,
64 const TargetMachine &TM,
65 const MCSymbol *Sym) const;
67 /// Extract the dependent library name from a linker option string. Returns
68 /// StringRef() if the option does not specify a library.
69 virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
73 /// Emit the module flags that the platform cares about.
74 virtual void emitModuleFlags(MCStreamer &Streamer,
75 ArrayRef<Module::ModuleFlagEntry> Flags,
76 Mangler &Mang, const TargetMachine &TM) const {}
78 /// Given a constant with the SectionKind, return a section that it should be
80 virtual MCSection *getSectionForConstant(SectionKind Kind,
81 const Constant *C) const;
83 /// Classify the specified global variable into a set of target independent
84 /// categories embodied in SectionKind.
85 static SectionKind getKindForGlobal(const GlobalValue *GV,
86 const TargetMachine &TM);
88 /// This method computes the appropriate section to emit the specified global
89 /// variable or function definition. This should not be passed external (or
90 /// available externally) globals.
91 MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
92 Mangler &Mang, const TargetMachine &TM) const;
94 /// This method computes the appropriate section to emit the specified global
95 /// variable or function definition. This should not be passed external (or
96 /// available externally) globals.
97 MCSection *SectionForGlobal(const GlobalValue *GV, Mangler &Mang,
98 const TargetMachine &TM) const {
99 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
102 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
103 const GlobalValue *GV,
104 bool CannotUsePrivateLabel, Mangler &Mang,
105 const TargetMachine &TM) const;
107 virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
108 const TargetMachine &TM) const;
110 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
111 const Function &F) const;
113 /// Targets should implement this method to assign a section to globals with
114 /// an explicit section specfied. The implementation of this method can
115 /// assume that GV->hasSection() is true.
117 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
118 Mangler &Mang, const TargetMachine &TM) const = 0;
120 /// Allow the target to completely override section assignment of a global.
121 virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
123 Mangler &Mang) const {
127 /// Return an MCExpr to use for a reference to the specified global variable
128 /// from exception handling information.
129 virtual const MCExpr *
130 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
131 Mangler &Mang, const TargetMachine &TM,
132 MachineModuleInfo *MMI, MCStreamer &Streamer) const;
134 /// Return the MCSymbol for a private symbol with global value name as its
135 /// base, with the specified suffix.
136 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
137 StringRef Suffix, Mangler &Mang,
138 const TargetMachine &TM) const;
140 // The symbol that gets passed to .cfi_personality.
141 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
143 const TargetMachine &TM,
144 MachineModuleInfo *MMI) const;
147 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
148 MCStreamer &Streamer) const;
150 virtual MCSection *getStaticCtorSection(unsigned Priority,
151 const MCSymbol *KeySym) const {
152 return StaticCtorSection;
155 virtual MCSection *getStaticDtorSection(unsigned Priority,
156 const MCSymbol *KeySym) const {
157 return StaticDtorSection;
160 /// \brief Create a symbol reference to describe the given TLS variable when
161 /// emitting the address in debug info.
162 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
164 virtual const MCExpr *
165 getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
166 const TargetMachine &TM) const {
170 /// \brief Target supports replacing a data "PC"-relative access to a symbol
171 /// through another symbol, by accessing the later via a GOT entry instead?
172 bool supportIndirectSymViaGOTPCRel() const {
173 return SupportIndirectSymViaGOTPCRel;
176 /// \brief Target GOT "PC"-relative relocation supports encoding an additional
177 /// binary expression with an offset?
178 bool supportGOTPCRelWithOffset() const {
179 return SupportGOTPCRelWithOffset;
182 /// \brief Get the target specific PC relative GOT entry relocation
183 virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
186 MachineModuleInfo *MMI,
187 MCStreamer &Streamer) const {
192 virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
193 SectionKind Kind, Mangler &Mang,
194 const TargetMachine &TM) const = 0;
197 } // end namespace llvm