MCAsmInfo.h 33 KB

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