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)
44 enum class ExceptionHandling {
45 None, /// No exception support
46 DwarfCFI, /// DWARF-like instruction based exceptions
47 SjLj, /// setjmp/longjmp based exceptions
49 ItaniumWinEH, /// Itanium EH built on Windows unwind info (.pdata and .xdata)
53 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
56 /// This class is intended to be used as a base class for asm
57 /// properties and features specific to the target.
60 //===------------------------------------------------------------------===//
61 // Properties to be set by the target writer, used to configure asm printer.
64 /// Pointer size in bytes. Default is 4.
67 /// Size of the stack slot reserved for callee-saved registers, in bytes.
68 /// Default is same as pointer size.
69 unsigned CalleeSaveStackSlotSize;
71 /// True if target is little endian. Default is true.
74 /// True if target stack grow up. Default is false.
77 /// True if this target has the MachO .subsections_via_symbols directive.
79 bool HasSubsectionsViaSymbols;
81 /// True if this is a MachO target that supports the macho-specific .zerofill
82 /// directive for emitting BSS Symbols. Default is false.
83 bool HasMachoZeroFillDirective;
85 /// True if this is a MachO target that supports the macho-specific .tbss
86 /// directive for emitting thread local BSS Symbols. Default is false.
87 bool HasMachoTBSSDirective;
89 /// True if the compiler should emit a ".reference .constructors_used" or
90 /// ".reference .destructors_used" directive after the static ctor/dtor
91 /// list. This directive is only emitted in Static relocation model. Default
93 bool HasStaticCtorDtorReferenceInStaticMode;
95 /// This is the maximum possible length of an instruction, which is needed to
96 /// compute the size of an inline asm. Defaults to 4.
97 unsigned MaxInstLength;
99 /// Every possible instruction length is a multiple of this value. Factored
100 /// out in .debug_frame and .debug_line. Defaults to 1.
101 unsigned MinInstAlignment;
103 /// The '$' token, when not referencing an identifier or constant, refers to
104 /// the current PC. Defaults to false.
107 /// This string, if specified, is used to separate instructions from each
108 /// other when on the same line. Defaults to ';'
109 const char *SeparatorString;
111 /// This indicates the comment character used by the assembler. Defaults to
113 const char *CommentString;
115 /// This is appended to emitted labels. Defaults to ":"
116 const char *LabelSuffix;
118 // Print the EH begin symbol with an assignment. Defaults to false.
119 bool UseAssignmentForEHBegin;
121 /// This prefix is used for globals like constant pool entries that are
122 /// completely private to the .s file and should not have names in the .o
123 /// file. Defaults to "L"
124 const char *PrivateGlobalPrefix;
126 /// This prefix is used for symbols that should be passed through the
127 /// assembler but be removed by the linker. This is 'l' on Darwin, currently
128 /// used for some ObjC metadata. The default of "" meast that for this system
129 /// a plain private symbol should be used. Defaults to "".
130 const char *LinkerPrivateGlobalPrefix;
132 /// If these are nonempty, they contain a directive to emit before and after
133 /// an inline assembly statement. Defaults to "#APP\n", "#NO_APP\n"
134 const char *InlineAsmStart;
135 const char *InlineAsmEnd;
137 /// These are assembly directives that tells the assembler to interpret the
138 /// following instructions differently. Defaults to ".code16", ".code32",
140 const char *Code16Directive;
141 const char *Code32Directive;
142 const char *Code64Directive;
144 /// Which dialect of an assembler variant to use. Defaults to 0
145 unsigned AssemblerDialect;
147 /// This is true if the assembler allows @ characters in symbol names.
148 /// Defaults to false.
151 /// This is true if data region markers should be printed as
152 /// ".data_region/.end_data_region" directives. If false, use "$d/$a" labels
154 bool UseDataRegionDirectives;
156 //===--- Data Emission Directives -------------------------------------===//
158 /// This should be set to the directive used to get some number of zero bytes
159 /// emitted to the current section. Common cases are "\t.zero\t" and
160 /// "\t.space\t". If this is set to null, the Data*bitsDirective's will be
161 /// used to emit zero bytes. Defaults to "\t.zero\t"
162 const char *ZeroDirective;
164 /// This directive allows emission of an ascii string with the standard C
165 /// escape characters embedded into it. Defaults to "\t.ascii\t"
166 const char *AsciiDirective;
168 /// If not null, this allows for special handling of zero terminated strings
169 /// on this target. This is commonly supported as ".asciz". If a target
170 /// doesn't support this, it can be set to null. Defaults to "\t.asciz\t"
171 const char *AscizDirective;
173 /// These directives are used to output some unit of integer data to the
174 /// current section. If a data directive is set to null, smaller data
175 /// directives will be used to emit the large sizes. Defaults to "\t.byte\t",
176 /// "\t.short\t", "\t.long\t", "\t.quad\t"
177 const char *Data8bitsDirective;
178 const char *Data16bitsDirective;
179 const char *Data32bitsDirective;
180 const char *Data64bitsDirective;
182 /// If non-null, a directive that is used to emit a word which should be
183 /// relocated as a 64-bit GP-relative offset, e.g. .gpdword on Mips. Defaults
185 const char *GPRel64Directive;
187 /// If non-null, a directive that is used to emit a word which should be
188 /// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
189 /// on Alpha. Defaults to NULL.
190 const char *GPRel32Directive;
192 /// This is true if this target uses "Sun Style" syntax for section switching
193 /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
194 /// .section directives. Defaults to false.
195 bool SunStyleELFSectionSwitchSyntax;
197 /// This is true if this target uses ELF '.section' directive before the
198 /// '.bss' one. It's used for PPC/Linux which doesn't support the '.bss'
199 /// directive only. Defaults to false.
200 bool UsesELFSectionDirectiveForBSS;
202 bool NeedsDwarfSectionOffsetDirective;
204 //===--- Alignment Information ----------------------------------------===//
206 /// If this is true (the default) then the asmprinter emits ".align N"
207 /// directives, where N is the number of bytes to align to. Otherwise, it
208 /// emits ".align log2(N)", e.g. 3 to align to an 8 byte boundary. Defaults
210 bool AlignmentIsInBytes;
212 /// If non-zero, this is used to fill the executable space created as the
213 /// result of a alignment directive. Defaults to 0
214 unsigned TextAlignFillValue;
216 //===--- Global Variable Emission Directives --------------------------===//
218 /// This is the directive used to declare a global entity. Defaults to NULL.
219 const char *GlobalDirective;
221 /// True if the expression
223 /// uses an relocation but it can be supressed by writting
226 bool SetDirectiveSuppressesReloc;
228 /// False if the assembler requires that we use
240 /// Defaults to true.
241 bool HasAggressiveSymbolFolding;
243 /// True is .comm's and .lcomms optional alignment is to be specified in bytes
244 /// instead of log2(n). Defaults to true.
245 bool COMMDirectiveAlignmentIsInBytes;
247 /// Describes if the .lcomm directive for the target supports an alignment
248 /// argument and how it is interpreted. Defaults to NoAlignment.
249 LCOMM::LCOMMType LCOMMDirectiveAlignmentType;
251 /// True if the target has .type and .size directives, this is true for most
252 /// ELF targets. Defaults to true.
253 bool HasDotTypeDotSizeDirective;
255 /// True if the target has a single parameter .file directive, this is true
256 /// for ELF targets. Defaults to true.
257 bool HasSingleParameterDotFile;
259 /// True if the target has a .ident directive, this is true for ELF targets.
260 /// Defaults to false.
261 bool HasIdentDirective;
263 /// True if this target supports the MachO .no_dead_strip directive. Defaults
267 /// This directive, if non-null, is used to declare a global as being a weak
268 /// undefined symbol. Defaults to NULL.
269 const char *WeakRefDirective;
271 /// True if we have a directive to declare a global as being a weak defined
272 /// symbol. Defaults to false.
273 bool HasWeakDefDirective;
275 /// True if we have a directive to declare a global as being a weak defined
276 /// symbol that can be hidden (unexported). Defaults to false.
277 bool HasWeakDefCanBeHiddenDirective;
279 /// True if we have a .linkonce directive. This is used on cygwin/mingw.
280 /// Defaults to false.
281 bool HasLinkOnceDirective;
283 /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
284 /// hidden visibility. Defaults to MCSA_Hidden.
285 MCSymbolAttr HiddenVisibilityAttr;
287 /// This attribute, if not MCSA_Invalid, is used to declare an undefined
288 /// symbol as having hidden visibility. Defaults to MCSA_Hidden.
289 MCSymbolAttr HiddenDeclarationVisibilityAttr;
291 /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
292 /// protected visibility. Defaults to MCSA_Protected
293 MCSymbolAttr ProtectedVisibilityAttr;
295 //===--- Dwarf Emission Directives -----------------------------------===//
297 /// True if target supports emission of debugging information. Defaults to
299 bool SupportsDebugInformation;
301 /// Exception handling format for the target. Defaults to None.
302 ExceptionHandling ExceptionsType;
304 /// Windows exception handling data (.pdata) encoding. Defaults to Invalid.
305 WinEH::EncodingType WinEHEncodingType;
307 /// True if Dwarf2 output generally uses relocations for references to other
308 /// .debug_* sections.
309 bool DwarfUsesRelocationsAcrossSections;
311 /// True if DWARF FDE symbol reference relocations should be replaced by an
312 /// absolute difference.
313 bool DwarfFDESymbolsUseAbsDiff;
315 /// True if dwarf register numbers are printed instead of symbolic register
316 /// names in .cfi_* directives. Defaults to false.
317 bool DwarfRegNumForCFI;
319 /// True if target uses parens to indicate the symbol variant instead of @.
320 /// For example, foo(plt) instead of foo@plt. Defaults to false.
321 bool UseParensForSymbolVariant;
323 //===--- Prologue State ----------------------------------------------===//
325 std::vector<MCCFIInstruction> InitialFrameState;
327 //===--- Integrated Assembler State ----------------------------------===//
329 /// Should we use the integrated assembler?
330 /// The integrated assembler should be enabled by default (by the
331 /// constructors) when failing to parse a valid piece of assembly (inline
332 /// or otherwise) is considered a bug. It may then be overridden after
333 /// construction (see LLVMTargetMachine::initAsmInfo()).
334 bool UseIntegratedAssembler;
336 /// Compress DWARF debug sections. Defaults to false.
337 bool CompressDebugSections;
340 explicit MCAsmInfo();
341 virtual ~MCAsmInfo();
343 /// Get the pointer size in bytes.
344 unsigned getPointerSize() const { return PointerSize; }
346 /// Get the callee-saved register stack slot
348 unsigned getCalleeSaveStackSlotSize() const {
349 return CalleeSaveStackSlotSize;
352 /// True if the target is little endian.
353 bool isLittleEndian() const { return IsLittleEndian; }
355 /// True if target stack grow up.
356 bool isStackGrowthDirectionUp() const { return StackGrowsUp; }
358 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
360 // Data directive accessors.
362 const char *getData8bitsDirective() const { return Data8bitsDirective; }
363 const char *getData16bitsDirective() const { return Data16bitsDirective; }
364 const char *getData32bitsDirective() const { return Data32bitsDirective; }
365 const char *getData64bitsDirective() const { return Data64bitsDirective; }
366 const char *getGPRel64Directive() const { return GPRel64Directive; }
367 const char *getGPRel32Directive() const { return GPRel32Directive; }
369 /// Targets can implement this method to specify a section to switch to if the
370 /// translation unit doesn't have any trampolines that require an executable
372 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
376 virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
378 MCStreamer &Streamer) const;
380 virtual const MCExpr *getExprForFDESymbol(const MCSymbol *Sym,
382 MCStreamer &Streamer) const;
384 bool usesSunStyleELFSectionSwitchSyntax() const {
385 return SunStyleELFSectionSwitchSyntax;
388 bool usesELFSectionDirectiveForBSS() const {
389 return UsesELFSectionDirectiveForBSS;
392 bool needsDwarfSectionOffsetDirective() const {
393 return NeedsDwarfSectionOffsetDirective;
398 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
399 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
400 bool hasStaticCtorDtorReferenceInStaticMode() const {
401 return HasStaticCtorDtorReferenceInStaticMode;
403 unsigned getMaxInstLength() const { return MaxInstLength; }
404 unsigned getMinInstAlignment() const { return MinInstAlignment; }
405 bool getDollarIsPC() const { return DollarIsPC; }
406 const char *getSeparatorString() const { return SeparatorString; }
408 /// This indicates the column (zero-based) at which asm comments should be
410 unsigned getCommentColumn() const { return 40; }
412 const char *getCommentString() const { return CommentString; }
413 const char *getLabelSuffix() const { return LabelSuffix; }
415 bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
416 const char *getPrivateGlobalPrefix() const { return PrivateGlobalPrefix; }
417 bool hasLinkerPrivateGlobalPrefix() const {
418 return LinkerPrivateGlobalPrefix[0] != '\0';
420 const char *getLinkerPrivateGlobalPrefix() const {
421 if (hasLinkerPrivateGlobalPrefix())
422 return LinkerPrivateGlobalPrefix;
423 return getPrivateGlobalPrefix();
425 const char *getInlineAsmStart() const { return InlineAsmStart; }
426 const char *getInlineAsmEnd() const { return InlineAsmEnd; }
427 const char *getCode16Directive() const { return Code16Directive; }
428 const char *getCode32Directive() const { return Code32Directive; }
429 const char *getCode64Directive() const { return Code64Directive; }
430 unsigned getAssemblerDialect() const { return AssemblerDialect; }
431 bool doesAllowAtInName() const { return AllowAtInName; }
432 bool doesSupportDataRegionDirectives() const {
433 return UseDataRegionDirectives;
435 const char *getZeroDirective() const { return ZeroDirective; }
436 const char *getAsciiDirective() const { return AsciiDirective; }
437 const char *getAscizDirective() const { return AscizDirective; }
438 bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
439 unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
440 const char *getGlobalDirective() const { return GlobalDirective; }
441 bool doesSetDirectiveSuppressesReloc() const {
442 return SetDirectiveSuppressesReloc;
444 bool hasAggressiveSymbolFolding() const { return HasAggressiveSymbolFolding; }
445 bool getCOMMDirectiveAlignmentIsInBytes() const {
446 return COMMDirectiveAlignmentIsInBytes;
448 LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
449 return LCOMMDirectiveAlignmentType;
451 bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
452 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
453 bool hasIdentDirective() const { return HasIdentDirective; }
454 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
455 const char *getWeakRefDirective() const { return WeakRefDirective; }
456 bool hasWeakDefDirective() const { return HasWeakDefDirective; }
457 bool hasWeakDefCanBeHiddenDirective() const {
458 return HasWeakDefCanBeHiddenDirective;
460 bool hasLinkOnceDirective() const { return HasLinkOnceDirective; }
462 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr; }
463 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
464 return HiddenDeclarationVisibilityAttr;
466 MCSymbolAttr getProtectedVisibilityAttr() const {
467 return ProtectedVisibilityAttr;
469 bool doesSupportDebugInformation() const { return SupportsDebugInformation; }
470 bool doesSupportExceptionHandling() const {
471 return ExceptionsType != ExceptionHandling::None;
473 ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
474 WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
476 /// Return true if the exception handling type uses the language-specific data
477 /// area (LSDA) format specified by the Itanium C++ ABI.
478 bool usesItaniumLSDAForExceptions() const {
479 return (ExceptionsType == ExceptionHandling::DwarfCFI ||
480 ExceptionsType == ExceptionHandling::ARM ||
481 // This Windows EH type uses the Itanium LSDA encoding.
482 ExceptionsType == ExceptionHandling::ItaniumWinEH);
485 bool doesDwarfUseRelocationsAcrossSections() const {
486 return DwarfUsesRelocationsAcrossSections;
488 bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
489 bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
490 bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; }
492 void addInitialFrameState(const MCCFIInstruction &Inst) {
493 InitialFrameState.push_back(Inst);
496 const std::vector<MCCFIInstruction> &getInitialFrameState() const {
497 return InitialFrameState;
500 /// Return true if assembly (inline or otherwise) should be parsed.
501 bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
503 /// Set whether assembly (inline or otherwise) should be parsed.
504 virtual void setUseIntegratedAssembler(bool Value) {
505 UseIntegratedAssembler = Value;
508 bool compressDebugSections() const { return CompressDebugSections; }
510 void setCompressDebugSections(bool CompressDebugSections) {
511 this->CompressDebugSections = CompressDebugSections;