LLVM 20.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;
25class MachineModuleInfo;
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:
42
43public:
45 ~TargetLoweringObjectFileELF() override = default;
46
47 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
48
49 void getModuleMetadata(Module &M) override;
50
51 /// Emit Obj-C garbage collection and linker options.
52 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
53
54 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL,
55 const MCSymbol *Sym) const override;
56
57 /// Given a constant with the SectionKind, return a section that it should be
58 /// placed in.
60 const Constant *C,
61 Align &Alignment) const override;
62
64 const TargetMachine &TM) const override;
65
67 const TargetMachine &TM) const override;
68
70 const TargetMachine &TM) const override;
71 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
72 const TargetMachine &TM) const override;
73
74 MCSection *
77 const TargetMachine &TM) const override;
78
79 MCSection *
81 const TargetMachine &TM) const override;
82
83 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
84 const Function &F) const override;
85
86 /// Return an MCExpr to use for a reference to the specified type info global
87 /// variable from exception handling information.
89 unsigned Encoding,
90 const TargetMachine &TM,
92 MCStreamer &Streamer) const override;
93
94 // The symbol that gets passed to .cfi_personality.
96 const TargetMachine &TM,
97 MachineModuleInfo *MMI) const override;
98
99 void InitializeELF(bool UseInitArray_);
100 MCSection *getStaticCtorSection(unsigned Priority,
101 const MCSymbol *KeySym) const override;
102 MCSection *getStaticDtorSection(unsigned Priority,
103 const MCSymbol *KeySym) const override;
104
106 const GlobalValue *RHS,
107 const TargetMachine &TM) const override;
108
110 const TargetMachine &TM) const override;
111
112 MCSection *getSectionForCommandLines() const override;
113};
114
116public:
118 ~TargetLoweringObjectFileMachO() override = default;
119
120 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
121
122 MCSection *getStaticDtorSection(unsigned Priority,
123 const MCSymbol *KeySym) const override;
124
125 /// Emit the module flags that specify the garbage collection information.
126 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
127
129 const TargetMachine &TM) const override;
130
132 const TargetMachine &TM) const override;
133
135 const Constant *C,
136 Align &Alignment) const override;
137
138 /// The mach-o version of this method defaults to returning a stub reference.
140 unsigned Encoding,
141 const TargetMachine &TM,
143 MCStreamer &Streamer) const override;
144
145 // The symbol that gets passed to .cfi_personality.
147 const TargetMachine &TM,
148 MachineModuleInfo *MMI) const override;
149
150 /// Get MachO PC relative GOT entry relocation
152 const MCSymbol *Sym,
153 const MCValue &MV, int64_t Offset,
155 MCStreamer &Streamer) const override;
156
157 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
158 const TargetMachine &TM) const override;
159
160 MCSection *getSectionForCommandLines() const override;
161};
162
164 mutable unsigned NextUniqueID = 0;
165 const TargetMachine *TM = nullptr;
166
167public:
168 ~TargetLoweringObjectFileCOFF() override = default;
169
170 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
172 const TargetMachine &TM) const override;
173
175 const TargetMachine &TM) const override;
176
177 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
178 const TargetMachine &TM) const override;
179
181 const TargetMachine &TM) const override;
182
183 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
184 const Function &F) const override;
185
186 /// Emit Obj-C garbage collection and linker options.
187 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
188
189 MCSection *getStaticCtorSection(unsigned Priority,
190 const MCSymbol *KeySym) const override;
191 MCSection *getStaticDtorSection(unsigned Priority,
192 const MCSymbol *KeySym) const override;
193
195 const GlobalValue *RHS,
196 const TargetMachine &TM) const override;
197
198 /// Given a mergeable constant with the specified size and relocation
199 /// information, return a section that it should be placed in.
201 const Constant *C,
202 Align &Alignment) const override;
203
204private:
205 void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const;
206};
207
209 mutable unsigned NextUniqueID = 0;
211
212public:
214 ~TargetLoweringObjectFileWasm() override = default;
215
216 void getModuleMetadata(Module &M) override;
217
219 const TargetMachine &TM) const override;
220
222 const TargetMachine &TM) const override;
223
224 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
225 const Function &F) const override;
226
227 void InitializeWasm();
228 MCSection *getStaticCtorSection(unsigned Priority,
229 const MCSymbol *KeySym) const override;
230 MCSection *getStaticDtorSection(unsigned Priority,
231 const MCSymbol *KeySym) const override;
232
234 const GlobalValue *RHS,
235 const TargetMachine &TM) const override;
236};
237
239public:
241 ~TargetLoweringObjectFileXCOFF() override = default;
242
243 static bool ShouldEmitEHBlock(const MachineFunction *MF);
244 static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF);
245
247
248 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
249
250 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
251 const Function &F) const override;
252
254 const TargetMachine &TM) const override;
255
256 MCSection *getStaticCtorSection(unsigned Priority,
257 const MCSymbol *KeySym) const override;
258 MCSection *getStaticDtorSection(unsigned Priority,
259 const MCSymbol *KeySym) const override;
260
262 const GlobalValue *RHS,
263 const TargetMachine &TM) const override;
264
266 const TargetMachine &TM) const override;
267
269 const TargetMachine &TM) const override;
270
271 /// Given a constant with the SectionKind, return a section that it should be
272 /// placed in.
274 const Constant *C,
275 Align &Alignment) const override;
276
278
279 MCSection *
281 const TargetMachine &TM) const override;
283 const TargetMachine &TM) const override;
284
285 /// For external functions, this will always return a function descriptor
286 /// csect.
287 MCSection *
289 const TargetMachine &TM) const override;
290
291 /// For functions, this will always return a function descriptor symbol.
293 const TargetMachine &TM) const override;
294
296 const TargetMachine &TM) const override;
297
298 /// For functions, this will return the LSDA section. If option
299 /// -ffunction-sections is on, this will return a unique csect with the
300 /// function name appended to .gcc_except_table as a suffix of the LSDA
301 /// section name.
302 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
303 const TargetMachine &TM) const override;
304};
305
307public:
309 ~TargetLoweringObjectFileGOFF() override = default;
310
312 const TargetMachine &TM) const override;
314 const TargetMachine &TM) const override;
315 MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym,
316 const TargetMachine &TM) const override;
317};
318
319} // end namespace llvm
320
321#endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
This file defines the SmallPtrSet class.
Value * RHS
Value * LHS
This is an important base class in LLVM.
Definition: Constant.h:42
Wrapper for a function that represents a value that functionally represents the original function.
Definition: Constants.h:936
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
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:36
Streaming machine code generation interface.
Definition: MCStreamer.h:213
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
This represents an "assembler immediate".
Definition: MCValue.h:36
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:65
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.
Definition: SmallPtrSet.h:502
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, 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...
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a mergeable constant with the specified size and relocation information, return a section that ...
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
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 * 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 * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
~TargetLoweringObjectFileELF() override=default
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
void emitModuleMetadata(MCStreamer &Streamer, 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 * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym) 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.
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
const MCExpr * lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv, 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
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) const override
Returns a unique section for the given machine basic block.
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind
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 * 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
~TargetLoweringObjectFileMachO() override=default
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
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...
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.
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
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
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
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)
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const override
Given a constant with the SectionKind, return a section that it should be placed in.
MCSymbol * getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const override
For functions, this will always return a function descriptor symbol.
MCSection * getSectionForFunctionDescriptor(const Function *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.
Definition: TargetMachine.h:77
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
StorageClass
Definition: XCOFF.h:170
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39