LLVM 24.0.0git
TargetLoweringObjectFileImpl.h
Go to the documentation of this file.
1//==- llvm/CodeGen/TargetLoweringObjectFileImpl.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_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
15#define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16
19#include "llvm/MC/MCExpr.h"
21
22namespace llvm {
23
24class GlobalValue;
26class MachineFunction;
27class MCContext;
28class MCExpr;
29class MCSection;
30class MCSymbol;
31class Module;
32class TargetMachine;
33
35 bool UseInitArray = false;
36 mutable unsigned NextUniqueID = 1; // ID 0 is reserved for execute-only sections
38
39protected:
41 bool isLargeConstant(const DataLayout &DL, SectionKind Kind,
42 const Constant *C) const;
44 const Constant *C,
45 StringRef SectionSuffix) const;
46
47public:
48 ~TargetLoweringObjectFileELF() override = default;
49
50 void initialize(MCContext &Ctx, const TargetMachine &TM,
51 const Module &M) override;
52
53 /// Emit Obj-C garbage collection and linker options.
54 void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const override;
55
56 MCSection *getNamedSection(StringRef Name, SectionKind Kind) const override;
57
59 const MCSymbol *Sym,
60 const MachineModuleInfo *MMI) const override;
61
63 const DataLayout &DL,
64 const MCSymbol *Sym,
65 const MachineModuleInfo *MMI) const;
66
68 const Module &M) const override;
69
70 /// Given a constant with the SectionKind, return a section that it should be
71 /// placed in.
73 const Constant *C, Align &Alignment,
74 const Function *F) const override;
75
76 /// Similar to the function above, but append \p SectionSuffix to the section
77 /// name.
79 const Constant *C, Align &Alignment,
80 const Function *F,
81 StringRef SectionSuffix) const override;
82
84 const TargetMachine &TM) const override;
85
87 const TargetMachine &TM) const override;
88
90 const TargetMachine &TM) const override;
91 MCSection *
93 const MachineJumpTableEntry *JTE) const override;
94 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
95 const TargetMachine &TM) const override;
96
97 MCSection *
100 const TargetMachine &TM) const override;
101
102 MCSection *
104 const TargetMachine &TM) const override;
105
106 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
107 const Function &F) const override;
108
109 /// Return an MCExpr to use for a reference to the specified type info global
110 /// variable from exception handling information.
112 unsigned Encoding,
113 const TargetMachine &TM,
115 MCStreamer &Streamer) const override;
116
117 // The symbol that gets passed to .cfi_personality.
119 const TargetMachine &TM,
120 MachineModuleInfo *MMI) const override;
121
122 void InitializeELF(bool UseInitArray_);
123 MCSection *getStaticCtorSection(unsigned Priority,
124 const MCSymbol *KeySym) const override;
125 MCSection *getStaticDtorSection(unsigned Priority,
126 const MCSymbol *KeySym) const override;
127
128 const MCExpr *
130 int64_t Addend,
131 std::optional<int64_t> PCRelativeOffset) const;
132
134 const MCSymbol *RHS, int64_t Addend,
135 std::optional<int64_t> PCRelativeOffset,
136 const TargetMachine &TM) const override;
137
138 MCSection *getSectionForCommandLines() const override;
139};
140
142public:
144 ~TargetLoweringObjectFileMachO() override = default;
145
146 void initialize(MCContext &Ctx, const TargetMachine &TM,
147 const Module &M) override;
148
149 MCSection *getStaticDtorSection(unsigned Priority,
150 const MCSymbol *KeySym) const override;
151
152 /// Emit the module flags that specify the garbage collection information.
153 void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const override;
154
155 MCSection *getNamedSection(StringRef Name, SectionKind Kind) const override;
156
158 const Module &M) const override;
159
161 const TargetMachine &TM) const override;
162
164 const TargetMachine &TM) const override;
165
167 const Constant *C, Align &Alignment,
168 const Function *F) const override;
169
170 /// The mach-o version of this method defaults to returning a stub reference.
172 unsigned Encoding,
173 const TargetMachine &TM,
175 MCStreamer &Streamer) const override;
176
177 // The symbol that gets passed to .cfi_personality.
179 const TargetMachine &TM,
180 MachineModuleInfo *MMI) const override;
181
182 /// Get MachO PC relative GOT entry relocation
184 const MCSymbol *Sym,
185 const MCValue &MV, int64_t Offset,
187 MCStreamer &Streamer) const override;
188
189 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
190 const TargetMachine &TM) const override;
191
192 MCSection *getSectionForCommandLines() const override;
193};
194
196 mutable unsigned NextUniqueID = 0;
197
198public:
199 ~TargetLoweringObjectFileCOFF() override = default;
200
201 void initialize(MCContext &Ctx, const TargetMachine &TM,
202 const Module &M) override;
204 const TargetMachine &TM) const override;
205
207 const TargetMachine &TM) const override;
208
209 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
210 const TargetMachine &TM) const override;
211
213 const TargetMachine &TM) const override;
214
215 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
216 const Function &F) const override;
217
218 /// Emit Obj-C garbage collection and linker options.
219 void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const override;
220
221 MCSection *getNamedSection(StringRef Name, SectionKind Kind) const override;
222
224 const Module &M) const override;
225
226 MCSection *getStaticCtorSection(unsigned Priority,
227 const MCSymbol *KeySym) const override;
228 MCSection *getStaticDtorSection(unsigned Priority,
229 const MCSymbol *KeySym) const override;
230
232 const GlobalValue *RHS, int64_t Addend,
233 std::optional<int64_t> PCRelativeOffset,
234 const TargetMachine &TM) const override;
235
236 /// Given a mergeable constant with the specified size and relocation
237 /// information, return a section that it should be placed in.
239 const Constant *C, Align &Alignment,
240 const Function *F) const override;
241};
242
244 mutable unsigned NextUniqueID = 0;
246
247public:
249 ~TargetLoweringObjectFileWasm() override = default;
250
251 void initialize(MCContext &Ctx, const TargetMachine &TM,
252 const Module &M) override;
253
255 const TargetMachine &TM) const override;
256
258 const TargetMachine &TM) const override;
259
260 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
261 const Function &F) const override;
262
263 MCSection *getNamedSection(StringRef Name, SectionKind Kind) const override;
264
265 void InitializeWasm();
266 MCSection *getStaticCtorSection(unsigned Priority,
267 const MCSymbol *KeySym) const override;
268 MCSection *getStaticDtorSection(unsigned Priority,
269 const MCSymbol *KeySym) const override;
270};
271
273public:
275 ~TargetLoweringObjectFileXCOFF() override = default;
276
277 static bool ShouldEmitEHBlock(const MachineFunction *MF);
278 static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF);
279
281
282 void initialize(MCContext &Ctx, const TargetMachine &TM,
283 const Module &M) override;
284
285 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
286 const Function &F) const override;
287
289 const TargetMachine &TM) const override;
290
291 MCSection *getStaticCtorSection(unsigned Priority,
292 const MCSymbol *KeySym) const override;
293 MCSection *getStaticDtorSection(unsigned Priority,
294 const MCSymbol *KeySym) const override;
295
297 const TargetMachine &TM) const override;
298
300 const TargetMachine &TM) const override;
301
302 /// Given a constant with the SectionKind, return a section that it should be
303 /// placed in.
305 const Constant *C, Align &Alignment,
306 const Function *F) const override;
307
309
310 MCSection *
312 const TargetMachine &TM) const override;
314 const TargetMachine &TM) const override;
315
316 /// For external functions, this will always return a function descriptor
317 /// csect.
318 MCSection *
320 const TargetMachine &TM) const override;
321
322 /// For functions, this will always return a function descriptor symbol.
324 const TargetMachine &TM) const override;
325
327 const TargetMachine &TM) const override;
328
329 /// For functions, this will return the LSDA section. If option
330 /// -ffunction-sections is on, this will return a unique csect with the
331 /// function name appended to .gcc_except_table as a suffix of the LSDA
332 /// section name.
333 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
334 const TargetMachine &TM) const override;
335};
336
338 std::string DefaultRootSDName;
339 std::string DefaultADAPRName;
340
341public:
343 ~TargetLoweringObjectFileGOFF() override = default;
344
345 void initialize(MCContext &Ctx, const TargetMachine &TM,
346 const Module &M) override;
347
348 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
349 const Function &F) const override;
351 const Constant *C, Align &Alignment,
352 const Function *F) const override;
354 const TargetMachine &TM) const override;
356 const TargetMachine &TM) const override;
357 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
358 const TargetMachine &TM) const override;
359 MCSection *getStaticXtorSection(unsigned Priority) const;
360};
361
362} // end namespace llvm
363
364#endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_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
This file defines the SmallPtrSet class.
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: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
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
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
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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 * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend, std::optional< int64_t > PCRelativeOffset, const TargetMachine &TM) const override
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
MCSection * getNamedSection(StringRef Name, SectionKind Kind) const override
Get a section with the given name and kind, using format-appropriate defaults for section flags.
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
~TargetLoweringObjectFileCOFF() override=default
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a mergeable constant with the specified size and relocation information, return a section that ...
void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const override
Emit Obj-C garbage collection and linker options.
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
void emitLinkerDirectives(MCStreamer &Streamer, const Module &M) const override
Process linker options metadata and emit platform-specific bits.
MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const override
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
~TargetLoweringObjectFileELF() override=default
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
MCSection * getSectionForConstantImpl(const DataLayout &DL, SectionKind Kind, const Constant *C, StringRef SectionSuffix) const
void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const override
Emit Obj-C garbage collection and linker options.
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym, const MachineModuleInfo *MMI) const override
void emitLinkerDirectives(MCStreamer &Streamer, const Module &M) const override
Process linker options metadata and emit platform-specific bits.
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Return an MCExpr to use for a reference to the specified type info global variable from exception han...
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
const MCExpr * lowerSymbolDifference(const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend, std::optional< int64_t > PCRelativeOffset) const
MCSection * getNamedSection(StringRef Name, SectionKind Kind) const override
Get a section with the given name and kind, using format-appropriate defaults for section flags.
const MCExpr * lowerDSOLocalEquivalent(const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend, std::optional< int64_t > PCRelativeOffset, const TargetMachine &TM) const override
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
virtual void emitPersonalityValueImpl(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym, const MachineModuleInfo *MMI) const
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
bool isLargeConstant(const DataLayout &DL, SectionKind Kind, const Constant *C) const
Given a mergeable constant with the specified size and relocation information, return a section that ...
MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) const override
Returns a unique section for the given machine basic block.
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSection * getStaticXtorSection(unsigned Priority) const
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
~TargetLoweringObjectFileGOFF() override=default
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
~TargetLoweringObjectFileMachO() override=default
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
void emitModuleMetadata(MCStreamer &Streamer, const Module &M) const override
Emit the module flags that specify the garbage collection information.
const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
void emitLinkerDirectives(MCStreamer &Streamer, const Module &M) const override
Process linker options metadata and emit platform-specific bits.
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
MCSection * getNamedSection(StringRef Name, SectionKind Kind) const override
Get a section with the given name and kind, using format-appropriate defaults for section flags.
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getNamedSection(StringRef Name, SectionKind Kind) const override
Get a section with the given name and kind, using format-appropriate defaults for section flags.
~TargetLoweringObjectFileWasm() override=default
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF)
MCSection * getSectionForTOCEntry(const MCSymbol *Sym, const TargetMachine &TM) const override
On targets that support TOC entries, return a section for the entry given the symbol it refers to.
MCSection * getSectionForExternalReference(const GlobalObject *GO, const TargetMachine &TM) const override
For external functions, this will always return a function descriptor csect.
MCSymbol * getFunctionEntryPointSymbol(const GlobalValue *Func, const TargetMachine &TM) const override
If supported, return the function entry point symbol.
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment, const Function *F) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
~TargetLoweringObjectFileXCOFF() override=default
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
static XCOFF::StorageClass getStorageClassForGlobal(const GlobalValue *GV)
MCSymbol * getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const override
For functions, this will always return a function descriptor symbol.
MCSection * getSectionForFunctionDescriptor(const GlobalObject *F, const TargetMachine &TM) const override
On targets that use separate function descriptor symbols, return a section for the descriptor given i...
static bool ShouldEmitEHBlock(const MachineFunction *MF)
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override
For functions, this will return the LSDA section.
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.