]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
Merge ^/head r319251 through r319479.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / CodeGen / TargetLoweringObjectFileImpl.h
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"
20 #include "llvm/Target/TargetLoweringObjectFile.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
32 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
33   bool UseInitArray = false;
34   mutable unsigned NextUniqueID = 1;  // ID 0 is reserved for execute-only sections
35
36 protected:
37   MCSymbolRefExpr::VariantKind PLTRelativeVariantKind =
38       MCSymbolRefExpr::VK_None;
39
40 public:
41   TargetLoweringObjectFileELF() = default;
42   ~TargetLoweringObjectFileELF() override = default;
43
44   void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
45                             const MCSymbol *Sym) const override;
46
47   /// Given a constant with the SectionKind, return a section that it should be
48   /// placed in.
49   MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
50                                    const Constant *C,
51                                    unsigned &Align) const override;
52
53   MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
54                                       const TargetMachine &TM) const override;
55
56   MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
57                                     const TargetMachine &TM) const override;
58
59   MCSection *getSectionForJumpTable(const Function &F,
60                                     const TargetMachine &TM) const override;
61
62   bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
63                                            const Function &F) const override;
64
65   /// Return an MCExpr to use for a reference to the specified type info global
66   /// variable from exception handling information.
67   const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
68                                         unsigned Encoding,
69                                         const TargetMachine &TM,
70                                         MachineModuleInfo *MMI,
71                                         MCStreamer &Streamer) const override;
72
73   // The symbol that gets passed to .cfi_personality.
74   MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
75                                     const TargetMachine &TM,
76                                     MachineModuleInfo *MMI) const override;
77
78   void InitializeELF(bool UseInitArray_);
79   MCSection *getStaticCtorSection(unsigned Priority,
80                                   const MCSymbol *KeySym) const override;
81   MCSection *getStaticDtorSection(unsigned Priority,
82                                   const MCSymbol *KeySym) const override;
83
84   const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
85                                        const GlobalValue *RHS,
86                                        const TargetMachine &TM) const override;
87 };
88
89 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
90 public:
91   TargetLoweringObjectFileMachO();
92   ~TargetLoweringObjectFileMachO() override = default;
93
94   void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
95
96   /// Emit the module flags that specify the garbage collection information.
97   void emitModuleFlags(MCStreamer &Streamer,
98                        ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
99                        const TargetMachine &TM) const override;
100
101   MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
102                                     const TargetMachine &TM) const override;
103
104   MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
105                                       const TargetMachine &TM) const override;
106
107   MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
108                                    const Constant *C,
109                                    unsigned &Align) const override;
110
111   /// The mach-o version of this method defaults to returning a stub reference.
112   const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
113                                         unsigned Encoding,
114                                         const TargetMachine &TM,
115                                         MachineModuleInfo *MMI,
116                                         MCStreamer &Streamer) const override;
117
118   // The symbol that gets passed to .cfi_personality.
119   MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
120                                     const TargetMachine &TM,
121                                     MachineModuleInfo *MMI) const override;
122
123   /// Get MachO PC relative GOT entry relocation
124   const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
125                                           const MCValue &MV, int64_t Offset,
126                                           MachineModuleInfo *MMI,
127                                           MCStreamer &Streamer) const override;
128
129   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
130                          const TargetMachine &TM) const override;
131 };
132
133 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
134   mutable unsigned NextUniqueID = 0;
135
136 public:
137   ~TargetLoweringObjectFileCOFF() override = default;
138
139   void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
140   MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
141                                       const TargetMachine &TM) const override;
142
143   MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
144                                     const TargetMachine &TM) const override;
145
146   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
147                          const TargetMachine &TM) const override;
148
149   MCSection *getSectionForJumpTable(const Function &F,
150                                     const TargetMachine &TM) const override;
151
152   /// Emit Obj-C garbage collection and linker options. Only linker option
153   /// emission is implemented for COFF.
154   void emitModuleFlags(MCStreamer &Streamer,
155                        ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
156                        const TargetMachine &TM) const override;
157
158   MCSection *getStaticCtorSection(unsigned Priority,
159                                   const MCSymbol *KeySym) const override;
160   MCSection *getStaticDtorSection(unsigned Priority,
161                                   const MCSymbol *KeySym) const override;
162
163   void emitLinkerFlagsForGlobal(raw_ostream &OS,
164                                 const GlobalValue *GV) const override;
165 };
166
167 class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile {
168   mutable unsigned NextUniqueID = 0;
169
170 public:
171   TargetLoweringObjectFileWasm() = default;
172   ~TargetLoweringObjectFileWasm() override = default;
173
174   MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
175                                       const TargetMachine &TM) const override;
176
177   MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
178                                     const TargetMachine &TM) const override;
179
180   bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
181                                            const Function &F) const override;
182
183   void InitializeWasm();
184
185   const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
186                                        const GlobalValue *RHS,
187                                        const TargetMachine &TM) const override;
188 };
189
190 } // end namespace llvm
191
192 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H