f6b1220e6cb8958a7074ff00b59f8c2e2afdb871
[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 public:
54   // FIXME: NONPUB.
55   const MCSection *getOrCreateSection(const char *Name,
56                                       bool isDirective,
57                                       SectionKind K) const;
58 public:
59   
60   virtual ~TargetLoweringObjectFile();
61   
62   /// Initialize - this method must be called before any actual lowering is
63   /// done.  This specifies the current context for codegen, and gives the
64   /// lowering implementations a chance to set up their default sections.
65   virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
66     Ctx = &ctx;
67   }
68   
69   
70   const MCSection *getTextSection() const { return TextSection; }
71   const MCSection *getDataSection() const { return DataSection; }
72   
73   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
74   /// decide not to emit the UsedDirective for some symbols in llvm.used.
75   /// FIXME: REMOVE this (rdar://7071300)
76   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
77                                           Mangler *) const {
78     return GV != 0;
79   }
80   
81   /// getSectionForConstant - Given a constant with the SectionKind, return a
82   /// section that it should be placed in.
83   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
84   
85   /// getKindForNamedSection - If this target wants to be able to override
86   /// section flags based on the name of the section specified for a global
87   /// variable, it can implement this.  This is used on ELF systems so that
88   /// ".tbss" gets the TLS bit set etc.
89   virtual SectionKind getKindForNamedSection(const char *Section,
90                                              SectionKind K) const {
91     return K;
92   }
93   
94   /// SectionForGlobal - This method computes the appropriate section to emit
95   /// the specified global variable or function definition.  This should not
96   /// be passed external (or available externally) globals.
97   const MCSection *SectionForGlobal(const GlobalValue *GV,
98                                     Mangler *Mang,
99                                     const TargetMachine &TM) const;
100   
101   /// getSpecialCasedSectionGlobals - Allow the target to completely override
102   /// section assignment of a global.
103   /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
104   /// getFlagsForNamedSection.
105   virtual const MCSection *
106   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
107                                 SectionKind Kind) const {
108     return 0;
109   }
110   
111   /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
112   /// into a string that can be printed to the assembly file after the
113   /// ".section foo" part of a section directive.
114   virtual void getSectionFlagsAsString(SectionKind Kind,
115                                        SmallVectorImpl<char> &Str) const {
116   }
117   
118 protected:
119   virtual const MCSection *
120   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
121                          Mangler *Mang, const TargetMachine &TM) const;
122 };
123   
124   
125   
126
127 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
128   bool AtIsCommentChar;  // True if @ is the comment character on this target.
129   bool HasCrazyBSS;
130 protected:
131   /// TLSDataSection - Section directive for Thread Local data.
132   ///
133   const MCSection *TLSDataSection;        // Defaults to ".tdata".
134   
135   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
136   /// Null if this target doesn't support a BSS section.
137   ///
138   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
139   
140   const MCSection *CStringSection;
141   
142   const MCSection *DataRelSection;
143   const MCSection *DataRelLocalSection;
144   const MCSection *DataRelROSection;
145   const MCSection *DataRelROLocalSection;
146   
147   const MCSection *MergeableConst4Section;
148   const MCSection *MergeableConst8Section;
149   const MCSection *MergeableConst16Section;
150 public:
151   /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
152   /// is "@".
153   TargetLoweringObjectFileELF(bool atIsCommentChar = false,
154                               // FIXME: REMOVE AFTER UNIQUING IS FIXED.
155                               bool hasCrazyBSS = false)
156     : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
157     
158   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
159   
160   
161   /// getSectionForConstant - Given a constant with the SectionKind, return a
162   /// section that it should be placed in.
163   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
164   
165   virtual SectionKind getKindForNamedSection(const char *Section,
166                                              SectionKind K) const;
167   void getSectionFlagsAsString(SectionKind Kind,
168                                SmallVectorImpl<char> &Str) const;
169   
170   virtual const MCSection *
171   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
172                          Mangler *Mang, const TargetMachine &TM) const;
173 };
174
175   
176   
177 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
178   const MCSection *CStringSection;
179   const MCSection *TextCoalSection;
180   const MCSection *ConstTextCoalSection;
181   const MCSection *ConstDataCoalSection;
182   const MCSection *ConstDataSection;
183   const MCSection *DataCoalSection;
184   const MCSection *FourByteConstantSection;
185   const MCSection *EightByteConstantSection;
186   const MCSection *SixteenByteConstantSection;
187 public:
188   
189   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
190
191   virtual const MCSection *
192   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
193                          Mangler *Mang, const TargetMachine &TM) const;
194   
195   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
196   
197   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
198   /// decide not to emit the UsedDirective for some symbols in llvm.used.
199   /// FIXME: REMOVE this (rdar://7071300)
200   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
201                                           Mangler *) const;
202 };
203
204
205
206 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
207 public:
208   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
209   
210   virtual void getSectionFlagsAsString(SectionKind Kind,
211                                        SmallVectorImpl<char> &Str) 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