blob: 78da77fbd480f69fee1be666dab6bb4e4a7e50e9 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//==- 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
22namespace llvm {
23
24class GlobalValue;
25class MachineModuleInfo;
26class Mangler;
27class MCContext;
28class MCSection;
29class MCSymbol;
30class TargetMachine;
31
32class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
33 bool UseInitArray = false;
34 mutable unsigned NextUniqueID = 1; // ID 0 is reserved for execute-only sections
35
36protected:
37 MCSymbolRefExpr::VariantKind PLTRelativeVariantKind =
38 MCSymbolRefExpr::VK_None;
39
40public:
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.
53 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
54 const Constant *C,
55 unsigned &Align) const override;
56
57 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
58 const TargetMachine &TM) const override;
59
60 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
61 const TargetMachine &TM) const override;
62
63 MCSection *getSectionForJumpTable(const Function &F,
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.
71 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
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.
78 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
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
93class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
94public:
95 TargetLoweringObjectFileMachO();
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
104 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
105 const TargetMachine &TM) const override;
106
107 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
108 const TargetMachine &TM) const override;
109
110 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
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.
122 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
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
136class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
137 mutable unsigned NextUniqueID = 0;
138
139public:
140 ~TargetLoweringObjectFileCOFF() override = default;
141
142 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
143 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
144 const TargetMachine &TM) const override;
145
146 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
147 const TargetMachine &TM) const override;
148
149 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
150 const TargetMachine &TM) const override;
151
152 MCSection *getSectionForJumpTable(const Function &F,
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
164 void emitLinkerFlagsForGlobal(raw_ostream &OS,
165 const GlobalValue *GV) const override;
166
167 void emitLinkerFlagsForUsed(raw_ostream &OS,
168 const GlobalValue *GV) const override;
169};
170
171class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile {
172 mutable unsigned NextUniqueID = 0;
173
174public:
175 TargetLoweringObjectFileWasm() = default;
176 ~TargetLoweringObjectFileWasm() override = default;
177
178 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
179 const TargetMachine &TM) const override;
180
181 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
182 const TargetMachine &TM) const override;
183
184 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
185 const Function &F) const override;
186
187 void InitializeWasm();
188 MCSection *getStaticCtorSection(unsigned Priority,
189 const MCSymbol *KeySym) const override;
190 MCSection *getStaticDtorSection(unsigned Priority,
191 const MCSymbol *KeySym) const override;
192
193 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
194 const GlobalValue *RHS,
195 const TargetMachine &TM) const override;
196};
197
198} // end namespace llvm
199
200#endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H