a868cbd020fdf2dbae725dbc6d8d5bc93a66b432
[oota-llvm.git] / 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/ADT/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
20 #include "llvm/Target/TargetLoweringObjectFile.h"
21
22 namespace llvm {
23   class MachineModuleInfo;
24   class Mangler;
25   class MCAsmInfo;
26   class MCExpr;
27   class MCSection;
28   class MCSectionMachO;
29   class MCSymbol;
30   class MCContext;
31   class GlobalValue;
32   class TargetMachine;
33
34
35 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
36   bool UseInitArray;
37   mutable unsigned NextUniqueID = 0;
38
39 public:
40   TargetLoweringObjectFileELF() : UseInitArray(false) {}
41
42   ~TargetLoweringObjectFileELF() override {}
43
44   void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &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   const MCSection *getSectionForConstant(SectionKind Kind,
50                                          const Constant *C) const override;
51
52   const MCSection *getExplicitSectionGlobal(const GlobalValue *GV,
53                                         SectionKind Kind, Mangler &Mang,
54                                         const TargetMachine &TM) const override;
55
56   const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
57                                         SectionKind Kind, Mangler &Mang,
58                                         const TargetMachine &TM) const override;
59
60   const MCSection *
61   getSectionForJumpTable(const Function &F, Mangler &Mang,
62                          const TargetMachine &TM) const override;
63
64   bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
65                                            const Function &F) const override;
66
67   /// Return an MCExpr to use for a reference to the specified type info global
68   /// variable from exception handling information.
69   const MCExpr *
70   getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
71                           Mangler &Mang, const TargetMachine &TM,
72                           MachineModuleInfo *MMI,
73                           MCStreamer &Streamer) const override;
74
75   // The symbol that gets passed to .cfi_personality.
76   MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
77                                     const TargetMachine &TM,
78                                     MachineModuleInfo *MMI) const override;
79
80   void InitializeELF(bool UseInitArray_);
81   const MCSection *getStaticCtorSection(unsigned Priority,
82                                         const MCSymbol *KeySym) const override;
83   const MCSection *getStaticDtorSection(unsigned Priority,
84                                         const MCSymbol *KeySym) const override;
85 };
86
87
88
89 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
90 public:
91   ~TargetLoweringObjectFileMachO() override {}
92   TargetLoweringObjectFileMachO();
93
94   /// Extract the dependent library name from a linker option string. Returns
95   /// StringRef() if the option does not specify a library.
96   StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
97
98   /// Emit the module flags that specify the garbage collection information.
99   void emitModuleFlags(MCStreamer &Streamer,
100                        ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
101                        Mangler &Mang, const TargetMachine &TM) const override;
102
103   const MCSection *
104     SelectSectionForGlobal(const GlobalValue *GV,
105                            SectionKind Kind, Mangler &Mang,
106                            const TargetMachine &TM) const override;
107
108   const MCSection *
109     getExplicitSectionGlobal(const GlobalValue *GV,
110                              SectionKind Kind, Mangler &Mang,
111                              const TargetMachine &TM) const override;
112
113   const MCSection *getSectionForConstant(SectionKind Kind,
114                                          const Constant *C) const override;
115
116   /// The mach-o version of this method defaults to returning a stub reference.
117   const MCExpr *
118   getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
119                           Mangler &Mang, const TargetMachine &TM,
120                           MachineModuleInfo *MMI,
121                           MCStreamer &Streamer) const override;
122
123   // The symbol that gets passed to .cfi_personality.
124   MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
125                                     const TargetMachine &TM,
126                                     MachineModuleInfo *MMI) const override;
127
128   /// Get MachO PC relative GOT entry relocation
129   const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
130                                           const MCValue &MV, int64_t Offset,
131                                           MachineModuleInfo *MMI,
132                                           MCStreamer &Streamer) const override;
133 };
134
135
136
137 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
138 public:
139   ~TargetLoweringObjectFileCOFF() override {}
140
141   const MCSection *
142     getExplicitSectionGlobal(const GlobalValue *GV,
143                              SectionKind Kind, Mangler &Mang,
144                              const TargetMachine &TM) const override;
145
146   const MCSection *
147     SelectSectionForGlobal(const GlobalValue *GV,
148                            SectionKind Kind, Mangler &Mang,
149                            const TargetMachine &TM) const override;
150
151   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
152                          bool CannotUsePrivateLabel, Mangler &Mang,
153                          const TargetMachine &TM) const override;
154
155   const MCSection *
156   getSectionForJumpTable(const Function &F, Mangler &Mang,
157                          const TargetMachine &TM) const override;
158
159   /// Extract the dependent library name from a linker option string. Returns
160   /// StringRef() if the option does not specify a library.
161   StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
162
163   /// Emit Obj-C garbage collection and linker options. Only linker option
164   /// emission is implemented for COFF.
165   void emitModuleFlags(MCStreamer &Streamer,
166                        ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
167                        Mangler &Mang, const TargetMachine &TM) const override;
168
169   const MCSection *getStaticCtorSection(unsigned Priority,
170                                         const MCSymbol *KeySym) const override;
171   const MCSection *getStaticDtorSection(unsigned Priority,
172                                         const MCSymbol *KeySym) const override;
173 };
174
175 } // end namespace llvm
176
177 #endif