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;
46
48 /// Name-mangler for global names.
49 Mangler *Mang = nullptr;
50
51protected:
56
57 /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
58 /// for EH.
59 unsigned PersonalityEncoding = 0;
60 unsigned LSDAEncoding = 0;
61 unsigned TTypeEncoding = 0;
62 unsigned CallSiteEncoding = 0;
63
64 /// This section contains the static constructor pointer list.
66
67 /// This section contains the static destructor pointer list.
69
70 const TargetMachine *TM = nullptr;
71
72public:
78
79 Mangler &getMangler() const { return *Mang; }
80
81 /// This method must be called before any actual lowering is done. This
82 /// specifies the current context for codegen, and gives the lowering
83 /// implementations a chance to set up their default sections.
84 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
85
86 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
87 const MCSymbol *Sym,
88 const MachineModuleInfo *MMI) const;
89
90 /// Emit the module-level metadata that the platform cares about.
91 virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}
92
93 /// Emit Call Graph Profile metadata.
94 void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const;
95
96 /// Emit pseudo_probe_desc metadata.
97 void emitPseudoProbeDescMetadata(MCStreamer &Streamer, Module &M,
98 std::function<void(MCStreamer &Streamer)>
99 COMDATSymEmitter = nullptr) const;
100
101 /// Process linker options metadata and emit platform-specific bits.
102 virtual void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const {}
103
104 /// Get the module-level metadata that the platform cares about.
105 virtual void getModuleMetadata(Module &M) {}
106
107 /// Given a constant with the SectionKind, return a section that it should be
108 /// placed in.
109 virtual MCSection *getSectionForConstant(const DataLayout &DL,
110 SectionKind Kind, const Constant *C,
111 Align &Alignment,
112 const Function *F) const;
113
114 /// Similar to the function above, but append \p SectionSuffix to the section
115 /// name.
116 virtual MCSection *getSectionForConstant(const DataLayout &DL,
117 SectionKind Kind, const Constant *C,
118 Align &Alignment, const Function *F,
119 StringRef SectionSuffix) const;
120
121 virtual MCSection *
122 getSectionForMachineBasicBlock(const Function &F,
123 const MachineBasicBlock &MBB,
124 const TargetMachine &TM) const;
125
126 virtual MCSection *
127 getUniqueSectionForFunction(const Function &F,
128 const TargetMachine &TM) const;
129
130 /// Classify the specified global variable into a set of target independent
131 /// categories embodied in SectionKind.
132 static SectionKind getKindForGlobal(const GlobalObject *GO,
133 const TargetMachine &TM);
134
135 /// Return the section name specified by '#pragma clang section' or the
136 /// section attribute.
137 static StringRef getCustomSectionName(const GlobalObject *GO,
138 const TargetMachine &TM);
139
140 /// This method computes the appropriate section to emit the specified global
141 /// variable or function definition. This should not be passed external (or
142 /// available externally) globals.
143 MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
144 const TargetMachine &TM) const;
145
146 /// This method computes the appropriate section to emit the specified global
147 /// variable or function definition. This should not be passed external (or
148 /// available externally) globals.
149 MCSection *SectionForGlobal(const GlobalObject *GO,
150 const TargetMachine &TM) const;
151
152 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
153 const GlobalValue *GV,
154 const TargetMachine &TM) const;
155
156 virtual MCSection *getSectionForJumpTable(const Function &F,
157 const TargetMachine &TM) const;
158 virtual MCSection *
159 getSectionForJumpTable(const Function &F, const TargetMachine &TM,
160 const MachineJumpTableEntry *JTE) const;
161
162 virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &,
163 const TargetMachine &) const {
164 return LSDASection;
165 }
166
167 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
168 const Function &F) const;
169
170 /// Targets should implement this method to assign a section to globals with
171 /// an explicit section specfied. The implementation of this method can
172 /// assume that GO->hasSection() is true.
173 virtual MCSection *
175 const TargetMachine &TM) const = 0;
176
177 /// Return an MCExpr to use for a reference to the specified global variable
178 /// from exception handling information.
179 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
180 unsigned Encoding,
181 const TargetMachine &TM,
183 MCStreamer &Streamer) const;
184
185 /// Return the MCSymbol for a private symbol with global value name as its
186 /// base, with the specified suffix.
188 StringRef Suffix,
189 const TargetMachine &TM) const;
190
191 // The symbol that gets passed to .cfi_personality.
193 const TargetMachine &TM,
194 MachineModuleInfo *MMI) const;
195
196 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
197 unsigned getLSDAEncoding() const { return LSDAEncoding; }
198 unsigned getTTypeEncoding() const { return TTypeEncoding; }
199 unsigned getCallSiteEncoding() const;
200
201 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
202 MCStreamer &Streamer) const;
203
204 virtual MCSection *getStaticCtorSection(unsigned Priority,
205 const MCSymbol *KeySym) const {
206 return StaticCtorSection;
207 }
208
209 virtual MCSection *getStaticDtorSection(unsigned Priority,
210 const MCSymbol *KeySym) const {
211 return StaticDtorSection;
212 }
213
214 /// Create a symbol reference to describe the given TLS variable when
215 /// emitting the address in debug info.
216 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
217
219 const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
220 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
221 return nullptr;
222 }
223
224 /// Target supports a PC-relative relocation that references the PLT of a
225 /// function.
227
229 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
230 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
231 return nullptr;
232 }
233
234 /// Target supports replacing a data "PC"-relative access to a symbol
235 /// through another symbol, by accessing the later via a GOT entry instead?
239
240 /// Target GOT "PC"-relative relocation supports encoding an additional
241 /// binary expression with an offset?
244 }
245
246 /// Target supports TLS offset relocation in debug section?
250
251 /// Returns the register used as static base in RWPI variants.
253
254 /// Get the target specific RWPI relocation.
255 virtual const MCExpr *getIndirectSymViaRWPI(const MCSymbol *Sym) const {
256 return nullptr;
257 }
258
259 /// Get the target specific PC relative GOT entry relocation
261 const MCSymbol *Sym,
262 const MCValue &MV,
263 int64_t Offset,
265 MCStreamer &Streamer) const {
266 return nullptr;
267 }
268
269 /// If supported, return the section to use for the llvm.commandline
270 /// metadata. Otherwise, return nullptr.
272 return nullptr;
273 }
274
275 /// On targets that use separate function descriptor symbols, return a section
276 /// for the descriptor given its symbol. Use only with defined functions.
277 virtual MCSection *
279 const TargetMachine &TM) const {
280 return nullptr;
281 }
282
283 /// On targets that support TOC entries, return a section for the entry given
284 /// the symbol it refers to.
285 /// TODO: Implement this interface for existing ELF targets.
287 const TargetMachine &TM) const {
288 return nullptr;
289 }
290
291 /// On targets that associate external references with a section, return such
292 /// a section for the given external global.
293 virtual MCSection *
295 const TargetMachine &TM) const {
296 return nullptr;
297 }
298
299 /// Targets that have a special convention for their symbols could use
300 /// this hook to return a specialized symbol.
302 const TargetMachine &TM) const {
303 return nullptr;
304 }
305
306 /// If supported, return the function entry point symbol.
307 /// Otherwise, returns nullptr.
308 /// Func must be a function or an alias which has a function as base object.
310 const TargetMachine &TM) const {
311 return nullptr;
312 }
313
314protected:
316 SectionKind Kind,
317 const TargetMachine &TM) const = 0;
318};
319
320} // end namespace llvm
321
322#endif // LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:215
#define F(x, y, z)
Definition MD5.cpp:54
Value * RHS
Value * LHS
This is an important base class in LLVM.
Definition Constant.h:43
Wrapper for a function that represents a value that functionally represents the original function.
Definition Constants.h:1143
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
static constexpr unsigned NoRegister
Definition MCRegister.h:60
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:573
Streaming machine code generation interface.
Definition MCStreamer.h:222
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:190
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:67
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 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const
Emit the module-level metadata that the platform cares about.
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.
virtual void getModuleMetadata(Module &M)
Get the module-level metadata that the platform cares about.
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 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 * getSectionForFunctionDescriptor(const GlobalObject *F, const TargetMachine &TM) const
On targets that use separate function descriptor symbols, return a section for the descriptor given i...
virtual void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const
Process linker options metadata and emit platform-specific bits.
TargetLoweringObjectFile(const TargetLoweringObjectFile &)=delete
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.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
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.