LLVM  5.0.0
TargetLoweringObjectFileImpl.h
Go to the documentation of this file.
1 //==- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info --*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
17 
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 
40 public:
41  TargetLoweringObjectFileELF() = default;
42  ~TargetLoweringObjectFileELF() override = default;
43 
44  /// Emit Obj-C garbage collection and linker options.
45  void emitModuleMetadata(MCStreamer &Streamer, Module &M,
46  const TargetMachine &TM) const override;
47 
48  void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
49  const MCSymbol *Sym) const override;
50 
51  /// Given a constant with the SectionKind, return a section that it should be
52  /// placed in.
54  const Constant *C,
55  unsigned &Align) const override;
56 
58  const TargetMachine &TM) const override;
59 
61  const TargetMachine &TM) const override;
62 
64  const TargetMachine &TM) const override;
65 
66  bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
67  const Function &F) const override;
68 
69  /// Return an MCExpr to use for a reference to the specified type info global
70  /// variable from exception handling information.
72  unsigned Encoding,
73  const TargetMachine &TM,
74  MachineModuleInfo *MMI,
75  MCStreamer &Streamer) const override;
76 
77  // The symbol that gets passed to .cfi_personality.
79  const TargetMachine &TM,
80  MachineModuleInfo *MMI) const override;
81 
82  void InitializeELF(bool UseInitArray_);
83  MCSection *getStaticCtorSection(unsigned Priority,
84  const MCSymbol *KeySym) const override;
85  MCSection *getStaticDtorSection(unsigned Priority,
86  const MCSymbol *KeySym) const override;
87 
88  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
89  const GlobalValue *RHS,
90  const TargetMachine &TM) const override;
91 };
92 
94 public:
96  ~TargetLoweringObjectFileMachO() override = default;
97 
98  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
99 
100  /// Emit the module flags that specify the garbage collection information.
101  void emitModuleMetadata(MCStreamer &Streamer, Module &M,
102  const TargetMachine &TM) const override;
103 
105  const TargetMachine &TM) const override;
106 
108  const TargetMachine &TM) const override;
109 
111  const Constant *C,
112  unsigned &Align) const override;
113 
114  /// The mach-o version of this method defaults to returning a stub reference.
115  const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
116  unsigned Encoding,
117  const TargetMachine &TM,
118  MachineModuleInfo *MMI,
119  MCStreamer &Streamer) const override;
120 
121  // The symbol that gets passed to .cfi_personality.
123  const TargetMachine &TM,
124  MachineModuleInfo *MMI) const override;
125 
126  /// Get MachO PC relative GOT entry relocation
127  const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
128  const MCValue &MV, int64_t Offset,
129  MachineModuleInfo *MMI,
130  MCStreamer &Streamer) const override;
131 
132  void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
133  const TargetMachine &TM) const override;
134 };
135 
137  mutable unsigned NextUniqueID = 0;
138 
139 public:
140  ~TargetLoweringObjectFileCOFF() override = default;
141 
142  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
144  const TargetMachine &TM) const override;
145 
147  const TargetMachine &TM) const override;
148 
149  void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
150  const TargetMachine &TM) const override;
151 
153  const TargetMachine &TM) const override;
154 
155  /// Emit Obj-C garbage collection and linker options.
156  void emitModuleMetadata(MCStreamer &Streamer, Module &M,
157  const TargetMachine &TM) const override;
158 
159  MCSection *getStaticCtorSection(unsigned Priority,
160  const MCSymbol *KeySym) const override;
161  MCSection *getStaticDtorSection(unsigned Priority,
162  const MCSymbol *KeySym) const override;
163 
165  const GlobalValue *GV) const override;
166 };
167 
169  mutable unsigned NextUniqueID = 0;
170 
171 public:
172  TargetLoweringObjectFileWasm() = default;
173  ~TargetLoweringObjectFileWasm() override = default;
174 
176  const TargetMachine &TM) const override;
177 
179  const TargetMachine &TM) const override;
180 
181  bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
182  const Function &F) const override;
183 
184  void InitializeWasm();
185 
186  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
187  const GlobalValue *RHS,
188  const TargetMachine &TM) const override;
189 };
190 
191 } // end namespace llvm
192 
193 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
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
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
This represents an "assembler immediate".
Definition: MCValue.h:40
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV) const override
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
DataLayout DL
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) 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...
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, const MCSymbol *Sym) const override
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.
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
const MCExpr * getIndirectSymViaGOTPCRel(const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
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
Context object for machine code objects.
Definition: MCContext.h:59
#define F(x, y, z)
Definition: MD5.cpp:55
~TargetLoweringObjectFileWasm() override=default
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 * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
void emitModuleMetadata(MCStreamer &Streamer, Module &M, const TargetMachine &TM) const override
Emit the module flags that specify the garbage collection information.
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
~TargetLoweringObjectFileCOFF() override=default
void emitModuleMetadata(MCStreamer &Streamer, Module &M, const TargetMachine &TM) const override
Emit Obj-C garbage collection and linker options.
Streaming machine code generation interface.
Definition: MCStreamer.h:167
This is an important base class in LLVM.
Definition: Constant.h:42
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:23
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.
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.
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Module.h This file contains the declarations for the Module class.
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind
~TargetLoweringObjectFileMachO() override=default
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
#define C
Definition: LargeTest.cpp:25
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
void emitModuleMetadata(MCStreamer &Streamer, Module &M, const TargetMachine &TM) const override
Emit Obj-C garbage collection and linker options.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const unsigned Kind
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...
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
This class contains meta information specific to a module.
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override