LLVM 20.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"
19#include <cstdint>
20
21namespace llvm {
22
23struct Align;
24class Constant;
25class DataLayout;
26class Function;
27class GlobalObject;
28class GlobalValue;
29class MachineBasicBlock;
30class MachineModuleInfo;
31class Mangler;
32class MCContext;
33class MCExpr;
34class MCSection;
35class MCSymbol;
36class MCSymbolRefExpr;
37class MCStreamer;
38class MCValue;
39class Module;
40class SectionKind;
41class StringRef;
42class TargetMachine;
43class DSOLocalEquivalent;
44
46 /// Name-mangler for global names.
47 Mangler *Mang = nullptr;
48
49protected:
54
55 /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
56 /// for EH.
57 unsigned PersonalityEncoding = 0;
58 unsigned LSDAEncoding = 0;
59 unsigned TTypeEncoding = 0;
60 unsigned CallSiteEncoding = 0;
61
62 /// This section contains the static constructor pointer list.
64
65 /// This section contains the static destructor pointer list.
67
68 const TargetMachine *TM = nullptr;
69
70public:
76
77 Mangler &getMangler() const { return *Mang; }
78
79 /// This method must be called before any actual lowering is done. This
80 /// specifies the current context for codegen, and gives the lowering
81 /// implementations a chance to set up their default sections.
82 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
83
84 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
85 const MCSymbol *Sym,
86 const MachineModuleInfo *MMI) const;
87
88 /// Emit the module-level metadata that the platform cares about.
89 virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}
90
91 /// Emit Call Graph Profile metadata.
92 void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const;
93
94 /// Get the module-level metadata that the platform cares about.
95 virtual void getModuleMetadata(Module &M) {}
96
97 /// Given a constant with the SectionKind, return a section that it should be
98 /// placed in.
100 SectionKind Kind, const Constant *C,
101 Align &Alignment) const;
102
103 virtual MCSection *
105 const MachineBasicBlock &MBB,
106 const TargetMachine &TM) const;
107
108 virtual MCSection *
110 const TargetMachine &TM) const;
111
112 /// Classify the specified global variable into a set of target independent
113 /// categories embodied in SectionKind.
115 const TargetMachine &TM);
116
117 /// This method computes the appropriate section to emit the specified global
118 /// variable or function definition. This should not be passed external (or
119 /// available externally) globals.
121 const TargetMachine &TM) const;
122
123 /// This method computes the appropriate section to emit the specified global
124 /// variable or function definition. This should not be passed external (or
125 /// available externally) globals.
127 const TargetMachine &TM) const;
128
129 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
130 const GlobalValue *GV,
131 const TargetMachine &TM) const;
132
134 const TargetMachine &TM) const;
135 virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &,
136 const TargetMachine &) const {
137 return LSDASection;
138 }
139
140 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
141 const Function &F) const;
142
143 /// Targets should implement this method to assign a section to globals with
144 /// an explicit section specfied. The implementation of this method can
145 /// assume that GO->hasSection() is true.
146 virtual MCSection *
148 const TargetMachine &TM) const = 0;
149
150 /// Return an MCExpr to use for a reference to the specified global variable
151 /// from exception handling information.
152 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
153 unsigned Encoding,
154 const TargetMachine &TM,
156 MCStreamer &Streamer) const;
157
158 /// Return the MCSymbol for a private symbol with global value name as its
159 /// base, with the specified suffix.
161 StringRef Suffix,
162 const TargetMachine &TM) const;
163
164 // The symbol that gets passed to .cfi_personality.
166 const TargetMachine &TM,
167 MachineModuleInfo *MMI) const;
168
169 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
170 unsigned getLSDAEncoding() const { return LSDAEncoding; }
171 unsigned getTTypeEncoding() const { return TTypeEncoding; }
172 unsigned getCallSiteEncoding() const;
173
174 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
175 MCStreamer &Streamer) const;
176
177 virtual MCSection *getStaticCtorSection(unsigned Priority,
178 const MCSymbol *KeySym) const {
179 return StaticCtorSection;
180 }
181
182 virtual MCSection *getStaticDtorSection(unsigned Priority,
183 const MCSymbol *KeySym) const {
184 return StaticDtorSection;
185 }
186
187 /// Create a symbol reference to describe the given TLS variable when
188 /// emitting the address in debug info.
189 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
190
192 const GlobalValue *RHS,
193 const TargetMachine &TM) const {
194 return nullptr;
195 }
196
197 /// Target supports a native lowering of a dso_local_equivalent constant
198 /// without needing to replace it with equivalent IR.
201 }
202
204 const TargetMachine &TM) const {
205 return nullptr;
206 }
207
208 /// Target supports replacing a data "PC"-relative access to a symbol
209 /// through another symbol, by accessing the later via a GOT entry instead?
212 }
213
214 /// Target GOT "PC"-relative relocation supports encoding an additional
215 /// binary expression with an offset?
218 }
219
220 /// Target supports TLS offset relocation in debug section?
223 }
224
225 /// Returns the register used as static base in RWPI variants.
227
228 /// Get the target specific RWPI relocation.
229 virtual const MCExpr *getIndirectSymViaRWPI(const MCSymbol *Sym) const {
230 return nullptr;
231 }
232
233 /// Get the target specific PC relative GOT entry relocation
235 const MCSymbol *Sym,
236 const MCValue &MV,
237 int64_t Offset,
239 MCStreamer &Streamer) const {
240 return nullptr;
241 }
242
243 /// If supported, return the section to use for the llvm.commandline
244 /// metadata. Otherwise, return nullptr.
246 return nullptr;
247 }
248
249 /// On targets that use separate function descriptor symbols, return a section
250 /// for the descriptor given its symbol. Use only with defined functions.
251 virtual MCSection *
253 const TargetMachine &TM) const {
254 return nullptr;
255 }
256
257 /// On targets that support TOC entries, return a section for the entry given
258 /// the symbol it refers to.
259 /// TODO: Implement this interface for existing ELF targets.
261 const TargetMachine &TM) const {
262 return nullptr;
263 }
264
265 /// On targets that associate external references with a section, return such
266 /// a section for the given external global.
267 virtual MCSection *
269 const TargetMachine &TM) const {
270 return nullptr;
271 }
272
273 /// Targets that have a special convention for their symbols could use
274 /// this hook to return a specialized symbol.
276 const TargetMachine &TM) const {
277 return nullptr;
278 }
279
280 /// If supported, return the function entry point symbol.
281 /// Otherwise, returns nullptr.
282 /// Func must be a function or an alias which has a function as base object.
284 const TargetMachine &TM) const {
285 return nullptr;
286 }
287
288protected:
290 SectionKind Kind,
291 const TargetMachine &TM) const = 0;
292};
293
294} // end namespace llvm
295
296#endif // LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
uint64_t Align
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:42
Wrapper for a function that represents a value that functionally represents the original function.
Definition: Constants.h:941
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
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:33
static constexpr unsigned NoRegister
Definition: MCRegister.h:52
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
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
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
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const
Emit Call Graph Profile metadata.
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
MCSection * StaticDtorSection
This section contains the static destructor pointer list.
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.
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
virtual MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const
virtual MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const
virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) 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...
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const
bool supportDSOLocalEquivalentLowering() const
Target supports a native lowering of a dso_local_equivalent constant without needing to replace it wi...
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
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?
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 MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment) const
Given a constant with the SectionKind, return a section that it should be placed in.
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 const MCExpr * lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv, const TargetMachine &TM) const
virtual MCSection * getSectionForMachineBasicBlock(const Function &F, const MachineBasicBlock &MBB, const TargetMachine &TM) 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 const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const
Create a symbol reference to describe the given TLS variable when emitting the address in debug info.
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 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...
const MCExpr * getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding, MCStreamer &Streamer) const
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...
TargetLoweringObjectFile(const TargetLoweringObjectFile &)=delete
virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, const MCSymbol *Sym, const MachineModuleInfo *MMI) const
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 ...
virtual const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const
virtual MCSection * getUniqueSectionForFunction(const Function &F, const TargetMachine &TM) const
MCSection * SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
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
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