a9cbe3963cdeeebe95b48408fa1d2fc46728366c
[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
55 protected:
56   const MCSection *getELFSection(StringRef Section, unsigned Type,
57                                  unsigned Flags, SectionKind Kind,
58                                  bool IsExplicit = false) const;
59 public:
60   TargetLoweringObjectFileELF() {}
61   ~TargetLoweringObjectFileELF() {}
62
63   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
64
65   const MCSection *getDataRelSection() const { return DataRelSection; }
66
67   /// getSectionForConstant - Given a constant with the SectionKind, return a
68   /// section that it should be placed in.
69   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
70
71
72   virtual const MCSection *
73   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
74                            Mangler *Mang, const TargetMachine &TM) const;
75
76   virtual const MCSection *
77   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
78                          Mangler *Mang, const TargetMachine &TM) const;
79
80   /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
81   /// to the specified global variable from exception handling information.
82   ///
83   virtual const MCExpr *
84   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
85                                  MachineModuleInfo *MMI, unsigned Encoding,
86                                  MCStreamer &Streamer) const;
87 };
88
89
90
91 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
92   const MCSection *CStringSection;
93   const MCSection *UStringSection;
94   const MCSection *TextCoalSection;
95   const MCSection *ConstTextCoalSection;
96   const MCSection *ConstDataCoalSection;
97   const MCSection *ConstDataSection;
98   const MCSection *DataCoalSection;
99   const MCSection *DataCommonSection;
100   const MCSection *DataBSSSection;
101   const MCSection *FourByteConstantSection;
102   const MCSection *EightByteConstantSection;
103   const MCSection *SixteenByteConstantSection;
104
105   const MCSection *LazySymbolPointerSection;
106   const MCSection *NonLazySymbolPointerSection;
107 public:
108   TargetLoweringObjectFileMachO() {}
109   ~TargetLoweringObjectFileMachO() {}
110
111   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
112
113   virtual const MCSection *
114   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
115                          Mangler *Mang, const TargetMachine &TM) const;
116
117   virtual const MCSection *
118   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
119                            Mangler *Mang, const TargetMachine &TM) const;
120
121   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
122
123   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
124   /// decide not to emit the UsedDirective for some symbols in llvm.used.
125   /// FIXME: REMOVE this (rdar://7071300)
126   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
127                                           Mangler *) const;
128
129   /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
130   /// text symbols into.
131   const MCSection *getTextCoalSection() const {
132     return TextCoalSection;
133   }
134
135   /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
136   /// we put weak read-only symbols into.
137   const MCSection *getConstTextCoalSection() const {
138     return ConstTextCoalSection;
139   }
140
141   /// getLazySymbolPointerSection - Return the section corresponding to
142   /// the .lazy_symbol_pointer directive.
143   const MCSection *getLazySymbolPointerSection() const {
144     return LazySymbolPointerSection;
145   }
146
147   /// getNonLazySymbolPointerSection - Return the section corresponding to
148   /// the .non_lazy_symbol_pointer directive.
149   const MCSection *getNonLazySymbolPointerSection() const {
150     return NonLazySymbolPointerSection;
151   }
152
153   /// getExprForDwarfGlobalReference - The mach-o version of this method
154   /// defaults to returning a stub reference.
155   virtual const MCExpr *
156   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
157                                  MachineModuleInfo *MMI, unsigned Encoding,
158                                  MCStreamer &Streamer) const;
159
160   virtual unsigned getPersonalityEncoding() const;
161   virtual unsigned getLSDAEncoding() const;
162   virtual unsigned getFDEEncoding() const;
163   virtual unsigned getTTypeEncoding() const;
164 };
165
166
167
168 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
169   mutable void *UniquingMap;
170 public:
171   TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
172   ~TargetLoweringObjectFileCOFF();
173
174   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
175
176   virtual const MCSection *
177   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
178                            Mangler *Mang, const TargetMachine &TM) const;
179
180   virtual const MCSection *
181   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
182                          Mangler *Mang, const TargetMachine &TM) const;
183
184   /// getCOFFSection - Return the MCSection for the specified COFF section.
185   /// FIXME: Switch this to a semantic view eventually.
186   const MCSection *getCOFFSection(StringRef Name, bool isDirective,
187                                   SectionKind K) const;
188 };
189
190 } // end namespace llvm
191
192 #endif