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_MC_MCASMINFO_H
17 #define LLVM_MC_MCASMINFO_H
19 #include "llvm/MC/MCDirectives.h"
20 #include "llvm/MC/MachineLocation.h"
31 namespace ExceptionHandling {
32 enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
36 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
39 /// MCAsmInfo - This class is intended to be used as a base class for asm
40 /// properties and features specific to the target.
43 //===------------------------------------------------------------------===//
44 // Properties to be set by the target writer, used to configure asm printer.
47 /// PointerSize - Pointer size in bytes.
51 /// CalleeSaveStackSlotSize - Size of the stack slot reserved for
52 /// callee-saved registers, in bytes.
53 /// Default is same as pointer size.
54 unsigned CalleeSaveStackSlotSize;
56 /// IsLittleEndian - True if target is little endian.
60 /// StackGrowsUp - True if target stack grow up.
64 /// HasSubsectionsViaSymbols - True if this target has the MachO
65 /// .subsections_via_symbols directive.
66 bool HasSubsectionsViaSymbols; // Default is false.
68 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
69 /// the macho-specific .zerofill directive for emitting BSS Symbols.
70 bool HasMachoZeroFillDirective; // Default is false.
72 /// HasMachoTBSSDirective - True if this is a MachO target that supports
73 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
74 bool HasMachoTBSSDirective; // Default is false.
76 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
77 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
78 /// directive after the a static ctor/dtor list. This directive is only
79 /// emitted in Static relocation model.
80 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
82 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
83 /// requires that the debug_line section be of a minimum size. In practice
84 /// such a linker requires a non empty line sequence if a file is present.
85 bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
87 /// MaxInstLength - This is the maximum possible length of an instruction,
88 /// which is needed to compute the size of an inline asm.
89 unsigned MaxInstLength; // Defaults to 4.
91 /// PCSymbol - The symbol used to represent the current PC. Used in PC
92 /// relative expressions.
93 const char *PCSymbol; // Defaults to "$".
95 /// SeparatorString - This string, if specified, is used to separate
96 /// instructions from each other when on the same line.
97 const char *SeparatorString; // Defaults to ';'
99 /// CommentColumn - This indicates the comment num (zero-based) at
100 /// which asm comments should be printed.
101 unsigned CommentColumn; // Defaults to 40
103 /// CommentString - This indicates the comment character used by the
105 const char *CommentString; // Defaults to "#"
107 /// LabelSuffix - This is appended to emitted labels.
108 const char *LabelSuffix; // Defaults to ":"
110 /// LabelSuffix - This is appended to emitted labels.
111 const char *DebugLabelSuffix; // Defaults to ":"
113 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
114 /// onto all global symbols. This is often used for "_" or ".".
115 const char *GlobalPrefix; // Defaults to ""
117 /// PrivateGlobalPrefix - This prefix is used for globals like constant
118 /// pool entries that are completely private to the .s file and should not
119 /// have names in the .o file. This is often "." or "L".
120 const char *PrivateGlobalPrefix; // Defaults to "."
122 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
123 /// be passed through the assembler but be removed by the linker. This
124 /// is "l" on Darwin, currently used for some ObjC metadata.
125 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
127 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
128 /// emit before and after an inline assembly statement.
129 const char *InlineAsmStart; // Defaults to "#APP\n"
130 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
132 /// Code16Directive, Code32Directive, Code64Directive - These are assembly
133 /// directives that tells the assembler to interpret the following
134 /// instructions differently.
135 const char *Code16Directive; // Defaults to ".code16"
136 const char *Code32Directive; // Defaults to ".code32"
137 const char *Code64Directive; // Defaults to ".code64"
139 /// AssemblerDialect - Which dialect of an assembler variant to use.
140 unsigned AssemblerDialect; // Defaults to 0
142 /// AllowQuotesInName - This is true if the assembler allows for complex
143 /// symbol names to be surrounded in quotes. This defaults to false.
144 bool AllowQuotesInName;
146 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
147 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
148 bool AllowNameToStartWithDigit;
150 /// AllowPeriodsInName - This is true if the assembler allows periods in
151 /// symbol names. This defaults to true.
152 bool AllowPeriodsInName;
154 /// AllowUTF8 - This is true if the assembler accepts UTF-8 input.
155 // FIXME: Make this a more general encoding setting?
158 /// UseDataRegionDirectives - This is true if data region markers should
159 /// be printed as ".data_region/.end_data_region" directives. If false,
160 /// use "$d/$a" labels instead.
161 bool UseDataRegionDirectives;
163 //===--- Data Emission Directives -------------------------------------===//
165 /// ZeroDirective - this should be set to the directive used to get some
166 /// number of zero bytes emitted to the current section. Common cases are
167 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
168 /// Data*bitsDirective's will be used to emit zero bytes.
169 const char *ZeroDirective; // Defaults to "\t.zero\t"
171 /// AsciiDirective - This directive allows emission of an ascii string with
172 /// the standard C escape characters embedded into it.
173 const char *AsciiDirective; // Defaults to "\t.ascii\t"
175 /// AscizDirective - If not null, this allows for special handling of
176 /// zero terminated strings on this target. This is commonly supported as
177 /// ".asciz". If a target doesn't support this, it can be set to null.
178 const char *AscizDirective; // Defaults to "\t.asciz\t"
180 /// DataDirectives - These directives are used to output some unit of
181 /// integer data to the current section. If a data directive is set to
182 /// null, smaller data directives will be used to emit the large sizes.
183 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
184 const char *Data16bitsDirective; // Defaults to "\t.short\t"
185 const char *Data32bitsDirective; // Defaults to "\t.long\t"
186 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
188 /// GPRel64Directive - if non-null, a directive that is used to emit a word
189 /// which should be relocated as a 64-bit GP-relative offset, e.g. .gpdword
191 const char *GPRel64Directive; // Defaults to NULL.
193 /// GPRel32Directive - if non-null, a directive that is used to emit a word
194 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
195 /// on Mips or .gprel32 on Alpha.
196 const char *GPRel32Directive; // Defaults to NULL.
198 /// getDataASDirective - Return the directive that should be used to emit
199 /// data of the specified size to the specified numeric address space.
200 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
201 assert(AS != 0 && "Don't know the directives for default addr space");
205 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
206 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
207 /// normal ELF syntax (,"a,w") in .section directives.
208 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
210 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
211 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
212 /// which doesn't support the '.bss' directive only.
213 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
215 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
216 /// style mangling for functions with X86_StdCall/X86_FastCall calling
218 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
220 bool NeedsDwarfSectionOffsetDirective;
222 //===--- Alignment Information ----------------------------------------===//
224 /// AlignDirective - The directive used to emit round up to an alignment
227 const char *AlignDirective; // Defaults to "\t.align\t"
229 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
230 /// emits ".align N" directives, where N is the number of bytes to align to.
231 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
233 bool AlignmentIsInBytes; // Defaults to true
235 /// TextAlignFillValue - If non-zero, this is used to fill the executable
236 /// space created as the result of a alignment directive.
237 unsigned TextAlignFillValue; // Defaults to 0
239 //===--- Global Variable Emission Directives --------------------------===//
241 /// GlobalDirective - This is the directive used to declare a global entity.
243 const char *GlobalDirective; // Defaults to NULL.
245 /// ExternDirective - This is the directive used to declare external
248 const char *ExternDirective; // Defaults to NULL.
250 /// HasSetDirective - True if the assembler supports the .set directive.
251 bool HasSetDirective; // Defaults to true.
253 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
258 bool HasAggressiveSymbolFolding; // Defaults to true.
260 /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional
261 /// alignment is to be specified in bytes instead of log2(n).
262 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
264 /// LCOMMDirectiveAlignment - Describes if the .lcomm directive for the
265 /// target supports an alignment argument and how it is interpreted.
266 LCOMM::LCOMMType LCOMMDirectiveAlignmentType; // Defaults to NoAlignment.
268 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
269 /// directives, this is true for most ELF targets.
270 bool HasDotTypeDotSizeDirective; // Defaults to true.
272 /// HasSingleParameterDotFile - True if the target has a single parameter
273 /// .file directive, this is true for ELF targets.
274 bool HasSingleParameterDotFile; // Defaults to true.
276 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
278 bool HasNoDeadStrip; // Defaults to false.
280 /// HasSymbolResolver - True if this target supports the MachO
281 /// .symbol_resolver directive.
282 bool HasSymbolResolver; // Defaults to false.
284 /// WeakRefDirective - This directive, if non-null, is used to declare a
285 /// global as being a weak undefined symbol.
286 const char *WeakRefDirective; // Defaults to NULL.
288 /// WeakDefDirective - This directive, if non-null, is used to declare a
289 /// global as being a weak defined symbol.
290 const char *WeakDefDirective; // Defaults to NULL.
292 /// LinkOnceDirective - This directive, if non-null is used to declare a
293 /// global as being a weak defined symbol. This is used on cygwin/mingw.
294 const char *LinkOnceDirective; // Defaults to NULL.
296 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
297 /// declare a symbol as having hidden visibility.
298 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
300 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
301 /// is used to declare an undefined symbol as having hidden visibility.
302 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
305 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
306 /// to declare a symbol as having protected visibility.
307 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
309 //===--- Dwarf Emission Directives -----------------------------------===//
311 /// HasLEB128 - True if target asm supports leb128 directives.
312 bool HasLEB128; // Defaults to false.
314 /// SupportsDebugInformation - True if target supports emission of debugging
316 bool SupportsDebugInformation; // Defaults to false.
318 /// SupportsExceptionHandling - True if target supports exception handling.
319 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
321 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
322 /// encode inline subroutine information.
323 bool DwarfUsesInlineInfoSection; // Defaults to false.
325 /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
326 /// uses relocations for references to other .debug_* sections.
327 bool DwarfUsesRelocationsAcrossSections;
329 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
330 /// instead of symbolic register names in .cfi_* directives.
331 bool DwarfRegNumForCFI; // Defaults to false;
333 //===--- Prologue State ----------------------------------------------===//
335 std::vector<MachineMove> InitialFrameState;
338 explicit MCAsmInfo();
339 virtual ~MCAsmInfo();
341 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
342 static unsigned getSLEB128Size(int Value);
343 static unsigned getULEB128Size(unsigned Value);
345 /// getPointerSize - Get the pointer size in bytes.
346 unsigned getPointerSize() const {
350 /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot
352 unsigned getCalleeSaveStackSlotSize() const {
353 return CalleeSaveStackSlotSize;
356 /// isLittleEndian - True if the target is little endian.
357 bool isLittleEndian() const {
358 return IsLittleEndian;
361 /// isStackGrowthDirectionUp - True if target stack grow up.
362 bool isStackGrowthDirectionUp() const {
366 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
368 // Data directive accessors.
370 const char *getData8bitsDirective(unsigned AS = 0) const {
371 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
373 const char *getData16bitsDirective(unsigned AS = 0) const {
374 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
376 const char *getData32bitsDirective(unsigned AS = 0) const {
377 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
379 const char *getData64bitsDirective(unsigned AS = 0) const {
380 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
382 const char *getGPRel64Directive() const { return GPRel64Directive; }
383 const char *getGPRel32Directive() const { return GPRel32Directive; }
385 /// getNonexecutableStackSection - Targets can implement this method to
386 /// specify a section to switch to if the translation unit doesn't have any
387 /// trampolines that require an executable stack.
388 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
392 virtual const MCExpr *
393 getExprForPersonalitySymbol(const MCSymbol *Sym,
395 MCStreamer &Streamer) const;
398 getExprForFDESymbol(const MCSymbol *Sym,
400 MCStreamer &Streamer) const;
402 bool usesSunStyleELFSectionSwitchSyntax() const {
403 return SunStyleELFSectionSwitchSyntax;
406 bool usesELFSectionDirectiveForBSS() const {
407 return UsesELFSectionDirectiveForBSS;
410 bool hasMicrosoftFastStdCallMangling() const {
411 return HasMicrosoftFastStdCallMangling;
414 bool needsDwarfSectionOffsetDirective() const {
415 return NeedsDwarfSectionOffsetDirective;
420 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
421 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
422 bool hasStaticCtorDtorReferenceInStaticMode() const {
423 return HasStaticCtorDtorReferenceInStaticMode;
425 bool getLinkerRequiresNonEmptyDwarfLines() const {
426 return LinkerRequiresNonEmptyDwarfLines;
428 unsigned getMaxInstLength() const {
429 return MaxInstLength;
431 const char *getPCSymbol() const {
434 const char *getSeparatorString() const {
435 return SeparatorString;
437 unsigned getCommentColumn() const {
438 return CommentColumn;
440 const char *getCommentString() const {
441 return CommentString;
443 const char *getLabelSuffix() const {
447 const char *getDebugLabelSuffix() const {
448 return DebugLabelSuffix;
451 const char *getGlobalPrefix() const {
454 const char *getPrivateGlobalPrefix() const {
455 return PrivateGlobalPrefix;
457 const char *getLinkerPrivateGlobalPrefix() const {
458 return LinkerPrivateGlobalPrefix;
460 const char *getInlineAsmStart() const {
461 return InlineAsmStart;
463 const char *getInlineAsmEnd() const {
466 const char *getCode16Directive() const {
467 return Code16Directive;
469 const char *getCode32Directive() const {
470 return Code32Directive;
472 const char *getCode64Directive() const {
473 return Code64Directive;
475 unsigned getAssemblerDialect() const {
476 return AssemblerDialect;
478 bool doesAllowQuotesInName() const {
479 return AllowQuotesInName;
481 bool doesAllowNameToStartWithDigit() const {
482 return AllowNameToStartWithDigit;
484 bool doesAllowPeriodsInName() const {
485 return AllowPeriodsInName;
487 bool doesAllowUTF8() const {
490 bool doesSupportDataRegionDirectives() const {
491 return UseDataRegionDirectives;
493 const char *getZeroDirective() const {
494 return ZeroDirective;
496 const char *getAsciiDirective() const {
497 return AsciiDirective;
499 const char *getAscizDirective() const {
500 return AscizDirective;
502 const char *getAlignDirective() const {
503 return AlignDirective;
505 bool getAlignmentIsInBytes() const {
506 return AlignmentIsInBytes;
508 unsigned getTextAlignFillValue() const {
509 return TextAlignFillValue;
511 const char *getGlobalDirective() const {
512 return GlobalDirective;
514 const char *getExternDirective() const {
515 return ExternDirective;
517 bool hasSetDirective() const { return HasSetDirective; }
518 bool hasAggressiveSymbolFolding() const {
519 return HasAggressiveSymbolFolding;
521 bool getCOMMDirectiveAlignmentIsInBytes() const {
522 return COMMDirectiveAlignmentIsInBytes;
524 LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
525 return LCOMMDirectiveAlignmentType;
527 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
528 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
529 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
530 bool hasSymbolResolver() const { return HasSymbolResolver; }
531 const char *getWeakRefDirective() const { return WeakRefDirective; }
532 const char *getWeakDefDirective() const { return WeakDefDirective; }
533 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
535 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
536 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
537 return HiddenDeclarationVisibilityAttr;
539 MCSymbolAttr getProtectedVisibilityAttr() const {
540 return ProtectedVisibilityAttr;
542 bool hasLEB128() const {
545 bool doesSupportDebugInformation() const {
546 return SupportsDebugInformation;
548 bool doesSupportExceptionHandling() const {
549 return ExceptionsType != ExceptionHandling::None;
551 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
552 return ExceptionsType;
554 bool isExceptionHandlingDwarf() const {
556 (ExceptionsType == ExceptionHandling::DwarfCFI ||
557 ExceptionsType == ExceptionHandling::ARM ||
558 ExceptionsType == ExceptionHandling::Win64);
560 bool doesDwarfUseInlineInfoSection() const {
561 return DwarfUsesInlineInfoSection;
563 bool doesDwarfUseRelocationsAcrossSections() const {
564 return DwarfUsesRelocationsAcrossSections;
566 bool useDwarfRegNumForCFI() const {
567 return DwarfRegNumForCFI;
570 void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
571 const MachineLocation &S) {
572 InitialFrameState.push_back(MachineMove(label, D, S));
574 const std::vector<MachineMove> &getInitialFrameState() const {
575 return InitialFrameState;