Big change #1 for personality function references:
[llvm/avr.git] / include / llvm / Target / TargetLoweringObjectFile.h
blob6480bf46a5783c6336fabdc3cfd363280ebf2031
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
18 #include "llvm/MC/SectionKind.h"
20 namespace llvm {
21 class Mangler;
22 class MCSection;
23 class MCSectionMachO;
24 class MCContext;
25 class GlobalValue;
26 class StringRef;
27 class TargetMachine;
28 class MCAsmInfo;
29 class MCExpr;
31 class TargetLoweringObjectFile {
32 MCContext *Ctx;
34 TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
35 void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
36 protected:
38 TargetLoweringObjectFile();
40 /// TextSection - Section directive for standard text.
41 ///
42 const MCSection *TextSection;
44 /// DataSection - Section directive for standard data.
45 ///
46 const MCSection *DataSection;
48 /// BSSSection - Section that is default initialized to zero.
49 const MCSection *BSSSection;
51 /// ReadOnlySection - Section that is readonly and can contain arbitrary
52 /// initialized data. Targets are not required to have a readonly section.
53 /// If they don't, various bits of code will fall back to using the data
54 /// section for constants.
55 const MCSection *ReadOnlySection;
57 /// StaticCtorSection - This section contains the static constructor pointer
58 /// list.
59 const MCSection *StaticCtorSection;
61 /// StaticDtorSection - This section contains the static destructor pointer
62 /// list.
63 const MCSection *StaticDtorSection;
65 /// LSDASection - If exception handling is supported by the target, this is
66 /// the section the Language Specific Data Area information is emitted to.
67 const MCSection *LSDASection;
69 /// EHFrameSection - If exception handling is supported by the target, this is
70 /// the section the EH Frame is emitted to.
71 const MCSection *EHFrameSection;
73 // Dwarf sections for debug info. If a target supports debug info, these must
74 // be set.
75 const MCSection *DwarfAbbrevSection;
76 const MCSection *DwarfInfoSection;
77 const MCSection *DwarfLineSection;
78 const MCSection *DwarfFrameSection;
79 const MCSection *DwarfPubNamesSection;
80 const MCSection *DwarfPubTypesSection;
81 const MCSection *DwarfDebugInlineSection;
82 const MCSection *DwarfStrSection;
83 const MCSection *DwarfLocSection;
84 const MCSection *DwarfARangesSection;
85 const MCSection *DwarfRangesSection;
86 const MCSection *DwarfMacroInfoSection;
88 public:
90 MCContext &getContext() const { return *Ctx; }
93 virtual ~TargetLoweringObjectFile();
95 /// Initialize - this method must be called before any actual lowering is
96 /// done. This specifies the current context for codegen, and gives the
97 /// lowering implementations a chance to set up their default sections.
98 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
99 Ctx = &ctx;
103 const MCSection *getTextSection() const { return TextSection; }
104 const MCSection *getDataSection() const { return DataSection; }
105 const MCSection *getBSSSection() const { return BSSSection; }
106 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
107 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
108 const MCSection *getLSDASection() const { return LSDASection; }
109 const MCSection *getEHFrameSection() const { return EHFrameSection; }
110 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
111 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
112 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
113 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
114 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
115 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
116 const MCSection *getDwarfDebugInlineSection() const {
117 return DwarfDebugInlineSection;
119 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
120 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
121 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
122 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
123 const MCSection *getDwarfMacroInfoSection() const {
124 return DwarfMacroInfoSection;
127 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
128 /// decide not to emit the UsedDirective for some symbols in llvm.used.
129 /// FIXME: REMOVE this (rdar://7071300)
130 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
131 Mangler *) const {
132 return GV != 0;
135 /// getSectionForConstant - Given a constant with the SectionKind, return a
136 /// section that it should be placed in.
137 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
139 /// getKindForGlobal - Classify the specified global variable into a set of
140 /// target independent categories embodied in SectionKind.
141 static SectionKind getKindForGlobal(const GlobalValue *GV,
142 const TargetMachine &TM);
144 /// SectionForGlobal - This method computes the appropriate section to emit
145 /// the specified global variable or function definition. This should not
146 /// be passed external (or available externally) globals.
147 const MCSection *SectionForGlobal(const GlobalValue *GV,
148 SectionKind Kind, Mangler *Mang,
149 const TargetMachine &TM) const;
151 /// SectionForGlobal - This method computes the appropriate section to emit
152 /// the specified global variable or function definition. This should not
153 /// be passed external (or available externally) globals.
154 const MCSection *SectionForGlobal(const GlobalValue *GV,
155 Mangler *Mang,
156 const TargetMachine &TM) const {
157 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
162 /// getExplicitSectionGlobal - Targets should implement this method to assign
163 /// a section to globals with an explicit section specfied. The
164 /// implementation of this method can assume that GV->hasSection() is true.
165 virtual const MCSection *
166 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
167 Mangler *Mang, const TargetMachine &TM) const = 0;
169 /// getSpecialCasedSectionGlobals - Allow the target to completely override
170 /// section assignment of a global.
171 virtual const MCSection *
172 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
173 SectionKind Kind) const {
174 return 0;
177 /// getSymbolForDwarfGlobalReference - Return an MCExpr to use for a
178 /// pc-relative reference to the specified global variable from exception
179 /// handling information. In addition to the symbol, this returns
180 /// by-reference:
182 /// IsIndirect - True if the returned symbol is actually a stub that contains
183 /// the address of the symbol, false if the symbol is the global itself.
185 /// IsPCRel - True if the symbol reference is already pc-relative, false if
186 /// the caller needs to subtract off the address of the reference from the
187 /// symbol.
189 virtual const MCExpr *
190 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
191 bool &IsIndirect, bool &IsPCRel) const;
193 protected:
194 virtual const MCSection *
195 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
196 Mangler *Mang, const TargetMachine &TM) const;
202 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
203 mutable void *UniquingMap;
204 protected:
205 /// TLSDataSection - Section directive for Thread Local data.
207 const MCSection *TLSDataSection; // Defaults to ".tdata".
209 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
210 /// Null if this target doesn't support a BSS section.
212 const MCSection *TLSBSSSection; // Defaults to ".tbss".
214 const MCSection *DataRelSection;
215 const MCSection *DataRelLocalSection;
216 const MCSection *DataRelROSection;
217 const MCSection *DataRelROLocalSection;
219 const MCSection *MergeableConst4Section;
220 const MCSection *MergeableConst8Section;
221 const MCSection *MergeableConst16Section;
223 protected:
224 const MCSection *getELFSection(StringRef Section, unsigned Type,
225 unsigned Flags, SectionKind Kind,
226 bool IsExplicit = false) const;
227 public:
228 TargetLoweringObjectFileELF() : UniquingMap(0) {}
229 ~TargetLoweringObjectFileELF();
231 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
233 /// getSectionForConstant - Given a constant with the SectionKind, return a
234 /// section that it should be placed in.
235 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
238 virtual const MCSection *
239 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
240 Mangler *Mang, const TargetMachine &TM) const;
242 virtual const MCSection *
243 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
244 Mangler *Mang, const TargetMachine &TM) const;
249 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
250 mutable void *UniquingMap;
252 const MCSection *CStringSection;
253 const MCSection *UStringSection;
254 const MCSection *TextCoalSection;
255 const MCSection *ConstTextCoalSection;
256 const MCSection *ConstDataCoalSection;
257 const MCSection *ConstDataSection;
258 const MCSection *DataCoalSection;
259 const MCSection *FourByteConstantSection;
260 const MCSection *EightByteConstantSection;
261 const MCSection *SixteenByteConstantSection;
263 const MCSection *LazySymbolPointerSection;
264 const MCSection *NonLazySymbolPointerSection;
265 public:
266 TargetLoweringObjectFileMachO() : UniquingMap(0) {}
267 ~TargetLoweringObjectFileMachO();
269 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
271 virtual const MCSection *
272 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
273 Mangler *Mang, const TargetMachine &TM) const;
275 virtual const MCSection *
276 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
277 Mangler *Mang, const TargetMachine &TM) const;
279 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
281 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
282 /// decide not to emit the UsedDirective for some symbols in llvm.used.
283 /// FIXME: REMOVE this (rdar://7071300)
284 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
285 Mangler *) const;
287 /// getMachOSection - Return the MCSection for the specified mach-o section.
288 /// This requires the operands to be valid.
289 const MCSectionMachO *getMachOSection(const StringRef &Segment,
290 const StringRef &Section,
291 unsigned TypeAndAttributes,
292 SectionKind K) const {
293 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
295 const MCSectionMachO *getMachOSection(const StringRef &Segment,
296 const StringRef &Section,
297 unsigned TypeAndAttributes,
298 unsigned Reserved2,
299 SectionKind K) const;
301 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
302 /// symbols into.
303 const MCSection *getTextCoalSection() const {
304 return TextCoalSection;
307 /// getLazySymbolPointerSection - Return the section corresponding to
308 /// the .lazy_symbol_pointer directive.
309 const MCSection *getLazySymbolPointerSection() const {
310 return LazySymbolPointerSection;
313 /// getNonLazySymbolPointerSection - Return the section corresponding to
314 /// the .non_lazy_symbol_pointer directive.
315 const MCSection *getNonLazySymbolPointerSection() const {
316 return NonLazySymbolPointerSection;
319 /// getSymbolForDwarfGlobalReference - The mach-o version of this method
320 /// defaults to returning a stub reference.
321 virtual const MCExpr *
322 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
323 bool &IsIndirect, bool &IsPCRel) const;
328 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
329 mutable void *UniquingMap;
330 public:
331 TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
332 ~TargetLoweringObjectFileCOFF();
334 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
336 virtual const MCSection *
337 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
338 Mangler *Mang, const TargetMachine &TM) const;
340 virtual const MCSection *
341 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
342 Mangler *Mang, const TargetMachine &TM) const;
344 /// getCOFFSection - Return the MCSection for the specified COFF section.
345 /// FIXME: Switch this to a semantic view eventually.
346 const MCSection *getCOFFSection(const char *Name, bool isDirective,
347 SectionKind K) const;
350 } // end namespace llvm
352 #endif