fix a fixme by sinking various target-specific directives down into
[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.
49   const MCSection *ReadOnlySection;
50   
51 public:
52   // FIXME: NONPUB.
53   const MCSection *getOrCreateSection(const char *Name,
54                                       bool isDirective,
55                                       SectionKind K) const;
56 public:
57   
58   virtual ~TargetLoweringObjectFile();
59   
60   /// Initialize - this method must be called before any actual lowering is
61   /// done.  This specifies the current context for codegen, and gives the
62   /// lowering implementations a chance to set up their default sections.
63   virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
64     Ctx = &ctx;
65   }
66   
67   
68   const MCSection *getTextSection() const { return TextSection; }
69   const MCSection *getDataSection() const { return DataSection; }
70   
71   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
72   /// decide not to emit the UsedDirective for some symbols in llvm.used.
73   /// FIXME: REMOVE this (rdar://7071300)
74   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
75                                           Mangler *) const {
76     return GV != 0;
77   }
78   
79   /// getSectionForMergeableConstant - Given a mergeable constant with the
80   /// specified size and relocation information, return a section that it
81   /// should be placed in.
82   virtual const MCSection *
83   getSectionForMergeableConstant(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   /// getSectionForMergeableConstant - Given a mergeable constant with the
162   /// specified size and relocation information, return a section that it
163   /// should be placed in.
164   virtual const MCSection *
165   getSectionForMergeableConstant(SectionKind Kind) const;
166   
167   virtual SectionKind getKindForNamedSection(const char *Section,
168                                              SectionKind K) const;
169   void getSectionFlagsAsString(SectionKind Kind,
170                                SmallVectorImpl<char> &Str) const;
171   
172   virtual const MCSection *
173   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
174                          Mangler *Mang, const TargetMachine &TM) const;
175 };
176
177   
178   
179 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
180   const MCSection *CStringSection;
181   const MCSection *TextCoalSection;
182   const MCSection *ConstTextCoalSection;
183   const MCSection *ConstDataCoalSection;
184   const MCSection *ConstDataSection;
185   const MCSection *DataCoalSection;
186   const MCSection *FourByteConstantSection;
187   const MCSection *EightByteConstantSection;
188   const MCSection *SixteenByteConstantSection;
189 public:
190   
191   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
192
193   virtual const MCSection *
194   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
195                          Mangler *Mang, const TargetMachine &TM) const;
196   
197   virtual const MCSection *
198   getSectionForMergeableConstant(SectionKind Kind) const;
199   
200   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
201   /// decide not to emit the UsedDirective for some symbols in llvm.used.
202   /// FIXME: REMOVE this (rdar://7071300)
203   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
204                                           Mangler *) const;
205 };
206
207
208
209 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
210 public:
211   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
212   
213   virtual void getSectionFlagsAsString(SectionKind Kind,
214                                        SmallVectorImpl<char> &Str) const;
215   
216   virtual const MCSection *
217   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
218                          Mangler *Mang, const TargetMachine &TM) const;
219 };
220
221 } // end namespace llvm
222
223 #endif