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;
55 const MCSection *getOrCreateSection(const char *Name,
60 virtual ~TargetLoweringObjectFile();
62 /// Initialize - this method must be called before any actual lowering is
63 /// done. This specifies the current context for codegen, and gives the
64 /// lowering implementations a chance to set up their default sections.
65 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
70 const MCSection *getTextSection() const { return TextSection; }
71 const MCSection *getDataSection() const { return DataSection; }
73 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
74 /// decide not to emit the UsedDirective for some symbols in llvm.used.
75 /// FIXME: REMOVE this (rdar://7071300)
76 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
81 /// getSectionForConstant - Given a constant with the SectionKind, return a
82 /// section that it should be placed in.
83 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
85 /// getKindForNamedSection - If this target wants to be able to override
86 /// section flags based on the name of the section specified for a global
87 /// variable, it can implement this. This is used on ELF systems so that
88 /// ".tbss" gets the TLS bit set etc.
89 virtual SectionKind getKindForNamedSection(const char *Section,
90 SectionKind K) const {
94 /// SectionForGlobal - This method computes the appropriate section to emit
95 /// the specified global variable or function definition. This should not
96 /// be passed external (or available externally) globals.
97 const MCSection *SectionForGlobal(const GlobalValue *GV,
99 const TargetMachine &TM) const;
101 /// getSpecialCasedSectionGlobals - Allow the target to completely override
102 /// section assignment of a global.
103 /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
104 /// getFlagsForNamedSection.
105 virtual const MCSection *
106 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
107 SectionKind Kind) const {
111 /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
112 /// into a string that can be printed to the assembly file after the
113 /// ".section foo" part of a section directive.
114 virtual void getSectionFlagsAsString(SectionKind Kind,
115 SmallVectorImpl<char> &Str) const {
119 virtual const MCSection *
120 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
121 Mangler *Mang, const TargetMachine &TM) const;
127 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
128 bool AtIsCommentChar; // True if @ is the comment character on this target.
131 /// TLSDataSection - Section directive for Thread Local data.
133 const MCSection *TLSDataSection; // Defaults to ".tdata".
135 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
136 /// Null if this target doesn't support a BSS section.
138 const MCSection *TLSBSSSection; // Defaults to ".tbss".
140 const MCSection *CStringSection;
142 const MCSection *DataRelSection;
143 const MCSection *DataRelLocalSection;
144 const MCSection *DataRelROSection;
145 const MCSection *DataRelROLocalSection;
147 const MCSection *MergeableConst4Section;
148 const MCSection *MergeableConst8Section;
149 const MCSection *MergeableConst16Section;
151 /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
153 TargetLoweringObjectFileELF(bool atIsCommentChar = false,
154 // FIXME: REMOVE AFTER UNIQUING IS FIXED.
155 bool hasCrazyBSS = false)
156 : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
158 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
161 /// getSectionForConstant - Given a constant with the SectionKind, return a
162 /// section that it should be placed in.
163 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
165 virtual SectionKind getKindForNamedSection(const char *Section,
166 SectionKind K) const;
167 void getSectionFlagsAsString(SectionKind Kind,
168 SmallVectorImpl<char> &Str) const;
170 virtual const MCSection *
171 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
172 Mangler *Mang, const TargetMachine &TM) const;
177 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
178 const MCSection *CStringSection;
179 const MCSection *TextCoalSection;
180 const MCSection *ConstTextCoalSection;
181 const MCSection *ConstDataCoalSection;
182 const MCSection *ConstDataSection;
183 const MCSection *DataCoalSection;
184 const MCSection *FourByteConstantSection;
185 const MCSection *EightByteConstantSection;
186 const MCSection *SixteenByteConstantSection;
189 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
191 virtual const MCSection *
192 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
193 Mangler *Mang, const TargetMachine &TM) const;
195 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
197 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
198 /// decide not to emit the UsedDirective for some symbols in llvm.used.
199 /// FIXME: REMOVE this (rdar://7071300)
200 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
206 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
208 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
210 virtual void getSectionFlagsAsString(SectionKind Kind,
211 SmallVectorImpl<char> &Str) const;
213 virtual const MCSection *
214 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
215 Mangler *Mang, const TargetMachine &TM) const;
218 } // end namespace llvm