1 //===-- llvm/MC/MCAsmInfo.h - Asm info --------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a class to be used as the basis for target specific
10 // asm writers.  This class primarily takes care of global printing constants,
11 // which are used in very similar ways across all targets.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_MC_MCASMINFO_H
16 #define LLVM_MC_MCASMINFO_H
17 
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/MCDirectives.h"
20 #include "llvm/MC/MCTargetOptions.h"
21 #include <vector>
22 
23 namespace llvm {
24 
25 class MCContext;
26 class MCCFIInstruction;
27 class MCExpr;
28 class MCSection;
29 class MCStreamer;
30 class MCSubtargetInfo;
31 class MCSymbol;
32 
33 namespace WinEH {
34 
35 enum class EncodingType {
36   Invalid, /// Invalid
37   Alpha,   /// Windows Alpha
38   Alpha64, /// Windows AXP64
39   ARM,     /// Windows NT (Windows on ARM)
40   CE,      /// Windows CE ARM, PowerPC, SH3, SH4
41   Itanium, /// Windows x64, Windows Itanium (IA-64)
42   X86,     /// Windows x86, uses no CFI, just EH tables
43   MIPS = Alpha,
44 };
45 
46 } // end namespace WinEH
47 
48 namespace LCOMM {
49 
50 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
51 
52 } // end namespace LCOMM
53 
54 /// This class is intended to be used as a base class for asm
55 /// properties and features specific to the target.
56 class MCAsmInfo {
57 public:
58   /// Assembly character literal syntax types.
59   enum AsmCharLiteralSyntax {
60     ACLS_Unknown, /// Unknown; character literals not used by LLVM for this
61                   /// target.
62     ACLS_SingleQuotePrefix, /// The desired character is prefixed by a single
63                             /// quote, e.g., `'A`.
64   };
65 
66 protected:
67   //===------------------------------------------------------------------===//
68   // Properties to be set by the target writer, used to configure asm printer.
69   //
70 
71   /// Code pointer size in bytes.  Default is 4.
72   unsigned CodePointerSize = 4;
73 
74   /// Size of the stack slot reserved for callee-saved registers, in bytes.
75   /// Default is same as pointer size.
76   unsigned CalleeSaveStackSlotSize = 4;
77 
78   /// True if target is little endian.  Default is true.
79   bool IsLittleEndian = true;
80 
81   /// True if target stack grow up.  Default is false.
82   bool StackGrowsUp = false;
83 
84   /// True if this target has the MachO .subsections_via_symbols directive.
85   /// Default is false.
86   bool HasSubsectionsViaSymbols = false;
87 
88   /// True if this is a MachO target that supports the macho-specific .zerofill
89   /// directive for emitting BSS Symbols.  Default is false.
90   bool HasMachoZeroFillDirective = false;
91 
92   /// True if this is a MachO target that supports the macho-specific .tbss
93   /// directive for emitting thread local BSS Symbols.  Default is false.
94   bool HasMachoTBSSDirective = false;
95 
96   /// True if this is a non-GNU COFF target. The COFF port of the GNU linker
97   /// doesn't handle associative comdats in the way that we would like to use
98   /// them.
99   bool HasCOFFAssociativeComdats = false;
100 
101   /// True if this is a non-GNU COFF target. For GNU targets, we don't generate
102   /// constants into comdat sections.
103   bool HasCOFFComdatConstants = false;
104 
105   /// True if this is an XCOFF target that supports visibility attributes as
106   /// part of .global, .weak, .extern, and .comm. Default is false.
107   bool HasVisibilityOnlyWithLinkage = false;
108 
109   /// This is the maximum possible length of an instruction, which is needed to
110   /// compute the size of an inline asm.  Defaults to 4.
111   unsigned MaxInstLength = 4;
112 
113   /// Every possible instruction length is a multiple of this value.  Factored
114   /// out in .debug_frame and .debug_line.  Defaults to 1.
115   unsigned MinInstAlignment = 1;
116 
117   /// The '$' token, when not referencing an identifier or constant, refers to
118   /// the current PC.  Defaults to false.
119   bool DollarIsPC = false;
120 
121   /// Allow '.' token, when not referencing an identifier or constant, to refer
122   /// to the current PC. Defaults to true.
123   bool DotIsPC = true;
124 
125   /// Whether the '*' token refers to the current PC. This is used for the
126   /// HLASM dialect.
127   bool StarIsPC = false;
128 
129   /// This string, if specified, is used to separate instructions from each
130   /// other when on the same line.  Defaults to ';'
131   const char *SeparatorString;
132 
133   /// This indicates the comment string used by the assembler.  Defaults to
134   /// "#"
135   StringRef CommentString;
136 
137   /// This indicates whether the comment string is only accepted as a comment
138   /// at the beginning of statements. Defaults to false.
139   bool RestrictCommentStringToStartOfStatement = false;
140 
141   /// This indicates whether to allow additional "comment strings" to be lexed
142   /// as a comment. Setting this attribute to true, will ensure that C-style
143   /// line comments (// ..), C-style block comments (/* .. */), and "#" are
144   /// all treated as comments in addition to the string specified by the
145   /// CommentString attribute.
146   /// Default is true.
147   bool AllowAdditionalComments = true;
148 
149   /// Should we emit the '\t' as the starting indentation marker for GNU inline
150   /// asm statements. Defaults to true.
151   bool EmitGNUAsmStartIndentationMarker = true;
152 
153   /// This is appended to emitted labels.  Defaults to ":"
154   const char *LabelSuffix;
155 
156   /// Emit labels in purely upper case. Defaults to false.
157   bool EmitLabelsInUpperCase = false;
158 
159   // Print the EH begin symbol with an assignment. Defaults to false.
160   bool UseAssignmentForEHBegin = false;
161 
162   // Do we need to create a local symbol for .size?
163   bool NeedsLocalForSize = false;
164 
165   /// This prefix is used for globals like constant pool entries that are
166   /// completely private to the .s file and should not have names in the .o
167   /// file.  Defaults to "L"
168   StringRef PrivateGlobalPrefix;
169 
170   /// This prefix is used for labels for basic blocks. Defaults to the same as
171   /// PrivateGlobalPrefix.
172   StringRef PrivateLabelPrefix;
173 
174   /// This prefix is used for symbols that should be passed through the
175   /// assembler but be removed by the linker.  This is 'l' on Darwin, currently
176   /// used for some ObjC metadata.  The default of "" meast that for this system
177   /// a plain private symbol should be used.  Defaults to "".
178   StringRef LinkerPrivateGlobalPrefix;
179 
180   /// If these are nonempty, they contain a directive to emit before and after
181   /// an inline assembly statement.  Defaults to "#APP\n", "#NO_APP\n"
182   const char *InlineAsmStart;
183   const char *InlineAsmEnd;
184 
185   /// These are assembly directives that tells the assembler to interpret the
186   /// following instructions differently.  Defaults to ".code16", ".code32",
187   /// ".code64".
188   const char *Code16Directive;
189   const char *Code32Directive;
190   const char *Code64Directive;
191 
192   /// Which dialect of an assembler variant to use.  Defaults to 0
193   unsigned AssemblerDialect = 0;
194 
195   /// This is true if the assembler allows @ characters in symbol names.
196   /// Defaults to false.
197   bool AllowAtInName = false;
198 
199   /// This is true if the assembler allows the "?" character at the start of
200   /// of a string to be lexed as an AsmToken::Identifier.
201   /// If the AsmLexer determines that the string can be lexed as a possible
202   /// comment, setting this option will have no effect, and the string will
203   /// still be lexed as a comment.
204   bool AllowQuestionAtStartOfIdentifier = false;
205 
206   /// This is true if the assembler allows the "$" character at the start of
207   /// of a string to be lexed as an AsmToken::Identifier.
208   /// If the AsmLexer determines that the string can be lexed as a possible
209   /// comment, setting this option will have no effect, and the string will
210   /// still be lexed as a comment.
211   bool AllowDollarAtStartOfIdentifier = false;
212 
213   /// This is true if the assembler allows the "@" character at the start of
214   /// a string to be lexed as an AsmToken::Identifier.
215   /// If the AsmLexer determines that the string can be lexed as a possible
216   /// comment, setting this option will have no effect, and the string will
217   /// still be lexed as a comment.
218   bool AllowAtAtStartOfIdentifier = false;
219 
220   /// This is true if the assembler allows the "#" character at the start of
221   /// a string to be lexed as an AsmToken::Identifier.
222   /// If the AsmLexer determines that the string can be lexed as a possible
223   /// comment, setting this option will have no effect, and the string will
224   /// still be lexed as a comment.
225   bool AllowHashAtStartOfIdentifier = false;
226 
227   /// If this is true, symbol names with invalid characters will be printed in
228   /// quotes.
229   bool SupportsQuotedNames = true;
230 
231   /// This is true if data region markers should be printed as
232   /// ".data_region/.end_data_region" directives. If false, use "$d/$a" labels
233   /// instead.
234   bool UseDataRegionDirectives = false;
235 
236   /// True if .align is to be used for alignment. Only power-of-two
237   /// alignment is supported.
238   bool UseDotAlignForAlignment = false;
239 
240   /// True if the target supports LEB128 directives.
241   bool HasLEB128Directives = true;
242 
243   /// True if full register names are printed.
244   bool PPCUseFullRegisterNames = false;
245 
246   //===--- Data Emission Directives -------------------------------------===//
247 
248   /// This should be set to the directive used to get some number of zero (and
249   /// non-zero if supported by the directive) bytes emitted to the current
250   /// section. Common cases are "\t.zero\t" and "\t.space\t". Defaults to
251   /// "\t.zero\t"
252   const char *ZeroDirective;
253 
254   /// This should be set to true if the zero directive supports a value to emit
255   /// other than zero. If this is set to false, the Data*bitsDirective's will be
256   /// used to emit these bytes. Defaults to true.
257   bool ZeroDirectiveSupportsNonZeroValue = true;
258 
259   /// This directive allows emission of an ascii string with the standard C
260   /// escape characters embedded into it.  If a target doesn't support this, it
261   /// can be set to null. Defaults to "\t.ascii\t"
262   const char *AsciiDirective;
263 
264   /// If not null, this allows for special handling of zero terminated strings
265   /// on this target.  This is commonly supported as ".asciz".  If a target
266   /// doesn't support this, it can be set to null.  Defaults to "\t.asciz\t"
267   const char *AscizDirective;
268 
269   /// This directive accepts a comma-separated list of bytes for emission as a
270   /// string of bytes.  For targets that do not support this, it shall be set to
271   /// null.  Defaults to null.
272   const char *ByteListDirective = nullptr;
273 
274   /// This directive allows emission of a zero-terminated ascii string without
275   /// the standard C escape characters embedded into it.  If a target doesn't
276   /// support this, it can be set to null. Defaults to null.
277   const char *PlainStringDirective = nullptr;
278 
279   /// Form used for character literals in the assembly syntax.  Useful for
280   /// producing strings as byte lists.  If a target does not use or support
281   /// this, it shall be set to ACLS_Unknown.  Defaults to ACLS_Unknown.
282   AsmCharLiteralSyntax CharacterLiteralSyntax = ACLS_Unknown;
283 
284   /// These directives are used to output some unit of integer data to the
285   /// current section.  If a data directive is set to null, smaller data
286   /// directives will be used to emit the large sizes.  Defaults to "\t.byte\t",
287   /// "\t.short\t", "\t.long\t", "\t.quad\t"
288   const char *Data8bitsDirective;
289   const char *Data16bitsDirective;
290   const char *Data32bitsDirective;
291   const char *Data64bitsDirective;
292 
293   /// True if data directives support signed values
294   bool SupportsSignedData = true;
295 
296   /// If non-null, a directive that is used to emit a word which should be
297   /// relocated as a 64-bit GP-relative offset, e.g. .gpdword on Mips.  Defaults
298   /// to nullptr.
299   const char *GPRel64Directive = nullptr;
300 
301   /// If non-null, a directive that is used to emit a word which should be
302   /// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
303   /// on Alpha.  Defaults to nullptr.
304   const char *GPRel32Directive = nullptr;
305 
306   /// If non-null, directives that are used to emit a word/dword which should
307   /// be relocated as a 32/64-bit DTP/TP-relative offset, e.g. .dtprelword/
308   /// .dtpreldword/.tprelword/.tpreldword on Mips.
309   const char *DTPRel32Directive = nullptr;
310   const char *DTPRel64Directive = nullptr;
311   const char *TPRel32Directive = nullptr;
312   const char *TPRel64Directive = nullptr;
313 
314   /// This is true if this target uses "Sun Style" syntax for section switching
315   /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
316   /// .section directives.  Defaults to false.
317   bool SunStyleELFSectionSwitchSyntax = false;
318 
319   /// This is true if this target uses ELF '.section' directive before the
320   /// '.bss' one. It's used for PPC/Linux which doesn't support the '.bss'
321   /// directive only.  Defaults to false.
322   bool UsesELFSectionDirectiveForBSS = false;
323 
324   bool NeedsDwarfSectionOffsetDirective = false;
325 
326   //===--- Alignment Information ----------------------------------------===//
327 
328   /// If this is true (the default) then the asmprinter emits ".align N"
329   /// directives, where N is the number of bytes to align to.  Otherwise, it
330   /// emits ".align log2(N)", e.g. 3 to align to an 8 byte boundary.  Defaults
331   /// to true.
332   bool AlignmentIsInBytes = true;
333 
334   /// If non-zero, this is used to fill the executable space created as the
335   /// result of a alignment directive.  Defaults to 0
336   unsigned TextAlignFillValue = 0;
337 
338   //===--- Global Variable Emission Directives --------------------------===//
339 
340   /// This is the directive used to declare a global entity. Defaults to
341   /// ".globl".
342   const char *GlobalDirective;
343 
344   /// True if the expression
345   ///   .long f - g
346   /// uses a relocation but it can be suppressed by writing
347   ///   a = f - g
348   ///   .long a
349   bool SetDirectiveSuppressesReloc = false;
350 
351   /// False if the assembler requires that we use
352   /// \code
353   ///   Lc = a - b
354   ///   .long Lc
355   /// \endcode
356   //
357   /// instead of
358   //
359   /// \code
360   ///   .long a - b
361   /// \endcode
362   ///
363   ///  Defaults to true.
364   bool HasAggressiveSymbolFolding = true;
365 
366   /// True is .comm's and .lcomms optional alignment is to be specified in bytes
367   /// instead of log2(n).  Defaults to true.
368   bool COMMDirectiveAlignmentIsInBytes = true;
369 
370   /// Describes if the .lcomm directive for the target supports an alignment
371   /// argument and how it is interpreted.  Defaults to NoAlignment.
372   LCOMM::LCOMMType LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
373 
374   /// True if the target only has basename for .file directive. False if the
375   /// target also needs the directory along with the basename. Defaults to true.
376   bool HasBasenameOnlyForFileDirective = true;
377 
378   /// True if the target represents string constants as mostly raw characters in
379   /// paired double quotation with paired double quotation marks as the escape
380   /// mechanism to represent a double quotation mark within the string. Defaults
381   /// to false.
382   bool HasPairedDoubleQuoteStringConstants = false;
383 
384   // True if the target allows .align directives on functions. This is true for
385   // most targets, so defaults to true.
386   bool HasFunctionAlignment = true;
387 
388   /// True if the target has .type and .size directives, this is true for most
389   /// ELF targets.  Defaults to true.
390   bool HasDotTypeDotSizeDirective = true;
391 
392   /// True if the target has a single parameter .file directive, this is true
393   /// for ELF targets.  Defaults to true.
394   bool HasSingleParameterDotFile = true;
395 
396   /// True if the target has a four strings .file directive, strings seperated
397   /// by comma. Defaults to false.
398   bool HasFourStringsDotFile = false;
399 
400   /// True if the target has a .ident directive, this is true for ELF targets.
401   /// Defaults to false.
402   bool HasIdentDirective = false;
403 
404   /// True if this target supports the MachO .no_dead_strip directive.  Defaults
405   /// to false.
406   bool HasNoDeadStrip = false;
407 
408   /// True if this target supports the MachO .alt_entry directive.  Defaults to
409   /// false.
410   bool HasAltEntry = false;
411 
412   /// Used to declare a global as being a weak symbol. Defaults to ".weak".
413   const char *WeakDirective;
414 
415   /// This directive, if non-null, is used to declare a global as being a weak
416   /// undefined symbol.  Defaults to nullptr.
417   const char *WeakRefDirective = nullptr;
418 
419   /// True if we have a directive to declare a global as being a weak defined
420   /// symbol.  Defaults to false.
421   bool HasWeakDefDirective = false;
422 
423   /// True if we have a directive to declare a global as being a weak defined
424   /// symbol that can be hidden (unexported).  Defaults to false.
425   bool HasWeakDefCanBeHiddenDirective = false;
426 
427   /// True if we should mark symbols as global instead of weak, for
428   /// weak*/linkonce*, if the symbol has a comdat.
429   /// Defaults to false.
430   bool AvoidWeakIfComdat = false;
431 
432   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
433   /// hidden visibility.  Defaults to MCSA_Hidden.
434   MCSymbolAttr HiddenVisibilityAttr = MCSA_Hidden;
435 
436   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
437   /// exported visibility.  Defaults to MCSA_Exported.
438   MCSymbolAttr ExportedVisibilityAttr = MCSA_Exported;
439 
440   /// This attribute, if not MCSA_Invalid, is used to declare an undefined
441   /// symbol as having hidden visibility. Defaults to MCSA_Hidden.
442   MCSymbolAttr HiddenDeclarationVisibilityAttr = MCSA_Hidden;
443 
444   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
445   /// protected visibility.  Defaults to MCSA_Protected
446   MCSymbolAttr ProtectedVisibilityAttr = MCSA_Protected;
447 
448   MCSymbolAttr MemtagAttr = MCSA_Memtag;
449 
450   //===--- Dwarf Emission Directives -----------------------------------===//
451 
452   /// True if target supports emission of debugging information.  Defaults to
453   /// false.
454   bool SupportsDebugInformation = false;
455 
456   /// Exception handling format for the target.  Defaults to None.
457   ExceptionHandling ExceptionsType = ExceptionHandling::None;
458 
459   /// True if target uses CFI unwind information for other purposes than EH
460   /// (debugging / sanitizers) when `ExceptionsType == ExceptionHandling::None`.
461   bool UsesCFIWithoutEH = false;
462 
463   /// Windows exception handling data (.pdata) encoding.  Defaults to Invalid.
464   WinEH::EncodingType WinEHEncodingType = WinEH::EncodingType::Invalid;
465 
466   /// True if Dwarf2 output generally uses relocations for references to other
467   /// .debug_* sections.
468   bool DwarfUsesRelocationsAcrossSections = true;
469 
470   /// True if DWARF FDE symbol reference relocations should be replaced by an
471   /// absolute difference.
472   bool DwarfFDESymbolsUseAbsDiff = false;
473 
474   /// True if the target supports generating the DWARF line table through using
475   /// the .loc/.file directives. Defaults to true.
476   bool UsesDwarfFileAndLocDirectives = true;
477 
478   /// True if DWARF `.file directory' directive syntax is used by
479   /// default.
480   bool EnableDwarfFileDirectoryDefault = true;
481 
482   /// True if the target needs the DWARF section length in the header (if any)
483   /// of the DWARF section in the assembly file. Defaults to true.
484   bool DwarfSectionSizeRequired = true;
485 
486   /// True if dwarf register numbers are printed instead of symbolic register
487   /// names in .cfi_* directives.  Defaults to false.
488   bool DwarfRegNumForCFI = false;
489 
490   /// True if target uses parens to indicate the symbol variant instead of @.
491   /// For example, foo(plt) instead of foo@plt.  Defaults to false.
492   bool UseParensForSymbolVariant = false;
493 
494   /// True if the target uses parens for symbol names starting with
495   /// '$' character to distinguish them from absolute names.
496   bool UseParensForDollarSignNames = true;
497 
498   /// True if the target supports flags in ".loc" directive, false if only
499   /// location is allowed.
500   bool SupportsExtendedDwarfLocDirective = true;
501 
502   //===--- Prologue State ----------------------------------------------===//
503 
504   std::vector<MCCFIInstruction> InitialFrameState;
505 
506   //===--- Integrated Assembler Information ----------------------------===//
507 
508   // Generated object files can use all ELF features supported by GNU ld of
509   // this binutils version and later. INT_MAX means all features can be used,
510   // regardless of GNU ld support. The default value is referenced by
511   // clang/Driver/Options.td.
512   std::pair<int, int> BinutilsVersion = {2, 26};
513 
514   /// Should we use the integrated assembler?
515   /// The integrated assembler should be enabled by default (by the
516   /// constructors) when failing to parse a valid piece of assembly (inline
517   /// or otherwise) is considered a bug. It may then be overridden after
518   /// construction (see LLVMTargetMachine::initAsmInfo()).
519   bool UseIntegratedAssembler;
520 
521   /// Use AsmParser to parse inlineAsm when UseIntegratedAssembler is not set.
522   bool ParseInlineAsmUsingAsmParser;
523 
524   /// Preserve Comments in assembly
525   bool PreserveAsmComments;
526 
527   /// Compress DWARF debug sections. Defaults to no compression.
528   DebugCompressionType CompressDebugSections = DebugCompressionType::None;
529 
530   /// True if the integrated assembler should interpret 'a >> b' constant
531   /// expressions as logical rather than arithmetic.
532   bool UseLogicalShr = true;
533 
534   // If true, emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL, on
535   // X86_64 ELF.
536   bool RelaxELFRelocations = true;
537 
538   // If true, then the lexer and expression parser will support %neg(),
539   // %hi(), and similar unary operators.
540   bool HasMipsExpressions = false;
541 
542   // If true, use Motorola-style integers in Assembly (ex. $0ac).
543   bool UseMotorolaIntegers = false;
544 
545   // If true, emit function descriptor symbol on AIX.
546   bool NeedsFunctionDescriptors = false;
547 
548 public:
549   explicit MCAsmInfo();
550   virtual ~MCAsmInfo();
551 
552   /// Get the code pointer size in bytes.
553   unsigned getCodePointerSize() const { return CodePointerSize; }
554 
555   /// Get the callee-saved register stack slot
556   /// size in bytes.
557   unsigned getCalleeSaveStackSlotSize() const {
558     return CalleeSaveStackSlotSize;
559   }
560 
561   /// True if the target is little endian.
562   bool isLittleEndian() const { return IsLittleEndian; }
563 
564   /// True if target stack grow up.
565   bool isStackGrowthDirectionUp() const { return StackGrowsUp; }
566 
567   bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
568 
569   // Data directive accessors.
570 
571   const char *getData8bitsDirective() const { return Data8bitsDirective; }
572   const char *getData16bitsDirective() const { return Data16bitsDirective; }
573   const char *getData32bitsDirective() const { return Data32bitsDirective; }
574   const char *getData64bitsDirective() const { return Data64bitsDirective; }
575   bool supportsSignedData() const { return SupportsSignedData; }
576   const char *getGPRel64Directive() const { return GPRel64Directive; }
577   const char *getGPRel32Directive() const { return GPRel32Directive; }
578   const char *getDTPRel64Directive() const { return DTPRel64Directive; }
579   const char *getDTPRel32Directive() const { return DTPRel32Directive; }
580   const char *getTPRel64Directive() const { return TPRel64Directive; }
581   const char *getTPRel32Directive() const { return TPRel32Directive; }
582 
583   /// Targets can implement this method to specify a section to switch to if the
584   /// translation unit doesn't have any trampolines that require an executable
585   /// stack.
586   virtual MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
587     return nullptr;
588   }
589 
590   /// True if the section is atomized using the symbols in it.
591   /// This is false if the section is not atomized at all (most ELF sections) or
592   /// if it is atomized based on its contents (MachO' __TEXT,__cstring for
593   /// example).
594   virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
595 
596   virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
597                                                     unsigned Encoding,
598                                                     MCStreamer &Streamer) const;
599 
600   virtual const MCExpr *getExprForFDESymbol(const MCSymbol *Sym,
601                                             unsigned Encoding,
602                                             MCStreamer &Streamer) const;
603 
604   /// Return true if C is an acceptable character inside a symbol name.
605   virtual bool isAcceptableChar(char C) const;
606 
607   /// Return true if the identifier \p Name does not need quotes to be
608   /// syntactically correct.
609   virtual bool isValidUnquotedName(StringRef Name) const;
610 
611   /// Return true if the .section directive should be omitted when
612   /// emitting \p SectionName.  For example:
613   ///
614   /// shouldOmitSectionDirective(".text")
615   ///
616   /// returns false => .section .text,#alloc,#execinstr
617   /// returns true  => .text
618   virtual bool shouldOmitSectionDirective(StringRef SectionName) const;
619 
620   bool usesSunStyleELFSectionSwitchSyntax() const {
621     return SunStyleELFSectionSwitchSyntax;
622   }
623 
624   bool usesELFSectionDirectiveForBSS() const {
625     return UsesELFSectionDirectiveForBSS;
626   }
627 
628   bool needsDwarfSectionOffsetDirective() const {
629     return NeedsDwarfSectionOffsetDirective;
630   }
631 
632   // Accessors.
633 
634   bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
635   bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
636   bool hasCOFFAssociativeComdats() const { return HasCOFFAssociativeComdats; }
637   bool hasCOFFComdatConstants() const { return HasCOFFComdatConstants; }
638   bool hasVisibilityOnlyWithLinkage() const {
639     return HasVisibilityOnlyWithLinkage;
640   }
641 
642   /// Returns the maximum possible encoded instruction size in bytes. If \p STI
643   /// is null, this should be the maximum size for any subtarget.
644   virtual unsigned getMaxInstLength(const MCSubtargetInfo *STI = nullptr) const {
645     return MaxInstLength;
646   }
647 
648   unsigned getMinInstAlignment() const { return MinInstAlignment; }
649   bool getDollarIsPC() const { return DollarIsPC; }
650   bool getDotIsPC() const { return DotIsPC; }
651   bool getStarIsPC() const { return StarIsPC; }
652   const char *getSeparatorString() const { return SeparatorString; }
653 
654   /// This indicates the column (zero-based) at which asm comments should be
655   /// printed.
656   unsigned getCommentColumn() const { return 40; }
657 
658   StringRef getCommentString() const { return CommentString; }
659   bool getRestrictCommentStringToStartOfStatement() const {
660     return RestrictCommentStringToStartOfStatement;
661   }
662   bool shouldAllowAdditionalComments() const { return AllowAdditionalComments; }
663   bool getEmitGNUAsmStartIndentationMarker() const {
664     return EmitGNUAsmStartIndentationMarker;
665   }
666   const char *getLabelSuffix() const { return LabelSuffix; }
667   bool shouldEmitLabelsInUpperCase() const { return EmitLabelsInUpperCase; }
668 
669   bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
670   bool needsLocalForSize() const { return NeedsLocalForSize; }
671   StringRef getPrivateGlobalPrefix() const { return PrivateGlobalPrefix; }
672   StringRef getPrivateLabelPrefix() const { return PrivateLabelPrefix; }
673 
674   bool hasLinkerPrivateGlobalPrefix() const {
675     return !LinkerPrivateGlobalPrefix.empty();
676   }
677 
678   StringRef getLinkerPrivateGlobalPrefix() const {
679     if (hasLinkerPrivateGlobalPrefix())
680       return LinkerPrivateGlobalPrefix;
681     return getPrivateGlobalPrefix();
682   }
683 
684   const char *getInlineAsmStart() const { return InlineAsmStart; }
685   const char *getInlineAsmEnd() const { return InlineAsmEnd; }
686   const char *getCode16Directive() const { return Code16Directive; }
687   const char *getCode32Directive() const { return Code32Directive; }
688   const char *getCode64Directive() const { return Code64Directive; }
689   unsigned getAssemblerDialect() const { return AssemblerDialect; }
690   bool doesAllowAtInName() const { return AllowAtInName; }
691   void setAllowAtInName(bool V) { AllowAtInName = V; }
692   bool doesAllowQuestionAtStartOfIdentifier() const {
693     return AllowQuestionAtStartOfIdentifier;
694   }
695   bool doesAllowAtAtStartOfIdentifier() const {
696     return AllowAtAtStartOfIdentifier;
697   }
698   bool doesAllowDollarAtStartOfIdentifier() const {
699     return AllowDollarAtStartOfIdentifier;
700   }
701   bool doesAllowHashAtStartOfIdentifier() const {
702     return AllowHashAtStartOfIdentifier;
703   }
704   bool supportsNameQuoting() const { return SupportsQuotedNames; }
705 
706   bool doesSupportDataRegionDirectives() const {
707     return UseDataRegionDirectives;
708   }
709 
710   bool useDotAlignForAlignment() const {
711     return UseDotAlignForAlignment;
712   }
713 
714   bool hasLEB128Directives() const { return HasLEB128Directives; }
715 
716   bool useFullRegisterNames() const { return PPCUseFullRegisterNames; }
717   void setFullRegisterNames(bool V) { PPCUseFullRegisterNames = V; }
718 
719   const char *getZeroDirective() const { return ZeroDirective; }
720   bool doesZeroDirectiveSupportNonZeroValue() const {
721     return ZeroDirectiveSupportsNonZeroValue;
722   }
723   const char *getAsciiDirective() const { return AsciiDirective; }
724   const char *getAscizDirective() const { return AscizDirective; }
725   const char *getByteListDirective() const { return ByteListDirective; }
726   const char *getPlainStringDirective() const { return PlainStringDirective; }
727   AsmCharLiteralSyntax characterLiteralSyntax() const {
728     return CharacterLiteralSyntax;
729   }
730   bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
731   unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
732   const char *getGlobalDirective() const { return GlobalDirective; }
733 
734   bool doesSetDirectiveSuppressReloc() const {
735     return SetDirectiveSuppressesReloc;
736   }
737 
738   bool hasAggressiveSymbolFolding() const { return HasAggressiveSymbolFolding; }
739 
740   bool getCOMMDirectiveAlignmentIsInBytes() const {
741     return COMMDirectiveAlignmentIsInBytes;
742   }
743 
744   LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
745     return LCOMMDirectiveAlignmentType;
746   }
747 
748   bool hasBasenameOnlyForFileDirective() const {
749     return HasBasenameOnlyForFileDirective;
750   }
751   bool hasPairedDoubleQuoteStringConstants() const {
752     return HasPairedDoubleQuoteStringConstants;
753   }
754   bool hasFunctionAlignment() const { return HasFunctionAlignment; }
755   bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
756   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
757   bool hasFourStringsDotFile() const { return HasFourStringsDotFile; }
758   bool hasIdentDirective() const { return HasIdentDirective; }
759   bool hasNoDeadStrip() const { return HasNoDeadStrip; }
760   bool hasAltEntry() const { return HasAltEntry; }
761   const char *getWeakDirective() const { return WeakDirective; }
762   const char *getWeakRefDirective() const { return WeakRefDirective; }
763   bool hasWeakDefDirective() const { return HasWeakDefDirective; }
764 
765   bool hasWeakDefCanBeHiddenDirective() const {
766     return HasWeakDefCanBeHiddenDirective;
767   }
768 
769   bool avoidWeakIfComdat() const { return AvoidWeakIfComdat; }
770 
771   MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr; }
772 
773   MCSymbolAttr getExportedVisibilityAttr() const { return ExportedVisibilityAttr; }
774 
775   MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
776     return HiddenDeclarationVisibilityAttr;
777   }
778 
779   MCSymbolAttr getProtectedVisibilityAttr() const {
780     return ProtectedVisibilityAttr;
781   }
782 
783   MCSymbolAttr getMemtagAttr() const { return MemtagAttr; }
784 
785   bool doesSupportDebugInformation() const { return SupportsDebugInformation; }
786 
787   ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
788   WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
789 
790   void setExceptionsType(ExceptionHandling EH) {
791     ExceptionsType = EH;
792   }
793 
794   bool usesCFIWithoutEH() const {
795     return ExceptionsType == ExceptionHandling::None && UsesCFIWithoutEH;
796   }
797 
798   /// Returns true if the exception handling method for the platform uses call
799   /// frame information to unwind.
800   bool usesCFIForEH() const {
801     return (ExceptionsType == ExceptionHandling::DwarfCFI ||
802             ExceptionsType == ExceptionHandling::ARM || usesWindowsCFI());
803   }
804 
805   bool usesWindowsCFI() const {
806     return ExceptionsType == ExceptionHandling::WinEH &&
807            (WinEHEncodingType != WinEH::EncodingType::Invalid &&
808             WinEHEncodingType != WinEH::EncodingType::X86);
809   }
810 
811   bool doesDwarfUseRelocationsAcrossSections() const {
812     return DwarfUsesRelocationsAcrossSections;
813   }
814 
815   bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
816   bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
817   bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; }
818   bool useParensForDollarSignNames() const {
819     return UseParensForDollarSignNames;
820   }
821   bool supportsExtendedDwarfLocDirective() const {
822     return SupportsExtendedDwarfLocDirective;
823   }
824 
825   bool usesDwarfFileAndLocDirectives() const {
826     return UsesDwarfFileAndLocDirectives;
827   }
828 
829   bool needsDwarfSectionSizeInHeader() const {
830     return DwarfSectionSizeRequired;
831   }
832 
833   bool enableDwarfFileDirectoryDefault() const {
834     return EnableDwarfFileDirectoryDefault;
835   }
836 
837   void addInitialFrameState(const MCCFIInstruction &Inst);
838 
839   const std::vector<MCCFIInstruction> &getInitialFrameState() const {
840     return InitialFrameState;
841   }
842 
843   void setBinutilsVersion(std::pair<int, int> Value) {
844     BinutilsVersion = Value;
845   }
846 
847   /// Return true if assembly (inline or otherwise) should be parsed.
848   bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
849 
850   /// Return true if target want to use AsmParser to parse inlineasm.
851   bool parseInlineAsmUsingAsmParser() const {
852     return ParseInlineAsmUsingAsmParser;
853   }
854 
855   bool binutilsIsAtLeast(int Major, int Minor) const {
856     return BinutilsVersion >= std::make_pair(Major, Minor);
857   }
858 
859   /// Set whether assembly (inline or otherwise) should be parsed.
860   virtual void setUseIntegratedAssembler(bool Value) {
861     UseIntegratedAssembler = Value;
862   }
863 
864   /// Set whether target want to use AsmParser to parse inlineasm.
865   virtual void setParseInlineAsmUsingAsmParser(bool Value) {
866     ParseInlineAsmUsingAsmParser = Value;
867   }
868 
869   /// Return true if assembly (inline or otherwise) should be parsed.
870   bool preserveAsmComments() const { return PreserveAsmComments; }
871 
872   /// Set whether assembly (inline or otherwise) should be parsed.
873   virtual void setPreserveAsmComments(bool Value) {
874     PreserveAsmComments = Value;
875   }
876 
877   DebugCompressionType compressDebugSections() const {
878     return CompressDebugSections;
879   }
880 
881   void setCompressDebugSections(DebugCompressionType CompressDebugSections) {
882     this->CompressDebugSections = CompressDebugSections;
883   }
884 
885   bool shouldUseLogicalShr() const { return UseLogicalShr; }
886 
887   bool canRelaxRelocations() const { return RelaxELFRelocations; }
888   void setRelaxELFRelocations(bool V) { RelaxELFRelocations = V; }
889   bool hasMipsExpressions() const { return HasMipsExpressions; }
890   bool needsFunctionDescriptors() const { return NeedsFunctionDescriptors; }
891   bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
892 };
893 
894 } // end namespace llvm
895 
896 #endif // LLVM_MC_MCASMINFO_H
897