LLVM 23.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 /// This method computes the appropriate section to emit the specified global
136 /// variable or function definition. This should not be passed external (or
137 /// available externally) globals.
138 MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
139 const TargetMachine &TM) const;
140
141 /// This method computes the appropriate section to emit the specified global
142 /// variable or function definition. This should not be passed external (or
143 /// available externally) globals.
144 MCSection *SectionForGlobal(const GlobalObject *GO,
145 const TargetMachine &TM) const;
146
147 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
148 const GlobalValue *GV,
149 const TargetMachine &TM) const;
150
151 virtual MCSection *getSectionForJumpTable(const Function &F,
152 const TargetMachine &TM) const;
153 virtual MCSection *
154 getSectionForJumpTable(const Function &F, const TargetMachine &TM,
155 const MachineJumpTableEntry *JTE) const;
156
157 virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &,
158 const TargetMachine &) const {
159 return LSDASection;
160 }
161
162 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
163 const Function &F) const;
164
165 /// Targets should implement this method to assign a section to globals with
166 /// an explicit section specfied. The implementation of this method can
167 /// assume that GO->hasSection() is true.
168 virtual MCSection *
170 const TargetMachine &TM) const = 0;
171
172 /// Return an MCExpr to use for a reference to the specified global variable
173 /// from exception handling information.
174 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
175 unsigned Encoding,
176 const TargetMachine &TM,
178 MCStreamer &Streamer) const;
179
180 /// Return the MCSymbol for a private symbol with global value name as its
181 /// base, with the specified suffix.
183 StringRef Suffix,
184 const TargetMachine &TM) const;
185
186 // The symbol that gets passed to .cfi_personality.
188 const TargetMachine &TM,
189 MachineModuleInfo *MMI) const;
190
191 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
192 unsigned getLSDAEncoding() const { return LSDAEncoding; }
193 unsigned getTTypeEncoding() const { return TTypeEncoding; }
194 unsigned getCallSiteEncoding() const;
195
196 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
197 MCStreamer &Streamer) const;
198
199 virtual MCSection *getStaticCtorSection(unsigned Priority,
200 const MCSymbol *KeySym) const {
201 return StaticCtorSection;
202 }
203
204 virtual MCSection *getStaticDtorSection(unsigned Priority,
205 const MCSymbol *KeySym) const {
206 return StaticDtorSection;
207 }
208
209 /// Create a symbol reference to describe the given TLS variable when
210 /// emitting the address in debug info.
211 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
212
214 const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
215 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
216 return nullptr;
217 }
218
219 /// Target supports a PC-relative relocation that references the PLT of a
220 /// function.
222
224 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
225 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
226 return nullptr;
227 }
228
229 /// Target supports replacing a data "PC"-relative access to a symbol
230 /// through another symbol, by accessing the later via a GOT entry instead?
234
235 /// Target GOT "PC"-relative relocation supports encoding an additional
236 /// binary expression with an offset?
239 }
240
241 /// Target supports TLS offset relocation in debug section?
245
246 /// Returns the register used as static base in RWPI variants.
248
249 /// Get the target specific RWPI relocation.
250 virtual const MCExpr *getIndirectSymViaRWPI(const MCSymbol *Sym) const {
251 return nullptr;
252 }
253
254 /// Get the target specific PC relative GOT entry relocation
256 const MCSymbol *Sym,
257 const MCValue &MV,
258 int64_t Offset,
260 MCStreamer &Streamer) const {
261 return nullptr;
262 }
263
264 /// If supported, return the section to use for the llvm.commandline
265 /// metadata. Otherwise, return nullptr.
267 return nullptr;
268 }
269
270 /// On targets that use separate function descriptor symbols, return a section
271 /// for the descriptor given its symbol. Use only with defined functions.
272 virtual MCSection *
274 const TargetMachine &TM) const {
275 return nullptr;
276 }
277
278 /// On targets that support TOC entries, return a section for the entry given
279 /// the symbol it refers to.
280 /// TODO: Implement this interface for existing ELF targets.
282 const TargetMachine &TM) const {
283 return nullptr;
284 }
285
286 /// On targets that associate external references with a section, return such
287 /// a section for the given external global.
288 virtual MCSection *
290 const TargetMachine &TM) const {
291 return nullptr;
292 }
293
294 /// Targets that have a special convention for their symbols could use
295 /// this hook to return a specialized symbol.
297 const TargetMachine &TM) const {
298 return nullptr;
299 }
300
301 /// If supported, return the function entry point symbol.
302 /// Otherwise, returns nullptr.
303 /// Func must be a function or an alias which has a function as base object.
305 const TargetMachine &TM) const {
306 return nullptr;
307 }
308
309protected:
311 SectionKind Kind,
312 const TargetMachine &TM) const = 0;
313};
314
315} // end namespace llvm
316
317#endif // LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:213
#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:957
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:516
Streaming machine code generation interface.
Definition MCStreamer.h:221
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...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
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.