Rename NeedsSetToChangeDiffSize to HasAggressiveSymbolFolding which is a much
[oota-llvm.git] / include / llvm / MC / MCAsmInfo.h
1 //===-- llvm/MC/MCAsmInfo.h - Asm 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 contains a class to be used as the basis for target specific
11 // asm writers.  This class primarily takes care of global printing constants,
12 // which are used in very similar ways across all targets.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TARGET_ASM_INFO_H
17 #define LLVM_TARGET_ASM_INFO_H
18
19 #include "llvm/MC/MCDirectives.h"
20 #include <cassert>
21
22 namespace llvm {
23   class MCSection;
24   class MCContext;
25
26   /// MCAsmInfo - This class is intended to be used as a base class for asm
27   /// properties and features specific to the target.
28   namespace ExceptionHandling { enum ExceptionsType { None, Dwarf, SjLj }; }
29
30   class MCAsmInfo {
31   protected:
32     //===------------------------------------------------------------------===//
33     // Properties to be set by the target writer, used to configure asm printer.
34     //
35
36     /// HasSubsectionsViaSymbols - True if this target has the MachO
37     /// .subsections_via_symbols directive.
38     bool HasSubsectionsViaSymbols;           // Default is false.
39
40     /// HasMachoZeroFillDirective - True if this is a MachO target that supports
41     /// the macho-specific .zerofill directive for emitting BSS Symbols.
42     bool HasMachoZeroFillDirective;               // Default is false.
43
44     /// HasMachoTBSSDirective - True if this is a MachO target that supports
45     /// the macho-specific .tbss directive for emitting thread local BSS Symbols
46     bool HasMachoTBSSDirective;                 // Default is false.
47
48     /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
49     /// emit a ".reference .constructors_used" or ".reference .destructors_used"
50     /// directive after the a static ctor/dtor list.  This directive is only
51     /// emitted in Static relocation model.
52     bool HasStaticCtorDtorReferenceInStaticMode;  // Default is false.
53
54     /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
55     /// requires that the debug_line section be of a minimum size. In practice
56     /// such a linker requires a non empty line sequence if a file is present.
57     bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
58
59     /// MaxInstLength - This is the maximum possible length of an instruction,
60     /// which is needed to compute the size of an inline asm.
61     unsigned MaxInstLength;                  // Defaults to 4.
62
63     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
64     /// relative expressions.
65     const char *PCSymbol;                    // Defaults to "$".
66
67     /// SeparatorChar - This character, if specified, is used to separate
68     /// instructions from each other when on the same line.  This is used to
69     /// measure inline asm instructions.
70     char SeparatorChar;                      // Defaults to ';'
71
72     /// CommentColumn - This indicates the comment num (zero-based) at
73     /// which asm comments should be printed.
74     unsigned CommentColumn;                  // Defaults to 40
75
76     /// CommentString - This indicates the comment character used by the
77     /// assembler.
78     const char *CommentString;               // Defaults to "#"
79
80     /// LabelSuffix - This is appended to emitted labels.
81     const char *LabelSuffix;                 // Defaults to ":"
82
83     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
84     /// onto all global symbols.  This is often used for "_" or ".".
85     const char *GlobalPrefix;                // Defaults to ""
86
87     /// PrivateGlobalPrefix - This prefix is used for globals like constant
88     /// pool entries that are completely private to the .s file and should not
89     /// have names in the .o file.  This is often "." or "L".
90     const char *PrivateGlobalPrefix;         // Defaults to "."
91
92     /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
93     /// be passed through the assembler but be removed by the linker.  This
94     /// is "l" on Darwin, currently used for some ObjC metadata.
95     const char *LinkerPrivateGlobalPrefix;   // Defaults to ""
96
97     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
98     /// emit before and after an inline assembly statement.
99     const char *InlineAsmStart;              // Defaults to "#APP\n"
100     const char *InlineAsmEnd;                // Defaults to "#NO_APP\n"
101
102     /// AssemblerDialect - Which dialect of an assembler variant to use.
103     unsigned AssemblerDialect;               // Defaults to 0
104
105     /// AllowQuotesInName - This is true if the assembler allows for complex
106     /// symbol names to be surrounded in quotes.  This defaults to false.
107     bool AllowQuotesInName;
108
109     /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
110     /// names to start with a digit (e.g., "0x0021").  This defaults to false.
111     bool AllowNameToStartWithDigit;
112
113     /// AllowPeriodsInName - This is true if the assembler allows periods in
114     /// symbol names.  This defaults to true.
115     bool AllowPeriodsInName;
116
117     //===--- Data Emission Directives -------------------------------------===//
118
119     /// ZeroDirective - this should be set to the directive used to get some
120     /// number of zero bytes emitted to the current section.  Common cases are
121     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
122     /// Data*bitsDirective's will be used to emit zero bytes.
123     const char *ZeroDirective;               // Defaults to "\t.zero\t"
124
125     /// AsciiDirective - This directive allows emission of an ascii string with
126     /// the standard C escape characters embedded into it.
127     const char *AsciiDirective;              // Defaults to "\t.ascii\t"
128
129     /// AscizDirective - If not null, this allows for special handling of
130     /// zero terminated strings on this target.  This is commonly supported as
131     /// ".asciz".  If a target doesn't support this, it can be set to null.
132     const char *AscizDirective;              // Defaults to "\t.asciz\t"
133
134     /// DataDirectives - These directives are used to output some unit of
135     /// integer data to the current section.  If a data directive is set to
136     /// null, smaller data directives will be used to emit the large sizes.
137     const char *Data8bitsDirective;          // Defaults to "\t.byte\t"
138     const char *Data16bitsDirective;         // Defaults to "\t.short\t"
139     const char *Data32bitsDirective;         // Defaults to "\t.long\t"
140     const char *Data64bitsDirective;         // Defaults to "\t.quad\t"
141
142     /// GPRel32Directive - if non-null, a directive that is used to emit a word
143     /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
144     /// on Mips or .gprel32 on Alpha.
145     const char *GPRel32Directive;            // Defaults to NULL.
146
147     /// getDataASDirective - Return the directive that should be used to emit
148     /// data of the specified size to the specified numeric address space.
149     virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
150       assert(AS != 0 && "Don't know the directives for default addr space");
151       return 0;
152     }
153
154     /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
155     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
156     /// normal ELF syntax (,"a,w") in .section directives.
157     bool SunStyleELFSectionSwitchSyntax;     // Defaults to false.
158
159     /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
160     /// '.section' directive before the '.bss' one. It's used for PPC/Linux
161     /// which doesn't support the '.bss' directive only.
162     bool UsesELFSectionDirectiveForBSS;      // Defaults to false.
163
164     /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
165     /// style mangling for functions with X86_StdCall/X86_FastCall calling
166     /// convention.
167     bool HasMicrosoftFastStdCallMangling;    // Defaults to false.
168
169     //===--- Alignment Information ----------------------------------------===//
170
171     /// AlignDirective - The directive used to emit round up to an alignment
172     /// boundary.
173     ///
174     const char *AlignDirective;              // Defaults to "\t.align\t"
175
176     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
177     /// emits ".align N" directives, where N is the number of bytes to align to.
178     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
179     /// boundary.
180     bool AlignmentIsInBytes;                 // Defaults to true
181
182     /// TextAlignFillValue - If non-zero, this is used to fill the executable
183     /// space created as the result of a alignment directive.
184     unsigned TextAlignFillValue;             // Defaults to 0
185
186     //===--- Global Variable Emission Directives --------------------------===//
187
188     /// GlobalDirective - This is the directive used to declare a global entity.
189     ///
190     const char *GlobalDirective;             // Defaults to NULL.
191
192     /// ExternDirective - This is the directive used to declare external
193     /// globals.
194     ///
195     const char *ExternDirective;             // Defaults to NULL.
196
197     /// HasSetDirective - True if the assembler supports the .set directive.
198     bool HasSetDirective;                    // Defaults to true.
199
200     /// HasAggressiveSymbolFolding - False if the assembler requires that we use
201     /// Lc = a - b
202     /// .long Lc
203     /// instead of
204     /// .long a - b
205     bool HasAggressiveSymbolFolding;           // Defaults to true.
206
207     /// HasLCOMMDirective - This is true if the target supports the .lcomm
208     /// directive.
209     bool HasLCOMMDirective;                  // Defaults to false.
210
211     /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
212     /// alignment is to be specified in bytes instead of log2(n).
213     bool COMMDirectiveAlignmentIsInBytes;    // Defaults to true;
214
215     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
216     /// directives, this is true for most ELF targets.
217     bool HasDotTypeDotSizeDirective;         // Defaults to true.
218
219     /// HasSingleParameterDotFile - True if the target has a single parameter
220     /// .file directive, this is true for ELF targets.
221     bool HasSingleParameterDotFile;          // Defaults to true.
222
223     /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
224     /// directive.
225     bool HasNoDeadStrip;                     // Defaults to false.
226
227     /// HasSymbolResolver - True if this target supports the MachO
228     /// .symbol_resolver directive.
229     bool HasSymbolResolver;                     // Defaults to false.
230
231     /// WeakRefDirective - This directive, if non-null, is used to declare a
232     /// global as being a weak undefined symbol.
233     const char *WeakRefDirective;            // Defaults to NULL.
234
235     /// WeakDefDirective - This directive, if non-null, is used to declare a
236     /// global as being a weak defined symbol.
237     const char *WeakDefDirective;            // Defaults to NULL.
238
239     /// LinkOnceDirective - This directive, if non-null is used to declare a
240     /// global as being a weak defined symbol.  This is used on cygwin/mingw.
241     const char *LinkOnceDirective;           // Defaults to NULL.
242
243     /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
244     /// declare a symbol as having hidden visibility.
245     MCSymbolAttr HiddenVisibilityAttr;       // Defaults to MCSA_Hidden.
246
247     /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
248     /// to declare a symbol as having protected visibility.
249     MCSymbolAttr ProtectedVisibilityAttr;    // Defaults to MCSA_Protected
250
251     //===--- Dwarf Emission Directives -----------------------------------===//
252
253     /// HasLEB128 - True if target asm supports leb128 directives.
254     bool HasLEB128;                          // Defaults to false.
255
256     /// SupportsDebugInformation - True if target supports emission of debugging
257     /// information.
258     bool SupportsDebugInformation;           // Defaults to false.
259
260     /// SupportsExceptionHandling - True if target supports exception handling.
261     ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
262
263     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
264     bool DwarfRequiresFrameSection;          // Defaults to true.
265
266     /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
267     /// encode inline subroutine information.
268     bool DwarfUsesInlineInfoSection;         // Defaults to false.
269
270     /// DwarfSectionOffsetDirective - Special section offset directive.
271     const char* DwarfSectionOffsetDirective; // Defaults to NULL
272
273     /// DwarfUsesAbsoluteLabelForStmtList - True if DW_AT_stmt_list needs
274     /// absolute label instead of offset.
275     bool DwarfUsesAbsoluteLabelForStmtList;  // Defaults to true;
276
277     // DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
278     // use EmitLabelOffsetDifference.
279     bool DwarfUsesLabelOffsetForRanges;
280
281     //===--- CBE Asm Translation Table -----------------------------------===//
282
283     const char *const *AsmTransCBE;          // Defaults to empty
284
285   public:
286     explicit MCAsmInfo();
287     virtual ~MCAsmInfo();
288
289     // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
290     static unsigned getSLEB128Size(int Value);
291     static unsigned getULEB128Size(unsigned Value);
292
293     bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
294
295     // Data directive accessors.
296     //
297     const char *getData8bitsDirective(unsigned AS = 0) const {
298       return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
299     }
300     const char *getData16bitsDirective(unsigned AS = 0) const {
301       return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
302     }
303     const char *getData32bitsDirective(unsigned AS = 0) const {
304       return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
305     }
306     const char *getData64bitsDirective(unsigned AS = 0) const {
307       return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
308     }
309     const char *getGPRel32Directive() const { return GPRel32Directive; }
310
311     /// getNonexecutableStackSection - Targets can implement this method to
312     /// specify a section to switch to if the translation unit doesn't have any
313     /// trampolines that require an executable stack.
314     virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
315       return 0;
316     }
317
318     bool usesSunStyleELFSectionSwitchSyntax() const {
319       return SunStyleELFSectionSwitchSyntax;
320     }
321
322     bool usesELFSectionDirectiveForBSS() const {
323       return UsesELFSectionDirectiveForBSS;
324     }
325
326     bool hasMicrosoftFastStdCallMangling() const {
327       return HasMicrosoftFastStdCallMangling;
328     }
329
330     // Accessors.
331     //
332     bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
333     bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
334     bool hasStaticCtorDtorReferenceInStaticMode() const {
335       return HasStaticCtorDtorReferenceInStaticMode;
336     }
337     bool getLinkerRequiresNonEmptyDwarfLines() const {
338       return LinkerRequiresNonEmptyDwarfLines;
339     }
340     unsigned getMaxInstLength() const {
341       return MaxInstLength;
342     }
343     const char *getPCSymbol() const {
344       return PCSymbol;
345     }
346     char getSeparatorChar() const {
347       return SeparatorChar;
348     }
349     unsigned getCommentColumn() const {
350       return CommentColumn;
351     }
352     const char *getCommentString() const {
353       return CommentString;
354     }
355     const char *getLabelSuffix() const {
356       return LabelSuffix;
357     }
358     const char *getGlobalPrefix() const {
359       return GlobalPrefix;
360     }
361     const char *getPrivateGlobalPrefix() const {
362       return PrivateGlobalPrefix;
363     }
364     const char *getLinkerPrivateGlobalPrefix() const {
365       return LinkerPrivateGlobalPrefix;
366     }
367     const char *getInlineAsmStart() const {
368       return InlineAsmStart;
369     }
370     const char *getInlineAsmEnd() const {
371       return InlineAsmEnd;
372     }
373     unsigned getAssemblerDialect() const {
374       return AssemblerDialect;
375     }
376     bool doesAllowQuotesInName() const {
377       return AllowQuotesInName;
378     }
379     bool doesAllowNameToStartWithDigit() const {
380       return AllowNameToStartWithDigit;
381     }
382     bool doesAllowPeriodsInName() const {
383       return AllowPeriodsInName;
384     }
385     const char *getZeroDirective() const {
386       return ZeroDirective;
387     }
388     const char *getAsciiDirective() const {
389       return AsciiDirective;
390     }
391     const char *getAscizDirective() const {
392       return AscizDirective;
393     }
394     const char *getAlignDirective() const {
395       return AlignDirective;
396     }
397     bool getAlignmentIsInBytes() const {
398       return AlignmentIsInBytes;
399     }
400     unsigned getTextAlignFillValue() const {
401       return TextAlignFillValue;
402     }
403     const char *getGlobalDirective() const {
404       return GlobalDirective;
405     }
406     const char *getExternDirective() const {
407       return ExternDirective;
408     }
409     bool hasSetDirective() const { return HasSetDirective; }
410     bool hasAggressiveSymbolFolding() const {
411       return HasAggressiveSymbolFolding;
412     }
413     bool hasLCOMMDirective() const { return HasLCOMMDirective; }
414     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
415     bool getCOMMDirectiveAlignmentIsInBytes() const {
416       return COMMDirectiveAlignmentIsInBytes;
417     }
418     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
419     bool hasNoDeadStrip() const { return HasNoDeadStrip; }
420     bool hasSymbolResolver() const { return HasSymbolResolver; }
421     const char *getWeakRefDirective() const { return WeakRefDirective; }
422     const char *getWeakDefDirective() const { return WeakDefDirective; }
423     const char *getLinkOnceDirective() const { return LinkOnceDirective; }
424
425     MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
426     MCSymbolAttr getProtectedVisibilityAttr() const {
427       return ProtectedVisibilityAttr;
428     }
429     bool hasLEB128() const {
430       return HasLEB128;
431     }
432     bool doesSupportDebugInformation() const {
433       return SupportsDebugInformation;
434     }
435     bool doesSupportExceptionHandling() const {
436       return ExceptionsType != ExceptionHandling::None;
437     }
438     ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
439       return ExceptionsType;
440     }
441     bool doesDwarfRequireFrameSection() const {
442       return DwarfRequiresFrameSection;
443     }
444     bool doesDwarfUsesInlineInfoSection() const {
445       return DwarfUsesInlineInfoSection;
446     }
447     const char *getDwarfSectionOffsetDirective() const {
448       return DwarfSectionOffsetDirective;
449     }
450     bool doesDwarfUsesAbsoluteLabelForStmtList() const {
451       return DwarfUsesAbsoluteLabelForStmtList;
452     }
453     bool doesDwarfUsesLabelOffsetForRanges() const {
454       return DwarfUsesLabelOffsetForRanges;
455     }
456     const char *const *getAsmCBE() const {
457       return AsmTransCBE;
458     }
459   };
460 }
461
462 #endif