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 };
33 enum ARMEHABIMode { ARMEHABIDisabled, ARMEHABIUnwind, ARMEHABIFull };
37 enum LCOMMType { None, NoAlignment, ByteAlignment };
40 /// MCAsmInfo - This class is intended to be used as a base class for asm
41 /// properties and features specific to the target.
44 //===------------------------------------------------------------------===//
45 // Properties to be set by the target writer, used to configure asm printer.
48 /// PointerSize - Pointer size in bytes.
52 /// IsLittleEndian - True if target is little endian.
56 /// StackGrowsUp - True if target stack grow up.
60 /// HasSubsectionsViaSymbols - True if this target has the MachO
61 /// .subsections_via_symbols directive.
62 bool HasSubsectionsViaSymbols; // Default is false.
64 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
65 /// the macho-specific .zerofill directive for emitting BSS Symbols.
66 bool HasMachoZeroFillDirective; // Default is false.
68 /// HasMachoTBSSDirective - True if this is a MachO target that supports
69 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
70 bool HasMachoTBSSDirective; // Default is false.
72 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
73 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
74 /// directive after the a static ctor/dtor list. This directive is only
75 /// emitted in Static relocation model.
76 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
78 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
79 /// requires that the debug_line section be of a minimum size. In practice
80 /// such a linker requires a non empty line sequence if a file is present.
81 bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
83 /// MaxInstLength - This is the maximum possible length of an instruction,
84 /// which is needed to compute the size of an inline asm.
85 unsigned MaxInstLength; // Defaults to 4.
87 /// PCSymbol - The symbol used to represent the current PC. Used in PC
88 /// relative expressions.
89 const char *PCSymbol; // Defaults to "$".
91 /// SeparatorString - This string, if specified, is used to separate
92 /// instructions from each other when on the same line.
93 const char *SeparatorString; // Defaults to ';'
95 /// CommentColumn - This indicates the comment num (zero-based) at
96 /// which asm comments should be printed.
97 unsigned CommentColumn; // Defaults to 40
99 /// CommentString - This indicates the comment character used by the
101 const char *CommentString; // Defaults to "#"
103 /// LabelSuffix - This is appended to emitted labels.
104 const char *LabelSuffix; // Defaults to ":"
106 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
107 /// onto all global symbols. This is often used for "_" or ".".
108 const char *GlobalPrefix; // Defaults to ""
110 /// PrivateGlobalPrefix - This prefix is used for globals like constant
111 /// pool entries that are completely private to the .s file and should not
112 /// have names in the .o file. This is often "." or "L".
113 const char *PrivateGlobalPrefix; // Defaults to "."
115 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
116 /// be passed through the assembler but be removed by the linker. This
117 /// is "l" on Darwin, currently used for some ObjC metadata.
118 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
120 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
121 /// emit before and after an inline assembly statement.
122 const char *InlineAsmStart; // Defaults to "#APP\n"
123 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
125 /// Code16Directive, Code32Directive, Code64Directive - These are assembly
126 /// directives that tells the assembler to interpret the following
127 /// instructions differently.
128 const char *Code16Directive; // Defaults to ".code16"
129 const char *Code32Directive; // Defaults to ".code32"
130 const char *Code64Directive; // Defaults to ".code64"
132 /// AssemblerDialect - Which dialect of an assembler variant to use.
133 unsigned AssemblerDialect; // Defaults to 0
135 /// AllowQuotesInName - This is true if the assembler allows for complex
136 /// symbol names to be surrounded in quotes. This defaults to false.
137 bool AllowQuotesInName;
139 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
140 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
141 bool AllowNameToStartWithDigit;
143 /// AllowPeriodsInName - This is true if the assembler allows periods in
144 /// symbol names. This defaults to true.
145 bool AllowPeriodsInName;
147 //===--- Data Emission Directives -------------------------------------===//
149 /// ZeroDirective - this should be set to the directive used to get some
150 /// number of zero bytes emitted to the current section. Common cases are
151 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
152 /// Data*bitsDirective's will be used to emit zero bytes.
153 const char *ZeroDirective; // Defaults to "\t.zero\t"
155 /// AsciiDirective - This directive allows emission of an ascii string with
156 /// the standard C escape characters embedded into it.
157 const char *AsciiDirective; // Defaults to "\t.ascii\t"
159 /// AscizDirective - If not null, this allows for special handling of
160 /// zero terminated strings on this target. This is commonly supported as
161 /// ".asciz". If a target doesn't support this, it can be set to null.
162 const char *AscizDirective; // Defaults to "\t.asciz\t"
164 /// DataDirectives - These directives are used to output some unit of
165 /// integer data to the current section. If a data directive is set to
166 /// null, smaller data directives will be used to emit the large sizes.
167 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
168 const char *Data16bitsDirective; // Defaults to "\t.short\t"
169 const char *Data32bitsDirective; // Defaults to "\t.long\t"
170 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
172 /// [Data|Code]Begin - These magic labels are used to marked a region as
173 /// data or code, and are used to provide additional information for
174 /// correct disassembly on targets that like to mix data and code within
175 /// a segment. These labels will be implicitly suffixed by the streamer
176 /// to give them unique names.
177 const char *DataBegin; // Defaults to "$d."
178 const char *CodeBegin; // Defaults to "$a."
179 const char *JT8Begin; // Defaults to "$a."
180 const char *JT16Begin; // Defaults to "$a."
181 const char *JT32Begin; // Defaults to "$a."
182 bool SupportsDataRegions;
184 /// GPRel32Directive - if non-null, a directive that is used to emit a word
185 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
186 /// on Mips or .gprel32 on Alpha.
187 const char *GPRel32Directive; // Defaults to NULL.
189 /// getDataASDirective - Return the directive that should be used to emit
190 /// data of the specified size to the specified numeric address space.
191 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
192 assert(AS != 0 && "Don't know the directives for default addr space");
196 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
197 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
198 /// normal ELF syntax (,"a,w") in .section directives.
199 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
201 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
202 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
203 /// which doesn't support the '.bss' directive only.
204 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
206 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
207 /// style mangling for functions with X86_StdCall/X86_FastCall calling
209 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
211 //===--- Alignment Information ----------------------------------------===//
213 /// AlignDirective - The directive used to emit round up to an alignment
216 const char *AlignDirective; // Defaults to "\t.align\t"
218 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
219 /// emits ".align N" directives, where N is the number of bytes to align to.
220 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
222 bool AlignmentIsInBytes; // Defaults to true
224 /// TextAlignFillValue - If non-zero, this is used to fill the executable
225 /// space created as the result of a alignment directive.
226 unsigned TextAlignFillValue; // Defaults to 0
228 //===--- Global Variable Emission Directives --------------------------===//
230 /// GlobalDirective - This is the directive used to declare a global entity.
232 const char *GlobalDirective; // Defaults to NULL.
234 /// ExternDirective - This is the directive used to declare external
237 const char *ExternDirective; // Defaults to NULL.
239 /// HasSetDirective - True if the assembler supports the .set directive.
240 bool HasSetDirective; // Defaults to true.
242 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
247 bool HasAggressiveSymbolFolding; // Defaults to true.
249 /// LCOMMDirectiveType - Describes if the target supports the .lcomm
250 /// directive and whether it has an alignment parameter.
251 LCOMM::LCOMMType LCOMMDirectiveType; // Defaults to LCOMM::None.
253 /// COMMDirectiveAlignmentIsInBytes - True is COMMDirective's optional
254 /// alignment is to be specified in bytes instead of log2(n).
255 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
257 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
258 /// directives, this is true for most ELF targets.
259 bool HasDotTypeDotSizeDirective; // Defaults to true.
261 /// HasSingleParameterDotFile - True if the target has a single parameter
262 /// .file directive, this is true for ELF targets.
263 bool HasSingleParameterDotFile; // Defaults to true.
265 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
267 bool HasNoDeadStrip; // Defaults to false.
269 /// HasSymbolResolver - True if this target supports the MachO
270 /// .symbol_resolver directive.
271 bool HasSymbolResolver; // Defaults to false.
273 /// WeakRefDirective - This directive, if non-null, is used to declare a
274 /// global as being a weak undefined symbol.
275 const char *WeakRefDirective; // Defaults to NULL.
277 /// WeakDefDirective - This directive, if non-null, is used to declare a
278 /// global as being a weak defined symbol.
279 const char *WeakDefDirective; // Defaults to NULL.
281 /// LinkOnceDirective - This directive, if non-null is used to declare a
282 /// global as being a weak defined symbol. This is used on cygwin/mingw.
283 const char *LinkOnceDirective; // Defaults to NULL.
285 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
286 /// declare a symbol as having hidden visibility.
287 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
289 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
290 /// is used to declare an undefined symbol as having hidden visibility.
291 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
294 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
295 /// to declare a symbol as having protected visibility.
296 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
298 //===--- Dwarf Emission Directives -----------------------------------===//
300 /// HasLEB128 - True if target asm supports leb128 directives.
301 bool HasLEB128; // Defaults to false.
303 /// SupportsDebugInformation - True if target supports emission of debugging
305 bool SupportsDebugInformation; // Defaults to false.
307 /// SupportsExceptionHandling - True if target supports exception handling.
308 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
310 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
311 /// encode inline subroutine information.
312 bool DwarfUsesInlineInfoSection; // Defaults to false.
314 /// DwarfSectionOffsetDirective - Special section offset directive.
315 const char* DwarfSectionOffsetDirective; // Defaults to NULL
317 /// DwarfRequiresRelocationForSectionOffset - True if we need to produce a
318 /// relocation when we want a section offset in dwarf.
319 bool DwarfRequiresRelocationForSectionOffset; // Defaults to true;
321 /// DwarfUsesLabelOffsetDifference - True if Dwarf2 output can
322 /// use EmitLabelOffsetDifference.
323 bool DwarfUsesLabelOffsetForRanges;
325 /// DwarfUsesRelocationsForStringPool - True if this Dwarf output must use
326 /// relocations to refer to entries in the string pool.
327 bool DwarfUsesRelocationsForStringPool;
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 //===--- CBE Asm Translation Table -----------------------------------===//
335 const char *const *AsmTransCBE; // Defaults to empty
337 //===--- Prologue State ----------------------------------------------===//
339 std::vector<MachineMove> InitialFrameState;
342 explicit MCAsmInfo();
343 virtual ~MCAsmInfo();
345 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
346 static unsigned getSLEB128Size(int Value);
347 static unsigned getULEB128Size(unsigned Value);
349 /// getPointerSize - Get the pointer size in bytes.
350 unsigned getPointerSize() const {
354 /// islittleendian - True if the target is little endian.
355 bool isLittleEndian() const {
356 return IsLittleEndian;
359 /// isStackGrowthDirectionUp - True if target stack grow up.
360 bool isStackGrowthDirectionUp() const {
364 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
366 // Data directive accessors.
368 const char *getData8bitsDirective(unsigned AS = 0) const {
369 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
371 const char *getData16bitsDirective(unsigned AS = 0) const {
372 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
374 const char *getData32bitsDirective(unsigned AS = 0) const {
375 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
377 const char *getData64bitsDirective(unsigned AS = 0) const {
378 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
380 const char *getGPRel32Directive() const { return GPRel32Directive; }
382 /// [Code|Data]Begin label name accessors.
383 const char *getCodeBeginLabelName() const { return CodeBegin; }
384 const char *getDataBeginLabelName() const { return DataBegin; }
385 const char *getJumpTable8BeginLabelName() const { return JT8Begin; }
386 const char *getJumpTable16BeginLabelName() const { return JT16Begin; }
387 const char *getJumpTable32BeginLabelName() const { return JT32Begin; }
388 bool getSupportsDataRegions() const { return SupportsDataRegions; }
390 /// getNonexecutableStackSection - Targets can implement this method to
391 /// specify a section to switch to if the translation unit doesn't have any
392 /// trampolines that require an executable stack.
393 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
397 virtual const MCExpr *
398 getExprForPersonalitySymbol(const MCSymbol *Sym,
400 MCStreamer &Streamer) const;
403 getExprForFDESymbol(const MCSymbol *Sym,
405 MCStreamer &Streamer) const;
407 bool usesSunStyleELFSectionSwitchSyntax() const {
408 return SunStyleELFSectionSwitchSyntax;
411 bool usesELFSectionDirectiveForBSS() const {
412 return UsesELFSectionDirectiveForBSS;
415 bool hasMicrosoftFastStdCallMangling() const {
416 return HasMicrosoftFastStdCallMangling;
421 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
422 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
423 bool hasStaticCtorDtorReferenceInStaticMode() const {
424 return HasStaticCtorDtorReferenceInStaticMode;
426 bool getLinkerRequiresNonEmptyDwarfLines() const {
427 return LinkerRequiresNonEmptyDwarfLines;
429 unsigned getMaxInstLength() const {
430 return MaxInstLength;
432 const char *getPCSymbol() const {
435 const char *getSeparatorString() const {
436 return SeparatorString;
438 unsigned getCommentColumn() const {
439 return CommentColumn;
441 const char *getCommentString() const {
442 return CommentString;
444 const char *getLabelSuffix() const {
447 const char *getGlobalPrefix() const {
450 const char *getPrivateGlobalPrefix() const {
451 return PrivateGlobalPrefix;
453 const char *getLinkerPrivateGlobalPrefix() const {
454 return LinkerPrivateGlobalPrefix;
456 const char *getInlineAsmStart() const {
457 return InlineAsmStart;
459 const char *getInlineAsmEnd() const {
462 const char *getCode16Directive() const {
463 return Code16Directive;
465 const char *getCode32Directive() const {
466 return Code32Directive;
468 const char *getCode64Directive() const {
469 return Code64Directive;
471 unsigned getAssemblerDialect() const {
472 return AssemblerDialect;
474 bool doesAllowQuotesInName() const {
475 return AllowQuotesInName;
477 bool doesAllowNameToStartWithDigit() const {
478 return AllowNameToStartWithDigit;
480 bool doesAllowPeriodsInName() const {
481 return AllowPeriodsInName;
483 const char *getZeroDirective() const {
484 return ZeroDirective;
486 const char *getAsciiDirective() const {
487 return AsciiDirective;
489 const char *getAscizDirective() const {
490 return AscizDirective;
492 const char *getAlignDirective() const {
493 return AlignDirective;
495 bool getAlignmentIsInBytes() const {
496 return AlignmentIsInBytes;
498 unsigned getTextAlignFillValue() const {
499 return TextAlignFillValue;
501 const char *getGlobalDirective() const {
502 return GlobalDirective;
504 const char *getExternDirective() const {
505 return ExternDirective;
507 bool hasSetDirective() const { return HasSetDirective; }
508 bool hasAggressiveSymbolFolding() const {
509 return HasAggressiveSymbolFolding;
511 LCOMM::LCOMMType getLCOMMDirectiveType() const {
512 return LCOMMDirectiveType;
514 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
515 bool getCOMMDirectiveAlignmentIsInBytes() const {
516 return COMMDirectiveAlignmentIsInBytes;
518 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
519 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
520 bool hasSymbolResolver() const { return HasSymbolResolver; }
521 const char *getWeakRefDirective() const { return WeakRefDirective; }
522 const char *getWeakDefDirective() const { return WeakDefDirective; }
523 const char *getLinkOnceDirective() const { return LinkOnceDirective; }
525 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
526 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
527 return HiddenDeclarationVisibilityAttr;
529 MCSymbolAttr getProtectedVisibilityAttr() const {
530 return ProtectedVisibilityAttr;
532 bool hasLEB128() const {
535 bool doesSupportDebugInformation() const {
536 return SupportsDebugInformation;
538 bool doesSupportExceptionHandling() const {
539 return ExceptionsType != ExceptionHandling::None;
541 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
542 return ExceptionsType;
544 bool isExceptionHandlingDwarf() const {
546 (ExceptionsType == ExceptionHandling::DwarfCFI ||
547 ExceptionsType == ExceptionHandling::ARM ||
548 ExceptionsType == ExceptionHandling::Win64);
550 bool doesDwarfUsesInlineInfoSection() const {
551 return DwarfUsesInlineInfoSection;
553 const char *getDwarfSectionOffsetDirective() const {
554 return DwarfSectionOffsetDirective;
556 bool doesDwarfRequireRelocationForSectionOffset() const {
557 return DwarfRequiresRelocationForSectionOffset;
559 bool doesDwarfUsesLabelOffsetForRanges() const {
560 return DwarfUsesLabelOffsetForRanges;
562 bool doesDwarfUseRelocationsForStringPool() const {
563 return DwarfUsesRelocationsForStringPool;
565 bool useDwarfRegNumForCFI() const {
566 return DwarfRegNumForCFI;
568 const char *const *getAsmCBE() const {
572 void addInitialFrameState(MCSymbol *label, const MachineLocation &D,
573 const MachineLocation &S) {
574 InitialFrameState.push_back(MachineMove(label, D, S));
576 const std::vector<MachineMove> &getInitialFrameState() const {
577 return InitialFrameState;