TargetLoweringObjectFile.h revision d5bbb07ec806e6fa1e804afd7073987fdacc83e4
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/SmallVector.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/MC/SectionKind.h"
21
22namespace llvm {
23  class MCSection;
24  class MCContext;
25  class GlobalValue;
26  class Mangler;
27  class TargetMachine;
28
29
30class TargetLoweringObjectFile {
31  MCContext *Ctx;
32protected:
33
34  TargetLoweringObjectFile();
35
36  /// TextSection - Section directive for standard text.
37  ///
38  const MCSection *TextSection;
39
40  /// DataSection - Section directive for standard data.
41  ///
42  const MCSection *DataSection;
43
44  /// BSSSection - Section that is default initialized to zero.
45  const MCSection *BSSSection;
46
47  /// ReadOnlySection - Section that is readonly and can contain arbitrary
48  /// initialized data.  Targets are not required to have a readonly section.
49  /// If they don't, various bits of code will fall back to using the data
50  /// section for constants.
51  const MCSection *ReadOnlySection;
52
53  /// StaticCtorSection - This section contains the static constructor pointer
54  /// list.
55  const MCSection *StaticCtorSection;
56
57  /// StaticDtorSection - This section contains the static destructor pointer
58  /// list.
59  const MCSection *StaticDtorSection;
60
61  /// LSDASection - If exception handling is supported by the target, this is
62  /// the section the Language Specific Data Area information is emitted to.
63  const MCSection *LSDASection;
64
65public:
66  // FIXME: NONPUB.
67  const MCSection *getOrCreateSection(const char *Name,
68                                      bool isDirective,
69                                      SectionKind K) const;
70public:
71
72  virtual ~TargetLoweringObjectFile();
73
74  /// Initialize - this method must be called before any actual lowering is
75  /// done.  This specifies the current context for codegen, and gives the
76  /// lowering implementations a chance to set up their default sections.
77  virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
78    Ctx = &ctx;
79  }
80
81
82  const MCSection *getTextSection() const { return TextSection; }
83  const MCSection *getDataSection() const { return DataSection; }
84  const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
85  const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
86  const MCSection *getLSDASection() const { return LSDASection; }
87
88  /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
89  /// decide not to emit the UsedDirective for some symbols in llvm.used.
90  /// FIXME: REMOVE this (rdar://7071300)
91  virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
92                                          Mangler *) const {
93    return GV != 0;
94  }
95
96  /// getSectionForConstant - Given a constant with the SectionKind, return a
97  /// section that it should be placed in.
98  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
99
100  /// getKindForNamedSection - If this target wants to be able to override
101  /// section flags based on the name of the section specified for a global
102  /// variable, it can implement this.  This is used on ELF systems so that
103  /// ".tbss" gets the TLS bit set etc.
104  virtual SectionKind getKindForNamedSection(const char *Section,
105                                             SectionKind K) const {
106    return K;
107  }
108
109  /// SectionForGlobal - This method computes the appropriate section to emit
110  /// the specified global variable or function definition.  This should not
111  /// be passed external (or available externally) globals.
112  const MCSection *SectionForGlobal(const GlobalValue *GV,
113                                    Mangler *Mang,
114                                    const TargetMachine &TM) const;
115
116  /// getSpecialCasedSectionGlobals - Allow the target to completely override
117  /// section assignment of a global.
118  /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
119  /// getFlagsForNamedSection.
120  virtual const MCSection *
121  getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
122                                SectionKind Kind) const {
123    return 0;
124  }
125
126  /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
127  /// into a string that can be printed to the assembly file after the
128  /// ".section foo" part of a section directive.
129  virtual void getSectionFlagsAsString(SectionKind Kind,
130                                       SmallVectorImpl<char> &Str) const {
131  }
132
133protected:
134  virtual const MCSection *
135  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
136                         Mangler *Mang, const TargetMachine &TM) const;
137};
138
139
140
141
142class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
143  bool AtIsCommentChar;  // True if @ is the comment character on this target.
144  bool HasCrazyBSS;
145protected:
146  /// TLSDataSection - Section directive for Thread Local data.
147  ///
148  const MCSection *TLSDataSection;        // Defaults to ".tdata".
149
150  /// TLSBSSSection - Section directive for Thread Local uninitialized data.
151  /// Null if this target doesn't support a BSS section.
152  ///
153  const MCSection *TLSBSSSection;         // Defaults to ".tbss".
154
155  const MCSection *CStringSection;
156
157  const MCSection *DataRelSection;
158  const MCSection *DataRelLocalSection;
159  const MCSection *DataRelROSection;
160  const MCSection *DataRelROLocalSection;
161
162  const MCSection *MergeableConst4Section;
163  const MCSection *MergeableConst8Section;
164  const MCSection *MergeableConst16Section;
165public:
166  /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
167  /// is "@".
168  TargetLoweringObjectFileELF(bool atIsCommentChar = false,
169                              // FIXME: REMOVE AFTER UNIQUING IS FIXED.
170                              bool hasCrazyBSS = false)
171    : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
172
173  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
174
175
176  /// getSectionForConstant - Given a constant with the SectionKind, return a
177  /// section that it should be placed in.
178  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
179
180  virtual SectionKind getKindForNamedSection(const char *Section,
181                                             SectionKind K) const;
182  void getSectionFlagsAsString(SectionKind Kind,
183                               SmallVectorImpl<char> &Str) const;
184
185  virtual const MCSection *
186  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
187                         Mangler *Mang, const TargetMachine &TM) const;
188};
189
190
191
192class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
193  const MCSection *CStringSection;
194  const MCSection *TextCoalSection;
195  const MCSection *ConstTextCoalSection;
196  const MCSection *ConstDataCoalSection;
197  const MCSection *ConstDataSection;
198  const MCSection *DataCoalSection;
199  const MCSection *FourByteConstantSection;
200  const MCSection *EightByteConstantSection;
201  const MCSection *SixteenByteConstantSection;
202public:
203
204  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
205
206  virtual const MCSection *
207  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
208                         Mangler *Mang, const TargetMachine &TM) const;
209
210  virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
211
212  /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
213  /// decide not to emit the UsedDirective for some symbols in llvm.used.
214  /// FIXME: REMOVE this (rdar://7071300)
215  virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
216                                          Mangler *) const;
217};
218
219
220
221class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
222public:
223  virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
224
225  virtual void getSectionFlagsAsString(SectionKind Kind,
226                                       SmallVectorImpl<char> &Str) const;
227
228  virtual const MCSection *
229  SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
230                         Mangler *Mang, const TargetMachine &TM) const;
231};
232
233} // end namespace llvm
234
235#endif
236