LLVM 22.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;
25struct MachineJumpTableEntry;
26class Constant;
27class DataLayout;
28class Function;
29class GlobalObject;
30class GlobalValue;
31class MachineBasicBlock;
32class MachineModuleInfo;
33class Mangler;
34class MCContext;
35class MCExpr;
36class MCSection;
37class MCSymbol;
38class MCSymbolRefExpr;
39class MCStreamer;
40class MCValue;
41class Module;
42class SectionKind;
43class StringRef;
44class TargetMachine;
45class DSOLocalEquivalent;
46
48 /// Name-mangler for global names.
49 Mangler *Mang = nullptr;
50
51protected:
52 bool SupportIndirectSymViaGOTPCRel = false;
53 bool SupportGOTPCRelWithOffset = true;
54 bool SupportDebugThreadLocalLocation = true;
55 uint32_t PLTPCRelativeSpecifier = 0;
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.
65 MCSection *StaticCtorSection = nullptr;
66
67 /// This section contains the static destructor pointer list.
68 MCSection *StaticDtorSection = nullptr;
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) const;
112
113 /// Similar to the function above, but append \p SectionSuffix to the section
114 /// name.
115 virtual MCSection *getSectionForConstant(const DataLayout &DL,
116 SectionKind Kind, const Constant *C,
117 Align &Alignment,
118 StringRef SectionSuffix) const;
119
120 virtual MCSection *
121 getSectionForMachineBasicBlock(const Function &F,
122 const MachineBasicBlock &MBB,
123 const TargetMachine &TM) const;
124
125 virtual MCSection *
126 getUniqueSectionForFunction(const Function &F,
127 const TargetMachine &TM) const;
128
129 /// Classify the specified global variable into a set of target independent
130 /// categories embodied in SectionKind.
131 static SectionKind getKindForGlobal(const GlobalObject *GO,
132 const TargetMachine &TM);
133
134 /// This method computes the appropriate section to emit the specified global
135 /// variable or function definition. This should not be passed external (or
136 /// available externally) globals.
137 MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
138 const TargetMachine &TM) const;
139
140 /// This method computes the appropriate section to emit the specified global
141 /// variable or function definition. This should not be passed external (or
142 /// available externally) globals.
143 MCSection *SectionForGlobal(const GlobalObject *GO,
144 const TargetMachine &TM) const;
145
146 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
147 const GlobalValue *GV,
148 const TargetMachine &TM) const;
149
150 virtual MCSection *getSectionForJumpTable(const Function &F,
151 const TargetMachine &TM) const;
152 virtual MCSection *
153 getSectionForJumpTable(const Function &F, const TargetMachine &TM,
154 const MachineJumpTableEntry *JTE) const;
155
156 virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &,
157 const TargetMachine &) const {
158 return LSDASection;
159 }
160
161 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
162 const Function &F) const;
163
164 /// Targets should implement this method to assign a section to globals with
165 /// an explicit section specfied. The implementation of this method can
166 /// assume that GO->hasSection() is true.
167 virtual MCSection *
169 const TargetMachine &TM) const = 0;
170
171 /// Return an MCExpr to use for a reference to the specified global variable
172 /// from exception handling information.
173 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
174 unsigned Encoding,
175 const TargetMachine &TM,
177 MCStreamer &Streamer) const;
178
179 /// Return the MCSymbol for a private symbol with global value name as its
180 /// base, with the specified suffix.
181 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
182 StringRef Suffix,
183 const TargetMachine &TM) const;
184
185 // The symbol that gets passed to .cfi_personality.
186 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
187 const TargetMachine &TM,
188 MachineModuleInfo *MMI) const;
189
190 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
191 unsigned getLSDAEncoding() const { return LSDAEncoding; }
192 unsigned getTTypeEncoding() const { return TTypeEncoding; }
193 unsigned getCallSiteEncoding() const;
194
195 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
196 MCStreamer &Streamer) const;
197
198 virtual MCSection *getStaticCtorSection(unsigned Priority,
199 const MCSymbol *KeySym) const {
200 return StaticCtorSection;
201 }
202
203 virtual MCSection *getStaticDtorSection(unsigned Priority,
204 const MCSymbol *KeySym) const {
205 return StaticDtorSection;
206 }
207
208 /// Create a symbol reference to describe the given TLS variable when
209 /// emitting the address in debug info.
210 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
211
213 const GlobalValue *LHS, const GlobalValue *RHS, int64_t Addend,
214 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
215 return nullptr;
216 }
217
218 /// Target supports a PC-relative relocation that references the PLT of a
219 /// function.
220 bool hasPLTPCRelative() const { return PLTPCRelativeSpecifier; }
221
223 const MCSymbol *LHS, const MCSymbol *RHS, int64_t Addend,
224 std::optional<int64_t> PCRelativeOffset, const TargetMachine &TM) const {
225 return nullptr;
226 }
227
228 /// Target supports replacing a data "PC"-relative access to a symbol
229 /// through another symbol, by accessing the later via a GOT entry instead?
231 return SupportIndirectSymViaGOTPCRel;
232 }
233
234 /// Target GOT "PC"-relative relocation supports encoding an additional
235 /// binary expression with an offset?
237 return SupportGOTPCRelWithOffset;
238 }
239
240 /// Target supports TLS offset relocation in debug section?
242 return SupportDebugThreadLocalLocation;
243 }
244
245 /// Returns the register used as static base in RWPI variants.
246 virtual MCRegister getStaticBase() const { return MCRegister::NoRegister; }
247
248 /// Get the target specific RWPI relocation.
249 virtual const MCExpr *getIndirectSymViaRWPI(const MCSymbol *Sym) const {
250 return nullptr;
251 }
252
253 /// Get the target specific PC relative GOT entry relocation
255 const MCSymbol *Sym,
256 const MCValue &MV,
257 int64_t Offset,
259 MCStreamer &Streamer) const {
260 return nullptr;
261 }
262
263 /// If supported, return the section to use for the llvm.commandline
264 /// metadata. Otherwise, return nullptr.
266 return nullptr;
267 }
268
269 /// On targets that use separate function descriptor symbols, return a section
270 /// for the descriptor given its symbol. Use only with defined functions.
271 virtual MCSection *
273 const TargetMachine &TM) const {
274 return nullptr;
275 }
276
277 /// On targets that support TOC entries, return a section for the entry given
278 /// the symbol it refers to.
279 /// TODO: Implement this interface for existing ELF targets.
281 const TargetMachine &TM) const {
282 return nullptr;
283 }
284
285 /// On targets that associate external references with a section, return such
286 /// a section for the given external global.
287 virtual MCSection *
289 const TargetMachine &TM) const {
290 return nullptr;
291 }
292
293 /// Targets that have a special convention for their symbols could use
294 /// this hook to return a specialized symbol.
296 const TargetMachine &TM) const {
297 return nullptr;
298 }
299
300 /// If supported, return the function entry point symbol.
301 /// Otherwise, returns nullptr.
302 /// Func must be a function or an alias which has a function as base object.
304 const TargetMachine &TM) const {
305 return nullptr;
306 }
307
308protected:
310 SectionKind Kind,
311 const TargetMachine &TM) const = 0;
312};
313
314} // end namespace llvm
315
316#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:213
uint64_t Align
uint64_t Offset
Definition: ELF_riscv.cpp:478
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
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: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
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
Streaming machine code generation interface.
Definition: MCStreamer.h:220
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...
Definition: SmallVector.h:574
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
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.
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...
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?
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
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 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 Function *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.
Definition: TargetMachine.h:83
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.