Debian Codegraph @

suite/synctools/tablegen/include/llvm/Target/TargetLoweringObjectFile.h

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