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 | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame^] | 29 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 30 | class TargetLoweringObjectFile { |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 31 | MCContext *Ctx; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 32 | protected: |
| 33 | |
| 34 | TargetLoweringObjectFile(); |
| 35 | |
| 36 | /// TextSection - Section directive for standard text. |
| 37 | /// |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 38 | const MCSection *TextSection; // Defaults to ".text". |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 39 | |
| 40 | /// DataSection - Section directive for standard data. |
| 41 | /// |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 42 | const MCSection *DataSection; // Defaults to ".data". |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | |
| 46 | // FIXME: SINK THESE. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 47 | const MCSection *BSSSection_; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 48 | |
| 49 | /// ReadOnlySection - This is the directive that is emitted to switch to a |
| 50 | /// read-only section for constant data (e.g. data declared const, |
| 51 | /// jump tables). |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 52 | const MCSection *ReadOnlySection; // Defaults to NULL |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 53 | |
| 54 | /// TLSDataSection - Section directive for Thread Local data. |
| 55 | /// |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 56 | const MCSection *TLSDataSection; // Defaults to ".tdata". |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 57 | |
| 58 | /// TLSBSSSection - Section directive for Thread Local uninitialized data. |
| 59 | /// Null if this target doesn't support a BSS section. |
| 60 | /// |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 61 | const MCSection *TLSBSSSection; // Defaults to ".tbss". |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 62 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 63 | const MCSection *CStringSection_; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 64 | |
| 65 | public: |
| 66 | // FIXME: NONPUB. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 67 | const MCSection *getOrCreateSection(const char *Name, |
| 68 | bool isDirective, |
Chris Lattner | 9de4876 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 69 | SectionKind K) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 70 | public: |
| 71 | |
| 72 | virtual ~TargetLoweringObjectFile(); |
| 73 | |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 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. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 77 | virtual void Initialize(MCContext &ctx, const TargetMachine &TM) { |
| 78 | Ctx = &ctx; |
| 79 | } |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 80 | |
| 81 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 82 | const MCSection *getTextSection() const { return TextSection; } |
| 83 | const MCSection *getDataSection() const { return DataSection; } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 85 | /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively |
| 86 | /// decide not to emit the UsedDirective for some symbols in llvm.used. |
| 87 | /// FIXME: REMOVE this (rdar://7071300) |
| 88 | virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, |
| 89 | Mangler *) const { |
| 90 | return (GV!=0); |
| 91 | } |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 92 | |
| 93 | /// getSectionForMergeableConstant - Given a mergeable constant with the |
| 94 | /// specified size and relocation information, return a section that it |
| 95 | /// should be placed in. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 96 | virtual const MCSection * |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 97 | getSectionForMergeableConstant(SectionKind Kind) const; |
| 98 | |
| 99 | /// getKindForNamedSection - If this target wants to be able to override |
| 100 | /// section flags based on the name of the section specified for a global |
| 101 | /// variable, it can implement this. This is used on ELF systems so that |
| 102 | /// ".tbss" gets the TLS bit set etc. |
Chris Lattner | 9de4876 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 103 | virtual SectionKind getKindForNamedSection(const char *Section, |
| 104 | SectionKind K) const { |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 105 | return K; |
| 106 | } |
| 107 | |
| 108 | /// SectionForGlobal - This method computes the appropriate section to emit |
| 109 | /// the specified global variable or function definition. This should not |
| 110 | /// be passed external (or available externally) globals. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 111 | const MCSection *SectionForGlobal(const GlobalValue *GV, |
| 112 | Mangler *Mang, |
| 113 | const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 114 | |
| 115 | /// getSpecialCasedSectionGlobals - Allow the target to completely override |
| 116 | /// section assignment of a global. |
| 117 | /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with |
| 118 | /// getFlagsForNamedSection. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 119 | virtual const MCSection * |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 120 | getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang, |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame^] | 121 | SectionKind Kind) const { |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /// getSectionFlagsAsString - Turn the flags in the specified SectionKind |
| 126 | /// into a string that can be printed to the assembly file after the |
| 127 | /// ".section foo" part of a section directive. |
| 128 | virtual void getSectionFlagsAsString(SectionKind Kind, |
| 129 | SmallVectorImpl<char> &Str) const { |
| 130 | } |
| 131 | |
| 132 | protected: |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 133 | virtual const MCSection * |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame^] | 134 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 135 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { |
| 142 | bool AtIsCommentChar; // True if @ is the comment character on this target. |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 143 | bool HasCrazyBSS; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 144 | public: |
| 145 | /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI |
| 146 | /// is "@". |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 147 | TargetLoweringObjectFileELF(bool atIsCommentChar = false, |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 148 | // FIXME: REMOVE AFTER UNIQUING IS FIXED. |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 149 | bool hasCrazyBSS = false) |
| 150 | : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {} |
| 151 | |
| 152 | virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 153 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 154 | |
| 155 | /// getSectionForMergeableConstant - Given a mergeable constant with the |
| 156 | /// specified size and relocation information, return a section that it |
| 157 | /// should be placed in. |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 158 | virtual const MCSection * |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 159 | getSectionForMergeableConstant(SectionKind Kind) const; |
| 160 | |
Chris Lattner | 9de4876 | 2009-08-01 21:11:14 +0000 | [diff] [blame] | 161 | virtual SectionKind getKindForNamedSection(const char *Section, |
| 162 | SectionKind K) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 163 | void getSectionFlagsAsString(SectionKind Kind, |
| 164 | SmallVectorImpl<char> &Str) const; |
| 165 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 166 | virtual const MCSection * |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame^] | 167 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 168 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 169 | protected: |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 170 | const MCSection *DataRelSection; |
| 171 | const MCSection *DataRelLocalSection; |
| 172 | const MCSection *DataRelROSection; |
| 173 | const MCSection *DataRelROLocalSection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 174 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 175 | const MCSection *MergeableConst4Section; |
| 176 | const MCSection *MergeableConst8Section; |
| 177 | const MCSection *MergeableConst16Section; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 180 | |
| 181 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 182 | class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile { |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 183 | const MCSection *TextCoalSection; |
| 184 | const MCSection *ConstTextCoalSection; |
| 185 | const MCSection *ConstDataCoalSection; |
| 186 | const MCSection *ConstDataSection; |
| 187 | const MCSection *DataCoalSection; |
| 188 | const MCSection *FourByteConstantSection; |
| 189 | const MCSection *EightByteConstantSection; |
| 190 | const MCSection *SixteenByteConstantSection; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 191 | public: |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 192 | |
| 193 | virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 194 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 195 | virtual const MCSection * |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame^] | 196 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 197 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 198 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 199 | virtual const MCSection * |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 200 | getSectionForMergeableConstant(SectionKind Kind) const; |
Chris Lattner | 84362ac | 2009-07-31 20:52:39 +0000 | [diff] [blame] | 201 | |
| 202 | /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively |
| 203 | /// decide not to emit the UsedDirective for some symbols in llvm.used. |
| 204 | /// FIXME: REMOVE this (rdar://7071300) |
| 205 | virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, |
| 206 | Mangler *) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | |
| 210 | |
| 211 | class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { |
| 212 | public: |
Chris Lattner | 0131627 | 2009-07-31 17:42:42 +0000 | [diff] [blame] | 213 | virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); |
| 214 | |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 215 | virtual void getSectionFlagsAsString(SectionKind Kind, |
| 216 | SmallVectorImpl<char> &Str) const; |
| 217 | |
Chris Lattner | e6ad12f | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 218 | virtual const MCSection * |
Chris Lattner | cfd15d8 | 2009-08-01 21:46:23 +0000 | [diff] [blame^] | 219 | SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, |
Chris Lattner | 2931fe4 | 2009-07-29 05:09:30 +0000 | [diff] [blame] | 220 | Mangler *Mang, const TargetMachine &TM) const; |
Chris Lattner | c4c40a9 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | } // end namespace llvm |
| 224 | |
| 225 | #endif |