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