1 //===-- llvm/MC/MCAsmInfo.h - Asm 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 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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TARGET_ASM_INFO_H
17 #define LLVM_TARGET_ASM_INFO_H
19 #include "llvm/MC/MachineLocation.h"
20 #include "llvm/MC/MCDirectives.h"
31 namespace ExceptionHandling {
32 enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
35 /// MCAsmInfo - This class is intended to be used as a base class for asm
36 /// properties and features specific to the target.
39 //===------------------------------------------------------------------===//
40 // Properties to be set by the target writer, used to configure asm printer.
43 /// PointerSize - Pointer size in bytes.
47 /// IsLittleEndian - True if target is little endian.
51 /// StackGrowsUp - True if target stack grow up.
55 /// HasSubsectionsViaSymbols - True if this target has the MachO
56 /// .subsections_via_symbols directive.
57 bool HasSubsectionsViaSymbols; // Default is false.
59 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
60 /// the macho-specific .zerofill directive for emitting BSS Symbols.
61 bool HasMachoZeroFillDirective; // Default is false.
63 /// HasMachoTBSSDirective - True if this is a MachO target that supports
64 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
65 bool HasMachoTBSSDirective; // Default is false.
67 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
68 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
69 /// directive after the a static ctor/dtor list. This directive is only
70 /// emitted in Static relocation model.
71 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
73 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
74 /// requires that the debug_line section be of a minimum size. In practice
75 /// such a linker requires a non empty line sequence if a file is present.
76 bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
78 /// MaxInstLength - This is the maximum possible length of an instruction,
79 /// which is needed to compute the size of an inline asm.
80 unsigned MaxInstLength; // Defaults to 4.
82 /// PCSymbol - The symbol used to represent the current PC. Used in PC
83 /// relative expressions.
84 const char *PCSymbol; // Defaults to "$".
86 /// SeparatorString - This string, if specified, is used to separate
87 /// instructions from each other when on the same line.
88 const char *SeparatorString; // Defaults to ';'
90 /// CommentColumn - This indicates the comment num (zero-based) at
91 /// which asm comments should be printed.
92 unsigned CommentColumn; // Defaults to 40
94 /// CommentString - This indicates the comment character used by the
96 const char *CommentString; // Defaults to "#"
98 /// LabelSuffix - This is appended to emitted labels.
99 const char *LabelSuffix; // Defaults to ":"
101 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
102 /// onto all global symbols. This is often used for "_" or ".".
103 const char *GlobalPrefix; // Defaults to ""
105 /// PrivateGlobalPrefix - This prefix is used for globals like constant
106 /// pool entries that are completely private to the .s file and should not
107 /// have names in the .o file. This is often "." or "L".
108 const char *PrivateGlobalPrefix; // Defaults to "."
110 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
111 /// be passed through the assembler but be removed by the linker. This
112 /// is "l" on Darwin, currently used for some ObjC metadata.
113 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
115 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
116 /// emit before and after an inline assembly statement.
117 const char *InlineAsmStart; // Defaults to "#APP\n"
118 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
120 /// Code16Directive, Code32Directive, Code64Directive - These are assembly
121 /// directives that tells the assembler to interpret the following
122 /// instructions differently.
123 const char *Code16Directive; // Defaults to ".code16"
124 const char *Code32Directive; // Defaults to ".code32"
125 const char *Code64Directive; // Defaults to ".code64"
127 /// AssemblerDialect - Which dialect of an assembler variant to use.
128 unsigned AssemblerDialect; // Defaults to 0
130 /// AllowQuotesInName - This is true if the assembler allows for complex
131 /// symbol names to be surrounded in quotes. This defaults to false.
132 bool AllowQuotesInName;
134 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
135 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
136 bool AllowNameToStartWithDigit;
138 /// AllowPeriodsInName - This is true if the assembler allows periods in
139 /// symbol names. This defaults to true.
140 bool AllowPeriodsInName;
142 /// AllowUTF8 - This is true if the assembler accepts UTF-8 input.
143 // FIXME: Make this a more general encoding setting?
146 /// UseDataRegionDirectives - This is true if data region markers should
147 /// be printed as ".data_region/.end_data_region" directives. If false,
148 /// use "$d/$a" labels instead.
149 bool UseDataRegionDirectives;
151 //===--- Data Emission Directives -------------------------------------===//
153 /// ZeroDirective - this should be set to the directive used to get some
154 /// number of zero bytes emitted to the current section. Common cases are
155 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
156 /// Data*bitsDirective's will be used to emit zero bytes.
157 const char *ZeroDirective; // Defaults to "\t.zero\t"
159 /// AsciiDirective - This directive allows emission of an ascii string with
160 /// the standard C escape characters embedded into it.
161 const char *AsciiDirective; // Defaults to "\t.ascii\t"
163 /// AscizDirective - If not null, this allows for special handling of
164 /// zero terminated strings on this target. This is commonly supported as
165 /// ".asciz". If a target doesn't support this, it can be set to null.
166 const char *AscizDirective; // Defaults to "\t.asciz\t"
168 /// DataDirectives - These directives are used to output some unit of
169 /// integer data to the current section. If a data directive is set to
170 /// null, smaller data directives will be used to emit the large sizes.
171 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
172 const char *Data16bitsDirective; // Defaults to "\t.short\t"
173 const char *Data32bitsDirective; // Defaults to "\t.long\t"
174 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
176 /// GPRel64Directive - if non-null, a directive that is used to emit a word
177 /// which should be relocated as a 64-bit GP-relative offset, e.g. .gpdword
179 const char *GPRel64Directive; // Defaults to NULL.
181 /// GPRel32Directive - if non-null, a directive that is used to emit a word
182 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
183 /// on Mips or .gprel32 on Alpha.
184 const char *GPRel32Directive; // Defaults to NULL.
186 /// getDataASDirective - Return the directive that should be used to emit
187 /// data of the specified size to the specified numeric address space.
188 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
189 assert(AS != 0 && "Don't know the directives for default addr space");
193 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
194 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
195 /// normal ELF syntax (,"a,w") in .section directives.
196 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
198 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
199 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
200 /// which doesn't support the '.bss' directive only.
201 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
203 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
204 /// style mangling for functions with X86_StdCall/X86_FastCall calling
206 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
208 //===--- Alignment Information ----------------------------------------===//
210 /// AlignDirective - The directive used to emit round up to an alignment
213 const char *AlignDirective; // Defaults to "\t.align\t"
215 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
216 /// emits ".align N" directives, where N is the number of bytes to align to.
217 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
219 bool AlignmentIsInBytes; // Defaults to true
221 /// TextAlignFillValue - If non-zero, this is used to fill the executable
222 /// space created as the result of a alignment directive.
223 unsigned TextAlignFillValue; // Defaults to 0
225 //===--- Global Variable Emission Directives --------------------------===//
227 /// GlobalDirective - This is the directive used to declare a global entity.
229 const char *GlobalDirective; // Defaults to NULL.
231 /// ExternDirective - This is the directive used to declare external
234 const char *ExternDirective; // Defaults to NULL.
236 /// HasSetDirective - True if the assembler supports the .set directive.
237 bool HasSetDirective; // Defaults to true.
239 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
244 bool HasAggressiveSymbolFolding; // Defaults to true.
246 /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional
247 /// alignment is to be specified in bytes instead of log2(n).
248 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
250 /// LCOMMDirectiveSupportsAlignment - True if .lcomm supports an optional
251 /// alignment argument on this target.
252 bool LCOMMDirectiveSupportsAlignment; // Defaults to false.
254 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
255 /// directives, this is true for most ELF targets.
256 bool HasDotTypeDotSizeDirective; // Defaults to true.
258 /// HasSingleParameterDotFile - True if the target has a single parameter
259 /// .file directive, this is true for ELF targets.
260 bool HasSingleParameterDotFile; // Defaults to true.
262 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
264 bool HasNoDeadStrip; // Defaults to false.
266 /// HasSymbolResolver - True if this target supports the MachO
267 /// .symbol_resolver directive.
268 bool HasSymbolResolver; // Defaults to false.
270 /// WeakRefDirective - This directive, if non-null, is used to declare a
271 /// global as being a weak undefined symbol.
272 const char *WeakRefDirective; // Defaults to NULL.
274 /// WeakDefDirective - This directive, if non-null, is used to declare a
275 /// global as being a weak defined symbol.
276 const char *WeakDefDirective; // Defaults to NULL.
278 /// LinkOnceDirective - This directive, if non-null is used to declare a
279 /// global as being a weak defined symbol. This is used on cygwin/mingw.
280 const char *LinkOnceDirective; // Defaults to NULL.
282 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
283 /// declare a symbol as having hidden visibility.
284 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
286 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
287 /// is used to declare an undefined symbol as having hidden visibility.
288 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
291 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
292 /// to declare a symbol as having protected visibility.
293 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
295 //===--- Dwarf Emission Directives -----------------------------------===//
297 /// HasLEB128 - True if target asm supports leb128 directives.
298 bool HasLEB128; // Defaults to false.
300 /// SupportsDebugInformation - True if target supports emission of debugging
302 bool SupportsDebugInformation; // Defaults to false.
304 /// SupportsExceptionHandling - True if target supports exception handling.
305 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
307 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
308 /// encode inline subroutine information.
309 bool DwarfUsesInlineInfoSection; // Defaults to false.
311 /// DwarfSectionOffsetDirective - Special section offset directive.
312 const char* DwarfSectionOffsetDirective; // Defaults to NULL
314 /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
315 /// uses relocations for references to other .debug_* sections.
316 bool DwarfUsesRelocationsAcrossSections;
318 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
319 /// instead of symbolic register names in .cfi_* directives.
320 bool DwarfRegNumForCFI; // Defaults to false;
322 //===--- Prologue State ----------------------------------------------===//
324 std::vector<MachineMove> InitialFrameState;
327 explicit MCAsmInfo();
328 virtual ~MCAsmInfo();
330 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
331 static unsigned getSLEB128Size(int Value);
332 static unsigned getULEB128Size(unsigned Value);
334 /// getPointerSize - Get the pointer size in bytes.
335 unsigned getPointerSize() const {
339 /// islittleendian - True if the target is little endian.
340 bool isLittleEndian() const {
341 return IsLittleEndian;
344 /// isStackGrowthDirectionUp - True if target stack grow up.
345 bool isStackGrowthDirectionUp() const {
349 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
351 // Data directive accessors.
353 const char *getData8bitsDirective(unsigned AS = 0) const {
354 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
356 const char *getData16bitsDirective(unsigned AS = 0) const {
357 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
359 const char *getData32bitsDirective(unsigned AS = 0) const {
360 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
362 const char *getData64bitsDirective(unsigned AS = 0) const {
363 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
365 const char *getGPRel64Directive() const { return GPRel64Directive; }
366 const char *getGPRel32Directive() const { return GPRel32Directive; }
368 /// getNonexecutableStackSection - Targets can implement this method to
369 /// specify a section to switch to if the translation unit doesn't have any
370 /// trampolines that require an executable stack.
371 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
375 virtual const MCExpr *
376 getExprForPersonalitySymbol(const MCSymbol *Sym,
378 MCStreamer &Streamer) const;
381 getExprForFDESymbol(const MCSymbol *Sym,
383 MCStreamer &Streamer) const;
385 bool usesSunStyleELFSectionSwitchSyntax() const {
386 return SunStyleELFSectionSwitchSyntax;
389 bool usesELFSectionDirectiveForBSS() const {
390 return UsesELFSectionDirectiveForBSS;
393 bool hasMicrosoftFastStdCallMangling() const {
394 return HasMicrosoftFastStdCallMangling;
399 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
400 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
401 bool hasStaticCtorDtorReferenceInStaticMode() const {
402 return HasStaticCtorDtorReferenceInStaticMode;
404 bool getLinkerRequiresNonEmptyDwarfLines() const {
405 return LinkerRequiresNonEmptyDwarfLines;
407 unsigned getMaxInstLength() const {
408 return MaxInstLength;
410 const char *getPCSymbol() const {
413 const char *getSeparatorString() const {
414 return SeparatorString;
416 unsigned getCommentColumn() const {
417 return CommentColumn;
419 const char *getCommentString() const {
420 return CommentString;
422 const char *getLabelSuffix() const {
425 const char *getGlobalPrefix() const {
428 const char *getPrivateGlobalPrefix() const {
429 return PrivateGlobalPrefix;
431 const char *getLinkerPrivateGlobalPrefix() const {
432 return LinkerPrivateGlobalPrefix;
434 const char *getInlineAsmStart() const {
435 return InlineAsmStart;
437 const char *getInlineAsmEnd() const {
440 const char *getCode16Directive() const {
441 return Code16Directive;
443 const char *getCode32Directive() const {
444 return Code32Directive;
446 const char *getCode64Directive() const {
447 return Code64Directive;
449 unsigned getAssemblerDialect() const {
450 return AssemblerDialect;
452 bool doesAllowQuotesInName() const {
453 return AllowQuotesInName;
455 bool doesAllowNameToStartWithDigit() const {
456 return AllowNameToStartWithDigit;
458 bool doesAllowPeriodsInName() const {
459 return AllowPeriodsInName;
461 bool doesAllowUTF8() const {
464 bool doesSupportDataRegionDirectives() const {
465 return UseDataRegionDirectives;
467 const char *getZeroDirective() const {
468 return ZeroDirective;
470 const char *getAsciiDirective() const {
471 return AsciiDirective;
473 const char *getAscizDirective() const {
474 return AscizDirective;
476 const char *getAlignDirective() const {
477 return AlignDirective;
479 bool getAlignmentIsInBytes() const {
480 return AlignmentIsInBytes;
482 unsigned getTextAlignFillValue() const {
483 return TextAlignFillValue;
485 const char *getGlobalDirective() const {
486 return GlobalDirective;
488 const char *getExternDirective() const {
489 return ExternDirective;
491 bool hasSetDirective() const { return HasSetDirective; }
492 bool hasAggressiveSymbolFolding() const {
493 return HasAggressiveSymbolFolding;
495 bool getCOMMDirectiveAlignmentIsInBytes() const {
496 return COMMDirectiveAlignmentIsInBytes;
498 bool getLCOMMDirectiveSupportsAlignment() const {
499 return LCOMMDirectiveSupportsAlignment;
501 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
502 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
503 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
504 bool hasSymbolResolver() const { return HasSymbolResolver; }
505 const char *getWeakRefDirective() const { return WeakRefDirective; }
506 const char *getWeakDefDirective() const { return WeakDefDirective; }
507 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
509 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
510 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
511 return HiddenDeclarationVisibilityAttr;
513 MCSymbolAttr getProtectedVisibilityAttr() const {
514 return ProtectedVisibilityAttr;
516 bool hasLEB128() const {
519 bool doesSupportDebugInformation() const {
520 return SupportsDebugInformation;
522 bool doesSupportExceptionHandling() const {
523 return ExceptionsType != ExceptionHandling::None;
525 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
526 return ExceptionsType;
528 bool isExceptionHandlingDwarf() const {
530 (ExceptionsType == ExceptionHandling::DwarfCFI ||
531 ExceptionsType == ExceptionHandling::ARM ||
532 ExceptionsType == ExceptionHandling::Win64);
534 bool doesDwarfUseInlineInfoSection() const {
535 return DwarfUsesInlineInfoSection;
537 const char *getDwarfSectionOffsetDirective() const {
538 return DwarfSectionOffsetDirective;
540 bool doesDwarfUseRelocationsAcrossSections() const {
541 return DwarfUsesRelocationsAcrossSections;
543 bool useDwarfRegNumForCFI() const {
544 return DwarfRegNumForCFI;
547 void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
548 const MachineLocation &S) {
549 InitialFrameState.push_back(MachineMove(label, D, S));
551 const std::vector<MachineMove> &getInitialFrameState() const {
552 return InitialFrameState;