90905f51e3779bc20b093ee253f80df769c4a0b5
[oota-llvm.git] / include / llvm / CodeGen / TargetLoweringObjectFileImpl.h
1 //==-- llvm/CodeGen/TargetLoweringObjectFileImpl.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_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
17
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
20 #include "llvm/Target/TargetLoweringObjectFile.h"
21
22 namespace llvm {
23   class MachineModuleInfo;
24   class Mangler;
25   class MCAsmInfo;
26   class MCExpr;
27   class MCSection;
28   class MCSectionMachO;
29   class MCSymbol;
30   class MCContext;
31   class GlobalValue;
32   class TargetMachine;
33
34
35 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
36 protected:
37   /// TLSDataSection - Section directive for Thread Local data.
38   ///
39   const MCSection *TLSDataSection;        // Defaults to ".tdata".
40
41   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
42   /// Null if this target doesn't support a BSS section.
43   ///
44   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
45
46   const MCSection *DataRelSection;
47   const MCSection *DataRelLocalSection;
48   const MCSection *DataRelROSection;
49   const MCSection *DataRelROLocalSection;
50
51   const MCSection *MergeableConst4Section;
52   const MCSection *MergeableConst8Section;
53   const MCSection *MergeableConst16Section;
54 public:
55   TargetLoweringObjectFileELF() {}
56   ~TargetLoweringObjectFileELF() {}
57
58   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
59
60   const MCSection *getDataRelSection() const { return DataRelSection; }
61
62   /// getSectionForConstant - Given a constant with the SectionKind, return a
63   /// section that it should be placed in.
64   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
65
66
67   virtual const MCSection *
68   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
69                            Mangler *Mang, const TargetMachine &TM) const;
70
71   virtual const MCSection *
72   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
73                          Mangler *Mang, const TargetMachine &TM) const;
74
75   /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
76   /// to the specified global variable from exception handling information.
77   ///
78   virtual const MCExpr *
79   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
80                                  MachineModuleInfo *MMI, unsigned Encoding,
81                                  MCStreamer &Streamer) const;
82 };
83
84
85
86 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
87   const MCSection *CStringSection;
88   const MCSection *UStringSection;
89   const MCSection *TextCoalSection;
90   const MCSection *ConstTextCoalSection;
91   const MCSection *ConstDataCoalSection;
92   const MCSection *ConstDataSection;
93   const MCSection *DataCoalSection;
94   const MCSection *DataCommonSection;
95   const MCSection *DataBSSSection;
96   const MCSection *FourByteConstantSection;
97   const MCSection *EightByteConstantSection;
98   const MCSection *SixteenByteConstantSection;
99
100   const MCSection *LazySymbolPointerSection;
101   const MCSection *NonLazySymbolPointerSection;
102 public:
103   TargetLoweringObjectFileMachO() {}
104   ~TargetLoweringObjectFileMachO() {}
105
106   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
107
108   virtual const MCSection *
109   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
110                          Mangler *Mang, const TargetMachine &TM) const;
111
112   virtual const MCSection *
113   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
114                            Mangler *Mang, const TargetMachine &TM) const;
115
116   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
117
118   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
119   /// decide not to emit the UsedDirective for some symbols in llvm.used.
120   /// FIXME: REMOVE this (rdar://7071300)
121   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
122                                           Mangler *) const;
123
124   /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
125   /// text symbols into.
126   const MCSection *getTextCoalSection() const {
127     return TextCoalSection;
128   }
129
130   /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
131   /// we put weak read-only symbols into.
132   const MCSection *getConstTextCoalSection() const {
133     return ConstTextCoalSection;
134   }
135
136   /// getLazySymbolPointerSection - Return the section corresponding to
137   /// the .lazy_symbol_pointer directive.
138   const MCSection *getLazySymbolPointerSection() const {
139     return LazySymbolPointerSection;
140   }
141
142   /// getNonLazySymbolPointerSection - Return the section corresponding to
143   /// the .non_lazy_symbol_pointer directive.
144   const MCSection *getNonLazySymbolPointerSection() const {
145     return NonLazySymbolPointerSection;
146   }
147
148   /// getExprForDwarfGlobalReference - The mach-o version of this method
149   /// defaults to returning a stub reference.
150   virtual const MCExpr *
151   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
152                                  MachineModuleInfo *MMI, unsigned Encoding,
153                                  MCStreamer &Streamer) const;
154
155   virtual unsigned getPersonalityEncoding() const;
156   virtual unsigned getLSDAEncoding() const;
157   virtual unsigned getFDEEncoding() const;
158   virtual unsigned getTTypeEncoding() const;
159 };
160
161
162
163 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
164   mutable void *UniquingMap;
165 public:
166   TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
167   ~TargetLoweringObjectFileCOFF();
168
169   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
170
171   virtual const MCSection *
172   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
173                            Mangler *Mang, const TargetMachine &TM) const;
174
175   virtual const MCSection *
176   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
177                          Mangler *Mang, const TargetMachine &TM) const;
178
179   /// getCOFFSection - Return the MCSection for the specified COFF section.
180   /// FIXME: Switch this to a semantic view eventually.
181   const MCSection *getCOFFSection(StringRef Name, bool isDirective,
182                                   SectionKind K) const;
183 };
184
185 } // end namespace llvm
186
187 #endif