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