LLVM 24.0.0git
TargetLoweringObjectFile.h
Go to the documentation of this file.
1//===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements classes used to handle lowerings specific to common
10// object file formats.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
15#define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16
18#include "llvm/MC/MCRegister.h"
20#include <cstdint>
21
22namespace llvm {
23
24struct Align;
26class Constant;
27class DataLayout;
28class Function;
29class GlobalObject;
30class GlobalValue;
33class Mangler;
34class MCContext;
35class MCExpr;
36class MCSection;
37class MCSymbol;
38class MCSymbolRefExpr;
39class MCStreamer;
40class MCValue;
41class Module;
42class SectionKind;
43class StringRef;
44class TargetMachine;
45
47 /// Name-mangler for global names.
48 Mangler *Mang = nullptr;
49
50protected:
55
56 /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
57 /// for EH.
58 unsigned PersonalityEncoding = 0;
59 unsigned LSDAEncoding = 0;
60 unsigned TTypeEncoding = 0;
61 unsigned CallSiteEncoding = 0;
62
63 /// This section contains the static constructor pointer list.
65
66 /// This section contains the static destructor pointer list.
68
69 const TargetMachine *TM = nullptr;
70
71public:
77
78 Mangler &getMangler() const { return *Mang; }
79
80 /// This method must be called before any actual lowering is done. This
81 /// specifies the current context for codegen, and gives the lowering
82 /// implementations a chance to set up their default sections and to inspect
83 /// the module-level metadata the platform cares about.
84 virtual void initialize(MCContext &ctx, const TargetMachine &TM,
85 const Module &M);
86
87 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
88 const MCSymbol *Sym,
89 const MachineModuleInfo *MMI) const;
90
91 /// Emit the module-level metadata that the platform cares about.
92 virtual void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const {
93 }
94
95 /// Get a section with the given name and kind, using format-appropriate
96 /// defaults for section flags.
97 /// Returns nullptr if not supported by this object file format.
98 virtual MCSection *getNamedSection(StringRef Name, SectionKind Kind) const {
99 return nullptr;
100 }
101
102 /// Emit Call Graph Profile metadata.
103 void emitCGProfileMetadata(MCStreamer &Streamer, const Module &M) const;
104
105 /// Emit pseudo_probe_desc metadata.
106 void emitPseudoProbeDescMetadata(MCStreamer &Streamer, const Module &M,
107 std::function<void(MCStreamer &Streamer)>
108 COMDATSymEmitter = nullptr) const;
109
110 /// Process linker options metadata and emit platform-specific bits.
112 const Module &M) const {}
113
114 /// Given a constant with the SectionKind, return a section that it should be
115 /// placed in.
116 virtual MCSection *getSectionForConstant(const DataLayout &DL,
117 SectionKind Kind, const Constant *C,
118 Align &Alignment,
119 const Function *F) const;
120
121 /// Similar to the function above, but append \p SectionSuffix to the section
122 /// name.
123 virtual MCSection *getSectionForConstant(const DataLayout &DL,
124 SectionKind Kind, const Constant *C,
125 Align &Alignment, const Function *F,
126 StringRef SectionSuffix) const;
127
128 virtual MCSection *
129 getSectionForMachineBasicBlock(const Function &F,
130 const MachineBasicBlock &MBB,
131 const TargetMachine &TM) const;
132
133 virtual MCSection *
134 getUniqueSectionForFunction(const Function &F,
135 const TargetMachine &TM) const;
136
137 /// Classify the specified global variable into a set of target independent
138 /// categories embodied in SectionKind.
139 static SectionKind getKindForGlobal(const GlobalObject *GO,
140 const TargetMachine &TM);
141
142 /// Return the section name specified by '#pragma clang section' or the
143 /// section attribute.
144 static StringRef getCustomSectionName(const GlobalObject *GO,
145 const TargetMachine &TM);
146
147 /// This method computes the appropriate section to emit the specified global
148 /// variable or function definition. This should not be passed external (or
149 /// available externally) globals.
150 MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
151 const TargetMachine &TM) const;
152
153 /// This method computes the appropriate section to emit the specified global
154 /// variable or function definition. This should not be passed external (or
155 /// available externally) globals.
156 MCSection *SectionForGlobal(const GlobalObject *GO,
157 const TargetMachine &TM) const;
158
159 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
160 const GlobalValue *GV,
161 const TargetMachine &TM) const;
162
163 virtual MCSection *getSectionForJumpTable(const Function &F,
164 const TargetMachine &TM) const;
165 virtual MCSection *
166 getSectionForJumpTable(const Function &F, const TargetMachine &TM,
167 const MachineJumpTableEntry *JTE) const;
168
169 virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &,
170 const TargetMachine &) const {
171 return LSDASection;
172 }
173
174 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
175 const Function &F) const;
176
177 /// Targets should implement this method to assign a section to globals with
178 /// an explicit section specfied. The implementation of this method can
179 /// assume that GO->hasSection() is true.
180 virtual MCSection *
182 const TargetMachine &TM) const = 0;
183
184 /// Return an MCExpr to use for a reference to the specified global variable
185 /// from exception handling information.
186 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
187 unsigned Encoding,
188 const TargetMachine &TM,
190 MCStreamer &Streamer) const;
191
192 /// Return the MCSymbol for a private symbol with global value name as its
193 /// base, with the specified suffix.
195 StringRef Suffix,
196 const TargetMachine &TM) const;
197
198 // The symbol that gets passed to .cfi_personality.
200 const TargetMachine &TM,
201 MachineModuleInfo *MMI) const;
202
203 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
204 unsigned getLSDAEncoding() const { return LSDAEncoding; }
205 unsigned getTTypeEncoding() const { return TTypeEncoding; }
206 unsigned getCallSiteEncoding() const;
207
208 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
209 MCStreamer &Streamer) const;
210
211 virtual MCSection *getStaticCtorSection(unsigned Priority,
212 const MCSymbol *KeySym) const {
213 return StaticCtorSection;
214 }
215
216 virtual MCSection *getStaticDtorSection(unsigned Priority,
217 const MCSymbol *KeySym) const {
218 return StaticDtorSection;
219 }
220
221 /// Create a symbol reference to describe the given TLS variable when
222 /// emitting the address in debug info.
223 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
224
226 const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
227 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
228 return nullptr;
229 }
230
231 /// Target supports a PC-relative relocation that references the PLT of a
232 /// function.
234
236 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
237 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
238 return nullptr;
239 }
240
241 /// Target supports replacing a data "PC"-relative access to a symbol
242 /// through another symbol, by accessing the later via a GOT entry instead?
246
247 /// Target GOT "PC"-relative relocation supports encoding an additional
248 /// binary expression with an offset?
251 }
252
253 /// Target supports TLS offset relocation in debug section?
257
258 /// Returns the register used as static base in RWPI variants.
260
261 /// Get the target specific RWPI relocation.
262 virtual const MCExpr *getIndirectSymViaRWPI(const MCSymbol *Sym) const {
263 return nullptr;
264 }
265
266 /// Get the target specific PC relative GOT entry relocation
268 const MCSymbol *Sym,
269 const MCValue &MV,
270 int64_t Offset,
272 MCStreamer &Streamer) const {
273 return nullptr;
274 }
275
276 /// If supported, return the section to use for the llvm.commandline
277 /// metadata. Otherwise, return nullptr.
279 return nullptr;
280 }
281
282 /// On targets that use separate function descriptor symbols, return a section
283 /// for the descriptor given its symbol. Use only with defined functions.
284 virtual MCSection *
286 const TargetMachine &TM) const {
287 return nullptr;
288 }
289
290 /// On targets that support TOC entries, return a section for the entry given
291 /// the symbol it refers to.
292 /// TODO: Implement this interface for existing ELF targets.
294 const TargetMachine &TM) const {
295 return nullptr;
296 }
297
298 /// On targets that associate external references with a section, return such
299 /// a section for the given external global.
300 virtual MCSection *
302 const TargetMachine &TM) const {
303 return nullptr;
304 }
305
306 /// Targets that have a special convention for their symbols could use
307 /// this hook to return a specialized symbol.
309 const TargetMachine &TM) const {
310 return nullptr;
311 }
312
313 /// If supported, return the function entry point symbol.
314 /// Otherwise, returns nullptr.
315 /// Func must be a function or an alias which has a function as base object.
317 const TargetMachine &TM) const {
318 return nullptr;
319 }
320
321protected:
323 SectionKind Kind,
324 const TargetMachine &TM) const = 0;
325};
326
327} // end namespace llvm
328
329#endif // LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
#define F(x, y, z)
Definition MD5.cpp:54
std::unique_ptr< MCStreamer > && Streamer
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
Value * RHS
Value * LHS
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
Context object for machine code objects.
Definition MCContext.h:84
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:31
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
Wrapper class representing physical registers and target specific virtual registers.
Definition MCRegister.h:42
static constexpr unsigned NoRegister
Definition MCRegister.h:62
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:577
Streaming machine code generation interface.
Definition MCStreamer.h:221
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:187
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
This class contains meta information specific to a module.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition SectionKind.h:22
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
virtual const MCExpr * lowerDSOLocalEquivalent(const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend, std::optional< int64_t > PCRelativeOffset, const TargetMachine &TM) const
virtual MCRegister getStaticBase() const
Returns the register used as static base in RWPI variants.
virtual MCSection * getSectionForCommandLines() const
If supported, return the section to use for the llvm.commandline metadata.
unsigned PersonalityEncoding
PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values for EH.
virtual MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const
virtual const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Get the target specific PC relative GOT entry relocation.
TargetLoweringObjectFile & operator=(const TargetLoweringObjectFile &)=delete
virtual MCSection * getSectionForExternalReference(const GlobalObject *GO, const TargetMachine &TM) const
On targets that associate external references with a section, return such a section for the given ext...
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const
bool hasPLTPCRelative() const
Target supports a PC-relative relocation that references the PLT of a function.
bool supportDebugThreadLocalLocation() const
Target supports TLS offset relocation in debug section?
MCSection * StaticCtorSection
This section contains the static constructor pointer list.
virtual MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const =0
virtual const MCExpr * getIndirectSymViaRWPI(const MCSymbol *Sym) const
Get the target specific RWPI relocation.
virtual const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend, std::optional< int64_t > PCRelativeOffset, const TargetMachine &TM) const
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix, const TargetMachine &TM) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
virtual MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const
virtual MCSection * getSectionForTOCEntry(const MCSymbol *S, const TargetMachine &TM) const
On targets that support TOC entries, return a section for the entry given the symbol it refers to.
bool supportGOTPCRelWithOffset() const
Target GOT "PC"-relative relocation supports encoding an additional binary expression with an offset?
virtual MCSection * getSectionForLSDA(const Function &, const MCSymbol &, const TargetMachine &) const
bool supportIndirectSymViaGOTPCRel() const
Target supports replacing a data "PC"-relative access to a symbol through another symbol,...
virtual void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const
Emit the module-level metadata that the platform cares about.
virtual const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Return an MCExpr to use for a reference to the specified global variable from exception handling info...
virtual MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const =0
Targets should implement this method to assign a section to globals with an explicit section specfied...
virtual MCSymbol * getFunctionEntryPointSymbol(const GlobalValue *Func, const TargetMachine &TM) const
If supported, return the function entry point symbol.
virtual MCSection * getNamedSection(StringRef Name, SectionKind Kind) const
Get a section with the given name and kind, using format-appropriate defaults for section flags.
virtual MCSection * getSectionForFunctionDescriptor(const GlobalObject *F, const TargetMachine &TM) const
On targets that use separate function descriptor symbols, return a section for the descriptor given i...
TargetLoweringObjectFile(const TargetLoweringObjectFile &)=delete
virtual void emitLinkerDirectives(MCStreamer &Streamer, const Module &M) const
Process linker options metadata and emit platform-specific bits.
virtual MCSymbol * getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const
Targets that have a special convention for their symbols could use this hook to return a specialized ...
Primary interface to the complete machine description for the target machine.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
MachineJumpTableEntry - One jump table in the jump table info.