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/MCDwarf.h"
21 #include "llvm/MC/MachineLocation.h"
32 namespace ExceptionHandling {
33 enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
37 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
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 /// CalleeSaveStackSlotSize - Size of the stack slot reserved for
53 /// callee-saved registers, in bytes.
54 /// Default is same as pointer size.
55 unsigned CalleeSaveStackSlotSize;
57 /// IsLittleEndian - True if target is little endian.
61 /// StackGrowsUp - True if target stack grow up.
65 /// HasSubsectionsViaSymbols - True if this target has the MachO
66 /// .subsections_via_symbols directive.
67 bool HasSubsectionsViaSymbols; // Default is false.
69 /// HasMachoZeroFillDirective - True if this is a MachO target that supports
70 /// the macho-specific .zerofill directive for emitting BSS Symbols.
71 bool HasMachoZeroFillDirective; // Default is false.
73 /// HasMachoTBSSDirective - True if this is a MachO target that supports
74 /// the macho-specific .tbss directive for emitting thread local BSS Symbols
75 bool HasMachoTBSSDirective; // Default is false.
77 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
78 /// emit a ".reference .constructors_used" or ".reference .destructors_used"
79 /// directive after the a static ctor/dtor list. This directive is only
80 /// emitted in Static relocation model.
81 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
83 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and
84 /// requires that the debug_line section be of a minimum size. In practice
85 /// such a linker requires a non empty line sequence if a file is present.
86 bool LinkerRequiresNonEmptyDwarfLines; // Default to false.
88 /// MaxInstLength - This is the maximum possible length of an instruction,
89 /// which is needed to compute the size of an inline asm.
90 unsigned MaxInstLength; // Defaults to 4.
92 /// MinInstAlignment - Every possible instruction length is a multiple of
93 /// this value. Factored out in .debug_frame and .debug_line.
94 unsigned MinInstAlignment; // Defaults to 1.
96 /// DollarIsPC - The '$' token, when not referencing an identifier or
97 /// constant, refers to the current PC.
98 bool DollarIsPC; // Defaults to false.
100 /// SeparatorString - This string, if specified, is used to separate
101 /// instructions from each other when on the same line.
102 const char *SeparatorString; // Defaults to ';'
104 /// CommentColumn - This indicates the comment num (zero-based) at
105 /// which asm comments should be printed.
106 unsigned CommentColumn; // Defaults to 40
108 /// CommentString - This indicates the comment character used by the
110 const char *CommentString; // Defaults to "#"
112 /// LabelSuffix - This is appended to emitted labels.
113 const char *LabelSuffix; // Defaults to ":"
115 /// LabelSuffix - This is appended to emitted labels.
116 const char *DebugLabelSuffix; // Defaults to ":"
118 /// If this is set to anything other than '\0', it is prepended
119 /// onto all global symbols. This is often used for '_'.
120 char GlobalPrefix; // Defaults to '\0'
122 /// This prefix is used for globals like constant pool entries that are
123 /// completely private to the .s file and should not have names in the .o
125 const char *PrivateGlobalPrefix; // Defaults to "L"
127 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
128 /// be passed through the assembler but be removed by the linker. This
129 /// is "l" on Darwin, currently used for some ObjC metadata.
130 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
132 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
133 /// emit before and after an inline assembly statement.
134 const char *InlineAsmStart; // Defaults to "#APP\n"
135 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
137 /// Code16Directive, Code32Directive, Code64Directive - These are assembly
138 /// directives that tells the assembler to interpret the following
139 /// instructions differently.
140 const char *Code16Directive; // Defaults to ".code16"
141 const char *Code32Directive; // Defaults to ".code32"
142 const char *Code64Directive; // Defaults to ".code64"
144 /// AssemblerDialect - Which dialect of an assembler variant to use.
145 unsigned AssemblerDialect; // Defaults to 0
147 /// \brief This is true if the assembler allows @ characters in symbol
148 /// names. Defaults to false.
151 /// UseDataRegionDirectives - This is true if data region markers should
152 /// be printed as ".data_region/.end_data_region" directives. If false,
153 /// use "$d/$a" labels instead.
154 bool UseDataRegionDirectives;
156 //===--- Data Emission Directives -------------------------------------===//
158 /// ZeroDirective - this should be set to the directive used to get some
159 /// number of zero bytes emitted to the current section. Common cases are
160 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
161 /// Data*bitsDirective's will be used to emit zero bytes.
162 const char *ZeroDirective; // Defaults to "\t.zero\t"
164 /// AsciiDirective - This directive allows emission of an ascii string with
165 /// the standard C escape characters embedded into it.
166 const char *AsciiDirective; // Defaults to "\t.ascii\t"
168 /// AscizDirective - If not null, this allows for special handling of
169 /// zero terminated strings on this target. This is commonly supported as
170 /// ".asciz". If a target doesn't support this, it can be set to null.
171 const char *AscizDirective; // Defaults to "\t.asciz\t"
173 /// DataDirectives - These directives are used to output some unit of
174 /// integer data to the current section. If a data directive is set to
175 /// null, smaller data directives will be used to emit the large sizes.
176 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
177 const char *Data16bitsDirective; // Defaults to "\t.short\t"
178 const char *Data32bitsDirective; // Defaults to "\t.long\t"
179 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
181 /// GPRel64Directive - if non-null, a directive that is used to emit a word
182 /// which should be relocated as a 64-bit GP-relative offset, e.g. .gpdword
184 const char *GPRel64Directive; // Defaults to NULL.
186 /// GPRel32Directive - if non-null, a directive that is used to emit a word
187 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword
188 /// on Mips or .gprel32 on Alpha.
189 const char *GPRel32Directive; // Defaults to NULL.
191 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun
192 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
193 /// normal ELF syntax (,"a,w") in .section directives.
194 bool SunStyleELFSectionSwitchSyntax; // Defaults to false.
196 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
197 /// '.section' directive before the '.bss' one. It's used for PPC/Linux
198 /// which doesn't support the '.bss' directive only.
199 bool UsesELFSectionDirectiveForBSS; // Defaults to false.
201 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft
202 /// style mangling for functions with X86_StdCall/X86_FastCall calling
204 bool HasMicrosoftFastStdCallMangling; // Defaults to false.
206 bool NeedsDwarfSectionOffsetDirective;
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 /// HasSetDirective - True if the assembler supports the .set directive.
232 bool HasSetDirective; // Defaults to true.
234 /// HasAggressiveSymbolFolding - False if the assembler requires that we use
239 bool HasAggressiveSymbolFolding; // Defaults to true.
241 /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional
242 /// alignment is to be specified in bytes instead of log2(n).
243 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true;
245 /// LCOMMDirectiveAlignment - Describes if the .lcomm directive for the
246 /// target supports an alignment argument and how it is interpreted.
247 LCOMM::LCOMMType LCOMMDirectiveAlignmentType; // Defaults to NoAlignment.
249 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
250 /// directives, this is true for most ELF targets.
251 bool HasDotTypeDotSizeDirective; // Defaults to true.
253 /// HasSingleParameterDotFile - True if the target has a single parameter
254 /// .file directive, this is true for ELF targets.
255 bool HasSingleParameterDotFile; // Defaults to true.
257 /// hasIdentDirective - True if the target has a .ident directive, this is
258 /// true for ELF targets.
259 bool HasIdentDirective; // Defaults to false.
261 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
263 bool HasNoDeadStrip; // Defaults to false.
265 /// WeakRefDirective - This directive, if non-null, is used to declare a
266 /// global as being a weak undefined symbol.
267 const char *WeakRefDirective; // Defaults to NULL.
269 /// True if we have a directive to declare a global as being a weak
271 bool HasWeakDefDirective; // Defaults to false.
273 /// True if we have a .linkonce directive. This is used on cygwin/mingw.
274 bool HasLinkOnceDirective; // Defaults to false.
276 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to
277 /// declare a symbol as having hidden visibility.
278 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden.
280 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid,
281 /// is used to declare an undefined symbol as having hidden visibility.
282 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden.
285 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used
286 /// to declare a symbol as having protected visibility.
287 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected
289 //===--- Dwarf Emission Directives -----------------------------------===//
291 /// HasLEB128 - True if target asm supports leb128 directives.
292 bool HasLEB128; // Defaults to false.
294 /// SupportsDebugInformation - True if target supports emission of debugging
296 bool SupportsDebugInformation; // Defaults to false.
298 /// SupportsExceptionHandling - True if target supports exception handling.
299 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None
301 /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally
302 /// uses relocations for references to other .debug_* sections.
303 bool DwarfUsesRelocationsAcrossSections;
305 /// DwarfRegNumForCFI - True if dwarf register numbers are printed
306 /// instead of symbolic register names in .cfi_* directives.
307 bool DwarfRegNumForCFI; // Defaults to false;
309 //===--- Prologue State ----------------------------------------------===//
311 std::vector<MCCFIInstruction> InitialFrameState;
314 explicit MCAsmInfo();
315 virtual ~MCAsmInfo();
317 // FIXME: move these methods to DwarfPrinter when the JIT stops using them.
318 static unsigned getSLEB128Size(int64_t Value);
319 static unsigned getULEB128Size(uint64_t Value);
321 /// getPointerSize - Get the pointer size in bytes.
322 unsigned getPointerSize() const {
326 /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot
328 unsigned getCalleeSaveStackSlotSize() const {
329 return CalleeSaveStackSlotSize;
332 /// isLittleEndian - True if the target is little endian.
333 bool isLittleEndian() const {
334 return IsLittleEndian;
337 /// isStackGrowthDirectionUp - True if target stack grow up.
338 bool isStackGrowthDirectionUp() const {
342 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
344 // Data directive accessors.
346 const char *getData8bitsDirective() const {
347 return Data8bitsDirective;
349 const char *getData16bitsDirective() const {
350 return Data16bitsDirective;
352 const char *getData32bitsDirective() const {
353 return Data32bitsDirective;
355 const char *getData64bitsDirective() const {
356 return Data64bitsDirective;
358 const char *getGPRel64Directive() const { return GPRel64Directive; }
359 const char *getGPRel32Directive() const { return GPRel32Directive; }
361 /// getNonexecutableStackSection - Targets can implement this method to
362 /// specify a section to switch to if the translation unit doesn't have any
363 /// trampolines that require an executable stack.
364 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{
368 virtual const MCExpr *
369 getExprForPersonalitySymbol(const MCSymbol *Sym,
371 MCStreamer &Streamer) const;
374 getExprForFDESymbol(const MCSymbol *Sym,
376 MCStreamer &Streamer) const;
378 bool usesSunStyleELFSectionSwitchSyntax() const {
379 return SunStyleELFSectionSwitchSyntax;
382 bool usesELFSectionDirectiveForBSS() const {
383 return UsesELFSectionDirectiveForBSS;
386 bool hasMicrosoftFastStdCallMangling() const {
387 return HasMicrosoftFastStdCallMangling;
390 bool needsDwarfSectionOffsetDirective() const {
391 return NeedsDwarfSectionOffsetDirective;
396 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
397 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
398 bool hasStaticCtorDtorReferenceInStaticMode() const {
399 return HasStaticCtorDtorReferenceInStaticMode;
401 bool getLinkerRequiresNonEmptyDwarfLines() const {
402 return LinkerRequiresNonEmptyDwarfLines;
404 unsigned getMaxInstLength() const {
405 return MaxInstLength;
407 unsigned getMinInstAlignment() const {
408 return MinInstAlignment;
410 bool getDollarIsPC() 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 {
426 const char *getDebugLabelSuffix() const {
427 return DebugLabelSuffix;
430 char getGlobalPrefix() const {
433 const char *getPrivateGlobalPrefix() const {
434 return PrivateGlobalPrefix;
436 const char *getLinkerPrivateGlobalPrefix() const {
437 return LinkerPrivateGlobalPrefix;
439 const char *getInlineAsmStart() const {
440 return InlineAsmStart;
442 const char *getInlineAsmEnd() const {
445 const char *getCode16Directive() const {
446 return Code16Directive;
448 const char *getCode32Directive() const {
449 return Code32Directive;
451 const char *getCode64Directive() const {
452 return Code64Directive;
454 unsigned getAssemblerDialect() const {
455 return AssemblerDialect;
457 bool doesAllowAtInName() const {
458 return AllowAtInName;
460 bool doesSupportDataRegionDirectives() const {
461 return UseDataRegionDirectives;
463 const char *getZeroDirective() const {
464 return ZeroDirective;
466 const char *getAsciiDirective() const {
467 return AsciiDirective;
469 const char *getAscizDirective() const {
470 return AscizDirective;
472 const char *getAlignDirective() const {
473 return AlignDirective;
475 bool getAlignmentIsInBytes() const {
476 return AlignmentIsInBytes;
478 unsigned getTextAlignFillValue() const {
479 return TextAlignFillValue;
481 const char *getGlobalDirective() const {
482 return GlobalDirective;
484 bool hasSetDirective() const { return HasSetDirective; }
485 bool hasAggressiveSymbolFolding() const {
486 return HasAggressiveSymbolFolding;
488 bool getCOMMDirectiveAlignmentIsInBytes() const {
489 return COMMDirectiveAlignmentIsInBytes;
491 LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
492 return LCOMMDirectiveAlignmentType;
494 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
495 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
496 bool hasIdentDirective() const { return HasIdentDirective; }
497 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
498 const char *getWeakRefDirective() const { return WeakRefDirective; }
499 bool hasWeakDefDirective() const { return HasWeakDefDirective; }
500 bool hasLinkOnceDirective() const { return HasLinkOnceDirective; }
502 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;}
503 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
504 return HiddenDeclarationVisibilityAttr;
506 MCSymbolAttr getProtectedVisibilityAttr() const {
507 return ProtectedVisibilityAttr;
509 bool hasLEB128() const {
512 bool doesSupportDebugInformation() const {
513 return SupportsDebugInformation;
515 bool doesSupportExceptionHandling() const {
516 return ExceptionsType != ExceptionHandling::None;
518 ExceptionHandling::ExceptionsType getExceptionHandlingType() const {
519 return ExceptionsType;
521 bool isExceptionHandlingDwarf() const {
523 (ExceptionsType == ExceptionHandling::DwarfCFI ||
524 ExceptionsType == ExceptionHandling::ARM ||
525 ExceptionsType == ExceptionHandling::Win64);
527 bool doesDwarfUseRelocationsAcrossSections() const {
528 return DwarfUsesRelocationsAcrossSections;
530 bool useDwarfRegNumForCFI() const {
531 return DwarfRegNumForCFI;
534 void addInitialFrameState(const MCCFIInstruction &Inst) {
535 InitialFrameState.push_back(Inst);
538 const std::vector<MCCFIInstruction> &getInitialFrameState() const {
539 return InitialFrameState;