b121fc6bce3b1ae9b4ce2e2201219e30913c13bf
[oota-llvm.git] / include / llvm / Target / TargetLoweringObjectFile.h
1 //===-- llvm/Target/TargetLoweringObjectFile.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_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
17
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
21 #include "llvm/MC/SectionKind.h"
22
23 namespace llvm {
24   class MachineModuleInfo;
25   class Mangler;
26   class MCContext;
27   class MCExpr;
28   class MCSection;
29   class MCSymbol;
30   class MCSymbolRefExpr;
31   class MCStreamer;
32   class ConstantExpr;
33   class GlobalValue;
34   class TargetMachine;
35
36 class TargetLoweringObjectFile : public MCObjectFileInfo {
37   MCContext *Ctx;
38   const DataLayout *DL;
39
40   TargetLoweringObjectFile(
41     const TargetLoweringObjectFile&) = delete;
42   void operator=(const TargetLoweringObjectFile&) = delete;
43
44 protected:
45   bool SupportIndirectSymViaGOTPCRel;
46   bool SupportGOTPCRelWithOffset;
47
48 public:
49   MCContext &getContext() const { return *Ctx; }
50
51   TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr),
52                                SupportIndirectSymViaGOTPCRel(false),
53                                SupportGOTPCRelWithOffset(true) {}
54
55   virtual ~TargetLoweringObjectFile();
56
57   /// This method must be called before any actual lowering is done.  This
58   /// specifies the current context for codegen, and gives the lowering
59   /// implementations a chance to set up their default sections.
60   virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
61
62   virtual void emitPersonalityValue(MCStreamer &Streamer,
63                                     const TargetMachine &TM,
64                                     const MCSymbol *Sym) const;
65
66   /// Extract the dependent library name from a linker option string. Returns
67   /// StringRef() if the option does not specify a library.
68   virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
69     return StringRef();
70   }
71
72   /// Emit the module flags that the platform cares about.
73   virtual void emitModuleFlags(MCStreamer &Streamer,
74                                ArrayRef<Module::ModuleFlagEntry> Flags,
75                                Mangler &Mang, const TargetMachine &TM) const {}
76
77   /// Given a constant with the SectionKind, return a section that it should be
78   /// placed in.
79   virtual const MCSection *getSectionForConstant(SectionKind Kind,
80                                                  const Constant *C) const;
81
82   /// Classify the specified global variable into a set of target independent
83   /// categories embodied in SectionKind.
84   static SectionKind getKindForGlobal(const GlobalValue *GV,
85                                       const TargetMachine &TM);
86
87   /// This method computes the appropriate section to emit the specified global
88   /// variable or function definition. This should not be passed external (or
89   /// available externally) globals.
90   const MCSection *SectionForGlobal(const GlobalValue *GV,
91                                     SectionKind Kind, Mangler &Mang,
92                                     const TargetMachine &TM) const;
93
94   /// This method computes the appropriate section to emit the specified global
95   /// variable or function definition. This should not be passed external (or
96   /// available externally) globals.
97   const MCSection *SectionForGlobal(const GlobalValue *GV,
98                                     Mangler &Mang,
99                                     const TargetMachine &TM) const {
100     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
101   }
102
103   virtual const MCSection *
104   getSectionForJumpTable(const Function &F, Mangler &Mang,
105                          const TargetMachine &TM) const;
106
107   virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
108                                                    const Function &F) const;
109
110   /// Targets should implement this method to assign a section to globals with
111   /// an explicit section specfied. The implementation of this method can
112   /// assume that GV->hasSection() is true.
113   virtual const MCSection *
114   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
115                            Mangler &Mang, const TargetMachine &TM) const = 0;
116
117   /// Allow the target to completely override section assignment of a global.
118   virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
119                                                          SectionKind Kind,
120                                                          Mangler &Mang) const {
121     return nullptr;
122   }
123
124   /// Return an MCExpr to use for a reference to the specified global variable
125   /// from exception handling information.
126   virtual const MCExpr *
127   getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
128                           Mangler &Mang, const TargetMachine &TM,
129                           MachineModuleInfo *MMI, MCStreamer &Streamer) const;
130
131   /// Return the MCSymbol for a private symbol with global value name as its
132   /// base, with the specified suffix.
133   MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
134                                          StringRef Suffix, Mangler &Mang,
135                                          const TargetMachine &TM) const;
136
137   // The symbol that gets passed to .cfi_personality.
138   virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
139                                             Mangler &Mang,
140                                             const TargetMachine &TM,
141                                             MachineModuleInfo *MMI) const;
142
143   const MCExpr *
144   getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
145                     MCStreamer &Streamer) const;
146
147   virtual const MCSection *getStaticCtorSection(unsigned Priority,
148                                                 const MCSymbol *KeySym) const {
149     return StaticCtorSection;
150   }
151
152   virtual const MCSection *getStaticDtorSection(unsigned Priority,
153                                                 const MCSymbol *KeySym) const {
154     return StaticDtorSection;
155   }
156
157   /// \brief Create a symbol reference to describe the given TLS variable when
158   /// emitting the address in debug info.
159   virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
160
161   virtual const MCExpr *
162   getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
163                               const TargetMachine &TM) const {
164     return nullptr;
165   }
166
167   /// \brief Target supports replacing a data "PC"-relative access to a symbol
168   /// through another symbol, by accessing the later via a GOT entry instead?
169   bool supportIndirectSymViaGOTPCRel() const {
170     return SupportIndirectSymViaGOTPCRel;
171   }
172
173   /// \brief Target GOT "PC"-relative relocation supports encoding an additional
174   /// binary expression with an offset?
175   bool supportGOTPCRelWithOffset() const {
176     return SupportGOTPCRelWithOffset;
177   }
178
179   /// \brief Get the target specific PC relative GOT entry relocation
180   virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
181                                                   int64_t Offset,
182                                                   MCStreamer &Streamer) const {
183     return nullptr;
184   }
185
186 protected:
187   virtual const MCSection *
188   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
189                          Mangler &Mang, const TargetMachine &TM) const = 0;
190 };
191
192 } // end namespace llvm
193
194 #endif