1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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/ADT/SmallVector.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/MC/SectionKind.h"
30 class TargetLoweringObjectFile {
34 TargetLoweringObjectFile();
36 /// TextSection - Section directive for standard text.
38 const MCSection *TextSection;
40 /// DataSection - Section directive for standard data.
42 const MCSection *DataSection;
44 /// BSSSection - Section that is default initialized to zero.
45 const MCSection *BSSSection;
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;
53 /// StaticCtorSection - This section contains the static constructor pointer
55 const MCSection *StaticCtorSection;
57 /// StaticDtorSection - This section contains the static destructor pointer
59 const MCSection *StaticDtorSection;
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;
67 const MCSection *getOrCreateSection(const char *Name,
72 virtual ~TargetLoweringObjectFile();
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) {
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; }
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,
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;
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 {
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,
114 const TargetMachine &TM) const;
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 {
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 {
134 virtual const MCSection *
135 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
136 Mangler *Mang, const TargetMachine &TM) const;
142 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
143 bool AtIsCommentChar; // True if @ is the comment character on this target.
146 /// TLSDataSection - Section directive for Thread Local data.
148 const MCSection *TLSDataSection; // Defaults to ".tdata".
150 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
151 /// Null if this target doesn't support a BSS section.
153 const MCSection *TLSBSSSection; // Defaults to ".tbss".
155 const MCSection *CStringSection;
157 const MCSection *DataRelSection;
158 const MCSection *DataRelLocalSection;
159 const MCSection *DataRelROSection;
160 const MCSection *DataRelROLocalSection;
162 const MCSection *MergeableConst4Section;
163 const MCSection *MergeableConst8Section;
164 const MCSection *MergeableConst16Section;
166 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
168 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
169 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
170 bool hasCrazyBSS = false)
171 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
173 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
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;
180 virtual SectionKind getKindForNamedSection(const char *Section,
181 SectionKind K) const;
182 void getSectionFlagsAsString(SectionKind Kind,
183 SmallVectorImpl<char> &Str) const;
185 virtual const MCSection *
186 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
187 Mangler *Mang, const TargetMachine &TM) const;
192 class 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;
204 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
206 virtual const MCSection *
207 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
208 Mangler *Mang, const TargetMachine &TM) const;
210 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
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,
221 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
223 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
225 virtual void getSectionFlagsAsString(SectionKind Kind,
226 SmallVectorImpl<char> &Str) const;
228 virtual const MCSection *
229 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
230 Mangler *Mang, const TargetMachine &TM) const;
233 } // end namespace llvm