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 /// Emit the module flags that the platform cares about.
68 virtual void emitModuleFlags(MCStreamer &Streamer,
69 ArrayRef<Module::ModuleFlagEntry> Flags,
70 Mangler &Mang, const TargetMachine &TM) const {}
72 /// Given a constant with the SectionKind, return a section that it should be
74 virtual MCSection *getSectionForConstant(SectionKind Kind,
75 const Constant *C) const;
77 /// Classify the specified global variable into a set of target independent
78 /// categories embodied in SectionKind.
79 static SectionKind getKindForGlobal(const GlobalValue *GV,
80 const TargetMachine &TM);
82 /// This method computes the appropriate section to emit the specified global
83 /// variable or function definition. This should not be passed external (or
84 /// available externally) globals.
85 MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
86 Mangler &Mang, const TargetMachine &TM) const;
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, Mangler &Mang,
92 const TargetMachine &TM) const {
93 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
96 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
97 const GlobalValue *GV,
98 bool CannotUsePrivateLabel, Mangler &Mang,
99 const TargetMachine &TM) const;
101 virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
102 const TargetMachine &TM) const;
104 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
105 const Function &F) const;
107 /// Targets should implement this method to assign a section to globals with
108 /// an explicit section specfied. The implementation of this method can
109 /// assume that GV->hasSection() is true.
111 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
112 Mangler &Mang, const TargetMachine &TM) const = 0;
114 /// Allow the target to completely override section assignment of a global.
115 virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
117 Mangler &Mang) const {
121 /// Return an MCExpr to use for a reference to the specified global variable
122 /// from exception handling information.
123 virtual const MCExpr *
124 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
125 Mangler &Mang, const TargetMachine &TM,
126 MachineModuleInfo *MMI, MCStreamer &Streamer) const;
128 /// Return the MCSymbol for a private symbol with global value name as its
129 /// base, with the specified suffix.
130 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
131 StringRef Suffix, Mangler &Mang,
132 const TargetMachine &TM) const;
134 // The symbol that gets passed to .cfi_personality.
135 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
137 const TargetMachine &TM,
138 MachineModuleInfo *MMI) const;
141 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
142 MCStreamer &Streamer) const;
144 virtual MCSection *getStaticCtorSection(unsigned Priority,
145 const MCSymbol *KeySym) const {
146 return StaticCtorSection;
149 virtual MCSection *getStaticDtorSection(unsigned Priority,
150 const MCSymbol *KeySym) const {
151 return StaticDtorSection;
154 /// \brief Create a symbol reference to describe the given TLS variable when
155 /// emitting the address in debug info.
156 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
158 virtual const MCExpr *
159 getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
160 const TargetMachine &TM) const {
164 /// \brief Target supports replacing a data "PC"-relative access to a symbol
165 /// through another symbol, by accessing the later via a GOT entry instead?
166 bool supportIndirectSymViaGOTPCRel() const {
167 return SupportIndirectSymViaGOTPCRel;
170 /// \brief Target GOT "PC"-relative relocation supports encoding an additional
171 /// binary expression with an offset?
172 bool supportGOTPCRelWithOffset() const {
173 return SupportGOTPCRelWithOffset;
176 /// \brief Get the target specific PC relative GOT entry relocation
177 virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
180 MachineModuleInfo *MMI,
181 MCStreamer &Streamer) const {
185 virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
186 const Mangler &Mang) const {}
189 virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
190 SectionKind Kind, Mangler &Mang,
191 const TargetMachine &TM) const = 0;
194 } // end namespace llvm