Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 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 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/ADT/StringMap.h" |
Chris Lattner | fb299e4 | 2009-08-01 21:30:49 +0000 | [diff] [blame] | 20 | #include "llvm/MC/SectionKind.h" |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 23 | class MCSection; |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 24 | class MCContext; |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 25 | class GlobalValue; |
| 26 | class Mangler; |
| 27 | class TargetMachine; |
| 28 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 29 | class TargetLoweringObjectFile { |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 30 | MCContext *Ctx; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 31 | protected: |
| 32 | |
| 33 | TargetLoweringObjectFile(); |
| 34 | |
| 35 | /// TextSection - Section directive for standard text. |
| 36 | /// |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 37 | const MCSection *TextSection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 38 | |
| 39 | /// DataSection - Section directive for standard data. |
| 40 | /// |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 41 | const MCSection *DataSection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 42 | |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 43 | /// BSSSection - Section that is default initialized to zero. |
| 44 | const MCSection *BSSSection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 45 | |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 46 | /// ReadOnlySection - Section that is readonly and can contain arbitrary |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 47 | /// initialized data. Targets are not required to have a readonly section. |
| 48 | /// If they don't, various bits of code will fall back to using the data |
| 49 | /// section for constants. |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 50 | const MCSection *ReadOnlySection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 51 | |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 52 | /// StaticCtorSection - This section contains the static constructor pointer |
| 53 | /// list. |
| 54 | const MCSection *StaticCtorSection; |
| 55 | |
| 56 | /// StaticDtorSection - This section contains the static destructor pointer |
| 57 | /// list. |
| 58 | const MCSection *StaticDtorSection; |
| 59 | |
Chris Lattner | 3d77805 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 60 | /// LSDASection - If exception handling is supported by the target, this is |
| 61 | /// the section the Language Specific Data Area information is emitted to. |
| 62 | const MCSection *LSDASection; |
| 63 | |
Chris Lattner | c01e333 | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 64 | /// EHFrameSection - If exception handling is supported by the target, this is |
| 65 | /// the section the EH Frame is emitted to. |
| 66 | const MCSection *EHFrameSection; |
| 67 | |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 68 | // Dwarf sections for debug info. If a target supports debug info, these must |
| 69 | // be set. |
| 70 | const MCSection *DwarfAbbrevSection; |
| 71 | const MCSection *DwarfInfoSection; |
| 72 | const MCSection *DwarfLineSection; |
| 73 | const MCSection *DwarfFrameSection; |
| 74 | const MCSection *DwarfPubNamesSection; |
| 75 | const MCSection *DwarfPubTypesSection; |
| 76 | const MCSection *DwarfDebugInlineSection; |
| 77 | const MCSection *DwarfStrSection; |
| 78 | const MCSection *DwarfLocSection; |
| 79 | const MCSection *DwarfARangesSection; |
| 80 | const MCSection *DwarfRangesSection; |
| 81 | const MCSection *DwarfMacroInfoSection; |
Chris Lattner | c01e333 | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 82 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 83 | public: |
| 84 | // FIXME: NONPUB. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 85 | const MCSection *getOrCreateSection(const char *Name, |
| 86 | bool isDirective, |
Chris Lattner | 9de4876 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 87 | SectionKind K) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 88 | public: |
| 89 | |
| 90 | virtual ~TargetLoweringObjectFile(); |
| 91 | |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 92 | /// Initialize - this method must be called before any actual lowering is |
| 93 | /// done. This specifies the current context for codegen, and gives the |
| 94 | /// lowering implementations a chance to set up their default sections. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 95 | virtual void Initialize(MCContext &ctx, const TargetMachine &TM) { |
| 96 | Ctx = &ctx; |
| 97 | } |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 98 | |
| 99 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 100 | const MCSection *getTextSection() const { return TextSection; } |
| 101 | const MCSection *getDataSection() const { return DataSection; } |
Chris Lattner | b5c952a | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 102 | const MCSection *getStaticCtorSection() const { return StaticCtorSection; } |
| 103 | const MCSection *getStaticDtorSection() const { return StaticDtorSection; } |
Chris Lattner | 3d77805 | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 104 | const MCSection *getLSDASection() const { return LSDASection; } |
Chris Lattner | c01e333 | 2009-08-02 06:52:36 +0000 | [diff] [blame] | 105 | const MCSection *getEHFrameSection() const { return EHFrameSection; } |
Chris Lattner | 72d228d | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 106 | const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } |
| 107 | const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } |
| 108 | const MCSection *getDwarfLineSection() const { return DwarfLineSection; } |
| 109 | const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } |
| 110 | const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;} |
| 111 | const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;} |
| 112 | const MCSection *getDwarfDebugInlineSection() const { |
| 113 | return DwarfDebugInlineSection; |
| 114 | } |
| 115 | const MCSection *getDwarfStrSection() const { return DwarfStrSection; } |
| 116 | const MCSection *getDwarfLocSection() const { return DwarfLocSection; } |
| 117 | const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;} |
| 118 | const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } |
| 119 | const MCSection *getDwarfMacroInfoSection() const { |
| 120 | return DwarfMacroInfoSection; |
| 121 | } |
| 122 | |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 123 | /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively |
| 124 | /// decide not to emit the UsedDirective for some symbols in llvm.used. |
| 125 | /// FIXME: REMOVE this (rdar://7071300) |
| 126 | virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, |
| 127 | Mangler *) const { |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 128 | return GV != 0; |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 129 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 130 | |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 131 | /// getSectionForConstant - Given a constant with the SectionKind, return a |
| 132 | /// section that it should be placed in. |
| 133 | virtual const MCSection *getSectionForConstant(SectionKind Kind) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 134 | |
| 135 | /// getKindForNamedSection - If this target wants to be able to override |
| 136 | /// section flags based on the name of the section specified for a global |
| 137 | /// variable, it can implement this. This is used on ELF systems so that |
| 138 | /// ".tbss" gets the TLS bit set etc. |
Chris Lattner | 9de4876 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 139 | virtual SectionKind getKindForNamedSection(const char *Section, |
| 140 | SectionKind K) const { |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 141 | return K; |
| 142 | } |
| 143 | |
| 144 | /// SectionForGlobal - This method computes the appropriate section to emit |
| 145 | /// the specified global variable or function definition. This should not |
| 146 | /// be passed external (or available externally) globals. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 147 | const MCSection *SectionForGlobal(const GlobalValue *GV, |
| 148 | Mangler *Mang, |
| 149 | const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 150 | |
| 151 | /// getSpecialCasedSectionGlobals - Allow the target to completely override |
| 152 | /// section assignment of a global. |
| 153 | /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with |
| 154 | /// getFlagsForNamedSection. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 155 | virtual const MCSection * |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 156 | getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang, |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 157 | SectionKind Kind) const { |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /// getSectionFlagsAsString - Turn the flags in the specified SectionKind |
| 162 | /// into a string that can be printed to the assembly file after the |
| 163 | /// ".section foo" part of a section directive. |
| 164 | virtual void getSectionFlagsAsString(SectionKind Kind, |
| 165 | SmallVectorImpl<char> &Str) const { |
| 166 | } |
| 167 | |
| 168 | protected: |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 169 | virtual const MCSection * |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 170 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 171 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { |
| 178 | bool AtIsCommentChar; // True if @ is the comment character on this target. |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 179 | bool HasCrazyBSS; |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 180 | protected: |
| 181 | /// TLSDataSection - Section directive for Thread Local data. |
| 182 | /// |
| 183 | const MCSection *TLSDataSection; // Defaults to ".tdata". |
| 184 | |
| 185 | /// TLSBSSSection - Section directive for Thread Local uninitialized data. |
| 186 | /// Null if this target doesn't support a BSS section. |
| 187 | /// |
| 188 | const MCSection *TLSBSSSection; // Defaults to ".tbss". |
| 189 | |
| 190 | const MCSection *CStringSection; |
| 191 | |
| 192 | const MCSection *DataRelSection; |
| 193 | const MCSection *DataRelLocalSection; |
| 194 | const MCSection *DataRelROSection; |
| 195 | const MCSection *DataRelROLocalSection; |
| 196 | |
| 197 | const MCSection *MergeableConst4Section; |
| 198 | const MCSection *MergeableConst8Section; |
| 199 | const MCSection *MergeableConst16Section; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 200 | public: |
| 201 | /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI |
| 202 | /// is "@". |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 203 | TargetLoweringObjectFileELF(bool atIsCommentChar = false, |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 204 | // FIXME: REMOVE AFTER UNIQUING IS FIXED. |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 205 | bool hasCrazyBSS = false) |
| 206 | : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {} |
| 207 | |
| 208 | virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 209 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 210 | |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 211 | /// getSectionForConstant - Given a constant with the SectionKind, return a |
| 212 | /// section that it should be placed in. |
| 213 | virtual const MCSection *getSectionForConstant(SectionKind Kind) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 214 | |
Chris Lattner | 9de4876 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 215 | virtual SectionKind getKindForNamedSection(const char *Section, |
| 216 | SectionKind K) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 217 | void getSectionFlagsAsString(SectionKind Kind, |
| 218 | SmallVectorImpl<char> &Str) const; |
| 219 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 220 | virtual const MCSection * |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 221 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 222 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 223 | }; |
| 224 | |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 225 | |
| 226 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 227 | class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { |
Chris Lattner | a3954e6 | 2009-08-01 21:56:13 +0000 | [diff] [blame] | 228 | const MCSection *CStringSection; |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 229 | const MCSection *TextCoalSection; |
| 230 | const MCSection *ConstTextCoalSection; |
| 231 | const MCSection *ConstDataCoalSection; |
| 232 | const MCSection *ConstDataSection; |
| 233 | const MCSection *DataCoalSection; |
| 234 | const MCSection *FourByteConstantSection; |
| 235 | const MCSection *EightByteConstantSection; |
| 236 | const MCSection *SixteenByteConstantSection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 237 | public: |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 238 | |
| 239 | virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 240 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 241 | virtual const MCSection * |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 242 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 243 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 244 | |
Chris Lattner | d7f8c0a | 2009-08-01 23:46:12 +0000 | [diff] [blame] | 245 | virtual const MCSection *getSectionForConstant(SectionKind Kind) const; |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 246 | |
| 247 | /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively |
| 248 | /// decide not to emit the UsedDirective for some symbols in llvm.used. |
| 249 | /// FIXME: REMOVE this (rdar://7071300) |
| 250 | virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, |
| 251 | Mangler *) const; |
Chris Lattner | 9287346 | 2009-08-03 21:53:27 +0000 | [diff] [blame] | 252 | |
| 253 | /// getMachOSection - Return the MCSection for the specified mach-o section. |
| 254 | /// FIXME: Switch this to a semantic view eventually. |
| 255 | const MCSection *getMachOSection(const char *Name, bool isDirective, |
| 256 | SectionKind K); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | |
| 260 | |
| 261 | class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { |
| 262 | public: |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 263 | virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 264 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 265 | virtual void getSectionFlagsAsString(SectionKind Kind, |
| 266 | SmallVectorImpl<char> &Str) const; |
| 267 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 268 | virtual const MCSection * |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame] | 269 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 270 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | 9287346 | 2009-08-03 21:53:27 +0000 | [diff] [blame] | 271 | |
| 272 | /// getCOFFSection - Return the MCSection for the specified COFF section. |
| 273 | /// FIXME: Switch this to a semantic view eventually. |
| 274 | const MCSection *getCOFFSection(const char *Name, bool isDirective, |
| 275 | SectionKind K); |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 276 | }; |
| 277 | |
| 278 | } // end namespace llvm |
| 279 | |
| 280 | #endif |