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) override;
51
52 void getModuleMetadata(Module &M) override;
53
54 /// Emit Obj-C garbage collection and linker options.
55 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
56
58 const MCSymbol *Sym,
59 const MachineModuleInfo *MMI) const override;
60
62 const DataLayout &DL,
63 const MCSymbol *Sym,
64 const MachineModuleInfo *MMI) const;
65
66 void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override;
67
68 /// Given a constant with the SectionKind, return a section that it should be
69 /// placed in.
71 const Constant *C, Align &Alignment,
72 const Function *F) const override;
73
74 /// Similar to the function above, but append \p SectionSuffix to the section
75 /// name.
77 const Constant *C, Align &Alignment,
78 const Function *F,
79 StringRef SectionSuffix) const override;
80
82 const TargetMachine &TM) const override;
83
85 const TargetMachine &TM) const override;
86
88 const TargetMachine &TM) const override;
89 MCSection *
91 const MachineJumpTableEntry *JTE) const override;
92 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
93 const TargetMachine &TM) const override;
94
95 MCSection *
98 const TargetMachine &TM) const override;
99
100 MCSection *
102 const TargetMachine &TM) const override;
103
104 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
105 const Function &F) const override;
106
107 /// Return an MCExpr to use for a reference to the specified type info global
108 /// variable from exception handling information.
110 unsigned Encoding,
111 const TargetMachine &TM,
113 MCStreamer &Streamer) const override;
114
115 // The symbol that gets passed to .cfi_personality.
117 const TargetMachine &TM,
118 MachineModuleInfo *MMI) const override;
119
120 void InitializeELF(bool UseInitArray_);
121 MCSection *getStaticCtorSection(unsigned Priority,
122 const MCSymbol *KeySym) const override;
123 MCSection *getStaticDtorSection(unsigned Priority,
124 const MCSymbol *KeySym) const override;
125
126 const MCExpr *
128 int64_t Addend,
129 std::optional<int64_t> PCRelativeOffset) const;
130
132 const MCSymbol *RHS, int64_t Addend,
133 std::optional<int64_t> PCRelativeOffset,
134 const TargetMachine &TM) const override;
135
136 MCSection *getSectionForCommandLines() const override;
137};
138
140public:
142 ~TargetLoweringObjectFileMachO() override = default;
143
144 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
145
146 MCSection *getStaticDtorSection(unsigned Priority,
147 const MCSymbol *KeySym) const override;
148
149 /// Emit the module flags that specify the garbage collection information.
150 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
151
152 void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override;
153
155 const TargetMachine &TM) const override;
156
158 const TargetMachine &TM) const override;
159
161 const Constant *C, Align &Alignment,
162 const Function *F) const override;
163
164 /// The mach-o version of this method defaults to returning a stub reference.
166 unsigned Encoding,
167 const TargetMachine &TM,
169 MCStreamer &Streamer) const override;
170
171 // The symbol that gets passed to .cfi_personality.
173 const TargetMachine &TM,
174 MachineModuleInfo *MMI) const override;
175
176 /// Get MachO PC relative GOT entry relocation
178 const MCSymbol *Sym,
179 const MCValue &MV, int64_t Offset,
181 MCStreamer &Streamer) const override;
182
183 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
184 const TargetMachine &TM) const override;
185
186 MCSection *getSectionForCommandLines() const override;
187};
188
190 mutable unsigned NextUniqueID = 0;
191
192public:
193 ~TargetLoweringObjectFileCOFF() override = default;
194
195 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
197 const TargetMachine &TM) const override;
198
200 const TargetMachine &TM) const override;
201
202 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
203 const TargetMachine &TM) const override;
204
206 const TargetMachine &TM) const override;
207
208 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
209 const Function &F) const override;
210
211 /// Emit Obj-C garbage collection and linker options.
212 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
213
214 void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override;
215
216 MCSection *getStaticCtorSection(unsigned Priority,
217 const MCSymbol *KeySym) const override;
218 MCSection *getStaticDtorSection(unsigned Priority,
219 const MCSymbol *KeySym) const override;
220
222 const GlobalValue *RHS, int64_t Addend,
223 std::optional<int64_t> PCRelativeOffset,
224 const TargetMachine &TM) const override;
225
226 /// Given a mergeable constant with the specified size and relocation
227 /// information, return a section that it should be placed in.
229 const Constant *C, Align &Alignment,
230 const Function *F) const override;
231};
232
234 mutable unsigned NextUniqueID = 0;
236
237public:
239 ~TargetLoweringObjectFileWasm() override = default;
240
241 void getModuleMetadata(Module &M) override;
242
244 const TargetMachine &TM) const override;
245
247 const TargetMachine &TM) const override;
248
249 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
250 const Function &F) const override;
251
252 void InitializeWasm();
253 MCSection *getStaticCtorSection(unsigned Priority,
254 const MCSymbol *KeySym) const override;
255 MCSection *getStaticDtorSection(unsigned Priority,
256 const MCSymbol *KeySym) const override;
257};
258
260public:
262 ~TargetLoweringObjectFileXCOFF() override = default;
263
264 static bool ShouldEmitEHBlock(const MachineFunction *MF);
265 static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF);
266
268
269 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
270
271 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
272 const Function &F) const override;
273
275 const TargetMachine &TM) const override;
276
277 MCSection *getStaticCtorSection(unsigned Priority,
278 const MCSymbol *KeySym) const override;
279 MCSection *getStaticDtorSection(unsigned Priority,
280 const MCSymbol *KeySym) const override;
281
283 const TargetMachine &TM) const override;
284
286 const TargetMachine &TM) const override;
287
288 /// Given a constant with the SectionKind, return a section that it should be
289 /// placed in.
291 const Constant *C, Align &Alignment,
292 const Function *F) const override;
293
295
296 MCSection *
298 const TargetMachine &TM) const override;
300 const TargetMachine &TM) const override;
301
302 /// For external functions, this will always return a function descriptor
303 /// csect.
304 MCSection *
306 const TargetMachine &TM) const override;
307
308 /// For functions, this will always return a function descriptor symbol.
310 const TargetMachine &TM) const override;
311
313 const TargetMachine &TM) const override;
314
315 /// For functions, this will return the LSDA section. If option
316 /// -ffunction-sections is on, this will return a unique csect with the
317 /// function name appended to .gcc_except_table as a suffix of the LSDA
318 /// section name.
319 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
320 const TargetMachine &TM) const override;
321};
322
324 std::string DefaultRootSDName;
325 std::string DefaultADAPRName;
326
327public:
329 ~TargetLoweringObjectFileGOFF() override = default;
330
331 void getModuleMetadata(Module &M) override;
332
333 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
334 const Function &F) const override;
336 const Constant *C, Align &Alignment,
337 const Function *F) const override;
339 const TargetMachine &TM) const override;
341 const TargetMachine &TM) const override;
342 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
343 const TargetMachine &TM) const override;
344 MCSection *getStaticXtorSection(unsigned Priority) const;
345};
346
347} // end namespace llvm
348
349#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:215
#define F(x, y, z)
Definition MD5.cpp:54
This file defines the SmallPtrSet class.
std::unique_ptr< MCStreamer > && Streamer
Value * RHS
Value * LHS
This is an important base class in LLVM.
Definition Constant.h:43
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...
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override
Process linker options metadata and emit platform-specific bits.
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
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 ...
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const override
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
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, Module &M) const override
Emit Obj-C garbage collection and linker options.
void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override
Process linker options metadata and emit platform-specific bits.
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
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...
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
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
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
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
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
void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const override
Process linker options metadata and emit platform-specific bits.
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...
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.
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit the module flags that specify the garbage collection information.
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
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.
void getModuleMetadata(Module &M) override
Get the module-level metadata that the platform cares about.
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
~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)
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
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.