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