MCAsmInfo.h revision 6b6345f0167fb9ddf60bdc51d616d7a9ae590442
1//===-- llvm/MC/MCAsmInfo.h - Asm info --------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file contains a class to be used as the basis for target specific 11// asm writers. This class primarily takes care of global printing constants, 12// which are used in very similar ways across all targets. 13// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLVM_MC_MCASMINFO_H 17#define LLVM_MC_MCASMINFO_H 18 19#include "llvm/MC/MCDirectives.h" 20#include "llvm/MC/MCDwarf.h" 21#include "llvm/MC/MachineLocation.h" 22#include <cassert> 23#include <vector> 24 25namespace llvm { 26 class MCExpr; 27 class MCSection; 28 class MCStreamer; 29 class MCSymbol; 30 class MCContext; 31 32 namespace ExceptionHandling { 33 enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 }; 34 } 35 36 namespace LCOMM { 37 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment }; 38 } 39 40 /// MCAsmInfo - This class is intended to be used as a base class for asm 41 /// properties and features specific to the target. 42 class MCAsmInfo { 43 protected: 44 //===------------------------------------------------------------------===// 45 // Properties to be set by the target writer, used to configure asm printer. 46 // 47 48 /// PointerSize - Pointer size in bytes. 49 /// Default is 4. 50 unsigned PointerSize; 51 52 /// CalleeSaveStackSlotSize - Size of the stack slot reserved for 53 /// callee-saved registers, in bytes. 54 /// Default is same as pointer size. 55 unsigned CalleeSaveStackSlotSize; 56 57 /// IsLittleEndian - True if target is little endian. 58 /// Default is true. 59 bool IsLittleEndian; 60 61 /// StackGrowsUp - True if target stack grow up. 62 /// Default is false. 63 bool StackGrowsUp; 64 65 /// HasSubsectionsViaSymbols - True if this target has the MachO 66 /// .subsections_via_symbols directive. 67 bool HasSubsectionsViaSymbols; // Default is false. 68 69 /// HasMachoZeroFillDirective - True if this is a MachO target that supports 70 /// the macho-specific .zerofill directive for emitting BSS Symbols. 71 bool HasMachoZeroFillDirective; // Default is false. 72 73 /// HasMachoTBSSDirective - True if this is a MachO target that supports 74 /// the macho-specific .tbss directive for emitting thread local BSS Symbols 75 bool HasMachoTBSSDirective; // Default is false. 76 77 /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should 78 /// emit a ".reference .constructors_used" or ".reference .destructors_used" 79 /// directive after the a static ctor/dtor list. This directive is only 80 /// emitted in Static relocation model. 81 bool HasStaticCtorDtorReferenceInStaticMode; // Default is false. 82 83 /// LinkerRequiresNonEmptyDwarfLines - True if the linker has a bug and 84 /// requires that the debug_line section be of a minimum size. In practice 85 /// such a linker requires a non empty line sequence if a file is present. 86 bool LinkerRequiresNonEmptyDwarfLines; // Default to false. 87 88 /// MaxInstLength - This is the maximum possible length of an instruction, 89 /// which is needed to compute the size of an inline asm. 90 unsigned MaxInstLength; // Defaults to 4. 91 92 /// MinInstAlignment - Every possible instruction length is a multiple of 93 /// this value. Factored out in .debug_frame and .debug_line. 94 unsigned MinInstAlignment; // Defaults to 1. 95 96 /// PCSymbol - The symbol used to represent the current PC. Used in PC 97 /// relative expressions. 98 const char *PCSymbol; // Defaults to "$". 99 100 /// SeparatorString - This string, if specified, is used to separate 101 /// instructions from each other when on the same line. 102 const char *SeparatorString; // Defaults to ';' 103 104 /// CommentColumn - This indicates the comment num (zero-based) at 105 /// which asm comments should be printed. 106 unsigned CommentColumn; // Defaults to 40 107 108 /// CommentString - This indicates the comment character used by the 109 /// assembler. 110 const char *CommentString; // Defaults to "#" 111 112 /// LabelSuffix - This is appended to emitted labels. 113 const char *LabelSuffix; // Defaults to ":" 114 115 /// LabelSuffix - This is appended to emitted labels. 116 const char *DebugLabelSuffix; // Defaults to ":" 117 118 /// GlobalPrefix - If this is set to a non-empty string, it is prepended 119 /// onto all global symbols. This is often used for "_" or ".". 120 const char *GlobalPrefix; // Defaults to "" 121 122 /// PrivateGlobalPrefix - This prefix is used for globals like constant 123 /// pool entries that are completely private to the .s file and should not 124 /// have names in the .o file. This is often "." or "L". 125 const char *PrivateGlobalPrefix; // Defaults to "." 126 127 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should 128 /// be passed through the assembler but be removed by the linker. This 129 /// is "l" on Darwin, currently used for some ObjC metadata. 130 const char *LinkerPrivateGlobalPrefix; // Defaults to "" 131 132 /// InlineAsmStart/End - If these are nonempty, they contain a directive to 133 /// emit before and after an inline assembly statement. 134 const char *InlineAsmStart; // Defaults to "#APP\n" 135 const char *InlineAsmEnd; // Defaults to "#NO_APP\n" 136 137 /// Code16Directive, Code32Directive, Code64Directive - These are assembly 138 /// directives that tells the assembler to interpret the following 139 /// instructions differently. 140 const char *Code16Directive; // Defaults to ".code16" 141 const char *Code32Directive; // Defaults to ".code32" 142 const char *Code64Directive; // Defaults to ".code64" 143 144 /// AssemblerDialect - Which dialect of an assembler variant to use. 145 unsigned AssemblerDialect; // Defaults to 0 146 147 /// AllowQuotesInName - This is true if the assembler allows for complex 148 /// symbol names to be surrounded in quotes. This defaults to false. 149 bool AllowQuotesInName; 150 151 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol 152 /// names to start with a digit (e.g., "0x0021"). This defaults to false. 153 bool AllowNameToStartWithDigit; 154 155 /// AllowPeriodsInName - This is true if the assembler allows periods in 156 /// symbol names. This defaults to true. 157 bool AllowPeriodsInName; 158 159 /// AllowUTF8 - This is true if the assembler accepts UTF-8 input. 160 // FIXME: Make this a more general encoding setting? 161 bool AllowUTF8; 162 163 /// UseDataRegionDirectives - This is true if data region markers should 164 /// be printed as ".data_region/.end_data_region" directives. If false, 165 /// use "$d/$a" labels instead. 166 bool UseDataRegionDirectives; 167 168 //===--- Data Emission Directives -------------------------------------===// 169 170 /// ZeroDirective - this should be set to the directive used to get some 171 /// number of zero bytes emitted to the current section. Common cases are 172 /// "\t.zero\t" and "\t.space\t". If this is set to null, the 173 /// Data*bitsDirective's will be used to emit zero bytes. 174 const char *ZeroDirective; // Defaults to "\t.zero\t" 175 176 /// AsciiDirective - This directive allows emission of an ascii string with 177 /// the standard C escape characters embedded into it. 178 const char *AsciiDirective; // Defaults to "\t.ascii\t" 179 180 /// AscizDirective - If not null, this allows for special handling of 181 /// zero terminated strings on this target. This is commonly supported as 182 /// ".asciz". If a target doesn't support this, it can be set to null. 183 const char *AscizDirective; // Defaults to "\t.asciz\t" 184 185 /// DataDirectives - These directives are used to output some unit of 186 /// integer data to the current section. If a data directive is set to 187 /// null, smaller data directives will be used to emit the large sizes. 188 const char *Data8bitsDirective; // Defaults to "\t.byte\t" 189 const char *Data16bitsDirective; // Defaults to "\t.short\t" 190 const char *Data32bitsDirective; // Defaults to "\t.long\t" 191 const char *Data64bitsDirective; // Defaults to "\t.quad\t" 192 193 /// GPRel64Directive - if non-null, a directive that is used to emit a word 194 /// which should be relocated as a 64-bit GP-relative offset, e.g. .gpdword 195 /// on Mips. 196 const char *GPRel64Directive; // Defaults to NULL. 197 198 /// GPRel32Directive - if non-null, a directive that is used to emit a word 199 /// which should be relocated as a 32-bit GP-relative offset, e.g. .gpword 200 /// on Mips or .gprel32 on Alpha. 201 const char *GPRel32Directive; // Defaults to NULL. 202 203 /// SunStyleELFSectionSwitchSyntax - This is true if this target uses "Sun 204 /// Style" syntax for section switching ("#alloc,#write" etc) instead of the 205 /// normal ELF syntax (,"a,w") in .section directives. 206 bool SunStyleELFSectionSwitchSyntax; // Defaults to false. 207 208 /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF 209 /// '.section' directive before the '.bss' one. It's used for PPC/Linux 210 /// which doesn't support the '.bss' directive only. 211 bool UsesELFSectionDirectiveForBSS; // Defaults to false. 212 213 /// HasMicrosoftFastStdCallMangling - True if this target uses microsoft 214 /// style mangling for functions with X86_StdCall/X86_FastCall calling 215 /// convention. 216 bool HasMicrosoftFastStdCallMangling; // Defaults to false. 217 218 bool NeedsDwarfSectionOffsetDirective; 219 220 //===--- Alignment Information ----------------------------------------===// 221 222 /// AlignDirective - The directive used to emit round up to an alignment 223 /// boundary. 224 /// 225 const char *AlignDirective; // Defaults to "\t.align\t" 226 227 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter 228 /// emits ".align N" directives, where N is the number of bytes to align to. 229 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte 230 /// boundary. 231 bool AlignmentIsInBytes; // Defaults to true 232 233 /// TextAlignFillValue - If non-zero, this is used to fill the executable 234 /// space created as the result of a alignment directive. 235 unsigned TextAlignFillValue; // Defaults to 0 236 237 //===--- Global Variable Emission Directives --------------------------===// 238 239 /// GlobalDirective - This is the directive used to declare a global entity. 240 /// 241 const char *GlobalDirective; // Defaults to NULL. 242 243 /// ExternDirective - This is the directive used to declare external 244 /// globals. 245 /// 246 const char *ExternDirective; // Defaults to NULL. 247 248 /// HasSetDirective - True if the assembler supports the .set directive. 249 bool HasSetDirective; // Defaults to true. 250 251 /// HasAggressiveSymbolFolding - False if the assembler requires that we use 252 /// Lc = a - b 253 /// .long Lc 254 /// instead of 255 /// .long a - b 256 bool HasAggressiveSymbolFolding; // Defaults to true. 257 258 /// COMMDirectiveAlignmentIsInBytes - True is .comm's and .lcomms optional 259 /// alignment is to be specified in bytes instead of log2(n). 260 bool COMMDirectiveAlignmentIsInBytes; // Defaults to true; 261 262 /// LCOMMDirectiveAlignment - Describes if the .lcomm directive for the 263 /// target supports an alignment argument and how it is interpreted. 264 LCOMM::LCOMMType LCOMMDirectiveAlignmentType; // Defaults to NoAlignment. 265 266 /// HasDotTypeDotSizeDirective - True if the target has .type and .size 267 /// directives, this is true for most ELF targets. 268 bool HasDotTypeDotSizeDirective; // Defaults to true. 269 270 /// HasSingleParameterDotFile - True if the target has a single parameter 271 /// .file directive, this is true for ELF targets. 272 bool HasSingleParameterDotFile; // Defaults to true. 273 274 /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip 275 /// directive. 276 bool HasNoDeadStrip; // Defaults to false. 277 278 /// HasSymbolResolver - True if this target supports the MachO 279 /// .symbol_resolver directive. 280 bool HasSymbolResolver; // Defaults to false. 281 282 /// WeakRefDirective - This directive, if non-null, is used to declare a 283 /// global as being a weak undefined symbol. 284 const char *WeakRefDirective; // Defaults to NULL. 285 286 /// WeakDefDirective - This directive, if non-null, is used to declare a 287 /// global as being a weak defined symbol. 288 const char *WeakDefDirective; // Defaults to NULL. 289 290 /// LinkOnceDirective - This directive, if non-null is used to declare a 291 /// global as being a weak defined symbol. This is used on cygwin/mingw. 292 const char *LinkOnceDirective; // Defaults to NULL. 293 294 /// HiddenVisibilityAttr - This attribute, if not MCSA_Invalid, is used to 295 /// declare a symbol as having hidden visibility. 296 MCSymbolAttr HiddenVisibilityAttr; // Defaults to MCSA_Hidden. 297 298 /// HiddenDeclarationVisibilityAttr - This attribute, if not MCSA_Invalid, 299 /// is used to declare an undefined symbol as having hidden visibility. 300 MCSymbolAttr HiddenDeclarationVisibilityAttr; // Defaults to MCSA_Hidden. 301 302 303 /// ProtectedVisibilityAttr - This attribute, if not MCSA_Invalid, is used 304 /// to declare a symbol as having protected visibility. 305 MCSymbolAttr ProtectedVisibilityAttr; // Defaults to MCSA_Protected 306 307 //===--- Dwarf Emission Directives -----------------------------------===// 308 309 /// HasLEB128 - True if target asm supports leb128 directives. 310 bool HasLEB128; // Defaults to false. 311 312 /// SupportsDebugInformation - True if target supports emission of debugging 313 /// information. 314 bool SupportsDebugInformation; // Defaults to false. 315 316 /// SupportsExceptionHandling - True if target supports exception handling. 317 ExceptionHandling::ExceptionsType ExceptionsType; // Defaults to None 318 319 /// DwarfUsesRelocationsAcrossSections - True if Dwarf2 output generally 320 /// uses relocations for references to other .debug_* sections. 321 bool DwarfUsesRelocationsAcrossSections; 322 323 /// DwarfRegNumForCFI - True if dwarf register numbers are printed 324 /// instead of symbolic register names in .cfi_* directives. 325 bool DwarfRegNumForCFI; // Defaults to false; 326 327 //===--- Prologue State ----------------------------------------------===// 328 329 std::vector<MCCFIInstruction> InitialFrameState; 330 331 public: 332 explicit MCAsmInfo(); 333 virtual ~MCAsmInfo(); 334 335 // FIXME: move these methods to DwarfPrinter when the JIT stops using them. 336 static unsigned getSLEB128Size(int64_t Value); 337 static unsigned getULEB128Size(uint64_t Value); 338 339 /// getPointerSize - Get the pointer size in bytes. 340 unsigned getPointerSize() const { 341 return PointerSize; 342 } 343 344 /// getCalleeSaveStackSlotSize - Get the callee-saved register stack slot 345 /// size in bytes. 346 unsigned getCalleeSaveStackSlotSize() const { 347 return CalleeSaveStackSlotSize; 348 } 349 350 /// isLittleEndian - True if the target is little endian. 351 bool isLittleEndian() const { 352 return IsLittleEndian; 353 } 354 355 /// isStackGrowthDirectionUp - True if target stack grow up. 356 bool isStackGrowthDirectionUp() const { 357 return StackGrowsUp; 358 } 359 360 bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; } 361 362 // Data directive accessors. 363 // 364 const char *getData8bitsDirective() const { 365 return Data8bitsDirective; 366 } 367 const char *getData16bitsDirective() const { 368 return Data16bitsDirective; 369 } 370 const char *getData32bitsDirective() const { 371 return Data32bitsDirective; 372 } 373 const char *getData64bitsDirective() const { 374 return Data64bitsDirective; 375 } 376 const char *getGPRel64Directive() const { return GPRel64Directive; } 377 const char *getGPRel32Directive() const { return GPRel32Directive; } 378 379 /// getNonexecutableStackSection - Targets can implement this method to 380 /// specify a section to switch to if the translation unit doesn't have any 381 /// trampolines that require an executable stack. 382 virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const{ 383 return 0; 384 } 385 386 virtual const MCExpr * 387 getExprForPersonalitySymbol(const MCSymbol *Sym, 388 unsigned Encoding, 389 MCStreamer &Streamer) const; 390 391 const MCExpr * 392 getExprForFDESymbol(const MCSymbol *Sym, 393 unsigned Encoding, 394 MCStreamer &Streamer) const; 395 396 bool usesSunStyleELFSectionSwitchSyntax() const { 397 return SunStyleELFSectionSwitchSyntax; 398 } 399 400 bool usesELFSectionDirectiveForBSS() const { 401 return UsesELFSectionDirectiveForBSS; 402 } 403 404 bool hasMicrosoftFastStdCallMangling() const { 405 return HasMicrosoftFastStdCallMangling; 406 } 407 408 bool needsDwarfSectionOffsetDirective() const { 409 return NeedsDwarfSectionOffsetDirective; 410 } 411 412 // Accessors. 413 // 414 bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; } 415 bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; } 416 bool hasStaticCtorDtorReferenceInStaticMode() const { 417 return HasStaticCtorDtorReferenceInStaticMode; 418 } 419 bool getLinkerRequiresNonEmptyDwarfLines() const { 420 return LinkerRequiresNonEmptyDwarfLines; 421 } 422 unsigned getMaxInstLength() const { 423 return MaxInstLength; 424 } 425 unsigned getMinInstAlignment() const { 426 return MinInstAlignment; 427 } 428 const char *getPCSymbol() const { 429 return PCSymbol; 430 } 431 const char *getSeparatorString() const { 432 return SeparatorString; 433 } 434 unsigned getCommentColumn() const { 435 return CommentColumn; 436 } 437 const char *getCommentString() const { 438 return CommentString; 439 } 440 const char *getLabelSuffix() const { 441 return LabelSuffix; 442 } 443 444 const char *getDebugLabelSuffix() const { 445 return DebugLabelSuffix; 446 } 447 448 const char *getGlobalPrefix() const { 449 return GlobalPrefix; 450 } 451 const char *getPrivateGlobalPrefix() const { 452 return PrivateGlobalPrefix; 453 } 454 const char *getLinkerPrivateGlobalPrefix() const { 455 return LinkerPrivateGlobalPrefix; 456 } 457 const char *getInlineAsmStart() const { 458 return InlineAsmStart; 459 } 460 const char *getInlineAsmEnd() const { 461 return InlineAsmEnd; 462 } 463 const char *getCode16Directive() const { 464 return Code16Directive; 465 } 466 const char *getCode32Directive() const { 467 return Code32Directive; 468 } 469 const char *getCode64Directive() const { 470 return Code64Directive; 471 } 472 unsigned getAssemblerDialect() const { 473 return AssemblerDialect; 474 } 475 bool doesAllowQuotesInName() const { 476 return AllowQuotesInName; 477 } 478 bool doesAllowNameToStartWithDigit() const { 479 return AllowNameToStartWithDigit; 480 } 481 bool doesAllowPeriodsInName() const { 482 return AllowPeriodsInName; 483 } 484 bool doesAllowUTF8() const { 485 return AllowUTF8; 486 } 487 bool doesSupportDataRegionDirectives() const { 488 return UseDataRegionDirectives; 489 } 490 const char *getZeroDirective() const { 491 return ZeroDirective; 492 } 493 const char *getAsciiDirective() const { 494 return AsciiDirective; 495 } 496 const char *getAscizDirective() const { 497 return AscizDirective; 498 } 499 const char *getAlignDirective() const { 500 return AlignDirective; 501 } 502 bool getAlignmentIsInBytes() const { 503 return AlignmentIsInBytes; 504 } 505 unsigned getTextAlignFillValue() const { 506 return TextAlignFillValue; 507 } 508 const char *getGlobalDirective() const { 509 return GlobalDirective; 510 } 511 const char *getExternDirective() const { 512 return ExternDirective; 513 } 514 bool hasSetDirective() const { return HasSetDirective; } 515 bool hasAggressiveSymbolFolding() const { 516 return HasAggressiveSymbolFolding; 517 } 518 bool getCOMMDirectiveAlignmentIsInBytes() const { 519 return COMMDirectiveAlignmentIsInBytes; 520 } 521 LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const { 522 return LCOMMDirectiveAlignmentType; 523 } 524 bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;} 525 bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; } 526 bool hasNoDeadStrip() const { return HasNoDeadStrip; } 527 bool hasSymbolResolver() const { return HasSymbolResolver; } 528 const char *getWeakRefDirective() const { return WeakRefDirective; } 529 const char *getWeakDefDirective() const { return WeakDefDirective; } 530 const char *getLinkOnceDirective() const { return LinkOnceDirective; } 531 532 MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr;} 533 MCSymbolAttr getHiddenDeclarationVisibilityAttr() const { 534 return HiddenDeclarationVisibilityAttr; 535 } 536 MCSymbolAttr getProtectedVisibilityAttr() const { 537 return ProtectedVisibilityAttr; 538 } 539 bool hasLEB128() const { 540 return HasLEB128; 541 } 542 bool doesSupportDebugInformation() const { 543 return SupportsDebugInformation; 544 } 545 bool doesSupportExceptionHandling() const { 546 return ExceptionsType != ExceptionHandling::None; 547 } 548 ExceptionHandling::ExceptionsType getExceptionHandlingType() const { 549 return ExceptionsType; 550 } 551 bool isExceptionHandlingDwarf() const { 552 return 553 (ExceptionsType == ExceptionHandling::DwarfCFI || 554 ExceptionsType == ExceptionHandling::ARM || 555 ExceptionsType == ExceptionHandling::Win64); 556 } 557 bool doesDwarfUseRelocationsAcrossSections() const { 558 return DwarfUsesRelocationsAcrossSections; 559 } 560 bool useDwarfRegNumForCFI() const { 561 return DwarfRegNumForCFI; 562 } 563 564 void addInitialFrameState(const MCCFIInstruction &Inst) { 565 InitialFrameState.push_back(Inst); 566 } 567 568 const std::vector<MCCFIInstruction> &getInitialFrameState() const { 569 return InitialFrameState; 570 } 571 }; 572} 573 574#endif 575