411e4ccd081df99f8870fb3a3a2b960cd03a5596
[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 protected:
37   /// TLSDataSection - Section directive for Thread Local data.
38   ///
39   const MCSection *TLSDataSection;        // Defaults to ".tdata".
40
41   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
42   /// Null if this target doesn't support a BSS section.
43   ///
44   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
45
46   const MCSection *DataRelSection;
47   const MCSection *DataRelLocalSection;
48   const MCSection *DataRelROSection;
49   const MCSection *DataRelROLocalSection;
50
51   const MCSection *MergeableConst4Section;
52   const MCSection *MergeableConst8Section;
53   const MCSection *MergeableConst16Section;
54 public:
55   TargetLoweringObjectFileELF() {}
56   ~TargetLoweringObjectFileELF() {}
57
58   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
59
60   virtual const MCSection *getEHFrameSection() const;
61
62   virtual void emitPersonalityValue(MCStreamer &Streamer,
63                                     const TargetMachine &TM,
64                                     const MCSymbol *Sym) const;
65
66   const MCSection *getDataRelSection() const { return DataRelSection; }
67
68   /// getSectionForConstant - Given a constant with the SectionKind, return a
69   /// section that it should be placed in.
70   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
71
72
73   virtual const MCSection *
74   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
75                            Mangler *Mang, const TargetMachine &TM) const;
76
77   virtual const MCSection *
78   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
79                          Mangler *Mang, const TargetMachine &TM) const;
80
81   /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
82   /// to the specified global variable from exception handling information.
83   ///
84   virtual const MCExpr *
85   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
86                                  MachineModuleInfo *MMI, unsigned Encoding,
87                                  MCStreamer &Streamer) const;
88
89   // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
90   virtual MCSymbol *
91   getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding,
92                           Mangler *Mang, MachineModuleInfo *MMI) const;
93 };
94
95
96
97 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
98   /// TLSDataSection - Section for thread local data.
99   ///
100   const MCSection *TLSDataSection;        // Defaults to ".tdata".
101
102   /// TLSBSSSection - Section for thread local uninitialized data.
103   ///
104   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
105   
106   /// TLSTLVSection - Section for thread local structure information.
107   /// Contains the source code name of the variable, visibility and a pointer
108   /// to the initial value (.tdata or .tbss).
109   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
110   
111   /// TLSThreadInitSection - Section for thread local data initialization
112   /// functions.
113   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
114   
115   const MCSection *CStringSection;
116   const MCSection *UStringSection;
117   const MCSection *TextCoalSection;
118   const MCSection *ConstTextCoalSection;
119   const MCSection *ConstDataSection;
120   const MCSection *DataCoalSection;
121   const MCSection *DataCommonSection;
122   const MCSection *DataBSSSection;
123   const MCSection *FourByteConstantSection;
124   const MCSection *EightByteConstantSection;
125   const MCSection *SixteenByteConstantSection;
126
127   const MCSection *LazySymbolPointerSection;
128   const MCSection *NonLazySymbolPointerSection;
129 public:
130   TargetLoweringObjectFileMachO() {}
131   ~TargetLoweringObjectFileMachO() {}
132
133   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
134
135   virtual const MCSection *getEHFrameSection() const;
136
137   virtual const MCSection *
138   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
139                          Mangler *Mang, const TargetMachine &TM) const;
140
141   virtual const MCSection *
142   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
143                            Mangler *Mang, const TargetMachine &TM) const;
144
145   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
146
147   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
148   /// decide not to emit the UsedDirective for some symbols in llvm.used.
149   /// FIXME: REMOVE this (rdar://7071300)
150   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
151                                           Mangler *) const;
152
153   /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
154   /// text symbols into.
155   const MCSection *getTextCoalSection() const {
156     return TextCoalSection;
157   }
158
159   /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
160   /// we put weak read-only symbols into.
161   const MCSection *getConstTextCoalSection() const {
162     return ConstTextCoalSection;
163   }
164
165   /// getLazySymbolPointerSection - Return the section corresponding to
166   /// the .lazy_symbol_pointer directive.
167   const MCSection *getLazySymbolPointerSection() const {
168     return LazySymbolPointerSection;
169   }
170
171   /// getNonLazySymbolPointerSection - Return the section corresponding to
172   /// the .non_lazy_symbol_pointer directive.
173   const MCSection *getNonLazySymbolPointerSection() const {
174     return NonLazySymbolPointerSection;
175   }
176
177   /// getExprForDwarfGlobalReference - The mach-o version of this method
178   /// defaults to returning a stub reference.
179   virtual const MCExpr *
180   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
181                                  MachineModuleInfo *MMI, unsigned Encoding,
182                                  MCStreamer &Streamer) const;
183
184   // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
185   virtual MCSymbol *
186   getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding,
187                           Mangler *Mang, MachineModuleInfo *MMI) const;
188
189   virtual unsigned getPersonalityEncoding() const;
190   virtual unsigned getLSDAEncoding() const;
191   virtual unsigned getFDEEncoding() const;
192   virtual unsigned getTTypeEncoding() const;
193 };
194
195
196
197 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
198   const MCSection *DrectveSection;
199 public:
200   TargetLoweringObjectFileCOFF() {}
201   ~TargetLoweringObjectFileCOFF() {}
202
203   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
204
205   virtual const MCSection *getEHFrameSection() const;
206
207   virtual const MCSection *getDrectveSection() const { return DrectveSection; }
208
209   virtual const MCSection *
210   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
211                            Mangler *Mang, const TargetMachine &TM) const;
212
213   virtual const MCSection *
214   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
215                          Mangler *Mang, const TargetMachine &TM) const;
216 };
217
218 } // end namespace llvm
219
220 #endif