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 and to inspect
84 /// the module-level metadata the platform cares about.
85 virtual void initialize(MCContext &ctx, const TargetMachine &TM,
86 const Module &M);
87
88 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
89 const MCSymbol *Sym,
90 const MachineModuleInfo *MMI) const;
91
92 /// Emit the module-level metadata that the platform cares about.
93 virtual void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const {
94 }
95
96 /// Emit Call Graph Profile metadata.
97 void emitCGProfileMetadata(MCStreamer &Streamer, const Module &M) const;
98
99 /// Emit pseudo_probe_desc metadata.
100 void emitPseudoProbeDescMetadata(MCStreamer &Streamer, const Module &M,
101 std::function<void(MCStreamer &Streamer)>
102 COMDATSymEmitter = nullptr) const;
103
104 /// Process linker options metadata and emit platform-specific bits.
106 const Module &M) const {}
107
108 /// Given a constant with the SectionKind, return a section that it should be
109 /// placed in.
110 virtual MCSection *getSectionForConstant(const DataLayout &DL,
111 SectionKind Kind, const Constant *C,
112 Align &Alignment,
113 const Function *F) const;
114
115 /// Similar to the function above, but append \p SectionSuffix to the section
116 /// name.
117 virtual MCSection *getSectionForConstant(const DataLayout &DL,
118 SectionKind Kind, const Constant *C,
119 Align &Alignment, const Function *F,
120 StringRef SectionSuffix) const;
121
122 virtual MCSection *
123 getSectionForMachineBasicBlock(const Function &F,
124 const MachineBasicBlock &MBB,
125 const TargetMachine &TM) const;
126
127 virtual MCSection *
128 getUniqueSectionForFunction(const Function &F,
129 const TargetMachine &TM) const;
130
131 /// Classify the specified global variable into a set of target independent
132 /// categories embodied in SectionKind.
133 static SectionKind getKindForGlobal(const GlobalObject *GO,
134 const TargetMachine &TM);
135
136 /// Return the section name specified by '#pragma clang section' or the
137 /// section attribute.
138 static StringRef getCustomSectionName(const GlobalObject *GO,
139 const TargetMachine &TM);
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, SectionKind Kind,
145 const TargetMachine &TM) const;
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,
151 const TargetMachine &TM) const;
152
153 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
154 const GlobalValue *GV,
155 const TargetMachine &TM) const;
156
157 virtual MCSection *getSectionForJumpTable(const Function &F,
158 const TargetMachine &TM) const;
159 virtual MCSection *
160 getSectionForJumpTable(const Function &F, const TargetMachine &TM,
161 const MachineJumpTableEntry *JTE) const;
162
163 virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &,
164 const TargetMachine &) const {
165 return LSDASection;
166 }
167
168 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
169 const Function &F) const;
170
171 /// Targets should implement this method to assign a section to globals with
172 /// an explicit section specfied. The implementation of this method can
173 /// assume that GO->hasSection() is true.
174 virtual MCSection *
176 const TargetMachine &TM) const = 0;
177
178 /// Return an MCExpr to use for a reference to the specified global variable
179 /// from exception handling information.
180 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
181 unsigned Encoding,
182 const TargetMachine &TM,
184 MCStreamer &Streamer) const;
185
186 /// Return the MCSymbol for a private symbol with global value name as its
187 /// base, with the specified suffix.
189 StringRef Suffix,
190 const TargetMachine &TM) const;
191
192 // The symbol that gets passed to .cfi_personality.
194 const TargetMachine &TM,
195 MachineModuleInfo *MMI) const;
196
197 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
198 unsigned getLSDAEncoding() const { return LSDAEncoding; }
199 unsigned getTTypeEncoding() const { return TTypeEncoding; }
200 unsigned getCallSiteEncoding() const;
201
202 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
203 MCStreamer &Streamer) const;
204
205 virtual MCSection *getStaticCtorSection(unsigned Priority,
206 const MCSymbol *KeySym) const {
207 return StaticCtorSection;
208 }
209
210 virtual MCSection *getStaticDtorSection(unsigned Priority,
211 const MCSymbol *KeySym) const {
212 return StaticDtorSection;
213 }
214
215 /// Create a symbol reference to describe the given TLS variable when
216 /// emitting the address in debug info.
217 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
218
220 const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
221 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
222 return nullptr;
223 }
224
225 /// Target supports a PC-relative relocation that references the PLT of a
226 /// function.
228
230 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
231 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
232 return nullptr;
233 }
234
235 /// Target supports replacing a data "PC"-relative access to a symbol
236 /// through another symbol, by accessing the later via a GOT entry instead?
240
241 /// Target GOT "PC"-relative relocation supports encoding an additional
242 /// binary expression with an offset?
245 }
246
247 /// Target supports TLS offset relocation in debug section?
251
252 /// Returns the register used as static base in RWPI variants.
254
255 /// Get the target specific RWPI relocation.
256 virtual const MCExpr *getIndirectSymViaRWPI(const MCSymbol *Sym) const {
257 return nullptr;
258 }
259
260 /// Get the target specific PC relative GOT entry relocation
262 const MCSymbol *Sym,
263 const MCValue &MV,
264 int64_t Offset,
266 MCStreamer &Streamer) const {
267 return nullptr;
268 }
269
270 /// If supported, return the section to use for the llvm.commandline
271 /// metadata. Otherwise, return nullptr.
273 return nullptr;
274 }
275
276 /// On targets that use separate function descriptor symbols, return a section
277 /// for the descriptor given its symbol. Use only with defined functions.
278 virtual MCSection *
280 const TargetMachine &TM) const {
281 return nullptr;
282 }
283
284 /// On targets that support TOC entries, return a section for the entry given
285 /// the symbol it refers to.
286 /// TODO: Implement this interface for existing ELF targets.
288 const TargetMachine &TM) const {
289 return nullptr;
290 }
291
292 /// On targets that associate external references with a section, return such
293 /// a section for the given external global.
294 virtual MCSection *
296 const TargetMachine &TM) const {
297 return nullptr;
298 }
299
300 /// Targets that have a special convention for their symbols could use
301 /// this hook to return a specialized symbol.
303 const TargetMachine &TM) const {
304 return nullptr;
305 }
306
307 /// If supported, return the function entry point symbol.
308 /// Otherwise, returns nullptr.
309 /// Func must be a function or an alias which has a function as base object.
311 const TargetMachine &TM) const {
312 return nullptr;
313 }
314
315protected:
317 SectionKind Kind,
318 const TargetMachine &TM) const = 0;
319};
320
321} // end namespace llvm
322
323#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:215
#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: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:580
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: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 * 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.