convert EHFrameSection to be managed by TLOF instead of TAI.
[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/SmallVector.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/MC/SectionKind.h"
21
22 namespace llvm {
23   class MCSection;
24   class MCContext;
25   class GlobalValue;
26   class Mangler;
27   class TargetMachine;
28   
29  
30 class TargetLoweringObjectFile {
31   MCContext *Ctx;
32 protected:
33   
34   TargetLoweringObjectFile();
35   
36   /// TextSection - Section directive for standard text.
37   ///
38   const MCSection *TextSection;
39   
40   /// DataSection - Section directive for standard data.
41   ///
42   const MCSection *DataSection;
43   
44   /// BSSSection - Section that is default initialized to zero.
45   const MCSection *BSSSection;
46   
47   /// ReadOnlySection - Section that is readonly and can contain arbitrary
48   /// initialized data.  Targets are not required to have a readonly section.
49   /// If they don't, various bits of code will fall back to using the data
50   /// section for constants.
51   const MCSection *ReadOnlySection;
52   
53   /// StaticCtorSection - This section contains the static constructor pointer
54   /// list.
55   const MCSection *StaticCtorSection;
56
57   /// StaticDtorSection - This section contains the static destructor pointer
58   /// list.
59   const MCSection *StaticDtorSection;
60   
61   /// LSDASection - If exception handling is supported by the target, this is
62   /// the section the Language Specific Data Area information is emitted to.
63   const MCSection *LSDASection;
64   
65   /// EHFrameSection - If exception handling is supported by the target, this is
66   /// the section the EH Frame is emitted to.
67   const MCSection *EHFrameSection;
68   
69   
70 public:
71   // FIXME: NONPUB.
72   const MCSection *getOrCreateSection(const char *Name,
73                                       bool isDirective,
74                                       SectionKind K) const;
75 public:
76   
77   virtual ~TargetLoweringObjectFile();
78   
79   /// Initialize - this method must be called before any actual lowering is
80   /// done.  This specifies the current context for codegen, and gives the
81   /// lowering implementations a chance to set up their default sections.
82   virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
83     Ctx = &ctx;
84   }
85   
86   
87   const MCSection *getTextSection() const { return TextSection; }
88   const MCSection *getDataSection() const { return DataSection; }
89   const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
90   const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
91   const MCSection *getLSDASection() const { return LSDASection; }
92   const MCSection *getEHFrameSection() const { return EHFrameSection; }
93
94   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
95   /// decide not to emit the UsedDirective for some symbols in llvm.used.
96   /// FIXME: REMOVE this (rdar://7071300)
97   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
98                                           Mangler *) const {
99     return GV != 0;
100   }
101   
102   /// getSectionForConstant - Given a constant with the SectionKind, return a
103   /// section that it should be placed in.
104   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
105   
106   /// getKindForNamedSection - If this target wants to be able to override
107   /// section flags based on the name of the section specified for a global
108   /// variable, it can implement this.  This is used on ELF systems so that
109   /// ".tbss" gets the TLS bit set etc.
110   virtual SectionKind getKindForNamedSection(const char *Section,
111                                              SectionKind K) const {
112     return K;
113   }
114   
115   /// SectionForGlobal - This method computes the appropriate section to emit
116   /// the specified global variable or function definition.  This should not
117   /// be passed external (or available externally) globals.
118   const MCSection *SectionForGlobal(const GlobalValue *GV,
119                                     Mangler *Mang,
120                                     const TargetMachine &TM) const;
121   
122   /// getSpecialCasedSectionGlobals - Allow the target to completely override
123   /// section assignment of a global.
124   /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
125   /// getFlagsForNamedSection.
126   virtual const MCSection *
127   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
128                                 SectionKind Kind) const {
129     return 0;
130   }
131   
132   /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
133   /// into a string that can be printed to the assembly file after the
134   /// ".section foo" part of a section directive.
135   virtual void getSectionFlagsAsString(SectionKind Kind,
136                                        SmallVectorImpl<char> &Str) const {
137   }
138   
139 protected:
140   virtual const MCSection *
141   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
142                          Mangler *Mang, const TargetMachine &TM) const;
143 };
144   
145   
146   
147
148 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
149   bool AtIsCommentChar;  // True if @ is the comment character on this target.
150   bool HasCrazyBSS;
151 protected:
152   /// TLSDataSection - Section directive for Thread Local data.
153   ///
154   const MCSection *TLSDataSection;        // Defaults to ".tdata".
155   
156   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
157   /// Null if this target doesn't support a BSS section.
158   ///
159   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
160   
161   const MCSection *CStringSection;
162   
163   const MCSection *DataRelSection;
164   const MCSection *DataRelLocalSection;
165   const MCSection *DataRelROSection;
166   const MCSection *DataRelROLocalSection;
167   
168   const MCSection *MergeableConst4Section;
169   const MCSection *MergeableConst8Section;
170   const MCSection *MergeableConst16Section;
171 public:
172   /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
173   /// is "@".
174   TargetLoweringObjectFileELF(bool atIsCommentChar = false,
175                               // FIXME: REMOVE AFTER UNIQUING IS FIXED.
176                               bool hasCrazyBSS = false)
177     : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
178     
179   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
180   
181   
182   /// getSectionForConstant - Given a constant with the SectionKind, return a
183   /// section that it should be placed in.
184   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
185   
186   virtual SectionKind getKindForNamedSection(const char *Section,
187                                              SectionKind K) const;
188   void getSectionFlagsAsString(SectionKind Kind,
189                                SmallVectorImpl<char> &Str) const;
190   
191   virtual const MCSection *
192   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
193                          Mangler *Mang, const TargetMachine &TM) const;
194 };
195
196   
197   
198 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
199   const MCSection *CStringSection;
200   const MCSection *TextCoalSection;
201   const MCSection *ConstTextCoalSection;
202   const MCSection *ConstDataCoalSection;
203   const MCSection *ConstDataSection;
204   const MCSection *DataCoalSection;
205   const MCSection *FourByteConstantSection;
206   const MCSection *EightByteConstantSection;
207   const MCSection *SixteenByteConstantSection;
208 public:
209   
210   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
211
212   virtual const MCSection *
213   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
214                          Mangler *Mang, const TargetMachine &TM) const;
215   
216   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
217   
218   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
219   /// decide not to emit the UsedDirective for some symbols in llvm.used.
220   /// FIXME: REMOVE this (rdar://7071300)
221   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
222                                           Mangler *) const;
223 };
224
225
226
227 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
228 public:
229   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
230   
231   virtual void getSectionFlagsAsString(SectionKind Kind,
232                                        SmallVectorImpl<char> &Str) const;
233   
234   virtual const MCSection *
235   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
236                          Mangler *Mang, const TargetMachine &TM) const;
237 };
238
239 } // end namespace llvm
240
241 #endif