reduce #includage
[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/MC/SectionKind.h"
19
20 namespace llvm {
21   class Mangler;
22   class MCSection;
23   class MCContext;
24   class GlobalValue;
25   class StringRef;
26   class TargetMachine;
27   class TargetAsmInfo;
28   
29 class TargetLoweringObjectFile {
30   MCContext *Ctx;
31 protected:
32   
33   TargetLoweringObjectFile();
34   
35   /// TextSection - Section directive for standard text.
36   ///
37   const MCSection *TextSection;
38   
39   /// DataSection - Section directive for standard data.
40   ///
41   const MCSection *DataSection;
42   
43   /// BSSSection - Section that is default initialized to zero.
44   const MCSection *BSSSection;
45   
46   /// ReadOnlySection - Section that is readonly and can contain arbitrary
47   /// initialized data.  Targets are not required to have a readonly section.
48   /// If they don't, various bits of code will fall back to using the data
49   /// section for constants.
50   const MCSection *ReadOnlySection;
51   
52   /// StaticCtorSection - This section contains the static constructor pointer
53   /// list.
54   const MCSection *StaticCtorSection;
55
56   /// StaticDtorSection - This section contains the static destructor pointer
57   /// list.
58   const MCSection *StaticDtorSection;
59   
60   /// LSDASection - If exception handling is supported by the target, this is
61   /// the section the Language Specific Data Area information is emitted to.
62   const MCSection *LSDASection;
63   
64   /// EHFrameSection - If exception handling is supported by the target, this is
65   /// the section the EH Frame is emitted to.
66   const MCSection *EHFrameSection;
67   
68   // Dwarf sections for debug info.  If a target supports debug info, these must
69   // be set.
70   const MCSection *DwarfAbbrevSection;
71   const MCSection *DwarfInfoSection;
72   const MCSection *DwarfLineSection;
73   const MCSection *DwarfFrameSection;
74   const MCSection *DwarfPubNamesSection;
75   const MCSection *DwarfPubTypesSection;
76   const MCSection *DwarfDebugInlineSection;
77   const MCSection *DwarfStrSection;
78   const MCSection *DwarfLocSection;
79   const MCSection *DwarfARangesSection;
80   const MCSection *DwarfRangesSection;
81   const MCSection *DwarfMacroInfoSection;
82   
83 public:
84   
85   MCContext &getContext() const { return *Ctx; }
86   
87
88   virtual ~TargetLoweringObjectFile();
89   
90   /// Initialize - this method must be called before any actual lowering is
91   /// done.  This specifies the current context for codegen, and gives the
92   /// lowering implementations a chance to set up their default sections.
93   virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
94     Ctx = &ctx;
95   }
96   
97   
98   const MCSection *getTextSection() const { return TextSection; }
99   const MCSection *getDataSection() const { return DataSection; }
100   const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
101   const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
102   const MCSection *getLSDASection() const { return LSDASection; }
103   const MCSection *getEHFrameSection() const { return EHFrameSection; }
104   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
105   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
106   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
107   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
108   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
109   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
110   const MCSection *getDwarfDebugInlineSection() const {
111     return DwarfDebugInlineSection;
112   }
113   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
114   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
115   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
116   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
117   const MCSection *getDwarfMacroInfoSection() const {
118     return DwarfMacroInfoSection;
119   }
120   
121   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
122   /// decide not to emit the UsedDirective for some symbols in llvm.used.
123   /// FIXME: REMOVE this (rdar://7071300)
124   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
125                                           Mangler *) const {
126     return GV != 0;
127   }
128   
129   /// getSectionForConstant - Given a constant with the SectionKind, return a
130   /// section that it should be placed in.
131   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
132   
133   /// getKindForGlobal - Classify the specified global variable into a set of
134   /// target independent categories embodied in SectionKind.
135   static SectionKind getKindForGlobal(const GlobalValue *GV,
136                                       const TargetMachine &TM);
137   
138   /// SectionForGlobal - This method computes the appropriate section to emit
139   /// the specified global variable or function definition.  This should not
140   /// be passed external (or available externally) globals.
141   const MCSection *SectionForGlobal(const GlobalValue *GV,
142                                     SectionKind Kind, Mangler *Mang,
143                                     const TargetMachine &TM) const;
144   
145   /// SectionForGlobal - This method computes the appropriate section to emit
146   /// the specified global variable or function definition.  This should not
147   /// be passed external (or available externally) globals.
148   const MCSection *SectionForGlobal(const GlobalValue *GV,
149                                     Mangler *Mang,
150                                     const TargetMachine &TM) const {
151     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
152   }
153   
154   
155   
156   /// getExplicitSectionGlobal - Targets should implement this method to assign
157   /// a section to globals with an explicit section specfied.  The
158   /// implementation of this method can assume that GV->hasSection() is true.
159   virtual const MCSection *
160   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
161                            Mangler *Mang, const TargetMachine &TM) const = 0;
162   
163   /// getSpecialCasedSectionGlobals - Allow the target to completely override
164   /// section assignment of a global.
165   virtual const MCSection *
166   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
167                                 SectionKind Kind) const {
168     return 0;
169   }
170   
171 protected:
172   virtual const MCSection *
173   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
174                          Mangler *Mang, const TargetMachine &TM) const;
175 };
176   
177   
178   
179
180 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
181   bool HasCrazyBSS;
182 protected:
183   /// TLSDataSection - Section directive for Thread Local data.
184   ///
185   const MCSection *TLSDataSection;        // Defaults to ".tdata".
186   
187   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
188   /// Null if this target doesn't support a BSS section.
189   ///
190   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
191   
192   const MCSection *DataRelSection;
193   const MCSection *DataRelLocalSection;
194   const MCSection *DataRelROSection;
195   const MCSection *DataRelROLocalSection;
196   
197   const MCSection *MergeableConst4Section;
198   const MCSection *MergeableConst8Section;
199   const MCSection *MergeableConst16Section;
200   
201 protected:
202   const MCSection *getELFSection(const char *Name, bool isDirective,
203                                  SectionKind Kind) const;
204 public:
205   TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
206                               bool hasCrazyBSS = false)
207     : HasCrazyBSS(hasCrazyBSS) {}
208   
209   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
210   
211   /// getSectionForConstant - Given a constant with the SectionKind, return a
212   /// section that it should be placed in.
213   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
214   
215   
216   virtual const MCSection *
217   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
218                            Mangler *Mang, const TargetMachine &TM) const;
219   
220   virtual const MCSection *
221   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
222                          Mangler *Mang, const TargetMachine &TM) const;
223 };
224
225   
226   
227 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
228   const MCSection *CStringSection;
229   const MCSection *UStringSection;
230   const MCSection *TextCoalSection;
231   const MCSection *ConstTextCoalSection;
232   const MCSection *ConstDataCoalSection;
233   const MCSection *ConstDataSection;
234   const MCSection *DataCoalSection;
235   const MCSection *FourByteConstantSection;
236   const MCSection *EightByteConstantSection;
237   const MCSection *SixteenByteConstantSection;
238 public:
239   
240   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
241
242   virtual const MCSection *
243   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
244                          Mangler *Mang, const TargetMachine &TM) const;
245   
246   virtual const MCSection *
247   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
248                            Mangler *Mang, const TargetMachine &TM) const;
249   
250   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
251   
252   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
253   /// decide not to emit the UsedDirective for some symbols in llvm.used.
254   /// FIXME: REMOVE this (rdar://7071300)
255   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
256                                           Mangler *) const;
257
258   /// getMachOSection - Return the MCSection for the specified mach-o section.
259   /// This requires the operands to be valid.
260   const MCSection *getMachOSection(const StringRef &Segment,
261                                    const StringRef &Section,
262                                    unsigned TypeAndAttributes,
263                                    SectionKind K) const {
264     return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
265   }
266   const MCSection *getMachOSection(const StringRef &Segment,
267                                    const StringRef &Section,
268                                    unsigned TypeAndAttributes,
269                                    unsigned Reserved2, SectionKind K) const;
270
271   /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
272   /// symbols into.
273   const MCSection *getTextCoalSection() const {
274     return TextCoalSection;
275   }
276   
277   /// getLazySymbolPointerSection - Return the section corresponding to
278   /// the .lazy_symbol_pointer directive.
279   const MCSection *getLazySymbolPointerSection() const;
280   
281   /// getNonLazySymbolPointerSection - Return the section corresponding to
282   /// the .non_lazy_symbol_pointer directive.
283   const MCSection *getNonLazySymbolPointerSection() const;
284   
285 };
286
287
288
289 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
290 public:
291   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
292   
293   virtual const MCSection *
294   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
295                            Mangler *Mang, const TargetMachine &TM) const;
296   
297   virtual const MCSection *
298   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
299                          Mangler *Mang, const TargetMachine &TM) const;
300
301   /// getCOFFSection - Return the MCSection for the specified COFF section.
302   /// FIXME: Switch this to a semantic view eventually.
303   const MCSection *getCOFFSection(const char *Name, bool isDirective,
304                                   SectionKind K) const;
305 };
306
307 } // end namespace llvm
308
309 #endif