LLVM 22.0.0git
MCAsmInfo.h
Go to the documentation of this file.
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/DenseMap.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
24#include <vector>
25
26namespace llvm {
27
28class MCAssembler;
29class MCContext;
30class MCCFIInstruction;
31class MCExpr;
32class MCSpecifierExpr;
33class MCSection;
34class MCStreamer;
35class MCSubtargetInfo;
36class MCSymbol;
37class MCValue;
38class Triple;
39class raw_ostream;
40
41namespace WinEH {
42
43enum class EncodingType {
44 Invalid, /// Invalid
45 Alpha, /// Windows Alpha
46 Alpha64, /// Windows AXP64
47 ARM, /// Windows NT (Windows on ARM)
48 CE, /// Windows CE ARM, PowerPC, SH3, SH4
49 Itanium, /// Windows x64, Windows Itanium (IA-64)
50 X86, /// Windows x86, uses no CFI, just EH tables
51 MIPS = Alpha,
52};
53
54} // end namespace WinEH
55
56namespace LCOMM {
57
59
60} // end namespace LCOMM
61
62/// This class is intended to be used as a base class for asm
63/// properties and features specific to the target.
65public:
66 /// Assembly character literal syntax types.
68 ACLS_Unknown, /// Unknown; character literals not used by LLVM for this
69 /// target.
70 ACLS_SingleQuotePrefix, /// The desired character is prefixed by a single
71 /// quote, e.g., `'A`.
72 };
73
74 // This describes a @ style relocation specifier (expr@specifier) supported by
75 // AsmParser::parsePrimaryExpr.
76 struct AtSpecifier {
79 };
80
81protected:
82 //===------------------------------------------------------------------===//
83 // Properties to be set by the target writer, used to configure asm printer.
84 //
85
86 /// Code pointer size in bytes. Default is 4.
87 unsigned CodePointerSize = 4;
88
89 /// Size of the stack slot reserved for callee-saved registers, in bytes.
90 /// Default is same as pointer size.
91 unsigned CalleeSaveStackSlotSize = 4;
92
93 /// True if target is little endian. Default is true.
94 bool IsLittleEndian = true;
95
96 /// True if target stack grow up. Default is false.
97 bool StackGrowsUp = false;
98
99 /// True if this target has the MachO .subsections_via_symbols directive.
100 /// Default is false.
101 bool HasSubsectionsViaSymbols = false;
102
103 /// True if this is a non-GNU COFF target. The COFF port of the GNU linker
104 /// doesn't handle associative comdats in the way that we would like to use
105 /// them.
106 bool HasCOFFAssociativeComdats = false;
107
108 /// True if this is a non-GNU COFF target. For GNU targets, we don't generate
109 /// constants into comdat sections.
110 bool HasCOFFComdatConstants = false;
111
112 bool IsAIX = false;
113
114 // True if using the HLASM dialect on z/OS.
115 bool IsHLASM = false;
116
117 /// This is the maximum possible length of an instruction, which is needed to
118 /// compute the size of an inline asm. Defaults to 4.
119 unsigned MaxInstLength = 4;
120
121 /// Every possible instruction length is a multiple of this value. Factored
122 /// out in .debug_frame and .debug_line. Defaults to 1.
123 unsigned MinInstAlignment = 1;
124
125 /// The '$' token, when not referencing an identifier or constant, refers to
126 /// the current PC. Defaults to false.
127 bool DollarIsPC = 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 /// "#"
136
137 /// This indicates whether to allow additional "comment strings" to be lexed
138 /// as a comment. Setting this attribute to true, will ensure that C-style
139 /// line comments (// ..), C-style block comments (/* .. */), and "#" are
140 /// all treated as comments in addition to the string specified by the
141 /// CommentString attribute.
142 /// Default is true.
143 bool AllowAdditionalComments = true;
144
145 /// This is appended to emitted labels. Defaults to ":"
146 const char *LabelSuffix;
147
148 /// Use .set instead of = to equate a symbol to an expression.
149 bool UsesSetToEquateSymbol = false;
150
151 // Print the EH begin symbol with an assignment. Defaults to false.
152 bool UseAssignmentForEHBegin = false;
153
154 // Do we need to create a local symbol for .size?
155 bool NeedsLocalForSize = false;
156
157 /// This prefix is used for globals like constant pool entries that are
158 /// completely private to the .s file and should not have names in the .o
159 /// file. Defaults to "L"
161
162 /// This prefix is used for labels for basic blocks. Defaults to the same as
163 /// PrivateGlobalPrefix.
165
166 /// This prefix is used for symbols that should be passed through the
167 /// assembler but be removed by the linker. This is 'l' on Darwin, currently
168 /// used for some ObjC metadata. The default of "" meast that for this system
169 /// a plain private symbol should be used. Defaults to "".
171
172 /// If these are nonempty, they contain a directive to emit before and after
173 /// an inline assembly statement. Defaults to "#APP\n", "#NO_APP\n"
174 const char *InlineAsmStart;
175 const char *InlineAsmEnd;
176
177 /// Which dialect of an assembler variant to use. Defaults to 0
178 unsigned AssemblerDialect = 0;
179
180 /// This is true if the assembler allows @ characters in symbol names.
181 /// Defaults to false.
182 bool AllowAtInName = false;
183
184 /// This is true if the assembler allows the "?" character at the start of
185 /// of a string to be lexed as an AsmToken::Identifier.
186 /// If the AsmLexer determines that the string can be lexed as a possible
187 /// comment, setting this option will have no effect, and the string will
188 /// still be lexed as a comment.
189 bool AllowQuestionAtStartOfIdentifier = false;
190
191 /// This is true if the assembler allows the "$" character at the start of
192 /// of a string to be lexed as an AsmToken::Identifier.
193 /// If the AsmLexer determines that the string can be lexed as a possible
194 /// comment, setting this option will have no effect, and the string will
195 /// still be lexed as a comment.
196 bool AllowDollarAtStartOfIdentifier = false;
197
198 /// This is true if the assembler allows the "@" character at the start of
199 /// a string to be lexed as an AsmToken::Identifier.
200 /// If the AsmLexer determines that the string can be lexed as a possible
201 /// comment, setting this option will have no effect, and the string will
202 /// still be lexed as a comment.
203 bool AllowAtAtStartOfIdentifier = false;
204
205 /// If this is true, symbol names with invalid characters will be printed in
206 /// quotes.
207 bool SupportsQuotedNames = true;
208
209 /// This is true if data region markers should be printed as
210 /// ".data_region/.end_data_region" directives. If false, use "$d/$a" labels
211 /// instead.
212 bool UseDataRegionDirectives = false;
213
214 /// True if the target supports LEB128 directives.
215 bool HasLEB128Directives = true;
216
217 /// True if full register names are printed.
218 bool PPCUseFullRegisterNames = false;
219
220 //===--- Data Emission Directives -------------------------------------===//
221
222 /// This should be set to the directive used to get some number of zero (and
223 /// non-zero if supported by the directive) bytes emitted to the current
224 /// section. Common cases are "\t.zero\t" and "\t.space\t". Defaults to
225 /// "\t.zero\t"
226 const char *ZeroDirective;
227
228 /// This directive allows emission of an ascii string with the standard C
229 /// escape characters embedded into it. If a target doesn't support this, it
230 /// can be set to null. Defaults to "\t.ascii\t"
231 const char *AsciiDirective;
232
233 /// If not null, this allows for special handling of zero terminated strings
234 /// on this target. This is commonly supported as ".asciz". If a target
235 /// doesn't support this, it can be set to null. Defaults to "\t.asciz\t"
236 const char *AscizDirective;
237
238 /// Form used for character literals in the assembly syntax. Useful for
239 /// producing strings as byte lists. If a target does not use or support
240 /// this, it shall be set to ACLS_Unknown. Defaults to ACLS_Unknown.
241 AsmCharLiteralSyntax CharacterLiteralSyntax = ACLS_Unknown;
242
243 /// These directives are used to output some unit of integer data to the
244 /// current section. If a data directive is set to null, smaller data
245 /// directives will be used to emit the large sizes. Defaults to "\t.byte\t",
246 /// "\t.short\t", "\t.long\t", "\t.quad\t"
251
252 /// True if data directives support signed values
253 bool SupportsSignedData = true;
254
255 /// This is true if this target uses "Sun Style" syntax for section switching
256 /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
257 /// .section directives. Defaults to false.
258 bool SunStyleELFSectionSwitchSyntax = false;
259
260 /// This is true if this target uses ELF '.section' directive before the
261 /// '.bss' one. It's used for PPC/Linux which doesn't support the '.bss'
262 /// directive only. Defaults to false.
263 bool UsesELFSectionDirectiveForBSS = false;
264
265 bool NeedsDwarfSectionOffsetDirective = false;
266
267 //===--- Alignment Information ----------------------------------------===//
268
269 /// If this is true (the default) then the asmprinter emits ".align N"
270 /// directives, where N is the number of bytes to align to. Otherwise, it
271 /// emits ".align log2(N)", e.g. 3 to align to an 8 byte boundary. Defaults
272 /// to true.
273 bool AlignmentIsInBytes = true;
274
275 /// If non-zero, this is used to fill the executable space created as the
276 /// result of a alignment directive. Defaults to 0
277 unsigned TextAlignFillValue = 0;
278
279 //===--- Global Variable Emission Directives --------------------------===//
280
281 /// This is the directive used to declare a global entity. Defaults to
282 /// ".globl".
283 const char *GlobalDirective;
284
285 /// True if the expression
286 /// .long f - g
287 /// uses a relocation but it can be suppressed by writing
288 /// a = f - g
289 /// .long a
290 bool SetDirectiveSuppressesReloc = false;
291
292 /// True is .comm's and .lcomms optional alignment is to be specified in bytes
293 /// instead of log2(n). Defaults to true.
294 bool COMMDirectiveAlignmentIsInBytes = true;
295
296 /// Describes if the .lcomm directive for the target supports an alignment
297 /// argument and how it is interpreted. Defaults to NoAlignment.
298 LCOMM::LCOMMType LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
299
300 // True if the target allows .align directives on functions. This is true for
301 // most targets, so defaults to true.
302 bool HasFunctionAlignment = true;
303
304 /// True if the target has .type and .size directives, this is true for most
305 /// ELF targets. Defaults to true.
306 bool HasDotTypeDotSizeDirective = true;
307
308 /// True if the target has a single parameter .file directive, this is true
309 /// for ELF targets. Defaults to true.
310 bool HasSingleParameterDotFile = true;
311
312 /// True if the target has a .ident directive, this is true for ELF targets.
313 /// Defaults to false.
314 bool HasIdentDirective = false;
315
316 /// True if this target supports the MachO .no_dead_strip directive. Defaults
317 /// to false.
318 bool HasNoDeadStrip = false;
319
320 /// Used to declare a global as being a weak symbol. Defaults to ".weak".
321 const char *WeakDirective;
322
323 /// This directive, if non-null, is used to declare a global as being a weak
324 /// undefined symbol. Defaults to nullptr.
325 const char *WeakRefDirective = nullptr;
326
327 /// True if we have a directive to declare a global as being a weak defined
328 /// symbol that can be hidden (unexported). Defaults to false.
329 bool HasWeakDefCanBeHiddenDirective = false;
330
331 /// True if we should mark symbols as global instead of weak, for
332 /// weak*/linkonce*, if the symbol has a comdat.
333 /// Defaults to false.
334 bool AvoidWeakIfComdat = false;
335
336 /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
337 /// hidden visibility. Defaults to MCSA_Hidden.
338 MCSymbolAttr HiddenVisibilityAttr = MCSA_Hidden;
339
340 /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
341 /// exported visibility. Defaults to MCSA_Exported.
342 MCSymbolAttr ExportedVisibilityAttr = MCSA_Exported;
343
344 /// This attribute, if not MCSA_Invalid, is used to declare an undefined
345 /// symbol as having hidden visibility. Defaults to MCSA_Hidden.
346 MCSymbolAttr HiddenDeclarationVisibilityAttr = MCSA_Hidden;
347
348 /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
349 /// protected visibility. Defaults to MCSA_Protected
350 MCSymbolAttr ProtectedVisibilityAttr = MCSA_Protected;
351
352 //===--- Dwarf Emission Directives -----------------------------------===//
353
354 /// True if target supports emission of debugging information. Defaults to
355 /// false.
356 bool SupportsDebugInformation = false;
357
358 /// Exception handling format for the target. Defaults to None.
359 ExceptionHandling ExceptionsType = ExceptionHandling::None;
360
361 /// True if target uses CFI unwind information for other purposes than EH
362 /// (debugging / sanitizers) when `ExceptionsType == ExceptionHandling::None`.
363 bool UsesCFIWithoutEH = false;
364
365 /// Windows exception handling data (.pdata) encoding. Defaults to Invalid.
366 WinEH::EncodingType WinEHEncodingType = WinEH::EncodingType::Invalid;
367
368 /// True if Dwarf2 output generally uses relocations for references to other
369 /// .debug_* sections.
370 bool DwarfUsesRelocationsAcrossSections = true;
371
372 /// True if DWARF FDE symbol reference relocations should be replaced by an
373 /// absolute difference.
374 bool DwarfFDESymbolsUseAbsDiff = false;
375
376 /// True if DWARF `.file directory' directive syntax is used by
377 /// default.
378 bool EnableDwarfFileDirectoryDefault = true;
379
380 /// True if dwarf register numbers are printed instead of symbolic register
381 /// names in .cfi_* directives. Defaults to false.
382 bool DwarfRegNumForCFI = false;
383
384 /// True if target uses @ (expr@specifier) for relocation specifiers.
385 bool UseAtForSpecifier = true;
386
387 /// (ARM-specific) Uses parens for relocation specifier in data
388 /// directives, e.g. .word foo(got).
389 bool UseParensForSpecifier = false;
390
391 /// True if the target supports flags in ".loc" directive, false if only
392 /// location is allowed.
393 bool SupportsExtendedDwarfLocDirective = true;
394
395 //===--- Prologue State ----------------------------------------------===//
396
397 std::vector<MCCFIInstruction> InitialFrameState;
398
399 //===--- Integrated Assembler Information ----------------------------===//
400
401 // Generated object files can use all ELF features supported by GNU ld of
402 // this binutils version and later. INT_MAX means all features can be used,
403 // regardless of GNU ld support. The default value is referenced by
404 // clang/Driver/Options.td.
405 std::pair<int, int> BinutilsVersion = {2, 26};
406
407 /// Should we use the integrated assembler?
408 /// The integrated assembler should be enabled by default (by the
409 /// constructors) when failing to parse a valid piece of assembly (inline
410 /// or otherwise) is considered a bug. It may then be overridden after
411 /// construction (see CodeGenTargetMachineImpl::initAsmInfo()).
413
414 /// Use AsmParser to parse inlineAsm when UseIntegratedAssembler is not set.
416
417 /// Preserve Comments in assembly
419
420 /// The column (zero-based) at which asm comments should be printed.
421 unsigned CommentColumn = 40;
422
423 /// True if the integrated assembler should interpret 'a >> b' constant
424 /// expressions as logical rather than arithmetic.
425 bool UseLogicalShr = true;
426
427 // If true, use Motorola-style integers in Assembly (ex. $0ac).
428 bool UseMotorolaIntegers = false;
429
432 void initializeAtSpecifiers(ArrayRef<AtSpecifier>);
433
434public:
435 explicit MCAsmInfo();
436 virtual ~MCAsmInfo();
437
438 // Explicitly non-copyable.
439 MCAsmInfo(MCAsmInfo const &) = delete;
440 MCAsmInfo &operator=(MCAsmInfo const &) = delete;
441
442 /// Get the code pointer size in bytes.
443 unsigned getCodePointerSize() const { return CodePointerSize; }
444
445 /// Get the callee-saved register stack slot
446 /// size in bytes.
447 unsigned getCalleeSaveStackSlotSize() const {
448 return CalleeSaveStackSlotSize;
449 }
450
451 /// True if the target is little endian.
452 bool isLittleEndian() const { return IsLittleEndian; }
453
454 /// True if target stack grow up.
455 bool isStackGrowthDirectionUp() const { return StackGrowsUp; }
456
457 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
458
459 // Data directive accessors.
460
461 const char *getData8bitsDirective() const { return Data8bitsDirective; }
462 const char *getData16bitsDirective() const { return Data16bitsDirective; }
463 const char *getData32bitsDirective() const { return Data32bitsDirective; }
464 const char *getData64bitsDirective() const { return Data64bitsDirective; }
465 bool supportsSignedData() const { return SupportsSignedData; }
466
467 /// Targets can implement this method to specify a section to switch to if the
468 /// translation unit doesn't have any trampolines that require an executable
469 /// stack.
471 return nullptr;
472 }
473
474 virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
475 unsigned Encoding,
476 MCStreamer &Streamer) const;
477
478 virtual const MCExpr *getExprForFDESymbol(const MCSymbol *Sym,
479 unsigned Encoding,
480 MCStreamer &Streamer) const;
481
482 /// Return true if C is an acceptable character inside a symbol name.
483 virtual bool isAcceptableChar(char C) const;
484
485 /// Return true if the identifier \p Name does not need quotes to be
486 /// syntactically correct.
487 virtual bool isValidUnquotedName(StringRef Name) const;
488
489 virtual void printSwitchToSection(const MCSection &, uint32_t Subsection,
490 const Triple &, raw_ostream &) const {}
491
492 /// Return true if the .section directive should be omitted when
493 /// emitting \p SectionName. For example:
494 ///
495 /// shouldOmitSectionDirective(".text")
496 ///
497 /// returns false => .section .text,#alloc,#execinstr
498 /// returns true => .text
499 virtual bool shouldOmitSectionDirective(StringRef SectionName) const;
500
501 // Return true if a .align directive should use "optimized nops" to fill
502 // instead of 0s.
503 virtual bool useCodeAlign(const MCSection &Sec) const { return false; }
504
506 return SunStyleELFSectionSwitchSyntax;
507 }
508
510 return UsesELFSectionDirectiveForBSS;
511 }
512
514 return NeedsDwarfSectionOffsetDirective;
515 }
516
517 // Accessors.
518
519 bool isAIX() const { return IsAIX; }
520 bool isHLASM() const { return IsHLASM; }
521 bool isMachO() const { return HasSubsectionsViaSymbols; }
522 bool hasCOFFAssociativeComdats() const { return HasCOFFAssociativeComdats; }
523 bool hasCOFFComdatConstants() const { return HasCOFFComdatConstants; }
524
525 /// Returns the maximum possible encoded instruction size in bytes. If \p STI
526 /// is null, this should be the maximum size for any subtarget.
527 virtual unsigned getMaxInstLength(const MCSubtargetInfo *STI = nullptr) const {
528 return MaxInstLength;
529 }
530
531 unsigned getMinInstAlignment() const { return MinInstAlignment; }
532 bool getDollarIsPC() const { return DollarIsPC; }
533 const char *getSeparatorString() const { return SeparatorString; }
534
535 unsigned getCommentColumn() const { return CommentColumn; }
536 void setCommentColumn(unsigned Col) { CommentColumn = Col; }
537
538 StringRef getCommentString() const { return CommentString; }
539 bool shouldAllowAdditionalComments() const { return AllowAdditionalComments; }
540 const char *getLabelSuffix() const { return LabelSuffix; }
541
542 bool usesSetToEquateSymbol() const { return UsesSetToEquateSymbol; }
543 bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
544 bool needsLocalForSize() const { return NeedsLocalForSize; }
545 StringRef getPrivateGlobalPrefix() const { return PrivateGlobalPrefix; }
546 StringRef getPrivateLabelPrefix() const { return PrivateLabelPrefix; }
547
549 return !LinkerPrivateGlobalPrefix.empty();
550 }
551
553 if (hasLinkerPrivateGlobalPrefix())
554 return LinkerPrivateGlobalPrefix;
555 return getPrivateGlobalPrefix();
556 }
557
558 const char *getInlineAsmStart() const { return InlineAsmStart; }
559 const char *getInlineAsmEnd() const { return InlineAsmEnd; }
560 unsigned getAssemblerDialect() const { return AssemblerDialect; }
561 bool doesAllowAtInName() const { return AllowAtInName; }
562 void setAllowAtInName(bool V) { AllowAtInName = V; }
564 return AllowQuestionAtStartOfIdentifier;
565 }
567 return AllowAtAtStartOfIdentifier;
568 }
570 return AllowDollarAtStartOfIdentifier;
571 }
572 bool supportsNameQuoting() const { return SupportsQuotedNames; }
573
575 return UseDataRegionDirectives;
576 }
577
578 bool hasLEB128Directives() const { return HasLEB128Directives; }
579
580 bool useFullRegisterNames() const { return PPCUseFullRegisterNames; }
581 void setFullRegisterNames(bool V) { PPCUseFullRegisterNames = V; }
582
583 const char *getZeroDirective() const { return ZeroDirective; }
584 const char *getAsciiDirective() const { return AsciiDirective; }
585 const char *getAscizDirective() const { return AscizDirective; }
587 return CharacterLiteralSyntax;
588 }
589 bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
590 unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
591 const char *getGlobalDirective() const { return GlobalDirective; }
592
594 return SetDirectiveSuppressesReloc;
595 }
596
598 return COMMDirectiveAlignmentIsInBytes;
599 }
600
602 return LCOMMDirectiveAlignmentType;
603 }
604
605 bool hasFunctionAlignment() const { return HasFunctionAlignment; }
606 bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
607 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
608 bool hasIdentDirective() const { return HasIdentDirective; }
609 bool hasNoDeadStrip() const { return HasNoDeadStrip; }
610 const char *getWeakDirective() const { return WeakDirective; }
611 const char *getWeakRefDirective() const { return WeakRefDirective; }
612
614 return HasWeakDefCanBeHiddenDirective;
615 }
616
617 bool avoidWeakIfComdat() const { return AvoidWeakIfComdat; }
618
619 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr; }
620
621 MCSymbolAttr getExportedVisibilityAttr() const { return ExportedVisibilityAttr; }
622
624 return HiddenDeclarationVisibilityAttr;
625 }
626
628 return ProtectedVisibilityAttr;
629 }
630
631 bool doesSupportDebugInformation() const { return SupportsDebugInformation; }
632
633 ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
634 WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
635
637 ExceptionsType = EH;
638 }
639
640 bool usesCFIWithoutEH() const {
641 return ExceptionsType == ExceptionHandling::None && UsesCFIWithoutEH;
642 }
643
644 /// Returns true if the exception handling method for the platform uses call
645 /// frame information to unwind.
646 bool usesCFIForEH() const {
647 return (ExceptionsType == ExceptionHandling::DwarfCFI ||
648 ExceptionsType == ExceptionHandling::ARM ||
649 ExceptionsType == ExceptionHandling::ZOS || usesWindowsCFI());
650 }
651
652 bool usesWindowsCFI() const {
653 return ExceptionsType == ExceptionHandling::WinEH &&
654 (WinEHEncodingType != WinEH::EncodingType::Invalid &&
655 WinEHEncodingType != WinEH::EncodingType::X86);
656 }
657
659 return DwarfUsesRelocationsAcrossSections;
660 }
661
662 bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
663 bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
664 bool useAtForSpecifier() const { return UseAtForSpecifier; }
665 bool useParensForSpecifier() const { return UseParensForSpecifier; }
667 return SupportsExtendedDwarfLocDirective;
668 }
669
670 bool usesDwarfFileAndLocDirectives() const { return !IsAIX; }
671
673 return EnableDwarfFileDirectoryDefault;
674 }
675
676 void addInitialFrameState(const MCCFIInstruction &Inst);
677
678 const std::vector<MCCFIInstruction> &getInitialFrameState() const {
679 return InitialFrameState;
680 }
681
682 void setBinutilsVersion(std::pair<int, int> Value) {
683 BinutilsVersion = Value;
684 }
685
686 /// Return true if assembly (inline or otherwise) should be parsed.
687 bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
688
689 /// Return true if target want to use AsmParser to parse inlineasm.
691 return ParseInlineAsmUsingAsmParser;
692 }
693
694 bool binutilsIsAtLeast(int Major, int Minor) const {
695 return BinutilsVersion >= std::make_pair(Major, Minor);
696 }
697
698 /// Set whether assembly (inline or otherwise) should be parsed.
699 virtual void setUseIntegratedAssembler(bool Value) {
700 UseIntegratedAssembler = Value;
701 }
702
703 /// Set whether target want to use AsmParser to parse inlineasm.
705 ParseInlineAsmUsingAsmParser = Value;
706 }
707
708 /// Return true if assembly (inline or otherwise) should be parsed.
709 bool preserveAsmComments() const { return PreserveAsmComments; }
710
711 /// Set whether assembly (inline or otherwise) should be parsed.
712 virtual void setPreserveAsmComments(bool Value) {
713 PreserveAsmComments = Value;
714 }
715
716
717 bool shouldUseLogicalShr() const { return UseLogicalShr; }
718
719 bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
720
721 StringRef getSpecifierName(uint32_t S) const;
722 std::optional<uint32_t> getSpecifierForName(StringRef Name) const;
723
724 void printExpr(raw_ostream &, const MCExpr &) const;
726 const MCSpecifierExpr &) const {
727 llvm_unreachable("Need to implement hook if target uses MCSpecifierExpr");
728 }
729 virtual bool evaluateAsRelocatableImpl(const MCSpecifierExpr &, MCValue &Res,
730 const MCAssembler *Asm) const;
731};
732
733} // end namespace llvm
734
735#endif // LLVM_MC_MCASMINFO_H
This file defines the StringMap class.
static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI, raw_ostream &OS)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition: Compiler.h:213
This file defines the DenseMap class.
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:64
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:545
MCAsmInfo(MCAsmInfo const &)=delete
const char * Data16bitsDirective
Definition: MCAsmInfo.h:248
bool hasCOFFAssociativeComdats() const
Definition: MCAsmInfo.h:522
const char * getLabelSuffix() const
Definition: MCAsmInfo.h:540
void setAllowAtInName(bool V)
Definition: MCAsmInfo.h:562
bool preserveAsmComments() const
Return true if assembly (inline or otherwise) should be parsed.
Definition: MCAsmInfo.h:709
bool supportsSignedData() const
Definition: MCAsmInfo.h:465
const char * getInlineAsmStart() const
Definition: MCAsmInfo.h:558
bool isHLASM() const
Definition: MCAsmInfo.h:520
bool hasDotTypeDotSizeDirective() const
Definition: MCAsmInfo.h:606
bool isLittleEndian() const
True if the target is little endian.
Definition: MCAsmInfo.h:452
bool useAtForSpecifier() const
Definition: MCAsmInfo.h:664
bool useIntegratedAssembler() const
Return true if assembly (inline or otherwise) should be parsed.
Definition: MCAsmInfo.h:687
virtual void printSpecifierExpr(raw_ostream &, const MCSpecifierExpr &) const
Definition: MCAsmInfo.h:725
const char * AsciiDirective
This directive allows emission of an ascii string with the standard C escape characters embedded into...
Definition: MCAsmInfo.h:231
std::vector< MCCFIInstruction > InitialFrameState
Definition: MCAsmInfo.h:397
llvm::StringMap< uint32_t > NameToAtSpecifier
Definition: MCAsmInfo.h:431
MCAsmInfo & operator=(MCAsmInfo const &)=delete
MCSymbolAttr getProtectedVisibilityAttr() const
Definition: MCAsmInfo.h:627
bool usesSunStyleELFSectionSwitchSyntax() const
Definition: MCAsmInfo.h:505
bool doesAllowDollarAtStartOfIdentifier() const
Definition: MCAsmInfo.h:569
virtual unsigned getMaxInstLength(const MCSubtargetInfo *STI=nullptr) const
Returns the maximum possible encoded instruction size in bytes.
Definition: MCAsmInfo.h:527
unsigned getMinInstAlignment() const
Definition: MCAsmInfo.h:531
bool hasLEB128Directives() const
Definition: MCAsmInfo.h:578
bool doesSupportDataRegionDirectives() const
Definition: MCAsmInfo.h:574
MCSymbolAttr getExportedVisibilityAttr() const
Definition: MCAsmInfo.h:621
bool usesSetToEquateSymbol() const
Definition: MCAsmInfo.h:542
const char * getData32bitsDirective() const
Definition: MCAsmInfo.h:463
const char * Data8bitsDirective
These directives are used to output some unit of integer data to the current section.
Definition: MCAsmInfo.h:247
const char * Data64bitsDirective
Definition: MCAsmInfo.h:250
const std::vector< MCCFIInstruction > & getInitialFrameState() const
Definition: MCAsmInfo.h:678
bool useFullRegisterNames() const
Definition: MCAsmInfo.h:580
llvm::DenseMap< uint32_t, StringRef > AtSpecifierToName
Definition: MCAsmInfo.h:430
unsigned getAssemblerDialect() const
Definition: MCAsmInfo.h:560
virtual void setUseIntegratedAssembler(bool Value)
Set whether assembly (inline or otherwise) should be parsed.
Definition: MCAsmInfo.h:699
virtual ~MCAsmInfo()
const char * getInlineAsmEnd() const
Definition: MCAsmInfo.h:559
unsigned getTextAlignFillValue() const
Definition: MCAsmInfo.h:590
StringRef getLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:552
bool doesAllowAtInName() const
Definition: MCAsmInfo.h:561
bool useDwarfRegNumForCFI() const
Definition: MCAsmInfo.h:663
bool useAssignmentForEHBegin() const
Definition: MCAsmInfo.h:543
bool usesCFIWithoutEH() const
Definition: MCAsmInfo.h:640
bool supportsExtendedDwarfLocDirective() const
Definition: MCAsmInfo.h:666
StringRef getPrivateLabelPrefix() const
Definition: MCAsmInfo.h:546
bool PreserveAsmComments
Preserve Comments in assembly.
Definition: MCAsmInfo.h:418
const char * LabelSuffix
This is appended to emitted labels. Defaults to ":".
Definition: MCAsmInfo.h:146
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ....
Definition: MCAsmInfo.h:160
const char * getData8bitsDirective() const
Definition: MCAsmInfo.h:461
const char * getData64bitsDirective() const
Definition: MCAsmInfo.h:464
AsmCharLiteralSyntax characterLiteralSyntax() const
Definition: MCAsmInfo.h:586
bool avoidWeakIfComdat() const
Definition: MCAsmInfo.h:617
bool isAIX() const
Definition: MCAsmInfo.h:519
const char * Data32bitsDirective
Definition: MCAsmInfo.h:249
bool UseIntegratedAssembler
Should we use the integrated assembler? The integrated assembler should be enabled by default (by the...
Definition: MCAsmInfo.h:412
bool shouldUseMotorolaIntegers() const
Definition: MCAsmInfo.h:719
bool supportsNameQuoting() const
Definition: MCAsmInfo.h:572
MCSymbolAttr getHiddenDeclarationVisibilityAttr() const
Definition: MCAsmInfo.h:623
const char * GlobalDirective
This is the directive used to declare a global entity.
Definition: MCAsmInfo.h:283
bool hasWeakDefCanBeHiddenDirective() const
Definition: MCAsmInfo.h:613
virtual void setPreserveAsmComments(bool Value)
Set whether assembly (inline or otherwise) should be parsed.
Definition: MCAsmInfo.h:712
bool hasLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:548
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:164
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
Definition: MCAsmInfo.h:601
bool needsDwarfSectionOffsetDirective() const
Definition: MCAsmInfo.h:513
bool shouldUseLogicalShr() const
Definition: MCAsmInfo.h:717
bool usesCFIForEH() const
Returns true if the exception handling method for the platform uses call frame information to unwind.
Definition: MCAsmInfo.h:646
virtual void printSwitchToSection(const MCSection &, uint32_t Subsection, const Triple &, raw_ostream &) const
Definition: MCAsmInfo.h:489
StringRef getCommentString() const
Definition: MCAsmInfo.h:538
const char * getAscizDirective() const
Definition: MCAsmInfo.h:585
const char * InlineAsmStart
If these are nonempty, they contain a directive to emit before and after an inline assembly statement...
Definition: MCAsmInfo.h:174
bool doesSupportDebugInformation() const
Definition: MCAsmInfo.h:631
bool doesSetDirectiveSuppressReloc() const
Definition: MCAsmInfo.h:593
bool ParseInlineAsmUsingAsmParser
Use AsmParser to parse inlineAsm when UseIntegratedAssembler is not set.
Definition: MCAsmInfo.h:415
WinEH::EncodingType getWinEHEncodingType() const
Definition: MCAsmInfo.h:634
bool doesDwarfUseRelocationsAcrossSections() const
Definition: MCAsmInfo.h:658
virtual void setParseInlineAsmUsingAsmParser(bool Value)
Set whether target want to use AsmParser to parse inlineasm.
Definition: MCAsmInfo.h:704
const char * getZeroDirective() const
Definition: MCAsmInfo.h:583
StringRef LinkerPrivateGlobalPrefix
This prefix is used for symbols that should be passed through the assembler but be removed by the lin...
Definition: MCAsmInfo.h:170
void setFullRegisterNames(bool V)
Definition: MCAsmInfo.h:581
const char * getWeakDirective() const
Definition: MCAsmInfo.h:610
bool hasSubsectionsViaSymbols() const
Definition: MCAsmInfo.h:457
const char * InlineAsmEnd
Definition: MCAsmInfo.h:175
const char * getData16bitsDirective() const
Definition: MCAsmInfo.h:462
const char * getSeparatorString() const
Definition: MCAsmInfo.h:533
bool doesAllowAtAtStartOfIdentifier() const
Definition: MCAsmInfo.h:566
bool getCOMMDirectiveAlignmentIsInBytes() const
Definition: MCAsmInfo.h:597
bool isStackGrowthDirectionUp() const
True if target stack grow up.
Definition: MCAsmInfo.h:455
virtual bool useCodeAlign(const MCSection &Sec) const
Definition: MCAsmInfo.h:503
bool useParensForSpecifier() const
Definition: MCAsmInfo.h:665
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition: MCAsmInfo.h:131
bool shouldAllowAdditionalComments() const
Definition: MCAsmInfo.h:539
unsigned getCalleeSaveStackSlotSize() const
Get the callee-saved register stack slot size in bytes.
Definition: MCAsmInfo.h:447
bool isMachO() const
Definition: MCAsmInfo.h:521
bool parseInlineAsmUsingAsmParser() const
Return true if target want to use AsmParser to parse inlineasm.
Definition: MCAsmInfo.h:690
void setBinutilsVersion(std::pair< int, int > Value)
Definition: MCAsmInfo.h:682
bool doDwarfFDESymbolsUseAbsDiff() const
Definition: MCAsmInfo.h:662
const char * getGlobalDirective() const
Definition: MCAsmInfo.h:591
void setExceptionsType(ExceptionHandling EH)
Definition: MCAsmInfo.h:636
bool doesAllowQuestionAtStartOfIdentifier() const
Definition: MCAsmInfo.h:563
bool getAlignmentIsInBytes() const
Definition: MCAsmInfo.h:589
bool usesWindowsCFI() const
Definition: MCAsmInfo.h:652
bool usesELFSectionDirectiveForBSS() const
Definition: MCAsmInfo.h:509
bool getDollarIsPC() const
Definition: MCAsmInfo.h:532
bool binutilsIsAtLeast(int Major, int Minor) const
Definition: MCAsmInfo.h:694
const char * ZeroDirective
This should be set to the directive used to get some number of zero (and non-zero if supported by the...
Definition: MCAsmInfo.h:226
unsigned getCommentColumn() const
Definition: MCAsmInfo.h:535
MCSymbolAttr getHiddenVisibilityAttr() const
Definition: MCAsmInfo.h:619
bool hasSingleParameterDotFile() const
Definition: MCAsmInfo.h:607
const char * AscizDirective
If not null, this allows for special handling of zero terminated strings on this target.
Definition: MCAsmInfo.h:236
const char * getAsciiDirective() const
Definition: MCAsmInfo.h:584
AsmCharLiteralSyntax
Assembly character literal syntax types.
Definition: MCAsmInfo.h:67
@ ACLS_SingleQuotePrefix
Unknown; character literals not used by LLVM for this target.
Definition: MCAsmInfo.h:70
const char * getWeakRefDirective() const
Definition: MCAsmInfo.h:611
bool hasCOFFComdatConstants() const
Definition: MCAsmInfo.h:523
bool hasNoDeadStrip() const
Definition: MCAsmInfo.h:609
virtual MCSection * getNonexecutableStackSection(MCContext &Ctx) const
Targets can implement this method to specify a section to switch to if the translation unit doesn't h...
Definition: MCAsmInfo.h:470
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:633
StringRef CommentString
This indicates the comment string used by the assembler.
Definition: MCAsmInfo.h:135
bool needsLocalForSize() const
Definition: MCAsmInfo.h:544
const char * WeakDirective
Used to declare a global as being a weak symbol. Defaults to ".weak".
Definition: MCAsmInfo.h:321
void setCommentColumn(unsigned Col)
Definition: MCAsmInfo.h:536
bool hasFunctionAlignment() const
Definition: MCAsmInfo.h:605
bool enableDwarfFileDirectoryDefault() const
Definition: MCAsmInfo.h:672
bool usesDwarfFileAndLocDirectives() const
Definition: MCAsmInfo.h:670
bool hasIdentDirective() const
Definition: MCAsmInfo.h:608
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:443
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition: MCExpr.h:495
Streaming machine code generation interface.
Definition: MCStreamer.h:220
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ ByteAlignment
Definition: MCAsmInfo.h:58
@ Log2Alignment
Definition: MCAsmInfo.h:58
@ MIPS
Windows x86, uses no CFI, just EH tables.
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
@ CE
Windows NT (Windows on ARM)
@ Alpha64
Windows Alpha.
@ X86
Windows x64, Windows Itanium (IA-64)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ExceptionHandling
Definition: CodeGen.h:53
@ WinEH
Windows Exception Handling.
MCSymbolAttr
Definition: MCDirectives.h:18
@ MCSA_Protected
.protected (ELF)
Definition: MCDirectives.h:43
@ MCSA_Exported
.globl _foo, exported (XCOFF)
Definition: MCDirectives.h:34
@ MCSA_Hidden
.hidden (ELF)
Definition: MCDirectives.h:33