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 };
36 enum LCOMMType { None, NoAlignment, ByteAlignment };
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 /// IsLittleEndian - True if target is little endian.
55 /// StackGrowsUp - True if target stack grow up.
59 /// HasSubsectionsViaSymbols - True if this target has the MachO
60 /// .subsections_via_symbols directive.
61 bool HasSubsectionsViaSymbols; // Default is false.
63 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
64 /// the macho-specific .zerofill directive for emitting BSS Symbols.
65 bool HasMachoZeroFillDirective; // Default is false.
67 /// HasMachoTBSSDirective - True if this is a MachO target that supports
68 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
69 bool HasMachoTBSSDirective; // Default is false.
71 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
72 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
73 /// directive after the a static ctor/dtor list. This directive is only
74 /// emitted in Static relocation model.
75 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
77 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
78 /// requires that the debug_line section be of a minimum size. In practice
79 /// such a linker requires a non empty line sequence if a file is present.
80 bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
82 /// MaxInstLength - This is the maximum possible length of an instruction,
83 /// which is needed to compute the size of an inline asm.
84 unsigned MaxInstLength; // Defaults to 4.
86 /// PCSymbol - The symbol used to represent the current PC. Used in PC
87 /// relative expressions.
88 const char *PCSymbol; // Defaults to "$".
90 /// SeparatorString - This string, if specified, is used to separate
91 /// instructions from each other when on the same line.
92 const char *SeparatorString; // Defaults to ';'
94 /// CommentColumn - This indicates the comment num (zero-based) at
95 /// which asm comments should be printed.
96 unsigned CommentColumn; // Defaults to 40
98 /// CommentString - This indicates the comment character used by the
100 const char *CommentString; // Defaults to "#"
102 /// LabelSuffix - This is appended to emitted labels.
103 const char *LabelSuffix; // Defaults to ":"
105 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
106 /// onto all global symbols. This is often used for "_" or ".".
107 const char *GlobalPrefix; // Defaults to ""
109 /// PrivateGlobalPrefix - This prefix is used for globals like constant
110 /// pool entries that are completely private to the .s file and should not
111 /// have names in the .o file. This is often "." or "L".
112 const char *PrivateGlobalPrefix; // Defaults to "."
114 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
115 /// be passed through the assembler but be removed by the linker. This
116 /// is "l" on Darwin, currently used for some ObjC metadata.
117 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
119 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
120 /// emit before and after an inline assembly statement.
121 const char *InlineAsmStart; // Defaults to "#APP\n"
122 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
124 /// Code16Directive, Code32Directive, Code64Directive - These are assembly
125 /// directives that tells the assembler to interpret the following
126 /// instructions differently.
127 const char *Code16Directive; // Defaults to ".code16"
128 const char *Code32Directive; // Defaults to ".code32"
129 const char *Code64Directive; // Defaults to ".code64"
131 /// AssemblerDialect - Which dialect of an assembler variant to use.
132 unsigned AssemblerDialect; // Defaults to 0
134 /// AllowQuotesInName - This is true if the assembler allows for complex
135 /// symbol names to be surrounded in quotes. This defaults to false.
136 bool AllowQuotesInName;
138 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
139 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
140 bool AllowNameToStartWithDigit;
142 /// AllowPeriodsInName - This is true if the assembler allows periods in
143 /// symbol names. This defaults to true.
144 bool AllowPeriodsInName;
146 //===--- Data Emission Directives -------------------------------------===//
148 /// ZeroDirective - this should be set to the directive used to get some
149 /// number of zero bytes emitted to the current section. Common cases are
150 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
151 /// Data*bitsDirective's will be used to emit zero bytes.
152 const char *ZeroDirective; // Defaults to "\t.zero\t"
154 /// AsciiDirective - This directive allows emission of an ascii string with
155 /// the standard C escape characters embedded into it.
156 const char *AsciiDirective; // Defaults to "\t.ascii\t"
158 /// AscizDirective - If not null, this allows for special handling of
159 /// zero terminated strings on this target. This is commonly supported as
160 /// ".asciz". If a target doesn't support this, it can be set to null.
161 const char *AscizDirective; // Defaults to "\t.asciz\t"
163 /// DataDirectives - These directives are used to output some unit of
164 /// integer data to the current section. If a data directive is set to
165 /// null, smaller data directives will be used to emit the large sizes.
166 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
167 const char *Data16bitsDirective; // Defaults to "\t.short\t"
168 const char *Data32bitsDirective; // Defaults to "\t.long\t"
169 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
171 /// [Data|Code]Begin - These magic labels are used to marked a region as
172 /// data or code, and are used to provide additional information for
173 /// correct disassembly on targets that like to mix data and code within
174 /// a segment. These labels will be implicitly suffixed by the streamer
175 /// to give them unique names.
176 const char *DataBegin; // Defaults to "$d."
177 const char *CodeBegin; // Defaults to "$a."
178 const char *JT8Begin; // Defaults to "$a."
179 const char *JT16Begin; // Defaults to "$a."
180 const char *JT32Begin; // Defaults to "$a."
181 bool SupportsDataRegions;
183 /// GPRel32Directive - if non-null, a directive that is used to emit a word
184 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
185 /// on Mips or .gprel32 on Alpha.
186 const char *GPRel32Directive; // Defaults to NULL.
188 /// getDataASDirective - Return the directive that should be used to emit
189 /// data of the specified size to the specified numeric address space.
190 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
191 assert(AS != 0 && "Don't know the directives for default addr space");
195 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
196 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
197 /// normal ELF syntax (,"a,w") in .section directives.
198 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
200 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
201 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
202 /// which doesn't support the '.bss' directive only.
203 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
205 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
206 /// style mangling for functions with X86_StdCall/X86_FastCall calling
208 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
210 //===--- Alignment Information ----------------------------------------===//
212 /// AlignDirective - The directive used to emit round up to an alignment
215 const char *AlignDirective; // Defaults to "\t.align\t"
217 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
218 /// emits ".align N" directives, where N is the number of bytes to align to.
219 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
221 bool AlignmentIsInBytes; // Defaults to true
223 /// TextAlignFillValue - If non-zero, this is used to fill the executable
224 /// space created as the result of a alignment directive.
225 unsigned TextAlignFillValue; // Defaults to 0
227 //===--- Global Variable Emission Directives --------------------------===//
229 /// GlobalDirective - This is the directive used to declare a global entity.
231 const char *GlobalDirective; // Defaults to NULL.
233 /// ExternDirective - This is the directive used to declare external
236 const char *ExternDirective; // Defaults to NULL.
238 /// HasSetDirective - True if the assembler supports the .set directive.
239 bool HasSetDirective; // Defaults to true.
241 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
246 bool HasAggressiveSymbolFolding; // Defaults to true.
248 /// LCOMMDirectiveType - Describes if the target supports the .lcomm
249 /// directive and whether it has an alignment parameter.
250 LCOMM::LCOMMType LCOMMDirectiveType; // Defaults to LCOMM::None.
252 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
253 /// alignment is to be specified in bytes instead of log2(n).
254 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
256 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
257 /// directives, this is true for most ELF targets.
258 bool HasDotTypeDotSizeDirective; // Defaults to true.
260 /// HasSingleParameterDotFile - True if the target has a single parameter
261 /// .file directive, this is true for ELF targets.
262 bool HasSingleParameterDotFile; // Defaults to true.
264 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
266 bool HasNoDeadStrip; // Defaults to false.
268 /// HasSymbolResolver - True if this target supports the MachO
269 /// .symbol_resolver directive.
270 bool HasSymbolResolver; // Defaults to false.
272 /// WeakRefDirective - This directive, if non-null, is used to declare a
273 /// global as being a weak undefined symbol.
274 const char *WeakRefDirective; // Defaults to NULL.
276 /// WeakDefDirective - This directive, if non-null, is used to declare a
277 /// global as being a weak defined symbol.
278 const char *WeakDefDirective; // Defaults to NULL.
280 /// LinkOnceDirective - This directive, if non-null is used to declare a
281 /// global as being a weak defined symbol. This is used on cygwin/mingw.
282 const char *LinkOnceDirective; // Defaults to NULL.
284 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
285 /// declare a symbol as having hidden visibility.
286 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
288 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
289 /// is used to declare an undefined symbol as having hidden visibility.
290 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
293 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
294 /// to declare a symbol as having protected visibility.
295 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
297 //===--- Dwarf Emission Directives -----------------------------------===//
299 /// HasLEB128 - True if target asm supports leb128 directives.
300 bool HasLEB128; // Defaults to false.
302 /// SupportsDebugInformation - True if target supports emission of debugging
304 bool SupportsDebugInformation; // Defaults to false.
306 /// SupportsExceptionHandling - True if target supports exception handling.
307 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
309 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
310 /// encode inline subroutine information.
311 bool DwarfUsesInlineInfoSection; // Defaults to false.
313 /// DwarfSectionOffsetDirective - Special section offset directive.
314 const char* DwarfSectionOffsetDirective; // Defaults to NULL
316 /// DwarfRequiresRelocationForSectionOffset - True if we need to produce a
317 /// relocation when we want a section offset in dwarf.
318 bool DwarfRequiresRelocationForSectionOffset; // Defaults to true;
320 /// DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
321 /// use EmitLabelOffsetDifference.
322 bool DwarfUsesLabelOffsetForRanges;
324 /// DwarfUsesRelocationsForStringPool - True if this Dwarf output must use
325 /// relocations to refer to entries in the string pool.
326 bool DwarfUsesRelocationsForStringPool;
328 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
329 /// instead of symbolic register names in .cfi_* directives.
330 bool DwarfRegNumForCFI; // Defaults to false;
332 //===--- CBE Asm Translation Table -----------------------------------===//
334 const char *const *AsmTransCBE; // Defaults to empty
336 //===--- Prologue State ----------------------------------------------===//
338 std::vector<MachineMove> InitialFrameState;
341 explicit MCAsmInfo();
342 virtual ~MCAsmInfo();
344 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
345 static unsigned getSLEB128Size(int Value);
346 static unsigned getULEB128Size(unsigned Value);
348 /// getPointerSize - Get the pointer size in bytes.
349 unsigned getPointerSize() const {
353 /// islittleendian - True if the target is little endian.
354 bool isLittleEndian() const {
355 return IsLittleEndian;
358 /// isStackGrowthDirectionUp - True if target stack grow up.
359 bool isStackGrowthDirectionUp() const {
363 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
365 // Data directive accessors.
367 const char *getData8bitsDirective(unsigned AS = 0) const {
368 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
370 const char *getData16bitsDirective(unsigned AS = 0) const {
371 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
373 const char *getData32bitsDirective(unsigned AS = 0) const {
374 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
376 const char *getData64bitsDirective(unsigned AS = 0) const {
377 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
379 const char *getGPRel32Directive() const { return GPRel32Directive; }
381 /// [Code|Data]Begin label name accessors.
382 const char *getCodeBeginLabelName() const { return CodeBegin; }
383 const char *getDataBeginLabelName() const { return DataBegin; }
384 const char *getJumpTable8BeginLabelName() const { return JT8Begin; }
385 const char *getJumpTable16BeginLabelName() const { return JT16Begin; }
386 const char *getJumpTable32BeginLabelName() const { return JT32Begin; }
387 bool getSupportsDataRegions() const { return SupportsDataRegions; }
389 /// getNonexecutableStackSection - Targets can implement this method to
390 /// specify a section to switch to if the translation unit doesn't have any
391 /// trampolines that require an executable stack.
392 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
396 virtual const MCExpr *
397 getExprForPersonalitySymbol(const MCSymbol *Sym,
399 MCStreamer &Streamer) const;
402 getExprForFDESymbol(const MCSymbol *Sym,
404 MCStreamer &Streamer) const;
406 bool usesSunStyleELFSectionSwitchSyntax() const {
407 return SunStyleELFSectionSwitchSyntax;
410 bool usesELFSectionDirectiveForBSS() const {
411 return UsesELFSectionDirectiveForBSS;
414 bool hasMicrosoftFastStdCallMangling() const {
415 return HasMicrosoftFastStdCallMangling;
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 {
446 const char *getGlobalPrefix() const {
449 const char *getPrivateGlobalPrefix() const {
450 return PrivateGlobalPrefix;
452 const char *getLinkerPrivateGlobalPrefix() const {
453 return LinkerPrivateGlobalPrefix;
455 const char *getInlineAsmStart() const {
456 return InlineAsmStart;
458 const char *getInlineAsmEnd() const {
461 const char *getCode16Directive() const {
462 return Code16Directive;
464 const char *getCode32Directive() const {
465 return Code32Directive;
467 const char *getCode64Directive() const {
468 return Code64Directive;
470 unsigned getAssemblerDialect() const {
471 return AssemblerDialect;
473 bool doesAllowQuotesInName() const {
474 return AllowQuotesInName;
476 bool doesAllowNameToStartWithDigit() const {
477 return AllowNameToStartWithDigit;
479 bool doesAllowPeriodsInName() const {
480 return AllowPeriodsInName;
482 const char *getZeroDirective() const {
483 return ZeroDirective;
485 const char *getAsciiDirective() const {
486 return AsciiDirective;
488 const char *getAscizDirective() const {
489 return AscizDirective;
491 const char *getAlignDirective() const {
492 return AlignDirective;
494 bool getAlignmentIsInBytes() const {
495 return AlignmentIsInBytes;
497 unsigned getTextAlignFillValue() const {
498 return TextAlignFillValue;
500 const char *getGlobalDirective() const {
501 return GlobalDirective;
503 const char *getExternDirective() const {
504 return ExternDirective;
506 bool hasSetDirective() const { return HasSetDirective; }
507 bool hasAggressiveSymbolFolding() const {
508 return HasAggressiveSymbolFolding;
510 LCOMM::LCOMMType getLCOMMDirectiveType() const {
511 return LCOMMDirectiveType;
513 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
514 bool getCOMMDirectiveAlignmentIsInBytes() const {
515 return COMMDirectiveAlignmentIsInBytes;
517 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
518 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
519 bool hasSymbolResolver() const { return HasSymbolResolver; }
520 const char *getWeakRefDirective() const { return WeakRefDirective; }
521 const char *getWeakDefDirective() const { return WeakDefDirective; }
522 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
524 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
525 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
526 return HiddenDeclarationVisibilityAttr;
528 MCSymbolAttr getProtectedVisibilityAttr() const {
529 return ProtectedVisibilityAttr;
531 bool hasLEB128() const {
534 bool doesSupportDebugInformation() const {
535 return SupportsDebugInformation;
537 bool doesSupportExceptionHandling() const {
538 return ExceptionsType != ExceptionHandling::None;
540 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
541 return ExceptionsType;
543 bool isExceptionHandlingDwarf() const {
545 (ExceptionsType == ExceptionHandling::DwarfCFI ||
546 ExceptionsType == ExceptionHandling::ARM ||
547 ExceptionsType == ExceptionHandling::Win64);
549 bool doesDwarfUsesInlineInfoSection() const {
550 return DwarfUsesInlineInfoSection;
552 const char *getDwarfSectionOffsetDirective() const {
553 return DwarfSectionOffsetDirective;
555 bool doesDwarfRequireRelocationForSectionOffset() const {
556 return DwarfRequiresRelocationForSectionOffset;
558 bool doesDwarfUsesLabelOffsetForRanges() const {
559 return DwarfUsesLabelOffsetForRanges;
561 bool doesDwarfUseRelocationsForStringPool() const {
562 return DwarfUsesRelocationsForStringPool;
564 bool useDwarfRegNumForCFI() const {
565 return DwarfRegNumForCFI;
567 const char *const *getAsmCBE() const {
571 void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
572 const MachineLocation &S) {
573 InitialFrameState.push_back(MachineMove(label, D, S));
575 const std::vector<MachineMove> &getInitialFrameState() const {
576 return InitialFrameState;