LLVM  10.0.0svn
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 
18 #include "llvm/IR/Module.h"
19 #include "llvm/MC/MCExpr.h"
21 
22 namespace llvm {
23 
24 class GlobalValue;
25 class MachineModuleInfo;
26 class Mangler;
27 class MCContext;
28 class MCSection;
29 class MCSymbol;
30 class TargetMachine;
31 
33  bool UseInitArray = false;
34  mutable unsigned NextUniqueID = 1; // ID 0 is reserved for execute-only sections
35 
36 protected:
39  const TargetMachine *TM = nullptr;
40 
41 public:
42  TargetLoweringObjectFileELF() = default;
43  ~TargetLoweringObjectFileELF() override = default;
44 
45  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
46 
47  /// Emit Obj-C garbage collection and linker options.
48  void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
49 
50  void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL,
51  const MCSymbol *Sym) const override;
52 
53  /// Given a constant with the SectionKind, return a section that it should be
54  /// placed in.
56  const Constant *C,
57  unsigned &Align) const override;
58 
60  const TargetMachine &TM) const override;
61 
63  const TargetMachine &TM) const override;
64 
66  const TargetMachine &TM) const override;
67 
68  bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
69  const Function &F) const override;
70 
71  /// Return an MCExpr to use for a reference to the specified type info global
72  /// variable from exception handling information.
74  unsigned Encoding,
75  const TargetMachine &TM,
76  MachineModuleInfo *MMI,
77  MCStreamer &Streamer) const override;
78 
79  // The symbol that gets passed to .cfi_personality.
81  const TargetMachine &TM,
82  MachineModuleInfo *MMI) const override;
83 
84  void InitializeELF(bool UseInitArray_);
85  MCSection *getStaticCtorSection(unsigned Priority,
86  const MCSymbol *KeySym) const override;
87  MCSection *getStaticDtorSection(unsigned Priority,
88  const MCSymbol *KeySym) const override;
89 
90  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
91  const GlobalValue *RHS,
92  const TargetMachine &TM) const override;
93 
94  MCSection *getSectionForCommandLines() const override;
95 };
96 
98 public:
100  ~TargetLoweringObjectFileMachO() override = default;
101 
102  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
103 
104  /// Emit the module flags that specify the garbage collection information.
105  void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
106 
108  const TargetMachine &TM) const override;
109 
111  const TargetMachine &TM) const override;
112 
114  const Constant *C,
115  unsigned &Align) const override;
116 
117  /// The mach-o version of this method defaults to returning a stub reference.
118  const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
119  unsigned Encoding,
120  const TargetMachine &TM,
121  MachineModuleInfo *MMI,
122  MCStreamer &Streamer) const override;
123 
124  // The symbol that gets passed to .cfi_personality.
126  const TargetMachine &TM,
127  MachineModuleInfo *MMI) const override;
128 
129  /// Get MachO PC relative GOT entry relocation
131  const MCSymbol *Sym,
132  const MCValue &MV, int64_t Offset,
133  MachineModuleInfo *MMI,
134  MCStreamer &Streamer) const override;
135 
136  void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
137  const TargetMachine &TM) const override;
138 };
139 
141  mutable unsigned NextUniqueID = 0;
142 
143 public:
144  ~TargetLoweringObjectFileCOFF() override = default;
145 
146  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
148  const TargetMachine &TM) const override;
149 
151  const TargetMachine &TM) const override;
152 
153  void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
154  const TargetMachine &TM) const override;
155 
157  const TargetMachine &TM) const override;
158 
159  /// Emit Obj-C garbage collection and linker options.
160  void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
161 
162  MCSection *getStaticCtorSection(unsigned Priority,
163  const MCSymbol *KeySym) const override;
164  MCSection *getStaticDtorSection(unsigned Priority,
165  const MCSymbol *KeySym) const override;
166 
168  const GlobalValue *GV) const override;
169 
171  const GlobalValue *GV) const override;
172 
173  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
174  const GlobalValue *RHS,
175  const TargetMachine &TM) const override;
176 
177  /// Given a mergeable constant with the specified size and relocation
178  /// information, return a section that it should be placed in.
180  const Constant *C,
181  unsigned &Align) const override;
182 };
183 
185  mutable unsigned NextUniqueID = 0;
186 
187 public:
188  TargetLoweringObjectFileWasm() = default;
189  ~TargetLoweringObjectFileWasm() override = default;
190 
192  const TargetMachine &TM) const override;
193 
195  const TargetMachine &TM) const override;
196 
197  bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
198  const Function &F) const override;
199 
200  void InitializeWasm();
201  MCSection *getStaticCtorSection(unsigned Priority,
202  const MCSymbol *KeySym) const override;
203  MCSection *getStaticDtorSection(unsigned Priority,
204  const MCSymbol *KeySym) const override;
205 
206  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
207  const GlobalValue *RHS,
208  const TargetMachine &TM) const override;
209 };
210 
212 public:
213  TargetLoweringObjectFileXCOFF() = default;
214  ~TargetLoweringObjectFileXCOFF() override = default;
215 
216  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
217 
218  bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
219  const Function &F) const override;
220 
222  const TargetMachine &TM) const override;
223 
224  MCSection *getStaticCtorSection(unsigned Priority,
225  const MCSymbol *KeySym) const override;
226  MCSection *getStaticDtorSection(unsigned Priority,
227  const MCSymbol *KeySym) const override;
228 
229  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
230  const GlobalValue *RHS,
231  const TargetMachine &TM) const override;
232 
234  const TargetMachine &TM) const override;
235 
236  static XCOFF::StorageClass getStorageClassForGlobal(const GlobalObject *GO);
237 };
238 
239 } // end namespace llvm
240 
241 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
uint64_t CallInst * C
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
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 * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym) const override
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
F(f)
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, unsigned &Align) const override
Given a constant with the SectionKind, return a section that it should be placed in.
virtual void emitLinkerFlagsForUsed(raw_ostream &OS, const GlobalValue *GV) const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Context object for machine code objects.
Definition: MCContext.h:65
StorageClass
Definition: XCOFF.h:75
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Streaming machine code generation interface.
Definition: MCStreamer.h:189
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV) const
This is an important base class in LLVM.
Definition: Constant.h:41
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...
~TargetLoweringObjectFileELF() override=default
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Module.h This file contains the declarations for the Module class.
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
This class contains meta information specific to a module.