Add a flag that indicates whether a target supports compact unwind info or not.
[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/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
20
21 namespace llvm {
22   class MachineModuleInfo;
23   class Mangler;
24   class MCAsmInfo;
25   class MCContext;
26   class MCExpr;
27   class MCSection;
28   class MCSectionMachO;
29   class MCSymbol;
30   class MCStreamer;
31   class GlobalValue;
32   class TargetMachine;
33   
34 class TargetLoweringObjectFile {
35   MCContext *Ctx;
36   
37   TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
38   void operator=(const TargetLoweringObjectFile&);           // DO NOT IMPLEMENT
39 protected:
40   
41   TargetLoweringObjectFile();
42   
43   /// TextSection - Section directive for standard text.
44   ///
45   const MCSection *TextSection;
46   
47   /// DataSection - Section directive for standard data.
48   ///
49   const MCSection *DataSection;
50   
51   /// BSSSection - Section that is default initialized to zero.
52   const MCSection *BSSSection;
53   
54   /// ReadOnlySection - Section that is readonly and can contain arbitrary
55   /// initialized data.  Targets are not required to have a readonly section.
56   /// If they don't, various bits of code will fall back to using the data
57   /// section for constants.
58   const MCSection *ReadOnlySection;
59   
60   /// StaticCtorSection - This section contains the static constructor pointer
61   /// list.
62   const MCSection *StaticCtorSection;
63
64   /// StaticDtorSection - This section contains the static destructor pointer
65   /// list.
66   const MCSection *StaticDtorSection;
67   
68   /// LSDASection - If exception handling is supported by the target, this is
69   /// the section the Language Specific Data Area information is emitted to.
70   const MCSection *LSDASection;
71
72   /// CompactUnwindSection - If exception handling is supported by the target
73   /// and the target can support a compact representation of the CIE and FDE,
74   /// this is the section to emit them into.
75   const MCSection *CompactUnwindSection;
76   
77   // Dwarf sections for debug info.  If a target supports debug info, these must
78   // be set.
79   const MCSection *DwarfAbbrevSection;
80   const MCSection *DwarfInfoSection;
81   const MCSection *DwarfLineSection;
82   const MCSection *DwarfFrameSection;
83   const MCSection *DwarfPubNamesSection;
84   const MCSection *DwarfPubTypesSection;
85   const MCSection *DwarfDebugInlineSection;
86   const MCSection *DwarfStrSection;
87   const MCSection *DwarfLocSection;
88   const MCSection *DwarfARangesSection;
89   const MCSection *DwarfRangesSection;
90   const MCSection *DwarfMacroInfoSection;
91   
92   // Extra TLS Variable Data section.  If the target needs to put additional
93   // information for a TLS variable, it'll go here.
94   const MCSection *TLSExtraDataSection;
95   
96   /// CommDirectiveSupportsAlignment - True if .comm supports alignment.  This
97   /// is a hack for as long as we support 10.4 Tiger, whose assembler doesn't
98   /// support alignment on comm.
99   bool CommDirectiveSupportsAlignment;
100   
101   /// SupportsWeakEmptyEHFrame - True if target object file supports a
102   /// weak_definition of constant 0 for an omitted EH frame.
103   bool SupportsWeakOmittedEHFrame;
104   
105   /// IsFunctionEHFrameSymbolPrivate - This flag is set to true if the
106   /// "EH_frame" symbol for EH information should be an assembler temporary (aka
107   /// private linkage, aka an L or .L label) or false if it should be a normal
108   /// non-.globl label.  This defaults to true.
109   bool IsFunctionEHFrameSymbolPrivate;
110
111   /// SupportsCompactUnwindInfo - This flag is set to true if the CIE and FDE
112   /// information should be emitted in a compact form.
113   bool SupportsCompactUnwindInfo;
114
115 public:
116   MCContext &getContext() const { return *Ctx; }
117   
118   virtual ~TargetLoweringObjectFile();
119   
120   /// Initialize - this method must be called before any actual lowering is
121   /// done.  This specifies the current context for codegen, and gives the
122   /// lowering implementations a chance to set up their default sections.
123   virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
124     Ctx = &ctx;
125   }
126   
127   bool isFunctionEHFrameSymbolPrivate() const {
128     return IsFunctionEHFrameSymbolPrivate;
129   }
130   bool getSupportsWeakOmittedEHFrame() const {
131     return SupportsWeakOmittedEHFrame;
132   }
133   bool getCommDirectiveSupportsAlignment() const {
134     return CommDirectiveSupportsAlignment;
135   }
136   bool getSupportsCompactUnwindInfo() const {
137     return SupportsCompactUnwindInfo;
138   }
139
140   const MCSection *getTextSection() const { return TextSection; }
141   const MCSection *getDataSection() const { return DataSection; }
142   const MCSection *getBSSSection() const { return BSSSection; }
143   const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
144   const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
145   const MCSection *getLSDASection() const { return LSDASection; }
146   const MCSection *getCompactUnwindSection() const{return CompactUnwindSection;}
147   virtual const MCSection *getEHFrameSection() const = 0;
148   virtual void emitPersonalityValue(MCStreamer &Streamer,
149                                     const TargetMachine &TM,
150                                     const MCSymbol *Sym) const;
151   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
152   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
153   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
154   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
155   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
156   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
157   const MCSection *getDwarfDebugInlineSection() const {
158     return DwarfDebugInlineSection;
159   }
160   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
161   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
162   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
163   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
164   const MCSection *getDwarfMacroInfoSection() const {
165     return DwarfMacroInfoSection;
166   }
167   const MCSection *getTLSExtraDataSection() const {
168     return TLSExtraDataSection;
169   }
170   virtual const MCSection *getWin64EHFuncTableSection(StringRef suffix)const=0;
171   virtual const MCSection *getWin64EHTableSection(StringRef suffix) const = 0;
172   
173   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
174   /// decide not to emit the UsedDirective for some symbols in llvm.used.
175   /// FIXME: REMOVE this (rdar://7071300)
176   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
177                                           Mangler *) const {
178     return GV != 0;
179   }
180   
181   /// getSectionForConstant - Given a constant with the SectionKind, return a
182   /// section that it should be placed in.
183   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
184   
185   /// getKindForGlobal - Classify the specified global variable into a set of
186   /// target independent categories embodied in SectionKind.
187   static SectionKind getKindForGlobal(const GlobalValue *GV,
188                                       const TargetMachine &TM);
189   
190   /// SectionForGlobal - This method computes the appropriate section to emit
191   /// the specified global variable or function definition.  This should not
192   /// be passed external (or available externally) globals.
193   const MCSection *SectionForGlobal(const GlobalValue *GV,
194                                     SectionKind Kind, Mangler *Mang,
195                                     const TargetMachine &TM) const;
196   
197   /// SectionForGlobal - This method computes the appropriate section to emit
198   /// the specified global variable or function definition.  This should not
199   /// be passed external (or available externally) globals.
200   const MCSection *SectionForGlobal(const GlobalValue *GV,
201                                     Mangler *Mang,
202                                     const TargetMachine &TM) const {
203     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
204   }
205   
206   
207   
208   /// getExplicitSectionGlobal - Targets should implement this method to assign
209   /// a section to globals with an explicit section specfied.  The
210   /// implementation of this method can assume that GV->hasSection() is true.
211   virtual const MCSection *
212   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
213                            Mangler *Mang, const TargetMachine &TM) const = 0;
214   
215   /// getSpecialCasedSectionGlobals - Allow the target to completely override
216   /// section assignment of a global.
217   virtual const MCSection *
218   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
219                                 SectionKind Kind) const {
220     return 0;
221   }
222   
223   /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
224   /// to the specified global variable from exception handling information.
225   ///
226   virtual const MCExpr *
227   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
228                                  MachineModuleInfo *MMI, unsigned Encoding,
229                                  MCStreamer &Streamer) const;
230
231   // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
232   virtual MCSymbol *
233   getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
234                           MachineModuleInfo *MMI) const;
235
236   /// 
237   const MCExpr *
238   getExprForDwarfReference(const MCSymbol *Sym, unsigned Encoding,
239                            MCStreamer &Streamer) const;
240   
241   virtual unsigned getPersonalityEncoding() const;
242   virtual unsigned getLSDAEncoding() const;
243   virtual unsigned getFDEEncoding(bool CFI) const;
244   virtual unsigned getTTypeEncoding() const;
245
246 protected:
247   virtual const MCSection *
248   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
249                          Mangler *Mang, const TargetMachine &TM) const;
250 };
251
252 } // end namespace llvm
253
254 #endif