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"
33 enum class EncodingType {
35 Alpha, /// Windows Alpha
36 Alpha64, /// Windows AXP64
37 ARM, /// Windows NT (Windows on ARM)
38 CE, /// Windows CE ARM, PowerPC, SH3, SH4
39 Itanium, /// Windows x64, Windows Itanium (IA-64)
40 X86, /// Windows x86, uses no CFI, just EH tables
45 enum class ExceptionHandling {
46 None, /// No exception support
47 DwarfCFI, /// DWARF-like instruction based exceptions
48 SjLj, /// setjmp/longjmp based exceptions
50 WinEH, /// Windows Exception Handling
54 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
57 /// This class is intended to be used as a base class for asm
58 /// properties and features specific to the target.
61 //===------------------------------------------------------------------===//
62 // Properties to be set by the target writer, used to configure asm printer.
65 /// Pointer size in bytes. Default is 4.
68 /// Size of the stack slot reserved for callee-saved registers, in bytes.
69 /// Default is same as pointer size.
70 unsigned CalleeSaveStackSlotSize;
72 /// True if target is little endian. Default is true.
75 /// True if target stack grow up. Default is false.
78 /// True if this target has the MachO .subsections_via_symbols directive.
80 bool HasSubsectionsViaSymbols;
82 /// True if this is a MachO target that supports the macho-specific .zerofill
83 /// directive for emitting BSS Symbols. Default is false.
84 bool HasMachoZeroFillDirective;
86 /// True if this is a MachO target that supports the macho-specific .tbss
87 /// directive for emitting thread local BSS Symbols. Default is false.
88 bool HasMachoTBSSDirective;
90 /// True if the compiler should emit a ".reference .constructors_used" or
91 /// ".reference .destructors_used" directive after the static ctor/dtor
92 /// list. This directive is only emitted in Static relocation model. Default
94 bool HasStaticCtorDtorReferenceInStaticMode;
96 /// This is the maximum possible length of an instruction, which is needed to
97 /// compute the size of an inline asm. Defaults to 4.
98 unsigned MaxInstLength;
100 /// Every possible instruction length is a multiple of this value. Factored
101 /// out in .debug_frame and .debug_line. Defaults to 1.
102 unsigned MinInstAlignment;
104 /// The '$' token, when not referencing an identifier or constant, refers to
105 /// the current PC. Defaults to false.
108 /// This string, if specified, is used to separate instructions from each
109 /// other when on the same line. Defaults to ';'
110 const char *SeparatorString;
112 /// This indicates the comment character used by the assembler. Defaults to
114 const char *CommentString;
116 /// This is appended to emitted labels. Defaults to ":"
117 const char *LabelSuffix;
119 // Print the EH begin symbol with an assignment. Defaults to false.
120 bool UseAssignmentForEHBegin;
122 // Do we need to create a local symbol for .size?
123 bool NeedsLocalForSize;
125 /// This prefix is used for globals like constant pool entries that are
126 /// completely private to the .s file and should not have names in the .o
127 /// file. Defaults to "L"
128 const char *PrivateGlobalPrefix;
130 /// This prefix is used for labels for basic blocks. Defaults to the same as
131 /// PrivateGlobalPrefix.
132 const char *PrivateLabelPrefix;
134 /// This prefix is used for symbols that should be passed through the
135 /// assembler but be removed by the linker. This is 'l' on Darwin, currently
136 /// used for some ObjC metadata. The default of "" meast that for this system
137 /// a plain private symbol should be used. Defaults to "".
138 const char *LinkerPrivateGlobalPrefix;
140 /// If these are nonempty, they contain a directive to emit before and after
141 /// an inline assembly statement. Defaults to "#APP\n", "#NO_APP\n"
142 const char *InlineAsmStart;
143 const char *InlineAsmEnd;
145 /// These are assembly directives that tells the assembler to interpret the
146 /// following instructions differently. Defaults to ".code16", ".code32",
148 const char *Code16Directive;
149 const char *Code32Directive;
150 const char *Code64Directive;
152 /// Which dialect of an assembler variant to use. Defaults to 0
153 unsigned AssemblerDialect;
155 /// This is true if the assembler allows @ characters in symbol names.
156 /// Defaults to false.
159 /// This is true if data region markers should be printed as
160 /// ".data_region/.end_data_region" directives. If false, use "$d/$a" labels
162 bool UseDataRegionDirectives;
164 //===--- Data Emission Directives -------------------------------------===//
166 /// This should be set to the directive used to get some number of zero bytes
167 /// emitted to the current section. Common cases are "\t.zero\t" and
168 /// "\t.space\t". If this is set to null, the Data*bitsDirective's will be
169 /// used to emit zero bytes. Defaults to "\t.zero\t"
170 const char *ZeroDirective;
172 /// This directive allows emission of an ascii string with the standard C
173 /// escape characters embedded into it. Defaults to "\t.ascii\t"
174 const char *AsciiDirective;
176 /// If not null, this allows for special handling of zero terminated strings
177 /// on this target. This is commonly supported as ".asciz". If a target
178 /// doesn't support this, it can be set to null. Defaults to "\t.asciz\t"
179 const char *AscizDirective;
181 /// These directives are used to output some unit of integer data to the
182 /// current section. If a data directive is set to null, smaller data
183 /// directives will be used to emit the large sizes. Defaults to "\t.byte\t",
184 /// "\t.short\t", "\t.long\t", "\t.quad\t"
185 const char *Data8bitsDirective;
186 const char *Data16bitsDirective;
187 const char *Data32bitsDirective;
188 const char *Data64bitsDirective;
190 /// If non-null, a directive that is used to emit a word which should be
191 /// relocated as a 64-bit GP-relative offset, e.g. .gpdword on Mips. Defaults
193 const char *GPRel64Directive;
195 /// If non-null, a directive that is used to emit a word which should be
196 /// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
197 /// on Alpha. Defaults to NULL.
198 const char *GPRel32Directive;
200 /// This is true if this target uses "Sun Style" syntax for section switching
201 /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
202 /// .section directives. Defaults to false.
203 bool SunStyleELFSectionSwitchSyntax;
205 /// This is true if this target uses ELF '.section' directive before the
206 /// '.bss' one. It's used for PPC/Linux which doesn't support the '.bss'
207 /// directive only. Defaults to false.
208 bool UsesELFSectionDirectiveForBSS;
210 bool NeedsDwarfSectionOffsetDirective;
212 //===--- Alignment Information ----------------------------------------===//
214 /// If this is true (the default) then the asmprinter emits ".align N"
215 /// directives, where N is the number of bytes to align to. Otherwise, it
216 /// emits ".align log2(N)", e.g. 3 to align to an 8 byte boundary. Defaults
218 bool AlignmentIsInBytes;
220 /// If non-zero, this is used to fill the executable space created as the
221 /// result of a alignment directive. Defaults to 0
222 unsigned TextAlignFillValue;
224 //===--- Global Variable Emission Directives --------------------------===//
226 /// This is the directive used to declare a global entity. Defaults to
228 const char *GlobalDirective;
230 /// True if the expression
232 /// uses a relocation but it can be suppressed by writing
235 bool SetDirectiveSuppressesReloc;
237 /// False if the assembler requires that we use
249 /// Defaults to true.
250 bool HasAggressiveSymbolFolding;
252 /// True is .comm's and .lcomms optional alignment is to be specified in bytes
253 /// instead of log2(n). Defaults to true.
254 bool COMMDirectiveAlignmentIsInBytes;
256 /// Describes if the .lcomm directive for the target supports an alignment
257 /// argument and how it is interpreted. Defaults to NoAlignment.
258 LCOMM::LCOMMType LCOMMDirectiveAlignmentType;
260 // True if the target allows .align directives on functions. This is true for
261 // most targets, so defaults to true.
262 bool HasFunctionAlignment;
264 /// True if the target has .type and .size directives, this is true for most
265 /// ELF targets. Defaults to true.
266 bool HasDotTypeDotSizeDirective;
268 /// True if the target has a single parameter .file directive, this is true
269 /// for ELF targets. Defaults to true.
270 bool HasSingleParameterDotFile;
272 /// True if the target has a .ident directive, this is true for ELF targets.
273 /// Defaults to false.
274 bool HasIdentDirective;
276 /// True if this target supports the MachO .no_dead_strip directive. Defaults
280 /// Used to declare a global as being a weak symbol. Defaults to ".weak".
281 const char *WeakDirective;
283 /// This directive, if non-null, is used to declare a global as being a weak
284 /// undefined symbol. Defaults to NULL.
285 const char *WeakRefDirective;
287 /// True if we have a directive to declare a global as being a weak defined
288 /// symbol. Defaults to false.
289 bool HasWeakDefDirective;
291 /// True if we have a directive to declare a global as being a weak defined
292 /// symbol that can be hidden (unexported). Defaults to false.
293 bool HasWeakDefCanBeHiddenDirective;
295 /// True if we have a .linkonce directive. This is used on cygwin/mingw.
296 /// Defaults to false.
297 bool HasLinkOnceDirective;
299 /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
300 /// hidden visibility. Defaults to MCSA_Hidden.
301 MCSymbolAttr HiddenVisibilityAttr;
303 /// This attribute, if not MCSA_Invalid, is used to declare an undefined
304 /// symbol as having hidden visibility. Defaults to MCSA_Hidden.
305 MCSymbolAttr HiddenDeclarationVisibilityAttr;
307 /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
308 /// protected visibility. Defaults to MCSA_Protected
309 MCSymbolAttr ProtectedVisibilityAttr;
311 //===--- Dwarf Emission Directives -----------------------------------===//
313 /// True if target supports emission of debugging information. Defaults to
315 bool SupportsDebugInformation;
317 /// Exception handling format for the target. Defaults to None.
318 ExceptionHandling ExceptionsType;
320 /// Windows exception handling data (.pdata) encoding. Defaults to Invalid.
321 WinEH::EncodingType WinEHEncodingType;
323 /// True if Dwarf2 output generally uses relocations for references to other
324 /// .debug_* sections.
325 bool DwarfUsesRelocationsAcrossSections;
327 /// True if DWARF FDE symbol reference relocations should be replaced by an
328 /// absolute difference.
329 bool DwarfFDESymbolsUseAbsDiff;
331 /// True if dwarf register numbers are printed instead of symbolic register
332 /// names in .cfi_* directives. Defaults to false.
333 bool DwarfRegNumForCFI;
335 /// True if target uses parens to indicate the symbol variant instead of @.
336 /// For example, foo(plt) instead of foo@plt. Defaults to false.
337 bool UseParensForSymbolVariant;
339 //===--- Prologue State ----------------------------------------------===//
341 std::vector<MCCFIInstruction> InitialFrameState;
343 //===--- Integrated Assembler Information ----------------------------===//
345 /// Should we use the integrated assembler?
346 /// The integrated assembler should be enabled by default (by the
347 /// constructors) when failing to parse a valid piece of assembly (inline
348 /// or otherwise) is considered a bug. It may then be overridden after
349 /// construction (see LLVMTargetMachine::initAsmInfo()).
350 bool UseIntegratedAssembler;
352 /// Compress DWARF debug sections. Defaults to false.
353 bool CompressDebugSections;
355 /// True if the integrated assembler should interpret 'a >> b' constant
356 /// expressions as logical rather than arithmetic.
360 explicit MCAsmInfo();
361 virtual ~MCAsmInfo();
363 /// Get the pointer size in bytes.
364 unsigned getPointerSize() const { return PointerSize; }
366 /// Get the callee-saved register stack slot
368 unsigned getCalleeSaveStackSlotSize() const {
369 return CalleeSaveStackSlotSize;
372 /// True if the target is little endian.
373 bool isLittleEndian() const { return IsLittleEndian; }
375 /// True if target stack grow up.
376 bool isStackGrowthDirectionUp() const { return StackGrowsUp; }
378 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
380 // Data directive accessors.
382 const char *getData8bitsDirective() const { return Data8bitsDirective; }
383 const char *getData16bitsDirective() const { return Data16bitsDirective; }
384 const char *getData32bitsDirective() const { return Data32bitsDirective; }
385 const char *getData64bitsDirective() const { return Data64bitsDirective; }
386 const char *getGPRel64Directive() const { return GPRel64Directive; }
387 const char *getGPRel32Directive() const { return GPRel32Directive; }
389 /// Targets can implement this method to specify a section to switch to if the
390 /// translation unit doesn't have any trampolines that require an executable
392 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
396 /// \brief True if the section is atomized using the symbols in it.
397 /// This is false if the section is not atomized at all (most ELF sections) or
398 /// if it is atomized based on its contents (MachO' __TEXT,__cstring for
400 virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
402 virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
404 MCStreamer &Streamer) const;
406 virtual const MCExpr *getExprForFDESymbol(const MCSymbol *Sym,
408 MCStreamer &Streamer) const;
410 bool usesSunStyleELFSectionSwitchSyntax() const {
411 return SunStyleELFSectionSwitchSyntax;
414 bool usesELFSectionDirectiveForBSS() const {
415 return UsesELFSectionDirectiveForBSS;
418 bool needsDwarfSectionOffsetDirective() const {
419 return NeedsDwarfSectionOffsetDirective;
424 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
425 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
426 bool hasStaticCtorDtorReferenceInStaticMode() const {
427 return HasStaticCtorDtorReferenceInStaticMode;
429 unsigned getMaxInstLength() const { return MaxInstLength; }
430 unsigned getMinInstAlignment() const { return MinInstAlignment; }
431 bool getDollarIsPC() const { return DollarIsPC; }
432 const char *getSeparatorString() const { return SeparatorString; }
434 /// This indicates the column (zero-based) at which asm comments should be
436 unsigned getCommentColumn() const { return 40; }
438 const char *getCommentString() const { return CommentString; }
439 const char *getLabelSuffix() const { return LabelSuffix; }
441 bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
442 bool needsLocalForSize() const { return NeedsLocalForSize; }
443 const char *getPrivateGlobalPrefix() const { return PrivateGlobalPrefix; }
444 const char *getPrivateLabelPrefix() const { return PrivateLabelPrefix; }
445 bool hasLinkerPrivateGlobalPrefix() const {
446 return LinkerPrivateGlobalPrefix[0] != '\0';
448 const char *getLinkerPrivateGlobalPrefix() const {
449 if (hasLinkerPrivateGlobalPrefix())
450 return LinkerPrivateGlobalPrefix;
451 return getPrivateGlobalPrefix();
453 const char *getInlineAsmStart() const { return InlineAsmStart; }
454 const char *getInlineAsmEnd() const { return InlineAsmEnd; }
455 const char *getCode16Directive() const { return Code16Directive; }
456 const char *getCode32Directive() const { return Code32Directive; }
457 const char *getCode64Directive() const { return Code64Directive; }
458 unsigned getAssemblerDialect() const { return AssemblerDialect; }
459 bool doesAllowAtInName() const { return AllowAtInName; }
460 bool doesSupportDataRegionDirectives() const {
461 return UseDataRegionDirectives;
463 const char *getZeroDirective() const { return ZeroDirective; }
464 const char *getAsciiDirective() const { return AsciiDirective; }
465 const char *getAscizDirective() const { return AscizDirective; }
466 bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
467 unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
468 const char *getGlobalDirective() const { return GlobalDirective; }
469 bool doesSetDirectiveSuppressesReloc() const {
470 return SetDirectiveSuppressesReloc;
472 bool hasAggressiveSymbolFolding() const { return HasAggressiveSymbolFolding; }
473 bool getCOMMDirectiveAlignmentIsInBytes() const {
474 return COMMDirectiveAlignmentIsInBytes;
476 LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
477 return LCOMMDirectiveAlignmentType;
479 bool hasFunctionAlignment() const { return HasFunctionAlignment; }
480 bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
481 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
482 bool hasIdentDirective() const { return HasIdentDirective; }
483 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
484 const char *getWeakDirective() const { return WeakDirective; }
485 const char *getWeakRefDirective() const { return WeakRefDirective; }
486 bool hasWeakDefDirective() const { return HasWeakDefDirective; }
487 bool hasWeakDefCanBeHiddenDirective() const {
488 return HasWeakDefCanBeHiddenDirective;
490 bool hasLinkOnceDirective() const { return HasLinkOnceDirective; }
492 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr; }
493 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
494 return HiddenDeclarationVisibilityAttr;
496 MCSymbolAttr getProtectedVisibilityAttr() const {
497 return ProtectedVisibilityAttr;
499 bool doesSupportDebugInformation() const { return SupportsDebugInformation; }
500 bool doesSupportExceptionHandling() const {
501 return ExceptionsType != ExceptionHandling::None;
503 ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
504 WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
506 /// Returns true if the exception handling method for the platform uses call
507 /// frame information to unwind.
508 bool usesCFIForEH() const {
509 return (ExceptionsType == ExceptionHandling::DwarfCFI ||
510 ExceptionsType == ExceptionHandling::ARM || usesWindowsCFI());
513 bool usesWindowsCFI() const {
514 return ExceptionsType == ExceptionHandling::WinEH &&
515 (WinEHEncodingType != WinEH::EncodingType::Invalid &&
516 WinEHEncodingType != WinEH::EncodingType::X86);
519 bool doesDwarfUseRelocationsAcrossSections() const {
520 return DwarfUsesRelocationsAcrossSections;
522 bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
523 bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
524 bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; }
526 void addInitialFrameState(const MCCFIInstruction &Inst) {
527 InitialFrameState.push_back(Inst);
530 const std::vector<MCCFIInstruction> &getInitialFrameState() const {
531 return InitialFrameState;
534 /// Return true if assembly (inline or otherwise) should be parsed.
535 bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
537 /// Set whether assembly (inline or otherwise) should be parsed.
538 virtual void setUseIntegratedAssembler(bool Value) {
539 UseIntegratedAssembler = Value;
542 bool compressDebugSections() const { return CompressDebugSections; }
544 void setCompressDebugSections(bool CompressDebugSections) {
545 this->CompressDebugSections = CompressDebugSections;
548 bool shouldUseLogicalShr() const { return UseLogicalShr; }