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